Added missing file.
[tinycc/k1w1.git] / tccpp.h
blobc7b516cfea0fa4725656c631bf485cfc7ef88776
1 /*
2 * TCC - Tiny C Compiler
3 *
4 * Copyright (c) 2001-2004 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef __TCCPP_H__
21 #define __TCCPP_H__
23 void save_parse_state(ParseState *s);
24 void restore_parse_state(ParseState *s);
25 void preprocess_init(TCCState *s1);
26 void preprocess_new(void);
27 char *get_tok_str(int v, CValue *cv);
28 void next(void);
29 /* find a token and add it if not found */
30 TokenSym *tok_alloc(const char *str, int len);
31 /* label lookup */
32 Sym *label_find(int v);
33 Sym *label_push(Sym **ptop, int v, int flags);
34 /* free define stack until top reaches 'b' */
35 void free_defines(Sym *b);
36 void next_nomacro(void);
37 /* defines handling */
38 void define_push(int v, int macro_type, int *str, Sym *first_arg);
39 /* parse after #define */
40 void parse_define(void);
41 static inline Sym *define_find(int v)
43 v -= TOK_IDENT;
44 if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
45 return NULL;
46 return table_ident[v]->sym_define;
48 void label_pop(Sym **ptop, Sym *slast);
49 void define_undef(Sym *s);
50 /* Preprocess the current file */
51 int tcc_preprocess(TCCState *s1);
52 /* input with '\[\r]\n' handling. Note that this function cannot
53 handle other characters after '\', so you cannot call it inside
54 strings or comments */
55 void minp(void);
56 /* C comments */
57 uint8_t *parse_comment(uint8_t *p);
58 /* return the current character, handling end of block if necessary
59 (but not stray) */
60 int handle_eob(void);
61 /* read next char from current input file and handle end of input buffer */
62 static inline void inp(void)
64 ch = *(++(file->buf_ptr));
65 /* end of buffer/file handling */
66 if (ch == CH_EOB)
67 ch = handle_eob();
70 /* return the number of additional 'ints' necessary to store the
71 token */
72 static inline int tok_ext_size(int t)
74 switch(t) {
75 /* 4 bytes */
76 case TOK_CINT:
77 case TOK_CUINT:
78 case TOK_CCHAR:
79 case TOK_LCHAR:
80 case TOK_CFLOAT:
81 case TOK_LINENUM:
82 return 1;
83 case TOK_STR:
84 case TOK_LSTR:
85 case TOK_PPNUM:
86 error("unsupported token");
87 return 1;
88 case TOK_CDOUBLE:
89 case TOK_CLLONG:
90 case TOK_CULLONG:
91 return 2;
92 case TOK_CLDOUBLE:
93 return LDOUBLE_SIZE / 4;
94 default:
95 return 0;
99 /* push back current token and set current token to 'last_tok'. Only
100 identifier case handled for labels. */
101 static inline void unget_tok(int last_tok)
103 int i, n;
104 int *q;
105 unget_saved_macro_ptr = macro_ptr;
106 unget_buffer_enabled = 1;
107 q = unget_saved_buffer;
108 macro_ptr = q;
109 *q++ = tok;
110 n = tok_ext_size(tok) - 1;
111 for(i=0;i<n;i++)
112 *q++ = tokc.tab[i];
113 *q = 0; /* end of token string */
114 tok = last_tok;
117 static inline void tok_str_new(TokenString *s)
119 s->str = NULL;
120 s->len = 0;
121 s->allocated_len = 0;
122 s->last_line_num = -1;
125 /* add the current parse token in token string 's' */
126 void tok_str_add_tok(TokenString *s);
127 void tok_str_add(TokenString *s, int t);
128 void tok_str_free(int *str);
130 #endif /* __TCCPP_H__ */