Add the field encoding to struct string_literal_t and merge T_WIDE_STRING_LITERAL...
[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_t {
30         T_NULL  =  0,
31         T_EOF   = '\x04', // EOT
32 #define T(mode,x,str,val) T_##x val,
33 #define TS(x,str,val) T_##x val,
34 #include "tokens.inc"
35 #undef TS
36 #undef T
37         T_LAST_TOKEN
38 } token_kind_t;
39
40 typedef enum preprocessor_token_kind_t {
41         TP_NULL  = T_NULL,
42         TP_EOF   = T_EOF,
43 #define T(mode,x,str,val) TP_##x val,
44 #define TS(x,str,val) TP_##x val,
45 #include "tokens_preprocessor.inc"
46 #undef TS
47 #undef T
48         TP_LAST_TOKEN
49 } preprocessor_token_kind_t;
50
51 typedef struct source_position_t source_position_t;
52 struct source_position_t {
53         const char *input_name;
54         unsigned    lineno;
55         unsigned    colno            : 31;
56         unsigned    is_system_header : 1;
57 };
58
59 /* position used for "builtin" declarations/types */
60 extern const source_position_t builtin_source_position;
61
62 typedef struct token_base_t     token_base_t;
63 typedef struct string_literal_t string_literal_t;
64 typedef struct number_literal_t number_literal_t;
65 typedef union  token_t          token_t;
66
67 struct token_base_t {
68         unsigned          kind;
69         source_position_t source_position;
70         symbol_t         *symbol;
71 };
72
73 enum string_encoding_t {
74         STRING_ENCODING_CHAR,
75         STRING_ENCODING_WIDE
76 };
77 typedef enum string_encoding_t string_encoding_t;
78
79 struct string_literal_t {
80         token_base_t      base;
81         string_encoding_t encoding;
82         string_t          string;
83 };
84
85 struct number_literal_t {
86         token_base_t  base;
87         string_t      number;
88         string_t      suffix;
89 };
90
91 union token_t {
92         unsigned          kind;
93         token_base_t      base;
94         string_literal_t  string;
95         number_literal_t  number;
96 };
97
98 char const *get_string_encoding_prefix(string_encoding_t);
99
100 void init_tokens(void);
101 void exit_tokens(void);
102 void print_token_kind(FILE *out, token_kind_t token_kind);
103 void print_token(FILE *out, const token_t *token);
104
105 void print_pp_token_kind(FILE *out, int kind);
106 void print_pp_token(FILE *out, const token_t *token);
107
108 /**
109  * returns true if pasting 2 preprocessing tokens next to each other
110  * without a space in between would generate (an)other preprocessing token(s)
111  */
112 bool tokens_would_paste(preprocessor_token_kind_t token1,
113                         preprocessor_token_kind_t token2);
114
115 #endif