summaryrefslogtreecommitdiffstats
path: root/libc/kernel/tools
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-01 10:17:27 -0700
committerElliott Hughes <enh@google.com>2014-05-01 10:27:49 -0700
commitfddbafdc0a63a1b4c5e9252719a913197a4eecfa (patch)
treef108fcc8076996cac4950f9e217b796bacd047dc /libc/kernel/tools
parent9fb53dd4dbaa7633c234d9da8417827fa3d3c32f (diff)
downloadbionic-fddbafdc0a63a1b4c5e9252719a913197a4eecfa.zip
bionic-fddbafdc0a63a1b4c5e9252719a913197a4eecfa.tar.gz
bionic-fddbafdc0a63a1b4c5e9252719a913197a4eecfa.tar.bz2
Keep the kernel header scrubber's data structures in sync.
If you rewrite the tokens of a #if you need to rewrite the expression to match because either might be used later. This was showing up as SIGRTMAX being rewritten in a #define but not in the #ifndef that guarded it, for which case I've added a unit test. Change-Id: I6929675461a1afe272edd667594529fd84a3dc4d
Diffstat (limited to 'libc/kernel/tools')
-rwxr-xr-xlibc/kernel/tools/clean_header.py2
-rw-r--r--libc/kernel/tools/cpp.py30
2 files changed, 23 insertions, 9 deletions
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index e825ae0..238087b 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -7,7 +7,7 @@ from utils import *
noUpdate = 1
-def cleanupFile( path, original_path):
+def cleanupFile(path, original_path):
"""reads an original header and perform the cleanup operation on it
this functions returns the destination path and the clean header
as a single string"""
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py
index 2c40d7c..2be9532 100644
--- a/libc/kernel/tools/cpp.py
+++ b/libc/kernel/tools/cpp.py
@@ -685,9 +685,9 @@ class CppExpr:
# we have the defined keyword, check the rest
self.i += 1
self.skip_spaces()
- use_parens = 0
+ used_parens = 0
if self.i < self.n and self.tok[self.i].id == tokLPAREN:
- use_parens = 1
+ used_parens = 1
self.i += 1
self.skip_spaces()
@@ -699,7 +699,7 @@ class CppExpr:
self.throw(CppConstantExpected,i,"### 'defined' must be followed by macro name")
self.i += 1
- if use_parens:
+ if used_parens:
self.expectId(tokRPAREN)
return ("defined", t.value)
@@ -1162,7 +1162,7 @@ class Block:
return self.directive in ["if","ifdef","ifndef","elif"]
def isInclude(self):
- """checks wether this is a #include directive. if true, then returns the
+ """checks whether this is a #include directive. if true, then returns the
corresponding file name (with brackets or double-qoutes). None otherwise"""
if self.directive != "include":
return None
@@ -1517,15 +1517,20 @@ class BlockList:
tokens = tokens[:-1] # remove trailing tokLN
self.blocks = [ Block(tokens) ] + self.blocks
- def replaceTokens(self,replacements=dict()):
- """replace tokens according to the given dict
- """
+ def replaceTokens(self,replacements):
+ """replace tokens according to the given dict"""
for b in self.blocks:
- if (not b.isDirective()) or b.isDefine():
+ made_change = False
+ if b.isInclude() == None:
for tok in b.tokens:
if tok.id == tokIDENT:
if tok.value in replacements:
tok.value = replacements[tok.value]
+ made_change = True
+
+ if made_change and b.isIf():
+ # Keep 'expr' in sync with 'tokens'.
+ b.expr = CppExpr(b.tokens)
class BlockParser:
"""a class used to convert an input source file into a BlockList object"""
@@ -1798,6 +1803,10 @@ def test_optimizeAll():
#define X
#endif
+#ifndef SIGRTMAX
+#define SIGRTMAX 123
+#endif /* SIGRTMAX */
+
#if 0
#if 1
#define BAD_6
@@ -1817,12 +1826,17 @@ def test_optimizeAll():
#define X
#endif
+#ifndef __SIGRTMAX
+#define __SIGRTMAX 123
+#endif
+
"""
out = StringOutput()
lines = string.split(text, '\n')
list = BlockParser().parse( CppLinesTokenizer(lines) )
#D_setlevel(2)
+ list.replaceTokens( kernel_token_replacements )
list.optimizeAll( {"__KERNEL__":kCppUndefinedMacro} )
list.write(out)
if out.get() != expected: