Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 1531 lines (1221 sloc) 43.674 kb
c6b37cb @nunorc [imcc]: make flex generate headerizer tags and "do not edit" notice f…
nunorc authored
1 %top{
2
22696aa @rurban [cage] Set emacs buffer-read-only analog to vim set ro #1034
rurban authored
3 /* ex: set ro ft=c: -*- buffer-read-only:t -*-
c6b37cb @nunorc [imcc]: make flex generate headerizer tags and "do not edit" notice f…
nunorc authored
4 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
5 *
6 * This file is generated automatically by the Parrot build process
7 * from the file compilers/imcc/imcc.l.
8 *
9 * Any changes made here will be lost!
10 *
11 */
12
13 /* HEADERIZER HFILE: none */
14 /* HEADERIZER STOP */
2f1b469 @chromatic [IMCC] Cleared up compilation warnings in IMCC.
chromatic authored
15
75f2435 @chromatic [src] Cleaned up several warnings (Matt Kraai, RT #51798).
chromatic authored
16 #ifndef __STDC_VERSION__
17 # define __STDC_VERSION__ 0
2f1b469 @chromatic [IMCC] Cleared up compilation warnings in IMCC.
chromatic authored
18 #endif
19
86820df @plobsing eliminate useless includes
plobsing authored
20 #include "imc.h"
21 #include "parser.h"
22
c6b37cb @nunorc [imcc]: make flex generate headerizer tags and "do not edit" notice f…
nunorc authored
23 }
24
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
25 %{
26 /*
6673250 PCC-1: s. ChangeLog and calling_conventions.pod
Leopold Toetsch authored
27 * imcc.l
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
28 *
6529843 Comment fixes.
Melvin Smith authored
29 * Intermediate Code Compiler for Parrot
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
30 *
8fbaef7 @ambs Removed a LOT of global variables.
ambs authored
31 * Copyright (C) 2002 Melvin Smith <melvin.smith@mindspring.com>
8ee1ad7 @allisonrandal [cage] Updating copyright in whole repository to Parrot Foundation.
allisonrandal authored
32 * Copyright (C) 2002-2008, Parrot Foundation.
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
33 *
6529843 Comment fixes.
Melvin Smith authored
34 * The tokenizer.
8fbaef7 @ambs Removed a LOT of global variables.
ambs authored
35 *
36 *
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
37 */
3029b29 @chromatic [IMCC] Cleaned up IMCC code; no behavioral changes.
chromatic authored
38 /* static function declarations */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
39 static void pop_parser_state(ARGMOD(imc_info_t *imcc), ARGMOD(void *yyscanner));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
40
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
41 static struct macro_frame_t *new_frame(ARGMOD(imc_info_t *imcc));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
42
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
43 static void define_macro(ARGMOD(imc_info_t *imcc), ARGIN(const char *name), ARGIN(const params_t *params),
00725ff @petdance isolating the cause of the segfaults without the dupe macro name
petdance authored
44 ARGIN(const char *expansion), int start_line);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
45
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
46 static macro_t *find_macro(ARGMOD(imc_info_t *imcc), ARGIN(const char *name));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
47
00725ff @petdance isolating the cause of the segfaults without the dupe macro name
petdance authored
48 static void scan_string(macro_frame_t *frame, ARGIN(const char *expansion),
49 ARGMOD(void *yyscanner));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
50
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
51 static void scan_file(ARGMOD(imc_info_t *imcc), ARGIN(struct macro_frame_t *frame), PIOHANDLE file,
00725ff @petdance isolating the cause of the segfaults without the dupe macro name
petdance authored
52 ARGMOD(void *yyscanner));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
53
00725ff @petdance isolating the cause of the segfaults without the dupe macro name
petdance authored
54 static int destroy_frame(macro_frame_t *frame, ARGMOD(void *yyscanner));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
55
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
56 static int yylex_skip(YYSTYPE *valp, ARGMOD(imc_info_t *imcc), ARGIN(const char *skip),
00725ff @petdance isolating the cause of the segfaults without the dupe macro name
petdance authored
57 ARGMOD(void *yyscanner));
0170f83 @audreyt * Re-apply the IMCC flex reentrancy patch.
audreyt authored
58
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
59 static int read_macro(YYSTYPE *valp, ARGMOD(imc_info_t *imcc), ARGMOD(void *yyscanner));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
60
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
61 static int expand_macro(ARGMOD(imc_info_t *imcc), ARGIN(const char *name), ARGMOD(void *yyscanner));
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
62
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
63 static void include_file(ARGMOD(imc_info_t *imcc), ARGIN(STRING *file_name), ARGMOD(void *yyscanner));
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
64
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
65 static int handle_identifier(ARGMOD(imc_info_t *imcc), YYSTYPE *valp, ARGIN(const char *id));
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
66
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
67 #define YY_DECL int yylex(YYSTYPE *valp, yyscan_t yyscanner, ARGMOD(imc_info_t *imcc))
963db5f imcc 0.0.9.6, s. Changelog
Leopold Toetsch authored
68
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
69 #define YYCHOP() (yytext[--yyleng] = '\0')
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
70
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
71 #define SET_LINE_NUMBER (imcc->line = yylineno)
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
72
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
73 #define DUP_AND_RET(valp, token) \
74 do { \
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
75 if (valp) (valp)->s = mem_sys_strndup(yytext, yyleng); \
aa881aa @petdance lots of macro wrapping
petdance authored
76 return (token); \
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
77 } while (0)
78
49b34a8 @chromatic [IMCC] Fixed some memory leaks around macros and labels.
chromatic authored
79 #define DUP_AND_RET_FREE(valp, token) \
80 do { \
81 if (valp) { \
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
82 mem_sys_free((valp)->s); \
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
83 (valp)->s = mem_sys_strndup(yytext, yyleng); \
aa881aa @petdance lots of macro wrapping
petdance authored
84 return (token); \
49b34a8 @chromatic [IMCC] Fixed some memory leaks around macros and labels.
chromatic authored
85 } \
86 } while (0)
87
cfd716e @nwellnhof [imcc] Undo initial approach to slurp input files at once
nwellnhof authored
88 #define YY_INPUT(buf, result, max_size) \
d74d1ff @rurban [cage] fix some -Wuseless-cast
rurban authored
89 (result) = Parrot_io_internal_read(yyextra->interp, (PIOHANDLE)yyin, (buf), (max_size))
cfd716e @nwellnhof [imcc] Undo initial approach to slurp input files at once
nwellnhof authored
90
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
91 %}
92
0170f83 @audreyt * Re-apply the IMCC flex reentrancy patch.
audreyt authored
93 %option reentrant
c56c4f8 remove some warnings - thanks to Vladimir Lipskiy for reporting these
Leopold Toetsch authored
94 %option never-interactive
9b6826d make sure pod parsing returns to prev state
Leopold Toetsch authored
95 %option stack
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
96 %option yylineno
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
97
4d8e6cb IMCC will generate error if register type is unknown.
Melvin Smith authored
98 LETTER [a-zA-Z_@]
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
99 DIGIT [0-9]
7ec568c HLL file and line info - s. ChangeLog
Leopold Toetsch authored
100 DIGITS {DIGIT}+
3ba6367 @ambs Support for 0o435 and 0O342 for octal values.
ambs authored
101 HEX 0[xX][0-9A-Fa-f]+
102 OCT 0[oO][0-7]+
1902f19 allow uppercase X and B for hex and bin
Leopold Toetsch authored
103 BIN 0[bB][01]+
3ba6367 @ambs Support for 0o435 and 0O342 for octal values.
ambs authored
104 DOT [.]
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
105 SIGN [-+]
24c7041 Pie-thon 51 - float() function, string_to_num uses atof
Leopold Toetsch authored
106 FLOATNUM {SIGN}?(({DIGITS}{DOT}{DIGIT}*|{DOT}{DIGITS})([eE]{SIGN}?{DIGITS})?|{DIGITS}[eE]{SIGN}?{DIGITS})
4397fec #18747
Leopold Toetsch authored
107 LETTERDIGIT [a-zA-Z0-9_]
500bcd2 @coke Resolve RT #48735; disallow :: in PIR identifiers; remove any usage o…
coke authored
108 LABELLETTERDIGIT([a-zA-Z0-9_@])
0da65ee implement .pcc_sub for PASM assembler; allow :: inside ident::ifier
Leopold Toetsch authored
109 ID {LETTER}{LABELLETTERDIGIT}*
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
110 DQ_STRING \"(\\.|[^"\\\n])*\"
22f716c Pie-thon 40 - unicode string parsing and repr()
Leopold Toetsch authored
111 ENCCHAR {LETTER}|{DIGIT}|"-"
112 ENCCHARS {ENCCHAR}*
113 ENC {LETTER}{ENCCHARS}":"
a35f817 @nwellnhof Remove support for deprecated charset:encoding:"" literals
nwellnhof authored
114 UNICODE {ENC}{DQ_STRING}
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
115 STRINGCONSTANT {SQ_STRING}|{DQ_STRING}
116 SQ_STRING \'[^'\n]*\'
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
117 EOL \r?\n
b26976c allow ctrl-z
Leopold Toetsch authored
118 WS [\t\f\r\x1a ]
7ec568c HLL file and line info - s. ChangeLog
Leopold Toetsch authored
119 SP [ ]
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
120
ca557eb Large patch from Leo, see ChangeLog.
Melvin Smith authored
121 %x emit
30c15a2 revert macro removal
Leopold Toetsch authored
122 %x macro
31d96ee ignore text between POD markers
Leopold Toetsch authored
123 %x pod
7ec568c HLL file and line info - s. ChangeLog
Leopold Toetsch authored
124 %x cmt1
125 %x cmt2
126 %x cmt3
127 %x cmt4
c29fe5d update preprocessor output
Leopold Toetsch authored
128 %x cmt5
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
129 %x heredoc1
130 %x heredoc2
131
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
132
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
133 %%
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
134 /* for emacs "*/
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
135 if (imcc->expect_pasm == 1 && !imcc->in_pod) {
136 imcc->expect_pasm = 2;
ca557eb Large patch from Leo, see ChangeLog.
Melvin Smith authored
137 BEGIN(emit);
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
138 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
139
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
140 if (imcc->frames->s.pasm_file && YYSTATE == INITIAL &&
141 !imcc->in_pod)
8fbaef7 @ambs Removed a LOT of global variables.
ambs authored
142 {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
143 if (imcc->frames->s.pasm_file == 1) {
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
144 BEGIN(emit);
145 return EMIT;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
146 }
147
41d160e eval #1 imcc
Leopold Toetsch authored
148 return 0;
4397fec #18747
Leopold Toetsch authored
149 }
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
150
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
151 <*>^{WS}* { SET_LINE_NUMBER; }
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
152
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
153 <heredoc1>.*{EOL} {
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
154 SET_LINE_NUMBER;
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
155 imcc->frames->heredoc_rest = mem_sys_strndup(yytext, yyleng);
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
156 BEGIN(heredoc2);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
157 }
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
158
159 <heredoc2>{EOL} {
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
160 /* heredocs have highest priority
f10043b @chromatic [IMCC] Improved IMCC line number tracking, especially in macros and o…
chromatic authored
161 * arrange them before all wildcard state matches */
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
162
163 /* Newline in the heredoc. Realloc and cat on. */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
164 imcc->heredoc_content =
165 (char*)mem_sys_realloc(imcc->heredoc_content,
166 strlen(imcc->heredoc_content) + 3);
167 strcpy(imcc->heredoc_content +
168 strlen(imcc->heredoc_content), "\n");
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
169 }
170
903db1c @nwellnhof [imcc] Switch to PIO and STRING filenames for all input files
nwellnhof authored
171 <heredoc2>([^\r\n]|\r[^\n])* {
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
172 SET_LINE_NUMBER;
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
173 /* Are we at the end of the heredoc? */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
174 if (STREQ(imcc->heredoc_end, yytext)) {
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
175 /* End of the heredoc. */
f38a9bc @rurban [cage] fix instances of -Wshadow
rurban authored
176 /*yyguts_t * const yyg = (yyguts_t *)yyscanner;*/
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
177 const int len = strlen(imcc->heredoc_content);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
178
179 /* delim */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
180 imcc->heredoc_content[len] =
181 imcc->heredoc_content[0];
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
182
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
183 imcc->heredoc_content[len + 1] = 0;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
184
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
185 mem_sys_free(imcc->heredoc_end);
186 imcc->heredoc_end = NULL;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
187
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
188 imcc->frames->buffer = YY_CURRENT_BUFFER;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
189 valp->s =
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
190 imcc->heredoc_content;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
191
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
192 yy_pop_state(yyscanner);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
193 yy_scan_string(imcc->frames->heredoc_rest, yyscanner);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
194
195 return STRINGC;
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
196 }
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
197 else {
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
198 /* Part of the heredoc. Realloc and cat the line on. */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
199 imcc->heredoc_content =
200 (char *)mem_sys_realloc(imcc->heredoc_content,
201 strlen(imcc->heredoc_content) +
8fbaef7 @ambs Removed a LOT of global variables.
ambs authored
202 strlen(yytext) + 2);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
203 strcpy(imcc->heredoc_content +
204 strlen(imcc->heredoc_content), yytext);
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
205 }
206 }
207
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
208 <cmt2>[^"]+ {
903db1c @nwellnhof [imcc] Switch to PIO and STRING filenames for all input files
nwellnhof authored
209 STRING *str;
210
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
211 yy_pop_state(yyscanner);
212 yy_push_state(cmt3, yyscanner);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
213
0cf2b8f @rurban trace: shorten the pmc flags and comma->space
rurban authored
214 str = Parrot_str_new(imcc->interp, yytext, 0);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
215 imcc->frames->s.file = str;
216 imcc->cur_unit->file = str;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
217
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
218 return FILECOMMENT;
219 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
220
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
221 <cmt3>["] {
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
222 yy_pop_state(yyscanner);
223 yy_push_state(cmt4, yyscanner);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
224 }
225
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
226 <cmt1>{DIGITS} {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
227 yylineno = imcc->line = atoi(yytext);
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
228 yy_pop_state(yyscanner);
229 yy_push_state(cmt4, yyscanner);
230 return LINECOMMENT;
231 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
232
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
233 <cmt4>.*{EOL} {
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
234 yy_pop_state(yyscanner);
235 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
236
ca557eb Large patch from Leo, see ChangeLog.
Melvin Smith authored
237 <INITIAL,emit>{EOL} {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
238 if (imcc->expect_pasm == 2)
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
239 BEGIN(INITIAL);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
240
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
241 imcc->expect_pasm = 0;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
242
ca557eb Large patch from Leo, see ChangeLog.
Melvin Smith authored
243 return '\n';
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
244 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
245
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
246 <INITIAL,emit># {
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
247 yy_push_state(cmt5, yyscanner);
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
248 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
249
c29fe5d update preprocessor output
Leopold Toetsch authored
250 <cmt5>.*{EOL} {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
251 if (imcc->expect_pasm == 2)
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
252 BEGIN(INITIAL);
c29fe5d update preprocessor output
Leopold Toetsch authored
253 else
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
254 yy_pop_state(yyscanner);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
255
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
256 imcc->expect_pasm = 0;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
257
ea7681b Big Scary Patch:
Sean O'Rourke authored
258 return '\n';
259 }
260
261
ff407fa @kjs [imcc] ignore =cut if not in POD mode.
kjs authored
262 <INITIAL,emit,macro>^"=cut"{EOL} {
f10043b @chromatic [IMCC] Improved IMCC line number tracking, especially in macros and o…
chromatic authored
263 /* this is a stand-alone =cut, but we're not in POD mode, so ignore. */
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
264 SET_LINE_NUMBER;
ff407fa @kjs [imcc] ignore =cut if not in POD mode.
kjs authored
265 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
266
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
267 <INITIAL,emit,macro>^"=".*{EOL} {
268 SET_LINE_NUMBER;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
269 imcc->in_pod = 1;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
270 yy_push_state(pod, yyscanner);
271 }
272
273 <pod>^"=cut"{EOL} {
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
274 SET_LINE_NUMBER;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
275 imcc->in_pod = 0;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
276 yy_pop_state(yyscanner);
af71414 @jnthn Debug Segment Update Part 3: Make files included with .include have t…
jnthn authored
277 }
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
278
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
279 <pod>.* { SET_LINE_NUMBER; }
31d96ee ignore text between POD markers
Leopold Toetsch authored
280
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
281 <pod>{EOL} { /* ignore */ }
779cdde @kjs [imcc] remove .sym from imcc lexer.
kjs authored
282
d027f9b @Infinoid Merge changes from bcanno branch back into trunk.
Infinoid authored
283 <INITIAL,emit>".annotate" return ANNOTATE;
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
284 <INITIAL,emit>".lex" return LEXICAL;
c7f9941 @kjs [imcc] change .arg into .set_arg. Step 1/3. (this step includes all i…
kjs authored
285 ".set_arg" return ARG;
008059c @mlschroe add SET_LINENUMBER to the SUB lexer action
mlschroe authored
286 ".sub" { SET_LINE_NUMBER; return SUB; }
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
287 ".end" return ESUB;
288 ".begin_call" return PCC_BEGIN;
289 ".end_call" return PCC_END;
290 ".call" return PCC_CALL;
291 ".invocant" return INVOCANT;
292 <emit,INITIAL>".pcc_sub" return PCC_SUB;
293 ".begin_return" return PCC_BEGIN_RETURN;
294 ".end_return" return PCC_END_RETURN;
295 ".begin_yield" return PCC_BEGIN_YIELD;
296 ".end_yield" return PCC_END_YIELD;
297
298 <emit,INITIAL>":method" return METHOD;
299 <emit,INITIAL>":multi" return MULTI;
300 <emit,INITIAL>":main" return MAIN;
301 <emit,INITIAL>":load" return LOAD;
302 <emit,INITIAL>":init" return INIT;
303 <emit,INITIAL>":immediate" return IMMEDIATE;
304 <emit,INITIAL>":postcomp" return POSTCOMP;
48d1287 @Whiteknight Add :tag(...) syntax to IMCC. This is just a prototype, but is intend…
Whiteknight authored
305 <emit,INITIAL>":tag" return SUBTAG;
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
306 <emit,INITIAL>":anon" return ANON;
307 <emit,INITIAL>":outer" return OUTER;
308 <emit,INITIAL>":lex" return NEED_LEX;
309 <emit,INITIAL>":vtable" return VTABLE_METHOD;
89c8a31 @tewk [nsentry] ns_entry -> nsentry tokenizer change
tewk authored
310 <emit,INITIAL>":nsentry" return NS_ENTRY;
877dcaf @jnthn [core] Add parsing (but not semantics) for :instanceof('Type') adverb…
jnthn authored
311 ":instanceof" return SUB_INSTANCE_OF;
54c7f97 @tewk [nsentry] method and nsentry now support unicode strings, subid needs…
tewk authored
312 ":subid" return SUBID;
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
313
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
314 ".get_result" return RESULT;
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
315 ".get_results" return GET_RESULTS;
316 ".yield" return YIELDT;
e33e715 @kjs [imcc] In .begin_yield-.end_yield pair, now use .set_yield to set val…
kjs authored
317 ".set_yield" return SET_YIELD;
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
318 ".return" return RETURN;
b1df14f @kjs [imcc] replace .arg by .set_arg, replace .result by .get_result.
kjs authored
319 ".set_return" return SET_RETURN;
6b4c0fd @Whiteknight [IMCC] Activate ".tailcall" syntax in IMCC, as perl RT#58974.
Whiteknight authored
320 ".tailcall" return TAILCALL;
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
321 <emit,INITIAL>".loadlib" return LOADLIB;
38f5a65 @paultcochrane [imcc] Removing unnecessary brackets around arguments to return.
paultcochrane authored
322
323 ":flat" return ADV_FLAT;
324 ":slurpy" return ADV_SLURPY;
325 ":optional" return ADV_OPTIONAL;
326 ":opt_flag" return ADV_OPT_FLAG;
327 ":named" return ADV_NAMED;
328 "=>" return ADV_ARROW;
204f307 @kjs [imcc] Add :invocant flag as a token to lexer and parser. Note: it is…
kjs authored
329 ":invocant" return ADV_INVOCANT;
fcc5985 @Whiteknight [pcc] Add EXPERIMENTAL support for :call_sig on the callee param side…
Whiteknight authored
330 ":call_sig" return ADV_CALL_SIG;
38f5a65 @paultcochrane [imcc] Removing unnecessary brackets around arguments to return.
paultcochrane authored
331
332 <emit,INITIAL>".namespace" return NAMESPACE;
333 <emit,INITIAL>".HLL" return HLL;
079929e @kjs [imcc] remove .namespace x / .endnamespace x syntax. make test passes…
kjs authored
334
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
335 ".local" return LOCAL;
38f5a65 @paultcochrane [imcc] Removing unnecessary brackets around arguments to return.
paultcochrane authored
336 <emit,INITIAL>".const" return CONST;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
337 ".globalconst" return GLOBAL_CONST;
338 ".param" return PARAM;
339 "goto" return GOTO;
340 "if" return IF;
341 "unless" return UNLESS;
342 "null" return PNULL;
343 "int" return INTV;
344 "num" return FLOATV;
ca1686b @Whiteknight [IMCC] remove some special cases for the 'new' keyword and let the no…
Whiteknight authored
345
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
346 "pmc" return PMCV;
347 "string" return STRINGV;
348 "<<" return SHIFT_LEFT;
349 ">>" return SHIFT_RIGHT;
350 ">>>" return SHIFT_RIGHT_U;
351 "&&" return LOG_AND;
352 "||" return LOG_OR;
353 "~~" return LOG_XOR;
354 "<" return RELOP_LT;
355 "<=" return RELOP_LTE;
356 ">" return RELOP_GT;
357 ">=" return RELOP_GTE;
358 "==" return RELOP_EQ;
359 "!=" return RELOP_NE;
360 "**" return POW;
63b3738 @kjs compilers/imcc:
kjs authored
361
b62fb55 @kjs [imcc] remove .pcc_ prefix from directives from the lexer. cleaned up…
kjs authored
362 {WS}+"."{WS}+ return CONCAT;
363 "." return DOT;
20f39e5 @kjs [imcc] remove ".." from IMCCs lexer. This token is only used for slic…
kjs authored
364
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
365 "+=" return PLUS_ASSIGN;
366 "-=" return MINUS_ASSIGN;
367 "*=" return MUL_ASSIGN;
368 "/=" return DIV_ASSIGN;
369 "%=" return MOD_ASSIGN;
370 "//" return FDIV;
371 "//=" return FDIV_ASSIGN;
372 "&=" return BAND_ASSIGN;
373 "|=" return BOR_ASSIGN;
374 "~=" return BXOR_ASSIGN;
375 ">>=" return SHR_ASSIGN;
376 "<<=" return SHL_ASSIGN;
377 ">>>=" return SHR_U_ASSIGN;
378 ".=" return CONCAT_ASSIGN;
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
379
891d9e1 @Whiteknight [compilers/imcc] Allowing .macro_const in *.pir files as per rt#55538.
Whiteknight authored
380 <emit,INITIAL>".macro_const" {
36f24ba @chromatic [IMCC] Plugged a memory leak of names of .macro_const declarations. …
chromatic authored
381 char *macro_name = NULL;
382 int start_cond = YY_START;
383 int macro_exists = 0;
384 int c;
385 int start_line;
30c15a2 revert macro removal
Leopold Toetsch authored
386
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
387 BEGIN(macro);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
388 c = yylex_skip(valp, imcc, " ", yyscanner);
30c15a2 revert macro removal
Leopold Toetsch authored
389
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
390 if (c != IDENTIFIER)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
391 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
392 "Constant names must be identifiers");
393
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
394 imcc->cur_macro_name = macro_name = valp->s;
395 start_line = imcc->line;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
396
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
397 c = yylex_skip(valp, imcc, " ", yyscanner);
30c15a2 revert macro removal
Leopold Toetsch authored
398
399 if (c != INTC && c != FLOATC && c != STRINGC && c != REG)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
400 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
401 "Constant '%s' value must be a number, "
36f24ba @chromatic [IMCC] Plugged a memory leak of names of .macro_const declarations. …
chromatic authored
402 "stringliteral or register", macro_name);
30c15a2 revert macro removal
Leopold Toetsch authored
403
36f24ba @chromatic [IMCC] Plugged a memory leak of names of .macro_const declarations. …
chromatic authored
404 /* macro_name becomes a hash key
405 * the first one needs to remain; destroying the hash frees it
406 * subsequent macro_names need destruction here to avoid leaks */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
407 if (find_macro(imcc, macro_name))
36f24ba @chromatic [IMCC] Plugged a memory leak of names of .macro_const declarations. …
chromatic authored
408 macro_exists = 1;
409
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
410 define_macro(imcc, macro_name, NULL, valp->s, start_line);
e6b661b @chromatic [IMCC] Fixed several memory leaks of string constants in IMCC. There…
chromatic authored
411 mem_sys_free(valp->s);
30c15a2 revert macro removal
Leopold Toetsch authored
412
36f24ba @chromatic [IMCC] Plugged a memory leak of names of .macro_const declarations. …
chromatic authored
413 /* don't leak these */
414 if (macro_exists)
415 mem_sys_free(macro_name);
416
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
417 imcc->cur_macro_name = NULL;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
418
891d9e1 @Whiteknight [compilers/imcc] Allowing .macro_const in *.pir files as per rt#55538.
Whiteknight authored
419 BEGIN(start_cond);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
420 return MACRO;
30c15a2 revert macro removal
Leopold Toetsch authored
421 }
422
891d9e1 @Whiteknight [compilers/imcc] Allowing .macro_const in *.pir files as per rt#55538.
Whiteknight authored
423 <emit,INITIAL>".macro" {
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
424 /* the initial whitespace catcher misses this one */
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
425 SET_LINE_NUMBER;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
426 return read_macro(valp, imcc, yyscanner);
891d9e1 @Whiteknight [compilers/imcc] Allowing .macro_const in *.pir files as per rt#55538.
Whiteknight authored
427 }
428
bc89edf fix heredoc tests with double-quoted strings (r9566)
Leopold Toetsch authored
429 <emit,INITIAL>".include" {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
430 const int c = yylex(valp, yyscanner, imcc);
903db1c @nwellnhof [imcc] Switch to PIO and STRING filenames for all input files
nwellnhof authored
431 STRING *filename;
e6b661b @chromatic [IMCC] Fixed several memory leaks of string constants in IMCC. There…
chromatic authored
432
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
433 if (c != STRINGC)
434 return c;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
435
372bac9 @NotFound [imcc] replace str_dup with mem_sys_strdup in lexer and parser
NotFound authored
436 /* STRINGCs have a mem_sys_strdup()ed valp->s */
e6b661b @chromatic [IMCC] Fixed several memory leaks of string constants in IMCC. There…
chromatic authored
437 mem_sys_free(valp->s);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
438 YYCHOP();
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
439 filename = Parrot_str_new(imcc->interp, yytext + 1, 0);
440 include_file(imcc, filename, yyscanner);
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
441 }
442
30c15a2 revert macro removal
Leopold Toetsch authored
443 <emit,INITIAL>{ID}"$:" {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
444 if (valp) {
445 char *label;
6f35f69 @petdance switching to mem_sys_free(). consting. Removed visible function mk_…
petdance authored
446 size_t len;
30c15a2 revert macro removal
Leopold Toetsch authored
447
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
448 YYCHOP();
30c15a2 revert macro removal
Leopold Toetsch authored
449 YYCHOP();
450
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
451 if (!imcc->frames || !imcc->frames->label)
452 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR, "missing space?");
30c15a2 revert macro removal
Leopold Toetsch authored
453
6f35f69 @petdance switching to mem_sys_free(). consting. Removed visible function mk_…
petdance authored
454 len = yyleng + 10;
455 label = (char *)mem_sys_allocate(len);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
456 snprintf(label, len, "%s%d", yytext, imcc->frames->label);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
457
458 /* XXX: free valp->s if it exists? */
459 valp->s = label;
460 }
30c15a2 revert macro removal
Leopold Toetsch authored
461
462 return LABEL;
463 }
464
465 <emit,INITIAL>{ID}"$" {
77ae9ce @ambs Some spaces/indentation
ambs authored
466 if (valp) {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
467 char *label;
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
468 size_t len;
77ae9ce @ambs Some spaces/indentation
ambs authored
469 YYCHOP();
30c15a2 revert macro removal
Leopold Toetsch authored
470
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
471 if (!imcc->frames || !imcc->frames->label)
472 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR, "missing space?");
718ee7c [perl #32434] [PATCH] Data/Dumper tidbits
Leopold Toetsch authored
473
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
474 len = yyleng + 10;
475 label = (char *)mem_sys_allocate(len);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
476 snprintf(label, len, "%s%d", yytext, imcc->frames->label);
30c15a2 revert macro removal
Leopold Toetsch authored
477
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
478 /* XXX: free valp->s if it exists? */
77ae9ce @ambs Some spaces/indentation
ambs authored
479 valp->s = label;
480 }
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
481
77ae9ce @ambs Some spaces/indentation
ambs authored
482 return IDENTIFIER;
483 }
30c15a2 revert macro removal
Leopold Toetsch authored
484
38f5a65 @paultcochrane [imcc] Removing unnecessary brackets around arguments to return.
paultcochrane authored
485 <emit,INITIAL>"," return COMMA;
ca557eb Large patch from Leo, see ChangeLog.
Melvin Smith authored
486
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
487 <emit,INITIAL>{ID}":" {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
488 /* trim last ':' */
489 YYCHOP();
490
2a17fea @chromatic [IMCC] Whacked one more memory leak. All coretests and Rakudo tests …
chromatic authored
491 if (valp)
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
492 valp->s = mem_sys_strndup(yytext, yyleng);
2a17fea @chromatic [IMCC] Whacked one more memory leak. All coretests and Rakudo tests …
chromatic authored
493
494 return LABEL;
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
495 }
496
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
497 <emit,INITIAL>{DOT}{LETTER}{LETTERDIGIT}* {
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
498 char * const macro_name = mem_sys_strndup(yytext + 1, yyleng - 1);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
499 int failed = expand_macro(imcc, macro_name, yyscanner);
1e0f076 @NotFound [imcc] use a copy of macro name, attempt to fix RT #60926
NotFound authored
500 mem_sys_free(macro_name);
f10043b @chromatic [IMCC] Improved IMCC line number tracking, especially in macros and o…
chromatic authored
501 if (!failed) {
c0afb55 PIR meth call syntax - 1
Leopold Toetsch authored
502 yyless(1);
9527449 require whitespace around CONCAT meaning of DOT
Leopold Toetsch authored
503 return DOT;
c0afb55 PIR meth call syntax - 1
Leopold Toetsch authored
504 }
ca557eb Large patch from Leo, see ChangeLog.
Melvin Smith authored
505 }
4951eb1 #18856 imcc namespace; test stuff
Leopold Toetsch authored
506
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
507
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
508
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
509 <*>{FLOATNUM} DUP_AND_RET(valp, FLOATC);
510 <*>{SIGN}?{DIGIT}+ DUP_AND_RET(valp, INTC);
511 <*>{HEX} DUP_AND_RET(valp, INTC);
512 <*>{BIN} DUP_AND_RET(valp, INTC);
3ba6367 @ambs Support for 0o435 and 0O342 for octal values.
ambs authored
513 <*>{OCT} DUP_AND_RET(valp, INTC);
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
514
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
515 <*>{STRINGCONSTANT} {
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
516 valp->s = mem_sys_strndup(yytext, yyleng);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
517
518 return STRINGC;
4397fec #18747
Leopold Toetsch authored
519 }
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
520
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
521 <*>"<<"{STRINGCONSTANT} {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
522 macro_frame_t *frame;
523
a91a2d1 @jnthn Fix disappearing first blank lines bug in heredocs.
jnthn authored
524 /* Save the string we want to mark the end of the heredoc and snip
525 off newline and quote. */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
526 if (imcc->frames->heredoc_rest)
527 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR, "nested heredoc not supported");
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
528 imcc->heredoc_end = mem_sys_strndup(yytext + 3, yyleng - 3);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
529 imcc->heredoc_end[strlen(imcc->heredoc_end) - 1] = 0;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
530
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
531 if (!strlen(imcc->heredoc_end))
532 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR, "empty heredoc delimiter");
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
533
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
534 frame = new_frame(imcc);
535 frame->s.next = (parser_state_t *)imcc->frames;
536 imcc->frames = frame;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
537
a91a2d1 @jnthn Fix disappearing first blank lines bug in heredocs.
jnthn authored
538 /* Start slurping up the heredoc. */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
539 imcc->heredoc_content = (char *)mem_sys_allocate(2);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
540
541 /* preserve delim */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
542 imcc->heredoc_content[0] = yytext[2];
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
543
544 /* eos */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
545 imcc->heredoc_content[1] = 0;
1c58556 Getting rid of static variable prev_state. First set of changes
Vishal Soni authored
546 yy_push_state(heredoc1, yyscanner);
d864ef5 @jnthn Modify the lexer to support heredocs
jnthn authored
547 }
548
22f716c Pie-thon 40 - unicode string parsing and repr()
Leopold Toetsch authored
549 <*>{UNICODE} {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
550 /* charset:"..." */
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
551 valp->s = mem_sys_strndup(yytext, yyleng);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
552
5282427 Strings. Finally. 1 - charset syntax for constants
Leopold Toetsch authored
553 /* this is actually not unicode but a string with a charset */
38f5a65 @paultcochrane [imcc] Removing unnecessary brackets around arguments to return.
paultcochrane authored
554 return USTRINGC;
22f716c Pie-thon 40 - unicode string parsing and repr()
Leopold Toetsch authored
555 }
d864ef5 @jnthn Modify the lexer to support heredocs
jnthn authored
556
fc7a7a5 @chromatic [IMCC] Plug another small handful of memory leaks.
chromatic authored
557 <emit,INITIAL>\$I[0-9]+ {
558 if (valp) (valp)->s = yytext;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
559 if (imcc->state->pasm_file)
560 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
561 "'%s' is not a valid register name in pasm mode", yytext);
fc7a7a5 @chromatic [IMCC] Plug another small handful of memory leaks.
chromatic authored
562 return IREG;
563 }
564
565 <emit,INITIAL>\$N[0-9]+ {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
566 if (valp)
567 (valp)->s = yytext;
568 if (imcc->state->pasm_file)
569 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
570 "'%s' is not a valid register name in pasm mode", yytext);
fc7a7a5 @chromatic [IMCC] Plug another small handful of memory leaks.
chromatic authored
571 return NREG;
572 }
573
574 <emit,INITIAL>\$S[0-9]+ {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
575 if (valp)
576 (valp)->s = yytext;
577 if (imcc->state->pasm_file)
578 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
579 "'%s' is not a valid register name in pasm mode", yytext);
fc7a7a5 @chromatic [IMCC] Plug another small handful of memory leaks.
chromatic authored
580 return SREG;
581 }
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
582
9b76397 @chromatic [IMCC] Removed one memory leak from the lexer. More remain.
chromatic authored
583 <emit,INITIAL>\$P[0-9]+ {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
584 if (valp)
585 (valp)->s = yytext;
586 if (imcc->state->pasm_file)
587 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
588 "'%s' is not a valid register name in pasm mode", yytext);
fc7a7a5 @chromatic [IMCC] Plug another small handful of memory leaks.
chromatic authored
589 return PREG;
590 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
591
24aeb1c @nunorc [imcc]
nunorc authored
592 <emit,INITIAL>\$[a-zA-Z0-9]+ {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
593 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
594 "'%s' is not a valid register name", yytext);
24aeb1c @nunorc [imcc]
nunorc authored
595 }
596
dbee1b1 @kjs [imcc] Disallow PASM registers. This is a huge patch, but that's to p…
kjs authored
597 <emit,INITIAL>[ISNP]{DIGIT}{DIGIT}? {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
598 if (imcc->state->pasm_file == 0)
599 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
dbee1b1 @kjs [imcc] Disallow PASM registers. This is a huge patch, but that's to p…
kjs authored
600 "'%s' is only a valid register name in PASM mode", yytext);
601
eb9d798 @kjs [imcc] do str_dup() after the PASM reg check, as suggested by chromat…
kjs authored
602 if (valp)
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
603 valp->s = mem_sys_strndup(yytext, yyleng);
eb9d798 @kjs [imcc] do str_dup() after the PASM reg check, as suggested by chromat…
kjs authored
604
dbee1b1 @kjs [imcc] Disallow PASM registers. This is a huge patch, but that's to p…
kjs authored
605 return REG;
606 }
607
608
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
609 <emit,INITIAL>{ID} { return handle_identifier(imcc, valp, yytext); }
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
610
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
611 <emit,INITIAL>{WS}+ /* skip */;
612
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
613 <emit,cmt1,cmt2,cmt3,cmt4,cmt5,INITIAL>. {
b673e3a [BUG] imcc: no newline at end of file
Leopold Toetsch authored
614 /* catch all except for state macro */
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
615 return yytext[0];
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
616 }
617
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
618 <emit><<EOF>> {
4938fc1 @paultcochrane [imcc] Adjusted parenthesis spacing according to coding standards.
paultcochrane authored
619 BEGIN(INITIAL);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
620
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
621 if (imcc->frames->s.pasm_file) {
622 imcc->frames->s.pasm_file = 2;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
623 return EOM;
624 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
625
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
626 return 0;
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
627 }
628
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
629 <INITIAL><<EOF>> yyterminate();
630
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
631 <macro>".endm" {
632 /* the initial whitespace catcher misses this one */
687ffe1 @chromatic [IMCC] Made IMCC use Flex's line numbers instead of tracking them its…
chromatic authored
633 SET_LINE_NUMBER;
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
634 DUP_AND_RET(valp, ENDM);
635 }
30c15a2 revert macro removal
Leopold Toetsch authored
636
637 <macro>{WS}*{EOL} {
638 DUP_AND_RET(valp, '\n');
639 }
640
641 <macro>"$"{ID}":" return LABEL;
642
12cb8c8 @bschmalhofer Add '.label' as a synonym of '.local' im macros.
bschmalhofer authored
643 <macro>".label"{WS}+ {
644
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
645 if (yylex(valp, yyscanner, imcc) != LABEL)
646 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR, "LABEL expected");
12cb8c8 @bschmalhofer Add '.label' as a synonym of '.local' im macros.
bschmalhofer authored
647
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
648 if (valp) {
649 char *label;
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
650 size_t len;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
651 YYCHOP();
12cb8c8 @bschmalhofer Add '.label' as a synonym of '.local' im macros.
bschmalhofer authored
652
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
653 len = strlen(imcc->cur_macro_name) + yyleng + 15;
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
654 label = (char *)mem_sys_allocate(len);
12cb8c8 @bschmalhofer Add '.label' as a synonym of '.local' im macros.
bschmalhofer authored
655
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
656 snprintf(label, len, "local__%s__%s__$:",
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
657 imcc->cur_macro_name, yytext+1);
12cb8c8 @bschmalhofer Add '.label' as a synonym of '.local' im macros.
bschmalhofer authored
658
94c03e4 @chromatic [IMCC] Plugged a memory leak of the comma separating macro parameters…
chromatic authored
659 if (valp->s)
660 mem_sys_free(valp->s);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
661 valp->s = label;
662 }
12cb8c8 @bschmalhofer Add '.label' as a synonym of '.local' im macros.
bschmalhofer authored
663
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
664 return LABEL;
665 }
30c15a2 revert macro removal
Leopold Toetsch authored
666
667 <macro>".$"{ID} {
f56e9c2 @chromatic [IMCC] Forbade use of relative macro labels in PIR (in IMCC anyway). …
chromatic authored
668 if (valp) {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
669 if (!imcc->cur_macro_name) {
f56e9c2 @chromatic [IMCC] Forbade use of relative macro labels in PIR (in IMCC anyway). …
chromatic authored
670 if (valp->s)
671 mem_sys_free(valp->s);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
672 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
f56e9c2 @chromatic [IMCC] Forbade use of relative macro labels in PIR (in IMCC anyway). …
chromatic authored
673 "Invalid LABEL outside of macro");
674 }
675 else {
7ff3a8b @bacek Constify some bison/flex strings
bacek authored
676 const char * const fmt = "local__%s__%s__$";
dbdddde @chromatic [IMCC] Refactored a magic constant into intention-revealing code and …
chromatic authored
677 const size_t fmtlen = strlen(fmt) - (2 * strlen("%s"));
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
678 const size_t len = strlen(imcc->cur_macro_name)
dbdddde @chromatic [IMCC] Refactored a magic constant into intention-revealing code and …
chromatic authored
679 + yyleng + fmtlen;
680 char * const label = (char *)mem_sys_allocate(len);
681
682 /* skip over ".$" prefix with the +2 */
683 snprintf(label, len, fmt,
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
684 imcc->cur_macro_name, yytext + 2);
30c15a2 revert macro removal
Leopold Toetsch authored
685
94c03e4 @chromatic [IMCC] Plugged a memory leak of the comma separating macro parameters…
chromatic authored
686 if (valp->s)
687 mem_sys_free(valp->s);
67113a3 @petdance removed two unnecessary str_dup calls, and switched a sprintf() to sn…
petdance authored
688 valp->s = label;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
689 }
30c15a2 revert macro removal
Leopold Toetsch authored
690 }
691
f56e9c2 @chromatic [IMCC] Forbade use of relative macro labels in PIR (in IMCC anyway). …
chromatic authored
692 return IDENTIFIER;
693 }
694
30c15a2 revert macro removal
Leopold Toetsch authored
695 <macro>{WS}+ DUP_AND_RET(valp, ' ');
dbee1b1 @kjs [imcc] Disallow PASM registers. This is a huge patch, but that's to p…
kjs authored
696 <macro>[SNIP]{DIGITS} DUP_AND_RET(valp, REG);
697 <macro>"$"[SNIP]{DIGITS} DUP_AND_RET(valp, REG);
30c15a2 revert macro removal
Leopold Toetsch authored
698 <macro>{ID} DUP_AND_RET(valp, IDENTIFIER);
699 <macro>{DOT}{ID} DUP_AND_RET(valp, MACRO);
700 <macro>. DUP_AND_RET(valp, yytext[0]);
701 <macro><<EOF>> yyterminate();
702
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
703 %%
704
705 #ifdef yywrap
ad4a212 @paultcochrane [compilers] Correcting indentation of preprocessor directives (part 1)
paultcochrane authored
706 # undef yywrap
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
707 #endif
708
4938fc1 @paultcochrane [imcc] Adjusted parenthesis spacing according to coding standards.
paultcochrane authored
709 int yywrap(void* yyscanner) {
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
710 /* Add code here to open next source file and start scanning
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
711 * yywrap returns 0 if scanning is to continue */
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
712 imc_info_t * imcc = yyget_extra(yyscanner);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
713 yyguts_t * const yyg = (yyguts_t *)yyscanner;
8fbaef7 @ambs Removed a LOT of global variables.
ambs authored
714
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
715 if (!imcc->interp) {
1c66167 @nunorc [compilers/imcc]
nunorc authored
716 fprintf(stderr, "Argh, interp not found\n");
4938fc1 @paultcochrane [imcc] Adjusted parenthesis spacing according to coding standards.
paultcochrane authored
717 exit(1);
8fbaef7 @ambs Removed a LOT of global variables.
ambs authored
718 }
719
0170f83 @audreyt * Re-apply the IMCC flex reentrancy patch.
audreyt authored
720 yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner);
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
721
db8c880 switch PASM,PIR mode for include files
Leopold Toetsch authored
722 /* pop old frame */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
723 if (imcc->frames->s.next) {
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
724 pop_parser_state(imcc, yyscanner);
db8c880 switch PASM,PIR mode for include files
Leopold Toetsch authored
725 if (YYSTATE == INITIAL || YYSTATE == emit)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
726 BEGIN(imcc->frames->s.pasm_file ? emit : INITIAL);
0a070ce remove a bunch of IMCC globals
Leopold Toetsch authored
727 return 0;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
728 }
729
3549d6b First version of the intermediate language compiler.
Melvin Smith authored
730 return 1;
731 }
732
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
733 static macro_frame_t *
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
734 new_frame(ARGMOD(imc_info_t *imcc)) {
735 macro_frame_t * const tmp = mem_gc_allocate_zeroed_typed(imcc->interp, macro_frame_t);
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
736
510b6c0 @Whiteknight Fix all instances of global/static variables in IMCC which had been m…
Whiteknight authored
737 tmp->label = imcc->unique_count;
738 imcc->unique_count++;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
739 tmp->s.line = imcc->line;
cfd716e @nwellnhof [imcc] Undo initial approach to slurp input files at once
nwellnhof authored
740 tmp->s.handle = PIO_INVALID_HANDLE;
30c15a2 revert macro removal
Leopold Toetsch authored
741
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
742 if (imcc->frames) {
743 tmp->s.pasm_file = imcc->frames->s.pasm_file;
744 if (imcc->frames->s.file)
745 tmp->s.file = imcc->frames->s.file;
0a070ce remove a bunch of IMCC globals
Leopold Toetsch authored
746 }
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
747
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
748 tmp->s.interp = imcc->interp;
30c15a2 revert macro removal
Leopold Toetsch authored
749
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
750 return tmp;
751 }
752
753 static void
f685873 @petdance removed an unnecessary malloc/free pairing
petdance authored
754 scan_string(macro_frame_t *frame, ARGIN(const char *expansion), void *yyscanner)
30c15a2 revert macro removal
Leopold Toetsch authored
755 {
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
756 yyguts_t * const yyg = (yyguts_t *)yyscanner;
757 imc_info_t * imcc = yyget_extra(yyscanner);
8fbaef7 @ambs Removed a LOT of global variables.
ambs authored
758
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
759 frame->buffer = YY_CURRENT_BUFFER;
760 frame->s.next = (parser_state_t *)imcc->frames;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
761 imcc->frames = frame;
30c15a2 revert macro removal
Leopold Toetsch authored
762
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
763 /* start at the effective *starting line* of the macro */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
764 imcc->line = frame->s.line - 2;
aa4c64a @chromatic [IMCC] Revised line number counting to start at the *start* of a line…
chromatic authored
765
0170f83 @audreyt * Re-apply the IMCC flex reentrancy patch.
audreyt authored
766 yy_scan_string(expansion, yyscanner);
30c15a2 revert macro removal
Leopold Toetsch authored
767 }
768
554a94c @ambs Removed the 'line' global variable and added it to IMCC_INFO
ambs authored
769 static int
4938fc1 @paultcochrane [imcc] Adjusted parenthesis spacing according to coding standards.
paultcochrane authored
770 destroy_frame(struct macro_frame_t *frame, void *yyscanner)
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
771 {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
772 YY_BUFFER_STATE buffer = frame->buffer;
773 int ret = 0;
774 int i;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
775
30c15a2 revert macro removal
Leopold Toetsch authored
776 for (i = 0; i < frame->expansion.num_param; i++) {
f685873 @petdance removed an unnecessary malloc/free pairing
petdance authored
777 mem_sys_free(frame->expansion.name[i]);
778 frame->expansion.name[i] = NULL;
30c15a2 revert macro removal
Leopold Toetsch authored
779 }
780
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
781 if (frame->heredoc_rest) {
c7858ba Variable-sized reg frames 29 - remove now obsolete foldup
Leopold Toetsch authored
782 mem_sys_free(frame->heredoc_rest);
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
783 frame->heredoc_rest = NULL;
bb282e3 @petdance get the regex for cuddled elses a little broader, and then fix the cu…
petdance authored
784 }
785 else {
554a94c @ambs Removed the 'line' global variable and added it to IMCC_INFO
ambs authored
786 ret = frame->s.line;
bb282e3 @petdance get the regex for cuddled elses a little broader, and then fix the cu…
petdance authored
787 }
2b334c9 imcc: macros: line numbers; lifeinfo f. restoreall..
Leopold Toetsch authored
788
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
789 mem_sys_free(frame);
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
790
49b34a8 @chromatic [IMCC] Fixed some memory leaks around macros and labels.
chromatic authored
791 if (buffer != NULL)
0170f83 @audreyt * Re-apply the IMCC flex reentrancy patch.
audreyt authored
792 yy_switch_to_buffer(buffer, yyscanner);
554a94c @ambs Removed the 'line' global variable and added it to IMCC_INFO
ambs authored
793
794 return ret;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
795 }
796
797 static int
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
798 yylex_skip(YYSTYPE *valp, ARGMOD(imc_info_t *imcc), const char *skip, void *yyscanner)
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
799 {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
800 int c;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
801 const char *p;
ee7aa2b @petdance Add an assertion in scan_string, and hoist some redundant code. Also…
petdance authored
802 yyguts_t * const yyg = (yyguts_t *)yyscanner;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
803
804 do {
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
805 c = yylex(valp, yyscanner, imcc);
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
806 p = skip;
77ae9ce @ambs Some spaces/indentation
ambs authored
807
808 while (*p && c != *p)
809 p++;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
810
c0084a2 @chromatic [IMCC] Made yylex_skip() free any str_dup()ed strings if it has to ru…
chromatic authored
811 /* leave loop early if it gets found */
812 if (*p == '\0')
813 break;
814
372bac9 @NotFound [imcc] replace str_dup with mem_sys_strdup in lexer and parser
NotFound authored
815 /* free any mem_sys_strdup()ed strings */
c0084a2 @chromatic [IMCC] Made yylex_skip() free any str_dup()ed strings if it has to ru…
chromatic authored
816 if (yytext)
817 mem_sys_free(valp->s);
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
818 } while (*p != '\0');
77ae9ce @ambs Some spaces/indentation
ambs authored
819
df0f41e fix macro test and vtable init
Leopold Toetsch authored
820 if (c)
49b34a8 @chromatic [IMCC] Fixed some memory leaks around macros and labels.
chromatic authored
821 DUP_AND_RET_FREE(valp, c);
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
822
823 return c;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
824 }
825
f8a867f Add brace support for macros
Joshua Isom authored
826 static char*
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
827 read_braced(YYSTYPE *valp, ARGMOD(imc_info_t *imcc), const char *macro_name,
64ceafe @ambs Error recover on imcc parser. imcparser generated with bison 2.3,
ambs authored
828 char *current, void *yyscanner)
f8a867f Add brace support for macros
Joshua Isom authored
829 {
830 YYSTYPE val;
be963f7 @petdance Switch to size_t where appropriate. Switch to some snprintf()s
petdance authored
831 size_t len = strlen(current);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
832 int c = yylex(&val, yyscanner, imcc);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
833 int count = 0;
0e8691b C89 compliance
Leopold Toetsch authored
834
f8a867f Add brace support for macros
Joshua Isom authored
835 while (c != '}' || count > 0) {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
836
837 if (c == '}')
838 count--;
839 else if (c == '{')
840 count++;
841
f8a867f Add brace support for macros
Joshua Isom authored
842 if (c <= 0)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
843 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
77ae9ce @ambs Some spaces/indentation
ambs authored
844 "End of file reached while reading arguments in '%s'",
845 macro_name);
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
846
847 len += strlen(val.s);
8922f7b @bacek Fix IMCC to use mem_sys_alloc/mem_sys_realloc/mem_sys_free
bacek authored
848 current = (char *)mem_sys_realloc(current, len + 1);
f8a867f Add brace support for macros
Joshua Isom authored
849 strcat(current,val.s);
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
850
f685873 @petdance removed an unnecessary malloc/free pairing
petdance authored
851 mem_sys_free(val.s);
852 val.s = NULL;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
853 c = yylex(&val, yyscanner, imcc);
f8a867f Add brace support for macros
Joshua Isom authored
854 }
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
855
798b42b @chromatic [IMCC] Plugged a memory leak in PIR macros using curly braces to deli…
chromatic authored
856 if (valp) {
857 if (valp->s)
858 mem_sys_free(valp->s);
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
859 *valp = val;
798b42b @chromatic [IMCC] Plugged a memory leak in PIR macros using curly braces to deli…
chromatic authored
860 }
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
861 else
f685873 @petdance removed an unnecessary malloc/free pairing
petdance authored
862 mem_sys_free(val.s);
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
863
f8a867f Add brace support for macros
Joshua Isom authored
864 return current;
865 }
866
30c15a2 revert macro removal
Leopold Toetsch authored
867 static int
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
868 read_params(YYSTYPE *valp, ARGMOD(imc_info_t *imcc), params_t *params,
dc4aae1 @petdance Isolating memory stomp in RT #50920. Also switched to flex 2.5.33 so…
petdance authored
869 ARGIN(const char *macro_name), int need_id, void *yyscanner)
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
870 {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
871 YYSTYPE val;
01af69d @chromatic [IMCC] Fixed signedness of all values passed to system calls such as …
chromatic authored
872 size_t len = 0;
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
873 char *current = mem_sys_strndup("", 0);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
874 yyguts_t *yyg = (yyguts_t *)yyscanner;
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
875 int c = yylex_skip(&val, imcc, " \n", yyscanner);
30c15a2 revert macro removal
Leopold Toetsch authored
876
877 params->num_param = 0;
878
3ddc172 @paultcochrane [imcc] Corrected spacing of keywords wrt parentheses as per coding st…
paultcochrane authored
879 while (c != ')') {
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
880 if (YYSTATE == heredoc2)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
881 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
882 "Heredoc in macro '%s' not allowed", macro_name);
883
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
884 if (c <= 0)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
885 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
77ae9ce @ambs Some spaces/indentation
ambs authored
886 "End of file reached while reading arguments in '%s'",
887 macro_name);
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
888 else if (c == ',') {
30c15a2 revert macro removal
Leopold Toetsch authored
889 if (params->num_param == MAX_PARAM)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
890 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
891 "More than %d params in '%s'",
77ae9ce @ambs Some spaces/indentation
ambs authored
892 MAX_PARAM, macro_name);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
893
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
894 params->name[params->num_param++] = current;
3fc4752 @felipensp - Added mem_sys_strndup() function which saves unnecessary strlen() c…
felipensp authored
895 current = mem_sys_strndup("", 0);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
896 len = 0;
897
94c03e4 @chromatic [IMCC] Plugged a memory leak of the comma separating macro parameters…
chromatic authored
898 if (val.s)
899 mem_sys_free(val.s);
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
900 c = yylex_skip(&val, imcc, " \n", yyscanner);
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
901 }
902 else if (need_id && (*current || c != IDENTIFIER) && c != ' ') {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
903 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
77ae9ce @ambs Some spaces/indentation
ambs authored
904 "Parameter definition in '%s' must be IDENTIFIER",
905 macro_name);
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
906 }
f8a867f Add brace support for macros
Joshua Isom authored
907 else if (c == '{') {
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
908 current = read_braced(&val, imcc, macro_name, current, yyscanner);
798b42b @chromatic [IMCC] Plugged a memory leak in PIR macros using curly braces to deli…
chromatic authored
909 mem_sys_free(val.s);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
910 c = yylex_skip(&val, imcc, " \n", yyscanner);
11a3926 @chromatic [IMCC] Fixed IMCC macro handling -- when reading braced contents of a…
chromatic authored
911 len = strlen(current);
f8a867f Add brace support for macros
Joshua Isom authored
912 }
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
913 else {
914 if (!need_id || c != ' ') {
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
915 len += strlen(val.s);
8922f7b @bacek Fix IMCC to use mem_sys_alloc/mem_sys_realloc/mem_sys_free
bacek authored
916 current = (char *)mem_sys_realloc(current, len + 1);
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
917 strcat(current, val.s);
648ffb6 better diagnostics for #37600
Leopold Toetsch authored
918 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
919
6f35f69 @petdance switching to mem_sys_free(). consting. Removed visible function mk_…
petdance authored
920 mem_sys_free(val.s);
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
921 val.s = NULL;
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
922 c = yylex(&val, yyscanner, imcc);
af71414 @jnthn Debug Segment Update Part 3: Make files included with .include have t…
jnthn authored
923 }
30c15a2 revert macro removal
Leopold Toetsch authored
924 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
925
30c15a2 revert macro removal
Leopold Toetsch authored
926 params->name[params->num_param++] = current;
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
927
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
928 if (valp)
929 *valp = val;
930 else
6f35f69 @petdance switching to mem_sys_free(). consting. Removed visible function mk_…
petdance authored
931 mem_sys_free(val.s);
9ccf610 imcc-opt: J.Boemmels patch #21033; much more optimizations
Leopold Toetsch authored
932
30c15a2 revert macro removal
Leopold Toetsch authored
933 return c;
934 }
935
936 static int
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
937 read_macro(YYSTYPE *valp, ARGMOD(imc_info_t *imcc), void *yyscanner)
30c15a2 revert macro removal
Leopold Toetsch authored
938 {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
939 int c, start_line;
940 params_t params;
2d8dd0f @petdance unreverted the macro_name str_dup patch. See http://rt.perl.org/rt3/…
petdance authored
941 yyguts_t * const yyg = (yyguts_t *)yyscanner;
bb35555 @chromatic [IMCC] Replaced a static 4096-byte buffer from the imc_info_t struct …
chromatic authored
942 int start_cond = YY_START;
01af69d @chromatic [IMCC] Fixed signedness of all values passed to system calls such as …
chromatic authored
943 size_t buffer_size = 0;
944 size_t buffer_used = 0;
30c15a2 revert macro removal
Leopold Toetsch authored
945
946 BEGIN(macro);
947
3094d55 @Whiteknight rebuild the lexer and parser files. reheaderizer. Some fixes. Some fi…
Whiteknight authored
948 c = yylex_skip(valp, imcc, " ", yyscanner);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
949
30c15a2 revert macro removal
Leopold Toetsch authored
950 if (c != IDENTIFIER)
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
951 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR, "Macro names must be identifiers");
30c15a2 revert macro removal
Leopold Toetsch authored
952
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
953 imcc->cur_macro_name = valp->s;
954 start_line = imcc->line;
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
955
ef60364 @chromatic [IMCC] Fixed more compiler warnings in IMCC.
chromatic authored
956 memset(&params, 0, sizeof (params_t));
30c15a2 revert macro removal
Leopold Toetsch authored
957
958 /* white space is allowed between macro and opening paren) */
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
959 c = yylex_skip(valp, imcc, " ", yyscanner);
30c15a2 revert macro removal
Leopold Toetsch authored
960
961 if (c == '(') {
6f35f69 @petdance switching to mem_sys_free(). consting. Removed visible function mk_…
petdance authored
962 mem_sys_free(valp->s);
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
963 valp->s = NULL;
30c15a2 revert macro removal
Leopold Toetsch authored
964
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
965 c = read_params(NULL, imcc, &params,
966 imcc->cur_macro_name, 1, yyscanner);
30c15a2 revert macro removal
Leopold Toetsch authored
967
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
968 c = yylex(valp, yyscanner, imcc);
30c15a2 revert macro removal
Leopold Toetsch authored
969 }
970
971 while (c != ENDM) {
acf013e @chromatic [IMCC] Changed some memory allocation properties of macros in order t…
chromatic authored
972 int elem_len;
bb35555 @chromatic [IMCC] Replaced a static 4096-byte buffer from the imc_info_t struct …
chromatic authored
973
acf013e @chromatic [IMCC] Changed some memory allocation properties of macros in order t…
chromatic authored
974 if (c <= 0) {
975 mem_sys_free(valp->s);
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
976 IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
bc43b2d @paultcochrane r4935@avon: cochrane | 2006-11-07 21:50:15 +0100
paultcochrane authored
977 "File ended before macro '%s' was complete",
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
978 imcc->cur_macro_name);
acf013e @chromatic [IMCC] Changed some memory allocation properties of macros in order t…
chromatic authored
979 }
37ff495 @chipdude Keep macros in a hash, thus eliminating N_MACROS forevermore.
chipdude authored
980
1a4d71d @chromatic [IMCC] Removed a misguided assert in read_macro(); when looping throu…
chromatic authored
981 if (valp->s) {
982 elem_len = strlen(valp->s);
bb35555 @chromatic [IMCC] Replaced a static 4096-byte buffer from the imc_info_t struct …
chromatic authored
983
1a4d71d @chromatic [IMCC] Removed a misguided assert in read_macro(); when looping throu…
chromatic authored
984 if (buffer_used) {
985 if (buffer_used + elem_len > buffer_size) {
986 buffer_size += elem_len;
987 buffer_size <<= 1;
bb35555 @chromatic [IMCC] Replaced a static 4096-byte buffer from the imc_info_t struct …
chromatic authored
988
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
989 imcc->macro_buffer =
990 (char *)mem_sys_realloc(imcc->macro_buffer,
1a4d71d @chromatic [IMCC] Removed a misguided assert in read_macro(); when looping throu…
chromatic authored
991 buffer_size);
992 }
bb35555 @chromatic [IMCC] Replaced a static 4096-byte buffer from the imc_info_t struct …
chromatic authored
993 }
1a4d71d @chromatic [IMCC] Removed a misguided assert in read_macro(); when looping throu…
chromatic authored
994 else {
995 buffer_size = (elem_len << 1) > 1024 ? elem_len << 1 : 1024;
bb35555 @chromatic [IMCC] Replaced a static 4096-byte buffer from the imc_info_t struct …
chromatic authored
996
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
997 imcc->macro_buffer =
1a4d71d @chromatic [IMCC] Removed a misguided assert in read_macro(); when looping throu…
chromatic authored
998 (char *)mem_sys_allocate_zeroed(buffer_size);
999 }
acf013e @chromatic [IMCC] Changed some memory allocation properties of macros in order t…
chromatic authored
1000
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1001 strcat(imcc->macro_buffer, valp->s);
1a4d71d @chromatic [IMCC] Removed a misguided assert in read_macro(); when looping throu…
chromatic authored
1002 buffer_used += elem_len;
30c15a2 revert macro removal
Leopold Toetsch authored
1003
1a4d71d @chromatic [IMCC] Removed a misguided assert in read_macro(); when looping throu…
chromatic authored
1004 mem_sys_free(valp->s);
1005 valp->s = NULL;
1006 }
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1007 c = yylex(valp, yyscanner, imcc);
30c15a2 revert macro removal
Leopold Toetsch authored
1008 }
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
1009
6f35f69 @petdance switching to mem_sys_free(). consting. Removed visible function mk_…
petdance authored
1010 mem_sys_free(valp->s);
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
1011 valp->s = NULL;
30c15a2 revert macro removal
Leopold Toetsch authored
1012
1013 BEGIN(start_cond);
1014
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1015 define_macro(imcc, imcc->cur_macro_name,
1016 &params, imcc->macro_buffer, start_line);
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
1017
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1018 mem_sys_free(imcc->macro_buffer);
1019 imcc->macro_buffer = NULL;
1020 imcc->cur_macro_name = NULL;
37ff495 @chipdude Keep macros in a hash, thus eliminating N_MACROS forevermore.
chipdude authored
1021
30c15a2 revert macro removal
Leopold Toetsch authored
1022 return MACRO;
1023 }
1024
1025 static char *
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1026 find_macro_param(ARGMOD(imc_info_t *imcc), const char *name)
30c15a2 revert macro removal
Leopold Toetsch authored
1027 {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
1028 macro_frame_t *f;
30c15a2 revert macro removal
Leopold Toetsch authored
1029
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1030 for (f = imcc->frames; f; f = (macro_frame_t *)f->s.next) {
ff12c70 imcc - macros
Leopold Toetsch authored
1031 if (f->params) {
6eba45b @chromatic [IMCC] Minor cleanups and tidyings, mostly coding standards but some …
chromatic authored
1032 int i;
ff12c70 imcc - macros
Leopold Toetsch authored
1033 for (i = 0; i < f->params->num_param; i++) {
2d8dd0f @petdance unreverted the macro_name str_dup patch. See http://rt.perl.org/rt3/…
petdance authored
1034 if (STREQ(f->params->name[i], name))
ff12c70 imcc - macros
Leopold Toetsch authored
1035 return f->expansion.name[i];
1036 }
af71414 @jnthn Debug Segment Update Part 3: Make files included with .include have t…
jnthn authored
1037 }
1038 }
30c15a2 revert macro removal
Leopold Toetsch authored
1039
1040 return NULL;
1041 }
1042
37ff495 @chipdude Keep macros in a hash, thus eliminating N_MACROS forevermore.
chipdude authored
1043 static void
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1044 define_macro(ARGMOD(imc_info_t *imcc), ARGIN(const char *name),
1045 ARGIN(const params_t *params), ARGIN(const char *expansion), int start_line)
77ae9ce @ambs Some spaces/indentation
ambs authored
1046 {
267ebc6 @NotFound [imcc] fix c++ build
NotFound authored
1047 DECL_CONST_CAST;
1048
bc1339f @Whiteknight quick update of imcc.l
Whiteknight authored
1049 macro_t *m = find_macro(imcc, name);
37ff495 @chipdude Keep macros in a hash, thus eliminating N_MACROS forevermore.
chipdude authored
1050
1051 if (m) {
1052 mem_sys_free(m->expansion);
3dbed77 @petdance use mem_sys_free where possible. NULL freed pointers. Remove a str_d…
petdance authored
1053 m->expansion = NULL;