diff options
author | Elliott Hughes <enh@google.com> | 2013-11-21 11:12:34 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-11-21 11:12:34 -0800 |
commit | 1198fd38645ff94bf48daae10f8b74903444badc (patch) | |
tree | 7ede00fdf4207fc607c1bf87b7fd3dee3f952379 /libc/kernel/tools | |
parent | d4143c8e4cd8b006d8f422883b53684881e0991a (diff) | |
download | bionic-1198fd38645ff94bf48daae10f8b74903444badc.zip bionic-1198fd38645ff94bf48daae10f8b74903444badc.tar.gz bionic-1198fd38645ff94bf48daae10f8b74903444badc.tar.bz2 |
Add support for the ternary operator to the header scrubber.
Used in various uapi headers.
Change-Id: Id0f862d2adc7ddc9727e8a29160d5435f8d547c3
Diffstat (limited to 'libc/kernel/tools')
-rw-r--r-- | libc/kernel/tools/cpp.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py index 2cc4e94..04e4256 100644 --- a/libc/kernel/tools/cpp.py +++ b/libc/kernel/tools/cpp.py @@ -554,19 +554,21 @@ class CppExpr: where "op" is a string describing the operation""" unaries = [ "!", "~" ] - binaries = [ "+", "-", "<", "<=", ">=", ">", "&&", "||", "*", "/", "%", "&", "|", "^", "<<", ">>", "==", "!=" ] - precedences = { "||": 1, - "&&": 2, - "|": 3, - "^": 4, - "&": 5, - "==":6, "!=":6, - "<":7, "<=":7, ">":7, ">=":7, - "<<":8, ">>":8, - "+":9, "-":9, - "*":10, "/":10, "%":10, - "!":11, "~":12 - } + binaries = [ "+", "-", "<", "<=", ">=", ">", "&&", "||", "*", "/", "%", "&", "|", "^", "<<", ">>", "==", "!=", "?", ":" ] + precedences = { + "?": 1, ":": 1, + "||": 2, + "&&": 3, + "|": 4, + "^": 5, + "&": 6, + "==": 7, "!=": 7, + "<": 8, "<=": 8, ">": 8, ">=": 8, + "<<": 9, ">>": 9, + "+": 10, "-": 10, + "*": 11, "/": 11, "%": 11, + "!": 12, "~": 12 + } re_cpp_constant = re.compile(r"((\d|\w|_)+)") @@ -581,7 +583,7 @@ class CppExpr: if debugCppExpr: print "CppExpr: got " + repr(self.expr) if self.i != self.n: - print 'crap at end of input (%d != %d)' % (self.i, self.n) + print 'crap at end of input (%d != %d): %s' % (self.i, self.n, repr(tokens)) raise @@ -778,6 +780,10 @@ class CppExpr: self.nextToken() primary = self.parseExpression(0) self.expectId(tokRPAREN) + elif op.id == "?": + self.nextToken() + primary = self.parseExpression(0) + self.expectId(":") elif op.id == tokNUMBER: primary = self.is_number() elif op.id == tokIDENT: |