2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-22 09:57:15 +01:00

handle empty defines when pasting tokens

This commit is contained in:
Thomas Nagy 2013-11-15 23:24:51 +01:00
parent 797b935305
commit 346601b103
2 changed files with 22 additions and 2 deletions

View File

@ -142,6 +142,21 @@ def build(bld):
'e' : 'e a || b || c || d'
}
def test_pasting():
main = bld.path.find_resource('src/pasting.c')
defs = ['PREFIX_VAL=', 'SUFFIX_VAL=']
bld.env['DEFINES'] = ["%s %s" %(x[0], trimquotes('='.join(x[1:]))) for x in [y.split('=') for y in defs]]
gruik = c_preproc.c_parser([main.parent])
gruik.start(main, bld.env)
if len(gruik.nodes) == 1 and gruik.nodes[0].name == 'a.h':
color = "GREEN"
else:
color = "RED"
pprint(color, "token pasting -> %r (expected a.h)" % gruik.nodes)
test_pasting()
def test(x, result):
toks = c_preproc.tokenize(x)
c_preproc.reduce_tokens(toks, defs, [])
@ -156,6 +171,7 @@ def build(bld):
test('a&&b&&c&&d', 0)
test('e', 1)
return
test("1?1,(0?5:9):3,4", 0) # <- invalid expression

View File

@ -478,7 +478,7 @@ def reduce_tokens(lst, defs, ban=[]):
if one_param: args.append(one_param)
break
elif v2 == ',':
if not one_param: raise PreprocError("empty param in funcall %s" % p)
if not one_param: raise PreprocError("empty param in funcall %s" % v)
args.append(one_param)
one_param = []
else:
@ -645,7 +645,11 @@ def extract_macro(txt):
return (name, [params, t[i+1:]])
else:
(p, v) = t[0]
return (v, [[], t[1:]])
if len(t) > 1:
return (v, [[], t[1:]])
else:
# empty define, assign an empty token
return (v, [[], [('T','')]])
re_include = re.compile('^\s*(<(?P<a>.*)>|"(?P<b>.*)")')
def extract_include(txt, defs):