more macro fixes, #undef
This commit is contained in:
parent
6ce6f76cc1
commit
29ea5195fa
3 changed files with 35 additions and 5 deletions
|
@ -115,6 +115,9 @@
|
||||||
:str_define
|
:str_define
|
||||||
string define
|
string define
|
||||||
byte 0
|
byte 0
|
||||||
|
:str_undef
|
||||||
|
string undef
|
||||||
|
byte 0
|
||||||
:str_include
|
:str_include
|
||||||
string include
|
string include
|
||||||
byte 0
|
byte 0
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#define z sz
|
||||||
|
z
|
||||||
|
|
||||||
#define STRINGIFY2(x) # x
|
#define STRINGIFY2(x) # x
|
||||||
#define STRINGIFY(x) STRINGIFY2(x)
|
#define STRINGIFY(x) STRINGIFY2(x)
|
||||||
#define JOIN2(x,y) x ## y
|
#define JOIN2(x,y) x ## y
|
||||||
|
|
|
@ -464,6 +464,7 @@ function translation_phase_4
|
||||||
local p
|
local p
|
||||||
local c
|
local c
|
||||||
local b
|
local b
|
||||||
|
local macro_name
|
||||||
local line_number
|
local line_number
|
||||||
|
|
||||||
output = malloc(16000000)
|
output = malloc(16000000)
|
||||||
|
@ -503,8 +504,8 @@ function translation_phase_4
|
||||||
if b != 0 goto pp_directive_error
|
if b != 0 goto pp_directive_error
|
||||||
b = str_equals(in, .str_define)
|
b = str_equals(in, .str_define)
|
||||||
if b != 0 goto pp_directive_define
|
if b != 0 goto pp_directive_define
|
||||||
puts(in)
|
b = str_equals(in, .str_undef)
|
||||||
putc(10)
|
if b != 0 goto pp_directive_undef
|
||||||
goto unrecognized_directive
|
goto unrecognized_directive
|
||||||
:pp_directive_error
|
:pp_directive_error
|
||||||
fputs(2, filename)
|
fputs(2, filename)
|
||||||
|
@ -512,8 +513,25 @@ function translation_phase_4
|
||||||
fputn(2, line_number)
|
fputn(2, line_number)
|
||||||
fputs(2, .str_directive_error)
|
fputs(2, .str_directive_error)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
:pp_directive_undef
|
||||||
|
pptoken_skip(&in)
|
||||||
|
pptoken_skip_spaces(&in)
|
||||||
|
macro_name = in
|
||||||
|
pptoken_skip(&in)
|
||||||
|
pptoken_skip_spaces(&in)
|
||||||
|
if *1in != 10 goto bad_undef
|
||||||
|
p = look_up_object_macro(macro_name)
|
||||||
|
if p == 0 goto undef_not_object
|
||||||
|
p -= 2
|
||||||
|
*1p = '@ ; replace last character of macro name with @ to "undefine" it
|
||||||
|
:undef_not_object
|
||||||
|
p = look_up_function_macro(macro_name)
|
||||||
|
if p == 0 goto undef_not_function
|
||||||
|
p -= 2
|
||||||
|
*1p = '@
|
||||||
|
:undef_not_function
|
||||||
|
goto process_pptoken
|
||||||
:pp_directive_define
|
:pp_directive_define
|
||||||
local macro_name
|
|
||||||
pptoken_skip(&in)
|
pptoken_skip(&in)
|
||||||
pptoken_skip_spaces(&in)
|
pptoken_skip_spaces(&in)
|
||||||
macro_name = in
|
macro_name = in
|
||||||
|
@ -604,6 +622,7 @@ function translation_phase_4
|
||||||
function_macros_size = p - function_macros
|
function_macros_size = p - function_macros
|
||||||
free(param_names)
|
free(param_names)
|
||||||
goto phase4_next_line
|
goto phase4_next_line
|
||||||
|
|
||||||
:str_directive_error
|
:str_directive_error
|
||||||
string : #error
|
string : #error
|
||||||
byte 10
|
byte 10
|
||||||
|
@ -630,6 +649,11 @@ function translation_phase_4
|
||||||
:str_bad_macro_params
|
:str_bad_macro_params
|
||||||
string Bad macro parameter list.
|
string Bad macro parameter list.
|
||||||
byte 0
|
byte 0
|
||||||
|
:bad_undef
|
||||||
|
compile_error(filename, line_number, .str_bad_undef)
|
||||||
|
:str_bad_undef
|
||||||
|
string Bad #undef.
|
||||||
|
byte 0
|
||||||
|
|
||||||
; returns a pointer to the replacement pptokens, or 0 if this macro is not defined
|
; returns a pointer to the replacement pptokens, or 0 if this macro is not defined
|
||||||
function look_up_macro
|
function look_up_macro
|
||||||
|
@ -699,11 +723,10 @@ function macro_replacement
|
||||||
|
|
||||||
p = banned_objmacros
|
p = banned_objmacros
|
||||||
|
|
||||||
|
|
||||||
:check_banned_objmacros_loop
|
:check_banned_objmacros_loop
|
||||||
if *1p == 255 goto check_banned_objmacros_loop_end
|
if *1p == 255 goto check_banned_objmacros_loop_end
|
||||||
b = str_equals(in, p)
|
b = str_equals(in, p)
|
||||||
if b != 0 goto done_replacement
|
if b != 0 goto no_replacement
|
||||||
p = memchr(p, 0)
|
p = memchr(p, 0)
|
||||||
p += 1
|
p += 1
|
||||||
goto check_banned_objmacros_loop
|
goto check_banned_objmacros_loop
|
||||||
|
@ -762,6 +785,7 @@ function macro_replacement
|
||||||
in += b ; skip argument
|
in += b ; skip argument
|
||||||
c = *1in
|
c = *1in
|
||||||
in += 2 ; skip , or )
|
in += 2 ; skip , or )
|
||||||
|
pptoken_skip_spaces(&in)
|
||||||
*1p = 255
|
*1p = 255
|
||||||
p += 1
|
p += 1
|
||||||
if c == ', goto fmacro_arg_loop
|
if c == ', goto fmacro_arg_loop
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue