diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index b69fec2256c..27eb4e0f8ff 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -890,7 +890,60 @@ public class IndexBugsTests extends BaseTestCase { finally { CProjectHelper.delete(p2); } - - } + + // #define MAC(...) Bug200239 + + // #include "header.h" + // int MAC(1); + // void func() { + // MAC()= MAC(1) + MAC(1,2); + // } + public void testVariadicMacros_Bug200239_1() throws Exception { + StringBuffer[] contents= getContentsForTest(2); + final IIndexManager indexManager = CCorePlugin.getIndexManager(); + IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString()); + waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME); + IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString()); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexBinding[] bindings= fIndex.findBindings("Bug200239".toCharArray(), IndexFilter.ALL, NPM); + assertEquals(1, bindings.length); + IIndexName[] refs= fIndex.findReferences(bindings[0]); + assertEquals(3, refs.length); + } + finally { + fIndex.releaseReadLock(); + } + } + + // #define GMAC(x...) Bug200239 + + // #include "header.h" + // int GMAC(1); + // void func() { + // GMAC()= GMAC(1) + GMAC(1,2); + // } + public void testVariadicMacros_Bug200239_2() throws Exception { + StringBuffer[] contents= getContentsForTest(2); + final IIndexManager indexManager = CCorePlugin.getIndexManager(); + IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString()); + waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME); + IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString()); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexBinding[] bindings= fIndex.findBindings("Bug200239".toCharArray(), IndexFilter.ALL, NPM); + assertEquals(1, bindings.length); + IIndexName[] refs= fIndex.findReferences(bindings[0]); + assertEquals(3, refs.length); + } + finally { + fIndex.releaseReadLock(); + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index 845fd762491..f246e96033d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Anton Leherbauer (Wind River Systems) - * Emanuel Graf (IFS) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Anton Leherbauer (Wind River Systems) + * Emanuel Graf (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner2; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java index e0b4886cf8c..1fd16dc4e01 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -7,9 +7,12 @@ * * Contributors: * IBM Corporation - initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner2; +import java.util.ArrayList; + import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -68,6 +71,33 @@ public class FunctionStyleMacro extends ObjectStyleMacro { } } + public char[][] getOriginalParameters() { + if (varArgsPosition == -1) { + return arglist; + } + ArrayList result= new ArrayList(arglist.length); + for (int i = 0; i < arglist.length; i++) { + final char[] var= arglist[i]; + if (var != null) { + if (i != varArgsPosition) { + result.add(var); + } + else { + if (CharArrayUtils.equals(var, VA_ARGS_CHARARRAY)) { + result.add(ELLIPSIS_CHARARRAY); + } + else { + char[] varell= new char[var.length+ELLIPSIS_CHARARRAY.length]; + System.arraycopy(var, 0, varell, 0, var.length); + System.arraycopy(ELLIPSIS_CHARARRAY, 0, varell, var.length, ELLIPSIS_CHARARRAY.length); + result.add(varell); + } + } + } + } + return (char[][]) result.toArray(new char[result.size()][]); + } + public char[] getSignature(){ if( sig != null ) return sig; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index c1721dcf81f..7842c3a2414 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Anton Leherbauer (Wind River Systems) - * Emanuel Graf (IFS) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Anton Leherbauer (Wind River Systems) + * Emanuel Graf (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner2; @@ -2289,7 +2289,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { int startOffset, int nameOffset, int nameEndOffset, int endOffset) { final _FunctionMacroDefinition functionMacroDefinition = new _FunctionMacroDefinition( currentContext, startOffset, endOffset, m.name, nameOffset, - m.getExpansion(), removeNullArguments(m.arglist)); + m.getExpansion(), m.getOriginalParameters()); currentContext.addSubContext(functionMacroDefinition); return functionMacroDefinition; }