1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Store #undef in index, bug 227088.

This commit is contained in:
Markus Schorn 2008-04-17 12:27:49 +00:00
parent 9aed58bb4e
commit 70db16224a
12 changed files with 303 additions and 241 deletions

View file

@ -99,9 +99,15 @@ public class IndexBugsTests extends BaseTestCase {
return fCProject.getProject();
}
protected StringBuffer[] getContentsForTest(int blocks) throws IOException {
return TestSourceReader.getContentsForTest(
protected String[] getContentsForTest(int blocks) throws IOException {
StringBuffer[] help= TestSourceReader.getContentsForTest(
CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), blocks);
String[] result= new String[help.length];
int i=0;
for (StringBuffer buf : help) {
result[i++]= buf.toString();
}
return result;
}
protected IFile createFile(IContainer container, String fileName, String contents) throws Exception {
@ -141,9 +147,9 @@ public class IndexBugsTests extends BaseTestCase {
// because of fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=193779
// this test case passes. However https://bugs.eclipse.org/bugs/show_bug.cgi?id=154563
// remains to be fixed.
StringBuffer[] content= getContentsForTest(3);
String[] content= getContentsForTest(3);
IFile file= createFile(getProject(), "header.h", content[0].toString());
IFile file= createFile(getProject(), "header.h", content[0]);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME);
IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject);
@ -157,7 +163,7 @@ public class IndexBugsTests extends BaseTestCase {
index.releaseReadLock();
}
file.setContents(new ByteArrayInputStream(content[1].toString().getBytes()), true, false, NPM);
file.setContents(new ByteArrayInputStream(content[1].getBytes()), true, false, NPM);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME);
index= CCorePlugin.getIndexManager().getIndex(fCProject);
@ -180,9 +186,9 @@ public class IndexBugsTests extends BaseTestCase {
// class B {};
// B var;
public void test173997_2() throws Exception {
StringBuffer[] content= getContentsForTest(2);
String[] content= getContentsForTest(2);
IFile file= createFile(getProject(), "header.h", content[0].toString());
IFile file= createFile(getProject(), "header.h", content[0]);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME);
IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject);
@ -197,7 +203,7 @@ public class IndexBugsTests extends BaseTestCase {
index.releaseReadLock();
}
file.setContents(new ByteArrayInputStream(content[1].toString().getBytes()), true, false, NPM);
file.setContents(new ByteArrayInputStream(content[1].getBytes()), true, false, NPM);
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME);
index= CCorePlugin.getIndexManager().getIndex(fCProject);
@ -220,7 +226,7 @@ public class IndexBugsTests extends BaseTestCase {
// void function162011(Class162011 x){};
// }
public void testBug162011() throws Exception {
String content = getContentsForTest(1)[0].toString();
String content = getContentsForTest(1)[0];
String fileName = "bug162011.cpp";
String funcName = "function162011";
@ -407,7 +413,7 @@ public class IndexBugsTests extends BaseTestCase {
// #define macro164500 2
public void test164500() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164500.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
@ -417,12 +423,12 @@ public class IndexBugsTests extends BaseTestCase {
IIndexFile ifile= fIndex.getFile(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(file));
assertNotNull(ifile);
IIndexMacro[] macros= ifile.getMacros();
assertEquals(2, macros.length);
assertEquals(3, macros.length);
IIndexMacro m= macros[0];
assertEquals("1", new String(m.getExpansionImage()));
assertEquals("macro164500", new String(m.getName()));
m= macros[1];
m= macros[2];
assertEquals("2", new String(m.getExpansionImage()));
assertEquals("macro164500", new String(m.getName()));
}
@ -441,7 +447,7 @@ public class IndexBugsTests extends BaseTestCase {
String pname = "deleteTest"+System.currentTimeMillis();
ICProject cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER);
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME);
CProjectHelper.delete(cproject);
@ -468,7 +474,7 @@ public class IndexBugsTests extends BaseTestCase {
ICProject cproject = CProjectHelper.createCCProject("moveTest", "bin", IPDOMManager.ID_FAST_INDEXER);
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME);
@ -504,9 +510,9 @@ public class IndexBugsTests extends BaseTestCase {
ICProject cproject = CProjectHelper.createCCProject("seq1", "bin", IPDOMManager.ID_FAST_INDEXER);
try {
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
StringBuffer[] testData = getContentsForTest(3);
IFile header= TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0].toString());
IFile referer= TestSourceReader.createFile(cproject.getProject(), "content.cpp", testData[1].toString());
String[] testData = getContentsForTest(3);
IFile header= TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0]);
IFile referer= TestSourceReader.createFile(cproject.getProject(), "content.cpp", testData[1]);
TestSourceReader.waitUntilFileIsIndexed(index, referer, INDEX_WAIT_TIME);
index.acquireReadLock();
@ -520,7 +526,7 @@ public class IndexBugsTests extends BaseTestCase {
index.releaseReadLock();
}
InputStream in = new ByteArrayInputStream(testData[2].toString().getBytes());
InputStream in = new ByteArrayInputStream(testData[2].getBytes());
header.setContents(in, IResource.FORCE, null);
TestSourceReader.waitUntilFileIsIndexed(index, header, INDEX_WAIT_TIME);
@ -544,7 +550,7 @@ public class IndexBugsTests extends BaseTestCase {
// } S20070201;
public void test172454_1() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.c", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
@ -579,7 +585,7 @@ public class IndexBugsTests extends BaseTestCase {
// } S20070201;
public void test172454_2() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
@ -615,7 +621,7 @@ public class IndexBugsTests extends BaseTestCase {
// enum {e20070206};
public void test156671() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test156671.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
@ -634,7 +640,7 @@ public class IndexBugsTests extends BaseTestCase {
// typedef int T20070213;
public void test173997() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
@ -691,7 +697,7 @@ public class IndexBugsTests extends BaseTestCase {
// };
public void testFindBindingsWithPrefix() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFBWP.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
@ -725,7 +731,7 @@ public class IndexBugsTests extends BaseTestCase {
// class a { class b { class c { void f(); }; }; };
public void testFilterFindBindingsFQCharArray() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
String content= getContentsForTest(1)[0];
IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFilterFindBindingsFQCharArray.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
@ -758,13 +764,13 @@ public class IndexBugsTests extends BaseTestCase {
// #include "../__bugsTest__/common.h"
// StructA_T gvar2;
public void testFileInMultipleFragments_bug192352() throws Exception {
StringBuffer[] contents= getContentsForTest(3);
String[] contents= getContentsForTest(3);
ICProject p2 = CProjectHelper.createCCProject("__bugsTest_2_", "bin", IPDOMManager.ID_FAST_INDEXER);
try {
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0].toString());
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[2].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0]);
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]);
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[2]);
waitForIndexer();
IIndex index= CCorePlugin.getIndexManager().getIndex(new ICProject[]{fCProject, p2});
@ -808,14 +814,14 @@ public class IndexBugsTests extends BaseTestCase {
// #endif
public void testIncludeGuardsOutsideOfHeader_Bug167100() throws Exception {
final IIndexManager indexManager = CCorePlugin.getIndexManager();
StringBuffer[] contents= getContentsForTest(5);
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header1.h", contents[0].toString());
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "header2.h", contents[1].toString());
IFile f3= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[2].toString());
String[] contents= getContentsForTest(5);
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header1.h", contents[0]);
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "header2.h", contents[1]);
IFile f3= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[2]);
indexManager.reindex(fCProject);
waitForIndexer();
IFile f4= TestSourceReader.createFile(fCProject.getProject(), "src2.cpp", contents[3].toString());
IFile f5= TestSourceReader.createFile(fCProject.getProject(), "src3.cpp", contents[4].toString());
IFile f4= TestSourceReader.createFile(fCProject.getProject(), "src2.cpp", contents[3]);
IFile f5= TestSourceReader.createFile(fCProject.getProject(), "src3.cpp", contents[4]);
waitForIndexer();
IIndex index= indexManager.getIndex(fCProject);
@ -849,7 +855,7 @@ public class IndexBugsTests extends BaseTestCase {
// globalVar++;
// }
public void testDependentProjectsWithFullIndexer_Bug197311() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
indexManager.setIndexerId(fCProject, IPDOMManager.ID_FULL_INDEXER);
ICProject p2 = CProjectHelper.createCCProject("bug197311", "bin", IPDOMManager.ID_FULL_INDEXER);
@ -858,9 +864,9 @@ public class IndexBugsTests extends BaseTestCase {
pd.setReferencedProjects(refs);
p2.getProject().setDescription(pd, new NullProgressMonitor());
try {
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0].toString());
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[1].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0]);
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]);
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[1]);
waitForIndexer();
IIndex index= indexManager.getIndex(p2, IIndexManager.ADD_DEPENDENCIES);
@ -909,11 +915,11 @@ public class IndexBugsTests extends BaseTestCase {
// MAC()= MAC(1) + MAC(1,2);
// }
public void testVariadicMacros_Bug200239_1() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME);
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]);
waitForIndexer();
fIndex.acquireReadLock();
@ -936,11 +942,11 @@ public class IndexBugsTests extends BaseTestCase {
// GMAC()= GMAC(1) + GMAC(1,2);
// }
public void testVariadicMacros_Bug200239_2() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME);
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]);
waitForIndexer();
fIndex.acquireReadLock();
@ -959,9 +965,9 @@ public class IndexBugsTests extends BaseTestCase {
// typedef bug200553_A bug200553_B;
// typedef bug200553_B bug200553_A;
public void testTypedefRecursionCpp_Bug200553() throws Exception {
StringBuffer[] contents= getContentsForTest(1);
String[] contents= getContentsForTest(1);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[0].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[0]);
waitForIndexer();
fIndex.acquireReadLock();
try {
@ -1010,9 +1016,9 @@ public class IndexBugsTests extends BaseTestCase {
// typedef bug200553_A bug200553_B;
// typedef bug200553_B bug200553_A;
public void testTypedefRecursionC_Bug200553() throws Exception {
StringBuffer[] contents= getContentsForTest(1);
String[] contents= getContentsForTest(1);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "src.c", contents[0].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "src.c", contents[0]);
waitForIndexer();
fIndex.acquireReadLock();
try {
@ -1053,9 +1059,9 @@ public class IndexBugsTests extends BaseTestCase {
// #include "source.cpp"
// #endif
public void testIncludeSource_Bug199412() throws Exception {
StringBuffer[] contents= getContentsForTest(1);
String[] contents= getContentsForTest(1);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[0].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[0]);
waitForIndexer();
final ITranslationUnit tu= (ITranslationUnit) fCProject.findElement(new Path("source.cpp"));
@ -1087,9 +1093,9 @@ public class IndexBugsTests extends BaseTestCase {
// void func_209049(long long x);
public void testGPPTypes_Bug209049() throws Exception {
StringBuffer[] contents= getContentsForTest(1);
String[] contents= getContentsForTest(1);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[0].toString());
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[0]);
waitForIndexer();
fIndex.acquireReadLock();
try {
@ -1109,11 +1115,11 @@ public class IndexBugsTests extends BaseTestCase {
// staticInHeader();
// }
public void testStaticFunctionsInHeader_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "source1.cpp", contents[1]);
TestSourceReader.createFile(fCProject.getProject(), "source2.cpp", contents[1]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
@ -1136,11 +1142,11 @@ public class IndexBugsTests extends BaseTestCase {
// int a= staticConstInHeader;
// }
public void testStaticVariableInHeader_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "source1.cpp", contents[1]);
TestSourceReader.createFile(fCProject.getProject(), "source2.cpp", contents[1]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
@ -1163,11 +1169,11 @@ public class IndexBugsTests extends BaseTestCase {
// staticInHeader();
// }
public void testStaticFunctionsInHeaderC_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.c", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.c", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "source1.c", contents[1]);
TestSourceReader.createFile(fCProject.getProject(), "source2.c", contents[1]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
@ -1190,11 +1196,11 @@ public class IndexBugsTests extends BaseTestCase {
// int a= staticConstInHeader;
// }
public void testStaticVariableInHeaderC_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.c", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.c", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "source1.c", contents[1]);
TestSourceReader.createFile(fCProject.getProject(), "source2.c", contents[1]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
@ -1214,10 +1220,10 @@ public class IndexBugsTests extends BaseTestCase {
// #include "header.x"
public void testNonStandardSuffix_Bug205778() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.x", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "header.x", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[1]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
@ -1237,10 +1243,10 @@ public class IndexBugsTests extends BaseTestCase {
// };
// #include "MyClass_inline.h"
public void testAddingMemberBeforeContainer_Bug203170() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "MyClass_inline.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "MyClass_inline.h", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[1]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
@ -1268,11 +1274,11 @@ public class IndexBugsTests extends BaseTestCase {
// a.b;
// }
public void testUnrelatedTypedef_Bug214146() throws Exception {
StringBuffer[] contents= getContentsForTest(3);
String[] contents= getContentsForTest(3);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "s1.cpp", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "h1.h", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "s2.h", contents[2].toString());
TestSourceReader.createFile(fCProject.getProject(), "s1.cpp", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "h1.h", contents[1]);
TestSourceReader.createFile(fCProject.getProject(), "s2.h", contents[2]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
@ -1286,4 +1292,35 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.releaseReadLock();
}
}
// #undef XXX
// #define XXX
// #include "header.h"
// #ifdef XXX
// int bug227088;
// #else
// int ok;
// #endif
public void testUndefInHeader_Bug227088() throws Exception {
String[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]);
TestSourceReader.createFile(fCProject.getProject(), "s1.cpp", contents[1]);
TestSourceReader.createFile(fCProject.getProject(), "s2.cpp", contents[1]);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();
try {
IIndexBinding[] bindings = fIndex.findBindings("bug227088".toCharArray(), IndexFilter.ALL, NPM);
assertEquals(0, bindings.length);
bindings = fIndex.findBindings("ok".toCharArray(), IndexFilter.ALL, NPM);
assertEquals(1, bindings.length);
IIndexName[] decls = fIndex.findNames(bindings[0], IIndex.FIND_ALL_OCCURENCES);
assertEquals(2, decls.length);
} finally {
fIndex.releaseReadLock();
}
}
}

View file

@ -36,7 +36,8 @@ public interface IMacroBinding extends IBinding {
char[][] getParameterList();
/**
* Returns the expansion of this macro definition. For dynamic macros an exemplary image is returned.
* Returns the expansion of this macro definition, or <code>null</code> if the definition is not
* available. For dynamic macros an exemplary image is returned.
* @since 5.0
*/
char[] getExpansion();
@ -51,7 +52,8 @@ public interface IMacroBinding extends IBinding {
char[][] getParameterPlaceholderList();
/**
* Returns the image of the expansion (also containing comments). For dynamic macros an exemplary image is returned.
* Returns the image of the expansion (also containing comments), or <code>null</code> if the definition
* is not available. For dynamic macros an exemplary image is returned.
* @since 5.0
*/
char[] getExpansionImage();

View file

@ -16,7 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.core.runtime.CoreException;
/**
* Represents a macro stored in the index.
* Represents a macro stored in the index.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
@ -37,7 +37,7 @@ public interface IIndexMacro extends IMacroBinding, IIndexBinding {
* If available, return the file location for the macro definition of this macro,
* otherwise return <code>null</code>.
*/
IASTFileLocation getFileLocation();
IASTFileLocation getFileLocation() throws CoreException;
/**
* Returns the file in which this macro is defined and belongs to.
@ -47,7 +47,8 @@ public interface IIndexMacro extends IMacroBinding, IIndexBinding {
/**
* Returns the name of the definition of this macro, or <code>null</code> if not available.
* @throws CoreException
* @since 5.0
*/
IIndexName getDefinition();
IIndexName getDefinition() throws CoreException;
}

View file

@ -16,7 +16,7 @@ import java.util.Collection;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
@ -72,7 +72,7 @@ public interface IWritableIndex extends IIndex {
*/
void setFileContent(IIndexFragmentFile sourceFile,
int linkageID, IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names,
IASTPreprocessorStatement[] macros, IASTName[][] names,
ASTFilePathResolver resolver) throws CoreException;
/**

View file

@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.index;
import java.util.Collection;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
@ -52,7 +52,7 @@ public interface IWritableIndexFragment extends IIndexFragment {
*/
void addFileContent(IIndexFragmentFile sourceFile,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException;
IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException;
/**
* Acquires a write lock, while giving up a certain amount of read locks.
@ -69,7 +69,7 @@ public interface IWritableIndexFragment extends IIndexFragment {
/**
* Write the key, value mapping to the fragment properties. If a mapping for the
* same key already exists, it is overwritten.
* @param key a non-null property name
* @param propertyName a non-null property name
* @param value a value to associate with the key. may not be null.
* @throws CoreException
* @throws NullPointerException if key is null

View file

@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.index;
import java.util.Collection;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
@ -60,15 +60,14 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
public void setFileContent(IIndexFragmentFile file, int linkageID,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException {
IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException {
IIndexFragment indexFragment = file.getIndexFragment();
if (!isWritableFragment(indexFragment)) {
assert false : "Attempt to update file of read-only fragment"; //$NON-NLS-1$
}
else {
for (int i = 0; i < includes.length; i++) {
IncludeInformation ii= includes[i];
for (IncludeInformation ii : includes) {
if (ii.fLocation != null) {
ii.fTargetFile= addFile(linkageID, ii.fLocation);
}

View file

@ -782,10 +782,17 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private void addMacroDefinition(IIndexMacro macro) {
try {
PreprocessorMacro result= MacroDefinitionParser.parseMacroDefinition(macro.getNameCharArray(), macro.getParameterList(), macro.getExpansionImage());
final IASTFileLocation loc= macro.getFileLocation();
fLocationMap.registerMacroFromIndex(result, loc, -1);
fMacroDictionary.put(result.getNameCharArray(), result);
final char[] expansionImage = macro.getExpansionImage();
if (expansionImage == null) {
// this is an undef
fMacroDictionary.remove(macro.getNameCharArray());
}
else {
PreprocessorMacro result= MacroDefinitionParser.parseMacroDefinition(macro.getNameCharArray(), macro.getParameterList(), expansionImage);
final IASTFileLocation loc= macro.getFileLocation();
fLocationMap.registerMacroFromIndex(result, loc, -1);
fMacroDictionary.put(result.getNameCharArray(), result);
}
}
catch (Exception e) {
fLog.traceLog("Invalid macro definition: '" + macro.getName() + "'"); //$NON-NLS-1$//$NON-NLS-2$

View file

@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
@ -46,6 +47,7 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@ -244,11 +246,10 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final boolean checkConfig= (fUpdateFlags & IIndexManager.UPDATE_CHECK_CONFIGURATION) != 0;
int count= 0;
for (int i = 0; i < fFilesToUpdate.length; i++) {
for (final Object tu : fFilesToUpdate) {
if (monitor.isCanceled())
return;
final Object tu= fFilesToUpdate[i];
final IIndexFileLocation ifl= fResolver.resolveFile(tu);
if (ifl == null)
continue;
@ -260,8 +261,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if ((isSourceUnit && !isExcludedSource) || fIndexHeadersWithoutContext) {
// headers or sources required with a specific linkage
AbstractLanguage[] langs= fResolver.getLanguages(tu);
for (int j = 0; j < langs.length; j++) {
int linkageID = langs[j].getLinkageID();
for (AbstractLanguage lang : langs) {
int linkageID = lang.getLinkageID();
IIndexFragmentFile ifile= getFile(linkageID, indexFiles);
if (ifile == null || !ifile.hasContent()) {
store(tu, linkageID, isSourceUnit, files);
@ -285,8 +286,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
// handle other files present in index
for (int j = 0; j < indexFiles.length; j++) {
IIndexFragmentFile ifile = indexFiles[j];
for (IIndexFragmentFile ifile : indexFiles) {
if (ifile != null && ifile.hasContent()) {
IIndexInclude ctx= ifile.getParsedInContext();
if (ctx == null) {
@ -354,8 +354,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
private IIndexFragmentFile getFile(int linkageID, IIndexFragmentFile[] indexFiles) throws CoreException {
for (int i = 0; i < indexFiles.length; i++) {
IIndexFragmentFile ifile = indexFiles[i];
for (IIndexFragmentFile ifile : indexFiles) {
if (ifile != null && ifile.getLinkageID() == linkageID) {
return ifile;
}
@ -391,26 +390,23 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (!filesToRemove.isEmpty() || !ifilesToRemove.isEmpty()) {
fIndex.acquireWriteLock(1);
try {
for (Iterator<Object> iterator = fFilesToRemove.iterator(); iterator.hasNext();) {
for (Object tu : fFilesToRemove) {
if (monitor.isCanceled()) {
return;
}
final Object tu = iterator.next();
IIndexFileLocation ifl= fResolver.resolveFile(tu);
if (ifl == null)
continue;
IIndexFragmentFile[] ifiles= fIndex.getWritableFiles(ifl);
for (int i = 0; i < ifiles.length; i++) {
IIndexFragmentFile ifile = ifiles[i];
for (IIndexFragmentFile ifile : ifiles) {
fIndex.clearFile(ifile, null);
}
updateRequestedFiles(-1);
}
for (Iterator<IIndexFragmentFile> iterator = ifilesToRemove.iterator(); iterator.hasNext();) {
for (IIndexFragmentFile ifile : ifilesToRemove) {
if (monitor.isCanceled()) {
return;
}
IIndexFragmentFile ifile= iterator.next();
fIndex.clearFile(ifile, null);
updateRequestedFiles(-1);
}
@ -422,11 +418,10 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
private void parseFilesUpFront(IProgressMonitor monitor) throws CoreException {
for (Iterator<String> iter = fFilesUpFront.iterator(); iter.hasNext();) {
for (String upfront : fFilesUpFront) {
if (monitor.isCanceled()) {
return;
}
String upfront= iter.next();
String filePath = upfront;
filePath= filePath.trim();
if (filePath.length() == 0) {
@ -442,8 +437,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
new Object[]{fileName, path.removeLastSegments(1).toString()}));
AbstractLanguage[] langs= getLanguages(fileName);
for (int i = 0; i < langs.length; i++) {
AbstractLanguage lang= langs[i];
for (AbstractLanguage lang : langs) {
int linkageID= lang.getLinkageID();
String code= "#include \"" + filePath + "\"\n"; //$NON-NLS-1$ //$NON-NLS-2$
@ -471,10 +465,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
// sources
List<Object> files= fileListMap.get(getFileListKey(linkageID, true));
if (files != null) {
for (Iterator<Object> iter = files.iterator(); iter.hasNext();) {
for (Object tu : files) {
if (monitor.isCanceled())
return;
final Object tu= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(tu);
if (ifl == null)
continue;
@ -575,9 +568,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
IPath path= getPathForLabel(ifl);
AbstractLanguage[] langs= fResolver.getLanguages(tu);
AbstractLanguage lang= null;
for (int i = 0; i < langs.length; i++) {
if (langs[i].getLinkageID() == linkageID) {
lang= langs[i];
for (AbstractLanguage lang2 : langs) {
if (lang2.getLinkageID() == linkageID) {
lang= lang2;
break;
}
}
@ -617,8 +610,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
enteredFiles.add(topIfl);
IDependencyTree tree= ast.getDependencyTree();
IASTInclusionNode[] inclusions= tree.getInclusions();
for (int i=0; i < inclusions.length; i++) {
collectOrderedIFLs(linkageID, inclusions[i], enteredFiles, orderedIFLs);
for (IASTInclusionNode inclusion : inclusions) {
collectOrderedIFLs(linkageID, inclusion, enteredFiles, orderedIFLs);
}
FileContent info= getFileInfo(linkageID, topIfl);
@ -634,10 +627,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
// mark as updated in any case, to avoid parsing files that caused an exception to be thrown.
for (IIndexFileLocation ifl : ifls) {
info= getFileInfo(linkageID, ifl);
assert info != null;
if (info != null) {
info.fIsUpdated= true;
}
Assert.isNotNull(info);
info.fIsUpdated= true;
}
}
}
@ -648,8 +639,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final IIndexFileLocation ifl= fResolver.resolveASTPath(id.getPath());
final boolean isFirstEntry= enteredFiles.add(ifl);
IASTInclusionNode[] nested= inclusion.getNestedInclusions();
for (int i = 0; i < nested.length; i++) {
collectOrderedIFLs(linkageID, nested[i], enteredFiles, orderedIFLs);
for (IASTInclusionNode element : nested) {
collectOrderedIFLs(linkageID, element, enteredFiles, orderedIFLs);
}
if (isFirstEntry && needToUpdateHeader(linkageID, ifl)) {
orderedIFLs.add(ifl);
@ -719,8 +710,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
int result= 0;
Map<String, String> macros= scannerInfo.getDefinedSymbols();
if (macros != null) {
for (Iterator<Map.Entry<String,String>> i = macros.entrySet().iterator(); i.hasNext();) {
Map.Entry<String,String> entry = i.next();
for (Entry<String, String> entry : macros.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
result= addToHashcode(result, key);
@ -731,8 +721,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
String[] a= scannerInfo.getIncludePaths();
if (a != null) {
for (int i = 0; i < a.length; i++) {
result= addToHashcode(result, a[i]);
for (String element : a) {
result= addToHashcode(result, element);
}
}
@ -740,22 +730,22 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
IExtendedScannerInfo esi= (IExtendedScannerInfo) scannerInfo;
a= esi.getIncludeFiles();
if (a != null) {
for (int i = 0; i < a.length; i++) {
result= addToHashcode(result, a[i]);
for (String element : a) {
result= addToHashcode(result, element);
}
}
a= esi.getLocalIncludePath();
if (a != null) {
for (int i = 0; i < a.length; i++) {
result= addToHashcode(result, a[i]);
for (String element : a) {
result= addToHashcode(result, element);
}
}
a= esi.getMacroFiles();
if (a != null) {
for (int i = 0; i < a.length; i++) {
result= addToHashcode(result, a[i]);
for (String element : a) {
result= addToHashcode(result, element);
}
}
@ -770,22 +760,20 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
public final FileContent getFileContent(int linkageID, IIndexFileLocation ifl) throws CoreException {
if (!needToUpdateHeader(linkageID, ifl)) {
FileContent info= getFileInfo(linkageID, ifl);
assert info != null;
if (info != null) {
Assert.isNotNull(info);
if (info.fIndexFile == null) {
info.fIndexFile= fIndex.getFile(linkageID, ifl);
if (info.fIndexFile == null) {
info.fIndexFile= fIndex.getFile(linkageID, ifl);
if (info.fIndexFile == null) {
return null;
}
return null;
}
if (info.fMacros == null) {
info.fMacros= info.fIndexFile.getMacros();
}
if (info.fDirectives == null) {
info.fDirectives= info.fIndexFile.getUsingDirectives();
}
return info;
}
if (info.fMacros == null) {
info.fMacros= info.fIndexFile.getMacros();
}
if (info.fDirectives == null) {
info.fDirectives= info.fIndexFile.getUsingDirectives();
}
return info;
}
return null;
}

View file

@ -27,6 +27,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -39,7 +41,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
@ -69,7 +70,7 @@ abstract public class PDOMWriter {
private static class Symbols {
ArrayList<IASTName[]> fNames= new ArrayList<IASTName[]>();
ArrayList<IASTPreprocessorMacroDefinition> fMacros= new ArrayList<IASTPreprocessorMacroDefinition>();
ArrayList<IASTPreprocessorStatement> fMacros= new ArrayList<IASTPreprocessorStatement>();
ArrayList<IASTPreprocessorIncludeStatement> fIncludes= new ArrayList<IASTPreprocessorIncludeStatement>();
}
private boolean fShowProblems;
@ -122,12 +123,7 @@ abstract public class PDOMWriter {
}
/**
* Extracts symbols from the given ast and adds them to the index. It will
* make calls to
* {@link #needToUpdate(IIndexFileLocation)},
* {@link #postAddToIndex(IIndexFileLocation, IIndexFile)},
* {@link #getLastModified(IIndexFileLocation)} and
* {@link #findLocation(String)} to obtain further information.
* Extracts symbols from the given ast and adds them to the index.
*
* When flushIndex is set to <code>false</code>, you must make sure to flush the
* index after your last write operation.
@ -142,8 +138,8 @@ abstract public class PDOMWriter {
fShowSyntaxProblems= true;
}
final Map<IIndexFileLocation, Symbols> symbolMap= new HashMap<IIndexFileLocation, Symbols>();
for (int i = 0; i < ifls.length; i++) {
prepareInMap(symbolMap, ifls[i]);
for (IIndexFileLocation ifl : ifls) {
prepareInMap(symbolMap, ifl);
}
ArrayList<IStatus> stati= new ArrayList<IStatus>();
@ -161,7 +157,7 @@ abstract public class PDOMWriter {
}
if (!stati.isEmpty()) {
String path= null;
if (ifls != null && ifls.length > 0) {
if (ifls.length > 0) {
path= ifls[ifls.length-1].getURI().getPath();
}
else {
@ -218,11 +214,10 @@ abstract public class PDOMWriter {
private void resolveNames(final Map<IIndexFileLocation, Symbols> symbolMap, IIndexFileLocation[] ifls, ArrayList<IStatus> stati, IProgressMonitor pm) {
long start= System.currentTimeMillis();
for (int i=0; i<ifls.length; i++) {
for (IIndexFileLocation path : ifls) {
if (pm.isCanceled()) {
return;
}
IIndexFileLocation path= ifls[i];
Symbols symbols= symbolMap.get(path);
final ArrayList<IASTName[]> names= symbols.fNames;
@ -277,39 +272,39 @@ abstract public class PDOMWriter {
final HashSet<IIndexFileLocation> contextIFLs= new HashSet<IIndexFileLocation>();
final IIndexFileLocation astIFL = fResolver.resolveASTPath(ast.getFilePath());
// includes
int unresolvedIncludes= 0;
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
for (int i= 0; i < includes.length; i++) {
final IASTPreprocessorIncludeStatement include = includes[i];
final IASTFileLocation astLoc= include.getFileLocation();
final IIndexFileLocation sourceIFL= astLoc != null ? fResolver.resolveASTPath(astLoc.getFileName()) : astIFL; // command-line includes
final boolean updateSource= symbolMap.containsKey(sourceIFL);
if (updateSource) {
addToMap(symbolMap, sourceIFL, include);
}
if (include.isActive()) {
if (!include.isResolved()) {
unresolvedIncludes++;
IASTPreprocessorStatement[] stmts = ast.getAllPreprocessorStatements();
for (final IASTPreprocessorStatement stmt : stmts) {
// includes
if (stmt instanceof IASTPreprocessorIncludeStatement) {
IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) stmt;
final IASTFileLocation astLoc= include.getFileLocation();
final IIndexFileLocation sourceIFL= astLoc != null ? fResolver.resolveASTPath(astLoc.getFileName()) : astIFL; // command-line includes
final boolean updateSource= symbolMap.containsKey(sourceIFL);
if (updateSource) {
addToMap(symbolMap, sourceIFL, include);
}
else if (updateSource) {
// the include was parsed, check if we want to update the included file in the index
final IIndexFileLocation targetIFL= fResolver.resolveASTPath(include.getPath());
if (symbolMap.containsKey(targetIFL) && contextIFLs.add(targetIFL)) {
contextIncludes.add(include);
if (include.isActive()) {
if (!include.isResolved()) {
unresolvedIncludes++;
}
else if (updateSource) {
// the include was parsed, check if we want to update the included file in the index
final IIndexFileLocation targetIFL= fResolver.resolveASTPath(include.getPath());
if (symbolMap.containsKey(targetIFL) && contextIFLs.add(targetIFL)) {
contextIncludes.add(include);
}
}
}
}
}
// macros
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
for (int i2 = 0; i2 < macros.length; ++i2) {
IASTPreprocessorMacroDefinition macro = macros[i2];
IASTFileLocation sourceLoc = macro.getFileLocation();
if (sourceLoc != null) { // skip built-ins and command line macros
IIndexFileLocation path2 = fResolver.resolveASTPath(sourceLoc.getFileName());
addToMap(symbolMap, path2, macro);
// macros
else if (stmt instanceof IASTPreprocessorMacroDefinition || stmt instanceof IASTPreprocessorUndefStatement) {
IASTFileLocation sourceLoc = stmt.getFileLocation();
if (sourceLoc != null) { // skip built-ins and command line macros
IIndexFileLocation path2 = fResolver.resolveASTPath(sourceLoc.getFileName());
addToMap(symbolMap, path2, stmt);
}
}
}
@ -412,7 +407,7 @@ abstract public class PDOMWriter {
lists.fIncludes.add(thing);
}
private void addToMap(Map<IIndexFileLocation, Symbols> map, IIndexFileLocation location, IASTPreprocessorMacroDefinition thing) {
private void addToMap(Map<IIndexFileLocation, Symbols> map, IIndexFileLocation location, IASTPreprocessorStatement thing) {
Symbols lists= map.get(location);
if (lists != null)
lists.fMacros.add(thing);
@ -439,10 +434,10 @@ abstract public class PDOMWriter {
file.setScannerConfigurationHashcode(configHash);
Symbols lists= symbolMap.get(location);
if (lists != null) {
IASTPreprocessorMacroDefinition[] macros= lists.fMacros.toArray(new IASTPreprocessorMacroDefinition[lists.fMacros.size()]);
IASTPreprocessorStatement[] macros= lists.fMacros.toArray(new IASTPreprocessorStatement[lists.fMacros.size()]);
IASTName[][] names= lists.fNames.toArray(new IASTName[lists.fNames.size()][]);
for (int j= 0; j<names.length; j++) {
final IASTName name= names[j][0];
for (IASTName[] name2 : names) {
final IASTName name= name2[0];
if (name != null) {
ASTInternal.setFullyResolved(name.getBinding(), true);
}

View file

@ -14,12 +14,11 @@ package org.eclipse.cdt.internal.core.pdom;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
@ -56,7 +55,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
}
public void addFileContent(IIndexFragmentFile sourceFile, IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names, ASTFilePathResolver pathResolver) throws CoreException {
IASTPreprocessorStatement[] macros, IASTName[][] names, ASTFilePathResolver pathResolver) throws CoreException {
assert sourceFile.getIndexFragment() == this;
PDOMFile pdomFile = (PDOMFile) sourceFile;
@ -113,7 +112,6 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
* <b>A write-lock must be obtained before calling this method</b>
*
* @param newConverter the converter to use to update internal file representations
* @return a list of PDOMFiles for which the location converter returned null when queried for the new internal representation
* @throws CoreException
*/
public void rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
@ -131,8 +129,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
clearFileIndex();
final List<PDOMFile> notConverted = new ArrayList<PDOMFile>();
for(Iterator<PDOMFile> i= pdomfiles.iterator(); i.hasNext(); ) {
PDOMFile file= i.next();
for (PDOMFile file : pdomfiles) {
String internalFormat = newConverter.toInternalFormat(file.getLocation());
if(internalFormat!=null) {
file.setInternalLocation(internalFormat);
@ -144,8 +141,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
// remove content where converter returns null
for(Iterator<PDOMFile> i = notConverted.iterator(); i.hasNext(); ) {
PDOMFile file = i.next();
for (PDOMFile file : notConverted) {
file.convertIncludersToUnresolved();
file.clear(null);
}

View file

@ -23,6 +23,8 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
@ -225,21 +227,31 @@ public class PDOMFile implements IIndexFragmentFile {
pdom.getDB().putInt(record + FIRST_MACRO, rec);
}
public void addMacros(IASTPreprocessorMacroDefinition[] macros) throws CoreException {
public void addMacros(IASTPreprocessorStatement[] macros) throws CoreException {
assert getFirstMacro() == null;
PDOMMacro lastMacro= null;
final PDOMLinkage linkage = getLinkage();
for (int i = 0; i < macros.length; i++) {
IASTPreprocessorMacroDefinition macro = macros[i];
PDOMMacroContainer container= linkage.getMacroContainer(macro.getName().toCharArray());
PDOMMacro pdomMacro = new PDOMMacro(pdom, container, macro, this);
if (lastMacro == null) {
setFirstMacro(pdomMacro);
} else {
lastMacro.setNextMacro(pdomMacro);
for (IASTPreprocessorStatement stmt : macros) {
PDOMMacro pdomMacro= null;
if (stmt instanceof IASTPreprocessorMacroDefinition) {
IASTPreprocessorMacroDefinition macro= (IASTPreprocessorMacroDefinition) stmt;
PDOMMacroContainer container= linkage.getMacroContainer(macro.getName().toCharArray());
pdomMacro = new PDOMMacro(pdom, container, macro, this);
}
else if (stmt instanceof IASTPreprocessorUndefStatement) {
IASTPreprocessorUndefStatement undef= (IASTPreprocessorUndefStatement) stmt;
PDOMMacroContainer container= linkage.getMacroContainer(undef.getMacroName().toCharArray());
pdomMacro = new PDOMMacro(pdom, container, undef, this);
}
if (pdomMacro != null) {
if (lastMacro == null) {
setFirstMacro(pdomMacro);
} else {
lastMacro.setNextMacro(pdomMacro);
}
lastMacro= pdomMacro;
}
lastMacro= pdomMacro;
}
}
@ -261,8 +273,7 @@ public class PDOMFile implements IIndexFragmentFile {
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>();
PDOMName lastName= null;
PDOMMacroReferenceName lastMacroName= null;
for (int i = 0; i < names.length; i++) {
IASTName[] name = names[i];
for (IASTName[] name : names) {
if (name[0] != null) {
PDOMName caller= nameCache.get(name[1]);
IIndexFragmentName fname= createPDOMName(linkage, name[0], caller);
@ -380,8 +391,7 @@ public class PDOMFile implements IIndexFragmentFile {
assert getFirstInclude() == null;
PDOMInclude lastInclude= null;
for (int i = 0; i < includeInfos.length; i++) {
final IncludeInformation info= includeInfos[i];
for (final IncludeInformation info : includeInfos) {
final PDOMFile targetFile= (PDOMFile) info.fTargetFile;
PDOMInclude pdomInclude = new PDOMInclude(pdom, info.fStatement, this, targetFile);
@ -463,7 +473,9 @@ public class PDOMFile implements IIndexFragmentFile {
int nameOffset= name.getNodeOffset();
if (nameOffset >= offset) {
if (nameOffset + name.getNodeLength() <= offset+length) {
result.add(name.getDefinition());
if (name.isMacroDefinition()) {
result.add(name.getDefinition());
}
} else {
break;
}

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro;
@ -56,12 +57,13 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo
private static final int RECORD_SIZE = 34;
private static final char[][] UNINITIALIZED= {};
private static final char[] UNINITIALIZED1= {};
private final PDOM fPDOM;
private final int fRecord;
private char[][] fParameterList= UNINITIALIZED;
private char[] fExpansion;
private char[] fExpansion= UNINITIALIZED1;
private PDOMMacroContainer fContainer;
private PDOMMacroDefinitionName fDefinition;
@ -70,36 +72,45 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo
fRecord = record;
}
public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorMacroDefinition macro, PDOMFile file) throws CoreException {
final Database db= pdom.getDB();
fPDOM = pdom;
fRecord = db.malloc(RECORD_SIZE);
fContainer= container;
this(pdom, container, file, macro.getName());
final IASTName name = macro.getName();
final IASTFileLocation fileloc = name.getFileLocation();
final IMacroBinding binding= (IMacroBinding) name.getBinding();
final char[][] params= binding.getParameterList();
db.putInt(fRecord + CONTAINER, container.getRecord());
db.putInt(fRecord + FILE, file.getRecord());
db.putInt(fRecord + EXPANSION, db.newString(binding.getExpansionImage()).getRecord());
db.putInt(fRecord + NAME_OFFSET, fileloc.getNodeOffset());
db.putShort(fRecord + NAME_LENGTH, (short) fileloc.getNodeLength());
final Database db= pdom.getDB();
db.putInt(fRecord + EXPANSION, db.newString(binding.getExpansionImage()).getRecord());
if (params != null) {
StringBuilder buf= new StringBuilder();
for (int i= 0; i < params.length; i++) {
buf.append(params[i]);
for (char[] param : params) {
buf.append(param);
buf.append(',');
}
db.putInt(fRecord + PARAMETERS, db.newString(buf.toString().toCharArray()).getRecord());
}
fContainer.addDefinition(this);
container.addDefinition(this);
}
public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorUndefStatement undef, PDOMFile file) throws CoreException {
this(pdom, container, file, undef.getMacroName());
}
private PDOMMacro(PDOM pdom, PDOMMacroContainer container, PDOMFile file, IASTName name) throws CoreException {
final Database db= pdom.getDB();
fPDOM = pdom;
fRecord = db.malloc(RECORD_SIZE);
fContainer= container;
final IASTFileLocation fileloc = name.getFileLocation();
db.putInt(fRecord + CONTAINER, container.getRecord());
db.putInt(fRecord + FILE, file.getRecord());
db.putInt(fRecord + NAME_OFFSET, fileloc.getNodeOffset());
db.putShort(fRecord + NAME_LENGTH, (short) fileloc.getNodeLength());
}
public PDOM getPDOM() {
return fPDOM;
}
@ -125,7 +136,10 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo
nextName.setPrevInContainer(prevName);
getExpansionInDB().delete();
final IString expansion = getExpansionInDB();
if (expansion != null) {
expansion.delete();
}
final IString params = getParamListInDB();
if (params != null) {
params.delete();
@ -142,7 +156,7 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo
private IString getExpansionInDB() throws CoreException {
Database db = fPDOM.getDB();
int rec = db.getInt(fRecord + EXPANSION);
return db.getString(rec);
return rec == 0 ? null : db.getString(rec);
}
private IString getParamListInDB() throws CoreException {
@ -215,13 +229,21 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo
return fParameterList;
}
public boolean isMacroDefinition() throws CoreException {
if (fExpansion == UNINITIALIZED1) {
return fPDOM.getDB().getInt(fRecord + EXPANSION) != 0;
}
return fExpansion != null;
}
public char[] getExpansionImage() {
if (fExpansion == null) {
if (fExpansion == UNINITIALIZED1) {
try {
fExpansion= getExpansionInDB().getChars();
final IString expansionInDB = getExpansionInDB();
fExpansion= expansionInDB == null ? null : expansionInDB.getChars();
} catch (CoreException e) {
CCorePlugin.log(e);
fExpansion= new char[] {};
fExpansion= CharArrayUtils.EMPTY;
}
}
return fExpansion;
@ -343,7 +365,10 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo
return null;
}
public IIndexFragmentName getDefinition() {
public IIndexFragmentName getDefinition() throws CoreException {
if (!isMacroDefinition()) {
return null;
}
if (fDefinition == null) {
fDefinition= new PDOMMacroDefinitionName(this);
}