cpplib.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. /* Definitions for CPP library.
  2. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  3. Written by Per Bothner, 1994-95.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 3, or (at your option) any
  7. later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>.
  15. In other words, you are welcome to use, share and improve this program.
  16. You are forbidden to forbid anyone else to use, share and improve
  17. what you give them. Help stamp out software-hoarding! */
  18. #ifndef LIBCPP_CPPLIB_H
  19. #define LIBCPP_CPPLIB_H
  20. #include <sys/types.h>
  21. #include "symtab.h"
  22. #include "line-map.h"
  23. typedef struct cpp_reader cpp_reader;
  24. typedef struct cpp_buffer cpp_buffer;
  25. typedef struct cpp_options cpp_options;
  26. typedef struct cpp_token cpp_token;
  27. typedef struct cpp_string cpp_string;
  28. typedef struct cpp_hashnode cpp_hashnode;
  29. typedef struct cpp_macro cpp_macro;
  30. typedef struct cpp_callbacks cpp_callbacks;
  31. typedef struct cpp_dir cpp_dir;
  32. struct _cpp_file;
  33. /* The first three groups, apart from '=', can appear in preprocessor
  34. expressions (+= and -= are used to indicate unary + and - resp.).
  35. This allows a lookup table to be implemented in _cpp_parse_expr.
  36. The first group, to CPP_LAST_EQ, can be immediately followed by an
  37. '='. The lexer needs operators ending in '=', like ">>=", to be in
  38. the same order as their counterparts without the '=', like ">>".
  39. See the cpp_operator table optab in expr.c if you change the order or
  40. add or remove anything in the first group. */
  41. #define TTYPE_TABLE \
  42. OP(EQ, "=") \
  43. OP(NOT, "!") \
  44. OP(GREATER, ">") /* compare */ \
  45. OP(LESS, "<") \
  46. OP(PLUS, "+") /* math */ \
  47. OP(MINUS, "-") \
  48. OP(MULT, "*") \
  49. OP(DIV, "/") \
  50. OP(MOD, "%") \
  51. OP(AND, "&") /* bit ops */ \
  52. OP(OR, "|") \
  53. OP(XOR, "^") \
  54. OP(RSHIFT, ">>") \
  55. OP(LSHIFT, "<<") \
  56. \
  57. OP(COMPL, "~") \
  58. OP(AND_AND, "&&") /* logical */ \
  59. OP(OR_OR, "||") \
  60. OP(QUERY, "?") \
  61. OP(COLON, ":") \
  62. OP(COMMA, ",") /* grouping */ \
  63. OP(OPEN_PAREN, "(") \
  64. OP(CLOSE_PAREN, ")") \
  65. TK(EOF, NONE) \
  66. OP(EQ_EQ, "==") /* compare */ \
  67. OP(NOT_EQ, "!=") \
  68. OP(GREATER_EQ, ">=") \
  69. OP(LESS_EQ, "<=") \
  70. \
  71. /* These two are unary + / - in preprocessor expressions. */ \
  72. OP(PLUS_EQ, "+=") /* math */ \
  73. OP(MINUS_EQ, "-=") \
  74. \
  75. OP(MULT_EQ, "*=") \
  76. OP(DIV_EQ, "/=") \
  77. OP(MOD_EQ, "%=") \
  78. OP(AND_EQ, "&=") /* bit ops */ \
  79. OP(OR_EQ, "|=") \
  80. OP(XOR_EQ, "^=") \
  81. OP(RSHIFT_EQ, ">>=") \
  82. OP(LSHIFT_EQ, "<<=") \
  83. /* Digraphs together, beginning with CPP_FIRST_DIGRAPH. */ \
  84. OP(HASH, "#") /* digraphs */ \
  85. OP(PASTE, "##") \
  86. OP(OPEN_SQUARE, "[") \
  87. OP(CLOSE_SQUARE, "]") \
  88. OP(OPEN_BRACE, "{") \
  89. OP(CLOSE_BRACE, "}") \
  90. /* The remainder of the punctuation. Order is not significant. */ \
  91. OP(SEMICOLON, ";") /* structure */ \
  92. OP(ELLIPSIS, "...") \
  93. OP(PLUS_PLUS, "++") /* increment */ \
  94. OP(MINUS_MINUS, "--") \
  95. OP(DEREF, "->") /* accessors */ \
  96. OP(DOT, ".") \
  97. OP(SCOPE, "::") \
  98. OP(DEREF_STAR, "->*") \
  99. OP(DOT_STAR, ".*") \
  100. OP(ATSIGN, "@") /* used in Objective-C */ \
  101. \
  102. TK(NAME, IDENT) /* word */ \
  103. TK(AT_NAME, IDENT) /* @word - Objective-C */ \
  104. TK(NUMBER, LITERAL) /* 34_be+ta */ \
  105. \
  106. TK(CHAR, LITERAL) /* 'char' */ \
  107. TK(WCHAR, LITERAL) /* L'char' */ \
  108. TK(CHAR16, LITERAL) /* u'char' */ \
  109. TK(CHAR32, LITERAL) /* U'char' */ \
  110. TK(UTF8CHAR, LITERAL) /* u8'char' */ \
  111. TK(OTHER, LITERAL) /* stray punctuation */ \
  112. \
  113. TK(STRING, LITERAL) /* "string" */ \
  114. TK(WSTRING, LITERAL) /* L"string" */ \
  115. TK(STRING16, LITERAL) /* u"string" */ \
  116. TK(STRING32, LITERAL) /* U"string" */ \
  117. TK(UTF8STRING, LITERAL) /* u8"string" */ \
  118. TK(OBJC_STRING, LITERAL) /* @"string" - Objective-C */ \
  119. TK(HEADER_NAME, LITERAL) /* <stdio.h> in #include */ \
  120. \
  121. TK(CHAR_USERDEF, LITERAL) /* 'char'_suffix - C++-0x */ \
  122. TK(WCHAR_USERDEF, LITERAL) /* L'char'_suffix - C++-0x */ \
  123. TK(CHAR16_USERDEF, LITERAL) /* u'char'_suffix - C++-0x */ \
  124. TK(CHAR32_USERDEF, LITERAL) /* U'char'_suffix - C++-0x */ \
  125. TK(UTF8CHAR_USERDEF, LITERAL) /* u8'char'_suffix - C++-0x */ \
  126. TK(STRING_USERDEF, LITERAL) /* "string"_suffix - C++-0x */ \
  127. TK(WSTRING_USERDEF, LITERAL) /* L"string"_suffix - C++-0x */ \
  128. TK(STRING16_USERDEF, LITERAL) /* u"string"_suffix - C++-0x */ \
  129. TK(STRING32_USERDEF, LITERAL) /* U"string"_suffix - C++-0x */ \
  130. TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */ \
  131. \
  132. TK(COMMENT, LITERAL) /* Only if output comments. */ \
  133. /* SPELL_LITERAL happens to DTRT. */ \
  134. TK(MACRO_ARG, NONE) /* Macro argument. */ \
  135. TK(PRAGMA, NONE) /* Only for deferred pragmas. */ \
  136. TK(PRAGMA_EOL, NONE) /* End-of-line for deferred pragmas. */ \
  137. TK(PADDING, NONE) /* Whitespace for -E. */
  138. #define OP(e, s) CPP_ ## e,
  139. #define TK(e, s) CPP_ ## e,
  140. enum cpp_ttype
  141. {
  142. TTYPE_TABLE
  143. N_TTYPES,
  144. /* A token type for keywords, as opposed to ordinary identifiers. */
  145. CPP_KEYWORD,
  146. /* Positions in the table. */
  147. CPP_LAST_EQ = CPP_LSHIFT,
  148. CPP_FIRST_DIGRAPH = CPP_HASH,
  149. CPP_LAST_PUNCTUATOR= CPP_ATSIGN,
  150. CPP_LAST_CPP_OP = CPP_LESS_EQ
  151. };
  152. #undef OP
  153. #undef TK
  154. /* C language kind, used when calling cpp_create_reader. */
  155. enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
  156. CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_STDC17,
  157. CLK_STDC2X,
  158. CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
  159. CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
  160. CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM};
  161. /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
  162. struct GTY(()) cpp_string {
  163. unsigned int len;
  164. const unsigned char *text;
  165. };
  166. /* Flags for the cpp_token structure. */
  167. #define PREV_WHITE (1 << 0) /* If whitespace before this token. */
  168. #define DIGRAPH (1 << 1) /* If it was a digraph. */
  169. #define STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */
  170. #define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */
  171. #define NAMED_OP (1 << 4) /* C++ named operators. */
  172. #define PREV_FALLTHROUGH (1 << 5) /* On a token preceeded by FALLTHROUGH
  173. comment. */
  174. #define BOL (1 << 6) /* Token at beginning of line. */
  175. #define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend,
  176. set in c-lex.c. */
  177. #define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph. */
  178. #define SP_PREV_WHITE (1 << 9) /* If whitespace before a ##
  179. operator, or before this token
  180. after a # operator. */
  181. #define NO_EXPAND (1 << 10) /* Do not macro-expand this token. */
  182. /* Specify which field, if any, of the cpp_token union is used. */
  183. enum cpp_token_fld_kind {
  184. CPP_TOKEN_FLD_NODE,
  185. CPP_TOKEN_FLD_SOURCE,
  186. CPP_TOKEN_FLD_STR,
  187. CPP_TOKEN_FLD_ARG_NO,
  188. CPP_TOKEN_FLD_TOKEN_NO,
  189. CPP_TOKEN_FLD_PRAGMA,
  190. CPP_TOKEN_FLD_NONE
  191. };
  192. /* A macro argument in the cpp_token union. */
  193. struct GTY(()) cpp_macro_arg {
  194. /* Argument number. */
  195. unsigned int arg_no;
  196. /* The original spelling of the macro argument token. */
  197. cpp_hashnode *
  198. GTY ((nested_ptr (union tree_node,
  199. "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
  200. "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
  201. spelling;
  202. };
  203. /* An identifier in the cpp_token union. */
  204. struct GTY(()) cpp_identifier {
  205. /* The canonical (UTF-8) spelling of the identifier. */
  206. cpp_hashnode *
  207. GTY ((nested_ptr (union tree_node,
  208. "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
  209. "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
  210. node;
  211. /* The original spelling of the identifier. */
  212. cpp_hashnode *
  213. GTY ((nested_ptr (union tree_node,
  214. "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
  215. "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
  216. spelling;
  217. };
  218. /* A preprocessing token. This has been carefully packed and should
  219. occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */
  220. struct GTY(()) cpp_token {
  221. /* Location of first char of token, together with range of full token. */
  222. location_t src_loc;
  223. ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */
  224. unsigned short flags; /* flags - see above */
  225. union cpp_token_u
  226. {
  227. /* An identifier. */
  228. struct cpp_identifier GTY ((tag ("CPP_TOKEN_FLD_NODE"))) node;
  229. /* Inherit padding from this token. */
  230. cpp_token * GTY ((tag ("CPP_TOKEN_FLD_SOURCE"))) source;
  231. /* A string, or number. */
  232. struct cpp_string GTY ((tag ("CPP_TOKEN_FLD_STR"))) str;
  233. /* Argument no. (and original spelling) for a CPP_MACRO_ARG. */
  234. struct cpp_macro_arg GTY ((tag ("CPP_TOKEN_FLD_ARG_NO"))) macro_arg;
  235. /* Original token no. for a CPP_PASTE (from a sequence of
  236. consecutive paste tokens in a macro expansion). */
  237. unsigned int GTY ((tag ("CPP_TOKEN_FLD_TOKEN_NO"))) token_no;
  238. /* Caller-supplied identifier for a CPP_PRAGMA. */
  239. unsigned int GTY ((tag ("CPP_TOKEN_FLD_PRAGMA"))) pragma;
  240. } GTY ((desc ("cpp_token_val_index (&%1)"))) val;
  241. };
  242. /* Say which field is in use. */
  243. extern enum cpp_token_fld_kind cpp_token_val_index (const cpp_token *tok);
  244. /* A type wide enough to hold any multibyte source character.
  245. cpplib's character constant interpreter requires an unsigned type.
  246. Also, a typedef for the signed equivalent.
  247. The width of this type is capped at 32 bits; there do exist targets
  248. where wchar_t is 64 bits, but only in a non-default mode, and there
  249. would be no meaningful interpretation for a wchar_t value greater
  250. than 2^32 anyway -- the widest wide-character encoding around is
  251. ISO 10646, which stops at 2^31. */
  252. #if CHAR_BIT * SIZEOF_INT >= 32
  253. # define CPPCHAR_SIGNED_T int
  254. #elif CHAR_BIT * SIZEOF_LONG >= 32
  255. # define CPPCHAR_SIGNED_T long
  256. #else
  257. # error "Cannot find a least-32-bit signed integer type"
  258. #endif
  259. typedef unsigned CPPCHAR_SIGNED_T cppchar_t;
  260. typedef CPPCHAR_SIGNED_T cppchar_signed_t;
  261. /* Style of header dependencies to generate. */
  262. enum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM };
  263. /* The possible normalization levels, from most restrictive to least. */
  264. enum cpp_normalize_level {
  265. /* In NFKC. */
  266. normalized_KC = 0,
  267. /* In NFC. */
  268. normalized_C,
  269. /* In NFC, except for subsequences where being in NFC would make
  270. the identifier invalid. */
  271. normalized_identifier_C,
  272. /* Not normalized at all. */
  273. normalized_none
  274. };
  275. /* This structure is nested inside struct cpp_reader, and
  276. carries all the options visible to the command line. */
  277. struct cpp_options
  278. {
  279. /* Characters between tab stops. */
  280. unsigned int tabstop;
  281. /* The language we're preprocessing. */
  282. enum c_lang lang;
  283. /* Nonzero means use extra default include directories for C++. */
  284. unsigned char cplusplus;
  285. /* Nonzero means handle cplusplus style comments. */
  286. unsigned char cplusplus_comments;
  287. /* Nonzero means define __OBJC__, treat @ as a special token, use
  288. the OBJC[PLUS]_INCLUDE_PATH environment variable, and allow
  289. "#import". */
  290. unsigned char objc;
  291. /* Nonzero means don't copy comments into the output file. */
  292. unsigned char discard_comments;
  293. /* Nonzero means don't copy comments into the output file during
  294. macro expansion. */
  295. unsigned char discard_comments_in_macro_exp;
  296. /* Nonzero means process the ISO trigraph sequences. */
  297. unsigned char trigraphs;
  298. /* Nonzero means process the ISO digraph sequences. */
  299. unsigned char digraphs;
  300. /* Nonzero means to allow hexadecimal floats and LL suffixes. */
  301. unsigned char extended_numbers;
  302. /* Nonzero means process u/U prefix literals (UTF-16/32). */
  303. unsigned char uliterals;
  304. /* Nonzero means process u8 prefixed character literals (UTF-8). */
  305. unsigned char utf8_char_literals;
  306. /* Nonzero means process r/R raw strings. If this is set, uliterals
  307. must be set as well. */
  308. unsigned char rliterals;
  309. /* Nonzero means print names of header files (-H). */
  310. unsigned char print_include_names;
  311. /* Nonzero means complain about deprecated features. */
  312. unsigned char cpp_warn_deprecated;
  313. /* Nonzero means warn if slash-star appears in a comment. */
  314. unsigned char warn_comments;
  315. /* Nonzero means to warn about __DATA__, __TIME__ and __TIMESTAMP__ usage. */
  316. unsigned char warn_date_time;
  317. /* Nonzero means warn if a user-supplied include directory does not
  318. exist. */
  319. unsigned char warn_missing_include_dirs;
  320. /* Nonzero means warn if there are any trigraphs. */
  321. unsigned char warn_trigraphs;
  322. /* Nonzero means warn about multicharacter charconsts. */
  323. unsigned char warn_multichar;
  324. /* Nonzero means warn about various incompatibilities with
  325. traditional C. */
  326. unsigned char cpp_warn_traditional;
  327. /* Nonzero means warn about long long numeric constants. */
  328. unsigned char cpp_warn_long_long;
  329. /* Nonzero means warn about text after an #endif (or #else). */
  330. unsigned char warn_endif_labels;
  331. /* Nonzero means warn about implicit sign changes owing to integer
  332. promotions. */
  333. unsigned char warn_num_sign_change;
  334. /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode.
  335. Presumably the usage is protected by the appropriate #ifdef. */
  336. unsigned char warn_variadic_macros;
  337. /* Nonzero means warn about builtin macros that are redefined or
  338. explicitly undefined. */
  339. unsigned char warn_builtin_macro_redefined;
  340. /* Different -Wimplicit-fallthrough= levels. */
  341. unsigned char cpp_warn_implicit_fallthrough;
  342. /* Nonzero means we should look for header.gcc files that remap file
  343. names. */
  344. unsigned char remap;
  345. /* Zero means dollar signs are punctuation. */
  346. unsigned char dollars_in_ident;
  347. /* Nonzero means UCNs are accepted in identifiers. */
  348. unsigned char extended_identifiers;
  349. /* True if we should warn about dollars in identifiers or numbers
  350. for this translation unit. */
  351. unsigned char warn_dollars;
  352. /* Nonzero means warn if undefined identifiers are evaluated in an #if. */
  353. unsigned char warn_undef;
  354. /* Nonzero means warn if "defined" is encountered in a place other than
  355. an #if. */
  356. unsigned char warn_expansion_to_defined;
  357. /* Nonzero means warn of unused macros from the main file. */
  358. unsigned char warn_unused_macros;
  359. /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */
  360. unsigned char c99;
  361. /* Nonzero if we are conforming to a specific C or C++ standard. */
  362. unsigned char std;
  363. /* Nonzero means give all the error messages the ANSI standard requires. */
  364. unsigned char cpp_pedantic;
  365. /* Nonzero means we're looking at already preprocessed code, so don't
  366. bother trying to do macro expansion and whatnot. */
  367. unsigned char preprocessed;
  368. /* Nonzero means we are going to emit debugging logs during
  369. preprocessing. */
  370. unsigned char debug;
  371. /* Nonzero means we are tracking locations of tokens involved in
  372. macro expansion. 1 Means we track the location in degraded mode
  373. where we do not track locations of tokens resulting from the
  374. expansion of arguments of function-like macro. 2 Means we do
  375. track all macro expansions. This last option is the one that
  376. consumes the highest amount of memory. */
  377. unsigned char track_macro_expansion;
  378. /* Nonzero means handle C++ alternate operator names. */
  379. unsigned char operator_names;
  380. /* Nonzero means warn about use of C++ alternate operator names. */
  381. unsigned char warn_cxx_operator_names;
  382. /* True for traditional preprocessing. */
  383. unsigned char traditional;
  384. /* Nonzero for C++ 2011 Standard user-defined literals. */
  385. unsigned char user_literals;
  386. /* Nonzero means warn when a string or character literal is followed by a
  387. ud-suffix which does not beging with an underscore. */
  388. unsigned char warn_literal_suffix;
  389. /* Nonzero means interpret imaginary, fixed-point, or other gnu extension
  390. literal number suffixes as user-defined literal number suffixes. */
  391. unsigned char ext_numeric_literals;
  392. /* Nonzero means extended identifiers allow the characters specified
  393. in C11 and C++11. */
  394. unsigned char c11_identifiers;
  395. /* Nonzero for C++ 2014 Standard binary constants. */
  396. unsigned char binary_constants;
  397. /* Nonzero for C++ 2014 Standard digit separators. */
  398. unsigned char digit_separators;
  399. /* Nonzero for C++2a __VA_OPT__ feature. */
  400. unsigned char va_opt;
  401. /* Holds the name of the target (execution) character set. */
  402. const char *narrow_charset;
  403. /* Holds the name of the target wide character set. */
  404. const char *wide_charset;
  405. /* Holds the name of the input character set. */
  406. const char *input_charset;
  407. /* The minimum permitted level of normalization before a warning
  408. is generated. See enum cpp_normalize_level. */
  409. int warn_normalize;
  410. /* True to warn about precompiled header files we couldn't use. */
  411. bool warn_invalid_pch;
  412. /* True if dependencies should be restored from a precompiled header. */
  413. bool restore_pch_deps;
  414. /* True if warn about differences between C90 and C99. */
  415. signed char cpp_warn_c90_c99_compat;
  416. /* True if warn about differences between C++98 and C++11. */
  417. bool cpp_warn_cxx11_compat;
  418. /* Dependency generation. */
  419. struct
  420. {
  421. /* Style of header dependencies to generate. */
  422. enum cpp_deps_style style;
  423. /* Assume missing files are generated files. */
  424. bool missing_files;
  425. /* Generate phony targets for each dependency apart from the first
  426. one. */
  427. bool phony_targets;
  428. /* If true, no dependency is generated on the main file. */
  429. bool ignore_main_file;
  430. /* If true, intend to use the preprocessor output (e.g., for compilation)
  431. in addition to the dependency info. */
  432. bool need_preprocessor_output;
  433. } deps;
  434. /* Target-specific features set by the front end or client. */
  435. /* Precision for target CPP arithmetic, target characters, target
  436. ints and target wide characters, respectively. */
  437. size_t precision, char_precision, int_precision, wchar_precision;
  438. /* True means chars (wide chars) are unsigned. */
  439. bool unsigned_char, unsigned_wchar;
  440. /* True if the most significant byte in a word has the lowest
  441. address in memory. */
  442. bool bytes_big_endian;
  443. /* Nonzero means __STDC__ should have the value 0 in system headers. */
  444. unsigned char stdc_0_in_system_headers;
  445. /* True disables tokenization outside of preprocessing directives. */
  446. bool directives_only;
  447. /* True enables canonicalization of system header file paths. */
  448. bool canonical_system_headers;
  449. };
  450. /* Diagnostic levels. To get a diagnostic without associating a
  451. position in the translation unit with it, use cpp_error_with_line
  452. with a line number of zero. */
  453. enum cpp_diagnostic_level {
  454. /* Warning, an error with -Werror. */
  455. CPP_DL_WARNING = 0,
  456. /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */
  457. CPP_DL_WARNING_SYSHDR,
  458. /* Warning, an error with -pedantic-errors or -Werror. */
  459. CPP_DL_PEDWARN,
  460. /* An error. */
  461. CPP_DL_ERROR,
  462. /* An internal consistency check failed. Prints "internal error: ",
  463. otherwise the same as CPP_DL_ERROR. */
  464. CPP_DL_ICE,
  465. /* An informative note following a warning. */
  466. CPP_DL_NOTE,
  467. /* A fatal error. */
  468. CPP_DL_FATAL
  469. };
  470. /* Warning reason codes. Use a reason code of CPP_W_NONE for unclassified
  471. warnings and diagnostics that are not warnings. */
  472. enum cpp_warning_reason {
  473. CPP_W_NONE = 0,
  474. CPP_W_DEPRECATED,
  475. CPP_W_COMMENTS,
  476. CPP_W_MISSING_INCLUDE_DIRS,
  477. CPP_W_TRIGRAPHS,
  478. CPP_W_MULTICHAR,
  479. CPP_W_TRADITIONAL,
  480. CPP_W_LONG_LONG,
  481. CPP_W_ENDIF_LABELS,
  482. CPP_W_NUM_SIGN_CHANGE,
  483. CPP_W_VARIADIC_MACROS,
  484. CPP_W_BUILTIN_MACRO_REDEFINED,
  485. CPP_W_DOLLARS,
  486. CPP_W_UNDEF,
  487. CPP_W_UNUSED_MACROS,
  488. CPP_W_CXX_OPERATOR_NAMES,
  489. CPP_W_NORMALIZE,
  490. CPP_W_INVALID_PCH,
  491. CPP_W_WARNING_DIRECTIVE,
  492. CPP_W_LITERAL_SUFFIX,
  493. CPP_W_DATE_TIME,
  494. CPP_W_PEDANTIC,
  495. CPP_W_C90_C99_COMPAT,
  496. CPP_W_CXX11_COMPAT,
  497. CPP_W_EXPANSION_TO_DEFINED
  498. };
  499. /* Callback for header lookup for HEADER, which is the name of a
  500. source file. It is used as a method of last resort to find headers
  501. that are not otherwise found during the normal include processing.
  502. The return value is the malloced name of a header to try and open,
  503. if any, or NULL otherwise. This callback is called only if the
  504. header is otherwise unfound. */
  505. typedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **);
  506. /* Call backs to cpplib client. */
  507. struct cpp_callbacks
  508. {
  509. /* Called when a new line of preprocessed output is started. */
  510. void (*line_change) (cpp_reader *, const cpp_token *, int);
  511. /* Called when switching to/from a new file.
  512. The line_map is for the new file. It is NULL if there is no new file.
  513. (In C this happens when done with <built-in>+<command line> and also
  514. when done with a main file.) This can be used for resource cleanup. */
  515. void (*file_change) (cpp_reader *, const line_map_ordinary *);
  516. void (*dir_change) (cpp_reader *, const char *);
  517. void (*include) (cpp_reader *, location_t, const unsigned char *,
  518. const char *, int, const cpp_token **);
  519. void (*define) (cpp_reader *, location_t, cpp_hashnode *);
  520. void (*undef) (cpp_reader *, location_t, cpp_hashnode *);
  521. void (*ident) (cpp_reader *, location_t, const cpp_string *);
  522. void (*def_pragma) (cpp_reader *, location_t);
  523. int (*valid_pch) (cpp_reader *, const char *, int);
  524. void (*read_pch) (cpp_reader *, const char *, int, const char *);
  525. missing_header_cb missing_header;
  526. /* Context-sensitive macro support. Returns macro (if any) that should
  527. be expanded. */
  528. cpp_hashnode * (*macro_to_expand) (cpp_reader *, const cpp_token *);
  529. /* Called to emit a diagnostic. This callback receives the
  530. translated message. */
  531. bool (*diagnostic) (cpp_reader *,
  532. enum cpp_diagnostic_level,
  533. enum cpp_warning_reason,
  534. rich_location *,
  535. const char *, va_list *)
  536. ATTRIBUTE_FPTR_PRINTF(5,0);
  537. /* Callbacks for when a macro is expanded, or tested (whether
  538. defined or not at the time) in #ifdef, #ifndef or "defined". */
  539. void (*used_define) (cpp_reader *, location_t, cpp_hashnode *);
  540. void (*used_undef) (cpp_reader *, location_t, cpp_hashnode *);
  541. /* Called before #define and #undef or other macro definition
  542. changes are processed. */
  543. void (*before_define) (cpp_reader *);
  544. /* Called whenever a macro is expanded or tested.
  545. Second argument is the location of the start of the current expansion. */
  546. void (*used) (cpp_reader *, location_t, cpp_hashnode *);
  547. /* Callback to identify whether an attribute exists. */
  548. int (*has_attribute) (cpp_reader *);
  549. /* Callback that can change a user lazy into normal macro. */
  550. void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned);
  551. /* Callback to parse SOURCE_DATE_EPOCH from environment. */
  552. time_t (*get_source_date_epoch) (cpp_reader *);
  553. /* Callback for providing suggestions for misspelled directives. */
  554. const char *(*get_suggestion) (cpp_reader *, const char *, const char *const *);
  555. /* Callback for when a comment is encountered, giving the location
  556. of the opening slash, a pointer to the content (which is not
  557. necessarily 0-terminated), and the length of the content.
  558. The content contains the opening slash-star (or slash-slash),
  559. and for C-style comments contains the closing star-slash. For
  560. C++-style comments it does not include the terminating newline. */
  561. void (*comment) (cpp_reader *, location_t, const unsigned char *,
  562. size_t);
  563. /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro
  564. expansions. */
  565. const char *(*remap_filename) (const char*);
  566. };
  567. #ifdef VMS
  568. #define INO_T_CPP ino_t ino[3]
  569. #else
  570. #define INO_T_CPP ino_t ino
  571. #endif
  572. /* Chain of directories to look for include files in. */
  573. struct cpp_dir
  574. {
  575. /* NULL-terminated singly-linked list. */
  576. struct cpp_dir *next;
  577. /* NAME of the directory, NUL-terminated. */
  578. char *name;
  579. unsigned int len;
  580. /* One if a system header, two if a system header that has extern
  581. "C" guards for C++. */
  582. unsigned char sysp;
  583. /* Is this a user-supplied directory? */
  584. bool user_supplied_p;
  585. /* The canonicalized NAME as determined by lrealpath. This field
  586. is only used by hosts that lack reliable inode numbers. */
  587. char *canonical_name;
  588. /* Mapping of file names for this directory for MS-DOS and related
  589. platforms. A NULL-terminated array of (from, to) pairs. */
  590. const char **name_map;
  591. /* Routine to construct pathname, given the search path name and the
  592. HEADER we are trying to find, return a constructed pathname to
  593. try and open. If this is NULL, the constructed pathname is as
  594. constructed by append_file_to_dir. */
  595. char *(*construct) (const char *header, cpp_dir *dir);
  596. /* The C front end uses these to recognize duplicated
  597. directories in the search path. */
  598. INO_T_CPP;
  599. dev_t dev;
  600. };
  601. /* The kind of the cpp_macro. */
  602. enum cpp_macro_kind {
  603. cmk_macro, /* An ISO macro (token expansion). */
  604. cmk_assert, /* An assertion. */
  605. cmk_traditional /* A traditional macro (text expansion). */
  606. };
  607. /* Each macro definition is recorded in a cpp_macro structure.
  608. Variadic macros cannot occur with traditional cpp. */
  609. struct GTY(()) cpp_macro {
  610. union cpp_parm_u
  611. {
  612. /* Parameters, if any. If parameter names use extended identifiers,
  613. the original spelling of those identifiers, not the canonical
  614. UTF-8 spelling, goes here. */
  615. cpp_hashnode ** GTY ((tag ("false"),
  616. nested_ptr (union tree_node,
  617. "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
  618. "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"),
  619. length ("%1.paramc"))) params;
  620. /* If this is an assertion, the next one in the chain. */
  621. cpp_macro *GTY ((tag ("true"))) next;
  622. } GTY ((desc ("%1.kind == cmk_assert"))) parm;
  623. /* Definition line number. */
  624. location_t line;
  625. /* Number of tokens in body, or bytes for traditional macros. */
  626. /* Do we really need 2^32-1 range here? */
  627. unsigned int count;
  628. /* Number of parameters. */
  629. unsigned short paramc;
  630. /* Non-zero if this is a user-lazy macro, value provided by user. */
  631. unsigned char lazy;
  632. /* The kind of this macro (ISO, trad or assert) */
  633. unsigned kind : 2;
  634. /* If a function-like macro. */
  635. unsigned int fun_like : 1;
  636. /* If a variadic macro. */
  637. unsigned int variadic : 1;
  638. /* If macro defined in system header. */
  639. unsigned int syshdr : 1;
  640. /* Nonzero if it has been expanded or had its existence tested. */
  641. unsigned int used : 1;
  642. /* Indicate whether the tokens include extra CPP_PASTE tokens at the
  643. end to track invalid redefinitions with consecutive CPP_PASTE
  644. tokens. */
  645. unsigned int extra_tokens : 1;
  646. /* 1 bits spare (32-bit). 33 on 64-bit target. */
  647. union cpp_exp_u
  648. {
  649. /* Trailing array of replacement tokens (ISO), or assertion body value. */
  650. cpp_token GTY ((tag ("false"), length ("%1.count"))) tokens[1];
  651. /* Pointer to replacement text (traditional). See comment at top
  652. of cpptrad.c for how traditional function-like macros are
  653. encoded. */
  654. const unsigned char *GTY ((tag ("true"))) text;
  655. } GTY ((desc ("%1.kind == cmk_traditional"))) exp;
  656. };
  657. /* Poisoned identifiers are flagged NODE_POISONED. NODE_OPERATOR (C++
  658. only) indicates an identifier that behaves like an operator such as
  659. "xor". NODE_DIAGNOSTIC is for speed in lex_token: it indicates a
  660. diagnostic may be required for this node. Currently this only
  661. applies to __VA_ARGS__, poisoned identifiers, and -Wc++-compat
  662. warnings about NODE_OPERATOR. */
  663. /* Hash node flags. */
  664. #define NODE_OPERATOR (1 << 0) /* C++ named operator. */
  665. #define NODE_POISONED (1 << 1) /* Poisoned identifier. */
  666. #define NODE_DIAGNOSTIC (1 << 2) /* Possible diagnostic when lexed. */
  667. #define NODE_WARN (1 << 3) /* Warn if redefined or undefined. */
  668. #define NODE_DISABLED (1 << 4) /* A disabled macro. */
  669. #define NODE_USED (1 << 5) /* Dumped with -dU. */
  670. #define NODE_CONDITIONAL (1 << 6) /* Conditional macro */
  671. #define NODE_WARN_OPERATOR (1 << 7) /* Warn about C++ named operator. */
  672. /* Different flavors of hash node. */
  673. enum node_type
  674. {
  675. NT_VOID = 0, /* Maybe an assert? */
  676. NT_MACRO_ARG, /* A macro arg. */
  677. NT_USER_MACRO, /* A user macro. */
  678. NT_BUILTIN_MACRO, /* A builtin macro. */
  679. NT_MACRO_MASK = NT_USER_MACRO /* Mask for either macro kind. */
  680. };
  681. /* Different flavors of builtin macro. _Pragma is an operator, but we
  682. handle it with the builtin code for efficiency reasons. */
  683. enum cpp_builtin_type
  684. {
  685. BT_SPECLINE = 0, /* `__LINE__' */
  686. BT_DATE, /* `__DATE__' */
  687. BT_FILE, /* `__FILE__' */
  688. BT_BASE_FILE, /* `__BASE_FILE__' */
  689. BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
  690. BT_TIME, /* `__TIME__' */
  691. BT_STDC, /* `__STDC__' */
  692. BT_PRAGMA, /* `_Pragma' operator */
  693. BT_TIMESTAMP, /* `__TIMESTAMP__' */
  694. BT_COUNTER, /* `__COUNTER__' */
  695. BT_HAS_ATTRIBUTE /* `__has_attribute__(x)' */
  696. };
  697. #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
  698. #define HT_NODE(NODE) (&(NODE)->ident)
  699. #define NODE_LEN(NODE) HT_LEN (HT_NODE (NODE))
  700. #define NODE_NAME(NODE) HT_STR (HT_NODE (NODE))
  701. /* The common part of an identifier node shared amongst all 3 C front
  702. ends. Also used to store CPP identifiers, which are a superset of
  703. identifiers in the grammatical sense. */
  704. union GTY(()) _cpp_hashnode_value {
  705. /* Assert (maybe NULL) */
  706. cpp_macro * GTY((tag ("NT_VOID"))) answers;
  707. /* Macro (never NULL) */
  708. cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro;
  709. /* Code for a builtin macro. */
  710. enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin;
  711. /* Macro argument index. */
  712. unsigned short GTY ((tag ("NT_MACRO_ARG"))) arg_index;
  713. };
  714. struct GTY(()) cpp_hashnode {
  715. struct ht_identifier ident;
  716. unsigned int is_directive : 1;
  717. unsigned int directive_index : 7; /* If is_directive,
  718. then index into directive table.
  719. Otherwise, a NODE_OPERATOR. */
  720. unsigned char rid_code; /* Rid code - for front ends. */
  721. ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */
  722. unsigned int flags : 8; /* CPP flags. */
  723. /* 6 bits spare (plus another 32 on 64-bit hosts). */
  724. union _cpp_hashnode_value GTY ((desc ("%1.type"))) value;
  725. };
  726. /* A class for iterating through the source locations within a
  727. string token (before escapes are interpreted, and before
  728. concatenation). */
  729. class cpp_string_location_reader {
  730. public:
  731. cpp_string_location_reader (location_t src_loc,
  732. line_maps *line_table);
  733. source_range get_next ();
  734. private:
  735. location_t m_loc;
  736. int m_offset_per_column;
  737. line_maps *m_line_table;
  738. };
  739. /* A class for storing the source ranges of all of the characters within
  740. a string literal, after escapes are interpreted, and after
  741. concatenation.
  742. This is not GTY-marked, as instances are intended to be temporary. */
  743. class cpp_substring_ranges
  744. {
  745. public:
  746. cpp_substring_ranges ();
  747. ~cpp_substring_ranges ();
  748. int get_num_ranges () const { return m_num_ranges; }
  749. source_range get_range (int idx) const
  750. {
  751. linemap_assert (idx < m_num_ranges);
  752. return m_ranges[idx];
  753. }
  754. void add_range (source_range range);
  755. void add_n_ranges (int num, cpp_string_location_reader &loc_reader);
  756. private:
  757. source_range *m_ranges;
  758. int m_num_ranges;
  759. int m_alloc_ranges;
  760. };
  761. /* Call this first to get a handle to pass to other functions.
  762. If you want cpplib to manage its own hashtable, pass in a NULL
  763. pointer. Otherwise you should pass in an initialized hash table
  764. that cpplib will share; this technique is used by the C front
  765. ends. */
  766. extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
  767. struct line_maps *);
  768. /* Reset the cpp_reader's line_map. This is only used after reading a
  769. PCH file. */
  770. extern void cpp_set_line_map (cpp_reader *, struct line_maps *);
  771. /* Call this to change the selected language standard (e.g. because of
  772. command line options). */
  773. extern void cpp_set_lang (cpp_reader *, enum c_lang);
  774. /* Set the include paths. */
  775. extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int);
  776. /* Call these to get pointers to the options, callback, and deps
  777. structures for a given reader. These pointers are good until you
  778. call cpp_finish on that reader. You can either edit the callbacks
  779. through the pointer returned from cpp_get_callbacks, or set them
  780. with cpp_set_callbacks. */
  781. extern cpp_options *cpp_get_options (cpp_reader *);
  782. extern cpp_callbacks *cpp_get_callbacks (cpp_reader *);
  783. extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
  784. extern struct deps *cpp_get_deps (cpp_reader *);
  785. /* This function reads the file, but does not start preprocessing. It
  786. returns the name of the original file; this is the same as the
  787. input file, except for preprocessed input. This will generate at
  788. least one file change callback, and possibly a line change callback
  789. too. If there was an error opening the file, it returns NULL. */
  790. extern const char *cpp_read_main_file (cpp_reader *, const char *);
  791. /* Set up built-ins with special behavior. Use cpp_init_builtins()
  792. instead unless your know what you are doing. */
  793. extern void cpp_init_special_builtins (cpp_reader *);
  794. /* Set up built-ins like __FILE__. */
  795. extern void cpp_init_builtins (cpp_reader *, int);
  796. /* This is called after options have been parsed, and partially
  797. processed. */
  798. extern void cpp_post_options (cpp_reader *);
  799. /* Set up translation to the target character set. */
  800. extern void cpp_init_iconv (cpp_reader *);
  801. /* Call this to finish preprocessing. If you requested dependency
  802. generation, pass an open stream to write the information to,
  803. otherwise NULL. It is your responsibility to close the stream. */
  804. extern void cpp_finish (cpp_reader *, FILE *deps_stream);
  805. /* Call this to release the handle at the end of preprocessing. Any
  806. use of the handle after this function returns is invalid. */
  807. extern void cpp_destroy (cpp_reader *);
  808. extern unsigned int cpp_token_len (const cpp_token *);
  809. extern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *);
  810. extern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *,
  811. unsigned char *, bool);
  812. extern void cpp_register_pragma (cpp_reader *, const char *, const char *,
  813. void (*) (cpp_reader *), bool);
  814. extern void cpp_register_deferred_pragma (cpp_reader *, const char *,
  815. const char *, unsigned, bool, bool);
  816. extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
  817. const cpp_token *);
  818. extern const cpp_token *cpp_get_token (cpp_reader *);
  819. extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
  820. location_t *);
  821. inline bool cpp_user_macro_p (const cpp_hashnode *node)
  822. {
  823. return node->type == NT_USER_MACRO;
  824. }
  825. inline bool cpp_builtin_macro_p (const cpp_hashnode *node)
  826. {
  827. return node->type == NT_BUILTIN_MACRO;
  828. }
  829. inline bool cpp_macro_p (const cpp_hashnode *node)
  830. {
  831. return node->type & NT_MACRO_MASK;
  832. }
  833. /* Returns true if NODE is a function-like user macro. */
  834. inline bool cpp_fun_like_macro_p (cpp_hashnode *node)
  835. {
  836. return cpp_user_macro_p (node) && node->value.macro->fun_like;
  837. }
  838. extern const unsigned char *cpp_macro_definition (cpp_reader *,
  839. cpp_hashnode *);
  840. inline location_t cpp_macro_definition_location (cpp_hashnode *node)
  841. {
  842. return node->value.macro->line;
  843. }
  844. extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
  845. extern const cpp_token *cpp_peek_token (cpp_reader *, int);
  846. /* Evaluate a CPP_*CHAR* token. */
  847. extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *,
  848. unsigned int *, int *);
  849. /* Evaluate a vector of CPP_*STRING* tokens. */
  850. extern bool cpp_interpret_string (cpp_reader *,
  851. const cpp_string *, size_t,
  852. cpp_string *, enum cpp_ttype);
  853. extern const char *cpp_interpret_string_ranges (cpp_reader *pfile,
  854. const cpp_string *from,
  855. cpp_string_location_reader *,
  856. size_t count,
  857. cpp_substring_ranges *out,
  858. enum cpp_ttype type);
  859. extern bool cpp_interpret_string_notranslate (cpp_reader *,
  860. const cpp_string *, size_t,
  861. cpp_string *, enum cpp_ttype);
  862. /* Convert a host character constant to the execution character set. */
  863. extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t);
  864. /* Used to register macros and assertions, perhaps from the command line.
  865. The text is the same as the command line argument. */
  866. extern void cpp_define (cpp_reader *, const char *);
  867. extern void cpp_define_formatted (cpp_reader *pfile,
  868. const char *fmt, ...) ATTRIBUTE_PRINTF_2;
  869. extern void cpp_assert (cpp_reader *, const char *);
  870. extern void cpp_undef (cpp_reader *, const char *);
  871. extern void cpp_unassert (cpp_reader *, const char *);
  872. /* Mark a node as a lazily defined macro. */
  873. extern void cpp_define_lazily (cpp_reader *, cpp_hashnode *node, unsigned N);
  874. /* Undefine all macros and assertions. */
  875. extern void cpp_undef_all (cpp_reader *);
  876. extern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *,
  877. size_t, int);
  878. extern int cpp_defined (cpp_reader *, const unsigned char *, int);
  879. /* A preprocessing number. Code assumes that any unused high bits of
  880. the double integer are set to zero. */
  881. /* This type has to be equal to unsigned HOST_WIDE_INT, see
  882. gcc/c-family/c-lex.c. */
  883. typedef uint64_t cpp_num_part;
  884. typedef struct cpp_num cpp_num;
  885. struct cpp_num
  886. {
  887. cpp_num_part high;
  888. cpp_num_part low;
  889. bool unsignedp; /* True if value should be treated as unsigned. */
  890. bool overflow; /* True if the most recent calculation overflowed. */
  891. };
  892. /* cpplib provides two interfaces for interpretation of preprocessing
  893. numbers.
  894. cpp_classify_number categorizes numeric constants according to
  895. their field (integer, floating point, or invalid), radix (decimal,
  896. octal, hexadecimal), and type suffixes. */
  897. #define CPP_N_CATEGORY 0x000F
  898. #define CPP_N_INVALID 0x0000
  899. #define CPP_N_INTEGER 0x0001
  900. #define CPP_N_FLOATING 0x0002
  901. #define CPP_N_WIDTH 0x00F0
  902. #define CPP_N_SMALL 0x0010 /* int, float, short _Fract/Accum */
  903. #define CPP_N_MEDIUM 0x0020 /* long, double, long _Fract/_Accum. */
  904. #define CPP_N_LARGE 0x0040 /* long long, long double,
  905. long long _Fract/Accum. */
  906. #define CPP_N_WIDTH_MD 0xF0000 /* machine defined. */
  907. #define CPP_N_MD_W 0x10000
  908. #define CPP_N_MD_Q 0x20000
  909. #define CPP_N_RADIX 0x0F00
  910. #define CPP_N_DECIMAL 0x0100
  911. #define CPP_N_HEX 0x0200
  912. #define CPP_N_OCTAL 0x0400
  913. #define CPP_N_BINARY 0x0800
  914. #define CPP_N_UNSIGNED 0x1000 /* Properties. */
  915. #define CPP_N_IMAGINARY 0x2000
  916. #define CPP_N_DFLOAT 0x4000
  917. #define CPP_N_DEFAULT 0x8000
  918. #define CPP_N_FRACT 0x100000 /* Fract types. */
  919. #define CPP_N_ACCUM 0x200000 /* Accum types. */
  920. #define CPP_N_FLOATN 0x400000 /* _FloatN types. */
  921. #define CPP_N_FLOATNX 0x800000 /* _FloatNx types. */
  922. #define CPP_N_USERDEF 0x1000000 /* C++0x user-defined literal. */
  923. #define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value
  924. of N, divided by 16. */
  925. #define CPP_FLOATN_SHIFT 24
  926. #define CPP_FLOATN_MAX 0xF0
  927. /* Classify a CPP_NUMBER token. The return value is a combination of
  928. the flags from the above sets. */
  929. extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
  930. const char **, location_t);
  931. /* Return the classification flags for a float suffix. */
  932. extern unsigned int cpp_interpret_float_suffix (cpp_reader *, const char *,
  933. size_t);
  934. /* Return the classification flags for an int suffix. */
  935. extern unsigned int cpp_interpret_int_suffix (cpp_reader *, const char *,
  936. size_t);
  937. /* Evaluate a token classified as category CPP_N_INTEGER. */
  938. extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
  939. unsigned int);
  940. /* Sign extend a number, with PRECISION significant bits and all
  941. others assumed clear, to fill out a cpp_num structure. */
  942. cpp_num cpp_num_sign_extend (cpp_num, size_t);
  943. /* Output a diagnostic of some kind. */
  944. extern bool cpp_error (cpp_reader *, enum cpp_diagnostic_level,
  945. const char *msgid, ...)
  946. ATTRIBUTE_PRINTF_3;
  947. extern bool cpp_warning (cpp_reader *, enum cpp_warning_reason,
  948. const char *msgid, ...)
  949. ATTRIBUTE_PRINTF_3;
  950. extern bool cpp_pedwarning (cpp_reader *, enum cpp_warning_reason,
  951. const char *msgid, ...)
  952. ATTRIBUTE_PRINTF_3;
  953. extern bool cpp_warning_syshdr (cpp_reader *, enum cpp_warning_reason reason,
  954. const char *msgid, ...)
  955. ATTRIBUTE_PRINTF_3;
  956. /* Output a diagnostic with "MSGID: " preceding the
  957. error string of errno. No location is printed. */
  958. extern bool cpp_errno (cpp_reader *, enum cpp_diagnostic_level,
  959. const char *msgid);
  960. /* Similarly, but with "FILENAME: " instead of "MSGID: ", where
  961. the filename is not localized. */
  962. extern bool cpp_errno_filename (cpp_reader *, enum cpp_diagnostic_level,
  963. const char *filename, location_t loc);
  964. /* Same as cpp_error, except additionally specifies a position as a
  965. (translation unit) physical line and physical column. If the line is
  966. zero, then no location is printed. */
  967. extern bool cpp_error_with_line (cpp_reader *, enum cpp_diagnostic_level,
  968. location_t, unsigned,
  969. const char *msgid, ...)
  970. ATTRIBUTE_PRINTF_5;
  971. extern bool cpp_warning_with_line (cpp_reader *, enum cpp_warning_reason,
  972. location_t, unsigned,
  973. const char *msgid, ...)
  974. ATTRIBUTE_PRINTF_5;
  975. extern bool cpp_pedwarning_with_line (cpp_reader *, enum cpp_warning_reason,
  976. location_t, unsigned,
  977. const char *msgid, ...)
  978. ATTRIBUTE_PRINTF_5;
  979. extern bool cpp_warning_with_line_syshdr (cpp_reader *, enum cpp_warning_reason,
  980. location_t, unsigned,
  981. const char *msgid, ...)
  982. ATTRIBUTE_PRINTF_5;
  983. extern bool cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level,
  984. location_t src_loc, const char *msgid, ...)
  985. ATTRIBUTE_PRINTF_4;
  986. extern bool cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level,
  987. rich_location *richloc, const char *msgid, ...)
  988. ATTRIBUTE_PRINTF_4;
  989. /* In lex.c */
  990. extern int cpp_ideq (const cpp_token *, const char *);
  991. extern void cpp_output_line (cpp_reader *, FILE *);
  992. extern unsigned char *cpp_output_line_to_string (cpp_reader *,
  993. const unsigned char *);
  994. extern void cpp_output_token (const cpp_token *, FILE *);
  995. extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags);
  996. /* Returns the value of an escape sequence, truncated to the correct
  997. target precision. PSTR points to the input pointer, which is just
  998. after the backslash. LIMIT is how much text we have. WIDE is true
  999. if the escape sequence is part of a wide character constant or
  1000. string literal. Handles all relevant diagnostics. */
  1001. extern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr,
  1002. const unsigned char *limit, int wide);
  1003. /* Structure used to hold a comment block at a given location in the
  1004. source code. */
  1005. typedef struct
  1006. {
  1007. /* Text of the comment including the terminators. */
  1008. char *comment;
  1009. /* source location for the given comment. */
  1010. location_t sloc;
  1011. } cpp_comment;
  1012. /* Structure holding all comments for a given cpp_reader. */
  1013. typedef struct
  1014. {
  1015. /* table of comment entries. */
  1016. cpp_comment *entries;
  1017. /* number of actual entries entered in the table. */
  1018. int count;
  1019. /* number of entries allocated currently. */
  1020. int allocated;
  1021. } cpp_comment_table;
  1022. /* Returns the table of comments encountered by the preprocessor. This
  1023. table is only populated when pfile->state.save_comments is true. */
  1024. extern cpp_comment_table *cpp_get_comments (cpp_reader *);
  1025. /* In hash.c */
  1026. /* Lookup an identifier in the hashtable. Puts the identifier in the
  1027. table if it is not already there. */
  1028. extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *,
  1029. unsigned int);
  1030. typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *);
  1031. extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *);
  1032. /* In macro.c */
  1033. extern void cpp_scan_nooutput (cpp_reader *);
  1034. extern int cpp_sys_macro_p (cpp_reader *);
  1035. extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *,
  1036. unsigned int);
  1037. /* In files.c */
  1038. extern bool cpp_included (cpp_reader *, const char *);
  1039. extern bool cpp_included_before (cpp_reader *, const char *, location_t);
  1040. extern void cpp_make_system_header (cpp_reader *, int, int);
  1041. extern bool cpp_push_include (cpp_reader *, const char *);
  1042. extern bool cpp_push_default_include (cpp_reader *, const char *);
  1043. extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *);
  1044. extern const char *cpp_get_path (struct _cpp_file *);
  1045. extern cpp_dir *cpp_get_dir (struct _cpp_file *);
  1046. extern cpp_buffer *cpp_get_buffer (cpp_reader *);
  1047. extern struct _cpp_file *cpp_get_file (cpp_buffer *);
  1048. extern cpp_buffer *cpp_get_prev (cpp_buffer *);
  1049. extern void cpp_clear_file_cache (cpp_reader *);
  1050. /* In pch.c */
  1051. struct save_macro_data;
  1052. extern int cpp_save_state (cpp_reader *, FILE *);
  1053. extern int cpp_write_pch_deps (cpp_reader *, FILE *);
  1054. extern int cpp_write_pch_state (cpp_reader *, FILE *);
  1055. extern int cpp_valid_state (cpp_reader *, const char *, int);
  1056. extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **);
  1057. extern int cpp_read_state (cpp_reader *, const char *, FILE *,
  1058. struct save_macro_data *);
  1059. /* In lex.c */
  1060. extern void cpp_force_token_locations (cpp_reader *, location_t);
  1061. extern void cpp_stop_forcing_token_locations (cpp_reader *);
  1062. /* In expr.c */
  1063. extern enum cpp_ttype cpp_userdef_string_remove_type
  1064. (enum cpp_ttype type);
  1065. extern enum cpp_ttype cpp_userdef_string_add_type
  1066. (enum cpp_ttype type);
  1067. extern enum cpp_ttype cpp_userdef_char_remove_type
  1068. (enum cpp_ttype type);
  1069. extern enum cpp_ttype cpp_userdef_char_add_type
  1070. (enum cpp_ttype type);
  1071. extern bool cpp_userdef_string_p
  1072. (enum cpp_ttype type);
  1073. extern bool cpp_userdef_char_p
  1074. (enum cpp_ttype type);
  1075. extern const char * cpp_get_userdef_suffix
  1076. (const cpp_token *);
  1077. #endif /* ! LIBCPP_CPPLIB_H */