aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/anarres/cpp/Macro.java
diff options
context:
space:
mode:
authorShevek <[email protected]>2014-09-10 16:10:52 -0700
committerShevek <[email protected]>2014-09-10 19:07:35 -0700
commitbcc3a2b96b0e8b8b03dad0babd7103903cc9df3f (patch)
tree09a2833189524f55e5a6c149cc0e4650a6e5a5f0 /src/main/java/org/anarres/cpp/Macro.java
parentaefac8ce01aee2f538db413d5812613facee9c55 (diff)
NetBeans refactorings to standardize codebase.
Diffstat (limited to 'src/main/java/org/anarres/cpp/Macro.java')
-rw-r--r--src/main/java/org/anarres/cpp/Macro.java308
1 files changed, 153 insertions, 155 deletions
diff --git a/src/main/java/org/anarres/cpp/Macro.java b/src/main/java/org/anarres/cpp/Macro.java
index 534cb2b..7ab38a8 100644
--- a/src/main/java/org/anarres/cpp/Macro.java
+++ b/src/main/java/org/anarres/cpp/Macro.java
@@ -14,7 +14,6 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
-
package org.anarres.cpp;
import java.util.ArrayList;
@@ -29,161 +28,160 @@ import java.util.List;
* extra tokens {@link Token#M_ARG} and {@link Token#M_STRING}.
*/
public class Macro {
- private Source source;
- private 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
- * is the index. The strings themselves are only used in
- * stringification of the macro, for debugging. */
- private List<String> args;
- private boolean variadic;
- private List<Token> tokens;
-
- public Macro(Source source, String name) {
- this.source = source;
- this.name = name;
- this.args = null;
- this.variadic = false;
- this.tokens = new ArrayList<Token>();
- }
-
- public Macro(String name) {
- this(null, name);
- }
-
- /**
- * Sets the Source from which this macro was parsed.
- */
- public void setSource(Source s) {
- this.source = s;
- }
-
- /**
- * Returns the Source from which this macro was parsed.
- *
- * This method may return null if the macro was not parsed
- * from a regular file.
- */
- public Source getSource() {
- return source;
- }
-
- /**
- * Returns the name of this macro.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the arguments to this macro.
- */
- public void setArgs(List<String> args) {
- this.args = args;
- }
-
- /**
- * Returns true if this is a function-like macro.
- */
- public boolean isFunctionLike() {
- return args != null;
- }
-
- /**
- * Returns the number of arguments to this macro.
- */
- public int getArgs() {
- return args.size();
- }
-
- /**
- * Sets the variadic flag on this Macro.
- */
- public void setVariadic(boolean b) {
- this.variadic = b;
- }
-
- /**
- * Returns true if this is a variadic function-like macro.
- */
- public boolean isVariadic() {
- return variadic;
- }
-
- /**
- * Adds a token to the expansion of this macro.
- */
- public void addToken(Token tok) {
- this.tokens.add(tok);
- }
-
- /**
- * Adds a "paste" operator to the expansion of this macro.
- *
- * A paste operator causes the next token added to be pasted
- * to the previous token when the macro is expanded.
- * It is an error for a macro to end with a paste token.
- */
- public void addPaste(Token tok) {
- /*
- * Given: tok0 ## tok1
- * We generate: M_PASTE, tok0, tok1
- * This extends as per a stack language:
- * tok0 ## tok1 ## tok2 ->
- * M_PASTE, tok0, M_PASTE, tok1, tok2
- */
- this.tokens.add(tokens.size() - 1, tok);
- }
-
- /* pp */ List<Token> getTokens() {
- return tokens;
- }
-
- /* Paste tokens are inserted before the first of the two pasted
- * tokens, so it's a kind of bytecode notation. This method
- * swaps them around again. We know that there will never be two
- * sequential paste tokens, so a boolean is sufficient. */
- public String getText() {
- StringBuilder buf = new StringBuilder();
- boolean paste = false;
- for (int i = 0; i < tokens.size(); i++) {
- Token tok = tokens.get(i);
- if (tok.getType() == Token.M_PASTE) {
- assert paste == false : "Two sequential pastes.";
- paste = true;
- continue;
- }
- else {
- buf.append(tok.getText());
- }
- if (paste) {
- buf.append(" #" + "# ");
- paste = false;
- }
- // buf.append(tokens.get(i));
- }
- return buf.toString();
- }
+
+ private Source source;
+ private 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
+ * is the index. The strings themselves are only used in
+ * stringification of the macro, for debugging. */
+ private List<String> args;
+ private boolean variadic;
+ private List<Token> tokens;
+
+ public Macro(Source source, String name) {
+ this.source = source;
+ this.name = name;
+ this.args = null;
+ this.variadic = false;
+ this.tokens = new ArrayList<Token>();
+ }
+
+ public Macro(String name) {
+ this(null, name);
+ }
+
+ /**
+ * Sets the Source from which this macro was parsed.
+ */
+ public void setSource(Source s) {
+ this.source = s;
+ }
+
+ /**
+ * Returns the Source from which this macro was parsed.
+ *
+ * This method may return null if the macro was not parsed
+ * from a regular file.
+ */
+ public Source getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the name of this macro.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the arguments to this macro.
+ */
+ public void setArgs(List<String> args) {
+ this.args = args;
+ }
+
+ /**
+ * Returns true if this is a function-like macro.
+ */
+ public boolean isFunctionLike() {
+ return args != null;
+ }
+
+ /**
+ * Returns the number of arguments to this macro.
+ */
+ public int getArgs() {
+ return args.size();
+ }
+
+ /**
+ * Sets the variadic flag on this Macro.
+ */
+ public void setVariadic(boolean b) {
+ this.variadic = b;
+ }
+
+ /**
+ * Returns true if this is a variadic function-like macro.
+ */
+ public boolean isVariadic() {
+ return variadic;
+ }
+
+ /**
+ * Adds a token to the expansion of this macro.
+ */
+ public void addToken(Token tok) {
+ this.tokens.add(tok);
+ }
+
+ /**
+ * Adds a "paste" operator to the expansion of this macro.
+ *
+ * A paste operator causes the next token added to be pasted
+ * to the previous token when the macro is expanded.
+ * It is an error for a macro to end with a paste token.
+ */
+ public void addPaste(Token tok) {
+ /*
+ * Given: tok0 ## tok1
+ * We generate: M_PASTE, tok0, tok1
+ * This extends as per a stack language:
+ * tok0 ## tok1 ## tok2 ->
+ * M_PASTE, tok0, M_PASTE, tok1, tok2
+ */
+ this.tokens.add(tokens.size() - 1, tok);
+ }
+
+ /* pp */ List<Token> getTokens() {
+ return tokens;
+ }
+
+ /* Paste tokens are inserted before the first of the two pasted
+ * tokens, so it's a kind of bytecode notation. This method
+ * swaps them around again. We know that there will never be two
+ * sequential paste tokens, so a boolean is sufficient. */
+ public String getText() {
+ StringBuilder buf = new StringBuilder();
+ boolean paste = false;
+ for (Token tok : tokens) {
+ if (tok.getType() == Token.M_PASTE) {
+ assert paste == false : "Two sequential pastes.";
+ paste = true;
+ continue;
+ } else {
+ buf.append(tok.getText());
+ }
+ if (paste) {
+ buf.append(" #" + "# ");
+ paste = false;
+ }
+ // buf.append(tokens.get(i));
+ }
+ return buf.toString();
+ }
@Override
- public String toString() {
- StringBuilder buf = new StringBuilder(name);
- if (args != null) {
- buf.append('(');
- Iterator<String> it = args.iterator();
- while (it.hasNext()) {
- buf.append(it.next());
- if (it.hasNext())
- buf.append(", ");
- else if (isVariadic())
- buf.append("...");
- }
- buf.append(')');
- }
- if (!tokens.isEmpty()) {
- buf.append(" => ").append(getText());
- }
- return buf.toString();
- }
+ public String toString() {
+ StringBuilder buf = new StringBuilder(name);
+ if (args != null) {
+ buf.append('(');
+ Iterator<String> it = args.iterator();
+ while (it.hasNext()) {
+ buf.append(it.next());
+ if (it.hasNext())
+ buf.append(", ");
+ else if (isVariadic())
+ buf.append("...");
+ }
+ buf.append(')');
+ }
+ if (!tokens.isEmpty()) {
+ buf.append(" => ").append(getText());
+ }
+ return buf.toString();
+ }
}