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