From d32c8052fc2b2d3c5da344eb673df35d4a5bc052 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Wed, 8 Dec 2010 11:38:14 +0100 Subject: [PATCH] Add a method for replacing tokens in the preprocessed headers Change-Id: I14cf6337945560b012732ae0fe7a247074810678 --- libc/kernel/tools/cpp.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py index 4b4bd3826..8828a5d23 100644 --- a/libc/kernel/tools/cpp.py +++ b/libc/kernel/tools/cpp.py @@ -1863,6 +1863,16 @@ 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 + """ + for b in self.blocks: + if not b.isDirective(): + for tok in b.tokens: + if tok.id == tokIDENT: + if tok.value in replacements: + tok.value = replacements[tok.value] + class BlockParser: """a class used to convert an input source file into a BlockList object"""