Replace macro arguments when applying replaceTokens
replaceTokens was only replacing tokens for cpp name clashes in the
macro body. This change will also replace tokens in the arguments.
Bug: 297317502
Test: bionic/libc/kernel/tools/update_all.py
Change-Id: I102d000a8a4cea507b00c867df2a16106d8aed89
Signed-off-by: Edward Liaw <edliaw@google.com>
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py
index 40e1f26..8b2b709 100755
--- a/libc/kernel/tools/cpp.py
+++ b/libc/kernel/tools/cpp.py
@@ -1471,9 +1471,18 @@
made_change = True
i += 1
- if b.isDefine() and b.define_id in replacements:
- b.define_id = replacements[b.define_id]
- made_change = True
+ if b.isDefine():
+ tokens = CppStringTokenizer(b.define_id).tokens
+ id_change = False
+ for tok in tokens:
+ if tok.kind == TokenKind.IDENTIFIER:
+ if tok.id in replacements:
+ tok.id = replacements[tok.id]
+ id_change = True
+ if id_change:
+ b.define_id = ''.join([tok.id for tok in tokens])
+ made_change = True
+
if made_change and b.isIf():
# Keep 'expr' in sync with 'tokens'.