add license comments
[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
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 } preprocessor_token_type_t;
47
48 typedef struct source_position_t source_position_t;
49 struct source_position_t {
50         const char *input_name;
51         unsigned    linenr;
52 };
53
54 /* position used for "builtin" declarations/types */
55 extern source_position_t builtin_source_position;
56
57 typedef struct {
58         int type;
59         union {
60                 symbol_t      *symbol;
61                 long long      intvalue;
62                 long double    floatvalue;
63                 string_t       string;
64                 wide_string_t  wide_string;
65         } v;
66         type_t            *datatype;
67         source_position_t  source_position;
68 } token_t;
69
70 void init_tokens(void);
71 void exit_tokens(void);
72 void print_token_type(FILE *out, token_type_t token_type);
73 void print_token(FILE *out, const token_t *token);
74
75 #endif