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 323*cfbe5d01SPedro F. Giffuni /* APPLE LOCAL begin -Wnewline-eof 2001-08-23 --sts */ 324*cfbe5d01SPedro F. Giffuni /* Nonzero means warn if no newline at end of file. */ 325*cfbe5d01SPedro F. Giffuni unsigned char warn_newline_at_eof; 326*cfbe5d01SPedro F. Giffuni /* APPLE LOCAL end -Wnewline-eof 2001-08-23 --sts */ 327*cfbe5d01SPedro F. Giffuni 328c7ca977eSAlexander Kabaev /* Nonzero means warn about multicharacter charconsts. */ 329c7ca977eSAlexander Kabaev unsigned char warn_multichar; 330c7ca977eSAlexander Kabaev 331c7ca977eSAlexander Kabaev /* Nonzero means warn about various incompatibilities with 332c7ca977eSAlexander Kabaev traditional C. */ 333c7ca977eSAlexander Kabaev unsigned char warn_traditional; 334c7ca977eSAlexander Kabaev 335c7ca977eSAlexander Kabaev /* Nonzero means warn about long long numeric constants. */ 336c7ca977eSAlexander Kabaev unsigned char warn_long_long; 337c7ca977eSAlexander Kabaev 338c7ca977eSAlexander Kabaev /* Nonzero means warn about text after an #endif (or #else). */ 339c7ca977eSAlexander Kabaev unsigned char warn_endif_labels; 340c7ca977eSAlexander Kabaev 341c7ca977eSAlexander Kabaev /* Nonzero means warn about implicit sign changes owing to integer 342c7ca977eSAlexander Kabaev promotions. */ 343c7ca977eSAlexander Kabaev unsigned char warn_num_sign_change; 344c7ca977eSAlexander Kabaev 345c7ca977eSAlexander Kabaev /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode. 346c7ca977eSAlexander Kabaev Presumably the usage is protected by the appropriate #ifdef. */ 347c7ca977eSAlexander Kabaev unsigned char warn_variadic_macros; 348c7ca977eSAlexander Kabaev 349c7ca977eSAlexander Kabaev /* Nonzero means turn warnings into errors. */ 350c7ca977eSAlexander Kabaev unsigned char warnings_are_errors; 351c7ca977eSAlexander Kabaev 352c7ca977eSAlexander Kabaev /* Nonzero means we should look for header.gcc files that remap file 353c7ca977eSAlexander Kabaev names. */ 354c7ca977eSAlexander Kabaev unsigned char remap; 355c7ca977eSAlexander Kabaev 356c7ca977eSAlexander Kabaev /* Zero means dollar signs are punctuation. */ 357c7ca977eSAlexander Kabaev unsigned char dollars_in_ident; 358c7ca977eSAlexander Kabaev 359c7ca977eSAlexander Kabaev /* Nonzero means UCNs are accepted in identifiers. */ 360c7ca977eSAlexander Kabaev unsigned char extended_identifiers; 361c7ca977eSAlexander Kabaev 362c7ca977eSAlexander Kabaev /* True if we should warn about dollars in identifiers or numbers 363c7ca977eSAlexander Kabaev for this translation unit. */ 364c7ca977eSAlexander Kabaev unsigned char warn_dollars; 365c7ca977eSAlexander Kabaev 366c7ca977eSAlexander Kabaev /* Nonzero means warn if undefined identifiers are evaluated in an #if. */ 367c7ca977eSAlexander Kabaev unsigned char warn_undef; 368c7ca977eSAlexander Kabaev 369c7ca977eSAlexander Kabaev /* Nonzero means warn of unused macros from the main file. */ 370c7ca977eSAlexander Kabaev unsigned char warn_unused_macros; 371c7ca977eSAlexander Kabaev 372c7ca977eSAlexander Kabaev /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */ 373c7ca977eSAlexander Kabaev unsigned char c99; 374c7ca977eSAlexander Kabaev 375c7ca977eSAlexander Kabaev /* Nonzero if we are conforming to a specific C or C++ standard. */ 376c7ca977eSAlexander Kabaev unsigned char std; 377c7ca977eSAlexander Kabaev 378c7ca977eSAlexander Kabaev /* Nonzero means give all the error messages the ANSI standard requires. */ 379c7ca977eSAlexander Kabaev unsigned char pedantic; 380c7ca977eSAlexander Kabaev 381c7ca977eSAlexander Kabaev /* Nonzero means we're looking at already preprocessed code, so don't 382c7ca977eSAlexander Kabaev bother trying to do macro expansion and whatnot. */ 383c7ca977eSAlexander Kabaev unsigned char preprocessed; 384c7ca977eSAlexander Kabaev 385c7ca977eSAlexander Kabaev /* Print column number in error messages. */ 386c7ca977eSAlexander Kabaev unsigned char show_column; 387c7ca977eSAlexander Kabaev 388c7ca977eSAlexander Kabaev /* Nonzero means handle C++ alternate operator names. */ 389c7ca977eSAlexander Kabaev unsigned char operator_names; 390c7ca977eSAlexander Kabaev 391c7ca977eSAlexander Kabaev /* True for traditional preprocessing. */ 392c7ca977eSAlexander Kabaev unsigned char traditional; 393c7ca977eSAlexander Kabaev 394c7ca977eSAlexander Kabaev /* Holds the name of the target (execution) character set. */ 395c7ca977eSAlexander Kabaev const char *narrow_charset; 396c7ca977eSAlexander Kabaev 397c7ca977eSAlexander Kabaev /* Holds the name of the target wide character set. */ 398c7ca977eSAlexander Kabaev const char *wide_charset; 399c7ca977eSAlexander Kabaev 400c7ca977eSAlexander Kabaev /* Holds the name of the input character set. */ 401c7ca977eSAlexander Kabaev const char *input_charset; 402c7ca977eSAlexander Kabaev 403c7ca977eSAlexander Kabaev /* The minimum permitted level of normalization before a warning 404c7ca977eSAlexander Kabaev is generated. */ 405c7ca977eSAlexander Kabaev enum cpp_normalize_level warn_normalize; 406c7ca977eSAlexander Kabaev 407c7ca977eSAlexander Kabaev /* True to warn about precompiled header files we couldn't use. */ 408c7ca977eSAlexander Kabaev bool warn_invalid_pch; 409c7ca977eSAlexander Kabaev 410c7ca977eSAlexander Kabaev /* True if dependencies should be restored from a precompiled header. */ 411c7ca977eSAlexander Kabaev bool restore_pch_deps; 412c7ca977eSAlexander Kabaev 413c7ca977eSAlexander Kabaev /* Dependency generation. */ 414c7ca977eSAlexander Kabaev struct 415c7ca977eSAlexander Kabaev { 416c7ca977eSAlexander Kabaev /* Style of header dependencies to generate. */ 417c7ca977eSAlexander Kabaev enum cpp_deps_style style; 418c7ca977eSAlexander Kabaev 419c7ca977eSAlexander Kabaev /* Assume missing files are generated files. */ 420c7ca977eSAlexander Kabaev bool missing_files; 421c7ca977eSAlexander Kabaev 422c7ca977eSAlexander Kabaev /* Generate phony targets for each dependency apart from the first 423c7ca977eSAlexander Kabaev one. */ 424c7ca977eSAlexander Kabaev bool phony_targets; 425c7ca977eSAlexander Kabaev 426c7ca977eSAlexander Kabaev /* If true, no dependency is generated on the main file. */ 427c7ca977eSAlexander Kabaev bool ignore_main_file; 428c7ca977eSAlexander Kabaev } deps; 429c7ca977eSAlexander Kabaev 430c7ca977eSAlexander Kabaev /* Target-specific features set by the front end or client. */ 431c7ca977eSAlexander Kabaev 432c7ca977eSAlexander Kabaev /* Precision for target CPP arithmetic, target characters, target 433c7ca977eSAlexander Kabaev ints and target wide characters, respectively. */ 434c7ca977eSAlexander Kabaev size_t precision, char_precision, int_precision, wchar_precision; 435c7ca977eSAlexander Kabaev 436c7ca977eSAlexander Kabaev /* True means chars (wide chars) are unsigned. */ 437c7ca977eSAlexander Kabaev bool unsigned_char, unsigned_wchar; 438c7ca977eSAlexander Kabaev 439c7ca977eSAlexander Kabaev /* True if the most significant byte in a word has the lowest 440c7ca977eSAlexander Kabaev address in memory. */ 441c7ca977eSAlexander Kabaev bool bytes_big_endian; 442c7ca977eSAlexander Kabaev 443c7ca977eSAlexander Kabaev /* Nonzero means __STDC__ should have the value 0 in system headers. */ 444c7ca977eSAlexander Kabaev unsigned char stdc_0_in_system_headers; 445c7ca977eSAlexander Kabaev 446c7ca977eSAlexander Kabaev /* True means error callback should be used for diagnostics. */ 447c7ca977eSAlexander Kabaev bool client_diagnostic; 44881e5b017SPedro F. Giffuni 44981e5b017SPedro F. Giffuni /* True disables tokenization outside of preprocessing directives. */ 45081e5b017SPedro F. Giffuni bool directives_only; 451c7ca977eSAlexander Kabaev }; 452c7ca977eSAlexander Kabaev 453c7ca977eSAlexander Kabaev /* Callback for header lookup for HEADER, which is the name of a 454c7ca977eSAlexander Kabaev source file. It is used as a method of last resort to find headers 455c7ca977eSAlexander Kabaev that are not otherwise found during the normal include processing. 456c7ca977eSAlexander Kabaev The return value is the malloced name of a header to try and open, 457c7ca977eSAlexander Kabaev if any, or NULL otherwise. This callback is called only if the 458c7ca977eSAlexander Kabaev header is otherwise unfound. */ 459c7ca977eSAlexander Kabaev typedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **); 460c7ca977eSAlexander Kabaev 461c7ca977eSAlexander Kabaev /* Call backs to cpplib client. */ 462c7ca977eSAlexander Kabaev struct cpp_callbacks 463c7ca977eSAlexander Kabaev { 464c7ca977eSAlexander Kabaev /* Called when a new line of preprocessed output is started. */ 465c7ca977eSAlexander Kabaev void (*line_change) (cpp_reader *, const cpp_token *, int); 466c7ca977eSAlexander Kabaev 467c7ca977eSAlexander Kabaev /* Called when switching to/from a new file. 468c7ca977eSAlexander Kabaev The line_map is for the new file. It is NULL if there is no new file. 469c7ca977eSAlexander Kabaev (In C this happens when done with <built-in>+<command line> and also 470c7ca977eSAlexander Kabaev when done with a main file.) This can be used for resource cleanup. */ 471c7ca977eSAlexander Kabaev void (*file_change) (cpp_reader *, const struct line_map *); 472c7ca977eSAlexander Kabaev 473c7ca977eSAlexander Kabaev void (*dir_change) (cpp_reader *, const char *); 474c7ca977eSAlexander Kabaev void (*include) (cpp_reader *, unsigned int, const unsigned char *, 475c7ca977eSAlexander Kabaev const char *, int, const cpp_token **); 476c7ca977eSAlexander Kabaev void (*define) (cpp_reader *, unsigned int, cpp_hashnode *); 477c7ca977eSAlexander Kabaev void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *); 478c7ca977eSAlexander Kabaev void (*ident) (cpp_reader *, unsigned int, const cpp_string *); 479c7ca977eSAlexander Kabaev void (*def_pragma) (cpp_reader *, unsigned int); 480c7ca977eSAlexander Kabaev int (*valid_pch) (cpp_reader *, const char *, int); 481c7ca977eSAlexander Kabaev void (*read_pch) (cpp_reader *, const char *, int, const char *); 482c7ca977eSAlexander Kabaev missing_header_cb missing_header; 483c7ca977eSAlexander Kabaev 484c7ca977eSAlexander Kabaev /* Called to emit a diagnostic if client_diagnostic option is true. 485c7ca977eSAlexander Kabaev This callback receives the translated message. */ 486c7ca977eSAlexander Kabaev void (*error) (cpp_reader *, int, const char *, va_list *) 487c7ca977eSAlexander Kabaev ATTRIBUTE_FPTR_PRINTF(3,0); 488c7ca977eSAlexander Kabaev }; 489c7ca977eSAlexander Kabaev 490c7ca977eSAlexander Kabaev /* Chain of directories to look for include files in. */ 491c7ca977eSAlexander Kabaev struct cpp_dir 492c7ca977eSAlexander Kabaev { 493c7ca977eSAlexander Kabaev /* NULL-terminated singly-linked list. */ 494c7ca977eSAlexander Kabaev struct cpp_dir *next; 495c7ca977eSAlexander Kabaev 496c7ca977eSAlexander Kabaev /* NAME of the directory, NUL-terminated. */ 497c7ca977eSAlexander Kabaev char *name; 498c7ca977eSAlexander Kabaev unsigned int len; 499c7ca977eSAlexander Kabaev 500c7ca977eSAlexander Kabaev /* One if a system header, two if a system header that has extern 501c7ca977eSAlexander Kabaev "C" guards for C++. */ 502c7ca977eSAlexander Kabaev unsigned char sysp; 503c7ca977eSAlexander Kabaev 504c7ca977eSAlexander Kabaev /* Mapping of file names for this directory for MS-DOS and related 505c7ca977eSAlexander Kabaev platforms. A NULL-terminated array of (from, to) pairs. */ 506c7ca977eSAlexander Kabaev const char **name_map; 507c7ca977eSAlexander Kabaev 508c7ca977eSAlexander Kabaev /* Routine to construct pathname, given the search path name and the 509c7ca977eSAlexander Kabaev HEADER we are trying to find, return a constructed pathname to 510c7ca977eSAlexander Kabaev try and open. If this is NULL, the constructed pathname is as 511c7ca977eSAlexander Kabaev constructed by append_file_to_dir. */ 512c7ca977eSAlexander Kabaev char *(*construct) (const char *header, cpp_dir *dir); 513c7ca977eSAlexander Kabaev 514c7ca977eSAlexander Kabaev /* The C front end uses these to recognize duplicated 515c7ca977eSAlexander Kabaev directories in the search path. */ 516c7ca977eSAlexander Kabaev ino_t ino; 517c7ca977eSAlexander Kabaev dev_t dev; 518c7ca977eSAlexander Kabaev 519c7ca977eSAlexander Kabaev /* Is this a user-supplied directory? */ 520c7ca977eSAlexander Kabaev bool user_supplied_p; 521c7ca977eSAlexander Kabaev }; 522c7ca977eSAlexander Kabaev 523c7ca977eSAlexander Kabaev /* Name under which this program was invoked. */ 524c7ca977eSAlexander Kabaev extern const char *progname; 525c7ca977eSAlexander Kabaev 526c7ca977eSAlexander Kabaev /* The structure of a node in the hash table. The hash table has 527c7ca977eSAlexander Kabaev entries for all identifiers: either macros defined by #define 528c7ca977eSAlexander Kabaev commands (type NT_MACRO), assertions created with #assert 529c7ca977eSAlexander Kabaev (NT_ASSERTION), or neither of the above (NT_VOID). Builtin macros 530c7ca977eSAlexander Kabaev like __LINE__ are flagged NODE_BUILTIN. Poisoned identifiers are 531c7ca977eSAlexander Kabaev flagged NODE_POISONED. NODE_OPERATOR (C++ only) indicates an 532c7ca977eSAlexander Kabaev identifier that behaves like an operator such as "xor". 533c7ca977eSAlexander Kabaev NODE_DIAGNOSTIC is for speed in lex_token: it indicates a 534c7ca977eSAlexander Kabaev diagnostic may be required for this node. Currently this only 535c7ca977eSAlexander Kabaev applies to __VA_ARGS__ and poisoned identifiers. */ 536c7ca977eSAlexander Kabaev 537c7ca977eSAlexander Kabaev /* Hash node flags. */ 538c7ca977eSAlexander Kabaev #define NODE_OPERATOR (1 << 0) /* C++ named operator. */ 539c7ca977eSAlexander Kabaev #define NODE_POISONED (1 << 1) /* Poisoned identifier. */ 540c7ca977eSAlexander Kabaev #define NODE_BUILTIN (1 << 2) /* Builtin macro. */ 541c7ca977eSAlexander Kabaev #define NODE_DIAGNOSTIC (1 << 3) /* Possible diagnostic when lexed. */ 542c7ca977eSAlexander Kabaev #define NODE_WARN (1 << 4) /* Warn if redefined or undefined. */ 543c7ca977eSAlexander Kabaev #define NODE_DISABLED (1 << 5) /* A disabled macro. */ 544c7ca977eSAlexander Kabaev #define NODE_MACRO_ARG (1 << 6) /* Used during #define processing. */ 545c7ca977eSAlexander Kabaev 546c7ca977eSAlexander Kabaev /* Different flavors of hash node. */ 547c7ca977eSAlexander Kabaev enum node_type 548c7ca977eSAlexander Kabaev { 549c7ca977eSAlexander Kabaev NT_VOID = 0, /* No definition yet. */ 550c7ca977eSAlexander Kabaev NT_MACRO, /* A macro of some form. */ 551c7ca977eSAlexander Kabaev NT_ASSERTION /* Predicate for #assert. */ 552c7ca977eSAlexander Kabaev }; 553c7ca977eSAlexander Kabaev 554c7ca977eSAlexander Kabaev /* Different flavors of builtin macro. _Pragma is an operator, but we 555c7ca977eSAlexander Kabaev handle it with the builtin code for efficiency reasons. */ 556c7ca977eSAlexander Kabaev enum builtin_type 557c7ca977eSAlexander Kabaev { 558c7ca977eSAlexander Kabaev BT_SPECLINE = 0, /* `__LINE__' */ 559c7ca977eSAlexander Kabaev BT_DATE, /* `__DATE__' */ 560c7ca977eSAlexander Kabaev BT_FILE, /* `__FILE__' */ 561c7ca977eSAlexander Kabaev BT_BASE_FILE, /* `__BASE_FILE__' */ 562c7ca977eSAlexander Kabaev BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ 563c7ca977eSAlexander Kabaev BT_TIME, /* `__TIME__' */ 564c7ca977eSAlexander Kabaev BT_STDC, /* `__STDC__' */ 565c7ca977eSAlexander Kabaev BT_PRAGMA, /* `_Pragma' operator */ 566bdc971ebSEd Schouten BT_TIMESTAMP, /* `__TIMESTAMP__' */ 567bdc971ebSEd Schouten BT_COUNTER /* `__COUNTER__' */ 568c7ca977eSAlexander Kabaev }; 569c7ca977eSAlexander Kabaev 570c7ca977eSAlexander Kabaev #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) 571c7ca977eSAlexander Kabaev #define HT_NODE(NODE) ((ht_identifier *) (NODE)) 572c7ca977eSAlexander Kabaev #define NODE_LEN(NODE) HT_LEN (&(NODE)->ident) 573c7ca977eSAlexander Kabaev #define NODE_NAME(NODE) HT_STR (&(NODE)->ident) 574c7ca977eSAlexander Kabaev 575c7ca977eSAlexander Kabaev /* Specify which field, if any, of the union is used. */ 576c7ca977eSAlexander Kabaev 577c7ca977eSAlexander Kabaev enum { 578c7ca977eSAlexander Kabaev NTV_MACRO, 579c7ca977eSAlexander Kabaev NTV_ANSWER, 580c7ca977eSAlexander Kabaev NTV_BUILTIN, 581c7ca977eSAlexander Kabaev NTV_ARGUMENT, 582c7ca977eSAlexander Kabaev NTV_NONE 583c7ca977eSAlexander Kabaev }; 584c7ca977eSAlexander Kabaev 585c7ca977eSAlexander Kabaev #define CPP_HASHNODE_VALUE_IDX(HNODE) \ 586c7ca977eSAlexander Kabaev ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT \ 587c7ca977eSAlexander Kabaev : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN) \ 588c7ca977eSAlexander Kabaev ? NTV_BUILTIN : NTV_MACRO) \ 589c7ca977eSAlexander Kabaev : HNODE.type == NT_ASSERTION ? NTV_ANSWER \ 590c7ca977eSAlexander Kabaev : NTV_NONE) 591c7ca977eSAlexander Kabaev 592c7ca977eSAlexander Kabaev /* The common part of an identifier node shared amongst all 3 C front 593c7ca977eSAlexander Kabaev ends. Also used to store CPP identifiers, which are a superset of 594c7ca977eSAlexander Kabaev identifiers in the grammatical sense. */ 595c7ca977eSAlexander Kabaev 596c7ca977eSAlexander Kabaev union _cpp_hashnode_value GTY(()) 597c7ca977eSAlexander Kabaev { 598c7ca977eSAlexander Kabaev /* If a macro. */ 599c7ca977eSAlexander Kabaev cpp_macro * GTY((tag ("NTV_MACRO"))) macro; 600c7ca977eSAlexander Kabaev /* Answers to an assertion. */ 601c7ca977eSAlexander Kabaev struct answer * GTY ((tag ("NTV_ANSWER"))) answers; 602c7ca977eSAlexander Kabaev /* Code for a builtin macro. */ 603c7ca977eSAlexander Kabaev enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin; 604c7ca977eSAlexander Kabaev /* Macro argument index. */ 605c7ca977eSAlexander Kabaev unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index; 606c7ca977eSAlexander Kabaev }; 607c7ca977eSAlexander Kabaev 608c7ca977eSAlexander Kabaev struct cpp_hashnode GTY(()) 609c7ca977eSAlexander Kabaev { 610c7ca977eSAlexander Kabaev struct ht_identifier ident; 611c7ca977eSAlexander Kabaev unsigned int is_directive : 1; 612c7ca977eSAlexander Kabaev unsigned int directive_index : 7; /* If is_directive, 613c7ca977eSAlexander Kabaev then index into directive table. 614c7ca977eSAlexander Kabaev Otherwise, a NODE_OPERATOR. */ 615c7ca977eSAlexander Kabaev unsigned char rid_code; /* Rid code - for front ends. */ 616c7ca977eSAlexander Kabaev ENUM_BITFIELD(node_type) type : 8; /* CPP node type. */ 617c7ca977eSAlexander Kabaev unsigned char flags; /* CPP flags. */ 618c7ca977eSAlexander Kabaev 619c7ca977eSAlexander Kabaev union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value; 620c7ca977eSAlexander Kabaev }; 621c7ca977eSAlexander Kabaev 622c7ca977eSAlexander Kabaev /* Call this first to get a handle to pass to other functions. 623c7ca977eSAlexander Kabaev 624c7ca977eSAlexander Kabaev If you want cpplib to manage its own hashtable, pass in a NULL 625c7ca977eSAlexander Kabaev pointer. Otherwise you should pass in an initialized hash table 626c7ca977eSAlexander Kabaev that cpplib will share; this technique is used by the C front 627c7ca977eSAlexander Kabaev ends. */ 628c7ca977eSAlexander Kabaev extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *, 629c7ca977eSAlexander Kabaev struct line_maps *); 630c7ca977eSAlexander Kabaev 631c7ca977eSAlexander Kabaev /* Call this to change the selected language standard (e.g. because of 632c7ca977eSAlexander Kabaev command line options). */ 633c7ca977eSAlexander Kabaev extern void cpp_set_lang (cpp_reader *, enum c_lang); 634c7ca977eSAlexander Kabaev 635c7ca977eSAlexander Kabaev /* Set the include paths. */ 636c7ca977eSAlexander Kabaev extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); 637c7ca977eSAlexander Kabaev 638c7ca977eSAlexander Kabaev /* Call these to get pointers to the options, callback, and deps 639c7ca977eSAlexander Kabaev structures for a given reader. These pointers are good until you 640c7ca977eSAlexander Kabaev call cpp_finish on that reader. You can either edit the callbacks 641c7ca977eSAlexander Kabaev through the pointer returned from cpp_get_callbacks, or set them 642c7ca977eSAlexander Kabaev with cpp_set_callbacks. */ 643c7ca977eSAlexander Kabaev extern cpp_options *cpp_get_options (cpp_reader *); 644c7ca977eSAlexander Kabaev extern cpp_callbacks *cpp_get_callbacks (cpp_reader *); 645c7ca977eSAlexander Kabaev extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *); 646c7ca977eSAlexander Kabaev extern struct deps *cpp_get_deps (cpp_reader *); 647c7ca977eSAlexander Kabaev 648c7ca977eSAlexander Kabaev /* This function reads the file, but does not start preprocessing. It 649c7ca977eSAlexander Kabaev returns the name of the original file; this is the same as the 650c7ca977eSAlexander Kabaev input file, except for preprocessed input. This will generate at 651c7ca977eSAlexander Kabaev least one file change callback, and possibly a line change callback 652c7ca977eSAlexander Kabaev too. If there was an error opening the file, it returns NULL. */ 653c7ca977eSAlexander Kabaev extern const char *cpp_read_main_file (cpp_reader *, const char *); 654c7ca977eSAlexander Kabaev 65581e5b017SPedro F. Giffuni /* Set up built-ins with special behavior. Use cpp_init_builtins() 65681e5b017SPedro F. Giffuni instead unless your know what you are doing. */ 65781e5b017SPedro F. Giffuni extern void cpp_init_special_builtins (cpp_reader *); 65881e5b017SPedro F. Giffuni 659c7ca977eSAlexander Kabaev /* Set up built-ins like __FILE__. */ 660c7ca977eSAlexander Kabaev extern void cpp_init_builtins (cpp_reader *, int); 661c7ca977eSAlexander Kabaev 662c7ca977eSAlexander Kabaev /* This is called after options have been parsed, and partially 663c7ca977eSAlexander Kabaev processed. */ 664c7ca977eSAlexander Kabaev extern void cpp_post_options (cpp_reader *); 665c7ca977eSAlexander Kabaev 666c7ca977eSAlexander Kabaev /* Set up translation to the target character set. */ 667c7ca977eSAlexander Kabaev extern void cpp_init_iconv (cpp_reader *); 668c7ca977eSAlexander Kabaev 669c7ca977eSAlexander Kabaev /* Call this to finish preprocessing. If you requested dependency 670c7ca977eSAlexander Kabaev generation, pass an open stream to write the information to, 671c7ca977eSAlexander Kabaev otherwise NULL. It is your responsibility to close the stream. 672c7ca977eSAlexander Kabaev 673c7ca977eSAlexander Kabaev Returns cpp_errors (pfile). */ 674c7ca977eSAlexander Kabaev extern int cpp_finish (cpp_reader *, FILE *deps_stream); 675c7ca977eSAlexander Kabaev 676c7ca977eSAlexander Kabaev /* Call this to release the handle at the end of preprocessing. Any 677c7ca977eSAlexander Kabaev use of the handle after this function returns is invalid. Returns 678c7ca977eSAlexander Kabaev cpp_errors (pfile). */ 679c7ca977eSAlexander Kabaev extern void cpp_destroy (cpp_reader *); 680c7ca977eSAlexander Kabaev 681c7ca977eSAlexander Kabaev /* Error count. */ 682c7ca977eSAlexander Kabaev extern unsigned int cpp_errors (cpp_reader *); 683c7ca977eSAlexander Kabaev 684c7ca977eSAlexander Kabaev extern unsigned int cpp_token_len (const cpp_token *); 685c7ca977eSAlexander Kabaev extern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *); 686c7ca977eSAlexander Kabaev extern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *, 687c7ca977eSAlexander Kabaev unsigned char *, bool); 688c7ca977eSAlexander Kabaev extern void cpp_register_pragma (cpp_reader *, const char *, const char *, 689c7ca977eSAlexander Kabaev void (*) (cpp_reader *), bool); 690c7ca977eSAlexander Kabaev extern void cpp_register_deferred_pragma (cpp_reader *, const char *, 691c7ca977eSAlexander Kabaev const char *, unsigned, bool, bool); 692c7ca977eSAlexander Kabaev extern int cpp_avoid_paste (cpp_reader *, const cpp_token *, 693c7ca977eSAlexander Kabaev const cpp_token *); 694c7ca977eSAlexander Kabaev extern const cpp_token *cpp_get_token (cpp_reader *); 695c7ca977eSAlexander Kabaev extern const unsigned char *cpp_macro_definition (cpp_reader *, 696c7ca977eSAlexander Kabaev const cpp_hashnode *); 697c7ca977eSAlexander Kabaev extern void _cpp_backup_tokens (cpp_reader *, unsigned int); 698c7ca977eSAlexander Kabaev 699c7ca977eSAlexander Kabaev /* Evaluate a CPP_CHAR or CPP_WCHAR token. */ 700c7ca977eSAlexander Kabaev extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *, 701c7ca977eSAlexander Kabaev unsigned int *, int *); 702c7ca977eSAlexander Kabaev /* Evaluate a vector of CPP_STRING or CPP_WSTRING tokens. */ 703c7ca977eSAlexander Kabaev extern bool cpp_interpret_string (cpp_reader *, 704c7ca977eSAlexander Kabaev const cpp_string *, size_t, 705c7ca977eSAlexander Kabaev cpp_string *, bool); 706c7ca977eSAlexander Kabaev extern bool cpp_interpret_string_notranslate (cpp_reader *, 707c7ca977eSAlexander Kabaev const cpp_string *, size_t, 708c7ca977eSAlexander Kabaev cpp_string *, bool); 709c7ca977eSAlexander Kabaev 710c7ca977eSAlexander Kabaev /* Convert a host character constant to the execution character set. */ 711c7ca977eSAlexander Kabaev extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); 712c7ca977eSAlexander Kabaev 713c7ca977eSAlexander Kabaev /* Used to register macros and assertions, perhaps from the command line. 714c7ca977eSAlexander Kabaev The text is the same as the command line argument. */ 715c7ca977eSAlexander Kabaev extern void cpp_define (cpp_reader *, const char *); 716c7ca977eSAlexander Kabaev extern void cpp_assert (cpp_reader *, const char *); 717c7ca977eSAlexander Kabaev extern void cpp_undef (cpp_reader *, const char *); 718c7ca977eSAlexander Kabaev extern void cpp_unassert (cpp_reader *, const char *); 719c7ca977eSAlexander Kabaev 720c7ca977eSAlexander Kabaev /* Undefine all macros and assertions. */ 721c7ca977eSAlexander Kabaev extern void cpp_undef_all (cpp_reader *); 722c7ca977eSAlexander Kabaev 723c7ca977eSAlexander Kabaev extern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *, 724c7ca977eSAlexander Kabaev size_t, int); 725c7ca977eSAlexander Kabaev extern int cpp_defined (cpp_reader *, const unsigned char *, int); 726c7ca977eSAlexander Kabaev 727c7ca977eSAlexander Kabaev /* A preprocessing number. Code assumes that any unused high bits of 728c7ca977eSAlexander Kabaev the double integer are set to zero. */ 729c7ca977eSAlexander Kabaev typedef unsigned HOST_WIDE_INT cpp_num_part; 730c7ca977eSAlexander Kabaev typedef struct cpp_num cpp_num; 731c7ca977eSAlexander Kabaev struct cpp_num 732c7ca977eSAlexander Kabaev { 733c7ca977eSAlexander Kabaev cpp_num_part high; 734c7ca977eSAlexander Kabaev cpp_num_part low; 735c7ca977eSAlexander Kabaev bool unsignedp; /* True if value should be treated as unsigned. */ 736c7ca977eSAlexander Kabaev bool overflow; /* True if the most recent calculation overflowed. */ 737c7ca977eSAlexander Kabaev }; 738c7ca977eSAlexander Kabaev 739c7ca977eSAlexander Kabaev /* cpplib provides two interfaces for interpretation of preprocessing 740c7ca977eSAlexander Kabaev numbers. 741c7ca977eSAlexander Kabaev 742c7ca977eSAlexander Kabaev cpp_classify_number categorizes numeric constants according to 743c7ca977eSAlexander Kabaev their field (integer, floating point, or invalid), radix (decimal, 744c7ca977eSAlexander Kabaev octal, hexadecimal), and type suffixes. */ 745c7ca977eSAlexander Kabaev 746c7ca977eSAlexander Kabaev #define CPP_N_CATEGORY 0x000F 747c7ca977eSAlexander Kabaev #define CPP_N_INVALID 0x0000 748c7ca977eSAlexander Kabaev #define CPP_N_INTEGER 0x0001 749c7ca977eSAlexander Kabaev #define CPP_N_FLOATING 0x0002 750c7ca977eSAlexander Kabaev 751c7ca977eSAlexander Kabaev #define CPP_N_WIDTH 0x00F0 752c7ca977eSAlexander Kabaev #define CPP_N_SMALL 0x0010 /* int, float. */ 753c7ca977eSAlexander Kabaev #define CPP_N_MEDIUM 0x0020 /* long, double. */ 754c7ca977eSAlexander Kabaev #define CPP_N_LARGE 0x0040 /* long long, long double. */ 755c7ca977eSAlexander Kabaev 756c7ca977eSAlexander Kabaev #define CPP_N_RADIX 0x0F00 757c7ca977eSAlexander Kabaev #define CPP_N_DECIMAL 0x0100 758c7ca977eSAlexander Kabaev #define CPP_N_HEX 0x0200 759c7ca977eSAlexander Kabaev #define CPP_N_OCTAL 0x0400 760e639f257SPedro F. Giffuni #define CPP_N_BINARY 0x0800 761c7ca977eSAlexander Kabaev 762c7ca977eSAlexander Kabaev #define CPP_N_UNSIGNED 0x1000 /* Properties. */ 763c7ca977eSAlexander Kabaev #define CPP_N_IMAGINARY 0x2000 764c7ca977eSAlexander Kabaev #define CPP_N_DFLOAT 0x4000 765691f7fadSPedro F. Giffuni #define CPP_N_DEFAULT 0x8000 766c7ca977eSAlexander Kabaev 767c7ca977eSAlexander Kabaev /* Classify a CPP_NUMBER token. The return value is a combination of 768c7ca977eSAlexander Kabaev the flags from the above sets. */ 769c7ca977eSAlexander Kabaev extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *); 770c7ca977eSAlexander Kabaev 771c7ca977eSAlexander Kabaev /* Evaluate a token classified as category CPP_N_INTEGER. */ 772c7ca977eSAlexander Kabaev extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *, 773c7ca977eSAlexander Kabaev unsigned int type); 774c7ca977eSAlexander Kabaev 775c7ca977eSAlexander Kabaev /* Sign extend a number, with PRECISION significant bits and all 776c7ca977eSAlexander Kabaev others assumed clear, to fill out a cpp_num structure. */ 777c7ca977eSAlexander Kabaev cpp_num cpp_num_sign_extend (cpp_num, size_t); 778c7ca977eSAlexander Kabaev 779c7ca977eSAlexander Kabaev /* Diagnostic levels. To get a diagnostic without associating a 780c7ca977eSAlexander Kabaev position in the translation unit with it, use cpp_error_with_line 781c7ca977eSAlexander Kabaev with a line number of zero. */ 782c7ca977eSAlexander Kabaev 783c7ca977eSAlexander Kabaev /* Warning, an error with -Werror. */ 784c7ca977eSAlexander Kabaev #define CPP_DL_WARNING 0x00 785c7ca977eSAlexander Kabaev /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */ 786c7ca977eSAlexander Kabaev #define CPP_DL_WARNING_SYSHDR 0x01 787c7ca977eSAlexander Kabaev /* Warning, an error with -pedantic-errors or -Werror. */ 788c7ca977eSAlexander Kabaev #define CPP_DL_PEDWARN 0x02 789c7ca977eSAlexander Kabaev /* An error. */ 790c7ca977eSAlexander Kabaev #define CPP_DL_ERROR 0x03 791c7ca977eSAlexander Kabaev /* An internal consistency check failed. Prints "internal error: ", 792c7ca977eSAlexander Kabaev otherwise the same as CPP_DL_ERROR. */ 793c7ca977eSAlexander Kabaev #define CPP_DL_ICE 0x04 794c7ca977eSAlexander Kabaev /* Extracts a diagnostic level from an int. */ 795c7ca977eSAlexander Kabaev #define CPP_DL_EXTRACT(l) (l & 0xf) 796c7ca977eSAlexander Kabaev /* Nonzero if a diagnostic level is one of the warnings. */ 797c7ca977eSAlexander Kabaev #define CPP_DL_WARNING_P(l) (CPP_DL_EXTRACT (l) >= CPP_DL_WARNING \ 798c7ca977eSAlexander Kabaev && CPP_DL_EXTRACT (l) <= CPP_DL_PEDWARN) 799c7ca977eSAlexander Kabaev 800c7ca977eSAlexander Kabaev /* Output a diagnostic of some kind. */ 801c7ca977eSAlexander Kabaev extern void cpp_error (cpp_reader *, int, const char *msgid, ...) 802c7ca977eSAlexander Kabaev ATTRIBUTE_PRINTF_3; 803c7ca977eSAlexander Kabaev 804c7ca977eSAlexander Kabaev /* Output a diagnostic with "MSGID: " preceding the 805c7ca977eSAlexander Kabaev error string of errno. No location is printed. */ 806c7ca977eSAlexander Kabaev extern void cpp_errno (cpp_reader *, int, const char *msgid); 807c7ca977eSAlexander Kabaev 808c7ca977eSAlexander Kabaev /* Same as cpp_error, except additionally specifies a position as a 809c7ca977eSAlexander Kabaev (translation unit) physical line and physical column. If the line is 810c7ca977eSAlexander Kabaev zero, then no location is printed. */ 811c7ca977eSAlexander Kabaev extern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned, 812c7ca977eSAlexander Kabaev const char *msgid, ...) ATTRIBUTE_PRINTF_5; 813c7ca977eSAlexander Kabaev 814c7ca977eSAlexander Kabaev /* In cpplex.c */ 815c7ca977eSAlexander Kabaev extern int cpp_ideq (const cpp_token *, const char *); 816c7ca977eSAlexander Kabaev extern void cpp_output_line (cpp_reader *, FILE *); 817c7ca977eSAlexander Kabaev extern void cpp_output_token (const cpp_token *, FILE *); 818c7ca977eSAlexander Kabaev extern const char *cpp_type2name (enum cpp_ttype); 819c7ca977eSAlexander Kabaev /* Returns the value of an escape sequence, truncated to the correct 820c7ca977eSAlexander Kabaev target precision. PSTR points to the input pointer, which is just 821c7ca977eSAlexander Kabaev after the backslash. LIMIT is how much text we have. WIDE is true 822c7ca977eSAlexander Kabaev if the escape sequence is part of a wide character constant or 823c7ca977eSAlexander Kabaev string literal. Handles all relevant diagnostics. */ 824c7ca977eSAlexander Kabaev extern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr, 825c7ca977eSAlexander Kabaev const unsigned char *limit, int wide); 826c7ca977eSAlexander Kabaev 827c7ca977eSAlexander Kabaev /* In cpphash.c */ 828c7ca977eSAlexander Kabaev 829c7ca977eSAlexander Kabaev /* Lookup an identifier in the hashtable. Puts the identifier in the 830c7ca977eSAlexander Kabaev table if it is not already there. */ 831c7ca977eSAlexander Kabaev extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *, 832c7ca977eSAlexander Kabaev unsigned int); 833c7ca977eSAlexander Kabaev 834c7ca977eSAlexander Kabaev typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *); 835c7ca977eSAlexander Kabaev extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *); 836c7ca977eSAlexander Kabaev 837c7ca977eSAlexander Kabaev /* In cppmacro.c */ 838c7ca977eSAlexander Kabaev extern void cpp_scan_nooutput (cpp_reader *); 839c7ca977eSAlexander Kabaev extern int cpp_sys_macro_p (cpp_reader *); 840c7ca977eSAlexander Kabaev extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, 841c7ca977eSAlexander Kabaev unsigned int); 842c7ca977eSAlexander Kabaev 843c7ca977eSAlexander Kabaev /* In cppfiles.c */ 844c7ca977eSAlexander Kabaev extern bool cpp_included (cpp_reader *, const char *); 845c7ca977eSAlexander Kabaev extern void cpp_make_system_header (cpp_reader *, int, int); 846c7ca977eSAlexander Kabaev extern bool cpp_push_include (cpp_reader *, const char *); 847c7ca977eSAlexander Kabaev extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *); 848c7ca977eSAlexander Kabaev extern const char *cpp_get_path (struct _cpp_file *); 849c7ca977eSAlexander Kabaev extern cpp_dir *cpp_get_dir (struct _cpp_file *); 850c7ca977eSAlexander Kabaev extern cpp_buffer *cpp_get_buffer (cpp_reader *); 851c7ca977eSAlexander Kabaev extern struct _cpp_file *cpp_get_file (cpp_buffer *); 852c7ca977eSAlexander Kabaev extern cpp_buffer *cpp_get_prev (cpp_buffer *); 853c7ca977eSAlexander Kabaev 854c7ca977eSAlexander Kabaev /* In cpppch.c */ 855c7ca977eSAlexander Kabaev struct save_macro_data; 856c7ca977eSAlexander Kabaev extern int cpp_save_state (cpp_reader *, FILE *); 857c7ca977eSAlexander Kabaev extern int cpp_write_pch_deps (cpp_reader *, FILE *); 858c7ca977eSAlexander Kabaev extern int cpp_write_pch_state (cpp_reader *, FILE *); 859c7ca977eSAlexander Kabaev extern int cpp_valid_state (cpp_reader *, const char *, int); 860c7ca977eSAlexander Kabaev extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **); 861c7ca977eSAlexander Kabaev extern int cpp_read_state (cpp_reader *, const char *, FILE *, 862c7ca977eSAlexander Kabaev struct save_macro_data *); 863c7ca977eSAlexander Kabaev 864c7ca977eSAlexander Kabaev #ifdef __cplusplus 865c7ca977eSAlexander Kabaev } 866c7ca977eSAlexander Kabaev #endif 867c7ca977eSAlexander Kabaev 868c7ca977eSAlexander Kabaev #endif /* ! LIBCPP_CPPLIB_H */ 869