1169695Skan/* Definitions for CPP library. 2169695Skan Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3169695Skan 2004, 2005 4169695Skan Free Software Foundation, Inc. 5169695Skan Written by Per Bothner, 1994-95. 6169695Skan 7169695SkanThis program is free software; you can redistribute it and/or modify it 8169695Skanunder the terms of the GNU General Public License as published by the 9169695SkanFree Software Foundation; either version 2, or (at your option) any 10169695Skanlater version. 11169695Skan 12169695SkanThis program is distributed in the hope that it will be useful, 13169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of 14169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15169695SkanGNU General Public License for more details. 16169695Skan 17169695SkanYou should have received a copy of the GNU General Public License 18169695Skanalong with this program; if not, write to the Free Software 19169695SkanFoundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20169695Skan 21169695Skan In other words, you are welcome to use, share and improve this program. 22169695Skan You are forbidden to forbid anyone else to use, share and improve 23169695Skan what you give them. Help stamp out software-hoarding! */ 24169695Skan#ifndef LIBCPP_CPPLIB_H 25169695Skan#define LIBCPP_CPPLIB_H 26169695Skan 27169695Skan#include <sys/types.h> 28169695Skan#include "symtab.h" 29169695Skan#include "line-map.h" 30169695Skan 31169695Skan#ifdef __cplusplus 32169695Skanextern "C" { 33169695Skan#endif 34169695Skan 35169695Skantypedef struct cpp_reader cpp_reader; 36169695Skantypedef struct cpp_buffer cpp_buffer; 37169695Skantypedef struct cpp_options cpp_options; 38169695Skantypedef struct cpp_token cpp_token; 39169695Skantypedef struct cpp_string cpp_string; 40169695Skantypedef struct cpp_hashnode cpp_hashnode; 41169695Skantypedef struct cpp_macro cpp_macro; 42169695Skantypedef struct cpp_callbacks cpp_callbacks; 43169695Skantypedef struct cpp_dir cpp_dir; 44169695Skan 45169695Skanstruct answer; 46169695Skanstruct _cpp_file; 47169695Skan 48169695Skan/* The first three groups, apart from '=', can appear in preprocessor 49169695Skan expressions (+= and -= are used to indicate unary + and - resp.). 50169695Skan This allows a lookup table to be implemented in _cpp_parse_expr. 51169695Skan 52169695Skan The first group, to CPP_LAST_EQ, can be immediately followed by an 53169695Skan '='. The lexer needs operators ending in '=', like ">>=", to be in 54169695Skan the same order as their counterparts without the '=', like ">>". 55169695Skan 56169695Skan See the cpp_operator table optab in expr.c if you change the order or 57169695Skan add or remove anything in the first group. */ 58169695Skan 59169695Skan#define TTYPE_TABLE \ 60169695Skan OP(EQ, "=") \ 61169695Skan OP(NOT, "!") \ 62169695Skan OP(GREATER, ">") /* compare */ \ 63169695Skan OP(LESS, "<") \ 64169695Skan OP(PLUS, "+") /* math */ \ 65169695Skan OP(MINUS, "-") \ 66169695Skan OP(MULT, "*") \ 67169695Skan OP(DIV, "/") \ 68169695Skan OP(MOD, "%") \ 69169695Skan OP(AND, "&") /* bit ops */ \ 70169695Skan OP(OR, "|") \ 71169695Skan OP(XOR, "^") \ 72169695Skan OP(RSHIFT, ">>") \ 73169695Skan OP(LSHIFT, "<<") \ 74169695Skan \ 75169695Skan OP(COMPL, "~") \ 76169695Skan OP(AND_AND, "&&") /* logical */ \ 77169695Skan OP(OR_OR, "||") \ 78169695Skan OP(QUERY, "?") \ 79169695Skan OP(COLON, ":") \ 80169695Skan OP(COMMA, ",") /* grouping */ \ 81169695Skan OP(OPEN_PAREN, "(") \ 82169695Skan OP(CLOSE_PAREN, ")") \ 83169695Skan TK(EOF, NONE) \ 84169695Skan OP(EQ_EQ, "==") /* compare */ \ 85169695Skan OP(NOT_EQ, "!=") \ 86169695Skan OP(GREATER_EQ, ">=") \ 87169695Skan OP(LESS_EQ, "<=") \ 88169695Skan \ 89169695Skan /* These two are unary + / - in preprocessor expressions. */ \ 90169695Skan OP(PLUS_EQ, "+=") /* math */ \ 91169695Skan OP(MINUS_EQ, "-=") \ 92169695Skan \ 93169695Skan OP(MULT_EQ, "*=") \ 94169695Skan OP(DIV_EQ, "/=") \ 95169695Skan OP(MOD_EQ, "%=") \ 96169695Skan OP(AND_EQ, "&=") /* bit ops */ \ 97169695Skan OP(OR_EQ, "|=") \ 98169695Skan OP(XOR_EQ, "^=") \ 99169695Skan OP(RSHIFT_EQ, ">>=") \ 100169695Skan OP(LSHIFT_EQ, "<<=") \ 101169695Skan /* Digraphs together, beginning with CPP_FIRST_DIGRAPH. */ \ 102169695Skan OP(HASH, "#") /* digraphs */ \ 103169695Skan OP(PASTE, "##") \ 104169695Skan OP(OPEN_SQUARE, "[") \ 105169695Skan OP(CLOSE_SQUARE, "]") \ 106169695Skan OP(OPEN_BRACE, "{") \ 107169695Skan OP(CLOSE_BRACE, "}") \ 108169695Skan /* The remainder of the punctuation. Order is not significant. */ \ 109169695Skan OP(SEMICOLON, ";") /* structure */ \ 110169695Skan OP(ELLIPSIS, "...") \ 111169695Skan OP(PLUS_PLUS, "++") /* increment */ \ 112169695Skan OP(MINUS_MINUS, "--") \ 113169695Skan OP(DEREF, "->") /* accessors */ \ 114169695Skan OP(DOT, ".") \ 115169695Skan OP(SCOPE, "::") \ 116169695Skan OP(DEREF_STAR, "->*") \ 117169695Skan OP(DOT_STAR, ".*") \ 118169695Skan OP(ATSIGN, "@") /* used in Objective-C */ \ 119169695Skan \ 120169695Skan TK(NAME, IDENT) /* word */ \ 121169695Skan TK(AT_NAME, IDENT) /* @word - Objective-C */ \ 122169695Skan TK(NUMBER, LITERAL) /* 34_be+ta */ \ 123169695Skan \ 124169695Skan TK(CHAR, LITERAL) /* 'char' */ \ 125169695Skan TK(WCHAR, LITERAL) /* L'char' */ \ 126169695Skan TK(OTHER, LITERAL) /* stray punctuation */ \ 127169695Skan \ 128169695Skan TK(STRING, LITERAL) /* "string" */ \ 129169695Skan TK(WSTRING, LITERAL) /* L"string" */ \ 130169695Skan TK(OBJC_STRING, LITERAL) /* @"string" - Objective-C */ \ 131169695Skan TK(HEADER_NAME, LITERAL) /* <stdio.h> in #include */ \ 132169695Skan \ 133169695Skan TK(COMMENT, LITERAL) /* Only if output comments. */ \ 134169695Skan /* SPELL_LITERAL happens to DTRT. */ \ 135169695Skan TK(MACRO_ARG, NONE) /* Macro argument. */ \ 136169695Skan TK(PRAGMA, NONE) /* Only for deferred pragmas. */ \ 137169695Skan TK(PRAGMA_EOL, NONE) /* End-of-line for deferred pragmas. */ \ 138169695Skan TK(PADDING, NONE) /* Whitespace for -E. */ 139169695Skan 140169695Skan#define OP(e, s) CPP_ ## e, 141169695Skan#define TK(e, s) CPP_ ## e, 142169695Skanenum cpp_ttype 143169695Skan{ 144169695Skan TTYPE_TABLE 145169695Skan N_TTYPES, 146169695Skan 147169695Skan /* Positions in the table. */ 148169695Skan CPP_LAST_EQ = CPP_LSHIFT, 149169695Skan CPP_FIRST_DIGRAPH = CPP_HASH, 150169695Skan CPP_LAST_PUNCTUATOR= CPP_ATSIGN, 151169695Skan CPP_LAST_CPP_OP = CPP_LESS_EQ 152169695Skan}; 153169695Skan#undef OP 154169695Skan#undef TK 155169695Skan 156169695Skan/* C language kind, used when calling cpp_create_reader. */ 157169695Skanenum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99, 158169695Skan CLK_GNUCXX, CLK_CXX98, CLK_ASM}; 159169695Skan 160169695Skan/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ 161169695Skanstruct cpp_string GTY(()) 162169695Skan{ 163169695Skan unsigned int len; 164169695Skan const unsigned char *text; 165169695Skan}; 166169695Skan 167169695Skan/* Flags for the cpp_token structure. */ 168169695Skan#define PREV_WHITE (1 << 0) /* If whitespace before this token. */ 169169695Skan#define DIGRAPH (1 << 1) /* If it was a digraph. */ 170169695Skan#define STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */ 171169695Skan#define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */ 172169695Skan#define NAMED_OP (1 << 4) /* C++ named operators. */ 173169695Skan#define NO_EXPAND (1 << 5) /* Do not macro-expand this token. */ 174169695Skan#define BOL (1 << 6) /* Token at beginning of line. */ 175169695Skan#define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend, 176169695Skan set in c-lex.c. */ 177169695Skan 178169695Skan/* Specify which field, if any, of the cpp_token union is used. */ 179169695Skan 180169695Skanenum cpp_token_fld_kind { 181169695Skan CPP_TOKEN_FLD_NODE, 182169695Skan CPP_TOKEN_FLD_SOURCE, 183169695Skan CPP_TOKEN_FLD_STR, 184169695Skan CPP_TOKEN_FLD_ARG_NO, 185169695Skan CPP_TOKEN_FLD_PRAGMA, 186169695Skan CPP_TOKEN_FLD_NONE 187169695Skan}; 188169695Skan 189169695Skan/* A preprocessing token. This has been carefully packed and should 190169695Skan occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */ 191169695Skanstruct cpp_token GTY(()) 192169695Skan{ 193169695Skan source_location src_loc; /* Location of first char of token. */ 194169695Skan ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */ 195169695Skan unsigned char flags; /* flags - see above */ 196169695Skan 197169695Skan union cpp_token_u 198169695Skan { 199169695Skan /* An identifier. */ 200169695Skan cpp_hashnode * 201169695Skan GTY ((nested_ptr (union tree_node, 202169695Skan "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", 203169695Skan "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), 204169695Skan tag ("CPP_TOKEN_FLD_NODE"))) 205169695Skan node; 206169695Skan 207169695Skan /* Inherit padding from this token. */ 208169695Skan cpp_token * GTY ((tag ("CPP_TOKEN_FLD_SOURCE"))) source; 209169695Skan 210169695Skan /* A string, or number. */ 211169695Skan struct cpp_string GTY ((tag ("CPP_TOKEN_FLD_STR"))) str; 212169695Skan 213169695Skan /* Argument no. for a CPP_MACRO_ARG. */ 214169695Skan unsigned int GTY ((tag ("CPP_TOKEN_FLD_ARG_NO"))) arg_no; 215169695Skan 216169695Skan /* Caller-supplied identifier for a CPP_PRAGMA. */ 217169695Skan unsigned int GTY ((tag ("CPP_TOKEN_FLD_PRAGMA"))) pragma; 218169695Skan } GTY ((desc ("cpp_token_val_index (&%1)"))) val; 219169695Skan}; 220169695Skan 221169695Skan/* Say which field is in use. */ 222169695Skanextern enum cpp_token_fld_kind cpp_token_val_index (cpp_token *tok); 223169695Skan 224169695Skan/* A type wide enough to hold any multibyte source character. 225169695Skan cpplib's character constant interpreter requires an unsigned type. 226169695Skan Also, a typedef for the signed equivalent. 227169695Skan The width of this type is capped at 32 bits; there do exist targets 228169695Skan where wchar_t is 64 bits, but only in a non-default mode, and there 229169695Skan would be no meaningful interpretation for a wchar_t value greater 230169695Skan than 2^32 anyway -- the widest wide-character encoding around is 231169695Skan ISO 10646, which stops at 2^31. */ 232169695Skan#if CHAR_BIT * SIZEOF_INT >= 32 233169695Skan# define CPPCHAR_SIGNED_T int 234169695Skan#elif CHAR_BIT * SIZEOF_LONG >= 32 235169695Skan# define CPPCHAR_SIGNED_T long 236169695Skan#else 237169695Skan# error "Cannot find a least-32-bit signed integer type" 238169695Skan#endif 239169695Skantypedef unsigned CPPCHAR_SIGNED_T cppchar_t; 240169695Skantypedef CPPCHAR_SIGNED_T cppchar_signed_t; 241169695Skan 242169695Skan/* Style of header dependencies to generate. */ 243169695Skanenum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM }; 244169695Skan 245169695Skan/* The possible normalization levels, from most restrictive to least. */ 246169695Skanenum cpp_normalize_level { 247169695Skan /* In NFKC. */ 248169695Skan normalized_KC = 0, 249169695Skan /* In NFC. */ 250169695Skan normalized_C, 251169695Skan /* In NFC, except for subsequences where being in NFC would make 252169695Skan the identifier invalid. */ 253169695Skan normalized_identifier_C, 254169695Skan /* Not normalized at all. */ 255169695Skan normalized_none 256169695Skan}; 257169695Skan 258169695Skan/* This structure is nested inside struct cpp_reader, and 259169695Skan carries all the options visible to the command line. */ 260169695Skanstruct cpp_options 261169695Skan{ 262169695Skan /* Characters between tab stops. */ 263169695Skan unsigned int tabstop; 264169695Skan 265169695Skan /* The language we're preprocessing. */ 266169695Skan enum c_lang lang; 267169695Skan 268169695Skan /* Nonzero means use extra default include directories for C++. */ 269169695Skan unsigned char cplusplus; 270169695Skan 271169695Skan /* Nonzero means handle cplusplus style comments. */ 272169695Skan unsigned char cplusplus_comments; 273169695Skan 274169695Skan /* Nonzero means define __OBJC__, treat @ as a special token, and 275169695Skan use the OBJC[PLUS]_INCLUDE_PATH environment variable. */ 276169695Skan unsigned char objc; 277169695Skan 278169695Skan /* Nonzero means don't copy comments into the output file. */ 279169695Skan unsigned char discard_comments; 280169695Skan 281169695Skan /* Nonzero means don't copy comments into the output file during 282169695Skan macro expansion. */ 283169695Skan unsigned char discard_comments_in_macro_exp; 284169695Skan 285169695Skan /* Nonzero means process the ISO trigraph sequences. */ 286169695Skan unsigned char trigraphs; 287169695Skan 288169695Skan /* Nonzero means process the ISO digraph sequences. */ 289169695Skan unsigned char digraphs; 290169695Skan 291169695Skan /* Nonzero means to allow hexadecimal floats and LL suffixes. */ 292169695Skan unsigned char extended_numbers; 293169695Skan 294169695Skan /* Nonzero means print names of header files (-H). */ 295169695Skan unsigned char print_include_names; 296169695Skan 297169695Skan /* Nonzero means cpp_pedwarn causes a hard error. */ 298169695Skan unsigned char pedantic_errors; 299169695Skan 300169695Skan /* Nonzero means don't print warning messages. */ 301169695Skan unsigned char inhibit_warnings; 302169695Skan 303169695Skan /* Nonzero means complain about deprecated features. */ 304169695Skan unsigned char warn_deprecated; 305169695Skan 306169695Skan /* Nonzero means don't suppress warnings from system headers. */ 307169695Skan unsigned char warn_system_headers; 308169695Skan 309169695Skan /* Nonzero means don't print error messages. Has no option to 310169695Skan select it, but can be set by a user of cpplib (e.g. fix-header). */ 311169695Skan unsigned char inhibit_errors; 312169695Skan 313169695Skan /* Nonzero means warn if slash-star appears in a comment. */ 314169695Skan unsigned char warn_comments; 315169695Skan 316169695Skan /* Nonzero means warn if a user-supplied include directory does not 317169695Skan exist. */ 318169695Skan unsigned char warn_missing_include_dirs; 319169695Skan 320169695Skan /* Nonzero means warn if there are any trigraphs. */ 321169695Skan unsigned char warn_trigraphs; 322169695Skan 323259890Spfg /* APPLE LOCAL begin -Wnewline-eof 2001-08-23 --sts */ 324259890Spfg /* Nonzero means warn if no newline at end of file. */ 325259890Spfg unsigned char warn_newline_at_eof; 326259890Spfg /* APPLE LOCAL end -Wnewline-eof 2001-08-23 --sts */ 327259890Spfg 328169695Skan /* Nonzero means warn about multicharacter charconsts. */ 329169695Skan unsigned char warn_multichar; 330169695Skan 331169695Skan /* Nonzero means warn about various incompatibilities with 332169695Skan traditional C. */ 333169695Skan unsigned char warn_traditional; 334169695Skan 335169695Skan /* Nonzero means warn about long long numeric constants. */ 336169695Skan unsigned char warn_long_long; 337169695Skan 338169695Skan /* Nonzero means warn about text after an #endif (or #else). */ 339169695Skan unsigned char warn_endif_labels; 340169695Skan 341169695Skan /* Nonzero means warn about implicit sign changes owing to integer 342169695Skan promotions. */ 343169695Skan unsigned char warn_num_sign_change; 344169695Skan 345169695Skan /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode. 346169695Skan Presumably the usage is protected by the appropriate #ifdef. */ 347169695Skan unsigned char warn_variadic_macros; 348169695Skan 349169695Skan /* Nonzero means turn warnings into errors. */ 350169695Skan unsigned char warnings_are_errors; 351169695Skan 352169695Skan /* Nonzero means we should look for header.gcc files that remap file 353169695Skan names. */ 354169695Skan unsigned char remap; 355169695Skan 356169695Skan /* Zero means dollar signs are punctuation. */ 357169695Skan unsigned char dollars_in_ident; 358169695Skan 359169695Skan /* Nonzero means UCNs are accepted in identifiers. */ 360169695Skan unsigned char extended_identifiers; 361169695Skan 362169695Skan /* True if we should warn about dollars in identifiers or numbers 363169695Skan for this translation unit. */ 364169695Skan unsigned char warn_dollars; 365169695Skan 366169695Skan /* Nonzero means warn if undefined identifiers are evaluated in an #if. */ 367169695Skan unsigned char warn_undef; 368169695Skan 369169695Skan /* Nonzero means warn of unused macros from the main file. */ 370169695Skan unsigned char warn_unused_macros; 371169695Skan 372169695Skan /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */ 373169695Skan unsigned char c99; 374169695Skan 375169695Skan /* Nonzero if we are conforming to a specific C or C++ standard. */ 376169695Skan unsigned char std; 377169695Skan 378169695Skan /* Nonzero means give all the error messages the ANSI standard requires. */ 379169695Skan unsigned char pedantic; 380169695Skan 381169695Skan /* Nonzero means we're looking at already preprocessed code, so don't 382169695Skan bother trying to do macro expansion and whatnot. */ 383169695Skan unsigned char preprocessed; 384169695Skan 385169695Skan /* Print column number in error messages. */ 386169695Skan unsigned char show_column; 387169695Skan 388169695Skan /* Nonzero means handle C++ alternate operator names. */ 389169695Skan unsigned char operator_names; 390169695Skan 391169695Skan /* True for traditional preprocessing. */ 392169695Skan unsigned char traditional; 393169695Skan 394169695Skan /* Holds the name of the target (execution) character set. */ 395169695Skan const char *narrow_charset; 396169695Skan 397169695Skan /* Holds the name of the target wide character set. */ 398169695Skan const char *wide_charset; 399169695Skan 400169695Skan /* Holds the name of the input character set. */ 401169695Skan const char *input_charset; 402169695Skan 403169695Skan /* The minimum permitted level of normalization before a warning 404169695Skan is generated. */ 405169695Skan enum cpp_normalize_level warn_normalize; 406169695Skan 407169695Skan /* True to warn about precompiled header files we couldn't use. */ 408169695Skan bool warn_invalid_pch; 409169695Skan 410169695Skan /* True if dependencies should be restored from a precompiled header. */ 411169695Skan bool restore_pch_deps; 412169695Skan 413169695Skan /* Dependency generation. */ 414169695Skan struct 415169695Skan { 416169695Skan /* Style of header dependencies to generate. */ 417169695Skan enum cpp_deps_style style; 418169695Skan 419169695Skan /* Assume missing files are generated files. */ 420169695Skan bool missing_files; 421169695Skan 422169695Skan /* Generate phony targets for each dependency apart from the first 423169695Skan one. */ 424169695Skan bool phony_targets; 425169695Skan 426169695Skan /* If true, no dependency is generated on the main file. */ 427169695Skan bool ignore_main_file; 428169695Skan } deps; 429169695Skan 430169695Skan /* Target-specific features set by the front end or client. */ 431169695Skan 432169695Skan /* Precision for target CPP arithmetic, target characters, target 433169695Skan ints and target wide characters, respectively. */ 434169695Skan size_t precision, char_precision, int_precision, wchar_precision; 435169695Skan 436169695Skan /* True means chars (wide chars) are unsigned. */ 437169695Skan bool unsigned_char, unsigned_wchar; 438169695Skan 439169695Skan /* True if the most significant byte in a word has the lowest 440169695Skan address in memory. */ 441169695Skan bool bytes_big_endian; 442169695Skan 443169695Skan /* Nonzero means __STDC__ should have the value 0 in system headers. */ 444169695Skan unsigned char stdc_0_in_system_headers; 445169695Skan 446169695Skan /* True means error callback should be used for diagnostics. */ 447169695Skan bool client_diagnostic; 448259405Spfg 449259405Spfg /* True disables tokenization outside of preprocessing directives. */ 450259405Spfg bool directives_only; 451169695Skan}; 452169695Skan 453169695Skan/* Callback for header lookup for HEADER, which is the name of a 454169695Skan source file. It is used as a method of last resort to find headers 455169695Skan that are not otherwise found during the normal include processing. 456169695Skan The return value is the malloced name of a header to try and open, 457169695Skan if any, or NULL otherwise. This callback is called only if the 458169695Skan header is otherwise unfound. */ 459169695Skantypedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **); 460169695Skan 461169695Skan/* Call backs to cpplib client. */ 462169695Skanstruct cpp_callbacks 463169695Skan{ 464169695Skan /* Called when a new line of preprocessed output is started. */ 465169695Skan void (*line_change) (cpp_reader *, const cpp_token *, int); 466169695Skan 467169695Skan /* Called when switching to/from a new file. 468169695Skan The line_map is for the new file. It is NULL if there is no new file. 469169695Skan (In C this happens when done with <built-in>+<command line> and also 470169695Skan when done with a main file.) This can be used for resource cleanup. */ 471169695Skan void (*file_change) (cpp_reader *, const struct line_map *); 472169695Skan 473169695Skan void (*dir_change) (cpp_reader *, const char *); 474169695Skan void (*include) (cpp_reader *, unsigned int, const unsigned char *, 475169695Skan const char *, int, const cpp_token **); 476169695Skan void (*define) (cpp_reader *, unsigned int, cpp_hashnode *); 477169695Skan void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *); 478169695Skan void (*ident) (cpp_reader *, unsigned int, const cpp_string *); 479169695Skan void (*def_pragma) (cpp_reader *, unsigned int); 480169695Skan int (*valid_pch) (cpp_reader *, const char *, int); 481169695Skan void (*read_pch) (cpp_reader *, const char *, int, const char *); 482169695Skan missing_header_cb missing_header; 483169695Skan 484169695Skan /* Called to emit a diagnostic if client_diagnostic option is true. 485169695Skan This callback receives the translated message. */ 486169695Skan void (*error) (cpp_reader *, int, const char *, va_list *) 487169695Skan ATTRIBUTE_FPTR_PRINTF(3,0); 488169695Skan}; 489169695Skan 490169695Skan/* Chain of directories to look for include files in. */ 491169695Skanstruct cpp_dir 492169695Skan{ 493169695Skan /* NULL-terminated singly-linked list. */ 494169695Skan struct cpp_dir *next; 495169695Skan 496169695Skan /* NAME of the directory, NUL-terminated. */ 497169695Skan char *name; 498169695Skan unsigned int len; 499169695Skan 500169695Skan /* One if a system header, two if a system header that has extern 501169695Skan "C" guards for C++. */ 502169695Skan unsigned char sysp; 503169695Skan 504169695Skan /* Mapping of file names for this directory for MS-DOS and related 505169695Skan platforms. A NULL-terminated array of (from, to) pairs. */ 506169695Skan const char **name_map; 507169695Skan 508169695Skan /* Routine to construct pathname, given the search path name and the 509169695Skan HEADER we are trying to find, return a constructed pathname to 510169695Skan try and open. If this is NULL, the constructed pathname is as 511169695Skan constructed by append_file_to_dir. */ 512169695Skan char *(*construct) (const char *header, cpp_dir *dir); 513169695Skan 514169695Skan /* The C front end uses these to recognize duplicated 515169695Skan directories in the search path. */ 516169695Skan ino_t ino; 517169695Skan dev_t dev; 518169695Skan 519169695Skan /* Is this a user-supplied directory? */ 520169695Skan bool user_supplied_p; 521169695Skan}; 522169695Skan 523169695Skan/* Name under which this program was invoked. */ 524169695Skanextern const char *progname; 525169695Skan 526169695Skan/* The structure of a node in the hash table. The hash table has 527169695Skan entries for all identifiers: either macros defined by #define 528169695Skan commands (type NT_MACRO), assertions created with #assert 529169695Skan (NT_ASSERTION), or neither of the above (NT_VOID). Builtin macros 530169695Skan like __LINE__ are flagged NODE_BUILTIN. Poisoned identifiers are 531169695Skan flagged NODE_POISONED. NODE_OPERATOR (C++ only) indicates an 532169695Skan identifier that behaves like an operator such as "xor". 533169695Skan NODE_DIAGNOSTIC is for speed in lex_token: it indicates a 534169695Skan diagnostic may be required for this node. Currently this only 535169695Skan applies to __VA_ARGS__ and poisoned identifiers. */ 536169695Skan 537169695Skan/* Hash node flags. */ 538169695Skan#define NODE_OPERATOR (1 << 0) /* C++ named operator. */ 539169695Skan#define NODE_POISONED (1 << 1) /* Poisoned identifier. */ 540169695Skan#define NODE_BUILTIN (1 << 2) /* Builtin macro. */ 541169695Skan#define NODE_DIAGNOSTIC (1 << 3) /* Possible diagnostic when lexed. */ 542169695Skan#define NODE_WARN (1 << 4) /* Warn if redefined or undefined. */ 543169695Skan#define NODE_DISABLED (1 << 5) /* A disabled macro. */ 544169695Skan#define NODE_MACRO_ARG (1 << 6) /* Used during #define processing. */ 545169695Skan 546169695Skan/* Different flavors of hash node. */ 547169695Skanenum node_type 548169695Skan{ 549169695Skan NT_VOID = 0, /* No definition yet. */ 550169695Skan NT_MACRO, /* A macro of some form. */ 551169695Skan NT_ASSERTION /* Predicate for #assert. */ 552169695Skan}; 553169695Skan 554169695Skan/* Different flavors of builtin macro. _Pragma is an operator, but we 555169695Skan handle it with the builtin code for efficiency reasons. */ 556169695Skanenum builtin_type 557169695Skan{ 558169695Skan BT_SPECLINE = 0, /* `__LINE__' */ 559169695Skan BT_DATE, /* `__DATE__' */ 560169695Skan BT_FILE, /* `__FILE__' */ 561169695Skan BT_BASE_FILE, /* `__BASE_FILE__' */ 562169695Skan BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ 563169695Skan BT_TIME, /* `__TIME__' */ 564169695Skan BT_STDC, /* `__STDC__' */ 565169695Skan BT_PRAGMA, /* `_Pragma' operator */ 566228474Sed BT_TIMESTAMP, /* `__TIMESTAMP__' */ 567228474Sed BT_COUNTER /* `__COUNTER__' */ 568169695Skan}; 569169695Skan 570169695Skan#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) 571169695Skan#define HT_NODE(NODE) ((ht_identifier *) (NODE)) 572169695Skan#define NODE_LEN(NODE) HT_LEN (&(NODE)->ident) 573169695Skan#define NODE_NAME(NODE) HT_STR (&(NODE)->ident) 574169695Skan 575169695Skan/* Specify which field, if any, of the union is used. */ 576169695Skan 577169695Skanenum { 578169695Skan NTV_MACRO, 579169695Skan NTV_ANSWER, 580169695Skan NTV_BUILTIN, 581169695Skan NTV_ARGUMENT, 582169695Skan NTV_NONE 583169695Skan}; 584169695Skan 585169695Skan#define CPP_HASHNODE_VALUE_IDX(HNODE) \ 586169695Skan ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT \ 587169695Skan : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN) \ 588169695Skan ? NTV_BUILTIN : NTV_MACRO) \ 589169695Skan : HNODE.type == NT_ASSERTION ? NTV_ANSWER \ 590169695Skan : NTV_NONE) 591169695Skan 592169695Skan/* The common part of an identifier node shared amongst all 3 C front 593169695Skan ends. Also used to store CPP identifiers, which are a superset of 594169695Skan identifiers in the grammatical sense. */ 595169695Skan 596169695Skanunion _cpp_hashnode_value GTY(()) 597169695Skan{ 598169695Skan /* If a macro. */ 599169695Skan cpp_macro * GTY((tag ("NTV_MACRO"))) macro; 600169695Skan /* Answers to an assertion. */ 601169695Skan struct answer * GTY ((tag ("NTV_ANSWER"))) answers; 602169695Skan /* Code for a builtin macro. */ 603169695Skan enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin; 604169695Skan /* Macro argument index. */ 605169695Skan unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index; 606169695Skan}; 607169695Skan 608169695Skanstruct cpp_hashnode GTY(()) 609169695Skan{ 610169695Skan struct ht_identifier ident; 611169695Skan unsigned int is_directive : 1; 612169695Skan unsigned int directive_index : 7; /* If is_directive, 613169695Skan then index into directive table. 614169695Skan Otherwise, a NODE_OPERATOR. */ 615169695Skan unsigned char rid_code; /* Rid code - for front ends. */ 616169695Skan ENUM_BITFIELD(node_type) type : 8; /* CPP node type. */ 617169695Skan unsigned char flags; /* CPP flags. */ 618169695Skan 619169695Skan union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value; 620169695Skan}; 621169695Skan 622169695Skan/* Call this first to get a handle to pass to other functions. 623169695Skan 624169695Skan If you want cpplib to manage its own hashtable, pass in a NULL 625169695Skan pointer. Otherwise you should pass in an initialized hash table 626169695Skan that cpplib will share; this technique is used by the C front 627169695Skan ends. */ 628169695Skanextern cpp_reader *cpp_create_reader (enum c_lang, struct ht *, 629169695Skan struct line_maps *); 630169695Skan 631169695Skan/* Call this to change the selected language standard (e.g. because of 632169695Skan command line options). */ 633169695Skanextern void cpp_set_lang (cpp_reader *, enum c_lang); 634169695Skan 635169695Skan/* Set the include paths. */ 636169695Skanextern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); 637169695Skan 638169695Skan/* Call these to get pointers to the options, callback, and deps 639169695Skan structures for a given reader. These pointers are good until you 640169695Skan call cpp_finish on that reader. You can either edit the callbacks 641169695Skan through the pointer returned from cpp_get_callbacks, or set them 642169695Skan with cpp_set_callbacks. */ 643169695Skanextern cpp_options *cpp_get_options (cpp_reader *); 644169695Skanextern cpp_callbacks *cpp_get_callbacks (cpp_reader *); 645169695Skanextern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *); 646169695Skanextern struct deps *cpp_get_deps (cpp_reader *); 647169695Skan 648169695Skan/* This function reads the file, but does not start preprocessing. It 649169695Skan returns the name of the original file; this is the same as the 650169695Skan input file, except for preprocessed input. This will generate at 651169695Skan least one file change callback, and possibly a line change callback 652169695Skan too. If there was an error opening the file, it returns NULL. */ 653169695Skanextern const char *cpp_read_main_file (cpp_reader *, const char *); 654169695Skan 655259405Spfg/* Set up built-ins with special behavior. Use cpp_init_builtins() 656259405Spfg instead unless your know what you are doing. */ 657259405Spfgextern void cpp_init_special_builtins (cpp_reader *); 658259405Spfg 659169695Skan/* Set up built-ins like __FILE__. */ 660169695Skanextern void cpp_init_builtins (cpp_reader *, int); 661169695Skan 662169695Skan/* This is called after options have been parsed, and partially 663169695Skan processed. */ 664169695Skanextern void cpp_post_options (cpp_reader *); 665169695Skan 666169695Skan/* Set up translation to the target character set. */ 667169695Skanextern void cpp_init_iconv (cpp_reader *); 668169695Skan 669169695Skan/* Call this to finish preprocessing. If you requested dependency 670169695Skan generation, pass an open stream to write the information to, 671169695Skan otherwise NULL. It is your responsibility to close the stream. 672169695Skan 673169695Skan Returns cpp_errors (pfile). */ 674169695Skanextern int cpp_finish (cpp_reader *, FILE *deps_stream); 675169695Skan 676169695Skan/* Call this to release the handle at the end of preprocessing. Any 677169695Skan use of the handle after this function returns is invalid. Returns 678169695Skan cpp_errors (pfile). */ 679169695Skanextern void cpp_destroy (cpp_reader *); 680169695Skan 681169695Skan/* Error count. */ 682169695Skanextern unsigned int cpp_errors (cpp_reader *); 683169695Skan 684169695Skanextern unsigned int cpp_token_len (const cpp_token *); 685169695Skanextern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *); 686169695Skanextern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *, 687169695Skan unsigned char *, bool); 688169695Skanextern void cpp_register_pragma (cpp_reader *, const char *, const char *, 689169695Skan void (*) (cpp_reader *), bool); 690169695Skanextern void cpp_register_deferred_pragma (cpp_reader *, const char *, 691169695Skan const char *, unsigned, bool, bool); 692169695Skanextern int cpp_avoid_paste (cpp_reader *, const cpp_token *, 693169695Skan const cpp_token *); 694169695Skanextern const cpp_token *cpp_get_token (cpp_reader *); 695169695Skanextern const unsigned char *cpp_macro_definition (cpp_reader *, 696169695Skan const cpp_hashnode *); 697169695Skanextern void _cpp_backup_tokens (cpp_reader *, unsigned int); 698169695Skan 699169695Skan/* Evaluate a CPP_CHAR or CPP_WCHAR token. */ 700169695Skanextern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *, 701169695Skan unsigned int *, int *); 702169695Skan/* Evaluate a vector of CPP_STRING or CPP_WSTRING tokens. */ 703169695Skanextern bool cpp_interpret_string (cpp_reader *, 704169695Skan const cpp_string *, size_t, 705169695Skan cpp_string *, bool); 706169695Skanextern bool cpp_interpret_string_notranslate (cpp_reader *, 707169695Skan const cpp_string *, size_t, 708169695Skan cpp_string *, bool); 709169695Skan 710169695Skan/* Convert a host character constant to the execution character set. */ 711169695Skanextern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); 712169695Skan 713169695Skan/* Used to register macros and assertions, perhaps from the command line. 714169695Skan The text is the same as the command line argument. */ 715169695Skanextern void cpp_define (cpp_reader *, const char *); 716169695Skanextern void cpp_assert (cpp_reader *, const char *); 717169695Skanextern void cpp_undef (cpp_reader *, const char *); 718169695Skanextern void cpp_unassert (cpp_reader *, const char *); 719169695Skan 720169695Skan/* Undefine all macros and assertions. */ 721169695Skanextern void cpp_undef_all (cpp_reader *); 722169695Skan 723169695Skanextern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *, 724169695Skan size_t, int); 725169695Skanextern int cpp_defined (cpp_reader *, const unsigned char *, int); 726169695Skan 727169695Skan/* A preprocessing number. Code assumes that any unused high bits of 728169695Skan the double integer are set to zero. */ 729169695Skantypedef unsigned HOST_WIDE_INT cpp_num_part; 730169695Skantypedef struct cpp_num cpp_num; 731169695Skanstruct cpp_num 732169695Skan{ 733169695Skan cpp_num_part high; 734169695Skan cpp_num_part low; 735169695Skan bool unsignedp; /* True if value should be treated as unsigned. */ 736169695Skan bool overflow; /* True if the most recent calculation overflowed. */ 737169695Skan}; 738169695Skan 739169695Skan/* cpplib provides two interfaces for interpretation of preprocessing 740169695Skan numbers. 741169695Skan 742169695Skan cpp_classify_number categorizes numeric constants according to 743169695Skan their field (integer, floating point, or invalid), radix (decimal, 744169695Skan octal, hexadecimal), and type suffixes. */ 745169695Skan 746169695Skan#define CPP_N_CATEGORY 0x000F 747169695Skan#define CPP_N_INVALID 0x0000 748169695Skan#define CPP_N_INTEGER 0x0001 749169695Skan#define CPP_N_FLOATING 0x0002 750169695Skan 751169695Skan#define CPP_N_WIDTH 0x00F0 752169695Skan#define CPP_N_SMALL 0x0010 /* int, float. */ 753169695Skan#define CPP_N_MEDIUM 0x0020 /* long, double. */ 754169695Skan#define CPP_N_LARGE 0x0040 /* long long, long double. */ 755169695Skan 756169695Skan#define CPP_N_RADIX 0x0F00 757169695Skan#define CPP_N_DECIMAL 0x0100 758169695Skan#define CPP_N_HEX 0x0200 759169695Skan#define CPP_N_OCTAL 0x0400 760255107Spfg#define CPP_N_BINARY 0x0800 761169695Skan 762169695Skan#define CPP_N_UNSIGNED 0x1000 /* Properties. */ 763169695Skan#define CPP_N_IMAGINARY 0x2000 764169695Skan#define CPP_N_DFLOAT 0x4000 765250566Spfg#define CPP_N_DEFAULT 0x8000 766169695Skan 767169695Skan/* Classify a CPP_NUMBER token. The return value is a combination of 768169695Skan the flags from the above sets. */ 769169695Skanextern unsigned cpp_classify_number (cpp_reader *, const cpp_token *); 770169695Skan 771169695Skan/* Evaluate a token classified as category CPP_N_INTEGER. */ 772169695Skanextern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *, 773169695Skan unsigned int type); 774169695Skan 775169695Skan/* Sign extend a number, with PRECISION significant bits and all 776169695Skan others assumed clear, to fill out a cpp_num structure. */ 777169695Skancpp_num cpp_num_sign_extend (cpp_num, size_t); 778169695Skan 779169695Skan/* Diagnostic levels. To get a diagnostic without associating a 780169695Skan position in the translation unit with it, use cpp_error_with_line 781169695Skan with a line number of zero. */ 782169695Skan 783169695Skan/* Warning, an error with -Werror. */ 784169695Skan#define CPP_DL_WARNING 0x00 785169695Skan/* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */ 786169695Skan#define CPP_DL_WARNING_SYSHDR 0x01 787169695Skan/* Warning, an error with -pedantic-errors or -Werror. */ 788169695Skan#define CPP_DL_PEDWARN 0x02 789169695Skan/* An error. */ 790169695Skan#define CPP_DL_ERROR 0x03 791169695Skan/* An internal consistency check failed. Prints "internal error: ", 792169695Skan otherwise the same as CPP_DL_ERROR. */ 793169695Skan#define CPP_DL_ICE 0x04 794169695Skan/* Extracts a diagnostic level from an int. */ 795169695Skan#define CPP_DL_EXTRACT(l) (l & 0xf) 796169695Skan/* Nonzero if a diagnostic level is one of the warnings. */ 797169695Skan#define CPP_DL_WARNING_P(l) (CPP_DL_EXTRACT (l) >= CPP_DL_WARNING \ 798169695Skan && CPP_DL_EXTRACT (l) <= CPP_DL_PEDWARN) 799169695Skan 800169695Skan/* Output a diagnostic of some kind. */ 801169695Skanextern void cpp_error (cpp_reader *, int, const char *msgid, ...) 802169695Skan ATTRIBUTE_PRINTF_3; 803169695Skan 804169695Skan/* Output a diagnostic with "MSGID: " preceding the 805169695Skan error string of errno. No location is printed. */ 806169695Skanextern void cpp_errno (cpp_reader *, int, const char *msgid); 807169695Skan 808169695Skan/* Same as cpp_error, except additionally specifies a position as a 809169695Skan (translation unit) physical line and physical column. If the line is 810169695Skan zero, then no location is printed. */ 811169695Skanextern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned, 812169695Skan const char *msgid, ...) ATTRIBUTE_PRINTF_5; 813169695Skan 814169695Skan/* In cpplex.c */ 815169695Skanextern int cpp_ideq (const cpp_token *, const char *); 816169695Skanextern void cpp_output_line (cpp_reader *, FILE *); 817169695Skanextern void cpp_output_token (const cpp_token *, FILE *); 818169695Skanextern const char *cpp_type2name (enum cpp_ttype); 819169695Skan/* Returns the value of an escape sequence, truncated to the correct 820169695Skan target precision. PSTR points to the input pointer, which is just 821169695Skan after the backslash. LIMIT is how much text we have. WIDE is true 822169695Skan if the escape sequence is part of a wide character constant or 823169695Skan string literal. Handles all relevant diagnostics. */ 824169695Skanextern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr, 825169695Skan const unsigned char *limit, int wide); 826169695Skan 827169695Skan/* In cpphash.c */ 828169695Skan 829169695Skan/* Lookup an identifier in the hashtable. Puts the identifier in the 830169695Skan table if it is not already there. */ 831169695Skanextern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *, 832169695Skan unsigned int); 833169695Skan 834169695Skantypedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *); 835169695Skanextern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *); 836169695Skan 837169695Skan/* In cppmacro.c */ 838169695Skanextern void cpp_scan_nooutput (cpp_reader *); 839169695Skanextern int cpp_sys_macro_p (cpp_reader *); 840169695Skanextern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, 841169695Skan unsigned int); 842169695Skan 843169695Skan/* In cppfiles.c */ 844169695Skanextern bool cpp_included (cpp_reader *, const char *); 845169695Skanextern void cpp_make_system_header (cpp_reader *, int, int); 846169695Skanextern bool cpp_push_include (cpp_reader *, const char *); 847169695Skanextern void cpp_change_file (cpp_reader *, enum lc_reason, const char *); 848169695Skanextern const char *cpp_get_path (struct _cpp_file *); 849169695Skanextern cpp_dir *cpp_get_dir (struct _cpp_file *); 850169695Skanextern cpp_buffer *cpp_get_buffer (cpp_reader *); 851169695Skanextern struct _cpp_file *cpp_get_file (cpp_buffer *); 852169695Skanextern cpp_buffer *cpp_get_prev (cpp_buffer *); 853169695Skan 854169695Skan/* In cpppch.c */ 855169695Skanstruct save_macro_data; 856169695Skanextern int cpp_save_state (cpp_reader *, FILE *); 857169695Skanextern int cpp_write_pch_deps (cpp_reader *, FILE *); 858169695Skanextern int cpp_write_pch_state (cpp_reader *, FILE *); 859169695Skanextern int cpp_valid_state (cpp_reader *, const char *, int); 860169695Skanextern void cpp_prepare_state (cpp_reader *, struct save_macro_data **); 861169695Skanextern int cpp_read_state (cpp_reader *, const char *, FILE *, 862169695Skan struct save_macro_data *); 863169695Skan 864169695Skan#ifdef __cplusplus 865169695Skan} 866169695Skan#endif 867169695Skan 868169695Skan#endif /* ! LIBCPP_CPPLIB_H */ 869