/* Definitions for CPP library.
- Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+ Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
Written by Per Bothner, 1994-95.
typedef struct cpp_hashnode cpp_hashnode;
typedef struct cpp_macro cpp_macro;
typedef struct cpp_callbacks cpp_callbacks;
-typedef struct cpp_path cpp_path;
+typedef struct cpp_dir cpp_dir;
struct answer;
-struct file_name_map_list;
+struct _cpp_file;
/* The first three groups, apart from '=', can appear in preprocessor
expressions (+= and -= are used to indicate unary + and - resp.).
OP(CPP_ATSIGN, "@") /* used in Objective-C */ \
\
TK(CPP_NAME, SPELL_IDENT) /* word */ \
+ TK(CPP_AT_NAME, SPELL_IDENT) /* @word - Objective-C */ \
TK(CPP_NUMBER, SPELL_LITERAL) /* 34_be+ta */ \
\
TK(CPP_CHAR, SPELL_LITERAL) /* 'char' */ \
\
TK(CPP_STRING, SPELL_LITERAL) /* "string" */ \
TK(CPP_WSTRING, SPELL_LITERAL) /* L"string" */ \
+ TK(CPP_OBJC_STRING, SPELL_LITERAL) /* @"string" - Objective-C */ \
TK(CPP_HEADER_NAME, SPELL_LITERAL) /* <stdio.h> in #include */ \
\
TK(CPP_COMMENT, SPELL_LITERAL) /* Only if output comments. */ \
occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */
struct cpp_token
{
- unsigned int line; /* Logical line of first char of token. */
- unsigned short col; /* Column of first char of token. */
+ 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 */
/* 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. */
-#ifndef MAX_WCHAR_TYPE_SIZE
-# define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
-#endif
-#if CHAR_BIT * SIZEOF_INT >= MAX_WCHAR_TYPE_SIZE
+ 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
-# if CHAR_BIT * SIZEOF_LONG >= MAX_WCHAR_TYPE_SIZE || !HAVE_LONG_LONG
-# define CPPCHAR_SIGNED_T long
-# else
-# define CPPCHAR_SIGNED_T long long
-# endif
+# 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;
/* Characters between tab stops. */
unsigned int tabstop;
- /* Map between header names and file names, used only on DOS where
- file names are limited in length. */
- struct file_name_map_list *map_list;
-
/* 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 */
+ /* Nonzero means handle cplusplus style comments. */
unsigned char cplusplus_comments;
/* Nonzero means define __OBJC__, treat @ as a special token, and
/* Nonzero means warn if there are any trigraphs. */
unsigned char warn_trigraphs;
- /* Nonzero means warn if #import is used. */
- unsigned char warn_import;
-
/* Nonzero means warn about multicharacter charconsts. */
unsigned char warn_multichar;
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;
/* 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;
+
/* True to warn about precompiled header files we couldn't use. */
bool warn_invalid_pch;
/* True means chars (wide chars) are unsigned. */
bool unsigned_char, unsigned_wchar;
- /* True if target is EBCDIC. */
- bool EBCDIC;
+ /* 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;
};
+/* 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 <built-in>+<command line> 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);
void (*define) (cpp_reader *, unsigned int, cpp_hashnode *);
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;
};
/* Chain of directories to look for include files in. */
-struct cpp_path
+struct cpp_dir
{
/* NULL-terminated singly-linked list. */
- struct cpp_path *next;
+ struct cpp_dir *next;
- /* NAME need not be NUL-terminated once inside cpplib. */
+ /* NAME of the directory, NUL-terminated. */
char *name;
unsigned int len;
"C" guards for C++. */
unsigned char sysp;
- /* Mapping of file names for this directory for MS-DOS and
- related platforms. */
- struct file_name_map *name_map;
-
+ /* 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;
{
struct ht_identifier ident;
unsigned int is_directive : 1;
- unsigned int directive_index : 7; /* If is_directive,
+ 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. */
union _cpp_hashnode_value
{
/* If a macro. */
- cpp_macro * GTY((skip (""))) macro;
+ cpp_macro * GTY((skip)) macro;
/* Answers to an assertion. */
- struct answer * GTY ((skip (""))) answers;
+ struct answer * GTY ((skip)) answers;
/* Code for a builtin macro. */
enum builtin_type GTY ((tag ("1"))) builtin;
/* Macro argument index. */
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 *);
+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_add_dependency_target (cpp_reader *, const char *, int);
/* Set the include paths. */
-extern void cpp_set_include_chains (cpp_reader *, cpp_path *, cpp_path *, int);
+extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int);
/* Call these to get pointers to the options and callback structures
for a given reader. These pointers are good until you call
through the pointer returned from cpp_get_callbacks, or set them
with cpp_set_callbacks. */
extern cpp_options *cpp_get_options (cpp_reader *);
-extern const struct line_maps *cpp_get_line_maps (cpp_reader *);
extern cpp_callbacks *cpp_get_callbacks (cpp_reader *);
extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
/* 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.
/* 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);
/* Used to register macros and assertions, perhaps from the command line.
The text is the same as the command line argument. */
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, int);
+ size_t, int);
extern int cpp_defined (cpp_reader *, const unsigned char *, int);
/* A preprocessing number. Code assumes that any unused high bits of
with a line number of zero. */
/* Warning, an error with -Werror. */
-#define DL_WARNING 0x00
-/* Same as DL_WARNING, except it is not suppressed in system headers. */
-#define DL_WARNING_SYSHDR 0x01
+#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 DL_PEDWARN 0x02
+#define CPP_DL_PEDWARN 0x02
/* An error. */
-#define DL_ERROR 0x03
+#define CPP_DL_ERROR 0x03
/* An internal consistency check failed. Prints "internal error: ",
- otherwise the same as DL_ERROR. */
-#define DL_ICE 0x04
+ otherwise the same as CPP_DL_ERROR. */
+#define CPP_DL_ICE 0x04
/* Extracts a diagnostic level from an int. */
-#define DL_EXTRACT(l) (l & 0xf)
+#define CPP_DL_EXTRACT(l) (l & 0xf)
/* Nonzero if a diagnostic level is one of the warnings. */
-#define DL_WARNING_P(l) (DL_EXTRACT (l) >= DL_WARNING \
- && DL_EXTRACT (l) <= DL_PEDWARN)
+#define CPP_DL_WARNING_P(l) (CPP_DL_EXTRACT (l) >= CPP_DL_WARNING \
+ && CPP_DL_EXTRACT (l) <= CPP_DL_PEDWARN)
/* N.B. The error-message-printer prototypes have not been nicely
formatted because exgettext needs to see 'msgid' on the same line
/* 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, unsigned, unsigned, const char *msgid, ...)
- ATTRIBUTE_PRINTF_5;
+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 *);
unsigned int);
/* In cppfiles.c */
-extern int cpp_included (cpp_reader *, const char *);
+extern bool cpp_included (cpp_reader *, const char *);
extern void cpp_make_system_header (cpp_reader *, int, int);
-extern void cpp_simplify_path (char *);
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;