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:
parent
0fe5609a10
commit
9c3e30e9a0
17 changed files with 170 additions and 23 deletions
|
@ -21,9 +21,11 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
|
|||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
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.model.ICProject;
|
||||
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.internal.core.CCoreInternals;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
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.IWorkspaceRunnable;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
@ -51,4 +52,8 @@ public class IndexTestBase extends BaseTestCase {
|
|||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(10000, new NullProgressMonitor()));
|
||||
return result[0];
|
||||
}
|
||||
|
||||
protected String readTaggedComment(String tag) throws Exception {
|
||||
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.testplugin;
|
||||
|
||||
|
@ -17,13 +18,16 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
|
|||
|
||||
public class TestScannerInfo implements IScannerInfo {
|
||||
private Map emptyMap = new HashMap(0);
|
||||
private String[] fIncludes;
|
||||
|
||||
public TestScannerInfo(String[] includes) {
|
||||
fIncludes= includes;
|
||||
}
|
||||
public Map getDefinedSymbols() {
|
||||
return emptyMap;
|
||||
}
|
||||
|
||||
public String[] getIncludePaths() {
|
||||
return new String[0];
|
||||
return fIncludes == null ? new String[0] : fIncludes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.testplugin;
|
||||
|
||||
|
@ -18,10 +19,11 @@ import org.eclipse.core.resources.IResource;
|
|||
|
||||
public class TestScannerProvider extends AbstractCExtension implements IScannerInfoProvider {
|
||||
|
||||
public static String[] sIncludes= null;
|
||||
public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner";
|
||||
|
||||
public IScannerInfo getScannerInformation(IResource resource) {
|
||||
return new TestScannerInfo();
|
||||
return new TestScannerInfo(sIncludes);
|
||||
}
|
||||
|
||||
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
|
|
|
@ -50,4 +50,25 @@ public interface IIndexInclude {
|
|||
* @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;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
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.index.IIndex;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -42,7 +43,7 @@ public interface IWritableIndex extends IIndex {
|
|||
/**
|
||||
* 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.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
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.core.runtime.CoreException;
|
||||
|
||||
|
@ -38,7 +39,7 @@ public interface IWritableIndexFragment extends IIndexFragment {
|
|||
/**
|
||||
* 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.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
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.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -44,12 +45,13 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
|
|||
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();
|
||||
assert isWritableFragment(indexFragment);
|
||||
assert isWritableFragment(destFile.getIndexFragment());
|
||||
|
||||
((IWritableIndexFragment) indexFragment).addInclude(sourceFile, destFile);
|
||||
((IWritableIndexFragment) indexFragment).addInclude(sourceFile, destFile, include);
|
||||
}
|
||||
|
||||
private boolean isWritableFragment(IIndexFragment frag) {
|
||||
|
|
|
@ -64,7 +64,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
|
||||
private Database db;
|
||||
|
||||
public static final int VERSION = 14;
|
||||
public static final int VERSION = 15;
|
||||
// 0 - the beginning of it all
|
||||
// 1 - first change to kick off upgrades
|
||||
// 2 - added file inclusions
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.text.MessageFormat;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
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.internal.core.index.IIndexFragmentFile;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
|
||||
|
@ -32,10 +33,11 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
|||
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 destFile.getIndexFragment() == this;
|
||||
((PDOMFile) sourceFile).addIncludeTo((PDOMFile) destFile);
|
||||
((PDOMFile) sourceFile).addIncludeTo((PDOMFile) destFile, include);
|
||||
}
|
||||
|
||||
public void addMacro(IIndexFragmentFile sourceFile, IASTPreprocessorMacroDefinition macro) throws CoreException {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.db;
|
||||
|
||||
|
@ -66,6 +67,14 @@ public class Chunk {
|
|||
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) {
|
||||
return buffer.getLong(offset % Database.CHUNK_SIZE);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* Symbian - Add some non-javadoc implementation notes
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.db;
|
||||
|
||||
|
@ -271,6 +272,16 @@ public class Database {
|
|||
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 {
|
||||
Chunk chunk= getChunk(offset);
|
||||
chunk.putLong(offset, value);
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
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.index.IIndexInclude;
|
||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
|
@ -234,19 +236,19 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
setFirstName(null);
|
||||
}
|
||||
|
||||
public PDOMInclude addIncludeTo(PDOMFile file) throws CoreException {
|
||||
PDOMInclude include = new PDOMInclude(pdom);
|
||||
include.setIncludedBy(this);
|
||||
include.setIncludes(file);
|
||||
public PDOMInclude addIncludeTo(PDOMFile file, IASTPreprocessorIncludeStatement include) throws CoreException {
|
||||
PDOMInclude pdomInclude = new PDOMInclude(pdom, include);
|
||||
pdomInclude.setIncludedBy(this);
|
||||
pdomInclude.setIncludes(file);
|
||||
|
||||
PDOMInclude firstInclude = getFirstInclude();
|
||||
if (firstInclude != null) {
|
||||
include.setNextInIncludes(firstInclude);
|
||||
pdomInclude.setNextInIncludes(firstInclude);
|
||||
}
|
||||
setFirstInclude(include);
|
||||
setFirstInclude(pdomInclude);
|
||||
|
||||
file.addIncludedBy(include);
|
||||
return include;
|
||||
file.addIncludedBy(pdomInclude);
|
||||
return pdomInclude;
|
||||
}
|
||||
|
||||
public void addIncludedBy(PDOMInclude include) throws CoreException {
|
||||
|
@ -267,6 +269,7 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
result.add(include);
|
||||
include = include.getNextInIncludes();
|
||||
}
|
||||
Collections.reverse(result);
|
||||
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
|
||||
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.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||
|
@ -33,19 +36,36 @@ public class PDOMInclude implements IIndexFragmentInclude {
|
|||
private final int INCLUDES_NEXT = 8;
|
||||
private final int INCLUDED_BY_NEXT = 12;
|
||||
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 static final int FLAG_SYSTEM_INCLUDE = 1;
|
||||
|
||||
private final int RECORD_SIZE = 20;
|
||||
private final int RECORD_SIZE = 27;
|
||||
|
||||
public PDOMInclude(PDOM pdom, int record) {
|
||||
this.pdom = pdom;
|
||||
this.record = record;
|
||||
}
|
||||
|
||||
public PDOMInclude(PDOM pdom) throws CoreException {
|
||||
public PDOMInclude(PDOM pdom, IASTPreprocessorIncludeStatement include) throws CoreException {
|
||||
this.pdom = pdom;
|
||||
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() {
|
||||
return record;
|
||||
}
|
||||
|
@ -127,4 +147,29 @@ public class PDOMInclude implements IIndexFragmentInclude {
|
|||
public IIndexFragment getFragment() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
|||
for (int i = 0; i < list.size(); i++) {
|
||||
IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i);
|
||||
IIndexFragmentFile destFile= createIndexFile(include.getPath());
|
||||
index.addInclude(file, destFile);
|
||||
index.addInclude(file, destFile, include);
|
||||
}
|
||||
|
||||
// macros
|
||||
|
|
|
@ -253,7 +253,7 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
|||
for (int i = 0; i < list.size(); i++) {
|
||||
IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i);
|
||||
IIndexFragmentFile destFile= index.addFile(new Path(include.getPath()));
|
||||
index.addInclude(file, destFile);
|
||||
index.addInclude(file, destFile, include);
|
||||
}
|
||||
|
||||
// macros
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
|
|||
|
||||
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) {
|
||||
super(name);
|
||||
|
|
Loading…
Add table
Reference in a new issue