some refactoring in preparation for a preprocessor
[cparser] / token_t.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 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 {
30 #define T(mode,x,str,val) T_##x val,
31 #define TS(x,str,val) T_##x val,
32 #include "tokens.inc"
33 #undef TS
34 #undef T
35         T_NULL  =  0,
36         T_EOF   = -1,
37         T_ERROR = -2
38 } token_type_t;
39
40 typedef enum {
41 #define T(mode,x,str,val) TP_##x val,
42 #define TS(x,str,val) TP_##x val,
43 #include "tokens_preprocessor.inc"
44 #undef TS
45 #undef T
46         TP_NULL  = T_NULL,
47         TP_EOF   = T_EOF,
48         TP_ERROR = T_ERROR
49 } preprocessor_token_type_t;
50
51 typedef struct source_position_t source_position_t;
52 struct source_position_t {
53         const char *input_name;
54         unsigned    linenr;
55 };
56
57 /* position used for "builtin" declarations/types */
58 extern source_position_t builtin_source_position;
59
60 typedef struct {
61         int type;
62         union {
63                 symbol_t      *symbol;
64                 long long      intvalue;
65                 long double    floatvalue;
66                 string_t       string;
67                 wide_string_t  wide_string;
68         } v;
69         type_t            *datatype;
70         source_position_t  source_position;
71 } token_t;
72
73 void init_tokens(void);
74 void exit_tokens(void);
75 void print_token_type(FILE *out, token_type_t token_type);
76 void print_token(FILE *out, const token_t *token);
77
78 void print_pp_token_type(FILE *out, preprocessor_token_type_t type);
79 void print_pp_token(FILE *out, const token_t *token);
80
81 #endif