1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 200239, using variadic macros stored in the index.

This commit is contained in:
Markus Schorn 2007-08-22 08:21:04 +00:00
parent 3cb5d2cb12
commit 53cdbc9b41
4 changed files with 95 additions and 12 deletions

View file

@ -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();
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;
}