cpplib.h 47 KB

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