make preprocessing behave a bit more like it should
This commit is contained in:
parent
6e75b24b7c
commit
e009f63506
2 changed files with 22 additions and 10 deletions
|
@ -1,5 +1,7 @@
|
||||||
#define z s z
|
#define z s z
|
||||||
z
|
z
|
||||||
|
#define f(x) f(2 * x)
|
||||||
|
f(f(4))
|
||||||
|
|
||||||
#define STRINGIFY2(x) # x
|
#define STRINGIFY2(x) # x
|
||||||
#define STRINGIFY(x) STRINGIFY2(x)
|
#define STRINGIFY(x) STRINGIFY2(x)
|
||||||
|
|
|
@ -408,9 +408,9 @@ function print_pptokens
|
||||||
p = pptokens
|
p = pptokens
|
||||||
:print_pptokens_loop
|
:print_pptokens_loop
|
||||||
if *1p == 0 goto print_pptokens_loop_end
|
if *1p == 0 goto print_pptokens_loop_end
|
||||||
putc('{)
|
; putc('{)
|
||||||
puts(p)
|
puts(p)
|
||||||
putc('})
|
; putc('})
|
||||||
p += strlen(p)
|
p += strlen(p)
|
||||||
p += 1
|
p += 1
|
||||||
goto print_pptokens_loop
|
goto print_pptokens_loop
|
||||||
|
@ -780,6 +780,7 @@ function macro_replacement
|
||||||
|
|
||||||
p = in
|
p = in
|
||||||
pptoken_skip(&p)
|
pptoken_skip(&p)
|
||||||
|
pptoken_skip_spaces(&p)
|
||||||
if *1p == '( goto fmacro_replacement
|
if *1p == '( goto fmacro_replacement
|
||||||
|
|
||||||
p = banned_objmacros
|
p = banned_objmacros
|
||||||
|
@ -793,13 +794,15 @@ function macro_replacement
|
||||||
goto check_banned_objmacros_loop
|
goto check_banned_objmacros_loop
|
||||||
:check_banned_objmacros_loop_end
|
:check_banned_objmacros_loop_end
|
||||||
|
|
||||||
|
|
||||||
|
replacement = look_up_object_macro(in)
|
||||||
|
if replacement == 0 goto no_replacement
|
||||||
|
|
||||||
; add this to list of banned macros
|
; add this to list of banned macros
|
||||||
p = strcpy(old_banned_objmacros_end, in)
|
p = strcpy(old_banned_objmacros_end, in)
|
||||||
p += 1
|
p += 1
|
||||||
*1p = 255
|
*1p = 255
|
||||||
|
|
||||||
replacement = look_up_object_macro(in)
|
|
||||||
if replacement == 0 goto no_replacement
|
|
||||||
p = replacement
|
p = replacement
|
||||||
pptoken_skip(&in) ; skip macro
|
pptoken_skip(&in) ; skip macro
|
||||||
:objreplace_loop
|
:objreplace_loop
|
||||||
|
@ -818,14 +821,13 @@ function macro_replacement
|
||||||
goto check_banned_fmacros_loop
|
goto check_banned_fmacros_loop
|
||||||
:check_banned_fmacros_loop_end
|
:check_banned_fmacros_loop_end
|
||||||
|
|
||||||
; add this to list of banned macros
|
|
||||||
p = strcpy(old_banned_fmacros_end, in)
|
|
||||||
p += 1
|
|
||||||
*1p = 255
|
|
||||||
|
|
||||||
replacement = look_up_function_macro(in)
|
replacement = look_up_function_macro(in)
|
||||||
if replacement == 0 goto no_replacement
|
if replacement == 0 goto no_replacement
|
||||||
|
local macro_name
|
||||||
|
macro_name = in
|
||||||
|
|
||||||
pptoken_skip(&in) ; skip macro name
|
pptoken_skip(&in) ; skip macro name
|
||||||
|
pptoken_skip_spaces(&in)
|
||||||
pptoken_skip(&in) ; skip opening bracket
|
pptoken_skip(&in) ; skip opening bracket
|
||||||
if *1in == ') goto empty_fmacro_invocation
|
if *1in == ') goto empty_fmacro_invocation
|
||||||
|
|
||||||
|
@ -901,6 +903,14 @@ function macro_replacement
|
||||||
goto freplace_loop
|
goto freplace_loop
|
||||||
:freplace_loop_end
|
:freplace_loop_end
|
||||||
|
|
||||||
|
; add this to list of banned macros
|
||||||
|
; it's important that we do this now and not earlier because this is valid:
|
||||||
|
; #define f(x) x x
|
||||||
|
; const char *s = f(f("a")); /* this preprocesses to s = "a" "a" "a" "a" */
|
||||||
|
p = strcpy(old_banned_fmacros_end, macro_name)
|
||||||
|
p += 1
|
||||||
|
*1p = 255
|
||||||
|
|
||||||
fmacro_out = fmacro_out_start
|
fmacro_out = fmacro_out_start
|
||||||
:frescan_loop
|
:frescan_loop
|
||||||
if *1fmacro_out == 0 goto frescan_loop_end
|
if *1fmacro_out == 0 goto frescan_loop_end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue