From b68145fe23170089f797f697163d75eedb3bb319 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 24 Mar 2015 03:26:55 +0100 Subject: Expose explicit macro expansiob and remove previously added implicit macro expansion. - Reverts commit 6d805e3f526b30144649232246d5ffdc04a31ebf and explicitly expose expanded macros to PP getMacros(boolean expand) - PP getMacros(boolean expand) - Returns a deep copy of all macros - May expand them if requested and if they are constants, i.e. non-function like. --- src/main/java/com/jogamp/gluegen/jcpp/Macro.java | 46 +++++++++++++++++------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/jogamp/gluegen/jcpp/Macro.java') diff --git a/src/main/java/com/jogamp/gluegen/jcpp/Macro.java b/src/main/java/com/jogamp/gluegen/jcpp/Macro.java index e41273e..3029252 100644 --- a/src/main/java/com/jogamp/gluegen/jcpp/Macro.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Macro.java @@ -29,7 +29,7 @@ import java.util.List; */ public class Macro { - private Source source; + private final Source source; private final String name; /* It's an explicit decision to keep these around here. We don't * need to; the argument token type is M_ARG and the value @@ -37,6 +37,7 @@ public class Macro { * stringification of the macro, for debugging. */ private List args; private boolean variadic; + private boolean hasPaste; private List tokens; public Macro(final Source source, final String name) { @@ -44,20 +45,36 @@ public class Macro { this.name = name; this.args = null; this.variadic = false; + this.hasPaste = false; this.tokens = new ArrayList(); } + public Macro(final Macro o) { + this(o, o.tokens, true); + } + public Macro(final Macro o, final List tokens) { + this(o, tokens, false); + } + private Macro(final Macro o, final List tokens, final boolean copyTokens) { + this.source = o.source; + this.name = o.name; + if(null != o.args) { + this.args = new ArrayList(o.args); + } else { + this.args = null; + } + this.variadic = o.variadic; + this.hasPaste = o.hasPaste; + if(null != tokens) { + this.tokens = copyTokens ? new ArrayList(tokens) : tokens; + } else { + this.tokens = new ArrayList(); + } + } public Macro(final String name) { this(null, name); } - /** - * Sets the Source from which this macro was parsed. - */ - public void setSource(final Source s) { - this.source = s; - } - /** * Returns the Source from which this macro was parsed. * @@ -78,7 +95,7 @@ public class Macro { /** * Sets the arguments to this macro. */ - public void setArgs(final List args) { + /* pp */ void setArgs(final List args) { this.args = args; } @@ -110,6 +127,13 @@ public class Macro { return variadic; } + /** + * Returns true if this macro contains a "paste" operator. + */ + public boolean hasPaste() { + return hasPaste; + } + /** * Adds a token to the expansion of this macro. */ @@ -133,14 +157,12 @@ public class Macro { * M_PASTE, tok0, M_PASTE, tok1, tok2 */ this.tokens.add(tokens.size() - 1, tok); + this.hasPaste = true; } /* 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 -- cgit v1.2.3