-
Notifications
You must be signed in to change notification settings - Fork 1
/
inc.libyacc.c
179 lines (168 loc) · 3.65 KB
/
inc.libyacc.c
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
/*
* THIS FILE IS INCLUDED BY "grammar.y"!
* do not add to build chain.
* it's put into a separate file to make file navigation a bit easier.
* TODO: the current setup is, at *best*, destined to break at some point...
* this file, lex.l, grammar.y, need to be chained better.
*/
#if defined(HAVE_CONFIG_H)
#include "lex.yy.c"
#else
#if defined(__EMX__) || defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(vms)
#ifdef USE_flex
#include "lexyy.c"
#else
#include "lex_yy.c"
#endif
#else
#include "lex.yy.c"
#endif
#endif
static const char* keywords[] =
{
"const",
"restrict",
"volatile",
"interrupt",
#ifdef vms
"noshare",
"readonly",
#endif
#if defined(MSDOS) || defined(OS2)
"__cdecl",
"__export",
"__far",
"__fastcall",
"__fortran",
"__huge",
"__inline",
"__interrupt",
"__loadds",
"__near",
"__pascal",
"__saveregs",
"__segment",
"__stdcall",
"__syscall",
"_cdecl",
"_cs",
"_ds",
"_es",
"_export",
"_far",
"_fastcall",
"_fortran",
"_huge",
"_interrupt",
"_loadds",
"_near",
"_pascal",
"_saveregs",
"_seg",
"_segment",
"_ss",
"cdecl",
"far",
"huge",
"near",
"pascal",
#ifdef OS2
"__far16",
#endif
#endif
#ifdef __GNUC__
/* gcc aliases */
"__builtin_va_arg",
"__builtin_va_list",
"__const",
"__const__",
"__gnuc_va_list",
"__inline",
"__inline__",
"__restrict",
"__restrict__",
"__volatile",
"__volatile__",
"_Noreturn",
#endif
};
static void yaccError(const char* msg)
{
func_params = NULL;
put_error(); /* tell what line we're on, and what file */
fprintf(stderr, "%s at token '%s'\n", msg, yytext);
}
/* Initialize the table of type qualifier keywords recognized by the lexical
* analyzer.
*/
void init_parser(void)
{
unsigned i;
/* Initialize type qualifier table. */
type_qualifiers = new_symbol_table();
for(i = 0; i < sizeof(keywords) / sizeof(keywords[0]); ++i)
{
new_symbol(type_qualifiers, keywords[i], NULL, DS_NONE);
}
}
/* Process the C source file. Write function prototypes to the standard
* output. Convert function definitions and write the converted source
* code to a temporary file.
*/
void process_file(FILE* infile, const char* name)
{
const char* s;
if(strlen(name) > 2)
{
s = name + strlen(name) - 2;
if(*s == '.')
{
++s;
if(*s == 'l' || *s == 'y')
BEGIN LEXYACC;
#if defined(MSDOS) || defined(OS2)
if(*s == 'L' || *s == 'Y')
BEGIN LEXYACC;
#endif
}
}
included_files = new_symbol_table();
typedef_names = new_symbol_table();
define_names = new_symbol_table();
inc_depth = -1;
curly = 0;
ly_count = 0;
func_params = NULL;
yyin = infile;
include_file(strcpy(base_file, name), func_style != FUNC_NONE);
if(file_comments)
{
if(lintLibrary())
{
put_blankline(stdout);
begin_tracking();
}
put_string(stdout, "/* ");
put_string(stdout, cur_file_name());
put_string(stdout, " */\n");
}
yyparse();
free_symbol_table(define_names);
free_symbol_table(typedef_names);
free_symbol_table(included_files);
}
#ifdef NO_LEAKS
void free_parser(void)
{
free_symbol_table(type_qualifiers);
#ifdef FLEX_SCANNER
if(yy_current_buffer != 0)
yy_delete_buffer(yy_current_buffer);
#endif
if(temp_buf != 0)
{
temp_buf = 0;
temp_len = 0;
}
}
#endif