From 518f686e52ade74aafb7c465ee2476c7da701c3e Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 15 Mar 2010 17:04:20 +0000 Subject: [PATCH] Bug 282418: String representation of token-paste. --- .../parser/tests/scanner/PreprocessorBugsTests.java | 12 +++++++++++- .../internal/core/parser/scanner/MacroExpander.java | 11 +++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java index 08d8fed97fc..bf6fca6bf61 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -298,4 +298,14 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase { validateEOF(); validateProblemCount(9); } + + // #define str(x) #x + // #define xstr(x) str(x) + // #define MY_MACROS(Type) unsigned ##Type f(); + // xstr(MY_MACROS(int)) + public void testStringify_Bug282418() throws Exception { + initializeScanner(); + validateString("unsignedint f();"); + validateEOF(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java index 6408d026e2e..7a051d21dc9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -629,6 +629,8 @@ public class MacroExpander { Token pasteArg2= null; TokenList rest= null; if (n != null) { + Token spaceDef0= n; + Token spaceDef1= (Token) n.getNext(); if (n.getType() == CPreprocessor.tMACRO_PARAMETER) { TokenList arg; idx= ((TokenParameterReference) n).getIndex(); @@ -636,12 +638,13 @@ public class MacroExpander { arg= clone(args[idx]); pasteArg2= arg.first(); if (pasteArg2 != null && arg.first() != arg.last()) { + spaceDef0= pasteArg2; rest= arg; rest.removeFirst(); + spaceDef1= rest.first(); } } - } - else { + } else { idx= -1; pasteArg2= n; } @@ -659,7 +662,7 @@ public class MacroExpander { } else { result.append(generated); - addSpacemarker(pasteArg2, rest == null ? n : rest.first(), result); // end token paste + addSpacemarker(spaceDef0, spaceDef1, result); // end token paste } } if (rest != null) {