aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-23 20:46:54 +0100
committerSven Gothel <[email protected]>2015-03-23 20:46:54 +0100
commit6d805e3f526b30144649232246d5ffdc04a31ebf (patch)
treea632ae9a9c6862734a5b63292a12b5bfd34b13a7
parenta5720fcb97b41c86f86537ffa512b1e802128a9e (diff)
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.
-rw-r--r--src/main/java/org/anarres/cpp/Macro.java3
-rw-r--r--src/main/java/org/anarres/cpp/Preprocessor.java4
2 files changed, 7 insertions, 0 deletions
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<Token> getTokens() {
return tokens;
}
+ /* pp */ void setTokens(final List<Token> 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);
}