cpplib.h revision 169695
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 323169695Skan /* Nonzero means warn about multicharacter charconsts. */ 324169695Skan unsigned char warn_multichar; 325169695Skan 326169695Skan /* Nonzero means warn about various incompatibilities with 327169695Skan traditional C. */ 328169695Skan unsigned char warn_traditional; 329169695Skan 330169695Skan /* Nonzero means warn about long long numeric constants. */ 331169695Skan unsigned char warn_long_long; 332169695Skan 333169695Skan /* Nonzero means warn about text after an #endif (or #else). */ 334169695Skan unsigned char warn_endif_labels; 335169695Skan 336169695Skan /* Nonzero means warn about implicit sign changes owing to integer 337169695Skan promotions. */ 338169695Skan unsigned char warn_num_sign_change; 339169695Skan 340169695Skan /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode. 341169695Skan Presumably the usage is protected by the appropriate #ifdef. */ 342169695Skan unsigned char warn_variadic_macros; 343169695Skan 344169695Skan /* Nonzero means turn warnings into errors. */ 345169695Skan unsigned char warnings_are_errors; 346169695Skan 347169695Skan /* Nonzero means we should look for header.gcc files that remap file 348169695Skan names. */ 349169695Skan unsigned char remap; 350169695Skan 351169695Skan /* Zero means dollar signs are punctuation. */ 352169695Skan unsigned char dollars_in_ident; 353169695Skan 354169695Skan /* Nonzero means UCNs are accepted in identifiers. */ 355169695Skan unsigned char extended_identifiers; 356169695Skan 357169695Skan /* True if we should warn about dollars in identifiers or numbers 358169695Skan for this translation unit. */ 359169695Skan unsigned char warn_dollars; 360169695Skan 361169695Skan /* Nonzero means warn if undefined identifiers are evaluated in an #if. */ 362169695Skan unsigned char warn_undef; 363169695Skan 364169695Skan /* Nonzero means warn of unused macros from the main file. */ 365169695Skan unsigned char warn_unused_macros; 366169695Skan 367169695Skan /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */ 368169695Skan unsigned char c99; 369169695Skan 370169695Skan /* Nonzero if we are conforming to a specific C or C++ standard. */ 371169695Skan unsigned char std; 372169695Skan 373169695Skan /* Nonzero means give all the error messages the ANSI standard requires. */ 374169695Skan unsigned char pedantic; 375169695Skan 376169695Skan /* Nonzero means we're looking at already preprocessed code, so don't 377169695Skan bother trying to do macro expansion and whatnot. */ 378169695Skan unsigned char preprocessed; 379169695Skan 380169695Skan /* Print column number in error messages. */ 381169695Skan unsigned char show_column; 382169695Skan 383169695Skan /* Nonzero means handle C++ alternate operator names. */ 384169695Skan unsigned char operator_names; 385169695Skan 386169695Skan /* True for traditional preprocessing. */ 387169695Skan unsigned char traditional; 388169695Skan 389169695Skan /* Holds the name of the target (execution) character set. */ 390169695Skan const char *narrow_charset; 391169695Skan 392169695Skan /* Holds the name of the target wide character set. */ 393169695Skan const char *wide_charset; 394169695Skan 395169695Skan /* Holds the name of the input character set. */ 396169695Skan const char *input_charset; 397169695Skan 398169695Skan /* The minimum permitted level of normalization before a warning 399169695Skan is generated. */ 400169695Skan enum cpp_normalize_level warn_normalize; 401169695Skan 402169695Skan /* True to warn about precompiled header files we couldn't use. */ 403169695Skan bool warn_invalid_pch; 404169695Skan 405169695Skan /* True if dependencies should be restored from a precompiled header. */ 406169695Skan bool restore_pch_deps; 407169695Skan 408169695Skan /* Dependency generation. */ 409169695Skan struct 410169695Skan { 411169695Skan /* Style of header dependencies to generate. */ 412169695Skan enum cpp_deps_style style; 413169695Skan 414169695Skan /* Assume missing files are generated files. */ 415169695Skan bool missing_files; 416169695Skan 417169695Skan /* Generate phony targets for each dependency apart from the first 418169695Skan one. */ 419169695Skan bool phony_targets; 420169695Skan 421169695Skan /* If true, no dependency is generated on the main file. */ 422169695Skan bool ignore_main_file; 423169695Skan } deps; 424169695Skan 425169695Skan /* Target-specific features set by the front end or client. */ 426169695Skan 427169695Skan /* Precision for target CPP arithmetic, target characters, target 428169695Skan ints and target wide characters, respectively. */ 429169695Skan size_t precision, char_precision, int_precision, wchar_precision; 430169695Skan 431169695Skan /* True means chars (wide chars) are unsigned. */ 432169695Skan bool unsigned_char, unsigned_wchar; 433169695Skan 434169695Skan /* True if the most significant byte in a word has the lowest 435169695Skan address in memory. */ 436169695Skan bool bytes_big_endian; 437169695Skan 438169695Skan /* Nonzero means __STDC__ should have the value 0 in system headers. */ 439169695Skan unsigned char stdc_0_in_system_headers; 440169695Skan 441169695Skan /* True means error callback should be used for diagnostics. */ 442169695Skan bool client_diagnostic; 443169695Skan}; 444169695Skan 445169695Skan/* Callback for header lookup for HEADER, which is the name of a 446169695Skan source file. It is used as a method of last resort to find headers 447169695Skan that are not otherwise found during the normal include processing. 448169695Skan The return value is the malloced name of a header to try and open, 449169695Skan if any, or NULL otherwise. This callback is called only if the 450169695Skan header is otherwise unfound. */ 451169695Skantypedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **); 452169695Skan 453169695Skan/* Call backs to cpplib client. */ 454169695Skanstruct cpp_callbacks 455169695Skan{ 456169695Skan /* Called when a new line of preprocessed output is started. */ 457169695Skan void (*line_change) (cpp_reader *, const cpp_token *, int); 458169695Skan 459169695Skan /* Called when switching to/from a new file. 460169695Skan The line_map is for the new file. It is NULL if there is no new file. 461169695Skan (In C this happens when done with <built-in>+<command line> and also 462169695Skan when done with a main file.) This can be used for resource cleanup. */ 463169695Skan void (*file_change) (cpp_reader *, const struct line_map *); 464169695Skan 465169695Skan void (*dir_change) (cpp_reader *, const char *); 466169695Skan void (*include) (cpp_reader *, unsigned int, const unsigned char *, 467169695Skan const char *, int, const cpp_token **); 468169695Skan void (*define) (cpp_reader *, unsigned int, cpp_hashnode *); 469169695Skan void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *); 470169695Skan void (*ident) (cpp_reader *, unsigned int, const cpp_string *); 471169695Skan void (*def_pragma) (cpp_reader *, unsigned int); 472169695Skan int (*valid_pch) (cpp_reader *, const char *, int); 473169695Skan void (*read_pch) (cpp_reader *, const char *, int, const char *); 474169695Skan missing_header_cb missing_header; 475169695Skan 476169695Skan /* Called to emit a diagnostic if client_diagnostic option is true. 477169695Skan This callback receives the translated message. */ 478169695Skan void (*error) (cpp_reader *, int, const char *, va_list *) 479169695Skan ATTRIBUTE_FPTR_PRINTF(3,0); 480169695Skan}; 481169695Skan 482169695Skan/* Chain of directories to look for include files in. */ 483169695Skanstruct cpp_dir 484169695Skan{ 485169695Skan /* NULL-terminated singly-linked list. */ 486169695Skan struct cpp_dir *next; 487169695Skan 488169695Skan /* NAME of the directory, NUL-terminated. */ 489169695Skan char *name; 490169695Skan unsigned int len; 491169695Skan 492169695Skan /* One if a system header, two if a system header that has extern 493169695Skan "C" guards for C++. */ 494169695Skan unsigned char sysp; 495169695Skan 496169695Skan /* Mapping of file names for this directory for MS-DOS and related 497169695Skan platforms. A NULL-terminated array of (from, to) pairs. */ 498169695Skan const char **name_map; 499169695Skan 500169695Skan /* Routine to construct pathname, given the search path name and the 501169695Skan HEADER we are trying to find, return a constructed pathname to 502169695Skan try and open. If this is NULL, the constructed pathname is as 503169695Skan constructed by append_file_to_dir. */ 504169695Skan char *(*construct) (const char *header, cpp_dir *dir); 505169695Skan 506169695Skan /* The C front end uses these to recognize duplicated 507169695Skan directories in the search path. */ 508169695Skan ino_t ino; 509169695Skan dev_t dev; 510169695Skan 511169695Skan /* Is this a user-supplied directory? */ 512169695Skan bool user_supplied_p; 513169695Skan}; 514169695Skan 515169695Skan/* Name under which this program was invoked. */ 516169695Skanextern const char *progname; 517169695Skan 518169695Skan/* The structure of a node in the hash table. The hash table has 519169695Skan entries for all identifiers: either macros defined by #define 520169695Skan commands (type NT_MACRO), assertions created with #assert 521169695Skan (NT_ASSERTION), or neither of the above (NT_VOID). Builtin macros 522169695Skan like __LINE__ are flagged NODE_BUILTIN. Poisoned identifiers are 523169695Skan flagged NODE_POISONED. NODE_OPERATOR (C++ only) indicates an 524169695Skan identifier that behaves like an operator such as "xor". 525169695Skan NODE_DIAGNOSTIC is for speed in lex_token: it indicates a 526169695Skan diagnostic may be required for this node. Currently this only 527169695Skan applies to __VA_ARGS__ and poisoned identifiers. */ 528169695Skan 529169695Skan/* Hash node flags. */ 530169695Skan#define NODE_OPERATOR (1 << 0) /* C++ named operator. */ 531169695Skan#define NODE_POISONED (1 << 1) /* Poisoned identifier. */ 532169695Skan#define NODE_BUILTIN (1 << 2) /* Builtin macro. */ 533169695Skan#define NODE_DIAGNOSTIC (1 << 3) /* Possible diagnostic when lexed. */ 534169695Skan#define NODE_WARN (1 << 4) /* Warn if redefined or undefined. */ 535169695Skan#define NODE_DISABLED (1 << 5) /* A disabled macro. */ 536169695Skan#define NODE_MACRO_ARG (1 << 6) /* Used during #define processing. */ 537169695Skan 538169695Skan/* Different flavors of hash node. */ 539169695Skanenum node_type 540169695Skan{ 541169695Skan NT_VOID = 0, /* No definition yet. */ 542169695Skan NT_MACRO, /* A macro of some form. */ 543169695Skan NT_ASSERTION /* Predicate for #assert. */ 544169695Skan}; 545169695Skan 546169695Skan/* Different flavors of builtin macro. _Pragma is an operator, but we 547169695Skan handle it with the builtin code for efficiency reasons. */ 548169695Skanenum builtin_type 549169695Skan{ 550169695Skan BT_SPECLINE = 0, /* `__LINE__' */ 551169695Skan BT_DATE, /* `__DATE__' */ 552169695Skan BT_FILE, /* `__FILE__' */ 553169695Skan BT_BASE_FILE, /* `__BASE_FILE__' */ 554169695Skan BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ 555169695Skan BT_TIME, /* `__TIME__' */ 556169695Skan BT_STDC, /* `__STDC__' */ 557169695Skan BT_PRAGMA, /* `_Pragma' operator */ 558169695Skan BT_TIMESTAMP /* `__TIMESTAMP__' */ 559169695Skan}; 560169695Skan 561169695Skan#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) 562169695Skan#define HT_NODE(NODE) ((ht_identifier *) (NODE)) 563169695Skan#define NODE_LEN(NODE) HT_LEN (&(NODE)->ident) 564169695Skan#define NODE_NAME(NODE) HT_STR (&(NODE)->ident) 565169695Skan 566169695Skan/* Specify which field, if any, of the union is used. */ 567169695Skan 568169695Skanenum { 569169695Skan NTV_MACRO, 570169695Skan NTV_ANSWER, 571169695Skan NTV_BUILTIN, 572169695Skan NTV_ARGUMENT, 573169695Skan NTV_NONE 574169695Skan}; 575169695Skan 576169695Skan#define CPP_HASHNODE_VALUE_IDX(HNODE) \ 577169695Skan ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT \ 578169695Skan : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN) \ 579169695Skan ? NTV_BUILTIN : NTV_MACRO) \ 580169695Skan : HNODE.type == NT_ASSERTION ? NTV_ANSWER \ 581169695Skan : NTV_NONE) 582169695Skan 583169695Skan/* The common part of an identifier node shared amongst all 3 C front 584169695Skan ends. Also used to store CPP identifiers, which are a superset of 585169695Skan identifiers in the grammatical sense. */ 586169695Skan 587169695Skanunion _cpp_hashnode_value GTY(()) 588169695Skan{ 589169695Skan /* If a macro. */ 590169695Skan cpp_macro * GTY((tag ("NTV_MACRO"))) macro; 591169695Skan /* Answers to an assertion. */ 592169695Skan struct answer * GTY ((tag ("NTV_ANSWER"))) answers; 593169695Skan /* Code for a builtin macro. */ 594169695Skan enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin; 595169695Skan /* Macro argument index. */ 596169695Skan unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index; 597169695Skan}; 598169695Skan 599169695Skanstruct cpp_hashnode GTY(()) 600169695Skan{ 601169695Skan struct ht_identifier ident; 602169695Skan unsigned int is_directive : 1; 603169695Skan unsigned int directive_index : 7; /* If is_directive, 604169695Skan then index into directive table. 605169695Skan Otherwise, a NODE_OPERATOR. */ 606169695Skan unsigned char rid_code; /* Rid code - for front ends. */ 607169695Skan ENUM_BITFIELD(node_type) type : 8; /* CPP node type. */ 608169695Skan unsigned char flags; /* CPP flags. */ 609169695Skan 610169695Skan union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value; 611169695Skan}; 612169695Skan 613169695Skan/* Call this first to get a handle to pass to other functions. 614169695Skan 615169695Skan If you want cpplib to manage its own hashtable, pass in a NULL 616169695Skan pointer. Otherwise you should pass in an initialized hash table 617169695Skan that cpplib will share; this technique is used by the C front 618169695Skan ends. */ 619169695Skanextern cpp_reader *cpp_create_reader (enum c_lang, struct ht *, 620169695Skan struct line_maps *); 621169695Skan 622169695Skan/* Call this to change the selected language standard (e.g. because of 623169695Skan command line options). */ 624169695Skanextern void cpp_set_lang (cpp_reader *, enum c_lang); 625169695Skan 626169695Skan/* Set the include paths. */ 627169695Skanextern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); 628169695Skan 629169695Skan/* Call these to get pointers to the options, callback, and deps 630169695Skan structures for a given reader. These pointers are good until you 631169695Skan call cpp_finish on that reader. You can either edit the callbacks 632169695Skan through the pointer returned from cpp_get_callbacks, or set them 633169695Skan with cpp_set_callbacks. */ 634169695Skanextern cpp_options *cpp_get_options (cpp_reader *); 635169695Skanextern cpp_callbacks *cpp_get_callbacks (cpp_reader *); 636169695Skanextern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *); 637169695Skanextern struct deps *cpp_get_deps (cpp_reader *); 638169695Skan 639169695Skan/* This function reads the file, but does not start preprocessing. It 640169695Skan returns the name of the original file; this is the same as the 641169695Skan input file, except for preprocessed input. This will generate at 642169695Skan least one file change callback, and possibly a line change callback 643169695Skan too. If there was an error opening the file, it returns NULL. */ 644169695Skanextern const char *cpp_read_main_file (cpp_reader *, const char *); 645169695Skan 646169695Skan/* Set up built-ins like __FILE__. */ 647169695Skanextern void cpp_init_builtins (cpp_reader *, int); 648169695Skan 649169695Skan/* This is called after options have been parsed, and partially 650169695Skan processed. */ 651169695Skanextern void cpp_post_options (cpp_reader *); 652169695Skan 653169695Skan/* Set up translation to the target character set. */ 654169695Skanextern void cpp_init_iconv (cpp_reader *); 655169695Skan 656169695Skan/* Call this to finish preprocessing. If you requested dependency 657169695Skan generation, pass an open stream to write the information to, 658169695Skan otherwise NULL. It is your responsibility to close the stream. 659169695Skan 660169695Skan Returns cpp_errors (pfile). */ 661169695Skanextern int cpp_finish (cpp_reader *, FILE *deps_stream); 662169695Skan 663169695Skan/* Call this to release the handle at the end of preprocessing. Any 664169695Skan use of the handle after this function returns is invalid. Returns 665169695Skan cpp_errors (pfile). */ 666169695Skanextern void cpp_destroy (cpp_reader *); 667169695Skan 668169695Skan/* Error count. */ 669169695Skanextern unsigned int cpp_errors (cpp_reader *); 670169695Skan 671169695Skanextern unsigned int cpp_token_len (const cpp_token *); 672169695Skanextern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *); 673169695Skanextern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *, 674169695Skan unsigned char *, bool); 675169695Skanextern void cpp_register_pragma (cpp_reader *, const char *, const char *, 676169695Skan void (*) (cpp_reader *), bool); 677169695Skanextern void cpp_register_deferred_pragma (cpp_reader *, const char *, 678169695Skan const char *, unsigned, bool, bool); 679169695Skanextern int cpp_avoid_paste (cpp_reader *, const cpp_token *, 680169695Skan const cpp_token *); 681169695Skanextern const cpp_token *cpp_get_token (cpp_reader *); 682169695Skanextern const unsigned char *cpp_macro_definition (cpp_reader *, 683169695Skan const cpp_hashnode *); 684169695Skanextern void _cpp_backup_tokens (cpp_reader *, unsigned int); 685169695Skan 686169695Skan/* Evaluate a CPP_CHAR or CPP_WCHAR token. */ 687169695Skanextern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *, 688169695Skan unsigned int *, int *); 689169695Skan/* Evaluate a vector of CPP_STRING or CPP_WSTRING tokens. */ 690169695Skanextern bool cpp_interpret_string (cpp_reader *, 691169695Skan const cpp_string *, size_t, 692169695Skan cpp_string *, bool); 693169695Skanextern bool cpp_interpret_string_notranslate (cpp_reader *, 694169695Skan const cpp_string *, size_t, 695169695Skan cpp_string *, bool); 696169695Skan 697169695Skan/* Convert a host character constant to the execution character set. */ 698169695Skanextern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); 699169695Skan 700169695Skan/* Used to register macros and assertions, perhaps from the command line. 701169695Skan The text is the same as the command line argument. */ 702169695Skanextern void cpp_define (cpp_reader *, const char *); 703169695Skanextern void cpp_assert (cpp_reader *, const char *); 704169695Skanextern void cpp_undef (cpp_reader *, const char *); 705169695Skanextern void cpp_unassert (cpp_reader *, const char *); 706169695Skan 707169695Skan/* Undefine all macros and assertions. */ 708169695Skanextern void cpp_undef_all (cpp_reader *); 709169695Skan 710169695Skanextern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *, 711169695Skan size_t, int); 712169695Skanextern int cpp_defined (cpp_reader *, const unsigned char *, int); 713169695Skan 714169695Skan/* A preprocessing number. Code assumes that any unused high bits of 715169695Skan the double integer are set to zero. */ 716169695Skantypedef unsigned HOST_WIDE_INT cpp_num_part; 717169695Skantypedef struct cpp_num cpp_num; 718169695Skanstruct cpp_num 719169695Skan{ 720169695Skan cpp_num_part high; 721169695Skan cpp_num_part low; 722169695Skan bool unsignedp; /* True if value should be treated as unsigned. */ 723169695Skan bool overflow; /* True if the most recent calculation overflowed. */ 724169695Skan}; 725169695Skan 726169695Skan/* cpplib provides two interfaces for interpretation of preprocessing 727169695Skan numbers. 728169695Skan 729169695Skan cpp_classify_number categorizes numeric constants according to 730169695Skan their field (integer, floating point, or invalid), radix (decimal, 731169695Skan octal, hexadecimal), and type suffixes. */ 732169695Skan 733169695Skan#define CPP_N_CATEGORY 0x000F 734169695Skan#define CPP_N_INVALID 0x0000 735169695Skan#define CPP_N_INTEGER 0x0001 736169695Skan#define CPP_N_FLOATING 0x0002 737169695Skan 738169695Skan#define CPP_N_WIDTH 0x00F0 739169695Skan#define CPP_N_SMALL 0x0010 /* int, float. */ 740169695Skan#define CPP_N_MEDIUM 0x0020 /* long, double. */ 741169695Skan#define CPP_N_LARGE 0x0040 /* long long, long double. */ 742169695Skan 743169695Skan#define CPP_N_RADIX 0x0F00 744169695Skan#define CPP_N_DECIMAL 0x0100 745169695Skan#define CPP_N_HEX 0x0200 746169695Skan#define CPP_N_OCTAL 0x0400 747169695Skan 748169695Skan#define CPP_N_UNSIGNED 0x1000 /* Properties. */ 749169695Skan#define CPP_N_IMAGINARY 0x2000 750169695Skan#define CPP_N_DFLOAT 0x4000 751169695Skan 752169695Skan/* Classify a CPP_NUMBER token. The return value is a combination of 753169695Skan the flags from the above sets. */ 754169695Skanextern unsigned cpp_classify_number (cpp_reader *, const cpp_token *); 755169695Skan 756169695Skan/* Evaluate a token classified as category CPP_N_INTEGER. */ 757169695Skanextern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *, 758169695Skan unsigned int type); 759169695Skan 760169695Skan/* Sign extend a number, with PRECISION significant bits and all 761169695Skan others assumed clear, to fill out a cpp_num structure. */ 762169695Skancpp_num cpp_num_sign_extend (cpp_num, size_t); 763169695Skan 764169695Skan/* Diagnostic levels. To get a diagnostic without associating a 765169695Skan position in the translation unit with it, use cpp_error_with_line 766169695Skan with a line number of zero. */ 767169695Skan 768169695Skan/* Warning, an error with -Werror. */ 769169695Skan#define CPP_DL_WARNING 0x00 770169695Skan/* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */ 771169695Skan#define CPP_DL_WARNING_SYSHDR 0x01 772169695Skan/* Warning, an error with -pedantic-errors or -Werror. */ 773169695Skan#define CPP_DL_PEDWARN 0x02 774169695Skan/* An error. */ 775169695Skan#define CPP_DL_ERROR 0x03 776169695Skan/* An internal consistency check failed. Prints "internal error: ", 777169695Skan otherwise the same as CPP_DL_ERROR. */ 778169695Skan#define CPP_DL_ICE 0x04 779169695Skan/* Extracts a diagnostic level from an int. */ 780169695Skan#define CPP_DL_EXTRACT(l) (l & 0xf) 781169695Skan/* Nonzero if a diagnostic level is one of the warnings. */ 782169695Skan#define CPP_DL_WARNING_P(l) (CPP_DL_EXTRACT (l) >= CPP_DL_WARNING \ 783169695Skan && CPP_DL_EXTRACT (l) <= CPP_DL_PEDWARN) 784169695Skan 785169695Skan/* Output a diagnostic of some kind. */ 786169695Skanextern void cpp_error (cpp_reader *, int, const char *msgid, ...) 787169695Skan ATTRIBUTE_PRINTF_3; 788169695Skan 789169695Skan/* Output a diagnostic with "MSGID: " preceding the 790169695Skan error string of errno. No location is printed. */ 791169695Skanextern void cpp_errno (cpp_reader *, int, const char *msgid); 792169695Skan 793169695Skan/* Same as cpp_error, except additionally specifies a position as a 794169695Skan (translation unit) physical line and physical column. If the line is 795169695Skan zero, then no location is printed. */ 796169695Skanextern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned, 797169695Skan const char *msgid, ...) ATTRIBUTE_PRINTF_5; 798169695Skan 799169695Skan/* In cpplex.c */ 800169695Skanextern int cpp_ideq (const cpp_token *, const char *); 801169695Skanextern void cpp_output_line (cpp_reader *, FILE *); 802169695Skanextern void cpp_output_token (const cpp_token *, FILE *); 803169695Skanextern const char *cpp_type2name (enum cpp_ttype); 804169695Skan/* Returns the value of an escape sequence, truncated to the correct 805169695Skan target precision. PSTR points to the input pointer, which is just 806169695Skan after the backslash. LIMIT is how much text we have. WIDE is true 807169695Skan if the escape sequence is part of a wide character constant or 808169695Skan string literal. Handles all relevant diagnostics. */ 809169695Skanextern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr, 810169695Skan const unsigned char *limit, int wide); 811169695Skan 812169695Skan/* In cpphash.c */ 813169695Skan 814169695Skan/* Lookup an identifier in the hashtable. Puts the identifier in the 815169695Skan table if it is not already there. */ 816169695Skanextern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *, 817169695Skan unsigned int); 818169695Skan 819169695Skantypedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *); 820169695Skanextern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *); 821169695Skan 822169695Skan/* In cppmacro.c */ 823169695Skanextern void cpp_scan_nooutput (cpp_reader *); 824169695Skanextern int cpp_sys_macro_p (cpp_reader *); 825169695Skanextern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, 826169695Skan unsigned int); 827169695Skan 828169695Skan/* In cppfiles.c */ 829169695Skanextern bool cpp_included (cpp_reader *, const char *); 830169695Skanextern void cpp_make_system_header (cpp_reader *, int, int); 831169695Skanextern bool cpp_push_include (cpp_reader *, const char *); 832169695Skanextern void cpp_change_file (cpp_reader *, enum lc_reason, const char *); 833169695Skanextern const char *cpp_get_path (struct _cpp_file *); 834169695Skanextern cpp_dir *cpp_get_dir (struct _cpp_file *); 835169695Skanextern cpp_buffer *cpp_get_buffer (cpp_reader *); 836169695Skanextern struct _cpp_file *cpp_get_file (cpp_buffer *); 837169695Skanextern cpp_buffer *cpp_get_prev (cpp_buffer *); 838169695Skan 839169695Skan/* In cpppch.c */ 840169695Skanstruct save_macro_data; 841169695Skanextern int cpp_save_state (cpp_reader *, FILE *); 842169695Skanextern int cpp_write_pch_deps (cpp_reader *, FILE *); 843169695Skanextern int cpp_write_pch_state (cpp_reader *, FILE *); 844169695Skanextern int cpp_valid_state (cpp_reader *, const char *, int); 845169695Skanextern void cpp_prepare_state (cpp_reader *, struct save_macro_data **); 846169695Skanextern int cpp_read_state (cpp_reader *, const char *, FILE *, 847169695Skan struct save_macro_data *); 848169695Skan 849169695Skan#ifdef __cplusplus 850169695Skan} 851169695Skan#endif 852169695Skan 853169695Skan#endif /* ! LIBCPP_CPPLIB_H */ 854