From 6d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dc Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Fri, 9 Jan 2009 17:50:54 -0800 Subject: auto import from //branches/cupcake/...@125939 --- libc/kernel/tools/cpp.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libc/kernel/tools/cpp.py') 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 ....""" + 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 -- cgit v1.1