"Fossies" - the Fresh Open Source Software Archive 
Member "ncc-2.8/global.h" (11 Oct 2008, 7236 Bytes) of package /linux/privat/old/ncc-2.8.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #include "config.h"
2 #include "norm.h"
3 #include "mem_pool.h"
4 #define MSPEC 20
5 #define BITFIELD_Q 64
6
7 #define COLS "\033[01;37m"
8 #define COLE "\033[0m"
9
10 #define PRINTF(...) fprintf (report_stream, __VA_ARGS__)
11
12 extern FILE *report_stream;
13
14 //
15 // the types we'll be using
16 //
17 typedef int NormPtr;
18 typedef int RegionPtr, ObjPtr, typeID, ArglPtr, Symbol, *Vspec;
19 typedef int exprID;
20
21
22 //
23 // preprocessing
24 //
25 extern void preproc (int, char**);
26 extern void ncc_keys ();
27
28
29 //
30 // program options
31 //
32 extern bool usage_only, include_values, include_strings, multiple, abs_paths,
33 report_structs, halt_on_error, pseudo_code, no_error;
34 extern char *sourcefile, *preprocfile, *cwd;
35
36
37 //
38 // inform
39 //
40 extern char* StrDup (char*);
41 extern void debug (const char*, NormPtr, int);
42 extern void prcode (NormPtr, int);
43 extern void prcode (NormPtr, int, Symbol[]);
44 extern void prcode (NormPtr, int, Symbol);
45 extern void printtype (int, int*);
46 extern void printtype (typeID);
47 extern int syntax_error (NormPtr, char* = NULL);
48 extern int syntax_error (char*, char*);
49 extern int syntax_error (NormPtr, char*, char*);
50 extern void half_error (char*, char* = NULL);
51 extern void warning (char*, char = 0);
52 extern char *expand (int);
53 extern int cline_of (NormPtr);
54 extern int cfile_of (NormPtr);
55 extern char *in_file (NormPtr);
56 extern void report_error ();
57 class EXPR_ERROR {public: EXPR_ERROR () {}};
58
59
60 //
61 // lex & normalized C source
62 //
63 struct token
64 {
65 int at_line;
66 unsigned int type;
67 char *p;
68 int len;
69 };
70 extern token CTok;
71
72 struct cfile_i
73 {
74 int indx;
75 char *file;
76 };
77
78 struct clines_i
79 {
80 int ftok, line;
81 };
82
83 extern int* CODE;
84 extern int C_Ntok;
85 extern char** C_Syms;
86 extern int C_Nsyms;
87 extern char** C_Strings;
88 extern int C_Nstrings;
89 extern cfile_i* C_Files;
90 extern int C_Nfiles;
91 extern clines_i* C_Lines;
92 extern int C_Nlines;
93
94 extern double* C_Floats;
95 extern signed char* C_Chars;
96 extern short int* C_Shortints;
97 extern long int* C_Ints;
98 extern unsigned long* C_Unsigned;
99
100 extern struct __builtins__ {
101 int bt__builtin_alloca;
102 int bt__builtin_return_address;
103 int bt__FUNCTION__;
104 int bt__func__;
105 int bt__PRETTY_FUNCTION__;
106 } ccbuiltins;
107
108 extern void enter_token ();
109 extern void enter_file_indicator (char*);
110 extern void prepare ();
111 extern void make_norm ();
112 extern int getint (int);
113 extern void yynorm (char*, int);
114
115 extern Symbol intern_sym;
116
117 //
118 // utilities
119 //
120 extern void intcpycat (int*, const int*, const int*);
121 extern int* intdup (int*);
122 extern int intcmp (int*, int*);
123 extern void intncpy (int*, int*, int);
124 extern inline void intcpy (int *d, const int *s)
125 { while ((*d++ = *s++) != -1); }
126 extern inline int intlen (const int *i)
127 { int l=0; while (*i++ != -1) l++; return l; }
128
129 class load_file
130 {
131 int fd;
132 public:
133 load_file (char*);
134 int success;
135 char *data;
136 int len;
137 ~load_file ();
138 };
139
140 #define ZC_OK 0
141 #define ZC_NA 1
142 #define ZC_AC 2
143 #define ZC_FF 3
144
145 //
146 // the compilation
147 //
148 extern void parse_C ();
149
150
151 //
152 // CDB interface
153 //
154 enum VARSPC {
155 EXTERN, STATIC, DEFAULT
156 };
157
158 typedef bool Ok;
159
160 extern typeID VoidType, SIntType;
161
162 enum BASETYPE {
163 S_CHAR = -20, U_CHAR, S_SINT, U_SINT, S_INT, U_INT,
164 S_LINT, U_LINT, S_LONG, U_LONG, FLOAT, DOUBLE, VOID,
165 _BTLIMIT
166 };
167 #define INTEGRAL(x) (x >= S_CHAR && x <= U_LONG)
168 #define TYPEDEF_BASE 50000
169
170 struct type {
171 int base;
172 Vspec spec;
173 };
174 #define ISFUNCTION(t) ((t).spec [0] == '(')
175 #define T_BASETYPE(t) ((t).base < _BTLIMIT)
176 #define T_BASESTRUCT(t) (t > 0 && t < TYPEDEF_BASE)
177
178 #define ARGLIST_OPEN -2
179 #define SPECIAL_ELLIPSIS -3
180
181 #define INCODE (!INGLOBAL && !INSTRUCT)
182 extern bool INGLOBAL, INSTRUCT, infuncs;
183 extern ArglPtr NoArgSpec;
184 extern void init_cdb ();
185 extern typeID gettype (type&);
186 extern typeID gettype (int, int*);
187 extern ArglPtr make_arglist (typeID*);
188 extern typeID* ret_arglist (ArglPtr);
189 extern void opentype (typeID, type&);
190 extern int base_of (typeID);
191 extern int* spec_of (typeID);
192 extern int esizeof_objptr (ObjPtr);
193 extern int sizeof_typeID (typeID);
194 extern int sizeof_type (int, Vspec);
195 extern int ptr_increment (int, Vspec);
196 extern Ok introduce_obj (Symbol, typeID, VARSPC);
197 extern Ok introduce_tdef (Symbol, typeID);
198 extern ObjPtr lookup_typedef (Symbol);
199 extern Ok is_typedef (Symbol);
200 extern Ok introduce_enumconst (Symbol, int);
201 extern Ok introduce_enumtag (Symbol, bool=false);
202 extern Ok valid_enumtag (Symbol);
203 extern RegionPtr introduce_anon_struct (bool);
204 extern RegionPtr introduce_named_struct (Symbol, bool);
205 extern RegionPtr use_struct_tag (Symbol, bool);
206 extern RegionPtr fwd_struct_tag (Symbol, bool);
207 extern Ok function_definition (Symbol, NormPtr, NormPtr, NormPtr, NormPtr);
208 extern Ok function_no (int, NormPtr*, NormPtr*);
209 extern void open_compound ();
210 extern void close_region ();
211 extern Symbol struct_by_name (RegionPtr);
212 extern void functions_of_file ();
213 extern bool have_function (Symbol);
214 extern bool rename_struct (typeID, Symbol);
215 extern void struct_location (typeID, NormPtr, NormPtr);
216 extern void structs_of_file ();
217 extern void spill_anonymous (RegionPtr);
218
219 //
220 // CDB lookups
221 //
222 struct lookup_object {
223 bool enumconst;
224 int ec;
225 ObjPtr base;
226 RegionPtr FRAME;
227 int displacement;
228 int spec [50];
229 lookup_object (Symbol, bool=true);
230 };
231
232 struct lookup_function {
233 bool fptr;
234 ObjPtr base;
235 RegionPtr FRAME;
236 bool ARGFUNC;
237 int displacement;
238 int spec [50];
239 bool found;
240 lookup_function (Symbol, bool=true);
241 };
242
243 struct lookup_member {
244 ObjPtr base;
245 int spec [50];
246 int displacement;
247 lookup_member (Symbol, RegionPtr);
248 };
249
250
251 //
252 // cc-expressions
253 //
254 enum COPS {
255 VALUE, FVALUE, SVALUE, UVALUE, AVALUE,
256 SYMBOL,
257 FCALL, ARRAY, MEMB,
258 PPPOST, MMPOST,
259 PPPRE, MMPRE, LNEG, OCPL, PTRIND, ADDROF, UPLUS, UMINUS, CAST, SIZEOF,
260 MUL, DIV, REM, ADD, SUB, SHL, SHR,
261 BEQ, BNEQ, CGR, CGRE, CLE, CLEE,
262 BAND, BOR, BXOR,
263 IAND, IOR,
264 GCOND, COND, // assignments taken from norm.h defines
265 COMMA, ARGCOMMA,
266 COMPOUND_RESULT
267 };
268
269 struct subexpr
270 {
271 int action;
272 union {
273 int using_result;
274 long int value;
275 unsigned long int uvalue;
276 double fvalue;
277 Symbol symbol;
278 exprID e;
279 } voici;
280 exprID e;
281 union {
282 typeID cast;
283 Symbol member;
284 exprID eelse;
285 typeID result_type;
286 } voila;
287 };
288
289 struct exprtree
290 {
291 subexpr *ee;
292 int ne;
293 exprID first;
294 };
295
296 extern exprtree CExpr;
297 extern int last_result;
298 extern subexpr *ⅇ
299 extern int &NeTop;
300 extern NormPtr ExpressionPtr;
301 extern typeID typeof_expression ();
302 extern int cc_int_expression ();
303
304 extern struct lrt {
305 int base;
306 int spec [MSPEC];
307 } last_result_type;
308
309 //
310 // expand initializer
311 //
312
313 class dcle
314 {
315 struct {
316 int p;
317 bool marked;
318 int c, max;
319 int s;
320 } nests [30];
321 int ni;
322 Symbol *dclstr;
323 NormPtr p;
324 void openarray ();
325 void openstruct ();
326 NormPtr skipbracket (NormPtr);
327 bool opennest ();
328 bool closenest ();
329 Symbol pexpr [30];
330 public:
331 dcle (Symbol);
332 bool open_bracket ();
333 bool tofield ();
334 bool comma ();
335 bool tostruct (RegionPtr);
336 bool designator (Symbol[]);
337 bool close_bracket ();
338 Symbol* mk_current ();
339 void printexpr ();
340 ~dcle ();
341 };
342
343 //
344 // different behaviour of the compiler
345 //
346 extern class ncci
347 {
348 public:
349 virtual void cc_expression () = 0;
350 virtual void new_function (Symbol) = 0;
351 virtual void inline_assembly (NormPtr, int) = 0;
352 virtual void finir () { }
353 } *ncc;
354
355 extern void set_compilation ();
356 extern void set_usage_report ();