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

Bug 367753: Correct propagating of internal modifications to the macro dictionary.

This commit is contained in:
Markus Schorn 2012-01-03 14:32:31 +01:00
parent 3bd21a03c4
commit 8afad54183
5 changed files with 126 additions and 25 deletions

View file

@ -84,6 +84,8 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
protected IASTName findName(String section, int len) {
if (len == 0)
len= section.length();
for (int i = 0; i < strategy.getAstCount(); i++) {
IASTTranslationUnit ast = strategy.getAst(i);
final IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
@ -260,30 +262,36 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
this.cpp = cpp;
}
@Override
public ICProject getCProject() {
return cproject;
}
@Override
public StringBuilder[] getTestData() {
return testData;
}
@Override
public int getAstCount() {
return 1;
}
@Override
public IASTTranslationUnit getAst(int index) {
if (index != 0)
throw new IllegalArgumentException();
return ast;
}
@Override
public StringBuilder getAstSource(int index) {
if (index != 0)
throw new IllegalArgumentException();
return testData[1];
}
@Override
public void setUp() throws Exception {
cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
@ -308,6 +316,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile);
}
@Override
public void tearDown() throws Exception {
if (index != null) {
index.releaseReadLock();
@ -317,10 +326,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
}
@Override
public IIndex getIndex() {
return index;
}
@Override
public boolean isCompositeIndex() {
return false;
}
@ -337,30 +348,36 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
this.cpp = cpp;
}
@Override
public ICProject getCProject() {
return cproject;
}
@Override
public StringBuilder[] getTestData() {
return testData;
}
@Override
public int getAstCount() {
return 1;
}
@Override
public IASTTranslationUnit getAst(int index) {
if (index != 0)
throw new IllegalArgumentException();
return ast;
}
@Override
public StringBuilder getAstSource(int index) {
if (index != 0)
throw new IllegalArgumentException();
return testData[1];
}
@Override
public void setUp() throws Exception {
cproject = cpp ? CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
@ -385,6 +402,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile);
}
@Override
public void tearDown() throws Exception {
if (index != null) {
index.releaseReadLock();
@ -394,10 +412,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
}
@Override
public IIndex getIndex() {
return index;
}
@Override
public boolean isCompositeIndex() {
return false;
}
@ -425,26 +445,32 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
asts = new ArrayList<IASTTranslationUnit>();
}
@Override
public ICProject getCProject() {
return cproject;
}
@Override
public StringBuilder[] getTestData() {
return testData;
}
@Override
public int getAstCount() {
return asts.size();
}
@Override
public IASTTranslationUnit getAst(int index) {
return asts.get(index);
}
@Override
public StringBuilder getAstSource(int index) {
return astSources.get(index);
}
@Override
public void setUp() throws Exception {
cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
@ -487,6 +513,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
}
@Override
public void tearDown() throws Exception {
if (index != null) {
index.releaseReadLock();
@ -496,10 +523,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
}
@Override
public IIndex getIndex() {
return index;
}
@Override
public boolean isCompositeIndex() {
return false;
}
@ -516,10 +545,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
this.cpp = cpp;
}
@Override
public ICProject getCProject() {
return cproject;
}
@Override
public void tearDown() throws Exception {
if (index != null) {
index.releaseReadLock();
@ -532,6 +563,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
}
@Override
public void setUp() throws Exception {
cproject= cpp ? CProjectHelper.createCCProject("OnlineContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject("OnlineContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
@ -580,30 +612,36 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return referenced;
}
@Override
public int getAstCount() {
return 1;
}
@Override
public IASTTranslationUnit getAst(int index) {
if (index != 0)
throw new IllegalArgumentException();
return ast;
}
@Override
public StringBuilder getAstSource(int index) {
if (index != 0)
throw new IllegalArgumentException();
return testData[1];
}
@Override
public IIndex getIndex() {
return index;
}
@Override
public StringBuilder[] getTestData() {
return testData;
}
@Override
public boolean isCompositeIndex() {
return true;
}

View file

@ -76,13 +76,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));}
public static TestSuite suite() {return suite(ProjectWithDepProj.class);}
// template <typename T= int> class XT;
// #include "header.h"
// template <typename T> class XT {};
// void test() {
// XT<> x;
// };
@Override
public void testDefaultTemplateArgInHeader_264988() throws Exception {
// Not supported across projects (the composite index does not merge

View file

@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.index.tests;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
@ -136,4 +138,50 @@ public class IndexMultiVariantHeaderTest extends IndexBindingResolutionTestBase
getBindingFromASTName("y = 0", 1, ICPPVariable.class);
getBindingFromASTName("z = 0", 1, ICPPVariable.class);
}
// b.h
// #ifndef _B
// #define _B
// #define SIG // This internal modification is not propagated
// #endif
// a.h
// #include "b.h"
// #ifdef SIG // Not significant, because it is defined in "b.h"
// #endif
// a.cpp *
// #include "a.h"
public void testSignificantMacroDetection_367753a() throws Exception {
IASTName includeName= findName("a.h", 0);
IASTPreprocessorIncludeStatement inc= (IASTPreprocessorIncludeStatement) includeName.getParent();
assertTrue(inc.isResolved());
assertEquals("{}", inc.getSignificantMacros().toString());
assertNotNull(inc.getImportedIndexFile());
}
// c.h
// #define SIG // This internal modification is not propagated
// b.h
// #ifndef _B
// #define _B
// #include "c.h"
// #endif
// a.h
// #include "b.h"
// #ifdef SIG // Not significant, because it is defined in "c.h"
// #endif
// a.cpp *
// #include "a.h"
public void testSignificantMacroDetection_367753b() throws Exception {
IASTName includeName= findName("a.h", 0);
IASTPreprocessorIncludeStatement inc= (IASTPreprocessorIncludeStatement) includeName.getParent();
assertTrue(inc.isResolved());
assertEquals("{}", inc.getSignificantMacros().toString());
assertNotNull(inc.getImportedIndexFile());
}
}

View file

@ -105,9 +105,12 @@ public class TestSourceReader {
contents.remove(0);
content = new StringBuilder();
}
int idx= line.indexOf(testName);
if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) {
return contents.toArray(new StringBuilder[contents.size()]);
if (line.length() > 0 && !contents.isEmpty()) {
int idx= line.indexOf(testName);
if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) {
return contents.toArray(new StringBuilder[contents.size()]);
}
contents.clear();
}
}
}
@ -229,6 +232,7 @@ public class TestSourceReader {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final IFile result[] = new IFile[1];
ws.run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
//Obtain file handle
IFile file = container.getFile(filePath);

View file

@ -330,10 +330,23 @@ final class ScannerContext {
}
public void internalModification(char[] macroName) {
if (fInternalModifications != null)
fInternalModifications.put(macroName);
final CharArraySet collector = findModificationCollector();
if (collector != null)
collector.put(macroName);
}
private CharArraySet findModificationCollector() {
ScannerContext ctx= this;
do {
final CharArraySet collector = ctx.fInternalModifications;
if (collector != null)
return collector;
ctx= ctx.getParent();
} while (ctx != null);
return null;
}
public void significantMacro(IMacroBinding macro) {
final char[] macroName= macro.getNameCharArray();
if (fInternalModifications != null && !fInternalModifications.containsKey(macroName)) {
@ -372,23 +385,28 @@ final class ScannerContext {
return;
if (fParent != null) {
final CharArraySet local = fParent.fInternalModifications;
if (local != null) {
final CharArrayObjectMap<char[]> significant = fParent.fSignificantMacros;
for (int i=0; i<fSignificantMacros.size(); i++) {
final char[] name = fSignificantMacros.keyAt(i);
if (!local.containsKey(name)) {
final char[] value= fSignificantMacros.getAt(i);
if (value == SignificantMacros.DEFINED) {
if (!local.containsKey(name)) {
fParent.addSignificantMacroDefined(name);
CharArraySet collector = fParent.findModificationCollector();
if (collector != null) {
// Propagate internal modifications to first interested parent.
collector.addAll(fInternalModifications);
// Propagate significant macros to direct parent, if it is interested.
if (collector == fParent.fInternalModifications) {
final CharArrayObjectMap<char[]> significant = fParent.fSignificantMacros;
for (int i=0; i<fSignificantMacros.size(); i++) {
final char[] name = fSignificantMacros.keyAt(i);
if (!collector.containsKey(name)) {
final char[] value= fSignificantMacros.getAt(i);
if (value == SignificantMacros.DEFINED) {
if (!collector.containsKey(name)) {
fParent.addSignificantMacroDefined(name);
}
} else {
significant.put(name, value);
}
} else {
significant.put(name, value);
}
}
}
local.addAll(fInternalModifications);
}
}
fInternalModifications= null;