Turn T_EOF into a properly registered token.
[cparser] / token_t.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #ifndef TOKEN_T_H
21 #define TOKEN_T_H
22
23 #include <stdio.h>
24 #include "string_rep.h"
25 #include "symbol.h"
26 #include "symbol_table.h"
27 #include "type.h"
28
29 typedef enum token_kind_tag_t {
30         T_NULL  =  0,
31 #define T(mode,x,str,val) T_##x val,
32 #define TS(x,str,val) T_##x val,
33 #include "tokens.inc"
34 #undef TS
35 #undef T
36         T_LAST_TOKEN
37 } token_kind_tag_t;
38 typedef unsigned short token_kind_t;
39
40 typedef enum pp_token_kind_tag_t {
41         TP_NULL = 0,
42 #define T(token) TP_##token,
43 #include "tokens_preprocessor.inc"
44 #undef T
45         TP_LAST_TOKEN
46 } pp_token_kind_tag_t;
47 typedef unsigned short pp_token_kind_t;
48
49 typedef struct source_position_t source_position_t;
50 struct source_position_t {
51         const char *input_name;
52         unsigned    lineno;
53         unsigned    colno            : 31;
54         unsigned    is_system_header : 1;
55 };
56
57 /* position used for "builtin" declarations/types */
58 extern const source_position_t builtin_source_position;
59
60 typedef struct token_base_t token_base_t;
61 typedef struct literal_t    literal_t;
62 typedef union  token_t      token_t;
63
64 struct token_base_t {
65         token_kind_t      kind;
66         source_position_t source_position;
67         symbol_t         *symbol;
68 };
69
70 struct literal_t {
71         token_base_t base;
72         string_t     string;
73 };
74
75 union token_t {
76         unsigned     kind;
77         token_base_t base;
78         literal_t    literal;
79 };
80
81 char const *get_string_encoding_prefix(string_encoding_t);
82
83 void init_tokens(void);
84 void exit_tokens(void);
85 void print_token_kind(FILE *out, token_kind_t token_kind);
86 void print_token(FILE *out, const token_t *token);
87
88 /**
89  * returns true if pasting 2 preprocessing tokens next to each other
90  * without a space in between would generate (an)other preprocessing token(s)
91  */
92 bool tokens_would_paste(token_kind_t token1, token_kind_t token2);
93
94 #endif