1*c7ca977eSAlexander Kabaev /* Definitions for CPP library. 2*c7ca977eSAlexander Kabaev Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3*c7ca977eSAlexander Kabaev 2004, 2005 4*c7ca977eSAlexander Kabaev Free Software Foundation, Inc. 5*c7ca977eSAlexander Kabaev Written by Per Bothner, 1994-95. 6*c7ca977eSAlexander Kabaev 7*c7ca977eSAlexander Kabaev This program is free software; you can redistribute it and/or modify it 8*c7ca977eSAlexander Kabaev under the terms of the GNU General Public License as published by the 9*c7ca977eSAlexander Kabaev Free Software Foundation; either version 2, or (at your option) any 10*c7ca977eSAlexander Kabaev later version. 11*c7ca977eSAlexander Kabaev 12*c7ca977eSAlexander Kabaev This program is distributed in the hope that it will be useful, 13*c7ca977eSAlexander Kabaev but WITHOUT ANY WARRANTY; without even the implied warranty of 14*c7ca977eSAlexander Kabaev MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*c7ca977eSAlexander Kabaev GNU General Public License for more details. 16*c7ca977eSAlexander Kabaev 17*c7ca977eSAlexander Kabaev You should have received a copy of the GNU General Public License 18*c7ca977eSAlexander Kabaev along with this program; if not, write to the Free Software 19*c7ca977eSAlexander Kabaev Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20*c7ca977eSAlexander Kabaev 21*c7ca977eSAlexander Kabaev In other words, you are welcome to use, share and improve this program. 22*c7ca977eSAlexander Kabaev You are forbidden to forbid anyone else to use, share and improve 23*c7ca977eSAlexander Kabaev what you give them. Help stamp out software-hoarding! */ 24*c7ca977eSAlexander Kabaev #ifndef LIBCPP_CPPLIB_H 25*c7ca977eSAlexander Kabaev #define LIBCPP_CPPLIB_H 26*c7ca977eSAlexander Kabaev 27*c7ca977eSAlexander Kabaev #include <sys/types.h> 28*c7ca977eSAlexander Kabaev #include "symtab.h" 29*c7ca977eSAlexander Kabaev #include "line-map.h" 30*c7ca977eSAlexander Kabaev 31*c7ca977eSAlexander Kabaev #ifdef __cplusplus 32*c7ca977eSAlexander Kabaev extern "C" { 33*c7ca977eSAlexander Kabaev #endif 34*c7ca977eSAlexander Kabaev 35*c7ca977eSAlexander Kabaev typedef struct cpp_reader cpp_reader; 36*c7ca977eSAlexander Kabaev typedef struct cpp_buffer cpp_buffer; 37*c7ca977eSAlexander Kabaev typedef struct cpp_options cpp_options; 38*c7ca977eSAlexander Kabaev typedef struct cpp_token cpp_token; 39*c7ca977eSAlexander Kabaev typedef struct cpp_string cpp_string; 40*c7ca977eSAlexander Kabaev typedef struct cpp_hashnode cpp_hashnode; 41*c7ca977eSAlexander Kabaev typedef struct cpp_macro cpp_macro; 42*c7ca977eSAlexander Kabaev typedef struct cpp_callbacks cpp_callbacks; 43*c7ca977eSAlexander Kabaev typedef struct cpp_dir cpp_dir; 44*c7ca977eSAlexander Kabaev 45*c7ca977eSAlexander Kabaev struct answer; 46*c7ca977eSAlexander Kabaev struct _cpp_file; 47*c7ca977eSAlexander Kabaev 48*c7ca977eSAlexander Kabaev /* The first three groups, apart from '=', can appear in preprocessor 49*c7ca977eSAlexander Kabaev expressions (+= and -= are used to indicate unary + and - resp.). 50*c7ca977eSAlexander Kabaev This allows a lookup table to be implemented in _cpp_parse_expr. 51*c7ca977eSAlexander Kabaev 52*c7ca977eSAlexander Kabaev The first group, to CPP_LAST_EQ, can be immediately followed by an 53*c7ca977eSAlexander Kabaev '='. The lexer needs operators ending in '=', like ">>=", to be in 54*c7ca977eSAlexander Kabaev the same order as their counterparts without the '=', like ">>". 55*c7ca977eSAlexander Kabaev 56*c7ca977eSAlexander Kabaev See the cpp_operator table optab in expr.c if you change the order or 57*c7ca977eSAlexander Kabaev add or remove anything in the first group. */ 58*c7ca977eSAlexander Kabaev 59*c7ca977eSAlexander Kabaev #define TTYPE_TABLE \ 60*c7ca977eSAlexander Kabaev OP(EQ, "=") \ 61*c7ca977eSAlexander Kabaev OP(NOT, "!") \ 62*c7ca977eSAlexander Kabaev OP(GREATER, ">") /* compare */ \ 63*c7ca977eSAlexander Kabaev OP(LESS, "<") \ 64*c7ca977eSAlexander Kabaev OP(PLUS, "+") /* math */ \ 65*c7ca977eSAlexander Kabaev OP(MINUS, "-") \ 66*c7ca977eSAlexander Kabaev OP(MULT, "*") \ 67*c7ca977eSAlexander Kabaev OP(DIV, "/") \ 68*c7ca977eSAlexander Kabaev OP(MOD, "%") \ 69*c7ca977eSAlexander Kabaev OP(AND, "&") /* bit ops */ \ 70*c7ca977eSAlexander Kabaev OP(OR, "|") \ 71*c7ca977eSAlexander Kabaev OP(XOR, "^") \ 72*c7ca977eSAlexander Kabaev OP(RSHIFT, ">>") \ 73*c7ca977eSAlexander Kabaev OP(LSHIFT, "<<") \ 74*c7ca977eSAlexander Kabaev \ 75*c7ca977eSAlexander Kabaev OP(COMPL, "~") \ 76*c7ca977eSAlexander Kabaev OP(AND_AND, "&&") /* logical */ \ 77*c7ca977eSAlexander Kabaev OP(OR_OR, "||") \ 78*c7ca977eSAlexander Kabaev OP(QUERY, "?") \ 79*c7ca977eSAlexander Kabaev OP(COLON, ":") \ 80*c7ca977eSAlexander Kabaev OP(COMMA, ",") /* grouping */ \ 81*c7ca977eSAlexander Kabaev OP(OPEN_PAREN, "(") \ 82*c7ca977eSAlexander Kabaev OP(CLOSE_PAREN, ")") \ 83*c7ca977eSAlexander Kabaev TK(EOF, NONE) \ 84*c7ca977eSAlexander Kabaev OP(EQ_EQ, "==") /* compare */ \ 85*c7ca977eSAlexander Kabaev OP(NOT_EQ, "!=") \ 86*c7ca977eSAlexander Kabaev OP(GREATER_EQ, ">=") \ 87*c7ca977eSAlexander Kabaev OP(LESS_EQ, "<=") \ 88*c7ca977eSAlexander Kabaev \ 89*c7ca977eSAlexander Kabaev /* These two are unary + / - in preprocessor expressions. */ \ 90*c7ca977eSAlexander Kabaev OP(PLUS_EQ, "+=") /* math */ \ 91*c7ca977eSAlexander Kabaev OP(MINUS_EQ, "-=") \ 92*c7ca977eSAlexander Kabaev \ 93*c7ca977eSAlexander Kabaev OP(MULT_EQ, "*=") \ 94*c7ca977eSAlexander Kabaev OP(DIV_EQ, "/=") \ 95*c7ca977eSAlexander Kabaev OP(MOD_EQ, "%=") \ 96*c7ca977eSAlexander Kabaev OP(AND_EQ, "&=") /* bit ops */ \ 97*c7ca977eSAlexander Kabaev OP(OR_EQ, "|=") \ 98*c7ca977eSAlexander Kabaev OP(XOR_EQ, "^=") \ 99*c7ca977eSAlexander Kabaev OP(RSHIFT_EQ, ">>=") \ 100*c7ca977eSAlexander Kabaev OP(LSHIFT_EQ, "<<=") \ 101*c7ca977eSAlexander Kabaev /* Digraphs together, beginning with CPP_FIRST_DIGRAPH. */ \ 102*c7ca977eSAlexander Kabaev OP(HASH, "#") /* digraphs */ \ 103*c7ca977eSAlexander Kabaev OP(PASTE, "##") \ 104*c7ca977eSAlexander Kabaev OP(OPEN_SQUARE, "[") \ 105*c7ca977eSAlexander Kabaev OP(CLOSE_SQUARE, "]") \ 106*c7ca977eSAlexander Kabaev OP(OPEN_BRACE, "{") \ 107*c7ca977eSAlexander Kabaev OP(CLOSE_BRACE, "}") \ 108*c7ca977eSAlexander Kabaev /* The remainder of the punctuation. Order is not significant. */ \ 109*c7ca977eSAlexander Kabaev OP(SEMICOLON, ";") /* structure */ \ 110*c7ca977eSAlexander Kabaev OP(ELLIPSIS, "...") \ 111*c7ca977eSAlexander Kabaev OP(PLUS_PLUS, "++") /* increment */ \ 112*c7ca977eSAlexander Kabaev OP(MINUS_MINUS, "--") \ 113*c7ca977eSAlexander Kabaev OP(DEREF, "->") /* accessors */ \ 114*c7ca977eSAlexander Kabaev OP(DOT, ".") \ 115*c7ca977eSAlexander Kabaev OP(SCOPE, "::") \ 116*c7ca977eSAlexander Kabaev OP(DEREF_STAR, "->*") \ 117*c7ca977eSAlexander Kabaev OP(DOT_STAR, ".*") \ 118*c7ca977eSAlexander Kabaev OP(ATSIGN, "@") /* used in Objective-C */ \ 119*c7ca977eSAlexander Kabaev \ 120*c7ca977eSAlexander Kabaev TK(NAME, IDENT) /* word */ \ 121*c7ca977eSAlexander Kabaev TK(AT_NAME, IDENT) /* @word - Objective-C */ \ 122*c7ca977eSAlexander Kabaev TK(NUMBER, LITERAL) /* 34_be+ta */ \ 123*c7ca977eSAlexander Kabaev \ 124*c7ca977eSAlexander Kabaev TK(CHAR, LITERAL) /* 'char' */ \ 125*c7ca977eSAlexander Kabaev TK(WCHAR, LITERAL) /* L'char' */ \ 126*c7ca977eSAlexander Kabaev TK(OTHER, LITERAL) /* stray punctuation */ \ 127*c7ca977eSAlexander Kabaev \ 128*c7ca977eSAlexander Kabaev TK(STRING, LITERAL) /* "string" */ \ 129*c7ca977eSAlexander Kabaev TK(WSTRING, LITERAL) /* L"string" */ \ 130*c7ca977eSAlexander Kabaev TK(OBJC_STRING, LITERAL) /* @"string" - Objective-C */ \ 131*c7ca977eSAlexander Kabaev TK(HEADER_NAME, LITERAL) /* <stdio.h> in #include */ \ 132*c7ca977eSAlexander Kabaev \ 133*c7ca977eSAlexander Kabaev TK(COMMENT, LITERAL) /* Only if output comments. */ \ 134*c7ca977eSAlexander Kabaev /* SPELL_LITERAL happens to DTRT. */ \ 135*c7ca977eSAlexander Kabaev TK(MACRO_ARG, NONE) /* Macro argument. */ \ 136*c7ca977eSAlexander Kabaev TK(PRAGMA, NONE) /* Only for deferred pragmas. */ \ 137*c7ca977eSAlexander Kabaev TK(PRAGMA_EOL, NONE) /* End-of-line for deferred pragmas. */ \ 138*c7ca977eSAlexander Kabaev TK(PADDING, NONE) /* Whitespace for -E. */ 139*c7ca977eSAlexander Kabaev 140*c7ca977eSAlexander Kabaev #define OP(e, s) CPP_ ## e, 141*c7ca977eSAlexander Kabaev #define TK(e, s) CPP_ ## e, 142*c7ca977eSAlexander Kabaev enum cpp_ttype 143*c7ca977eSAlexander Kabaev { 144*c7ca977eSAlexander Kabaev TTYPE_TABLE 145*c7ca977eSAlexander Kabaev N_TTYPES, 146*c7ca977eSAlexander Kabaev 147*c7ca977eSAlexander Kabaev /* Positions in the table. */ 148*c7ca977eSAlexander Kabaev CPP_LAST_EQ = CPP_LSHIFT, 149*c7ca977eSAlexander Kabaev CPP_FIRST_DIGRAPH = CPP_HASH, 150*c7ca977eSAlexander Kabaev CPP_LAST_PUNCTUATOR= CPP_ATSIGN, 151*c7ca977eSAlexander Kabaev CPP_LAST_CPP_OP = CPP_LESS_EQ 152*c7ca977eSAlexander Kabaev }; 153*c7ca977eSAlexander Kabaev #undef OP 154*c7ca977eSAlexander Kabaev #undef TK 155*c7ca977eSAlexander Kabaev 156*c7ca977eSAlexander Kabaev /* C language kind, used when calling cpp_create_reader. */ 157*c7ca977eSAlexander Kabaev enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99, 158*c7ca977eSAlexander Kabaev CLK_GNUCXX, CLK_CXX98, CLK_ASM}; 159*c7ca977eSAlexander Kabaev 160*c7ca977eSAlexander Kabaev /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ 161*c7ca977eSAlexander Kabaev struct cpp_string GTY(()) 162*c7ca977eSAlexander Kabaev { 163*c7ca977eSAlexander Kabaev unsigned int len; 164*c7ca977eSAlexander Kabaev const unsigned char *text; 165*c7ca977eSAlexander Kabaev }; 166*c7ca977eSAlexander Kabaev 167*c7ca977eSAlexander Kabaev /* Flags for the cpp_token structure. */ 168*c7ca977eSAlexander Kabaev #define PREV_WHITE (1 << 0) /* If whitespace before this token. */ 169*c7ca977eSAlexander Kabaev #define DIGRAPH (1 << 1) /* If it was a digraph. */ 170*c7ca977eSAlexander Kabaev #define STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */ 171*c7ca977eSAlexander Kabaev #define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */ 172*c7ca977eSAlexander Kabaev #define NAMED_OP (1 << 4) /* C++ named operators. */ 173*c7ca977eSAlexander Kabaev #define NO_EXPAND (1 << 5) /* Do not macro-expand this token. */ 174*c7ca977eSAlexander Kabaev #define BOL (1 << 6) /* Token at beginning of line. */ 175*c7ca977eSAlexander Kabaev #define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend, 176*c7ca977eSAlexander Kabaev set in c-lex.c. */ 177*c7ca977eSAlexander Kabaev 178*c7ca977eSAlexander Kabaev /* Specify which field, if any, of the cpp_token union is used. */ 179*c7ca977eSAlexander Kabaev 180*c7ca977eSAlexander Kabaev enum cpp_token_fld_kind { 181*c7ca977eSAlexander Kabaev CPP_TOKEN_FLD_NODE, 182*c7ca977eSAlexander Kabaev CPP_TOKEN_FLD_SOURCE, 183*c7ca977eSAlexander Kabaev CPP_TOKEN_FLD_STR, 184*c7ca977eSAlexander Kabaev CPP_TOKEN_FLD_ARG_NO, 185*c7ca977eSAlexander Kabaev CPP_TOKEN_FLD_PRAGMA, 186*c7ca977eSAlexander Kabaev CPP_TOKEN_FLD_NONE 187*c7ca977eSAlexander Kabaev }; 188*c7ca977eSAlexander Kabaev 189*c7ca977eSAlexander Kabaev /* A preprocessing token. This has been carefully packed and should 190*c7ca977eSAlexander Kabaev occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */ 191*c7ca977eSAlexander Kabaev struct cpp_token GTY(()) 192*c7ca977eSAlexander Kabaev { 193*c7ca977eSAlexander Kabaev source_location src_loc; /* Location of first char of token. */ 194*c7ca977eSAlexander Kabaev ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */ 195*c7ca977eSAlexander Kabaev unsigned char flags; /* flags - see above */ 196*c7ca977eSAlexander Kabaev 197*c7ca977eSAlexander Kabaev union cpp_token_u 198*c7ca977eSAlexander Kabaev { 199*c7ca977eSAlexander Kabaev /* An identifier. */ 200*c7ca977eSAlexander Kabaev cpp_hashnode * 201*c7ca977eSAlexander Kabaev GTY ((nested_ptr (union tree_node, 202*c7ca977eSAlexander Kabaev "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", 203*c7ca977eSAlexander Kabaev "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), 204*c7ca977eSAlexander Kabaev tag ("CPP_TOKEN_FLD_NODE"))) 205*c7ca977eSAlexander Kabaev node; 206*c7ca977eSAlexander Kabaev 207*c7ca977eSAlexander Kabaev /* Inherit padding from this token. */ 208*c7ca977eSAlexander Kabaev cpp_token * GTY ((tag ("CPP_TOKEN_FLD_SOURCE"))) source; 209*c7ca977eSAlexander Kabaev 210*c7ca977eSAlexander Kabaev /* A string, or number. */ 211*c7ca977eSAlexander Kabaev struct cpp_string GTY ((tag ("CPP_TOKEN_FLD_STR"))) str; 212*c7ca977eSAlexander Kabaev 213*c7ca977eSAlexander Kabaev /* Argument no. for a CPP_MACRO_ARG. */ 214*c7ca977eSAlexander Kabaev unsigned int GTY ((tag ("CPP_TOKEN_FLD_ARG_NO"))) arg_no; 215*c7ca977eSAlexander Kabaev 216*c7ca977eSAlexander Kabaev /* Caller-supplied identifier for a CPP_PRAGMA. */ 217*c7ca977eSAlexander Kabaev unsigned int GTY ((tag ("CPP_TOKEN_FLD_PRAGMA"))) pragma; 218*c7ca977eSAlexander Kabaev } GTY ((desc ("cpp_token_val_index (&%1)"))) val; 219*c7ca977eSAlexander Kabaev }; 220*c7ca977eSAlexander Kabaev 221*c7ca977eSAlexander Kabaev /* Say which field is in use. */ 222*c7ca977eSAlexander Kabaev extern enum cpp_token_fld_kind cpp_token_val_index (cpp_token *tok); 223*c7ca977eSAlexander Kabaev 224*c7ca977eSAlexander Kabaev /* A type wide enough to hold any multibyte source character. 225*c7ca977eSAlexander Kabaev cpplib's character constant interpreter requires an unsigned type. 226*c7ca977eSAlexander Kabaev Also, a typedef for the signed equivalent. 227*c7ca977eSAlexander Kabaev The width of this type is capped at 32 bits; there do exist targets 228*c7ca977eSAlexander Kabaev where wchar_t is 64 bits, but only in a non-default mode, and there 229*c7ca977eSAlexander Kabaev would be no meaningful interpretation for a wchar_t value greater 230*c7ca977eSAlexander Kabaev than 2^32 anyway -- the widest wide-character encoding around is 231*c7ca977eSAlexander Kabaev ISO 10646, which stops at 2^31. */ 232*c7ca977eSAlexander Kabaev #if CHAR_BIT * SIZEOF_INT >= 32 233*c7ca977eSAlexander Kabaev # define CPPCHAR_SIGNED_T int 234*c7ca977eSAlexander Kabaev #elif CHAR_BIT * SIZEOF_LONG >= 32 235*c7ca977eSAlexander Kabaev # define CPPCHAR_SIGNED_T long 236*c7ca977eSAlexander Kabaev #else 237*c7ca977eSAlexander Kabaev # error "Cannot find a least-32-bit signed integer type" 238*c7ca977eSAlexander Kabaev #endif 239*c7ca977eSAlexander Kabaev typedef unsigned CPPCHAR_SIGNED_T cppchar_t; 240*c7ca977eSAlexander Kabaev typedef CPPCHAR_SIGNED_T cppchar_signed_t; 241*c7ca977eSAlexander Kabaev 242*c7ca977eSAlexander Kabaev /* Style of header dependencies to generate. */ 243*c7ca977eSAlexander Kabaev enum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM }; 244*c7ca977eSAlexander Kabaev 245*c7ca977eSAlexander Kabaev /* The possible normalization levels, from most restrictive to least. */ 246*c7ca977eSAlexander Kabaev enum cpp_normalize_level { 247*c7ca977eSAlexander Kabaev /* In NFKC. */ 248*c7ca977eSAlexander Kabaev normalized_KC = 0, 249*c7ca977eSAlexander Kabaev /* In NFC. */ 250*c7ca977eSAlexander Kabaev normalized_C, 251*c7ca977eSAlexander Kabaev /* In NFC, except for subsequences where being in NFC would make 252*c7ca977eSAlexander Kabaev the identifier invalid. */ 253*c7ca977eSAlexander Kabaev normalized_identifier_C, 254*c7ca977eSAlexander Kabaev /* Not normalized at all. */ 255*c7ca977eSAlexander Kabaev normalized_none 256*c7ca977eSAlexander Kabaev }; 257*c7ca977eSAlexander Kabaev 258*c7ca977eSAlexander Kabaev /* This structure is nested inside struct cpp_reader, and 259*c7ca977eSAlexander Kabaev carries all the options visible to the command line. */ 260*c7ca977eSAlexander Kabaev struct cpp_options 261*c7ca977eSAlexander Kabaev { 262*c7ca977eSAlexander Kabaev /* Characters between tab stops. */ 263*c7ca977eSAlexander Kabaev unsigned int tabstop; 264*c7ca977eSAlexander Kabaev 265*c7ca977eSAlexander Kabaev /* The language we're preprocessing. */ 266*c7ca977eSAlexander Kabaev enum c_lang lang; 267*c7ca977eSAlexander Kabaev 268*c7ca977eSAlexander Kabaev /* Nonzero means use extra default include directories for C++. */ 269*c7ca977eSAlexander Kabaev unsigned char cplusplus; 270*c7ca977eSAlexander Kabaev 271*c7ca977eSAlexander Kabaev /* Nonzero means handle cplusplus style comments. */ 272*c7ca977eSAlexander Kabaev unsigned char cplusplus_comments; 273*c7ca977eSAlexander Kabaev 274*c7ca977eSAlexander Kabaev /* Nonzero means define __OBJC__, treat @ as a special token, and 275*c7ca977eSAlexander Kabaev use the OBJC[PLUS]_INCLUDE_PATH environment variable. */ 276*c7ca977eSAlexander Kabaev unsigned char objc; 277*c7ca977eSAlexander Kabaev 278*c7ca977eSAlexander Kabaev /* Nonzero means don't copy comments into the output file. */ 279*c7ca977eSAlexander Kabaev unsigned char discard_comments; 280*c7ca977eSAlexander Kabaev 281*c7ca977eSAlexander Kabaev /* Nonzero means don't copy comments into the output file during 282*c7ca977eSAlexander Kabaev macro expansion. */ 283*c7ca977eSAlexander Kabaev unsigned char discard_comments_in_macro_exp; 284*c7ca977eSAlexander Kabaev 285*c7ca977eSAlexander Kabaev /* Nonzero means process the ISO trigraph sequences. */ 286*c7ca977eSAlexander Kabaev unsigned char trigraphs; 287*c7ca977eSAlexander Kabaev 288*c7ca977eSAlexander Kabaev /* Nonzero means process the ISO digraph sequences. */ 289*c7ca977eSAlexander Kabaev unsigned char digraphs; 290*c7ca977eSAlexander Kabaev 291*c7ca977eSAlexander Kabaev /* Nonzero means to allow hexadecimal floats and LL suffixes. */ 292*c7ca977eSAlexander Kabaev unsigned char extended_numbers; 293*c7ca977eSAlexander Kabaev 294*c7ca977eSAlexander Kabaev /* Nonzero means print names of header files (-H). */ 295*c7ca977eSAlexander Kabaev unsigned char print_include_names; 296*c7ca977eSAlexander Kabaev 297*c7ca977eSAlexander Kabaev /* Nonzero means cpp_pedwarn causes a hard error. */ 298*c7ca977eSAlexander Kabaev unsigned char pedantic_errors; 299*c7ca977eSAlexander Kabaev 300*c7ca977eSAlexander Kabaev /* Nonzero means don't print warning messages. */ 301*c7ca977eSAlexander Kabaev unsigned char inhibit_warnings; 302*c7ca977eSAlexander Kabaev 303*c7ca977eSAlexander Kabaev /* Nonzero means complain about deprecated features. */ 304*c7ca977eSAlexander Kabaev unsigned char warn_deprecated; 305*c7ca977eSAlexander Kabaev 306*c7ca977eSAlexander Kabaev /* Nonzero means don't suppress warnings from system headers. */ 307*c7ca977eSAlexander Kabaev unsigned char warn_system_headers; 308*c7ca977eSAlexander Kabaev 309*c7ca977eSAlexander Kabaev /* Nonzero means don't print error messages. Has no option to 310*c7ca977eSAlexander Kabaev select it, but can be set by a user of cpplib (e.g. fix-header). */ 311*c7ca977eSAlexander Kabaev unsigned char inhibit_errors; 312*c7ca977eSAlexander Kabaev 313*c7ca977eSAlexander Kabaev /* Nonzero means warn if slash-star appears in a comment. */ 314*c7ca977eSAlexander Kabaev unsigned char warn_comments; 315*c7ca977eSAlexander Kabaev 316*c7ca977eSAlexander Kabaev /* Nonzero means warn if a user-supplied include directory does not 317*c7ca977eSAlexander Kabaev exist. */ 318*c7ca977eSAlexander Kabaev unsigned char warn_missing_include_dirs; 319*c7ca977eSAlexander Kabaev 320*c7ca977eSAlexander Kabaev /* Nonzero means warn if there are any trigraphs. */ 321*c7ca977eSAlexander Kabaev unsigned char warn_trigraphs; 322*c7ca977eSAlexander Kabaev 323*c7ca977eSAlexander Kabaev /* Nonzero means warn about multicharacter charconsts. */ 324*c7ca977eSAlexander Kabaev unsigned char warn_multichar; 325*c7ca977eSAlexander Kabaev 326*c7ca977eSAlexander Kabaev /* Nonzero means warn about various incompatibilities with 327*c7ca977eSAlexander Kabaev traditional C. */ 328*c7ca977eSAlexander Kabaev unsigned char warn_traditional; 329*c7ca977eSAlexander Kabaev 330*c7ca977eSAlexander Kabaev /* Nonzero means warn about long long numeric constants. */ 331*c7ca977eSAlexander Kabaev unsigned char warn_long_long; 332*c7ca977eSAlexander Kabaev 333*c7ca977eSAlexander Kabaev /* Nonzero means warn about text after an #endif (or #else). */ 334*c7ca977eSAlexander Kabaev unsigned char warn_endif_labels; 335*c7ca977eSAlexander Kabaev 336*c7ca977eSAlexander Kabaev /* Nonzero means warn about implicit sign changes owing to integer 337*c7ca977eSAlexander Kabaev promotions. */ 338*c7ca977eSAlexander Kabaev unsigned char warn_num_sign_change; 339*c7ca977eSAlexander Kabaev 340*c7ca977eSAlexander Kabaev /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode. 341*c7ca977eSAlexander Kabaev Presumably the usage is protected by the appropriate #ifdef. */ 342*c7ca977eSAlexander Kabaev unsigned char warn_variadic_macros; 343*c7ca977eSAlexander Kabaev 344*c7ca977eSAlexander Kabaev /* Nonzero means turn warnings into errors. */ 345*c7ca977eSAlexander Kabaev unsigned char warnings_are_errors; 346*c7ca977eSAlexander Kabaev 347*c7ca977eSAlexander Kabaev /* Nonzero means we should look for header.gcc files that remap file 348*c7ca977eSAlexander Kabaev names. */ 349*c7ca977eSAlexander Kabaev unsigned char remap; 350*c7ca977eSAlexander Kabaev 351*c7ca977eSAlexander Kabaev /* Zero means dollar signs are punctuation. */ 352*c7ca977eSAlexander Kabaev unsigned char dollars_in_ident; 353*c7ca977eSAlexander Kabaev 354*c7ca977eSAlexander Kabaev /* Nonzero means UCNs are accepted in identifiers. */ 355*c7ca977eSAlexander Kabaev unsigned char extended_identifiers; 356*c7ca977eSAlexander Kabaev 357*c7ca977eSAlexander Kabaev /* True if we should warn about dollars in identifiers or numbers 358*c7ca977eSAlexander Kabaev for this translation unit. */ 359*c7ca977eSAlexander Kabaev unsigned char warn_dollars; 360*c7ca977eSAlexander Kabaev 361*c7ca977eSAlexander Kabaev /* Nonzero means warn if undefined identifiers are evaluated in an #if. */ 362*c7ca977eSAlexander Kabaev unsigned char warn_undef; 363*c7ca977eSAlexander Kabaev 364*c7ca977eSAlexander Kabaev /* Nonzero means warn of unused macros from the main file. */ 365*c7ca977eSAlexander Kabaev unsigned char warn_unused_macros; 366*c7ca977eSAlexander Kabaev 367*c7ca977eSAlexander Kabaev /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */ 368*c7ca977eSAlexander Kabaev unsigned char c99; 369*c7ca977eSAlexander Kabaev 370*c7ca977eSAlexander Kabaev /* Nonzero if we are conforming to a specific C or C++ standard. */ 371*c7ca977eSAlexander Kabaev unsigned char std; 372*c7ca977eSAlexander Kabaev 373*c7ca977eSAlexander Kabaev /* Nonzero means give all the error messages the ANSI standard requires. */ 374*c7ca977eSAlexander Kabaev unsigned char pedantic; 375*c7ca977eSAlexander Kabaev 376*c7ca977eSAlexander Kabaev /* Nonzero means we're looking at already preprocessed code, so don't 377*c7ca977eSAlexander Kabaev bother trying to do macro expansion and whatnot. */ 378*c7ca977eSAlexander Kabaev unsigned char preprocessed; 379*c7ca977eSAlexander Kabaev 380*c7ca977eSAlexander Kabaev /* Print column number in error messages. */ 381*c7ca977eSAlexander Kabaev unsigned char show_column; 382*c7ca977eSAlexander Kabaev 383*c7ca977eSAlexander Kabaev /* Nonzero means handle C++ alternate operator names. */ 384*c7ca977eSAlexander Kabaev unsigned char operator_names; 385*c7ca977eSAlexander Kabaev 386*c7ca977eSAlexander Kabaev /* True for traditional preprocessing. */ 387*c7ca977eSAlexander Kabaev unsigned char traditional; 388*c7ca977eSAlexander Kabaev 389*c7ca977eSAlexander Kabaev /* Holds the name of the target (execution) character set. */ 390*c7ca977eSAlexander Kabaev const char *narrow_charset; 391*c7ca977eSAlexander Kabaev 392*c7ca977eSAlexander Kabaev /* Holds the name of the target wide character set. */ 393*c7ca977eSAlexander Kabaev const char *wide_charset; 394*c7ca977eSAlexander Kabaev 395*c7ca977eSAlexander Kabaev /* Holds the name of the input character set. */ 396*c7ca977eSAlexander Kabaev const char *input_charset; 397*c7ca977eSAlexander Kabaev 398*c7ca977eSAlexander Kabaev /* The minimum permitted level of normalization before a warning 399*c7ca977eSAlexander Kabaev is generated. */ 400*c7ca977eSAlexander Kabaev enum cpp_normalize_level warn_normalize; 401*c7ca977eSAlexander Kabaev 402*c7ca977eSAlexander Kabaev /* True to warn about precompiled header files we couldn't use. */ 403*c7ca977eSAlexander Kabaev bool warn_invalid_pch; 404*c7ca977eSAlexander Kabaev 405*c7ca977eSAlexander Kabaev /* True if dependencies should be restored from a precompiled header. */ 406*c7ca977eSAlexander Kabaev bool restore_pch_deps; 407*c7ca977eSAlexander Kabaev 408*c7ca977eSAlexander Kabaev /* Dependency generation. */ 409*c7ca977eSAlexander Kabaev struct 410*c7ca977eSAlexander Kabaev { 411*c7ca977eSAlexander Kabaev /* Style of header dependencies to generate. */ 412*c7ca977eSAlexander Kabaev enum cpp_deps_style style; 413*c7ca977eSAlexander Kabaev 414*c7ca977eSAlexander Kabaev /* Assume missing files are generated files. */ 415*c7ca977eSAlexander Kabaev bool missing_files; 416*c7ca977eSAlexander Kabaev 417*c7ca977eSAlexander Kabaev /* Generate phony targets for each dependency apart from the first 418*c7ca977eSAlexander Kabaev one. */ 419*c7ca977eSAlexander Kabaev bool phony_targets; 420*c7ca977eSAlexander Kabaev 421*c7ca977eSAlexander Kabaev /* If true, no dependency is generated on the main file. */ 422*c7ca977eSAlexander Kabaev bool ignore_main_file; 423*c7ca977eSAlexander Kabaev } deps; 424*c7ca977eSAlexander Kabaev 425*c7ca977eSAlexander Kabaev /* Target-specific features set by the front end or client. */ 426*c7ca977eSAlexander Kabaev 427*c7ca977eSAlexander Kabaev /* Precision for target CPP arithmetic, target characters, target 428*c7ca977eSAlexander Kabaev ints and target wide characters, respectively. */ 429*c7ca977eSAlexander Kabaev size_t precision, char_precision, int_precision, wchar_precision; 430*c7ca977eSAlexander Kabaev 431*c7ca977eSAlexander Kabaev /* True means chars (wide chars) are unsigned. */ 432*c7ca977eSAlexander Kabaev bool unsigned_char, unsigned_wchar; 433*c7ca977eSAlexander Kabaev 434*c7ca977eSAlexander Kabaev /* True if the most significant byte in a word has the lowest 435*c7ca977eSAlexander Kabaev address in memory. */ 436*c7ca977eSAlexander Kabaev bool bytes_big_endian; 437*c7ca977eSAlexander Kabaev 438*c7ca977eSAlexander Kabaev /* Nonzero means __STDC__ should have the value 0 in system headers. */ 439*c7ca977eSAlexander Kabaev unsigned char stdc_0_in_system_headers; 440*c7ca977eSAlexander Kabaev 441*c7ca977eSAlexander Kabaev /* True means error callback should be used for diagnostics. */ 442*c7ca977eSAlexander Kabaev bool client_diagnostic; 443*c7ca977eSAlexander Kabaev }; 444*c7ca977eSAlexander Kabaev 445*c7ca977eSAlexander Kabaev /* Callback for header lookup for HEADER, which is the name of a 446*c7ca977eSAlexander Kabaev source file. It is used as a method of last resort to find headers 447*c7ca977eSAlexander Kabaev that are not otherwise found during the normal include processing. 448*c7ca977eSAlexander Kabaev The return value is the malloced name of a header to try and open, 449*c7ca977eSAlexander Kabaev if any, or NULL otherwise. This callback is called only if the 450*c7ca977eSAlexander Kabaev header is otherwise unfound. */ 451*c7ca977eSAlexander Kabaev typedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **); 452*c7ca977eSAlexander Kabaev 453*c7ca977eSAlexander Kabaev /* Call backs to cpplib client. */ 454*c7ca977eSAlexander Kabaev struct cpp_callbacks 455*c7ca977eSAlexander Kabaev { 456*c7ca977eSAlexander Kabaev /* Called when a new line of preprocessed output is started. */ 457*c7ca977eSAlexander Kabaev void (*line_change) (cpp_reader *, const cpp_token *, int); 458*c7ca977eSAlexander Kabaev 459*c7ca977eSAlexander Kabaev /* Called when switching to/from a new file. 460*c7ca977eSAlexander Kabaev The line_map is for the new file. It is NULL if there is no new file. 461*c7ca977eSAlexander Kabaev (In C this happens when done with <built-in>+<command line> and also 462*c7ca977eSAlexander Kabaev when done with a main file.) This can be used for resource cleanup. */ 463*c7ca977eSAlexander Kabaev void (*file_change) (cpp_reader *, const struct line_map *); 464*c7ca977eSAlexander Kabaev 465*c7ca977eSAlexander Kabaev void (*dir_change) (cpp_reader *, const char *); 466*c7ca977eSAlexander Kabaev void (*include) (cpp_reader *, unsigned int, const unsigned char *, 467*c7ca977eSAlexander Kabaev const char *, int, const cpp_token **); 468*c7ca977eSAlexander Kabaev void (*define) (cpp_reader *, unsigned int, cpp_hashnode *); 469*c7ca977eSAlexander Kabaev void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *); 470*c7ca977eSAlexander Kabaev void (*ident) (cpp_reader *, unsigned int, const cpp_string *); 471*c7ca977eSAlexander Kabaev void (*def_pragma) (cpp_reader *, unsigned int); 472*c7ca977eSAlexander Kabaev int (*valid_pch) (cpp_reader *, const char *, int); 473*c7ca977eSAlexander Kabaev void (*read_pch) (cpp_reader *, const char *, int, const char *); 474*c7ca977eSAlexander Kabaev missing_header_cb missing_header; 475*c7ca977eSAlexander Kabaev 476*c7ca977eSAlexander Kabaev /* Called to emit a diagnostic if client_diagnostic option is true. 477*c7ca977eSAlexander Kabaev This callback receives the translated message. */ 478*c7ca977eSAlexander Kabaev void (*error) (cpp_reader *, int, const char *, va_list *) 479*c7ca977eSAlexander Kabaev ATTRIBUTE_FPTR_PRINTF(3,0); 480*c7ca977eSAlexander Kabaev }; 481*c7ca977eSAlexander Kabaev 482*c7ca977eSAlexander Kabaev /* Chain of directories to look for include files in. */ 483*c7ca977eSAlexander Kabaev struct cpp_dir 484*c7ca977eSAlexander Kabaev { 485*c7ca977eSAlexander Kabaev /* NULL-terminated singly-linked list. */ 486*c7ca977eSAlexander Kabaev struct cpp_dir *next; 487*c7ca977eSAlexander Kabaev 488*c7ca977eSAlexander Kabaev /* NAME of the directory, NUL-terminated. */ 489*c7ca977eSAlexander Kabaev char *name; 490*c7ca977eSAlexander Kabaev unsigned int len; 491*c7ca977eSAlexander Kabaev 492*c7ca977eSAlexander Kabaev /* One if a system header, two if a system header that has extern 493*c7ca977eSAlexander Kabaev "C" guards for C++. */ 494*c7ca977eSAlexander Kabaev unsigned char sysp; 495*c7ca977eSAlexander Kabaev 496*c7ca977eSAlexander Kabaev /* Mapping of file names for this directory for MS-DOS and related 497*c7ca977eSAlexander Kabaev platforms. A NULL-terminated array of (from, to) pairs. */ 498*c7ca977eSAlexander Kabaev const char **name_map; 499*c7ca977eSAlexander Kabaev 500*c7ca977eSAlexander Kabaev /* Routine to construct pathname, given the search path name and the 501*c7ca977eSAlexander Kabaev HEADER we are trying to find, return a constructed pathname to 502*c7ca977eSAlexander Kabaev try and open. If this is NULL, the constructed pathname is as 503*c7ca977eSAlexander Kabaev constructed by append_file_to_dir. */ 504*c7ca977eSAlexander Kabaev char *(*construct) (const char *header, cpp_dir *dir); 505*c7ca977eSAlexander Kabaev 506*c7ca977eSAlexander Kabaev /* The C front end uses these to recognize duplicated 507*c7ca977eSAlexander Kabaev directories in the search path. */ 508*c7ca977eSAlexander Kabaev ino_t ino; 509*c7ca977eSAlexander Kabaev dev_t dev; 510*c7ca977eSAlexander Kabaev 511*c7ca977eSAlexander Kabaev /* Is this a user-supplied directory? */ 512*c7ca977eSAlexander Kabaev bool user_supplied_p; 513*c7ca977eSAlexander Kabaev }; 514*c7ca977eSAlexander Kabaev 515*c7ca977eSAlexander Kabaev /* Name under which this program was invoked. */ 516*c7ca977eSAlexander Kabaev extern const char *progname; 517*c7ca977eSAlexander Kabaev 518*c7ca977eSAlexander Kabaev /* The structure of a node in the hash table. The hash table has 519*c7ca977eSAlexander Kabaev entries for all identifiers: either macros defined by #define 520*c7ca977eSAlexander Kabaev commands (type NT_MACRO), assertions created with #assert 521*c7ca977eSAlexander Kabaev (NT_ASSERTION), or neither of the above (NT_VOID). Builtin macros 522*c7ca977eSAlexander Kabaev like __LINE__ are flagged NODE_BUILTIN. Poisoned identifiers are 523*c7ca977eSAlexander Kabaev flagged NODE_POISONED. NODE_OPERATOR (C++ only) indicates an 524*c7ca977eSAlexander Kabaev identifier that behaves like an operator such as "xor". 525*c7ca977eSAlexander Kabaev NODE_DIAGNOSTIC is for speed in lex_token: it indicates a 526*c7ca977eSAlexander Kabaev diagnostic may be required for this node. Currently this only 527*c7ca977eSAlexander Kabaev applies to __VA_ARGS__ and poisoned identifiers. */ 528*c7ca977eSAlexander Kabaev 529*c7ca977eSAlexander Kabaev /* Hash node flags. */ 530*c7ca977eSAlexander Kabaev #define NODE_OPERATOR (1 << 0) /* C++ named operator. */ 531*c7ca977eSAlexander Kabaev #define NODE_POISONED (1 << 1) /* Poisoned identifier. */ 532*c7ca977eSAlexander Kabaev #define NODE_BUILTIN (1 << 2) /* Builtin macro. */ 533*c7ca977eSAlexander Kabaev #define NODE_DIAGNOSTIC (1 << 3) /* Possible diagnostic when lexed. */ 534*c7ca977eSAlexander Kabaev #define NODE_WARN (1 << 4) /* Warn if redefined or undefined. */ 535*c7ca977eSAlexander Kabaev #define NODE_DISABLED (1 << 5) /* A disabled macro. */ 536*c7ca977eSAlexander Kabaev #define NODE_MACRO_ARG (1 << 6) /* Used during #define processing. */ 537*c7ca977eSAlexander Kabaev 538*c7ca977eSAlexander Kabaev /* Different flavors of hash node. */ 539*c7ca977eSAlexander Kabaev enum node_type 540*c7ca977eSAlexander Kabaev { 541*c7ca977eSAlexander Kabaev NT_VOID = 0, /* No definition yet. */ 542*c7ca977eSAlexander Kabaev NT_MACRO, /* A macro of some form. */ 543*c7ca977eSAlexander Kabaev NT_ASSERTION /* Predicate for #assert. */ 544*c7ca977eSAlexander Kabaev }; 545*c7ca977eSAlexander Kabaev 546*c7ca977eSAlexander Kabaev /* Different flavors of builtin macro. _Pragma is an operator, but we 547*c7ca977eSAlexander Kabaev handle it with the builtin code for efficiency reasons. */ 548*c7ca977eSAlexander Kabaev enum builtin_type 549*c7ca977eSAlexander Kabaev { 550*c7ca977eSAlexander Kabaev BT_SPECLINE = 0, /* `__LINE__' */ 551*c7ca977eSAlexander Kabaev BT_DATE, /* `__DATE__' */ 552*c7ca977eSAlexander Kabaev BT_FILE, /* `__FILE__' */ 553*c7ca977eSAlexander Kabaev BT_BASE_FILE, /* `__BASE_FILE__' */ 554*c7ca977eSAlexander Kabaev BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ 555*c7ca977eSAlexander Kabaev BT_TIME, /* `__TIME__' */ 556*c7ca977eSAlexander Kabaev BT_STDC, /* `__STDC__' */ 557*c7ca977eSAlexander Kabaev BT_PRAGMA, /* `_Pragma' operator */ 558*c7ca977eSAlexander Kabaev BT_TIMESTAMP /* `__TIMESTAMP__' */ 559*c7ca977eSAlexander Kabaev }; 560*c7ca977eSAlexander Kabaev 561*c7ca977eSAlexander Kabaev #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) 562*c7ca977eSAlexander Kabaev #define HT_NODE(NODE) ((ht_identifier *) (NODE)) 563*c7ca977eSAlexander Kabaev #define NODE_LEN(NODE) HT_LEN (&(NODE)->ident) 564*c7ca977eSAlexander Kabaev #define NODE_NAME(NODE) HT_STR (&(NODE)->ident) 565*c7ca977eSAlexander Kabaev 566*c7ca977eSAlexander Kabaev /* Specify which field, if any, of the union is used. */ 567*c7ca977eSAlexander Kabaev 568*c7ca977eSAlexander Kabaev enum { 569*c7ca977eSAlexander Kabaev NTV_MACRO, 570*c7ca977eSAlexander Kabaev NTV_ANSWER, 571*c7ca977eSAlexander Kabaev NTV_BUILTIN, 572*c7ca977eSAlexander Kabaev NTV_ARGUMENT, 573*c7ca977eSAlexander Kabaev NTV_NONE 574*c7ca977eSAlexander Kabaev }; 575*c7ca977eSAlexander Kabaev 576*c7ca977eSAlexander Kabaev #define CPP_HASHNODE_VALUE_IDX(HNODE) \ 577*c7ca977eSAlexander Kabaev ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT \ 578*c7ca977eSAlexander Kabaev : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN) \ 579*c7ca977eSAlexander Kabaev ? NTV_BUILTIN : NTV_MACRO) \ 580*c7ca977eSAlexander Kabaev : HNODE.type == NT_ASSERTION ? NTV_ANSWER \ 581*c7ca977eSAlexander Kabaev : NTV_NONE) 582*c7ca977eSAlexander Kabaev 583*c7ca977eSAlexander Kabaev /* The common part of an identifier node shared amongst all 3 C front 584*c7ca977eSAlexander Kabaev ends. Also used to store CPP identifiers, which are a superset of 585*c7ca977eSAlexander Kabaev identifiers in the grammatical sense. */ 586*c7ca977eSAlexander Kabaev 587*c7ca977eSAlexander Kabaev union _cpp_hashnode_value GTY(()) 588*c7ca977eSAlexander Kabaev { 589*c7ca977eSAlexander Kabaev /* If a macro. */ 590*c7ca977eSAlexander Kabaev cpp_macro * GTY((tag ("NTV_MACRO"))) macro; 591*c7ca977eSAlexander Kabaev /* Answers to an assertion. */ 592*c7ca977eSAlexander Kabaev struct answer * GTY ((tag ("NTV_ANSWER"))) answers; 593*c7ca977eSAlexander Kabaev /* Code for a builtin macro. */ 594*c7ca977eSAlexander Kabaev enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin; 595*c7ca977eSAlexander Kabaev /* Macro argument index. */ 596*c7ca977eSAlexander Kabaev unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index; 597*c7ca977eSAlexander Kabaev }; 598*c7ca977eSAlexander Kabaev 599*c7ca977eSAlexander Kabaev struct cpp_hashnode GTY(()) 600*c7ca977eSAlexander Kabaev { 601*c7ca977eSAlexander Kabaev struct ht_identifier ident; 602*c7ca977eSAlexander Kabaev unsigned int is_directive : 1; 603*c7ca977eSAlexander Kabaev unsigned int directive_index : 7; /* If is_directive, 604*c7ca977eSAlexander Kabaev then index into directive table. 605*c7ca977eSAlexander Kabaev Otherwise, a NODE_OPERATOR. */ 606*c7ca977eSAlexander Kabaev unsigned char rid_code; /* Rid code - for front ends. */ 607*c7ca977eSAlexander Kabaev ENUM_BITFIELD(node_type) type : 8; /* CPP node type. */ 608*c7ca977eSAlexander Kabaev unsigned char flags; /* CPP flags. */ 609*c7ca977eSAlexander Kabaev 610*c7ca977eSAlexander Kabaev union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value; 611*c7ca977eSAlexander Kabaev }; 612*c7ca977eSAlexander Kabaev 613*c7ca977eSAlexander Kabaev /* Call this first to get a handle to pass to other functions. 614*c7ca977eSAlexander Kabaev 615*c7ca977eSAlexander Kabaev If you want cpplib to manage its own hashtable, pass in a NULL 616*c7ca977eSAlexander Kabaev pointer. Otherwise you should pass in an initialized hash table 617*c7ca977eSAlexander Kabaev that cpplib will share; this technique is used by the C front 618*c7ca977eSAlexander Kabaev ends. */ 619*c7ca977eSAlexander Kabaev extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *, 620*c7ca977eSAlexander Kabaev struct line_maps *); 621*c7ca977eSAlexander Kabaev 622*c7ca977eSAlexander Kabaev /* Call this to change the selected language standard (e.g. because of 623*c7ca977eSAlexander Kabaev command line options). */ 624*c7ca977eSAlexander Kabaev extern void cpp_set_lang (cpp_reader *, enum c_lang); 625*c7ca977eSAlexander Kabaev 626*c7ca977eSAlexander Kabaev /* Set the include paths. */ 627*c7ca977eSAlexander Kabaev extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); 628*c7ca977eSAlexander Kabaev 629*c7ca977eSAlexander Kabaev /* Call these to get pointers to the options, callback, and deps 630*c7ca977eSAlexander Kabaev structures for a given reader. These pointers are good until you 631*c7ca977eSAlexander Kabaev call cpp_finish on that reader. You can either edit the callbacks 632*c7ca977eSAlexander Kabaev through the pointer returned from cpp_get_callbacks, or set them 633*c7ca977eSAlexander Kabaev with cpp_set_callbacks. */ 634*c7ca977eSAlexander Kabaev extern cpp_options *cpp_get_options (cpp_reader *); 635*c7ca977eSAlexander Kabaev extern cpp_callbacks *cpp_get_callbacks (cpp_reader *); 636*c7ca977eSAlexander Kabaev extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *); 637*c7ca977eSAlexander Kabaev extern struct deps *cpp_get_deps (cpp_reader *); 638*c7ca977eSAlexander Kabaev 639*c7ca977eSAlexander Kabaev /* This function reads the file, but does not start preprocessing. It 640*c7ca977eSAlexander Kabaev returns the name of the original file; this is the same as the 641*c7ca977eSAlexander Kabaev input file, except for preprocessed input. This will generate at 642*c7ca977eSAlexander Kabaev least one file change callback, and possibly a line change callback 643*c7ca977eSAlexander Kabaev too. If there was an error opening the file, it returns NULL. */ 644*c7ca977eSAlexander Kabaev extern const char *cpp_read_main_file (cpp_reader *, const char *); 645*c7ca977eSAlexander Kabaev 646*c7ca977eSAlexander Kabaev /* Set up built-ins like __FILE__. */ 647*c7ca977eSAlexander Kabaev extern void cpp_init_builtins (cpp_reader *, int); 648*c7ca977eSAlexander Kabaev 649*c7ca977eSAlexander Kabaev /* This is called after options have been parsed, and partially 650*c7ca977eSAlexander Kabaev processed. */ 651*c7ca977eSAlexander Kabaev extern void cpp_post_options (cpp_reader *); 652*c7ca977eSAlexander Kabaev 653*c7ca977eSAlexander Kabaev /* Set up translation to the target character set. */ 654*c7ca977eSAlexander Kabaev extern void cpp_init_iconv (cpp_reader *); 655*c7ca977eSAlexander Kabaev 656*c7ca977eSAlexander Kabaev /* Call this to finish preprocessing. If you requested dependency 657*c7ca977eSAlexander Kabaev generation, pass an open stream to write the information to, 658*c7ca977eSAlexander Kabaev otherwise NULL. It is your responsibility to close the stream. 659*c7ca977eSAlexander Kabaev 660*c7ca977eSAlexander Kabaev Returns cpp_errors (pfile). */ 661*c7ca977eSAlexander Kabaev extern int cpp_finish (cpp_reader *, FILE *deps_stream); 662*c7ca977eSAlexander Kabaev 663*c7ca977eSAlexander Kabaev /* Call this to release the handle at the end of preprocessing. Any 664*c7ca977eSAlexander Kabaev use of the handle after this function returns is invalid. Returns 665*c7ca977eSAlexander Kabaev cpp_errors (pfile). */ 666*c7ca977eSAlexander Kabaev extern void cpp_destroy (cpp_reader *); 667*c7ca977eSAlexander Kabaev 668*c7ca977eSAlexander Kabaev /* Error count. */ 669*c7ca977eSAlexander Kabaev extern unsigned int cpp_errors (cpp_reader *); 670*c7ca977eSAlexander Kabaev 671*c7ca977eSAlexander Kabaev extern unsigned int cpp_token_len (const cpp_token *); 672*c7ca977eSAlexander Kabaev extern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *); 673*c7ca977eSAlexander Kabaev extern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *, 674*c7ca977eSAlexander Kabaev unsigned char *, bool); 675*c7ca977eSAlexander Kabaev extern void cpp_register_pragma (cpp_reader *, const char *, const char *, 676*c7ca977eSAlexander Kabaev void (*) (cpp_reader *), bool); 677*c7ca977eSAlexander Kabaev extern void cpp_register_deferred_pragma (cpp_reader *, const char *, 678*c7ca977eSAlexander Kabaev const char *, unsigned, bool, bool); 679*c7ca977eSAlexander Kabaev extern int cpp_avoid_paste (cpp_reader *, const cpp_token *, 680*c7ca977eSAlexander Kabaev const cpp_token *); 681*c7ca977eSAlexander Kabaev extern const cpp_token *cpp_get_token (cpp_reader *); 682*c7ca977eSAlexander Kabaev extern const unsigned char *cpp_macro_definition (cpp_reader *, 683*c7ca977eSAlexander Kabaev const cpp_hashnode *); 684*c7ca977eSAlexander Kabaev extern void _cpp_backup_tokens (cpp_reader *, unsigned int); 685*c7ca977eSAlexander Kabaev 686*c7ca977eSAlexander Kabaev /* Evaluate a CPP_CHAR or CPP_WCHAR token. */ 687*c7ca977eSAlexander Kabaev extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *, 688*c7ca977eSAlexander Kabaev unsigned int *, int *); 689*c7ca977eSAlexander Kabaev /* Evaluate a vector of CPP_STRING or CPP_WSTRING tokens. */ 690*c7ca977eSAlexander Kabaev extern bool cpp_interpret_string (cpp_reader *, 691*c7ca977eSAlexander Kabaev const cpp_string *, size_t, 692*c7ca977eSAlexander Kabaev cpp_string *, bool); 693*c7ca977eSAlexander Kabaev extern bool cpp_interpret_string_notranslate (cpp_reader *, 694*c7ca977eSAlexander Kabaev const cpp_string *, size_t, 695*c7ca977eSAlexander Kabaev cpp_string *, bool); 696*c7ca977eSAlexander Kabaev 697*c7ca977eSAlexander Kabaev /* Convert a host character constant to the execution character set. */ 698*c7ca977eSAlexander Kabaev extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); 699*c7ca977eSAlexander Kabaev 700*c7ca977eSAlexander Kabaev /* Used to register macros and assertions, perhaps from the command line. 701*c7ca977eSAlexander Kabaev The text is the same as the command line argument. */ 702*c7ca977eSAlexander Kabaev extern void cpp_define (cpp_reader *, const char *); 703*c7ca977eSAlexander Kabaev extern void cpp_assert (cpp_reader *, const char *); 704*c7ca977eSAlexander Kabaev extern void cpp_undef (cpp_reader *, const char *); 705*c7ca977eSAlexander Kabaev extern void cpp_unassert (cpp_reader *, const char *); 706*c7ca977eSAlexander Kabaev 707*c7ca977eSAlexander Kabaev /* Undefine all macros and assertions. */ 708*c7ca977eSAlexander Kabaev extern void cpp_undef_all (cpp_reader *); 709*c7ca977eSAlexander Kabaev 710*c7ca977eSAlexander Kabaev extern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *, 711*c7ca977eSAlexander Kabaev size_t, int); 712*c7ca977eSAlexander Kabaev extern int cpp_defined (cpp_reader *, const unsigned char *, int); 713*c7ca977eSAlexander Kabaev 714*c7ca977eSAlexander Kabaev /* A preprocessing number. Code assumes that any unused high bits of 715*c7ca977eSAlexander Kabaev the double integer are set to zero. */ 716*c7ca977eSAlexander Kabaev typedef unsigned HOST_WIDE_INT cpp_num_part; 717*c7ca977eSAlexander Kabaev typedef struct cpp_num cpp_num; 718*c7ca977eSAlexander Kabaev struct cpp_num 719*c7ca977eSAlexander Kabaev { 720*c7ca977eSAlexander Kabaev cpp_num_part high; 721*c7ca977eSAlexander Kabaev cpp_num_part low; 722*c7ca977eSAlexander Kabaev bool unsignedp; /* True if value should be treated as unsigned. */ 723*c7ca977eSAlexander Kabaev bool overflow; /* True if the most recent calculation overflowed. */ 724*c7ca977eSAlexander Kabaev }; 725*c7ca977eSAlexander Kabaev 726*c7ca977eSAlexander Kabaev /* cpplib provides two interfaces for interpretation of preprocessing 727*c7ca977eSAlexander Kabaev numbers. 728*c7ca977eSAlexander Kabaev 729*c7ca977eSAlexander Kabaev cpp_classify_number categorizes numeric constants according to 730*c7ca977eSAlexander Kabaev their field (integer, floating point, or invalid), radix (decimal, 731*c7ca977eSAlexander Kabaev octal, hexadecimal), and type suffixes. */ 732*c7ca977eSAlexander Kabaev 733*c7ca977eSAlexander Kabaev #define CPP_N_CATEGORY 0x000F 734*c7ca977eSAlexander Kabaev #define CPP_N_INVALID 0x0000 735*c7ca977eSAlexander Kabaev #define CPP_N_INTEGER 0x0001 736*c7ca977eSAlexander Kabaev #define CPP_N_FLOATING 0x0002 737*c7ca977eSAlexander Kabaev 738*c7ca977eSAlexander Kabaev #define CPP_N_WIDTH 0x00F0 739*c7ca977eSAlexander Kabaev #define CPP_N_SMALL 0x0010 /* int, float. */ 740*c7ca977eSAlexander Kabaev #define CPP_N_MEDIUM 0x0020 /* long, double. */ 741*c7ca977eSAlexander Kabaev #define CPP_N_LARGE 0x0040 /* long long, long double. */ 742*c7ca977eSAlexander Kabaev 743*c7ca977eSAlexander Kabaev #define CPP_N_RADIX 0x0F00 744*c7ca977eSAlexander Kabaev #define CPP_N_DECIMAL 0x0100 745*c7ca977eSAlexander Kabaev #define CPP_N_HEX 0x0200 746*c7ca977eSAlexander Kabaev #define CPP_N_OCTAL 0x0400 747*c7ca977eSAlexander Kabaev 748*c7ca977eSAlexander Kabaev #define CPP_N_UNSIGNED 0x1000 /* Properties. */ 749*c7ca977eSAlexander Kabaev #define CPP_N_IMAGINARY 0x2000 750*c7ca977eSAlexander Kabaev #define CPP_N_DFLOAT 0x4000 751*c7ca977eSAlexander Kabaev 752*c7ca977eSAlexander Kabaev /* Classify a CPP_NUMBER token. The return value is a combination of 753*c7ca977eSAlexander Kabaev the flags from the above sets. */ 754*c7ca977eSAlexander Kabaev extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *); 755*c7ca977eSAlexander Kabaev 756*c7ca977eSAlexander Kabaev /* Evaluate a token classified as category CPP_N_INTEGER. */ 757*c7ca977eSAlexander Kabaev extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *, 758*c7ca977eSAlexander Kabaev unsigned int type); 759*c7ca977eSAlexander Kabaev 760*c7ca977eSAlexander Kabaev /* Sign extend a number, with PRECISION significant bits and all 761*c7ca977eSAlexander Kabaev others assumed clear, to fill out a cpp_num structure. */ 762*c7ca977eSAlexander Kabaev cpp_num cpp_num_sign_extend (cpp_num, size_t); 763*c7ca977eSAlexander Kabaev 764*c7ca977eSAlexander Kabaev /* Diagnostic levels. To get a diagnostic without associating a 765*c7ca977eSAlexander Kabaev position in the translation unit with it, use cpp_error_with_line 766*c7ca977eSAlexander Kabaev with a line number of zero. */ 767*c7ca977eSAlexander Kabaev 768*c7ca977eSAlexander Kabaev /* Warning, an error with -Werror. */ 769*c7ca977eSAlexander Kabaev #define CPP_DL_WARNING 0x00 770*c7ca977eSAlexander Kabaev /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */ 771*c7ca977eSAlexander Kabaev #define CPP_DL_WARNING_SYSHDR 0x01 772*c7ca977eSAlexander Kabaev /* Warning, an error with -pedantic-errors or -Werror. */ 773*c7ca977eSAlexander Kabaev #define CPP_DL_PEDWARN 0x02 774*c7ca977eSAlexander Kabaev /* An error. */ 775*c7ca977eSAlexander Kabaev #define CPP_DL_ERROR 0x03 776*c7ca977eSAlexander Kabaev /* An internal consistency check failed. Prints "internal error: ", 777*c7ca977eSAlexander Kabaev otherwise the same as CPP_DL_ERROR. */ 778*c7ca977eSAlexander Kabaev #define CPP_DL_ICE 0x04 779*c7ca977eSAlexander Kabaev /* Extracts a diagnostic level from an int. */ 780*c7ca977eSAlexander Kabaev #define CPP_DL_EXTRACT(l) (l & 0xf) 781*c7ca977eSAlexander Kabaev /* Nonzero if a diagnostic level is one of the warnings. */ 782*c7ca977eSAlexander Kabaev #define CPP_DL_WARNING_P(l) (CPP_DL_EXTRACT (l) >= CPP_DL_WARNING \ 783*c7ca977eSAlexander Kabaev && CPP_DL_EXTRACT (l) <= CPP_DL_PEDWARN) 784*c7ca977eSAlexander Kabaev 785*c7ca977eSAlexander Kabaev /* Output a diagnostic of some kind. */ 786*c7ca977eSAlexander Kabaev extern void cpp_error (cpp_reader *, int, const char *msgid, ...) 787*c7ca977eSAlexander Kabaev ATTRIBUTE_PRINTF_3; 788*c7ca977eSAlexander Kabaev 789*c7ca977eSAlexander Kabaev /* Output a diagnostic with "MSGID: " preceding the 790*c7ca977eSAlexander Kabaev error string of errno. No location is printed. */ 791*c7ca977eSAlexander Kabaev extern void cpp_errno (cpp_reader *, int, const char *msgid); 792*c7ca977eSAlexander Kabaev 793*c7ca977eSAlexander Kabaev /* Same as cpp_error, except additionally specifies a position as a 794*c7ca977eSAlexander Kabaev (translation unit) physical line and physical column. If the line is 795*c7ca977eSAlexander Kabaev zero, then no location is printed. */ 796*c7ca977eSAlexander Kabaev extern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned, 797*c7ca977eSAlexander Kabaev const char *msgid, ...) ATTRIBUTE_PRINTF_5; 798*c7ca977eSAlexander Kabaev 799*c7ca977eSAlexander Kabaev /* In cpplex.c */ 800*c7ca977eSAlexander Kabaev extern int cpp_ideq (const cpp_token *, const char *); 801*c7ca977eSAlexander Kabaev extern void cpp_output_line (cpp_reader *, FILE *); 802*c7ca977eSAlexander Kabaev extern void cpp_output_token (const cpp_token *, FILE *); 803*c7ca977eSAlexander Kabaev extern const char *cpp_type2name (enum cpp_ttype); 804*c7ca977eSAlexander Kabaev /* Returns the value of an escape sequence, truncated to the correct 805*c7ca977eSAlexander Kabaev target precision. PSTR points to the input pointer, which is just 806*c7ca977eSAlexander Kabaev after the backslash. LIMIT is how much text we have. WIDE is true 807*c7ca977eSAlexander Kabaev if the escape sequence is part of a wide character constant or 808*c7ca977eSAlexander Kabaev string literal. Handles all relevant diagnostics. */ 809*c7ca977eSAlexander Kabaev extern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr, 810*c7ca977eSAlexander Kabaev const unsigned char *limit, int wide); 811*c7ca977eSAlexander Kabaev 812*c7ca977eSAlexander Kabaev /* In cpphash.c */ 813*c7ca977eSAlexander Kabaev 814*c7ca977eSAlexander Kabaev /* Lookup an identifier in the hashtable. Puts the identifier in the 815*c7ca977eSAlexander Kabaev table if it is not already there. */ 816*c7ca977eSAlexander Kabaev extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *, 817*c7ca977eSAlexander Kabaev unsigned int); 818*c7ca977eSAlexander Kabaev 819*c7ca977eSAlexander Kabaev typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *); 820*c7ca977eSAlexander Kabaev extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *); 821*c7ca977eSAlexander Kabaev 822*c7ca977eSAlexander Kabaev /* In cppmacro.c */ 823*c7ca977eSAlexander Kabaev extern void cpp_scan_nooutput (cpp_reader *); 824*c7ca977eSAlexander Kabaev extern int cpp_sys_macro_p (cpp_reader *); 825*c7ca977eSAlexander Kabaev extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, 826*c7ca977eSAlexander Kabaev unsigned int); 827*c7ca977eSAlexander Kabaev 828*c7ca977eSAlexander Kabaev /* In cppfiles.c */ 829*c7ca977eSAlexander Kabaev extern bool cpp_included (cpp_reader *, const char *); 830*c7ca977eSAlexander Kabaev extern void cpp_make_system_header (cpp_reader *, int, int); 831*c7ca977eSAlexander Kabaev extern bool cpp_push_include (cpp_reader *, const char *); 832*c7ca977eSAlexander Kabaev extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *); 833*c7ca977eSAlexander Kabaev extern const char *cpp_get_path (struct _cpp_file *); 834*c7ca977eSAlexander Kabaev extern cpp_dir *cpp_get_dir (struct _cpp_file *); 835*c7ca977eSAlexander Kabaev extern cpp_buffer *cpp_get_buffer (cpp_reader *); 836*c7ca977eSAlexander Kabaev extern struct _cpp_file *cpp_get_file (cpp_buffer *); 837*c7ca977eSAlexander Kabaev extern cpp_buffer *cpp_get_prev (cpp_buffer *); 838*c7ca977eSAlexander Kabaev 839*c7ca977eSAlexander Kabaev /* In cpppch.c */ 840*c7ca977eSAlexander Kabaev struct save_macro_data; 841*c7ca977eSAlexander Kabaev extern int cpp_save_state (cpp_reader *, FILE *); 842*c7ca977eSAlexander Kabaev extern int cpp_write_pch_deps (cpp_reader *, FILE *); 843*c7ca977eSAlexander Kabaev extern int cpp_write_pch_state (cpp_reader *, FILE *); 844*c7ca977eSAlexander Kabaev extern int cpp_valid_state (cpp_reader *, const char *, int); 845*c7ca977eSAlexander Kabaev extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **); 846*c7ca977eSAlexander Kabaev extern int cpp_read_state (cpp_reader *, const char *, FILE *, 847*c7ca977eSAlexander Kabaev struct save_macro_data *); 848*c7ca977eSAlexander Kabaev 849*c7ca977eSAlexander Kabaev #ifdef __cplusplus 850*c7ca977eSAlexander Kabaev } 851*c7ca977eSAlexander Kabaev #endif 852*c7ca977eSAlexander Kabaev 853*c7ca977eSAlexander Kabaev #endif /* ! LIBCPP_CPPLIB_H */ 854