Index: stable/9/contrib/gcclibs/libcpp/include/cpplib.h =================================================================== --- stable/9/contrib/gcclibs/libcpp/include/cpplib.h (revision 231288) +++ stable/9/contrib/gcclibs/libcpp/include/cpplib.h (revision 231289) @@ -1,853 +1,854 @@ /* Definitions for CPP library. Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Written by Per Bothner, 1994-95. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! */ #ifndef LIBCPP_CPPLIB_H #define LIBCPP_CPPLIB_H #include #include "symtab.h" #include "line-map.h" #ifdef __cplusplus extern "C" { #endif typedef struct cpp_reader cpp_reader; typedef struct cpp_buffer cpp_buffer; typedef struct cpp_options cpp_options; typedef struct cpp_token cpp_token; typedef struct cpp_string cpp_string; typedef struct cpp_hashnode cpp_hashnode; typedef struct cpp_macro cpp_macro; typedef struct cpp_callbacks cpp_callbacks; typedef struct cpp_dir cpp_dir; struct answer; struct _cpp_file; /* The first three groups, apart from '=', can appear in preprocessor expressions (+= and -= are used to indicate unary + and - resp.). This allows a lookup table to be implemented in _cpp_parse_expr. The first group, to CPP_LAST_EQ, can be immediately followed by an '='. The lexer needs operators ending in '=', like ">>=", to be in the same order as their counterparts without the '=', like ">>". See the cpp_operator table optab in expr.c if you change the order or add or remove anything in the first group. */ #define TTYPE_TABLE \ OP(EQ, "=") \ OP(NOT, "!") \ OP(GREATER, ">") /* compare */ \ OP(LESS, "<") \ OP(PLUS, "+") /* math */ \ OP(MINUS, "-") \ OP(MULT, "*") \ OP(DIV, "/") \ OP(MOD, "%") \ OP(AND, "&") /* bit ops */ \ OP(OR, "|") \ OP(XOR, "^") \ OP(RSHIFT, ">>") \ OP(LSHIFT, "<<") \ \ OP(COMPL, "~") \ OP(AND_AND, "&&") /* logical */ \ OP(OR_OR, "||") \ OP(QUERY, "?") \ OP(COLON, ":") \ OP(COMMA, ",") /* grouping */ \ OP(OPEN_PAREN, "(") \ OP(CLOSE_PAREN, ")") \ TK(EOF, NONE) \ OP(EQ_EQ, "==") /* compare */ \ OP(NOT_EQ, "!=") \ OP(GREATER_EQ, ">=") \ OP(LESS_EQ, "<=") \ \ /* These two are unary + / - in preprocessor expressions. */ \ OP(PLUS_EQ, "+=") /* math */ \ OP(MINUS_EQ, "-=") \ \ OP(MULT_EQ, "*=") \ OP(DIV_EQ, "/=") \ OP(MOD_EQ, "%=") \ OP(AND_EQ, "&=") /* bit ops */ \ OP(OR_EQ, "|=") \ OP(XOR_EQ, "^=") \ OP(RSHIFT_EQ, ">>=") \ OP(LSHIFT_EQ, "<<=") \ /* Digraphs together, beginning with CPP_FIRST_DIGRAPH. */ \ OP(HASH, "#") /* digraphs */ \ OP(PASTE, "##") \ OP(OPEN_SQUARE, "[") \ OP(CLOSE_SQUARE, "]") \ OP(OPEN_BRACE, "{") \ OP(CLOSE_BRACE, "}") \ /* The remainder of the punctuation. Order is not significant. */ \ OP(SEMICOLON, ";") /* structure */ \ OP(ELLIPSIS, "...") \ OP(PLUS_PLUS, "++") /* increment */ \ OP(MINUS_MINUS, "--") \ OP(DEREF, "->") /* accessors */ \ OP(DOT, ".") \ OP(SCOPE, "::") \ OP(DEREF_STAR, "->*") \ OP(DOT_STAR, ".*") \ OP(ATSIGN, "@") /* used in Objective-C */ \ \ TK(NAME, IDENT) /* word */ \ TK(AT_NAME, IDENT) /* @word - Objective-C */ \ TK(NUMBER, LITERAL) /* 34_be+ta */ \ \ TK(CHAR, LITERAL) /* 'char' */ \ TK(WCHAR, LITERAL) /* L'char' */ \ TK(OTHER, LITERAL) /* stray punctuation */ \ \ TK(STRING, LITERAL) /* "string" */ \ TK(WSTRING, LITERAL) /* L"string" */ \ TK(OBJC_STRING, LITERAL) /* @"string" - Objective-C */ \ TK(HEADER_NAME, LITERAL) /* in #include */ \ \ TK(COMMENT, LITERAL) /* Only if output comments. */ \ /* SPELL_LITERAL happens to DTRT. */ \ TK(MACRO_ARG, NONE) /* Macro argument. */ \ TK(PRAGMA, NONE) /* Only for deferred pragmas. */ \ TK(PRAGMA_EOL, NONE) /* End-of-line for deferred pragmas. */ \ TK(PADDING, NONE) /* Whitespace for -E. */ #define OP(e, s) CPP_ ## e, #define TK(e, s) CPP_ ## e, enum cpp_ttype { TTYPE_TABLE N_TTYPES, /* Positions in the table. */ CPP_LAST_EQ = CPP_LSHIFT, CPP_FIRST_DIGRAPH = CPP_HASH, CPP_LAST_PUNCTUATOR= CPP_ATSIGN, CPP_LAST_CPP_OP = CPP_LESS_EQ }; #undef OP #undef TK /* C language kind, used when calling cpp_create_reader. */ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_GNUCXX, CLK_CXX98, CLK_ASM}; /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ struct cpp_string GTY(()) { unsigned int len; const unsigned char *text; }; /* Flags for the cpp_token structure. */ #define PREV_WHITE (1 << 0) /* If whitespace before this token. */ #define DIGRAPH (1 << 1) /* If it was a digraph. */ #define STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */ #define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */ #define NAMED_OP (1 << 4) /* C++ named operators. */ #define NO_EXPAND (1 << 5) /* Do not macro-expand this token. */ #define BOL (1 << 6) /* Token at beginning of line. */ #define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend, set in c-lex.c. */ /* Specify which field, if any, of the cpp_token union is used. */ enum cpp_token_fld_kind { CPP_TOKEN_FLD_NODE, CPP_TOKEN_FLD_SOURCE, CPP_TOKEN_FLD_STR, CPP_TOKEN_FLD_ARG_NO, CPP_TOKEN_FLD_PRAGMA, CPP_TOKEN_FLD_NONE }; /* A preprocessing token. This has been carefully packed and should occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */ struct cpp_token GTY(()) { source_location src_loc; /* Location of first char of token. */ ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */ unsigned char flags; /* flags - see above */ union cpp_token_u { /* An identifier. */ cpp_hashnode * GTY ((nested_ptr (union tree_node, "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), tag ("CPP_TOKEN_FLD_NODE"))) node; /* Inherit padding from this token. */ cpp_token * GTY ((tag ("CPP_TOKEN_FLD_SOURCE"))) source; /* A string, or number. */ struct cpp_string GTY ((tag ("CPP_TOKEN_FLD_STR"))) str; /* Argument no. for a CPP_MACRO_ARG. */ unsigned int GTY ((tag ("CPP_TOKEN_FLD_ARG_NO"))) arg_no; /* Caller-supplied identifier for a CPP_PRAGMA. */ unsigned int GTY ((tag ("CPP_TOKEN_FLD_PRAGMA"))) pragma; } GTY ((desc ("cpp_token_val_index (&%1)"))) val; }; /* Say which field is in use. */ extern enum cpp_token_fld_kind cpp_token_val_index (cpp_token *tok); /* A type wide enough to hold any multibyte source character. cpplib's character constant interpreter requires an unsigned type. Also, a typedef for the signed equivalent. The width of this type is capped at 32 bits; there do exist targets where wchar_t is 64 bits, but only in a non-default mode, and there would be no meaningful interpretation for a wchar_t value greater than 2^32 anyway -- the widest wide-character encoding around is ISO 10646, which stops at 2^31. */ #if CHAR_BIT * SIZEOF_INT >= 32 # define CPPCHAR_SIGNED_T int #elif CHAR_BIT * SIZEOF_LONG >= 32 # define CPPCHAR_SIGNED_T long #else # error "Cannot find a least-32-bit signed integer type" #endif typedef unsigned CPPCHAR_SIGNED_T cppchar_t; typedef CPPCHAR_SIGNED_T cppchar_signed_t; /* Style of header dependencies to generate. */ enum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM }; /* The possible normalization levels, from most restrictive to least. */ enum cpp_normalize_level { /* In NFKC. */ normalized_KC = 0, /* In NFC. */ normalized_C, /* In NFC, except for subsequences where being in NFC would make the identifier invalid. */ normalized_identifier_C, /* Not normalized at all. */ normalized_none }; /* This structure is nested inside struct cpp_reader, and carries all the options visible to the command line. */ struct cpp_options { /* Characters between tab stops. */ unsigned int tabstop; /* The language we're preprocessing. */ enum c_lang lang; /* Nonzero means use extra default include directories for C++. */ unsigned char cplusplus; /* Nonzero means handle cplusplus style comments. */ unsigned char cplusplus_comments; /* Nonzero means define __OBJC__, treat @ as a special token, and use the OBJC[PLUS]_INCLUDE_PATH environment variable. */ unsigned char objc; /* Nonzero means don't copy comments into the output file. */ unsigned char discard_comments; /* Nonzero means don't copy comments into the output file during macro expansion. */ unsigned char discard_comments_in_macro_exp; /* Nonzero means process the ISO trigraph sequences. */ unsigned char trigraphs; /* Nonzero means process the ISO digraph sequences. */ unsigned char digraphs; /* Nonzero means to allow hexadecimal floats and LL suffixes. */ unsigned char extended_numbers; /* Nonzero means print names of header files (-H). */ unsigned char print_include_names; /* Nonzero means cpp_pedwarn causes a hard error. */ unsigned char pedantic_errors; /* Nonzero means don't print warning messages. */ unsigned char inhibit_warnings; /* Nonzero means complain about deprecated features. */ unsigned char warn_deprecated; /* Nonzero means don't suppress warnings from system headers. */ unsigned char warn_system_headers; /* Nonzero means don't print error messages. Has no option to select it, but can be set by a user of cpplib (e.g. fix-header). */ unsigned char inhibit_errors; /* Nonzero means warn if slash-star appears in a comment. */ unsigned char warn_comments; /* Nonzero means warn if a user-supplied include directory does not exist. */ unsigned char warn_missing_include_dirs; /* Nonzero means warn if there are any trigraphs. */ unsigned char warn_trigraphs; /* Nonzero means warn about multicharacter charconsts. */ unsigned char warn_multichar; /* Nonzero means warn about various incompatibilities with traditional C. */ unsigned char warn_traditional; /* Nonzero means warn about long long numeric constants. */ unsigned char warn_long_long; /* Nonzero means warn about text after an #endif (or #else). */ unsigned char warn_endif_labels; /* Nonzero means warn about implicit sign changes owing to integer promotions. */ unsigned char warn_num_sign_change; /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode. Presumably the usage is protected by the appropriate #ifdef. */ unsigned char warn_variadic_macros; /* Nonzero means turn warnings into errors. */ unsigned char warnings_are_errors; /* Nonzero means we should look for header.gcc files that remap file names. */ unsigned char remap; /* Zero means dollar signs are punctuation. */ unsigned char dollars_in_ident; /* Nonzero means UCNs are accepted in identifiers. */ unsigned char extended_identifiers; /* True if we should warn about dollars in identifiers or numbers for this translation unit. */ unsigned char warn_dollars; /* Nonzero means warn if undefined identifiers are evaluated in an #if. */ unsigned char warn_undef; /* Nonzero means warn of unused macros from the main file. */ unsigned char warn_unused_macros; /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */ unsigned char c99; /* Nonzero if we are conforming to a specific C or C++ standard. */ unsigned char std; /* Nonzero means give all the error messages the ANSI standard requires. */ unsigned char pedantic; /* Nonzero means we're looking at already preprocessed code, so don't bother trying to do macro expansion and whatnot. */ unsigned char preprocessed; /* Print column number in error messages. */ unsigned char show_column; /* Nonzero means handle C++ alternate operator names. */ unsigned char operator_names; /* True for traditional preprocessing. */ unsigned char traditional; /* Holds the name of the target (execution) character set. */ const char *narrow_charset; /* Holds the name of the target wide character set. */ const char *wide_charset; /* Holds the name of the input character set. */ const char *input_charset; /* The minimum permitted level of normalization before a warning is generated. */ enum cpp_normalize_level warn_normalize; /* True to warn about precompiled header files we couldn't use. */ bool warn_invalid_pch; /* True if dependencies should be restored from a precompiled header. */ bool restore_pch_deps; /* Dependency generation. */ struct { /* Style of header dependencies to generate. */ enum cpp_deps_style style; /* Assume missing files are generated files. */ bool missing_files; /* Generate phony targets for each dependency apart from the first one. */ bool phony_targets; /* If true, no dependency is generated on the main file. */ bool ignore_main_file; } deps; /* Target-specific features set by the front end or client. */ /* Precision for target CPP arithmetic, target characters, target ints and target wide characters, respectively. */ size_t precision, char_precision, int_precision, wchar_precision; /* True means chars (wide chars) are unsigned. */ bool unsigned_char, unsigned_wchar; /* True if the most significant byte in a word has the lowest address in memory. */ bool bytes_big_endian; /* Nonzero means __STDC__ should have the value 0 in system headers. */ unsigned char stdc_0_in_system_headers; /* True means error callback should be used for diagnostics. */ bool client_diagnostic; }; /* Callback for header lookup for HEADER, which is the name of a source file. It is used as a method of last resort to find headers that are not otherwise found during the normal include processing. The return value is the malloced name of a header to try and open, if any, or NULL otherwise. This callback is called only if the header is otherwise unfound. */ typedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **); /* Call backs to cpplib client. */ struct cpp_callbacks { /* Called when a new line of preprocessed output is started. */ void (*line_change) (cpp_reader *, const cpp_token *, int); /* Called when switching to/from a new file. The line_map is for the new file. It is NULL if there is no new file. (In C this happens when done with + and also when done with a main file.) This can be used for resource cleanup. */ void (*file_change) (cpp_reader *, const struct line_map *); void (*dir_change) (cpp_reader *, const char *); void (*include) (cpp_reader *, unsigned int, const unsigned char *, const char *, int, const cpp_token **); void (*define) (cpp_reader *, unsigned int, cpp_hashnode *); void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *); void (*ident) (cpp_reader *, unsigned int, const cpp_string *); void (*def_pragma) (cpp_reader *, unsigned int); int (*valid_pch) (cpp_reader *, const char *, int); void (*read_pch) (cpp_reader *, const char *, int, const char *); missing_header_cb missing_header; /* Called to emit a diagnostic if client_diagnostic option is true. This callback receives the translated message. */ void (*error) (cpp_reader *, int, const char *, va_list *) ATTRIBUTE_FPTR_PRINTF(3,0); }; /* Chain of directories to look for include files in. */ struct cpp_dir { /* NULL-terminated singly-linked list. */ struct cpp_dir *next; /* NAME of the directory, NUL-terminated. */ char *name; unsigned int len; /* One if a system header, two if a system header that has extern "C" guards for C++. */ unsigned char sysp; /* Mapping of file names for this directory for MS-DOS and related platforms. A NULL-terminated array of (from, to) pairs. */ const char **name_map; /* Routine to construct pathname, given the search path name and the HEADER we are trying to find, return a constructed pathname to try and open. If this is NULL, the constructed pathname is as constructed by append_file_to_dir. */ char *(*construct) (const char *header, cpp_dir *dir); /* The C front end uses these to recognize duplicated directories in the search path. */ ino_t ino; dev_t dev; /* Is this a user-supplied directory? */ bool user_supplied_p; }; /* Name under which this program was invoked. */ extern const char *progname; /* The structure of a node in the hash table. The hash table has entries for all identifiers: either macros defined by #define commands (type NT_MACRO), assertions created with #assert (NT_ASSERTION), or neither of the above (NT_VOID). Builtin macros like __LINE__ are flagged NODE_BUILTIN. Poisoned identifiers are flagged NODE_POISONED. NODE_OPERATOR (C++ only) indicates an identifier that behaves like an operator such as "xor". NODE_DIAGNOSTIC is for speed in lex_token: it indicates a diagnostic may be required for this node. Currently this only applies to __VA_ARGS__ and poisoned identifiers. */ /* Hash node flags. */ #define NODE_OPERATOR (1 << 0) /* C++ named operator. */ #define NODE_POISONED (1 << 1) /* Poisoned identifier. */ #define NODE_BUILTIN (1 << 2) /* Builtin macro. */ #define NODE_DIAGNOSTIC (1 << 3) /* Possible diagnostic when lexed. */ #define NODE_WARN (1 << 4) /* Warn if redefined or undefined. */ #define NODE_DISABLED (1 << 5) /* A disabled macro. */ #define NODE_MACRO_ARG (1 << 6) /* Used during #define processing. */ /* Different flavors of hash node. */ enum node_type { NT_VOID = 0, /* No definition yet. */ NT_MACRO, /* A macro of some form. */ NT_ASSERTION /* Predicate for #assert. */ }; /* Different flavors of builtin macro. _Pragma is an operator, but we handle it with the builtin code for efficiency reasons. */ enum builtin_type { BT_SPECLINE = 0, /* `__LINE__' */ BT_DATE, /* `__DATE__' */ BT_FILE, /* `__FILE__' */ BT_BASE_FILE, /* `__BASE_FILE__' */ BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ BT_TIME, /* `__TIME__' */ BT_STDC, /* `__STDC__' */ BT_PRAGMA, /* `_Pragma' operator */ - BT_TIMESTAMP /* `__TIMESTAMP__' */ + BT_TIMESTAMP, /* `__TIMESTAMP__' */ + BT_COUNTER /* `__COUNTER__' */ }; #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) #define HT_NODE(NODE) ((ht_identifier *) (NODE)) #define NODE_LEN(NODE) HT_LEN (&(NODE)->ident) #define NODE_NAME(NODE) HT_STR (&(NODE)->ident) /* Specify which field, if any, of the union is used. */ enum { NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE }; #define CPP_HASHNODE_VALUE_IDX(HNODE) \ ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT \ : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN) \ ? NTV_BUILTIN : NTV_MACRO) \ : HNODE.type == NT_ASSERTION ? NTV_ANSWER \ : NTV_NONE) /* The common part of an identifier node shared amongst all 3 C front ends. Also used to store CPP identifiers, which are a superset of identifiers in the grammatical sense. */ union _cpp_hashnode_value GTY(()) { /* If a macro. */ cpp_macro * GTY((tag ("NTV_MACRO"))) macro; /* Answers to an assertion. */ struct answer * GTY ((tag ("NTV_ANSWER"))) answers; /* Code for a builtin macro. */ enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin; /* Macro argument index. */ unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index; }; struct cpp_hashnode GTY(()) { struct ht_identifier ident; unsigned int is_directive : 1; unsigned int directive_index : 7; /* If is_directive, then index into directive table. Otherwise, a NODE_OPERATOR. */ unsigned char rid_code; /* Rid code - for front ends. */ ENUM_BITFIELD(node_type) type : 8; /* CPP node type. */ unsigned char flags; /* CPP flags. */ union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value; }; /* Call this first to get a handle to pass to other functions. If you want cpplib to manage its own hashtable, pass in a NULL pointer. Otherwise you should pass in an initialized hash table that cpplib will share; this technique is used by the C front ends. */ extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *, struct line_maps *); /* Call this to change the selected language standard (e.g. because of command line options). */ extern void cpp_set_lang (cpp_reader *, enum c_lang); /* Set the include paths. */ extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); /* Call these to get pointers to the options, callback, and deps structures for a given reader. These pointers are good until you call cpp_finish on that reader. You can either edit the callbacks through the pointer returned from cpp_get_callbacks, or set them with cpp_set_callbacks. */ extern cpp_options *cpp_get_options (cpp_reader *); extern cpp_callbacks *cpp_get_callbacks (cpp_reader *); extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *); extern struct deps *cpp_get_deps (cpp_reader *); /* This function reads the file, but does not start preprocessing. It returns the name of the original file; this is the same as the input file, except for preprocessed input. This will generate at least one file change callback, and possibly a line change callback too. If there was an error opening the file, it returns NULL. */ extern const char *cpp_read_main_file (cpp_reader *, const char *); /* Set up built-ins like __FILE__. */ extern void cpp_init_builtins (cpp_reader *, int); /* This is called after options have been parsed, and partially processed. */ extern void cpp_post_options (cpp_reader *); /* Set up translation to the target character set. */ extern void cpp_init_iconv (cpp_reader *); /* Call this to finish preprocessing. If you requested dependency generation, pass an open stream to write the information to, otherwise NULL. It is your responsibility to close the stream. Returns cpp_errors (pfile). */ extern int cpp_finish (cpp_reader *, FILE *deps_stream); /* Call this to release the handle at the end of preprocessing. Any use of the handle after this function returns is invalid. Returns cpp_errors (pfile). */ extern void cpp_destroy (cpp_reader *); /* Error count. */ extern unsigned int cpp_errors (cpp_reader *); extern unsigned int cpp_token_len (const cpp_token *); extern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *); extern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *, unsigned char *, bool); extern void cpp_register_pragma (cpp_reader *, const char *, const char *, void (*) (cpp_reader *), bool); extern void cpp_register_deferred_pragma (cpp_reader *, const char *, const char *, unsigned, bool, bool); extern int cpp_avoid_paste (cpp_reader *, const cpp_token *, const cpp_token *); extern const cpp_token *cpp_get_token (cpp_reader *); extern const unsigned char *cpp_macro_definition (cpp_reader *, const cpp_hashnode *); extern void _cpp_backup_tokens (cpp_reader *, unsigned int); /* Evaluate a CPP_CHAR or CPP_WCHAR token. */ extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *, unsigned int *, int *); /* Evaluate a vector of CPP_STRING or CPP_WSTRING tokens. */ extern bool cpp_interpret_string (cpp_reader *, const cpp_string *, size_t, cpp_string *, bool); extern bool cpp_interpret_string_notranslate (cpp_reader *, const cpp_string *, size_t, cpp_string *, bool); /* Convert a host character constant to the execution character set. */ extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); /* Used to register macros and assertions, perhaps from the command line. The text is the same as the command line argument. */ extern void cpp_define (cpp_reader *, const char *); extern void cpp_assert (cpp_reader *, const char *); extern void cpp_undef (cpp_reader *, const char *); extern void cpp_unassert (cpp_reader *, const char *); /* Undefine all macros and assertions. */ extern void cpp_undef_all (cpp_reader *); extern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *, size_t, int); extern int cpp_defined (cpp_reader *, const unsigned char *, int); /* A preprocessing number. Code assumes that any unused high bits of the double integer are set to zero. */ typedef unsigned HOST_WIDE_INT cpp_num_part; typedef struct cpp_num cpp_num; struct cpp_num { cpp_num_part high; cpp_num_part low; bool unsignedp; /* True if value should be treated as unsigned. */ bool overflow; /* True if the most recent calculation overflowed. */ }; /* cpplib provides two interfaces for interpretation of preprocessing numbers. cpp_classify_number categorizes numeric constants according to their field (integer, floating point, or invalid), radix (decimal, octal, hexadecimal), and type suffixes. */ #define CPP_N_CATEGORY 0x000F #define CPP_N_INVALID 0x0000 #define CPP_N_INTEGER 0x0001 #define CPP_N_FLOATING 0x0002 #define CPP_N_WIDTH 0x00F0 #define CPP_N_SMALL 0x0010 /* int, float. */ #define CPP_N_MEDIUM 0x0020 /* long, double. */ #define CPP_N_LARGE 0x0040 /* long long, long double. */ #define CPP_N_RADIX 0x0F00 #define CPP_N_DECIMAL 0x0100 #define CPP_N_HEX 0x0200 #define CPP_N_OCTAL 0x0400 #define CPP_N_UNSIGNED 0x1000 /* Properties. */ #define CPP_N_IMAGINARY 0x2000 #define CPP_N_DFLOAT 0x4000 /* Classify a CPP_NUMBER token. The return value is a combination of the flags from the above sets. */ extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *); /* Evaluate a token classified as category CPP_N_INTEGER. */ extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *, unsigned int type); /* Sign extend a number, with PRECISION significant bits and all others assumed clear, to fill out a cpp_num structure. */ cpp_num cpp_num_sign_extend (cpp_num, size_t); /* Diagnostic levels. To get a diagnostic without associating a position in the translation unit with it, use cpp_error_with_line with a line number of zero. */ /* Warning, an error with -Werror. */ #define CPP_DL_WARNING 0x00 /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */ #define CPP_DL_WARNING_SYSHDR 0x01 /* Warning, an error with -pedantic-errors or -Werror. */ #define CPP_DL_PEDWARN 0x02 /* An error. */ #define CPP_DL_ERROR 0x03 /* An internal consistency check failed. Prints "internal error: ", otherwise the same as CPP_DL_ERROR. */ #define CPP_DL_ICE 0x04 /* Extracts a diagnostic level from an int. */ #define CPP_DL_EXTRACT(l) (l & 0xf) /* Nonzero if a diagnostic level is one of the warnings. */ #define CPP_DL_WARNING_P(l) (CPP_DL_EXTRACT (l) >= CPP_DL_WARNING \ && CPP_DL_EXTRACT (l) <= CPP_DL_PEDWARN) /* Output a diagnostic of some kind. */ extern void cpp_error (cpp_reader *, int, const char *msgid, ...) ATTRIBUTE_PRINTF_3; /* Output a diagnostic with "MSGID: " preceding the error string of errno. No location is printed. */ extern void cpp_errno (cpp_reader *, int, const char *msgid); /* Same as cpp_error, except additionally specifies a position as a (translation unit) physical line and physical column. If the line is zero, then no location is printed. */ extern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned, const char *msgid, ...) ATTRIBUTE_PRINTF_5; /* In cpplex.c */ extern int cpp_ideq (const cpp_token *, const char *); extern void cpp_output_line (cpp_reader *, FILE *); extern void cpp_output_token (const cpp_token *, FILE *); extern const char *cpp_type2name (enum cpp_ttype); /* Returns the value of an escape sequence, truncated to the correct target precision. PSTR points to the input pointer, which is just after the backslash. LIMIT is how much text we have. WIDE is true if the escape sequence is part of a wide character constant or string literal. Handles all relevant diagnostics. */ extern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr, const unsigned char *limit, int wide); /* In cpphash.c */ /* Lookup an identifier in the hashtable. Puts the identifier in the table if it is not already there. */ extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *, unsigned int); typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *); extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *); /* In cppmacro.c */ extern void cpp_scan_nooutput (cpp_reader *); extern int cpp_sys_macro_p (cpp_reader *); extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, unsigned int); /* In cppfiles.c */ extern bool cpp_included (cpp_reader *, const char *); extern void cpp_make_system_header (cpp_reader *, int, int); extern bool cpp_push_include (cpp_reader *, const char *); extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *); extern const char *cpp_get_path (struct _cpp_file *); extern cpp_dir *cpp_get_dir (struct _cpp_file *); extern cpp_buffer *cpp_get_buffer (cpp_reader *); extern struct _cpp_file *cpp_get_file (cpp_buffer *); extern cpp_buffer *cpp_get_prev (cpp_buffer *); /* In cpppch.c */ struct save_macro_data; extern int cpp_save_state (cpp_reader *, FILE *); extern int cpp_write_pch_deps (cpp_reader *, FILE *); extern int cpp_write_pch_state (cpp_reader *, FILE *); extern int cpp_valid_state (cpp_reader *, const char *, int); extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **); extern int cpp_read_state (cpp_reader *, const char *, FILE *, struct save_macro_data *); #ifdef __cplusplus } #endif #endif /* ! LIBCPP_CPPLIB_H */ Index: stable/9/contrib/gcclibs/libcpp/init.c =================================================================== --- stable/9/contrib/gcclibs/libcpp/init.c (revision 231288) +++ stable/9/contrib/gcclibs/libcpp/init.c (revision 231289) @@ -1,638 +1,639 @@ /* CPP Library. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Contributed by Per Bothner, 1994-95. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" #include "system.h" #include "cpplib.h" #include "internal.h" #include "mkdeps.h" #include "localedir.h" static void init_library (void); static void mark_named_operators (cpp_reader *); static void read_original_filename (cpp_reader *); static void read_original_directory (cpp_reader *); static void post_options (cpp_reader *); /* If we have designated initializers (GCC >2.7) these tables can be initialized, constant data. Otherwise, they have to be filled in at runtime. */ #if HAVE_DESIGNATED_INITIALIZERS #define init_trigraph_map() /* Nothing. */ #define TRIGRAPH_MAP \ __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { #define END }; #define s(p, v) [p] = v, #else #define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \ static void init_trigraph_map (void) { \ unsigned char *x = _cpp_trigraph_map; #define END } #define s(p, v) x[p] = v; #endif TRIGRAPH_MAP s('=', '#') s(')', ']') s('!', '|') s('(', '[') s('\'', '^') s('>', '}') s('/', '\\') s('<', '{') s('-', '~') END #undef s #undef END #undef TRIGRAPH_MAP /* A set of booleans indicating what CPP features each source language requires. */ struct lang_flags { char c99; char cplusplus; char extended_numbers; char extended_identifiers; char std; char cplusplus_comments; char digraphs; }; static const struct lang_flags lang_defaults[] = { /* c99 c++ xnum xid std // digr */ /* GNUC89 */ { 0, 0, 1, 0, 0, 1, 1 }, /* GNUC99 */ { 1, 0, 1, 0, 0, 1, 1 }, /* STDC89 */ { 0, 0, 0, 0, 1, 0, 0 }, /* STDC94 */ { 0, 0, 0, 0, 1, 0, 1 }, /* STDC99 */ { 1, 0, 1, 0, 1, 1, 1 }, /* GNUCXX */ { 0, 1, 1, 0, 0, 1, 1 }, /* CXX98 */ { 0, 1, 1, 0, 1, 1, 1 }, /* ASM */ { 0, 0, 1, 0, 0, 1, 0 } /* xid should be 1 for GNUC99, STDC99, GNUCXX and CXX98 when no longer experimental (when all uses of identifiers in the compiler have been audited for correct handling of extended identifiers). */ }; /* Sets internal flags correctly for a given language. */ void cpp_set_lang (cpp_reader *pfile, enum c_lang lang) { const struct lang_flags *l = &lang_defaults[(int) lang]; CPP_OPTION (pfile, lang) = lang; CPP_OPTION (pfile, c99) = l->c99; CPP_OPTION (pfile, cplusplus) = l->cplusplus; CPP_OPTION (pfile, extended_numbers) = l->extended_numbers; CPP_OPTION (pfile, extended_identifiers) = l->extended_identifiers; CPP_OPTION (pfile, std) = l->std; CPP_OPTION (pfile, trigraphs) = l->std; CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments; CPP_OPTION (pfile, digraphs) = l->digraphs; } /* Initialize library global state. */ static void init_library (void) { static int initialized = 0; if (! initialized) { initialized = 1; /* Set up the trigraph map. This doesn't need to do anything if we were compiled with a compiler that supports C99 designated initializers. */ init_trigraph_map (); #ifdef ENABLE_NLS (void) bindtextdomain (PACKAGE, LOCALEDIR); #endif } } /* Initialize a cpp_reader structure. */ cpp_reader * cpp_create_reader (enum c_lang lang, hash_table *table, struct line_maps *line_table) { cpp_reader *pfile; /* Initialize this instance of the library if it hasn't been already. */ init_library (); pfile = XCNEW (cpp_reader); cpp_set_lang (pfile, lang); CPP_OPTION (pfile, warn_multichar) = 1; CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1; CPP_OPTION (pfile, show_column) = 1; CPP_OPTION (pfile, tabstop) = 8; CPP_OPTION (pfile, operator_names) = 1; CPP_OPTION (pfile, warn_trigraphs) = 2; CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, warn_deprecated) = 1; CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99); CPP_OPTION (pfile, dollars_in_ident) = 1; CPP_OPTION (pfile, warn_dollars) = 1; CPP_OPTION (pfile, warn_variadic_macros) = 1; CPP_OPTION (pfile, warn_normalize) = normalized_C; /* Default CPP arithmetic to something sensible for the host for the benefit of dumb users like fix-header. */ CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long); CPP_OPTION (pfile, char_precision) = CHAR_BIT; CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int); CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int); CPP_OPTION (pfile, unsigned_char) = 0; CPP_OPTION (pfile, unsigned_wchar) = 1; CPP_OPTION (pfile, bytes_big_endian) = 1; /* does not matter */ /* Default to no charset conversion. */ CPP_OPTION (pfile, narrow_charset) = _cpp_default_encoding (); CPP_OPTION (pfile, wide_charset) = 0; /* Default the input character set to UTF-8. */ CPP_OPTION (pfile, input_charset) = _cpp_default_encoding (); /* A fake empty "directory" used as the starting point for files looked up without a search path. Name cannot be '/' because we don't want to prepend anything at all to filenames using it. All other entries are correct zero-initialized. */ pfile->no_search_path.name = (char *) ""; /* Initialize the line map. */ pfile->line_table = line_table; /* Initialize lexer state. */ pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); /* Set up static tokens. */ pfile->avoid_paste.type = CPP_PADDING; pfile->avoid_paste.val.source = NULL; pfile->eof.type = CPP_EOF; pfile->eof.flags = 0; /* Create a token buffer for the lexer. */ _cpp_init_tokenrun (&pfile->base_run, 250); pfile->cur_run = &pfile->base_run; pfile->cur_token = pfile->base_run.base; /* Initialize the base context. */ pfile->context = &pfile->base_context; pfile->base_context.macro = 0; pfile->base_context.prev = pfile->base_context.next = 0; /* Aligned and unaligned storage. */ pfile->a_buff = _cpp_get_buff (pfile, 0); pfile->u_buff = _cpp_get_buff (pfile, 0); /* The expression parser stack. */ _cpp_expand_op_stack (pfile); /* Initialize the buffer obstack. */ _obstack_begin (&pfile->buffer_ob, 0, 0, (void *(*) (long)) xmalloc, (void (*) (void *)) free); _cpp_init_files (pfile); _cpp_init_hashtable (pfile, table); return pfile; } /* Free resources used by PFILE. Accessing PFILE after this function returns leads to undefined behavior. Returns the error count. */ void cpp_destroy (cpp_reader *pfile) { cpp_context *context, *contextn; tokenrun *run, *runn; free (pfile->op_stack); while (CPP_BUFFER (pfile) != NULL) _cpp_pop_buffer (pfile); if (pfile->out.base) free (pfile->out.base); if (pfile->macro_buffer) { free (pfile->macro_buffer); pfile->macro_buffer = NULL; pfile->macro_buffer_len = 0; } if (pfile->deps) deps_free (pfile->deps); obstack_free (&pfile->buffer_ob, 0); _cpp_destroy_hashtable (pfile); _cpp_cleanup_files (pfile); _cpp_destroy_iconv (pfile); _cpp_free_buff (pfile->a_buff); _cpp_free_buff (pfile->u_buff); _cpp_free_buff (pfile->free_buffs); for (run = &pfile->base_run; run; run = runn) { runn = run->next; free (run->base); if (run != &pfile->base_run) free (run); } for (context = pfile->base_context.next; context; context = contextn) { contextn = context->next; free (context); } free (pfile); } /* This structure defines one built-in identifier. A node will be entered in the hash table under the name NAME, with value VALUE. There are two tables of these. builtin_array holds all the "builtin" macros: these are handled by builtin_macro() in macro.c. Builtin is somewhat of a misnomer -- the property of interest is that these macros require special code to compute their expansions. The value is a "builtin_type" enumerator. operator_array holds the C++ named operators. These are keywords which act as aliases for punctuators. In C++, they cannot be altered through #define, and #if recognizes them as operators. In C, these are not entered into the hash table at all (but see ). The value is a token-type enumerator. */ struct builtin { const uchar *name; unsigned short len; unsigned short value; }; #define B(n, t) { DSC(n), t } static const struct builtin builtin_array[] = { B("__TIMESTAMP__", BT_TIMESTAMP), B("__TIME__", BT_TIME), B("__DATE__", BT_DATE), B("__FILE__", BT_FILE), B("__BASE_FILE__", BT_BASE_FILE), B("__LINE__", BT_SPECLINE), B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL), + B("__COUNTER__", BT_COUNTER), /* Keep builtins not used for -traditional-cpp at the end, and update init_builtins() if any more are added. */ B("_Pragma", BT_PRAGMA), B("__STDC__", BT_STDC), }; static const struct builtin operator_array[] = { B("and", CPP_AND_AND), B("and_eq", CPP_AND_EQ), B("bitand", CPP_AND), B("bitor", CPP_OR), B("compl", CPP_COMPL), B("not", CPP_NOT), B("not_eq", CPP_NOT_EQ), B("or", CPP_OR_OR), B("or_eq", CPP_OR_EQ), B("xor", CPP_XOR), B("xor_eq", CPP_XOR_EQ) }; #undef B /* Mark the C++ named operators in the hash table. */ static void mark_named_operators (cpp_reader *pfile) { const struct builtin *b; for (b = operator_array; b < (operator_array + ARRAY_SIZE (operator_array)); b++) { cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); hp->flags |= NODE_OPERATOR; hp->is_directive = 0; hp->directive_index = b->value; } } /* Read the builtins table above and enter them, and language-specific macros, into the hash table. HOSTED is true if this is a hosted environment. */ void cpp_init_builtins (cpp_reader *pfile, int hosted) { const struct builtin *b; size_t n = ARRAY_SIZE (builtin_array); if (CPP_OPTION (pfile, traditional)) n -= 2; else if (! CPP_OPTION (pfile, stdc_0_in_system_headers) || CPP_OPTION (pfile, std)) { n--; _cpp_define_builtin (pfile, "__STDC__ 1"); } for (b = builtin_array; b < builtin_array + n; b++) { cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); hp->type = NT_MACRO; hp->flags |= NODE_BUILTIN | NODE_WARN; hp->value.builtin = (enum builtin_type) b->value; } if (CPP_OPTION (pfile, cplusplus)) _cpp_define_builtin (pfile, "__cplusplus 1"); else if (CPP_OPTION (pfile, lang) == CLK_ASM) _cpp_define_builtin (pfile, "__ASSEMBLER__ 1"); else if (CPP_OPTION (pfile, lang) == CLK_STDC94) _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L"); else if (CPP_OPTION (pfile, c99)) _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L"); if (hosted) _cpp_define_builtin (pfile, "__STDC_HOSTED__ 1"); else _cpp_define_builtin (pfile, "__STDC_HOSTED__ 0"); if (CPP_OPTION (pfile, objc)) _cpp_define_builtin (pfile, "__OBJC__ 1"); } /* Sanity-checks are dependent on command-line options, so it is called as a subroutine of cpp_read_main_file (). */ #if ENABLE_CHECKING static void sanity_checks (cpp_reader *); static void sanity_checks (cpp_reader *pfile) { cppchar_t test = 0; size_t max_precision = 2 * CHAR_BIT * sizeof (cpp_num_part); /* Sanity checks for assumptions about CPP arithmetic and target type precisions made by cpplib. */ test--; if (test < 1) cpp_error (pfile, CPP_DL_ICE, "cppchar_t must be an unsigned type"); if (CPP_OPTION (pfile, precision) > max_precision) cpp_error (pfile, CPP_DL_ICE, "preprocessor arithmetic has maximum precision of %lu bits;" " target requires %lu bits", (unsigned long) max_precision, (unsigned long) CPP_OPTION (pfile, precision)); if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision)) cpp_error (pfile, CPP_DL_ICE, "CPP arithmetic must be at least as precise as a target int"); if (CPP_OPTION (pfile, char_precision) < 8) cpp_error (pfile, CPP_DL_ICE, "target char is less than 8 bits wide"); if (CPP_OPTION (pfile, wchar_precision) < CPP_OPTION (pfile, char_precision)) cpp_error (pfile, CPP_DL_ICE, "target wchar_t is narrower than target char"); if (CPP_OPTION (pfile, int_precision) < CPP_OPTION (pfile, char_precision)) cpp_error (pfile, CPP_DL_ICE, "target int is narrower than target char"); /* This is assumed in eval_token() and could be fixed if necessary. */ if (sizeof (cppchar_t) > sizeof (cpp_num_part)) cpp_error (pfile, CPP_DL_ICE, "CPP half-integer narrower than CPP character"); if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T) cpp_error (pfile, CPP_DL_ICE, "CPP on this host cannot handle wide character constants over" " %lu bits, but the target requires %lu bits", (unsigned long) BITS_PER_CPPCHAR_T, (unsigned long) CPP_OPTION (pfile, wchar_precision)); } #else # define sanity_checks(PFILE) #endif /* This is called after options have been parsed, and partially processed. */ void cpp_post_options (cpp_reader *pfile) { sanity_checks (pfile); post_options (pfile); /* Mark named operators before handling command line macros. */ if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names)) mark_named_operators (pfile); } /* Setup for processing input from the file named FNAME, or stdin if it is the empty string. Return the original filename on success (e.g. foo.i->foo.c), or NULL on failure. */ const char * cpp_read_main_file (cpp_reader *pfile, const char *fname) { if (CPP_OPTION (pfile, deps.style) != DEPS_NONE) { if (!pfile->deps) pfile->deps = deps_init (); /* Set the default target (if there is none already). */ deps_add_default_target (pfile->deps, fname); } pfile->main_file = _cpp_find_file (pfile, fname, &pfile->no_search_path, false, 0); if (_cpp_find_failed (pfile->main_file)) return NULL; _cpp_stack_file (pfile, pfile->main_file, false); /* For foo.i, read the original filename foo.c now, for the benefit of the front ends. */ if (CPP_OPTION (pfile, preprocessed)) { read_original_filename (pfile); fname = pfile->line_table->maps[pfile->line_table->used-1].to_file; } return fname; } /* For preprocessed files, if the first tokens are of the form # NUM. handle the directive so we know the original file name. This will generate file_change callbacks, which the front ends must handle appropriately given their state of initialization. */ static void read_original_filename (cpp_reader *pfile) { const cpp_token *token, *token1; /* Lex ahead; if the first tokens are of the form # NUM, then process the directive, otherwise back up. */ token = _cpp_lex_direct (pfile); if (token->type == CPP_HASH) { pfile->state.in_directive = 1; token1 = _cpp_lex_direct (pfile); _cpp_backup_tokens (pfile, 1); pfile->state.in_directive = 0; /* If it's a #line directive, handle it. */ if (token1->type == CPP_NUMBER) { _cpp_handle_directive (pfile, token->flags & PREV_WHITE); read_original_directory (pfile); return; } } /* Backup as if nothing happened. */ _cpp_backup_tokens (pfile, 1); } /* For preprocessed files, if the tokens following the first filename line is of the form # "/path/name//", handle the directive so we know the original current directory. */ static void read_original_directory (cpp_reader *pfile) { const cpp_token *hash, *token; /* Lex ahead; if the first tokens are of the form # NUM, then process the directive, otherwise back up. */ hash = _cpp_lex_direct (pfile); if (hash->type != CPP_HASH) { _cpp_backup_tokens (pfile, 1); return; } token = _cpp_lex_direct (pfile); if (token->type != CPP_NUMBER) { _cpp_backup_tokens (pfile, 2); return; } token = _cpp_lex_direct (pfile); if (token->type != CPP_STRING || ! (token->val.str.len >= 5 && token->val.str.text[token->val.str.len-2] == '/' && token->val.str.text[token->val.str.len-3] == '/')) { _cpp_backup_tokens (pfile, 3); return; } if (pfile->cb.dir_change) { char *debugdir = (char *) alloca (token->val.str.len - 3); memcpy (debugdir, (const char *) token->val.str.text + 1, token->val.str.len - 4); debugdir[token->val.str.len - 4] = '\0'; pfile->cb.dir_change (pfile, debugdir); } } /* This is called at the end of preprocessing. It pops the last buffer and writes dependency output, and returns the number of errors. Maybe it should also reset state, such that you could call cpp_start_read with a new filename to restart processing. */ int cpp_finish (cpp_reader *pfile, FILE *deps_stream) { /* Warn about unused macros before popping the final buffer. */ if (CPP_OPTION (pfile, warn_unused_macros)) cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL); /* lex.c leaves the final buffer on the stack. This it so that it returns an unending stream of CPP_EOFs to the client. If we popped the buffer, we'd dereference a NULL buffer pointer and segfault. It's nice to allow the client to do worry-free excess cpp_get_token calls. */ while (pfile->buffer) _cpp_pop_buffer (pfile); /* Don't write the deps file if there are errors. */ if (CPP_OPTION (pfile, deps.style) != DEPS_NONE && deps_stream && pfile->errors == 0) { deps_write (pfile->deps, deps_stream, 72); if (CPP_OPTION (pfile, deps.phony_targets)) deps_phony_targets (pfile->deps, deps_stream); } /* Report on headers that could use multiple include guards. */ if (CPP_OPTION (pfile, print_include_names)) _cpp_report_missing_guards (pfile); return pfile->errors; } static void post_options (cpp_reader *pfile) { /* -Wtraditional is not useful in C++ mode. */ if (CPP_OPTION (pfile, cplusplus)) CPP_OPTION (pfile, warn_traditional) = 0; /* Permanently disable macro expansion if we are rescanning preprocessed text. Read preprocesed source in ISO mode. */ if (CPP_OPTION (pfile, preprocessed)) { pfile->state.prevent_expansion = 1; CPP_OPTION (pfile, traditional) = 0; } if (CPP_OPTION (pfile, warn_trigraphs) == 2) CPP_OPTION (pfile, warn_trigraphs) = !CPP_OPTION (pfile, trigraphs); if (CPP_OPTION (pfile, traditional)) { CPP_OPTION (pfile, cplusplus_comments) = 0; /* Traditional CPP does not accurately track column information. */ CPP_OPTION (pfile, show_column) = 0; CPP_OPTION (pfile, trigraphs) = 0; CPP_OPTION (pfile, warn_trigraphs) = 0; } } Index: stable/9/contrib/gcclibs/libcpp/internal.h =================================================================== --- stable/9/contrib/gcclibs/libcpp/internal.h (revision 231288) +++ stable/9/contrib/gcclibs/libcpp/internal.h (revision 231289) @@ -1,670 +1,672 @@ /* Part of CPP library. Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* This header defines all the internal data structures and functions that need to be visible across files. It should not be used outside cpplib. */ #ifndef LIBCPP_INTERNAL_H #define LIBCPP_INTERNAL_H #include "symtab.h" #include "cpp-id-data.h" #ifndef HAVE_ICONV_H #undef HAVE_ICONV #endif #if HAVE_ICONV #include #else #define HAVE_ICONV 0 typedef int iconv_t; /* dummy */ #endif struct directive; /* Deliberately incomplete. */ struct pending_option; struct op; struct _cpp_strbuf; typedef bool (*convert_f) (iconv_t, const unsigned char *, size_t, struct _cpp_strbuf *); struct cset_converter { convert_f func; iconv_t cd; }; #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t)) /* Test if a sign is valid within a preprocessing number. */ #define VALID_SIGN(c, prevc) \ (((c) == '+' || (c) == '-') && \ ((prevc) == 'e' || (prevc) == 'E' \ || (((prevc) == 'p' || (prevc) == 'P') \ && CPP_OPTION (pfile, extended_numbers)))) #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION) #define CPP_BUFFER(PFILE) ((PFILE)->buffer) #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base) #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur) #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \ const struct line_maps *line_table = PFILE->line_table; \ const struct line_map *map = &line_table->maps[line_table->used-1]; \ unsigned int line = SOURCE_LINE (map, line_table->highest_line); \ linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \ } while (0) /* Maximum nesting of cpp_buffers. We use a static limit, partly for efficiency, and partly to limit runaway recursion. */ #define CPP_STACK_MAX 200 /* Host alignment handling. */ struct dummy { char c; union { double d; int *p; } u; }; #define DEFAULT_ALIGNMENT offsetof (struct dummy, u) #define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1)) #define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT) #define _cpp_mark_macro_used(NODE) do { \ if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN)) \ (NODE)->value.macro->used = 1; } while (0) /* A generic memory buffer, and operations on it. */ typedef struct _cpp_buff _cpp_buff; struct _cpp_buff { struct _cpp_buff *next; unsigned char *base, *cur, *limit; }; extern _cpp_buff *_cpp_get_buff (cpp_reader *, size_t); extern void _cpp_release_buff (cpp_reader *, _cpp_buff *); extern void _cpp_extend_buff (cpp_reader *, _cpp_buff **, size_t); extern _cpp_buff *_cpp_append_extend_buff (cpp_reader *, _cpp_buff *, size_t); extern void _cpp_free_buff (_cpp_buff *); extern unsigned char *_cpp_aligned_alloc (cpp_reader *, size_t); extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t); #define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur) #define BUFF_FRONT(BUFF) ((BUFF)->cur) #define BUFF_LIMIT(BUFF) ((BUFF)->limit) /* #include types. */ enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE}; union utoken { const cpp_token *token; const cpp_token **ptoken; }; /* A "run" of tokens; part of a chain of runs. */ typedef struct tokenrun tokenrun; struct tokenrun { tokenrun *next, *prev; cpp_token *base, *limit; }; /* Accessor macros for struct cpp_context. */ #define FIRST(c) ((c)->u.iso.first) #define LAST(c) ((c)->u.iso.last) #define CUR(c) ((c)->u.trad.cur) #define RLIMIT(c) ((c)->u.trad.rlimit) typedef struct cpp_context cpp_context; struct cpp_context { /* Doubly-linked list. */ cpp_context *next, *prev; union { /* For ISO macro expansion. Contexts other than the base context are contiguous tokens. e.g. macro expansions, expanded argument tokens. */ struct { union utoken first; union utoken last; } iso; /* For traditional macro expansion. */ struct { const unsigned char *cur; const unsigned char *rlimit; } trad; } u; /* If non-NULL, a buffer used for storage related to this context. When the context is popped, the buffer is released. */ _cpp_buff *buff; /* For a macro context, the macro node, otherwise NULL. */ cpp_hashnode *macro; /* True if utoken element is token, else ptoken. */ bool direct_p; }; struct lexer_state { /* Nonzero if first token on line is CPP_HASH. */ unsigned char in_directive; /* Nonzero if in a directive that will handle padding tokens itself. #include needs this to avoid problems with computed include and spacing between tokens. */ unsigned char directive_wants_padding; /* True if we are skipping a failed conditional group. */ unsigned char skipping; /* Nonzero if in a directive that takes angle-bracketed headers. */ unsigned char angled_headers; /* Nonzero if in a #if or #elif directive. */ unsigned char in_expression; /* Nonzero to save comments. Turned off if discard_comments, and in all directives apart from #define. */ unsigned char save_comments; /* Nonzero if lexing __VA_ARGS__ is valid. */ unsigned char va_args_ok; /* Nonzero if lexing poisoned identifiers is valid. */ unsigned char poisoned_ok; /* Nonzero to prevent macro expansion. */ unsigned char prevent_expansion; /* Nonzero when parsing arguments to a function-like macro. */ unsigned char parsing_args; /* Nonzero if prevent_expansion is true only because output is being discarded. */ unsigned char discarding_output; /* Nonzero to skip evaluating part of an expression. */ unsigned int skip_eval; /* Nonzero when handling a deferred pragma. */ unsigned char in_deferred_pragma; /* Nonzero if the deferred pragma being handled allows macro expansion. */ unsigned char pragma_allow_expansion; }; /* Special nodes - identifiers with predefined significance. */ struct spec_nodes { cpp_hashnode *n_defined; /* defined operator */ cpp_hashnode *n_true; /* C++ keyword true */ cpp_hashnode *n_false; /* C++ keyword false */ cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ }; typedef struct _cpp_line_note _cpp_line_note; struct _cpp_line_note { /* Location in the clean line the note refers to. */ const unsigned char *pos; /* Type of note. The 9 'from' trigraph characters represent those trigraphs, '\\' an escaped newline, ' ' an escaped newline with intervening space, and anything else is invalid. */ unsigned int type; }; /* Represents the contents of a file cpplib has read in. */ struct cpp_buffer { const unsigned char *cur; /* Current location. */ const unsigned char *line_base; /* Start of current physical line. */ const unsigned char *next_line; /* Start of to-be-cleaned logical line. */ const unsigned char *buf; /* Entire character buffer. */ const unsigned char *rlimit; /* Writable byte at end of file. */ _cpp_line_note *notes; /* Array of notes. */ unsigned int cur_note; /* Next note to process. */ unsigned int notes_used; /* Number of notes. */ unsigned int notes_cap; /* Size of allocated array. */ struct cpp_buffer *prev; /* Pointer into the file table; non-NULL if this is a file buffer. Used for include_next and to record control macros. */ struct _cpp_file *file; /* Saved value of __TIMESTAMP__ macro - date and time of last modification of the assotiated file. */ const unsigned char *timestamp; /* Value of if_stack at start of this file. Used to prohibit unmatched #endif (etc) in an include file. */ struct if_stack *if_stack; /* True if we need to get the next clean line. */ bool need_line; /* True if we have already warned about C++ comments in this file. The warning happens only for C89 extended mode with -pedantic on, or for -Wtraditional, and only once per file (otherwise it would be far too noisy). */ unsigned int warned_cplusplus_comments : 1; /* True if we don't process trigraphs and escaped newlines. True for preprocessed input, command line directives, and _Pragma buffers. */ unsigned int from_stage3 : 1; /* At EOF, a buffer is automatically popped. If RETURN_AT_EOF is true, a CPP_EOF token is then returned. Otherwise, the next token from the enclosing buffer is returned. */ unsigned int return_at_eof : 1; /* One for a system header, two for a C system header file that therefore needs to be extern "C" protected in C++, and zero otherwise. */ unsigned char sysp; /* The directory of the this buffer's file. Its NAME member is not allocated, so we don't need to worry about freeing it. */ struct cpp_dir dir; /* Descriptor for converting from the input character set to the source character set. */ struct cset_converter input_cset_desc; }; /* A cpp_reader encapsulates the "state" of a pre-processor run. Applying cpp_get_token repeatedly yields a stream of pre-processor tokens. Usually, there is only one cpp_reader object active. */ struct cpp_reader { /* Top of buffer stack. */ cpp_buffer *buffer; /* Overlaid buffer (can be different after processing #include). */ cpp_buffer *overlaid_buffer; /* Lexer state. */ struct lexer_state state; /* Source line tracking. */ struct line_maps *line_table; /* The line of the '#' of the current directive. */ source_location directive_line; /* Memory buffers. */ _cpp_buff *a_buff; /* Aligned permanent storage. */ _cpp_buff *u_buff; /* Unaligned permanent storage. */ _cpp_buff *free_buffs; /* Free buffer chain. */ /* Context stack. */ struct cpp_context base_context; struct cpp_context *context; /* If in_directive, the directive if known. */ const struct directive *directive; /* Token generated while handling a directive, if any. */ cpp_token directive_result; /* Search paths for include files. */ struct cpp_dir *quote_include; /* "" */ struct cpp_dir *bracket_include; /* <> */ struct cpp_dir no_search_path; /* No path. */ /* Chain of all hashed _cpp_file instances. */ struct _cpp_file *all_files; struct _cpp_file *main_file; /* File and directory hash table. */ struct htab *file_hash; struct htab *dir_hash; struct file_hash_entry *file_hash_entries; unsigned int file_hash_entries_allocated, file_hash_entries_used; /* Nonzero means don't look for #include "foo" the source-file directory. */ bool quote_ignores_source_dir; /* Nonzero if any file has contained #pragma once or #import has been used. */ bool seen_once_only; /* Multiple include optimization. */ const cpp_hashnode *mi_cmacro; const cpp_hashnode *mi_ind_cmacro; bool mi_valid; /* Lexing. */ cpp_token *cur_token; tokenrun base_run, *cur_run; unsigned int lookaheads; /* Nonzero prevents the lexer from re-using the token runs. */ unsigned int keep_tokens; /* Error counter for exit code. */ unsigned int errors; /* Buffer to hold macro definition string. */ unsigned char *macro_buffer; unsigned int macro_buffer_len; /* Descriptor for converting from the source character set to the execution character set. */ struct cset_converter narrow_cset_desc; /* Descriptor for converting from the source character set to the wide execution character set. */ struct cset_converter wide_cset_desc; /* Date and time text. Calculated together if either is requested. */ const unsigned char *date; const unsigned char *time; /* EOF token, and a token forcing paste avoidance. */ cpp_token avoid_paste; cpp_token eof; /* Opaque handle to the dependencies of mkdeps.c. */ struct deps *deps; /* Obstack holding all macro hash nodes. This never shrinks. See identifiers.c */ struct obstack hash_ob; /* Obstack holding buffer and conditional structures. This is a real stack. See directives.c. */ struct obstack buffer_ob; /* Pragma table - dynamic, because a library user can add to the list of recognized pragmas. */ struct pragma_entry *pragmas; /* Call backs to cpplib client. */ struct cpp_callbacks cb; /* Identifier hash table. */ struct ht *hash_table; /* Expression parser stack. */ struct op *op_stack, *op_limit; /* User visible options. */ struct cpp_options opts; /* Special nodes - identifiers with predefined significance to the preprocessor. */ struct spec_nodes spec_nodes; /* Whether cpplib owns the hashtable. */ bool our_hashtable; /* Traditional preprocessing output buffer (a logical line). */ struct { unsigned char *base; unsigned char *limit; unsigned char *cur; source_location first_line; } out; /* Used for buffer overlays by traditional.c. */ const unsigned char *saved_cur, *saved_rlimit, *saved_line_base; /* A saved list of the defined macros, for dependency checking of precompiled headers. */ struct cpp_savedstate *savedstate; + + unsigned int nextcounter; }; /* Character classes. Based on the more primitive macros in safe-ctype.h. If the definition of `numchar' looks odd to you, please look up the definition of a pp-number in the C standard [section 6.4.8 of C99]. In the unlikely event that characters other than \r and \n enter the set is_vspace, the macro handle_newline() in lex.c must be updated. */ #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident)) #define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x)) #define is_numchar(x) ISIDNUM(x) #define is_idstart(x) (ISIDST(x) || _dollar_ok(x)) #define is_numstart(x) ISDIGIT(x) #define is_hspace(x) ISBLANK(x) #define is_vspace(x) IS_VSPACE(x) #define is_nvspace(x) IS_NVSPACE(x) #define is_space(x) IS_SPACE_OR_NUL(x) /* This table is constant if it can be initialized at compile time, which is the case if cpp was compiled with GCC >=2.7, or another compiler that supports C99. */ #if HAVE_DESIGNATED_INITIALIZERS extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; #else extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; #endif /* Macros. */ static inline int cpp_in_system_header (cpp_reader *); static inline int cpp_in_system_header (cpp_reader *pfile) { return pfile->buffer ? pfile->buffer->sysp : 0; } #define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic) #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional) /* In errors.c */ extern int _cpp_begin_message (cpp_reader *, int, source_location, unsigned int); /* In macro.c */ extern void _cpp_free_definition (cpp_hashnode *); extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *); extern void _cpp_pop_context (cpp_reader *); extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *, const unsigned char *, size_t); extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *); extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *, unsigned int); extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *, cpp_hashnode *); extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *); extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *, const cpp_token *, unsigned int); /* In identifiers.c */ extern void _cpp_init_hashtable (cpp_reader *, hash_table *); extern void _cpp_destroy_hashtable (cpp_reader *); /* In files.c */ typedef struct _cpp_file _cpp_file; extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *, bool, int); extern bool _cpp_find_failed (_cpp_file *); extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *); extern void _cpp_fake_include (cpp_reader *, const char *); extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool); extern bool _cpp_stack_include (cpp_reader *, const char *, int, enum include_type); extern int _cpp_compare_file_date (cpp_reader *, const char *, int); extern void _cpp_report_missing_guards (cpp_reader *); extern void _cpp_init_files (cpp_reader *); extern void _cpp_cleanup_files (cpp_reader *); extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *); extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f); extern bool _cpp_read_file_entries (cpp_reader *, FILE *); extern struct stat *_cpp_get_file_stat (_cpp_file *); /* In expr.c */ extern bool _cpp_parse_expr (cpp_reader *); extern struct op *_cpp_expand_op_stack (cpp_reader *); /* In lex.c */ extern void _cpp_process_line_notes (cpp_reader *, int); extern void _cpp_clean_line (cpp_reader *); extern bool _cpp_get_fresh_line (cpp_reader *); extern bool _cpp_skip_block_comment (cpp_reader *); extern cpp_token *_cpp_temp_token (cpp_reader *); extern const cpp_token *_cpp_lex_token (cpp_reader *); extern cpp_token *_cpp_lex_direct (cpp_reader *); extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *); extern void _cpp_init_tokenrun (tokenrun *, unsigned int); /* In init.c. */ extern void _cpp_maybe_push_include_file (cpp_reader *); /* In directives.c */ extern int _cpp_test_assertion (cpp_reader *, unsigned int *); extern int _cpp_handle_directive (cpp_reader *, int); extern void _cpp_define_builtin (cpp_reader *, const char *); extern char ** _cpp_save_pragma_names (cpp_reader *); extern void _cpp_restore_pragma_names (cpp_reader *, char **); extern void _cpp_do__Pragma (cpp_reader *); extern void _cpp_init_directives (cpp_reader *); extern void _cpp_init_internal_pragmas (cpp_reader *); extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *, unsigned int, unsigned int); extern void _cpp_pop_buffer (cpp_reader *); /* In traditional.c. */ extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *); extern bool _cpp_read_logical_line_trad (cpp_reader *); extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *, size_t); extern void _cpp_remove_overlay (cpp_reader *); extern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *); extern bool _cpp_expansions_different_trad (const cpp_macro *, const cpp_macro *); extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *, unsigned char *); extern size_t _cpp_replacement_text_len (const cpp_macro *); /* In charset.c. */ /* The normalization state at this point in the sequence. It starts initialized to all zeros, and at the end 'level' is the normalization level of the sequence. */ struct normalize_state { /* The previous character. */ cppchar_t previous; /* The combining class of the previous character. */ unsigned char prev_class; /* The lowest normalization level so far. */ enum cpp_normalize_level level; }; #define INITIAL_NORMALIZE_STATE { 0, 0, normalized_KC } #define NORMALIZE_STATE_RESULT(st) ((st)->level) /* We saw a character that matches ISIDNUM(), update a normalize_state appropriately. */ #define NORMALIZE_STATE_UPDATE_IDNUM(st) \ ((st)->previous = 0, (st)->prev_class = 0) extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **, const unsigned char *, int, struct normalize_state *state); extern void _cpp_destroy_iconv (cpp_reader *); extern unsigned char *_cpp_convert_input (cpp_reader *, const char *, unsigned char *, size_t, size_t, off_t *); extern const char *_cpp_default_encoding (void); extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile, const unsigned char *id, size_t len); /* Utility routines and macros. */ #define DSC(str) (const unsigned char *)str, sizeof str - 1 /* These are inline functions instead of macros so we can get type checking. */ static inline int ustrcmp (const unsigned char *, const unsigned char *); static inline int ustrncmp (const unsigned char *, const unsigned char *, size_t); static inline size_t ustrlen (const unsigned char *); static inline unsigned char *uxstrdup (const unsigned char *); static inline unsigned char *ustrchr (const unsigned char *, int); static inline int ufputs (const unsigned char *, FILE *); /* Use a const char for the second parameter since it is usually a literal. */ static inline int ustrcspn (const unsigned char *, const char *); static inline int ustrcmp (const unsigned char *s1, const unsigned char *s2) { return strcmp ((const char *)s1, (const char *)s2); } static inline int ustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n) { return strncmp ((const char *)s1, (const char *)s2, n); } static inline int ustrcspn (const unsigned char *s1, const char *s2) { return strcspn ((const char *)s1, s2); } static inline size_t ustrlen (const unsigned char *s1) { return strlen ((const char *)s1); } static inline unsigned char * uxstrdup (const unsigned char *s1) { return (unsigned char *) xstrdup ((const char *)s1); } static inline unsigned char * ustrchr (const unsigned char *s1, int c) { return (unsigned char *) strchr ((const char *)s1, c); } static inline int ufputs (const unsigned char *s, FILE *f) { return fputs ((const char *)s, f); } #endif /* ! LIBCPP_INTERNAL_H */ Index: stable/9/contrib/gcclibs/libcpp/macro.c =================================================================== --- stable/9/contrib/gcclibs/libcpp/macro.c (revision 231288) +++ stable/9/contrib/gcclibs/libcpp/macro.c (revision 231289) @@ -1,1821 +1,1825 @@ /* Part of CPP library. (Macro and #define handling.) Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! */ #include "config.h" #include "system.h" #include "cpplib.h" #include "internal.h" typedef struct macro_arg macro_arg; struct macro_arg { const cpp_token **first; /* First token in unexpanded argument. */ const cpp_token **expanded; /* Macro-expanded argument. */ const cpp_token *stringified; /* Stringified argument. */ unsigned int count; /* # of tokens in argument. */ unsigned int expanded_count; /* # of tokens in expanded argument. */ }; /* Macro expansion. */ static int enter_macro_context (cpp_reader *, cpp_hashnode *); static int builtin_macro (cpp_reader *, cpp_hashnode *); static void push_ptoken_context (cpp_reader *, cpp_hashnode *, _cpp_buff *, const cpp_token **, unsigned int); static _cpp_buff *collect_args (cpp_reader *, const cpp_hashnode *); static cpp_context *next_context (cpp_reader *); static const cpp_token *padding_token (cpp_reader *, const cpp_token *); static void expand_arg (cpp_reader *, macro_arg *); static const cpp_token *new_string_token (cpp_reader *, uchar *, unsigned int); static const cpp_token *stringify_arg (cpp_reader *, macro_arg *); static void paste_all_tokens (cpp_reader *, const cpp_token *); static bool paste_tokens (cpp_reader *, const cpp_token **, const cpp_token *); static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *, macro_arg *); static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *); static bool create_iso_definition (cpp_reader *, cpp_macro *); /* #define directive parsing and handling. */ static cpp_token *alloc_expansion_token (cpp_reader *, cpp_macro *); static cpp_token *lex_expansion_token (cpp_reader *, cpp_macro *); static bool warn_of_redefinition (cpp_reader *, const cpp_hashnode *, const cpp_macro *); static bool parse_params (cpp_reader *, cpp_macro *); static void check_trad_stringification (cpp_reader *, const cpp_macro *, const cpp_string *); /* Emits a warning if NODE is a macro defined in the main file that has not been used. */ int _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED) { if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) { cpp_macro *macro = node->value.macro; if (!macro->used && MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line))) cpp_error_with_line (pfile, CPP_DL_WARNING, macro->line, 0, "macro \"%s\" is not used", NODE_NAME (node)); } return 1; } /* Allocates and returns a CPP_STRING token, containing TEXT of length LEN, after null-terminating it. TEXT must be in permanent storage. */ static const cpp_token * new_string_token (cpp_reader *pfile, unsigned char *text, unsigned int len) { cpp_token *token = _cpp_temp_token (pfile); text[len] = '\0'; token->type = CPP_STRING; token->val.str.len = len; token->val.str.text = text; token->flags = 0; return token; } static const char * const monthnames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; /* Helper function for builtin_macro. Returns the text generated by a builtin macro. */ const uchar * _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) { const struct line_map *map; const uchar *result = NULL; unsigned int number = 1; switch (node->value.builtin) { default: cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"", NODE_NAME (node)); break; case BT_TIMESTAMP: { cpp_buffer *pbuffer = cpp_get_buffer (pfile); if (pbuffer->timestamp == NULL) { /* Initialize timestamp value of the assotiated file. */ struct _cpp_file *file = cpp_get_file (pbuffer); if (file) { /* Generate __TIMESTAMP__ string, that represents the date and time of the last modification of the current source file. The string constant looks like "Sun Sep 16 01:03:52 1973". */ struct tm *tb = NULL; struct stat *st = _cpp_get_file_stat (file); if (st) tb = localtime (&st->st_mtime); if (tb) { char *str = asctime (tb); size_t len = strlen (str); unsigned char *buf = _cpp_unaligned_alloc (pfile, len + 2); buf[0] = '"'; strcpy ((char *) buf + 1, str); buf[len] = '"'; pbuffer->timestamp = buf; } else { cpp_errno (pfile, CPP_DL_WARNING, "could not determine file timestamp"); pbuffer->timestamp = U"\"??? ??? ?? ??:??:?? ????\""; } } } result = pbuffer->timestamp; } break; case BT_FILE: case BT_BASE_FILE: { unsigned int len; const char *name; uchar *buf; map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line); if (node->value.builtin == BT_BASE_FILE) while (! MAIN_FILE_P (map)) map = INCLUDED_FROM (pfile->line_table, map); name = map->to_file; len = strlen (name); buf = _cpp_unaligned_alloc (pfile, len * 2 + 3); result = buf; *buf = '"'; buf = cpp_quote_string (buf + 1, (const unsigned char *) name, len); *buf++ = '"'; *buf = '\0'; } break; case BT_INCLUDE_LEVEL: /* The line map depth counts the primary source as level 1, but historically __INCLUDE_DEPTH__ has called the primary source level 0. */ number = pfile->line_table->depth - 1; break; case BT_SPECLINE: map = &pfile->line_table->maps[pfile->line_table->used-1]; /* If __LINE__ is embedded in a macro, it must expand to the line of the macro's invocation, not its definition. Otherwise things like assert() will not work properly. */ if (CPP_OPTION (pfile, traditional)) number = pfile->line_table->highest_line; else number = pfile->cur_token[-1].src_loc; number = SOURCE_LINE (map, number); break; /* __STDC__ has the value 1 under normal circumstances. However, if (a) we are in a system header, (b) the option stdc_0_in_system_headers is true (set by target config), and (c) we are not in strictly conforming mode, then it has the value 0. (b) and (c) are already checked in cpp_init_builtins. */ case BT_STDC: if (cpp_in_system_header (pfile)) number = 0; else number = 1; break; case BT_DATE: case BT_TIME: if (pfile->date == NULL) { /* Allocate __DATE__ and __TIME__ strings from permanent storage. We only do this once, and don't generate them at init time, because time() and localtime() are very slow on some systems. */ time_t tt; struct tm *tb = NULL; /* (time_t) -1 is a legitimate value for "number of seconds since the Epoch", so we have to do a little dance to distinguish that from a genuine error. */ errno = 0; tt = time(NULL); if (tt != (time_t)-1 || errno == 0) tb = localtime (&tt); if (tb) { pfile->date = _cpp_unaligned_alloc (pfile, sizeof ("\"Oct 11 1347\"")); sprintf ((char *) pfile->date, "\"%s %2d %4d\"", monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900); pfile->time = _cpp_unaligned_alloc (pfile, sizeof ("\"12:34:56\"")); sprintf ((char *) pfile->time, "\"%02d:%02d:%02d\"", tb->tm_hour, tb->tm_min, tb->tm_sec); } else { cpp_errno (pfile, CPP_DL_WARNING, "could not determine date and time"); pfile->date = U"\"??? ?? ????\""; pfile->time = U"\"??:??:??\""; } } if (node->value.builtin == BT_DATE) result = pfile->date; else result = pfile->time; break; + + case BT_COUNTER: + number = pfile->nextcounter++; + break; } if (result == NULL) { /* 21 bytes holds all NUL-terminated unsigned 64-bit numbers. */ result = _cpp_unaligned_alloc (pfile, 21); sprintf ((char *) result, "%u", number); } return result; } /* Convert builtin macros like __FILE__ to a token and push it on the context stack. Also handles _Pragma, for which a new token may not be created. Returns 1 if it generates a new token context, 0 to return the token to the caller. */ static int builtin_macro (cpp_reader *pfile, cpp_hashnode *node) { const uchar *buf; size_t len; char *nbuf; if (node->value.builtin == BT_PRAGMA) { /* Don't interpret _Pragma within directives. The standard is not clear on this, but to me this makes most sense. */ if (pfile->state.in_directive) return 0; _cpp_do__Pragma (pfile); return 1; } buf = _cpp_builtin_macro_text (pfile, node); len = ustrlen (buf); nbuf = (char *) alloca (len + 1); memcpy (nbuf, buf, len); nbuf[len]='\n'; cpp_push_buffer (pfile, (uchar *) nbuf, len, /* from_stage3 */ true); _cpp_clean_line (pfile); /* Set pfile->cur_token as required by _cpp_lex_direct. */ pfile->cur_token = _cpp_temp_token (pfile); _cpp_push_token_context (pfile, NULL, _cpp_lex_direct (pfile), 1); if (pfile->buffer->cur != pfile->buffer->rlimit) cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"", NODE_NAME (node)); _cpp_pop_buffer (pfile); return 1; } /* Copies SRC, of length LEN, to DEST, adding backslashes before all backslashes and double quotes. DEST must be of sufficient size. Returns a pointer to the end of the string. */ uchar * cpp_quote_string (uchar *dest, const uchar *src, unsigned int len) { while (len--) { uchar c = *src++; if (c == '\\' || c == '"') { *dest++ = '\\'; *dest++ = c; } else *dest++ = c; } return dest; } /* Convert a token sequence ARG to a single string token according to the rules of the ISO C #-operator. */ static const cpp_token * stringify_arg (cpp_reader *pfile, macro_arg *arg) { unsigned char *dest; unsigned int i, escape_it, backslash_count = 0; const cpp_token *source = NULL; size_t len; if (BUFF_ROOM (pfile->u_buff) < 3) _cpp_extend_buff (pfile, &pfile->u_buff, 3); dest = BUFF_FRONT (pfile->u_buff); *dest++ = '"'; /* Loop, reading in the argument's tokens. */ for (i = 0; i < arg->count; i++) { const cpp_token *token = arg->first[i]; if (token->type == CPP_PADDING) { if (source == NULL) source = token->val.source; continue; } escape_it = (token->type == CPP_STRING || token->type == CPP_WSTRING || token->type == CPP_CHAR || token->type == CPP_WCHAR); /* Room for each char being written in octal, initial space and final quote and NUL. */ len = cpp_token_len (token); if (escape_it) len *= 4; len += 3; if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len) { size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff); _cpp_extend_buff (pfile, &pfile->u_buff, len); dest = BUFF_FRONT (pfile->u_buff) + len_so_far; } /* Leading white space? */ if (dest - 1 != BUFF_FRONT (pfile->u_buff)) { if (source == NULL) source = token; if (source->flags & PREV_WHITE) *dest++ = ' '; } source = NULL; if (escape_it) { _cpp_buff *buff = _cpp_get_buff (pfile, len); unsigned char *buf = BUFF_FRONT (buff); len = cpp_spell_token (pfile, token, buf, true) - buf; dest = cpp_quote_string (dest, buf, len); _cpp_release_buff (pfile, buff); } else dest = cpp_spell_token (pfile, token, dest, true); if (token->type == CPP_OTHER && token->val.str.text[0] == '\\') backslash_count++; else backslash_count = 0; } /* Ignore the final \ of invalid string literals. */ if (backslash_count & 1) { cpp_error (pfile, CPP_DL_WARNING, "invalid string literal, ignoring final '\\'"); dest--; } /* Commit the memory, including NUL, and return the token. */ *dest++ = '"'; len = dest - BUFF_FRONT (pfile->u_buff); BUFF_FRONT (pfile->u_buff) = dest + 1; return new_string_token (pfile, dest - len, len); } /* Try to paste two tokens. On success, return nonzero. In any case, PLHS is updated to point to the pasted token, which is guaranteed to not have the PASTE_LEFT flag set. */ static bool paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs) { unsigned char *buf, *end, *lhsend; const cpp_token *lhs; unsigned int len; lhs = *plhs; len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1; buf = (unsigned char *) alloca (len); end = lhsend = cpp_spell_token (pfile, lhs, buf, false); /* Avoid comment headers, since they are still processed in stage 3. It is simpler to insert a space here, rather than modifying the lexer to ignore comments in some circumstances. Simply returning false doesn't work, since we want to clear the PASTE_LEFT flag. */ if (lhs->type == CPP_DIV && rhs->type != CPP_EQ) *end++ = ' '; end = cpp_spell_token (pfile, rhs, end, false); *end = '\n'; cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true); _cpp_clean_line (pfile); /* Set pfile->cur_token as required by _cpp_lex_direct. */ pfile->cur_token = _cpp_temp_token (pfile); *plhs = _cpp_lex_direct (pfile); if (pfile->buffer->cur != pfile->buffer->rlimit) { _cpp_pop_buffer (pfile); _cpp_backup_tokens (pfile, 1); *lhsend = '\0'; /* Mandatory error for all apart from assembler. */ if (CPP_OPTION (pfile, lang) != CLK_ASM) cpp_error (pfile, CPP_DL_ERROR, "pasting \"%s\" and \"%s\" does not give a valid preprocessing token", buf, cpp_token_as_text (pfile, rhs)); return false; } _cpp_pop_buffer (pfile); return true; } /* Handles an arbitrarily long sequence of ## operators, with initial operand LHS. This implementation is left-associative, non-recursive, and finishes a paste before handling succeeding ones. If a paste fails, we back up to the RHS of the failing ## operator before pushing the context containing the result of prior successful pastes, with the effect that the RHS appears in the output stream after the pasted LHS normally. */ static void paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs) { const cpp_token *rhs; cpp_context *context = pfile->context; do { /* Take the token directly from the current context. We can do this, because we are in the replacement list of either an object-like macro, or a function-like macro with arguments inserted. In either case, the constraints to #define guarantee we have at least one more token. */ if (context->direct_p) rhs = FIRST (context).token++; else rhs = *FIRST (context).ptoken++; if (rhs->type == CPP_PADDING) abort (); if (!paste_tokens (pfile, &lhs, rhs)) break; } while (rhs->flags & PASTE_LEFT); /* Put the resulting token in its own context. */ _cpp_push_token_context (pfile, NULL, lhs, 1); } /* Returns TRUE if the number of arguments ARGC supplied in an invocation of the MACRO referenced by NODE is valid. An empty invocation to a macro with no parameters should pass ARGC as zero. Note that MACRO cannot necessarily be deduced from NODE, in case NODE was redefined whilst collecting arguments. */ bool _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node, unsigned int argc) { if (argc == macro->paramc) return true; if (argc < macro->paramc) { /* As an extension, a rest argument is allowed to not appear in the invocation at all. e.g. #define debug(format, args...) something debug("string"); This is exactly the same as if there had been an empty rest argument - debug("string", ). */ if (argc + 1 == macro->paramc && macro->variadic) { if (CPP_PEDANTIC (pfile) && ! macro->syshdr) cpp_error (pfile, CPP_DL_PEDWARN, "ISO C99 requires rest arguments to be used"); return true; } cpp_error (pfile, CPP_DL_ERROR, "macro \"%s\" requires %u arguments, but only %u given", NODE_NAME (node), macro->paramc, argc); } else cpp_error (pfile, CPP_DL_ERROR, "macro \"%s\" passed %u arguments, but takes just %u", NODE_NAME (node), argc, macro->paramc); return false; } /* Reads and returns the arguments to a function-like macro invocation. Assumes the opening parenthesis has been processed. If there is an error, emits an appropriate diagnostic and returns NULL. Each argument is terminated by a CPP_EOF token, for the future benefit of expand_arg(). */ static _cpp_buff * collect_args (cpp_reader *pfile, const cpp_hashnode *node) { _cpp_buff *buff, *base_buff; cpp_macro *macro; macro_arg *args, *arg; const cpp_token *token; unsigned int argc; macro = node->value.macro; if (macro->paramc) argc = macro->paramc; else argc = 1; buff = _cpp_get_buff (pfile, argc * (50 * sizeof (cpp_token *) + sizeof (macro_arg))); base_buff = buff; args = (macro_arg *) buff->base; memset (args, 0, argc * sizeof (macro_arg)); buff->cur = (unsigned char *) &args[argc]; arg = args, argc = 0; /* Collect the tokens making up each argument. We don't yet know how many arguments have been supplied, whether too many or too few. Hence the slightly bizarre usage of "argc" and "arg". */ do { unsigned int paren_depth = 0; unsigned int ntokens = 0; argc++; arg->first = (const cpp_token **) buff->cur; for (;;) { /* Require space for 2 new tokens (including a CPP_EOF). */ if ((unsigned char *) &arg->first[ntokens + 2] > buff->limit) { buff = _cpp_append_extend_buff (pfile, buff, 1000 * sizeof (cpp_token *)); arg->first = (const cpp_token **) buff->cur; } token = cpp_get_token (pfile); if (token->type == CPP_PADDING) { /* Drop leading padding. */ if (ntokens == 0) continue; } else if (token->type == CPP_OPEN_PAREN) paren_depth++; else if (token->type == CPP_CLOSE_PAREN) { if (paren_depth-- == 0) break; } else if (token->type == CPP_COMMA) { /* A comma does not terminate an argument within parentheses or as part of a variable argument. */ if (paren_depth == 0 && ! (macro->variadic && argc == macro->paramc)) break; } else if (token->type == CPP_EOF || (token->type == CPP_HASH && token->flags & BOL)) break; arg->first[ntokens++] = token; } /* Drop trailing padding. */ while (ntokens > 0 && arg->first[ntokens - 1]->type == CPP_PADDING) ntokens--; arg->count = ntokens; arg->first[ntokens] = &pfile->eof; /* Terminate the argument. Excess arguments loop back and overwrite the final legitimate argument, before failing. */ if (argc <= macro->paramc) { buff->cur = (unsigned char *) &arg->first[ntokens + 1]; if (argc != macro->paramc) arg++; } } while (token->type != CPP_CLOSE_PAREN && token->type != CPP_EOF); if (token->type == CPP_EOF) { /* We still need the CPP_EOF to end directives, and to end pre-expansion of a macro argument. Step back is not unconditional, since we don't want to return a CPP_EOF to our callers at the end of an -include-d file. */ if (pfile->context->prev || pfile->state.in_directive) _cpp_backup_tokens (pfile, 1); cpp_error (pfile, CPP_DL_ERROR, "unterminated argument list invoking macro \"%s\"", NODE_NAME (node)); } else { /* A single empty argument is counted as no argument. */ if (argc == 1 && macro->paramc == 0 && args[0].count == 0) argc = 0; if (_cpp_arguments_ok (pfile, macro, node, argc)) { /* GCC has special semantics for , ## b where b is a varargs parameter: we remove the comma if b was omitted entirely. If b was merely an empty argument, the comma is retained. If the macro takes just one (varargs) parameter, then we retain the comma only if we are standards conforming. If FIRST is NULL replace_args () swallows the comma. */ if (macro->variadic && (argc < macro->paramc || (argc == 1 && args[0].count == 0 && !CPP_OPTION (pfile, std)))) args[macro->paramc - 1].first = NULL; return base_buff; } } /* An error occurred. */ _cpp_release_buff (pfile, base_buff); return NULL; } /* Search for an opening parenthesis to the macro of NODE, in such a way that, if none is found, we don't lose the information in any intervening padding tokens. If we find the parenthesis, collect the arguments and return the buffer containing them. */ static _cpp_buff * funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node) { const cpp_token *token, *padding = NULL; for (;;) { token = cpp_get_token (pfile); if (token->type != CPP_PADDING) break; if (padding == NULL || (!(padding->flags & PREV_WHITE) && token->val.source == NULL)) padding = token; } if (token->type == CPP_OPEN_PAREN) { pfile->state.parsing_args = 2; return collect_args (pfile, node); } /* CPP_EOF can be the end of macro arguments, or the end of the file. We mustn't back up over the latter. Ugh. */ if (token->type != CPP_EOF || token == &pfile->eof) { /* Back up. We may have skipped padding, in which case backing up more than one token when expanding macros is in general too difficult. We re-insert it in its own context. */ _cpp_backup_tokens (pfile, 1); if (padding) _cpp_push_token_context (pfile, NULL, padding, 1); } return NULL; } /* Push the context of a macro with hash entry NODE onto the context stack. If we can successfully expand the macro, we push a context containing its yet-to-be-rescanned replacement list and return one. Otherwise, we don't push a context and return zero. */ static int enter_macro_context (cpp_reader *pfile, cpp_hashnode *node) { /* The presence of a macro invalidates a file's controlling macro. */ pfile->mi_valid = false; pfile->state.angled_headers = false; /* Handle standard macros. */ if (! (node->flags & NODE_BUILTIN)) { cpp_macro *macro = node->value.macro; if (macro->fun_like) { _cpp_buff *buff; pfile->state.prevent_expansion++; pfile->keep_tokens++; pfile->state.parsing_args = 1; buff = funlike_invocation_p (pfile, node); pfile->state.parsing_args = 0; pfile->keep_tokens--; pfile->state.prevent_expansion--; if (buff == NULL) { if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr) cpp_error (pfile, CPP_DL_WARNING, "function-like macro \"%s\" must be used with arguments in traditional C", NODE_NAME (node)); return 0; } if (macro->paramc > 0) replace_args (pfile, node, macro, (macro_arg *) buff->base); _cpp_release_buff (pfile, buff); } /* Disable the macro within its expansion. */ node->flags |= NODE_DISABLED; macro->used = 1; if (macro->paramc == 0) _cpp_push_token_context (pfile, node, macro->exp.tokens, macro->count); return 1; } /* Handle built-in macros and the _Pragma operator. */ return builtin_macro (pfile, node); } /* Replace the parameters in a function-like macro of NODE with the actual ARGS, and place the result in a newly pushed token context. Expand each argument before replacing, unless it is operated upon by the # or ## operators. */ static void replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args) { unsigned int i, total; const cpp_token *src, *limit; const cpp_token **dest, **first; macro_arg *arg; _cpp_buff *buff; /* First, fully macro-expand arguments, calculating the number of tokens in the final expansion as we go. The ordering of the if statements below is subtle; we must handle stringification before pasting. */ total = macro->count; limit = macro->exp.tokens + macro->count; for (src = macro->exp.tokens; src < limit; src++) if (src->type == CPP_MACRO_ARG) { /* Leading and trailing padding tokens. */ total += 2; /* We have an argument. If it is not being stringified or pasted it is macro-replaced before insertion. */ arg = &args[src->val.arg_no - 1]; if (src->flags & STRINGIFY_ARG) { if (!arg->stringified) arg->stringified = stringify_arg (pfile, arg); } else if ((src->flags & PASTE_LEFT) || (src > macro->exp.tokens && (src[-1].flags & PASTE_LEFT))) total += arg->count - 1; else { if (!arg->expanded) expand_arg (pfile, arg); total += arg->expanded_count - 1; } } /* Now allocate space for the expansion, copy the tokens and replace the arguments. */ buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *)); first = (const cpp_token **) buff->base; dest = first; for (src = macro->exp.tokens; src < limit; src++) { unsigned int count; const cpp_token **from, **paste_flag; if (src->type != CPP_MACRO_ARG) { *dest++ = src; continue; } paste_flag = 0; arg = &args[src->val.arg_no - 1]; if (src->flags & STRINGIFY_ARG) count = 1, from = &arg->stringified; else if (src->flags & PASTE_LEFT) count = arg->count, from = arg->first; else if (src != macro->exp.tokens && (src[-1].flags & PASTE_LEFT)) { count = arg->count, from = arg->first; if (dest != first) { if (dest[-1]->type == CPP_COMMA && macro->variadic && src->val.arg_no == macro->paramc) { /* Swallow a pasted comma if from == NULL, otherwise drop the paste flag. */ if (from == NULL) dest--; else paste_flag = dest - 1; } /* Remove the paste flag if the RHS is a placemarker. */ else if (count == 0) paste_flag = dest - 1; } } else count = arg->expanded_count, from = arg->expanded; /* Padding on the left of an argument (unless RHS of ##). */ if ((!pfile->state.in_directive || pfile->state.directive_wants_padding) && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT)) *dest++ = padding_token (pfile, src); if (count) { memcpy (dest, from, count * sizeof (cpp_token *)); dest += count; /* With a non-empty argument on the LHS of ##, the last token should be flagged PASTE_LEFT. */ if (src->flags & PASTE_LEFT) paste_flag = dest - 1; } /* Avoid paste on RHS (even case count == 0). */ if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT)) *dest++ = &pfile->avoid_paste; /* Add a new paste flag, or remove an unwanted one. */ if (paste_flag) { cpp_token *token = _cpp_temp_token (pfile); token->type = (*paste_flag)->type; token->val = (*paste_flag)->val; if (src->flags & PASTE_LEFT) token->flags = (*paste_flag)->flags | PASTE_LEFT; else token->flags = (*paste_flag)->flags & ~PASTE_LEFT; *paste_flag = token; } } /* Free the expanded arguments. */ for (i = 0; i < macro->paramc; i++) if (args[i].expanded) free (args[i].expanded); push_ptoken_context (pfile, node, buff, first, dest - first); } /* Return a special padding token, with padding inherited from SOURCE. */ static const cpp_token * padding_token (cpp_reader *pfile, const cpp_token *source) { cpp_token *result = _cpp_temp_token (pfile); result->type = CPP_PADDING; /* Data in GCed data structures cannot be made const so far, so we need a cast here. */ result->val.source = (cpp_token *) source; result->flags = 0; return result; } /* Get a new uninitialized context. Create a new one if we cannot re-use an old one. */ static cpp_context * next_context (cpp_reader *pfile) { cpp_context *result = pfile->context->next; if (result == 0) { result = XNEW (cpp_context); result->prev = pfile->context; result->next = 0; pfile->context->next = result; } pfile->context = result; return result; } /* Push a list of pointers to tokens. */ static void push_ptoken_context (cpp_reader *pfile, cpp_hashnode *macro, _cpp_buff *buff, const cpp_token **first, unsigned int count) { cpp_context *context = next_context (pfile); context->direct_p = false; context->macro = macro; context->buff = buff; FIRST (context).ptoken = first; LAST (context).ptoken = first + count; } /* Push a list of tokens. */ void _cpp_push_token_context (cpp_reader *pfile, cpp_hashnode *macro, const cpp_token *first, unsigned int count) { cpp_context *context = next_context (pfile); context->direct_p = true; context->macro = macro; context->buff = NULL; FIRST (context).token = first; LAST (context).token = first + count; } /* Push a traditional macro's replacement text. */ void _cpp_push_text_context (cpp_reader *pfile, cpp_hashnode *macro, const uchar *start, size_t len) { cpp_context *context = next_context (pfile); context->direct_p = true; context->macro = macro; context->buff = NULL; CUR (context) = start; RLIMIT (context) = start + len; macro->flags |= NODE_DISABLED; } /* Expand an argument ARG before replacing parameters in a function-like macro. This works by pushing a context with the argument's tokens, and then expanding that into a temporary buffer as if it were a normal part of the token stream. collect_args() has terminated the argument's tokens with a CPP_EOF so that we know when we have fully expanded the argument. */ static void expand_arg (cpp_reader *pfile, macro_arg *arg) { unsigned int capacity; bool saved_warn_trad; if (arg->count == 0) return; /* Don't warn about funlike macros when pre-expanding. */ saved_warn_trad = CPP_WTRADITIONAL (pfile); CPP_WTRADITIONAL (pfile) = 0; /* Loop, reading in the arguments. */ capacity = 256; arg->expanded = XNEWVEC (const cpp_token *, capacity); push_ptoken_context (pfile, NULL, NULL, arg->first, arg->count + 1); for (;;) { const cpp_token *token; if (arg->expanded_count + 1 >= capacity) { capacity *= 2; arg->expanded = XRESIZEVEC (const cpp_token *, arg->expanded, capacity); } token = cpp_get_token (pfile); if (token->type == CPP_EOF) break; arg->expanded[arg->expanded_count++] = token; } _cpp_pop_context (pfile); CPP_WTRADITIONAL (pfile) = saved_warn_trad; } /* Pop the current context off the stack, re-enabling the macro if the context represented a macro's replacement list. The context structure is not freed so that we can re-use it later. */ void _cpp_pop_context (cpp_reader *pfile) { cpp_context *context = pfile->context; if (context->macro) context->macro->flags &= ~NODE_DISABLED; if (context->buff) _cpp_release_buff (pfile, context->buff); pfile->context = context->prev; } /* External routine to get a token. Also used nearly everywhere internally, except for places where we know we can safely call _cpp_lex_token directly, such as lexing a directive name. Macro expansions and directives are transparently handled, including entering included files. Thus tokens are post-macro expansion, and after any intervening directives. External callers see CPP_EOF only at EOF. Internal callers also see it when meeting a directive inside a macro call, when at the end of a directive and state.in_directive is still 1, and at the end of argument pre-expansion. */ const cpp_token * cpp_get_token (cpp_reader *pfile) { const cpp_token *result; for (;;) { cpp_hashnode *node; cpp_context *context = pfile->context; /* Context->prev == 0 <=> base context. */ if (!context->prev) result = _cpp_lex_token (pfile); else if (FIRST (context).token != LAST (context).token) { if (context->direct_p) result = FIRST (context).token++; else result = *FIRST (context).ptoken++; if (result->flags & PASTE_LEFT) { paste_all_tokens (pfile, result); if (pfile->state.in_directive) continue; return padding_token (pfile, result); } } else { _cpp_pop_context (pfile); if (pfile->state.in_directive) continue; return &pfile->avoid_paste; } if (pfile->state.in_directive && result->type == CPP_COMMENT) continue; if (result->type != CPP_NAME) break; node = result->val.node; if (node->type != NT_MACRO || (result->flags & NO_EXPAND)) break; if (!(node->flags & NODE_DISABLED)) { if (!pfile->state.prevent_expansion && enter_macro_context (pfile, node)) { if (pfile->state.in_directive) continue; return padding_token (pfile, result); } } else { /* Flag this token as always unexpandable. FIXME: move this to collect_args()?. */ cpp_token *t = _cpp_temp_token (pfile); t->type = result->type; t->flags = result->flags | NO_EXPAND; t->val = result->val; result = t; } break; } return result; } /* Returns true if we're expanding an object-like macro that was defined in a system header. Just checks the macro at the top of the stack. Used for diagnostic suppression. */ int cpp_sys_macro_p (cpp_reader *pfile) { cpp_hashnode *node = pfile->context->macro; return node && node->value.macro && node->value.macro->syshdr; } /* Read each token in, until end of the current file. Directives are transparently processed. */ void cpp_scan_nooutput (cpp_reader *pfile) { /* Request a CPP_EOF token at the end of this file, rather than transparently continuing with the including file. */ pfile->buffer->return_at_eof = true; pfile->state.discarding_output++; pfile->state.prevent_expansion++; if (CPP_OPTION (pfile, traditional)) while (_cpp_read_logical_line_trad (pfile)) ; else while (cpp_get_token (pfile)->type != CPP_EOF) ; pfile->state.discarding_output--; pfile->state.prevent_expansion--; } /* Step back one (or more) tokens. Can only step back more than 1 if they are from the lexer, and not from macro expansion. */ void _cpp_backup_tokens (cpp_reader *pfile, unsigned int count) { if (pfile->context->prev == NULL) { pfile->lookaheads += count; while (count--) { pfile->cur_token--; if (pfile->cur_token == pfile->cur_run->base /* Possible with -fpreprocessed and no leading #line. */ && pfile->cur_run->prev != NULL) { pfile->cur_run = pfile->cur_run->prev; pfile->cur_token = pfile->cur_run->limit; } } } else { if (count != 1) abort (); if (pfile->context->direct_p) FIRST (pfile->context).token--; else FIRST (pfile->context).ptoken--; } } /* #define directive parsing and handling. */ /* Returns nonzero if a macro redefinition warning is required. */ static bool warn_of_redefinition (cpp_reader *pfile, const cpp_hashnode *node, const cpp_macro *macro2) { const cpp_macro *macro1; unsigned int i; /* Some redefinitions need to be warned about regardless. */ if (node->flags & NODE_WARN) return true; /* Redefinition of a macro is allowed if and only if the old and new definitions are the same. (6.10.3 paragraph 2). */ macro1 = node->value.macro; /* Don't check count here as it can be different in valid traditional redefinitions with just whitespace differences. */ if (macro1->paramc != macro2->paramc || macro1->fun_like != macro2->fun_like || macro1->variadic != macro2->variadic) return true; /* Check parameter spellings. */ for (i = 0; i < macro1->paramc; i++) if (macro1->params[i] != macro2->params[i]) return true; /* Check the replacement text or tokens. */ if (CPP_OPTION (pfile, traditional)) return _cpp_expansions_different_trad (macro1, macro2); if (macro1->count != macro2->count) return true; for (i = 0; i < macro1->count; i++) if (!_cpp_equiv_tokens (¯o1->exp.tokens[i], ¯o2->exp.tokens[i])) return true; return false; } /* Free the definition of hashnode H. */ void _cpp_free_definition (cpp_hashnode *h) { /* Macros and assertions no longer have anything to free. */ h->type = NT_VOID; /* Clear builtin flag in case of redefinition. */ h->flags &= ~(NODE_BUILTIN | NODE_DISABLED); } /* Save parameter NODE to the parameter list of macro MACRO. Returns zero on success, nonzero if the parameter is a duplicate. */ bool _cpp_save_parameter (cpp_reader *pfile, cpp_macro *macro, cpp_hashnode *node) { unsigned int len; /* Constraint 6.10.3.6 - duplicate parameter names. */ if (node->flags & NODE_MACRO_ARG) { cpp_error (pfile, CPP_DL_ERROR, "duplicate macro parameter \"%s\"", NODE_NAME (node)); return true; } if (BUFF_ROOM (pfile->a_buff) < (macro->paramc + 1) * sizeof (cpp_hashnode *)) _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (cpp_hashnode *)); ((cpp_hashnode **) BUFF_FRONT (pfile->a_buff))[macro->paramc++] = node; node->flags |= NODE_MACRO_ARG; len = macro->paramc * sizeof (union _cpp_hashnode_value); if (len > pfile->macro_buffer_len) { pfile->macro_buffer = XRESIZEVEC (unsigned char, pfile->macro_buffer, len); pfile->macro_buffer_len = len; } ((union _cpp_hashnode_value *) pfile->macro_buffer)[macro->paramc - 1] = node->value; node->value.arg_index = macro->paramc; return false; } /* Check the syntax of the parameters in a MACRO definition. Returns false if an error occurs. */ static bool parse_params (cpp_reader *pfile, cpp_macro *macro) { unsigned int prev_ident = 0; for (;;) { const cpp_token *token = _cpp_lex_token (pfile); switch (token->type) { default: /* Allow/ignore comments in parameter lists if we are preserving comments in macro expansions. */ if (token->type == CPP_COMMENT && ! CPP_OPTION (pfile, discard_comments_in_macro_exp)) continue; cpp_error (pfile, CPP_DL_ERROR, "\"%s\" may not appear in macro parameter list", cpp_token_as_text (pfile, token)); return false; case CPP_NAME: if (prev_ident) { cpp_error (pfile, CPP_DL_ERROR, "macro parameters must be comma-separated"); return false; } prev_ident = 1; if (_cpp_save_parameter (pfile, macro, token->val.node)) return false; continue; case CPP_CLOSE_PAREN: if (prev_ident || macro->paramc == 0) return true; /* Fall through to pick up the error. */ case CPP_COMMA: if (!prev_ident) { cpp_error (pfile, CPP_DL_ERROR, "parameter name missing"); return false; } prev_ident = 0; continue; case CPP_ELLIPSIS: macro->variadic = 1; if (!prev_ident) { _cpp_save_parameter (pfile, macro, pfile->spec_nodes.n__VA_ARGS__); pfile->state.va_args_ok = 1; if (! CPP_OPTION (pfile, c99) && CPP_OPTION (pfile, pedantic) && CPP_OPTION (pfile, warn_variadic_macros)) cpp_error (pfile, CPP_DL_PEDWARN, "anonymous variadic macros were introduced in C99"); } else if (CPP_OPTION (pfile, pedantic) && CPP_OPTION (pfile, warn_variadic_macros)) cpp_error (pfile, CPP_DL_PEDWARN, "ISO C does not permit named variadic macros"); /* We're at the end, and just expect a closing parenthesis. */ token = _cpp_lex_token (pfile); if (token->type == CPP_CLOSE_PAREN) return true; /* Fall through. */ case CPP_EOF: cpp_error (pfile, CPP_DL_ERROR, "missing ')' in macro parameter list"); return false; } } } /* Allocate room for a token from a macro's replacement list. */ static cpp_token * alloc_expansion_token (cpp_reader *pfile, cpp_macro *macro) { if (BUFF_ROOM (pfile->a_buff) < (macro->count + 1) * sizeof (cpp_token)) _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (cpp_token)); return &((cpp_token *) BUFF_FRONT (pfile->a_buff))[macro->count++]; } /* Lex a token from the expansion of MACRO, but mark parameters as we find them and warn of traditional stringification. */ static cpp_token * lex_expansion_token (cpp_reader *pfile, cpp_macro *macro) { cpp_token *token; pfile->cur_token = alloc_expansion_token (pfile, macro); token = _cpp_lex_direct (pfile); /* Is this a parameter? */ if (token->type == CPP_NAME && (token->val.node->flags & NODE_MACRO_ARG) != 0) { token->type = CPP_MACRO_ARG; token->val.arg_no = token->val.node->value.arg_index; } else if (CPP_WTRADITIONAL (pfile) && macro->paramc > 0 && (token->type == CPP_STRING || token->type == CPP_CHAR)) check_trad_stringification (pfile, macro, &token->val.str); return token; } static bool create_iso_definition (cpp_reader *pfile, cpp_macro *macro) { cpp_token *token; const cpp_token *ctoken; /* Get the first token of the expansion (or the '(' of a function-like macro). */ ctoken = _cpp_lex_token (pfile); if (ctoken->type == CPP_OPEN_PAREN && !(ctoken->flags & PREV_WHITE)) { bool ok = parse_params (pfile, macro); macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff); if (!ok) return false; /* Success. Commit or allocate the parameter array. */ if (pfile->hash_table->alloc_subobject) { cpp_hashnode **params = (cpp_hashnode **) pfile->hash_table->alloc_subobject (sizeof (cpp_hashnode *) * macro->paramc); memcpy (params, macro->params, sizeof (cpp_hashnode *) * macro->paramc); macro->params = params; } else BUFF_FRONT (pfile->a_buff) = (uchar *) ¯o->params[macro->paramc]; macro->fun_like = 1; } else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE)) { /* While ISO C99 requires whitespace before replacement text in a macro definition, ISO C90 with TC1 allows there characters from the basic source character set. */ if (CPP_OPTION (pfile, c99)) cpp_error (pfile, CPP_DL_PEDWARN, "ISO C99 requires whitespace after the macro name"); else { int warntype = CPP_DL_WARNING; switch (ctoken->type) { case CPP_ATSIGN: case CPP_AT_NAME: case CPP_OBJC_STRING: /* '@' is not in basic character set. */ warntype = CPP_DL_PEDWARN; break; case CPP_OTHER: /* Basic character set sans letters, digits and _. */ if (strchr ("!\"#%&'()*+,-./:;<=>?[\\]^{|}~", ctoken->val.str.text[0]) == NULL) warntype = CPP_DL_PEDWARN; break; default: /* All other tokens start with a character from basic character set. */ break; } cpp_error (pfile, warntype, "missing whitespace after the macro name"); } } if (macro->fun_like) token = lex_expansion_token (pfile, macro); else { token = alloc_expansion_token (pfile, macro); *token = *ctoken; } for (;;) { /* Check the stringifying # constraint 6.10.3.2.1 of function-like macros when lexing the subsequent token. */ if (macro->count > 1 && token[-1].type == CPP_HASH && macro->fun_like) { if (token->type == CPP_MACRO_ARG) { token->flags &= ~PREV_WHITE; token->flags |= STRINGIFY_ARG; token->flags |= token[-1].flags & PREV_WHITE; token[-1] = token[0]; macro->count--; } /* Let assembler get away with murder. */ else if (CPP_OPTION (pfile, lang) != CLK_ASM) { cpp_error (pfile, CPP_DL_ERROR, "'#' is not followed by a macro parameter"); return false; } } if (token->type == CPP_EOF) break; /* Paste operator constraint 6.10.3.3.1. */ if (token->type == CPP_PASTE) { /* Token-paste ##, can appear in both object-like and function-like macros, but not at the ends. */ if (--macro->count > 0) token = lex_expansion_token (pfile, macro); if (macro->count == 0 || token->type == CPP_EOF) { cpp_error (pfile, CPP_DL_ERROR, "'##' cannot appear at either end of a macro expansion"); return false; } token[-1].flags |= PASTE_LEFT; } token = lex_expansion_token (pfile, macro); } macro->exp.tokens = (cpp_token *) BUFF_FRONT (pfile->a_buff); macro->traditional = 0; /* Don't count the CPP_EOF. */ macro->count--; /* Clear whitespace on first token for warn_of_redefinition(). */ if (macro->count) macro->exp.tokens[0].flags &= ~PREV_WHITE; /* Commit or allocate the memory. */ if (pfile->hash_table->alloc_subobject) { cpp_token *tokns = (cpp_token *) pfile->hash_table->alloc_subobject (sizeof (cpp_token) * macro->count); memcpy (tokns, macro->exp.tokens, sizeof (cpp_token) * macro->count); macro->exp.tokens = tokns; } else BUFF_FRONT (pfile->a_buff) = (uchar *) ¯o->exp.tokens[macro->count]; return true; } /* Parse a macro and save its expansion. Returns nonzero on success. */ bool _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) { cpp_macro *macro; unsigned int i; bool ok; if (pfile->hash_table->alloc_subobject) macro = (cpp_macro *) pfile->hash_table->alloc_subobject (sizeof (cpp_macro)); else macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro)); macro->line = pfile->directive_line; macro->params = 0; macro->paramc = 0; macro->variadic = 0; macro->used = !CPP_OPTION (pfile, warn_unused_macros); macro->count = 0; macro->fun_like = 0; /* To suppress some diagnostics. */ macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0; if (CPP_OPTION (pfile, traditional)) ok = _cpp_create_trad_definition (pfile, macro); else { cpp_token *saved_cur_token = pfile->cur_token; ok = create_iso_definition (pfile, macro); /* Restore lexer position because of games lex_expansion_token() plays lexing the macro. We set the type for SEEN_EOL() in directives.c. Longer term we should lex the whole line before coming here, and just copy the expansion. */ saved_cur_token[-1].type = pfile->cur_token[-1].type; pfile->cur_token = saved_cur_token; /* Stop the lexer accepting __VA_ARGS__. */ pfile->state.va_args_ok = 0; } /* Clear the fast argument lookup indices. */ for (i = macro->paramc; i-- > 0; ) { struct cpp_hashnode *node = macro->params[i]; node->flags &= ~ NODE_MACRO_ARG; node->value = ((union _cpp_hashnode_value *) pfile->macro_buffer)[i]; } if (!ok) return ok; if (node->type == NT_MACRO) { if (CPP_OPTION (pfile, warn_unused_macros)) _cpp_warn_if_unused_macro (pfile, node, NULL); if (warn_of_redefinition (pfile, node, macro)) { cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->directive_line, 0, "\"%s\" redefined", NODE_NAME (node)); if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) cpp_error_with_line (pfile, CPP_DL_PEDWARN, node->value.macro->line, 0, "this is the location of the previous definition"); } } if (node->type != NT_VOID) _cpp_free_definition (node); /* Enter definition in hash table. */ node->type = NT_MACRO; node->value.macro = macro; if (! ustrncmp (NODE_NAME (node), DSC ("__STDC_"))) node->flags |= NODE_WARN; return ok; } /* Warn if a token in STRING matches one of a function-like MACRO's parameters. */ static void check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro, const cpp_string *string) { unsigned int i, len; const uchar *p, *q, *limit; /* Loop over the string. */ limit = string->text + string->len - 1; for (p = string->text + 1; p < limit; p = q) { /* Find the start of an identifier. */ while (p < limit && !is_idstart (*p)) p++; /* Find the end of the identifier. */ q = p; while (q < limit && is_idchar (*q)) q++; len = q - p; /* Loop over the function macro arguments to see if the identifier inside the string matches one of them. */ for (i = 0; i < macro->paramc; i++) { const cpp_hashnode *node = macro->params[i]; if (NODE_LEN (node) == len && !memcmp (p, NODE_NAME (node), len)) { cpp_error (pfile, CPP_DL_WARNING, "macro argument \"%s\" would be stringified in traditional C", NODE_NAME (node)); break; } } } } /* Returns the name, arguments and expansion of a macro, in a format suitable to be read back in again, and therefore also for DWARF 2 debugging info. e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION". Caller is expected to generate the "#define" bit if needed. The returned text is temporary, and automatically freed later. */ const unsigned char * cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node) { unsigned int i, len; const cpp_macro *macro = node->value.macro; unsigned char *buffer; if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN)) { cpp_error (pfile, CPP_DL_ICE, "invalid hash type %d in cpp_macro_definition", node->type); return 0; } /* Calculate length. */ len = NODE_LEN (node) + 2; /* ' ' and NUL. */ if (macro->fun_like) { len += 4; /* "()" plus possible final ".." of named varargs (we have + 1 below). */ for (i = 0; i < macro->paramc; i++) len += NODE_LEN (macro->params[i]) + 1; /* "," */ } /* This should match below where we fill in the buffer. */ if (CPP_OPTION (pfile, traditional)) len += _cpp_replacement_text_len (macro); else { for (i = 0; i < macro->count; i++) { cpp_token *token = ¯o->exp.tokens[i]; if (token->type == CPP_MACRO_ARG) len += NODE_LEN (macro->params[token->val.arg_no - 1]); else len += cpp_token_len (token); if (token->flags & STRINGIFY_ARG) len++; /* "#" */ if (token->flags & PASTE_LEFT) len += 3; /* " ##" */ if (token->flags & PREV_WHITE) len++; /* " " */ } } if (len > pfile->macro_buffer_len) { pfile->macro_buffer = XRESIZEVEC (unsigned char, pfile->macro_buffer, len); pfile->macro_buffer_len = len; } /* Fill in the buffer. Start with the macro name. */ buffer = pfile->macro_buffer; memcpy (buffer, NODE_NAME (node), NODE_LEN (node)); buffer += NODE_LEN (node); /* Parameter names. */ if (macro->fun_like) { *buffer++ = '('; for (i = 0; i < macro->paramc; i++) { cpp_hashnode *param = macro->params[i]; if (param != pfile->spec_nodes.n__VA_ARGS__) { memcpy (buffer, NODE_NAME (param), NODE_LEN (param)); buffer += NODE_LEN (param); } if (i + 1 < macro->paramc) /* Don't emit a space after the comma here; we're trying to emit a Dwarf-friendly definition, and the Dwarf spec forbids spaces in the argument list. */ *buffer++ = ','; else if (macro->variadic) *buffer++ = '.', *buffer++ = '.', *buffer++ = '.'; } *buffer++ = ')'; } /* The Dwarf spec requires a space after the macro name, even if the definition is the empty string. */ *buffer++ = ' '; if (CPP_OPTION (pfile, traditional)) buffer = _cpp_copy_replacement_text (macro, buffer); else if (macro->count) /* Expansion tokens. */ { for (i = 0; i < macro->count; i++) { cpp_token *token = ¯o->exp.tokens[i]; if (token->flags & PREV_WHITE) *buffer++ = ' '; if (token->flags & STRINGIFY_ARG) *buffer++ = '#'; if (token->type == CPP_MACRO_ARG) { memcpy (buffer, NODE_NAME (macro->params[token->val.arg_no - 1]), NODE_LEN (macro->params[token->val.arg_no - 1])); buffer += NODE_LEN (macro->params[token->val.arg_no - 1]); } else buffer = cpp_spell_token (pfile, token, buffer, false); if (token->flags & PASTE_LEFT) { *buffer++ = ' '; *buffer++ = '#'; *buffer++ = '#'; /* Next has PREV_WHITE; see _cpp_create_definition. */ } } } *buffer = '\0'; return pfile->macro_buffer; } Index: stable/9/contrib/gcclibs =================================================================== --- stable/9/contrib/gcclibs (revision 231288) +++ stable/9/contrib/gcclibs (revision 231289) Property changes on: stable/9/contrib/gcclibs ___________________________________________________________________ Added: svn:mergeinfo ## -0,0 +0,4 ## Merged /vendor/resolver/dist/contrib/gcclibs:r1540-186085 Merged /projects/quota64/contrib/gcclibs:r184125-207707 Merged /projects/largeSMP/contrib/gcclibs:r221273-222812,222815-223757 Merged /head/contrib/gcclibs:r226702,226785,227006,228474,228761,229067,230127