aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplib.h
diff options
context:
space:
mode:
authorZack Weinberg <zack@gcc.gnu.org>2000-04-20 19:33:11 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-04-20 19:33:11 +0000
commit1368ee700d0d2fd0f0c118e182dda14218dcff5b (patch)
treeb131b13cc8013ec316c7583f27a31866d32d9a99 /gcc/cpplib.h
parent70994f30394bd41eeb3173fcbd40b3db609cb445 (diff)
downloadgcc-1368ee700d0d2fd0f0c118e182dda14218dcff5b.zip
gcc-1368ee700d0d2fd0f0c118e182dda14218dcff5b.tar.gz
gcc-1368ee700d0d2fd0f0c118e182dda14218dcff5b.tar.bz2
cpplib.h (enum cpp_ttype): Add token types for all punctuators.
* cpplib.h (enum cpp_ttype): Add token types for all punctuators. Distinguish pp-numbers from valid C numbers. Give some tokens better names. Initialize from macro. (struct cpp_name, cpp_token, cpp_toklist): New data structures. Update prototypes. * cpplex.c (bump_column, expand_name_space, expand_token_space, init_token_list, cpp_output_list, _cpp_scan_line): New functions. (output_line_command): Add third argument, new line number. * cpphash.h: Update prototypes. * cppexp.c, cpphash.c, cpplib.c, scan-decls.c: Update for new token names. From-SVN: r33289
Diffstat (limited to 'gcc/cpplib.h')
-rw-r--r--gcc/cpplib.h176
1 files changed, 150 insertions, 26 deletions
diff --git a/gcc/cpplib.h b/gcc/cpplib.h
index e6f2529..6e3561a 100644
--- a/gcc/cpplib.h
+++ b/gcc/cpplib.h
@@ -32,36 +32,156 @@ typedef struct cpp_reader cpp_reader;
typedef struct cpp_buffer cpp_buffer;
typedef struct cpp_options cpp_options;
typedef struct cpp_printer cpp_printer;
-
+typedef struct cpp_token cpp_token;
+typedef struct cpp_toklist cpp_toklist;
+
+ /* Put operators that can appear in a preprocessor expression first.
+ This allows a lookup table to be implemented in _cpp_parse_expr.
+ Ordering within this group is currently not significant, apart
+ from those ending in '=' being at the end. */
+#define TTYPE_TABLE \
+ T(CPP_PLUS = 0, "+") /* math */ \
+ T(CPP_MINUS, "-") \
+ T(CPP_MULT, "*") \
+ T(CPP_DIV, "/") \
+ T(CPP_MOD, "%") \
+ T(CPP_AND, "&") /* bit ops */ \
+ T(CPP_OR, "|") \
+ T(CPP_XOR, "^") \
+ T(CPP_COMPL, "~") \
+ T(CPP_RSHIFT, ">>") \
+ T(CPP_LSHIFT, "<<") \
+ T(CPP_NOT, "!") /* logicals */ \
+ T(CPP_AND_AND, "&&") \
+ T(CPP_OR_OR, "||") \
+ T(CPP_QUERY, "?") \
+ T(CPP_COLON, ":") \
+ T(CPP_COMMA, ",") /* grouping */ \
+ T(CPP_OPEN_PAREN, "(") \
+ T(CPP_CLOSE_PAREN, ")") \
+ T(CPP_GREATER, ">") /* compare */ \
+ T(CPP_LESS, "<") \
+ T(CPP_EQ_EQ, "==") \
+ T(CPP_NOT_EQ, "!=") \
+ T(CPP_GREATER_EQ, ">=") \
+ T(CPP_LESS_EQ, "<=") \
+\
+ /* The remainder of the punctuation. Order is not significant. */ \
+ T(CPP_PLUS_EQ, "+=") /* math */ \
+ T(CPP_MINUS_EQ, "-=") \
+ T(CPP_MULT_EQ, "*=") \
+ T(CPP_DIV_EQ, "/=") \
+ T(CPP_MOD_EQ, "%=") \
+ T(CPP_AND_EQ, "&=") /* bit ops */ \
+ T(CPP_OR_EQ, "|=") \
+ T(CPP_XOR_EQ, "^=") \
+ T(CPP_COMPL_EQ, "~=") \
+ T(CPP_RSHIFT_EQ, ">>=") \
+ T(CPP_LSHIFT_EQ, "<<=") \
+ T(CPP_EQ, "=") /* assign */ \
+ T(CPP_PLUS_PLUS, "++") /* increment */ \
+ T(CPP_MINUS_MINUS, "--") \
+ T(CPP_DEREF, "->") /* accessors */ \
+ T(CPP_DOT, ".") \
+ T(CPP_OPEN_SQUARE, "[") \
+ T(CPP_CLOSE_SQUARE, "]") \
+ T(CPP_SCOPE, "::") \
+ T(CPP_DEREF_STAR, "->*") \
+ T(CPP_DOT_STAR, ".*") \
+ T(CPP_OPEN_BRACE, "{") /* structure */ \
+ T(CPP_CLOSE_BRACE, "}") \
+ T(CPP_SEMICOLON, ";") \
+ T(CPP_ELLIPSIS, "...") \
+ T(CPP_HASH, "#") \
+ T(CPP_PASTE, "##") \
+ T(CPP_BACKSLASH, "\\") \
+ T(CPP_MIN, "<?") /* extension */ \
+ T(CPP_MAX, ">?") \
+ T(CPP_OTHER, spell_other) /* stray punctuation */ \
+\
+ T(CPP_NAME, spell_name) /* word */ \
+ T(CPP_INT, 0) /* 23 */ \
+ T(CPP_FLOAT, 0) /* 3.14159 */ \
+ T(CPP_NUMBER, spell_name) /* 34_be+ta */ \
+ T(CPP_CHAR, spell_char) /* 'char' */ \
+ T(CPP_WCHAR, spell_char) /* L'char' */ \
+ T(CPP_STRING, spell_string) /* "string" */ \
+ T(CPP_WSTRING, spell_string) /* L"string" */ \
+\
+ T(CPP_COMMENT, spell_comment) /* Only if output comments. */ \
+ T(CPP_VSPACE, "\n") /* End of line. */ \
+ T(CPP_EOF, 0) /* End of file. */ \
+ T(CPP_HEADER_NAME, 0) /* <stdio.h> in #include */ \
+ T(CPP_ASSERTION, 0) /* (...) in #assert */ \
+\
+ /* Obsolete - will be removed when no code uses them still. */ \
+ T(CPP_HSPACE, 0) /* Horizontal white space. */ \
+ T(CPP_POP, 0) /* End of buffer. */ \
+ T(CPP_DIRECTIVE, 0) /* #define and the like */ \
+ T(CPP_MACRO, 0) /* Like a NAME, but expanded. */
+
+#define T(e, s) e,
enum cpp_ttype
{
- CPP_EOF = -1,
- CPP_OTHER = 0,
- CPP_COMMENT = 1,
- CPP_HSPACE,
- CPP_VSPACE, /* newlines and #line directives */
- CPP_NAME,
- CPP_MACRO,
- CPP_NUMBER,
- CPP_CHAR,
- CPP_WCHAR,
- CPP_STRING,
- CPP_WSTRING,
- CPP_DIRECTIVE,
- CPP_ASSERTION, /* #machine(a29k) */
- CPP_STRINGIZE, /* stringize macro argument */
- CPP_TOKPASTE, /* paste macro arg with next/prev token */
- CPP_LPAREN, /* "(" */
- CPP_RPAREN, /* ")" */
- CPP_LBRACE, /* "{" */
- CPP_RBRACE, /* "}" */
- CPP_COMMA, /* "," */
- CPP_SEMICOLON, /* ";" */
- CPP_3DOTS, /* "..." */
- CPP_POP /* We're about to pop the buffer stack. */
+ TTYPE_TABLE
+ N_TTYPES
+};
+#undef T
+
+/* Payload of a NAME, NUMBER, FLOAT, STRING, or COMMENT token. */
+struct cpp_name
+{
+ unsigned int len;
+ unsigned int offset; /* from list->namebuf */
+};
+
+/* A preprocessing token.
+ This has been carefully packed and should occupy 16 bytes on
+ both 32- and 64-bit hosts. */
+struct cpp_token
+{
+ unsigned short col; /* starting column of this token */
+#ifdef ENUM_BITFIELDS_ARE_UNSIGNED
+ enum cpp_ttype type : CHAR_BIT; /* node type */
+#else
+ unsigned char type;
+#endif
+ unsigned char flags; /* flags - not presently used */
+ unsigned int aux; /* hash of a NAME, or something -
+ see uses in the code */
+ union
+ {
+ struct cpp_name name; /* a string */
+ HOST_WIDEST_INT integer; /* an integer */
+ } val;
};
-typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader *));
+/* Directive flags. */
+#define SYNTAX_INCLUDE (1 << 8)
+#define SYNTAX_ASSERT (1 << 9)
+
+typedef int (*directive_handler) PARAMS ((cpp_reader *));
+typedef int (*parse_cleanup_t) PARAMS ((cpp_buffer *, cpp_reader *));
+
+struct cpp_toklist
+{
+ struct cpp_token *tokens; /* actual tokens as an array */
+ unsigned int tokens_used; /* tokens used */
+ unsigned int tokens_cap; /* tokens allocated */
+
+ unsigned char *namebuf; /* names buffer */
+ unsigned int name_used; /* _bytes_ used */
+ unsigned int name_cap; /* _bytes_ allocated */
+
+ unsigned int line; /* starting line number */
+
+ /* Only used if tokens[0].type == CPP_DIRECTIVE. This is the
+ handler to call after lexing the rest of this line. The flags
+ indicate whether the rest of the line gets special treatment
+ during lexing (#include, #if, #assert, #unassert). */
+ directive_handler dir_handler;
+ unsigned short dir_flags;
+};
struct cpp_buffer
{
@@ -442,6 +562,8 @@ extern void cpp_reader_init PARAMS ((cpp_reader *));
extern cpp_printer *cpp_printer_init PARAMS ((cpp_reader *, cpp_printer *));
extern int cpp_start_read PARAMS ((cpp_reader *, cpp_printer *, const char *));
extern void cpp_output_tokens PARAMS ((cpp_reader *, cpp_printer *));
+extern void cpp_output_list PARAMS ((cpp_reader *, cpp_printer *,
+ const cpp_toklist *));
extern void cpp_finish PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_cleanup PARAMS ((cpp_reader *));
@@ -487,6 +609,8 @@ extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *));
+
+
/* In cpphash.c */
extern int cpp_defined PARAMS ((cpp_reader *,
const unsigned char *, int));