зеркало из https://github.com/mozilla/gecko-dev.git
Bug 569373 - make Preprocessor.py handle -DVAR=NUMBER such that #if VAR == NUMBER works, r=l10n@mozilla.com
This commit is contained in:
Родитель
081b44aaef
Коммит
8beec9e10f
|
@ -109,7 +109,11 @@ class Expression:
|
|||
rv = None
|
||||
word_len = re.match('[0-9]*', self.content).end()
|
||||
if word_len:
|
||||
rv = Expression.__ASTLeaf('int', int(self.content[:word_len]))
|
||||
if self.content[0] == '0':
|
||||
value = int(self.content[:word_len], 8)
|
||||
else:
|
||||
value = int(self.content[:word_len])
|
||||
rv = Expression.__ASTLeaf('int', value)
|
||||
else:
|
||||
word_len = re.match('\w*', self.content).end()
|
||||
if word_len:
|
||||
|
|
|
@ -170,6 +170,7 @@ class Preprocessor:
|
|||
|
||||
def getCommandLineParser(self, unescapeDefines = False):
|
||||
escapedValue = re.compile('".*"$')
|
||||
numberValue = re.compile('\d+$')
|
||||
def handleE(option, opt, value, parser):
|
||||
for k,v in os.environ.iteritems():
|
||||
self.context[k] = v
|
||||
|
@ -180,6 +181,11 @@ class Preprocessor:
|
|||
elif unescapeDefines and escapedValue.match(vals[1]):
|
||||
# strip escaped string values
|
||||
vals[1] = vals[1][1:-1]
|
||||
elif numberValue.match(vals[1]):
|
||||
if vals[1][0] == '0':
|
||||
vals[1] = int(vals[1], 8)
|
||||
else:
|
||||
vals[1] = int(vals[1])
|
||||
self.context[vals[0]] = vals[1]
|
||||
def handleU(option, opt, value, parser):
|
||||
del self.context[value]
|
||||
|
|
|
@ -404,5 +404,49 @@ FAIL
|
|||
self.pp.do_include(f)
|
||||
self.assertEqual(self.pp.out.getvalue(), "first\rsecond\r")
|
||||
|
||||
def test_number_value_equals(self):
|
||||
f = NamedIO("number_value_equals.in", """#define FOO 1000
|
||||
#if FOO == 1000
|
||||
number value is equal
|
||||
#else
|
||||
number value is not equal
|
||||
#endif
|
||||
""")
|
||||
self.pp.do_include(f)
|
||||
self.assertEqual(self.pp.out.getvalue(), "number value is equal\n")
|
||||
|
||||
def test_number_value_equals_defines(self):
|
||||
f = NamedIO("number_value_equals_defines.in", """#if FOO == 1000
|
||||
number value is equal
|
||||
#else
|
||||
number value is not equal
|
||||
#endif
|
||||
""")
|
||||
self.pp.handleCommandLine(["-DFOO=1000"])
|
||||
self.pp.do_include(f)
|
||||
self.assertEqual(self.pp.out.getvalue(), "number value is equal\n")
|
||||
|
||||
def test_octal_value_equals(self):
|
||||
f = NamedIO("octal_value_equals.in", """#define FOO 0100
|
||||
#if FOO == 0100
|
||||
octal value is equal
|
||||
#else
|
||||
octal value is not equal
|
||||
#endif
|
||||
""")
|
||||
self.pp.do_include(f)
|
||||
self.assertEqual(self.pp.out.getvalue(), "octal value is equal\n")
|
||||
|
||||
def test_octal_value_equals_defines(self):
|
||||
f = NamedIO("octal_value_equals_defines.in", """#if FOO == 0100
|
||||
octal value is equal
|
||||
#else
|
||||
octal value is not equal
|
||||
#endif
|
||||
""")
|
||||
self.pp.handleCommandLine(["-DFOO=0100"])
|
||||
self.pp.do_include(f)
|
||||
self.assertEqual(self.pp.out.getvalue(), "octal value is equal\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче