summaryrefslogtreecommitdiffstats
path: root/libc/kernel/tools/cpp.py
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:50:54 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:50:54 -0800
commit6d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dc (patch)
tree8de86895228b63728c3a134c8b1fcab003db467d /libc/kernel/tools/cpp.py
parent4e468ed2eb86a2406e14f1eca82072ee501d05fd (diff)
downloadbionic-6d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dc.zip
bionic-6d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dc.tar.gz
bionic-6d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dc.tar.bz2
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'libc/kernel/tools/cpp.py')
-rw-r--r--libc/kernel/tools/cpp.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py
index 54ebaf4..4b4bd38 100644
--- a/libc/kernel/tools/cpp.py
+++ b/libc/kernel/tools/cpp.py
@@ -1571,6 +1571,13 @@ class Block:
"""returns True iff this is a conditional directive block"""
return self.directive in ["if","ifdef","ifndef","else","elif","endif"]
+ def isDefine(self):
+ """returns the macro name in a #define directive, or None otherwise"""
+ if self.directive != "define":
+ return None
+
+ return self.tokens[0].value
+
def isIf(self):
"""returns True iff this is an #if-like directive block"""
return self.directive in ["if","ifdef","ifndef","elif"]
@@ -1678,6 +1685,10 @@ class BlockList:
if b.isIf():
b.expr.optimize(macros)
+ def removeMacroDefines(self,macros):
+ """remove known macro definitions from a BlockList"""
+ self.blocks = remove_macro_defines(self.blocks,macros)
+
def removePrefixed(self,prefix,names):
for b in self.blocks:
if b.isIf():
@@ -1994,6 +2005,16 @@ def test_BlockParser():
#####################################################################################
#####################################################################################
+def remove_macro_defines( blocks, excludedMacros=set() ):
+ """remove macro definitions like #define <macroName> ...."""
+ result = []
+ for b in blocks:
+ macroName = b.isDefine()
+ if macroName == None or not macroName in excludedMacros:
+ result.append(b)
+
+ return result
+
def find_matching_endif( blocks, i ):
n = len(blocks)
depth = 1