File: ucppi.h

package info (click to toggle)
synopsis 0.12-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 38,112 kB
  • ctags: 18,122
  • sloc: ansic: 41,842; cpp: 39,920; xml: 17,704; python: 13,545; sh: 10,045; yacc: 1,271; makefile: 1,242; lex: 684; asm: 361
file content (196 lines) | stat: -rw-r--r-- 5,893 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * (c) Thomas Pornin 1999 - 2002
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. The name of the authors may not be used to endorse or promote
 *    products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef UCPP__UCPPI__
#define UCPP__UCPPI__

#include "tune.h"
#include "cpp.h"
#include "nhash.h"

/*
 * A macro represented in a compact form; simple tokens are represented
 * by one byte, containing their number. Tokens with a string value are
 * followed by the value (string finished by a 0). Macro arguments are
 * followed by the argument number (in one byte -- thus implying a hard
 * limit of 254 arguments (number 255 is for __VA_ARGS__).
 */
struct comp_token_fifo {
	size_t length;
	size_t rp;
	unsigned char *t;
};

/* These declarations are used only internally by ucpp */

/*
 * S_TOKEN(x)	checks whether x is a token type with an embedded string
 * ttMWS(x)	checks whether x is macro whitespace (space, comment...)
 * ttWHI(x)	checks whether x is whitespace (MWS or newline)
 */
#define S_TOKEN(x)	STRING_TOKEN(x)
#define ttMWS(x)	((x) == NONE || (x) == COMMENT || (x) == OPT_NONE)
#define ttWHI(x)	(ttMWS(x) || (x) == NEWLINE)

/*
 * Function prototypes
 */
/*
 * from lexer.c
 */
#define init_cppm	ucpp_init_cppm
#define put_char	ucpp_put_char
#define discard_char	ucpp_discard_char
#define next_token	ucpp_next_token
#define grap_char	ucpp_grap_char
#define space_char	ucpp_space_char

void init_cppm(void);
void put_char(struct lexer_state *, unsigned char);
void discard_char(struct lexer_state *);
int next_token(struct lexer_state *);
int grap_char(struct lexer_state *);
int space_char(int);

/*
 * from assert.c
 */
struct assert {
	hash_item_header head;    /* first field */
	size_t nbval;
	struct token_fifo *val;
};

#define cmp_token_list		ucpp_cmp_token_list
#define handle_assert		ucpp_handle_assert
#define handle_unassert		ucpp_handle_unassert
#define get_assertion		ucpp_get_assertion
#define wipe_assertions		ucpp_wipe_assertions

int cmp_token_list(struct token_fifo *, struct token_fifo *);
int handle_assert(struct lexer_state *);
int handle_unassert(struct lexer_state *);
struct assert *get_assertion(char *);
void wipe_assertions(void);

/*
 * from macro.c
 */
struct macro {
	hash_item_header head;     /* first field */
	int narg;
	char **arg;
	int nest;
	int vaarg;
#ifdef LOW_MEM
	struct comp_token_fifo cval;
#else
	struct token_fifo val;
#endif
};

#define print_token		ucpp_print_token
#define handle_define		ucpp_handle_define
#define handle_undef		ucpp_handle_undef
#define handle_ifdef		ucpp_handle_ifdef
#define handle_ifndef		ucpp_handle_ifndef
#define substitute_macro	ucpp_substitute_macro
#define get_macro		ucpp_get_macro
#define wipe_macros		ucpp_wipe_macros
#define dsharp_lexer		ucpp_dsharp_lexer
#define compile_time		ucpp_compile_time
#define compile_date		ucpp_compile_date
#ifdef PRAGMA_TOKENIZE
#define tokenize_lexer		ucpp_tokenize_lexer
#endif

void print_token(struct lexer_state *, struct token *, long);
int handle_define(struct lexer_state *);
int handle_undef(struct lexer_state *);
int handle_ifdef(struct lexer_state *);
int handle_ifndef(struct lexer_state *);
int substitute_macro(struct lexer_state *, struct macro *,
	struct token_fifo *, int, int, long);
struct macro *get_macro(char *);
void wipe_macros(void);

extern struct lexer_state dsharp_lexer;
extern char compile_time[], compile_date[];
#ifdef PRAGMA_TOKENIZE
extern struct lexer_state tokenize_lexer;
#endif

/*
 * from eval.c
 */
#define strtoconst	ucpp_strtoconst
#define eval_expr	ucpp_eval_expr
#define eval_line	ucpp_eval_line

unsigned long strtoconst(char *);
unsigned long eval_expr(struct token_fifo *, int *, int);
extern long eval_line;

#define eval_exception	ucpp_eval_exception

#ifdef POSIX_JMP
#define JMP_BUF	sigjmp_buf
#define catch(x)	sigsetjmp((x), 0)
#define throw(x)	siglongjmp((x), 1)
#else
#define JMP_BUF	jmp_buf
#define catch(x)	setjmp((x))
#define throw(x)	longjmp((x), 1)
#endif
extern JMP_BUF eval_exception;

/*
 * from cpp.c
 */
#define token_name		ucpp_token_name
#define throw_away		ucpp_throw_away
#define garbage_collect		ucpp_garbage_collect
#define init_buf_lexer_state	ucpp_init_buf_lexer_state
#ifdef PRAGMA_TOKENIZE
#define compress_token_list	ucpp_compress_token_list
#endif

char *token_name(struct token *);
void throw_away(struct garbage_fifo *, char *);
void garbage_collect(struct garbage_fifo *);
void init_buf_lexer_state(struct lexer_state *, int);
#ifdef PRAGMA_TOKENIZE
struct comp_token_fifo compress_token_list(struct token_fifo *);
#endif

#define ouch		ucpp_ouch
#define error		ucpp_error
#define warning		ucpp_warning

#endif