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

Testcase and fix for 159566 and 159570, additional info for IIndexInclude.

This commit is contained in:
Markus Schorn 2006-11-07 12:46:44 +00:00
parent 0fe5609a10
commit 9c3e30e9a0
17 changed files with 170 additions and 23 deletions

View file

@ -21,9 +21,11 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -135,4 +137,43 @@ public class IndexIncludeTest extends IndexTestBase {
} }
} }
// {source20061107}
// #include "user20061107.h"
// #include <system20061107.h>
public void testIncludeProperties() throws Exception {
waitForIndexer();
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
try {
String content= readTaggedComment("source20061107");
TestSourceReader.createFile(fProject.getProject(), "user20061107.h", "");
TestSourceReader.createFile(fProject.getProject(), "system20061107.h", "");
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
assertNotNull(ifile);
IIndexInclude[] includes= ifile.getIncludes();
assertEquals(2, includes.length);
checkInclude(includes[0], content, "user20061107.h", false);
checkInclude(includes[1], content, "system20061107.h", true);
}
finally {
fIndex.releaseReadLock();
}
}
finally {
TestScannerProvider.sIncludes= null;
}
}
private void checkInclude(IIndexInclude include, String content, String includeName, boolean isSystem) throws CoreException {
int offset= content.indexOf(includeName);
assertEquals(offset, include.getNameOffset());
assertEquals(includeName.length(), include.getNameLength());
assertEquals(isSystem, include.isSystemInclude());
}
} }

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -51,4 +52,8 @@ public class IndexTestBase extends BaseTestCase {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(10000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(10000, new NullProgressMonitor()));
return result[0]; return result[0];
} }
protected String readTaggedComment(String tag) throws Exception {
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag);
}
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin; package org.eclipse.cdt.core.testplugin;
@ -17,13 +18,16 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
public class TestScannerInfo implements IScannerInfo { public class TestScannerInfo implements IScannerInfo {
private Map emptyMap = new HashMap(0); private Map emptyMap = new HashMap(0);
private String[] fIncludes;
public TestScannerInfo(String[] includes) {
fIncludes= includes;
}
public Map getDefinedSymbols() { public Map getDefinedSymbols() {
return emptyMap; return emptyMap;
} }
public String[] getIncludePaths() { public String[] getIncludePaths() {
return new String[0]; return fIncludes == null ? new String[0] : fIncludes;
} }
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin; package org.eclipse.cdt.core.testplugin;
@ -18,10 +19,11 @@ import org.eclipse.core.resources.IResource;
public class TestScannerProvider extends AbstractCExtension implements IScannerInfoProvider { public class TestScannerProvider extends AbstractCExtension implements IScannerInfoProvider {
public static String[] sIncludes= null;
public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner"; public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner";
public IScannerInfo getScannerInformation(IResource resource) { public IScannerInfo getScannerInformation(IResource resource) {
return new TestScannerInfo(); return new TestScannerInfo(sIncludes);
} }
public void subscribe(IResource resource, IScannerInfoChangeListener listener) { public void subscribe(IResource resource, IScannerInfoChangeListener listener) {

View file

@ -50,4 +50,25 @@ public interface IIndexInclude {
* @throws CoreException * @throws CoreException
*/ */
String getIncludesLocation() throws CoreException; String getIncludesLocation() throws CoreException;
/**
* Returns the character offset of the name of the include in its source file. The name does
* not include the enclosing quotes or angle brackets.
* @throws CoreException
*/
int getNameOffset() throws CoreException;
/**
* Returns the length of the name of the include. The name does
* not include the enclosing quotes or angle brackets.
* @throws CoreException
*/
int getNameLength() throws CoreException;
/**
* Returns whether this is a system include (an include specified within angle
* brackets).
* @throws CoreException
*/
boolean isSystemInclude() throws CoreException;
} }

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.core.index; package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -42,7 +43,7 @@ public interface IWritableIndex extends IIndex {
/** /**
* Adds an include to the given file. * Adds an include to the given file.
*/ */
void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile) throws CoreException; void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile, IASTPreprocessorIncludeStatement directive) throws CoreException;
/** /**
* Clears the entire index. * Clears the entire index.

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.core.index; package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.IASTPreprocessorMacroDefinition;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -38,7 +39,7 @@ public interface IWritableIndexFragment extends IIndexFragment {
/** /**
* Adds an include to the given file. * Adds an include to the given file.
*/ */
void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile) throws CoreException; void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile, IASTPreprocessorIncludeStatement include) throws CoreException;
/** /**
* Adds a AST macro to the given file. * Adds a AST macro to the given file.

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.core.index; package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.IASTPreprocessorMacroDefinition;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -44,12 +45,13 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
return fWritableFragments[0]; return fWritableFragments[0];
} }
public void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile) throws CoreException { public void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile,
IASTPreprocessorIncludeStatement include) throws CoreException {
IIndexFragment indexFragment = sourceFile.getIndexFragment(); IIndexFragment indexFragment = sourceFile.getIndexFragment();
assert isWritableFragment(indexFragment); assert isWritableFragment(indexFragment);
assert isWritableFragment(destFile.getIndexFragment()); assert isWritableFragment(destFile.getIndexFragment());
((IWritableIndexFragment) indexFragment).addInclude(sourceFile, destFile); ((IWritableIndexFragment) indexFragment).addInclude(sourceFile, destFile, include);
} }
private boolean isWritableFragment(IIndexFragment frag) { private boolean isWritableFragment(IIndexFragment frag) {

View file

@ -64,7 +64,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
private Database db; private Database db;
public static final int VERSION = 14; public static final int VERSION = 15;
// 0 - the beginning of it all // 0 - the beginning of it all
// 1 - first change to kick off upgrades // 1 - first change to kick off upgrades
// 2 - added file inclusions // 2 - added file inclusions

View file

@ -15,6 +15,7 @@ import java.text.MessageFormat;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment; import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
@ -32,10 +33,11 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
return super.addFile(filename); return super.addFile(filename);
} }
public void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile) throws CoreException { public void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile,
IASTPreprocessorIncludeStatement include) throws CoreException {
assert sourceFile.getIndexFragment() == this; assert sourceFile.getIndexFragment() == this;
assert destFile.getIndexFragment() == this; assert destFile.getIndexFragment() == this;
((PDOMFile) sourceFile).addIncludeTo((PDOMFile) destFile); ((PDOMFile) sourceFile).addIncludeTo((PDOMFile) destFile, include);
} }
public void addMacro(IIndexFragmentFile sourceFile, IASTPreprocessorMacroDefinition macro) throws CoreException { public void addMacro(IIndexFragmentFile sourceFile, IASTPreprocessorMacroDefinition macro) throws CoreException {

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db; package org.eclipse.cdt.internal.core.pdom.db;
@ -66,6 +67,14 @@ public class Chunk {
return buffer.getInt(offset % Database.CHUNK_SIZE); return buffer.getInt(offset % Database.CHUNK_SIZE);
} }
public void putShort(int offset, short value) {
buffer.putShort(offset % Database.CHUNK_SIZE, value);
}
public short getShort(int offset) {
return buffer.getShort(offset % Database.CHUNK_SIZE);
}
public long getLong(int offset) { public long getLong(int offset) {
return buffer.getLong(offset % Database.CHUNK_SIZE); return buffer.getLong(offset % Database.CHUNK_SIZE);
} }

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Symbian - Add some non-javadoc implementation notes * Symbian - Add some non-javadoc implementation notes
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db; package org.eclipse.cdt.internal.core.pdom.db;
@ -271,6 +272,16 @@ public class Database {
return chunk.getInt(offset); return chunk.getInt(offset);
} }
public void putShort(int offset, short value) throws CoreException {
Chunk chunk = getChunk(offset);
chunk.putShort(offset, value);
}
public short getShort(int offset) throws CoreException {
Chunk chunk = getChunk(offset);
return chunk.getShort(offset);
}
public void putLong(int offset, long value) throws CoreException { public void putLong(int offset, long value) throws CoreException {
Chunk chunk= getChunk(offset); Chunk chunk= getChunk(offset);
chunk.putLong(offset, value); chunk.putLong(offset, value);

View file

@ -12,8 +12,10 @@
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexMacro;
@ -234,19 +236,19 @@ public class PDOMFile implements IIndexFragmentFile {
setFirstName(null); setFirstName(null);
} }
public PDOMInclude addIncludeTo(PDOMFile file) throws CoreException { public PDOMInclude addIncludeTo(PDOMFile file, IASTPreprocessorIncludeStatement include) throws CoreException {
PDOMInclude include = new PDOMInclude(pdom); PDOMInclude pdomInclude = new PDOMInclude(pdom, include);
include.setIncludedBy(this); pdomInclude.setIncludedBy(this);
include.setIncludes(file); pdomInclude.setIncludes(file);
PDOMInclude firstInclude = getFirstInclude(); PDOMInclude firstInclude = getFirstInclude();
if (firstInclude != null) { if (firstInclude != null) {
include.setNextInIncludes(firstInclude); pdomInclude.setNextInIncludes(firstInclude);
} }
setFirstInclude(include); setFirstInclude(pdomInclude);
file.addIncludedBy(include); file.addIncludedBy(pdomInclude);
return include; return pdomInclude;
} }
public void addIncludedBy(PDOMInclude include) throws CoreException { public void addIncludedBy(PDOMInclude include) throws CoreException {
@ -267,6 +269,7 @@ public class PDOMFile implements IIndexFragmentFile {
result.add(include); result.add(include);
include = include.getNextInIncludes(); include = include.getNextInIncludes();
} }
Collections.reverse(result);
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]); return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
} }

View file

@ -12,6 +12,9 @@
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
@ -33,17 +36,34 @@ public class PDOMInclude implements IIndexFragmentInclude {
private final int INCLUDES_NEXT = 8; private final int INCLUDES_NEXT = 8;
private final int INCLUDED_BY_NEXT = 12; private final int INCLUDED_BY_NEXT = 12;
private final int INCLUDED_BY_PREV = 16; private final int INCLUDED_BY_PREV = 16;
private static final int NODE_OFFSET_OFFSET = 20;
private static final int NODE_LENGTH_OFFSET = 24;
private static final int FLAG_OFFSET = 26;
private final int RECORD_SIZE = 20; private static final int FLAG_SYSTEM_INCLUDE = 1;
private final int RECORD_SIZE = 27;
public PDOMInclude(PDOM pdom, int record) { public PDOMInclude(PDOM pdom, int record) {
this.pdom = pdom; this.pdom = pdom;
this.record = record; this.record = record;
} }
public PDOMInclude(PDOM pdom) throws CoreException { public PDOMInclude(PDOM pdom, IASTPreprocessorIncludeStatement include) throws CoreException {
this.pdom = pdom; this.pdom = pdom;
this.record = pdom.getDB().malloc(RECORD_SIZE); this.record = pdom.getDB().malloc(RECORD_SIZE);
IASTName name= include.getName();
IASTFileLocation loc= name.getFileLocation();
setNameOffsetAndLength(loc.getNodeOffset(), (short) loc.getNodeLength());
setFlag(encodeFlags(include));
}
private byte encodeFlags(IASTPreprocessorIncludeStatement include) {
byte flags= 0;
if (include.isSystemInclude()) {
flags |= FLAG_SYSTEM_INCLUDE;
}
return flags;
} }
public int getRecord() { public int getRecord() {
@ -127,4 +147,29 @@ public class PDOMInclude implements IIndexFragmentInclude {
public IIndexFragment getFragment() { public IIndexFragment getFragment() {
return pdom; return pdom;
} }
private void setNameOffsetAndLength(int offset, short length) throws CoreException {
pdom.getDB().putInt(record + NODE_OFFSET_OFFSET, offset);
pdom.getDB().putShort(record + NODE_LENGTH_OFFSET, length);
}
private void setFlag(byte flag) throws CoreException {
pdom.getDB().putByte(record + FLAG_OFFSET, flag);
}
private int getFlag() throws CoreException {
return pdom.getDB().getByte(record + FLAG_OFFSET);
}
public boolean isSystemInclude() throws CoreException {
return (getFlag() & FLAG_SYSTEM_INCLUDE) != 0;
}
public int getNameOffset() throws CoreException {
return pdom.getDB().getInt(record + NODE_OFFSET_OFFSET);
}
public int getNameLength() throws CoreException {
return pdom.getDB().getShort(record + NODE_LENGTH_OFFSET) & 0xffff;
}
} }

View file

@ -212,7 +212,7 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i); IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i);
IIndexFragmentFile destFile= createIndexFile(include.getPath()); IIndexFragmentFile destFile= createIndexFile(include.getPath());
index.addInclude(file, destFile); index.addInclude(file, destFile, include);
} }
// macros // macros

View file

@ -253,7 +253,7 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i); IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i);
IIndexFragmentFile destFile= index.addFile(new Path(include.getPath())); IIndexFragmentFile destFile= index.addFile(new Path(include.getPath()));
index.addInclude(file, destFile); index.addInclude(file, destFile, include);
} }
// macros // macros

View file

@ -24,7 +24,7 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest { public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
private static final int MAX_TIME_INDEXER = 2000; private static final int MAX_TIME_INDEXER = 8000;
public BasicCppCallHierarchyTest(String name) { public BasicCppCallHierarchyTest(String name) {
super(name); super(name);