From 130f6b820dcb1a835b7bd9333f0cb9702793e262 Mon Sep 17 00:00:00 2001 From: Shevek Date: Wed, 8 Apr 2009 12:24:53 +0000 Subject: fix widening macro case --- src/java/org/anarres/cpp/Macro.java | 5 +++++ src/java/org/anarres/cpp/MacroTokenSource.java | 8 +++++++- src/java/org/anarres/cpp/Preprocessor.java | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/java') diff --git a/src/java/org/anarres/cpp/Macro.java b/src/java/org/anarres/cpp/Macro.java index b62810b..ca024bc 100644 --- a/src/java/org/anarres/cpp/Macro.java +++ b/src/java/org/anarres/cpp/Macro.java @@ -139,12 +139,17 @@ public class Macro { 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; } diff --git a/src/java/org/anarres/cpp/MacroTokenSource.java b/src/java/org/anarres/cpp/MacroTokenSource.java index 264a1a6..53b0932 100644 --- a/src/java/org/anarres/cpp/MacroTokenSource.java +++ b/src/java/org/anarres/cpp/MacroTokenSource.java @@ -89,9 +89,11 @@ import static org.anarres.cpp.Token.*; private Token stringify(Token pos, Argument arg) { StringBuilder buf = new StringBuilder(); concat(buf, arg); + // System.out.println("Concat: " + arg + " -> " + buf); StringBuilder str = new StringBuilder("\""); escape(str, buf); - str.append('\"'); + str.append("\""); + // System.out.println("Escape: " + buf + " -> " + str); return new Token(STRING, pos.getLine(), pos.getColumn(), str.toString(), buf.toString()); @@ -118,6 +120,7 @@ import static org.anarres.cpp.Token.*; break; } Token tok = tokens.next(); + // System.out.println("Paste " + tok); switch (tok.getType()) { case M_PASTE: /* One extra to paste, plus one because the @@ -140,9 +143,12 @@ import static org.anarres.cpp.Token.*; } /* Push and re-lex. */ + /* StringBuilder src = new StringBuilder(); escape(src, buf); StringLexerSource sl = new StringLexerSource(src.toString()); + */ + StringLexerSource sl = new StringLexerSource(buf.toString()); /* XXX Check that concatenation produces a valid token. */ diff --git a/src/java/org/anarres/cpp/Preprocessor.java b/src/java/org/anarres/cpp/Preprocessor.java index 3604abd..282c432 100644 --- a/src/java/org/anarres/cpp/Preprocessor.java +++ b/src/java/org/anarres/cpp/Preprocessor.java @@ -323,6 +323,7 @@ public class Preprocessor implements Closeable { * and the expansion. */ public void addMacro(Macro m) throws LexerException { + // System.out.println("Macro " + m); String name = m.getName(); /* Already handled as a source error in macro(). */ if ("defined".equals(name)) @@ -1582,6 +1583,8 @@ public class Preprocessor implements Closeable { /* From Olivier Chafik for Objective C? */ case '@': + /* The one remaining ASCII, might as well. */ + case '`': // case '#': -- cgit v1.2.3