redo preprocessor output concerning spaces,newlines
[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_type_t {
30         T_ERROR = -1,
31         T_NULL  =  0,
32         T_EOF   = '\x04', // EOT
33 #define T(mode,x,str,val) T_##x val,
34 #define TS(x,str,val) T_##x val,
35 #include "tokens.inc"
36 #undef TS
37 #undef T
38         T_LAST_TOKEN
39 } token_type_t;
40
41 typedef enum preprocessor_token_type_t {
42         TP_NULL  = T_NULL,
43         TP_EOF   = T_EOF,
44         TP_ERROR = T_ERROR,
45 #define T(mode,x,str,val) TP_##x val,
46 #define TS(x,str,val) TP_##x val,
47 #include "tokens_preprocessor.inc"
48 #undef TS
49 #undef T
50         TP_LAST_TOKEN
51 } preprocessor_token_type_t;
52
53 typedef struct source_position_t source_position_t;
54 struct source_position_t {
55         const char *input_name;
56         unsigned    lineno;
57         unsigned    colno;
58 };
59
60 /* position used for "builtin" declarations/types */
61 extern const source_position_t builtin_source_position;
62
63 typedef struct {
64         int                type;
65         symbol_t          *symbol;  /**< contains identifier. Contains number suffix for numbers */
66         string_t           literal; /**< string value/literal value */
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 symbol_t *get_token_symbol(const token_t *token);
76
77 void print_pp_token_type(FILE *out, int type);
78 void print_pp_token(FILE *out, const token_t *token);
79
80 /**
81  * returns true if pasting 2 preprocessing tokens next to each other
82  * without a space in between would generate (an)other preprocessing token(s)
83  */
84 bool tokens_would_paste(preprocessor_token_type_t token1,
85                         preprocessor_token_type_t token2);
86
87 #endif