From 6d805e3f526b30144649232246d5ffdc04a31ebf Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 23 Mar 2015 20:46:54 +0100 Subject: Preprocessor.addMacro: Expand active macros w/ non-expanding source right away, when defined. We use the expanded macros within GlueGen, hence we expand them as they are defined. This shall also reduce the load on later per-use expansion. --- src/main/java/org/anarres/cpp/Macro.java | 3 +++ src/main/java/org/anarres/cpp/Preprocessor.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/org/anarres/cpp/Macro.java b/src/main/java/org/anarres/cpp/Macro.java index f8a920a..ce00930 100644 --- a/src/main/java/org/anarres/cpp/Macro.java +++ b/src/main/java/org/anarres/cpp/Macro.java @@ -138,6 +138,9 @@ public class Macro { /* pp */ List getTokens() { return tokens; } + /* pp */ void setTokens(final List tokens) { + this.tokens = tokens; + } /* Paste tokens are inserted before the first of the two pasted * tokens, so it's a kind of bytecode notation. This method diff --git a/src/main/java/org/anarres/cpp/Preprocessor.java b/src/main/java/org/anarres/cpp/Preprocessor.java index 77e63ec..f0e5528 100644 --- a/src/main/java/org/anarres/cpp/Preprocessor.java +++ b/src/main/java/org/anarres/cpp/Preprocessor.java @@ -364,6 +364,10 @@ public class Preprocessor implements Closeable { /* Already handled as a source error in macro(). */ if ("defined".equals(name)) throw new LexerException("Cannot redefine name 'defined'"); + + if ( isActive() && null != source && !source.isExpanding(m) ) { + m.setTokens( expand( m.getTokens() ) ); + } macros.put(m.getName(), m); } -- cgit v1.2.3