annotate lwcc/cpp.h @ 305:54f213c8fb81 ccdev

Various bugfixes and output tuning Tuned output of preprocessor to include line markers similar to the ones added by the gcc preprocessor. Also, many fixes for various bits of dumbosity leading to misbehaviour and crashing.
author William Astle <lost@l-w.ca>
date Wed, 18 Sep 2013 19:17:52 -0600
parents d85d173ba120
children b08787e5b9f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
1 /*
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
2 lwcc/cpp.h
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
3
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
4 Copyright © 2013 William Astle
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
5
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
6 This file is part of LWTOOLS.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
7
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
11 version.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
12
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
16 more details.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
17
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
20 */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
21
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
22 #ifndef cpp_h_seen___
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
23 #define cpp_h_seen___
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
24
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
25 #include <stdio.h>
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
26
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
27 //#include "symbol.h"
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
28 #include "token.h"
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
29
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
30 #define TOKBUFSIZE 32
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
31
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
32 struct expand_e
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
33 {
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
34 struct expand_e *next;
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
35 struct symtab_e *s; // symbol table entry of the expanding symbol
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
36 };
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
37
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
38 struct preproc_info
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
39 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
40 const char *fn;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
41 FILE *fp;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
42 struct token *tokqueue;
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
43 struct token *curtok;
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
44 void (*errorcb)(const char *);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
45 void (*warningcb)(const char *);
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
46 int eolstate; // internal for use in handling newlines
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
47 int lineno; // the current input line number
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
48 int column; // the current input column
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
49 int trigraphs; // nonzero if we're going to handle trigraphs
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
50 int ra;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
51 int qseen;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
52 int ungetbufl;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
53 int ungetbufs;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
54 int *ungetbuf;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
55 int unget;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
56 int eolseen;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
57 int nlseen;
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
58 int ppeolseen; // nonzero if we've seen only whitespace (or nothing) since a newline
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
59 int skip_level; // nonzero if we're in a false conditional
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
60 int found_level; // nonzero if we're in a true conditional
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
61 int else_level; // for counting #else directives
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
62 int else_skip_level; // ditto
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
63 struct symtab_e *sh; // the preprocessor's symbol table
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
64 struct token *sourcelist; // for expanding a list of tokens
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
65 struct expand_e *expand_list; // record of which macros are currently being expanded
298
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
66 char *lexstr; // for lexing a string (token pasting)
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
67 int lexstrloc; // ditto
300
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 298
diff changeset
68 struct preproc_info *n; // next in file stack
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 298
diff changeset
69 struct preproc_info *filestack; // stack of saved files during include
304
d85d173ba120 Checkpoint lwcc development - preprocessor is runnable but nonfunctional
William Astle <lost@l-w.ca>
parents: 300
diff changeset
70 struct strpool *strpool;
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
71 };
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
72
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
73 extern struct preproc_info *preproc_init(const char *);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
74 extern struct token *preproc_next_token(struct preproc_info *);
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
75 extern struct token *preproc_next_processed_token(struct preproc_info *);
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
76 extern void preproc_finish(struct preproc_info *);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
77 extern void preproc_register_error_callback(struct preproc_info *, void (*)(const char *));
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
78 extern void preproc_register_warning_callback(struct preproc_info *, void (*)(const char *));
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
79 extern void preproc_throw_error(struct preproc_info *, const char *, ...);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
80 extern void preproc_throw_warning(struct preproc_info *, const char *, ...);
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
81 extern void preproc_unget_token(struct preproc_info *, struct token *);
304
d85d173ba120 Checkpoint lwcc development - preprocessor is runnable but nonfunctional
William Astle <lost@l-w.ca>
parents: 300
diff changeset
82 extern struct token *preproc_next(struct preproc_info *);
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
83
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
84 #endif // cpp_h_seen___