ast2firm: Implement casting from complex to real types.
[cparser] / token_t.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
4  */
5 #ifndef TOKEN_T_H
6 #define TOKEN_T_H
7
8 #include <stdio.h>
9 #include "string_rep.h"
10 #include "symbol.h"
11 #include "symbol_table.h"
12 #include "type.h"
13
14 typedef enum token_kind_tag_t {
15         T_NULL  =  0,
16 #define T(mode,x,str,val) x val,
17 #include "tokens.inc"
18 #undef T
19         T_LAST_TOKEN
20 } token_kind_tag_t;
21 typedef unsigned short token_kind_t;
22
23 typedef enum pp_token_kind_tag_t {
24         TP_NULL = 0,
25 #define T(token) TP_##token,
26 #include "tokens_preprocessor.inc"
27 #undef T
28         TP_LAST_TOKEN
29 } pp_token_kind_tag_t;
30 typedef unsigned short pp_token_kind_t;
31
32 typedef struct position_t position_t;
33 struct position_t {
34         const char *input_name;
35         unsigned    lineno;
36         unsigned    colno            : 31;
37         unsigned    is_system_header : 1;
38 };
39
40 extern symbol_t *token_symbols[];
41
42 /* position used for "builtin" declarations/types */
43 extern const position_t builtin_position;
44
45 typedef struct token_base_t      token_base_t;
46 typedef struct literal_t         literal_t;
47 typedef struct macro_parameter_t macro_parameter_t;
48 typedef union  token_t           token_t;
49
50 struct token_base_t {
51         token_kind_t kind;
52         position_t   pos;
53         symbol_t    *symbol;
54 };
55
56 struct literal_t {
57         token_base_t base;
58         string_t     string;
59 };
60
61 struct macro_parameter_t {
62         token_base_t     base;
63         pp_definition_t *def;
64 };
65
66 union token_t {
67         unsigned          kind;
68         token_base_t      base;
69         literal_t         literal;
70         macro_parameter_t macro_parameter;
71 };
72
73 char const *get_string_encoding_prefix(string_encoding_t);
74
75 void init_tokens(void);
76 void exit_tokens(void);
77 void print_token_kind(FILE *out, token_kind_t token_kind);
78 void print_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(token_kind_t token1, token_kind_t token2);
85
86 #endif