mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Preprocessor and Indexer independent of CodeReader, bug 294430.
This commit is contained in:
parent
3d72fc1408
commit
c6db7793a0
54 changed files with 1145 additions and 552 deletions
|
@ -67,16 +67,16 @@ import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.tests.ASTComparer;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner.FileCodeReaderFactory;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
|
@ -93,6 +93,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class AST2BaseTest extends BaseTestCase {
|
||||
protected final static String TEST_CODE = "<testcode>";
|
||||
protected static final IParserLogService NULL_LOG = new NullLogService();
|
||||
protected static boolean sValidateCopy;
|
||||
|
||||
|
@ -131,7 +132,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
|
||||
protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
|
||||
boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
|
||||
IScanner scanner = createScanner(new CodeReader(code.toCharArray()), lang, ParserMode.COMPLETE_PARSE,
|
||||
IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE,
|
||||
new ScannerInfo());
|
||||
configureScanner(scanner);
|
||||
AbstractGNUSourceCodeParser parser = null;
|
||||
|
@ -179,7 +180,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
protected void configureScanner(IScanner scanner) {
|
||||
}
|
||||
|
||||
public static IScanner createScanner(CodeReader codeReader, ParserLanguage lang, ParserMode mode,
|
||||
public static IScanner createScanner(FileContent codeReader, ParserLanguage lang, ParserMode mode,
|
||||
IScannerInfo scannerInfo) {
|
||||
IScannerExtensionConfiguration configuration = null;
|
||||
if (lang == ParserLanguage.C)
|
||||
|
@ -188,7 +189,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
configuration= GPPScannerExtensionConfiguration.getInstance();
|
||||
IScanner scanner;
|
||||
scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration,
|
||||
FileCodeReaderFactory.getInstance());
|
||||
IncludeFileContentProvider.getSavedFilesProvider());
|
||||
return scanner;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
|
@ -80,8 +80,7 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest {
|
|||
* @throws ParserException
|
||||
*/
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
CodeReader codeReader = new CodeReader(code
|
||||
.toCharArray());
|
||||
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
|
@ -80,7 +80,7 @@ public class AST2SpecBaseTest extends AST2BaseTest {
|
|||
// TODO beef this up with tests... i.e. run once with \n, and then run again with \r\n replacing \n ... etc
|
||||
// TODO another example might be to replace all characters with corresponding trigraph/digraph tests...
|
||||
|
||||
CodeReader codeReader = new CodeReader(code.toCharArray());
|
||||
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||
return parse(codeReader, lang, useGNUExtensions, expectNoProblems, checkBindings, expectedProblemBindings, problems);
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class AST2SpecBaseTest extends AST2BaseTest {
|
|||
// return parse(codeReader, lang, useGNUExtensions, expectNoProblems);
|
||||
// }
|
||||
|
||||
private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang,
|
||||
private IASTTranslationUnit parse(FileContent codeReader, ParserLanguage lang,
|
||||
boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings,
|
||||
int expectedProblemBindings, String[] problems) throws ParserException {
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
@ -53,7 +53,7 @@ public class ASTNodeSelectorTest extends AST2BaseTest {
|
|||
|
||||
protected void createTranslationUnit() throws IOException {
|
||||
fCode= getContents(1)[0].toString();
|
||||
CodeReader codeReader = new CodeReader(fCode.toCharArray());
|
||||
FileContent codeReader = FileContent.create("<test-code>", fCode.toCharArray());
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
GNUCPPSourceParser parser= new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, new NullLogService(), new GPPParserExtensionConfiguration());
|
||||
|
|
|
@ -69,7 +69,7 @@ import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
@ -176,8 +176,7 @@ public class CompleteParser2Tests extends BaseTestCase {
|
|||
ParserLanguage lang, boolean gcc) throws Exception {
|
||||
|
||||
|
||||
CodeReader codeReader = new CodeReader(code
|
||||
.toCharArray());
|
||||
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
ISourceCodeParser parser2 = null;
|
||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
|
|
@ -78,8 +78,6 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
public DOMLocationTests() {
|
||||
}
|
||||
|
||||
private static final String _TEXT_ = "<text>"; //$NON-NLS-1$
|
||||
|
||||
public DOMLocationTests(String name) {
|
||||
setName(name);
|
||||
}
|
||||
|
@ -97,7 +95,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
assertEquals(nodeLocations.length, 1);
|
||||
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
||||
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
||||
assertEquals(fileLocation.getFileName(), _TEXT_);
|
||||
assertEquals(fileLocation.getFileName(), TEST_CODE);
|
||||
assertEquals(fileLocation.getNodeOffset(), 0);
|
||||
assertEquals(fileLocation.getNodeLength(), 6);
|
||||
IASTNodeLocation[] tuLocations = tu.getNodeLocations();
|
||||
|
@ -120,7 +118,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
assertEquals(nodeLocations.length, 1);
|
||||
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
||||
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
||||
assertEquals(fileLocation.getFileName(), _TEXT_);
|
||||
assertEquals(fileLocation.getFileName(), TEST_CODE);
|
||||
assertEquals(fileLocation.getNodeOffset(), 0);
|
||||
assertEquals(fileLocation.getNodeLength(), code.indexOf(";") + 1); //$NON-NLS-1$
|
||||
IASTDeclarator[] declarators = declaration.getDeclarators();
|
||||
|
|
|
@ -30,12 +30,12 @@ import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.POPCPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.POPCPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner.FileCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
@ -72,19 +72,19 @@ public class LanguageExtensionsTest extends AST2BaseTest {
|
|||
|
||||
protected IASTTranslationUnit parse(String code, IScannerExtensionConfiguration sext,
|
||||
ICPPParserExtensionConfiguration pext) throws Exception {
|
||||
IScanner scanner=
|
||||
new CPreprocessor(new CodeReader(code.toCharArray()), new ScannerInfo(), ParserLanguage.CPP, NULL_LOG,
|
||||
sext, FileCodeReaderFactory.getInstance());
|
||||
GNUCPPSourceParser parser= new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
||||
return parse(parser);
|
||||
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||
IScanner scanner = new CPreprocessor(codeReader, new ScannerInfo(), ParserLanguage.CPP, NULL_LOG,
|
||||
sext, IncludeFileContentProvider.getSavedFilesProvider());
|
||||
GNUCPPSourceParser parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
||||
return parse(parser);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse(String code, IScannerExtensionConfiguration sext,
|
||||
ICParserExtensionConfiguration pext) throws Exception {
|
||||
IScanner scanner=
|
||||
new CPreprocessor(new CodeReader(code.toCharArray()), new ScannerInfo(), ParserLanguage.C, NULL_LOG,
|
||||
sext, FileCodeReaderFactory.getInstance());
|
||||
GNUCSourceParser parser= new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
||||
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||
IScanner scanner = new CPreprocessor(codeReader, new ScannerInfo(), ParserLanguage.C, NULL_LOG, sext,
|
||||
IncludeFileContentProvider.getSavedFilesProvider());
|
||||
GNUCSourceParser parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
||||
return parse(parser);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
|
@ -1363,7 +1363,7 @@ public class QuickParser2Tests extends TestCase {
|
|||
protected void parse(String code, boolean expectedToPass,
|
||||
ParserLanguage lang, boolean gcc) throws Exception {
|
||||
|
||||
CodeReader codeReader = new CodeReader( code.toCharArray() );
|
||||
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||
IScannerInfo scannerInfo = new ScannerInfo();
|
||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
ISourceCodeParser parser2 = null;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
|
@ -51,7 +51,7 @@ public class CompletionTestBase extends BaseTestCase {
|
|||
private static final IParserLogService NULL_LOG = new NullLogService();
|
||||
|
||||
protected IASTCompletionNode getCompletionNode(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException {
|
||||
CodeReader codeReader = new CodeReader(code.trim().toCharArray());
|
||||
FileContent codeReader = FileContent.create("<test-code>", code.trim().toCharArray());
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
|
@ -89,8 +89,8 @@ public class ASTWriterTest extends RewriteBaseTest {
|
|||
}
|
||||
|
||||
protected ISourceCodeParser getParser(TestSourceFile testFile) throws Exception {
|
||||
CodeReader codeReader = new CodeReader(file.getLocation().toOSString(), file.getContents());
|
||||
|
||||
FileContent codeReader = FileContent.create(file);
|
||||
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
ParserLanguage language = getLanguage(testFile);
|
||||
boolean useGNUExtensions = getGNUExtension(testFile);
|
||||
|
|
|
@ -13,7 +13,8 @@ package org.eclipse.cdt.core.parser.tests.scanner;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
||||
|
@ -22,7 +23,6 @@ import org.eclipse.cdt.core.parser.ScannerInfo;
|
|||
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.cdt.internal.core.dom.NullCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.MacroExpander;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.MacroExpansionTracker;
|
||||
|
@ -83,9 +83,9 @@ public class ExpansionExplorerTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
private MacroExpander createExpander(final String macrodefs) throws OffsetLimitReachedException {
|
||||
CPreprocessor cpp= new CPreprocessor(new CodeReader(macrodefs.toCharArray()),
|
||||
CPreprocessor cpp= new CPreprocessor(FileContent.create("<macro-expander>", macrodefs.toCharArray()),
|
||||
new ScannerInfo(), ParserLanguage.C, new NullLogService(),
|
||||
GCCScannerExtensionConfiguration.getInstance(), NullCodeReaderFactory.getInstance());
|
||||
GCCScannerExtensionConfiguration.getInstance(), IncludeFileContentProvider.getEmptyFilesProvider());
|
||||
int type;
|
||||
do {
|
||||
type= cpp.nextTokenRaw().getType();
|
||||
|
|
|
@ -10,60 +10,32 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.EmptyCodeReaderCache;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class FileCodeReaderFactory implements ICodeReaderFactory {
|
||||
public class FileCodeReaderFactory extends InternalFileContentProvider {
|
||||
|
||||
private static FileCodeReaderFactory instance;
|
||||
private ICodeReaderCache cache = null;
|
||||
|
||||
private FileCodeReaderFactory(ICodeReaderCache cache)
|
||||
{
|
||||
this.cache = cache;
|
||||
}
|
||||
private FileCodeReaderFactory() {}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier()
|
||||
*/
|
||||
public int getUniqueIdentifier() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||
return cache.get(path);
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(String path) {
|
||||
return (InternalFileContent) FileContent.createForExternalFileLocation(path);
|
||||
}
|
||||
|
||||
public CodeReader createCodeReaderForTranslationUnit(ITranslationUnit tu) {
|
||||
return new CodeReader(tu.getPath().toOSString(), tu.getContents());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.dom.ICodeReaderFactoryCallback, java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return cache.get(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static FileCodeReaderFactory getInstance() {
|
||||
if( instance == null )
|
||||
instance = new FileCodeReaderFactory(new EmptyCodeReaderCache());
|
||||
return instance;
|
||||
}
|
||||
if (instance == null)
|
||||
instance = new FileCodeReaderFactory();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ICodeReaderCache getCodeReaderCache() {
|
||||
return cache;
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(IIndexFileLocation ifl, String astPath) {
|
||||
// not used as a delegate
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.Collections;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
@ -99,7 +99,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
|||
f0.getLocation().removeLastSegments(1) + "/__framework__.framework/__header__"
|
||||
};
|
||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||
FileContent reader= FileContent.create(base);
|
||||
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
// first file is not picked up (no framework)
|
||||
|
@ -130,7 +130,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
|||
path[2] = oneThree.getLocation().toOSString();
|
||||
|
||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||
FileContent reader= FileContent.create(base);
|
||||
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
validateToken(IToken.t_int);
|
||||
|
@ -170,7 +170,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
|||
path[1] = two.getLocation().toOSString();
|
||||
|
||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||
FileContent reader= FileContent.create(base);
|
||||
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
validateInteger("0");
|
||||
|
@ -208,7 +208,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
|||
path[1] = threef.getLocation().toOSString();
|
||||
|
||||
IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[]{}, null );
|
||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||
FileContent reader= FileContent.create(base);
|
||||
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
validateToken(IToken.t_int);
|
||||
|
@ -236,7 +236,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
|||
buffer.append( "int var = FOUND;\n"); //$NON-NLS-1$
|
||||
IFile base = importFile( "base.cpp", buffer.toString() ); //$NON-NLS-1$
|
||||
|
||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||
FileContent reader= FileContent.create(base);
|
||||
ParserLanguage lang[]= {ParserLanguage.C, ParserLanguage.CPP};
|
||||
for (ParserLanguage element : lang) {
|
||||
initializeScanner(reader, element, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
||||
|
@ -254,7 +254,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
|||
StringBuffer buffer = new StringBuffer( "#include \"file.h\"" );
|
||||
IFile base = importFile( "base.cpp", buffer.toString() ); //$NON-NLS-1$
|
||||
|
||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||
FileContent reader= FileContent.create(base);
|
||||
initializeScanner(reader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
||||
validateIdentifier("ok");
|
||||
validateEOF();
|
||||
|
@ -272,7 +272,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
|||
|
||||
String[] path = {"f2"}; // relative include
|
||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||
FileContent reader= FileContent.create(base);
|
||||
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
validateInteger("1");
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
|||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.CharArray;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationCtx;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ImageLocationInfo;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.LocationMap;
|
||||
|
@ -118,7 +119,7 @@ public class LocationMapTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
private void init(char[] content) {
|
||||
fLocationMap.pushTranslationUnit(FN, content);
|
||||
fLocationMap.pushTranslationUnit(FN, new CharArray(content));
|
||||
fTu= new CPPASTTranslationUnit();
|
||||
fTu.setLocationResolver(fLocationMap);
|
||||
}
|
||||
|
@ -489,18 +490,18 @@ public class LocationMapTests extends BaseTestCase {
|
|||
assertEquals(FN, fLocationMap.getTranslationUnitPath());
|
||||
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||
// number: [30,36)[46,50)
|
||||
ILocationCtx pre1= fLocationMap.pushPreInclusion("0102030405".toCharArray(), 0, false);
|
||||
ILocationCtx pre1= fLocationMap.pushPreInclusion(new CharArray("0102030405"), 0, false);
|
||||
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||
// number: [0,6)[26,30)
|
||||
ILocationCtx pre2= fLocationMap.pushPreInclusion("a1a2a3a4a5".toCharArray(), 0, true);
|
||||
ILocationCtx pre2= fLocationMap.pushPreInclusion(new CharArray("a1a2a3a4a5"), 0, true);
|
||||
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||
fLocationMap.encounteredComment(0,2,true);
|
||||
// number: [6,15)[25,26)
|
||||
ILocationCtx i1= fLocationMap.pushInclusion(0, 2, 4, 6, "b1b2b3b4b5".toCharArray(), "pre1", "pre1".toCharArray(), false, false, false);
|
||||
ILocationCtx i1= fLocationMap.pushInclusion(0, 2, 4, 6, new CharArray("b1b2b3b4b5"), "pre1", "pre1".toCharArray(), false, false, false);
|
||||
assertEquals("pre1", fLocationMap.getCurrentFilePath());
|
||||
fLocationMap.encounteredComment(2,4,true);
|
||||
// number: [15,25)
|
||||
ILocationCtx i2= fLocationMap.pushInclusion(6, 7, 8, 9, "c1c2c3c4c5".toCharArray(), "pre11", "pre11".toCharArray(), false, false, false);
|
||||
ILocationCtx i2= fLocationMap.pushInclusion(6, 7, 8, 9, new CharArray("c1c2c3c4c5"), "pre11", "pre11".toCharArray(), false, false, false);
|
||||
assertEquals("pre11", fLocationMap.getCurrentFilePath());
|
||||
fLocationMap.encounteredComment(2,6,true);
|
||||
fLocationMap.popContext(i2);
|
||||
|
@ -513,7 +514,7 @@ public class LocationMapTests extends BaseTestCase {
|
|||
fLocationMap.popContext(pre2);
|
||||
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||
// number [36, 46)
|
||||
ILocationCtx i3= fLocationMap.pushInclusion(0, 2, 4, 6, "d1d2d3d4d5".toCharArray(), "pre2", "pre2".toCharArray(), false, false, false);
|
||||
ILocationCtx i3= fLocationMap.pushInclusion(0, 2, 4, 6, new CharArray("d1d2d3d4d5"), "pre2", "pre2".toCharArray(), false, false, false);
|
||||
assertEquals("pre2", fLocationMap.getCurrentFilePath());
|
||||
fLocationMap.encounteredComment(0,2,true);
|
||||
fLocationMap.popContext(i3);
|
||||
|
|
|
@ -16,11 +16,10 @@ import java.io.PrintStream;
|
|||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
@ -62,7 +61,7 @@ public class PreprocessorSpeedTest {
|
|||
"#include <stdio.h>\n" +
|
||||
"#include <iostream>\n";
|
||||
|
||||
CodeReader reader = new CodeReader(code.toCharArray());
|
||||
FileContent reader = FileContent.create("<test-code>", code.toCharArray());
|
||||
IScannerInfo info = getScannerInfo();
|
||||
long totalTime = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
|
@ -76,8 +75,8 @@ public class PreprocessorSpeedTest {
|
|||
}
|
||||
}
|
||||
|
||||
protected long testScan(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
||||
ICodeReaderFactory readerFactory= FileCodeReaderFactory.getInstance();
|
||||
protected long testScan(FileContent reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
||||
FileCodeReaderFactory readerFactory= FileCodeReaderFactory.getInstance();
|
||||
IScannerExtensionConfiguration scannerConfig;
|
||||
if (lang == ParserLanguage.C) {
|
||||
scannerConfig= GCCScannerExtensionConfiguration.getInstance();
|
||||
|
|
|
@ -14,13 +14,13 @@ import java.io.IOException;
|
|||
|
||||
import junit.framework.ComparisonFailure;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -55,23 +55,27 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
|
|||
}
|
||||
|
||||
protected void initializeScanner(String input, ParserMode mode) throws IOException {
|
||||
initializeScanner(new CodeReader(input.toCharArray()), ParserLanguage.CPP, mode, new ScannerInfo());
|
||||
initializeScanner(getContent(input), ParserLanguage.CPP, mode, new ScannerInfo());
|
||||
}
|
||||
|
||||
protected void initializeScanner(String input, ParserLanguage lang) throws IOException {
|
||||
initializeScanner(new CodeReader(input.toCharArray()), lang, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
||||
initializeScanner(getContent(input), lang, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
||||
}
|
||||
|
||||
protected void initializeScanner(String input, ParserLanguage lang, IScannerExtensionConfiguration scannerConfig) throws IOException {
|
||||
initializeScanner(new CodeReader(input.toCharArray()), lang, ParserMode.COMPLETE_PARSE, new ScannerInfo(), scannerConfig);
|
||||
initializeScanner(getContent(input), lang, ParserMode.COMPLETE_PARSE, new ScannerInfo(), scannerConfig);
|
||||
}
|
||||
|
||||
protected void initializeScanner(CodeReader input, ParserLanguage lang, ParserMode mode, IScannerInfo scannerInfo) throws IOException {
|
||||
private FileContent getContent(String input) {
|
||||
return FileContent.create("<test-code>", input.toCharArray());
|
||||
}
|
||||
|
||||
protected void initializeScanner(FileContent input, ParserLanguage lang, ParserMode mode, IScannerInfo scannerInfo) throws IOException {
|
||||
initializeScanner(input, lang, mode, scannerInfo, null);
|
||||
}
|
||||
|
||||
protected void initializeScanner(CodeReader input, ParserLanguage lang, ParserMode mode, IScannerInfo scannerInfo, IScannerExtensionConfiguration scannerConfig) throws IOException {
|
||||
ICodeReaderFactory readerFactory= FileCodeReaderFactory.getInstance();
|
||||
protected void initializeScanner(FileContent input, ParserLanguage lang, ParserMode mode, IScannerInfo scannerInfo, IScannerExtensionConfiguration scannerConfig) throws IOException {
|
||||
IncludeFileContentProvider readerFactory= FileCodeReaderFactory.getInstance();
|
||||
//IScannerExtensionConfiguration scannerConfig;
|
||||
|
||||
if(scannerConfig == null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,11 +12,15 @@
|
|||
package org.eclipse.cdt.core.model;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.CodeReaderAdapter;
|
||||
import org.eclipse.cdt.internal.core.parser.CodeReaderFactoryAdapter;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
|
@ -36,9 +40,40 @@ public abstract class AbstractLanguage extends PlatformObject implements ILangua
|
|||
return getId();
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log)
|
||||
/**
|
||||
* @deprecated replaced by {@link #getASTTranslationUnit(FileContent, IScannerInfo,
|
||||
* IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
*/
|
||||
@Deprecated
|
||||
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log)
|
||||
throws CoreException {
|
||||
// for backwards compatibility
|
||||
// For backwards compatibility, should be overridden.
|
||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, log);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.2
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public IASTTranslationUnit getASTTranslationUnit(FileContent content, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, int options, IParserLogService log)
|
||||
throws CoreException {
|
||||
// For backwards compatibility, should be overridden.
|
||||
return getASTTranslationUnit(CodeReaderAdapter.adapt(content), scanInfo, CodeReaderFactoryAdapter
|
||||
.adapt(fileCreator), index, options, log);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.2
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public IASTCompletionNode getCompletionNode(FileContent reader, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, IParserLogService log, int offset)
|
||||
throws CoreException {
|
||||
// For backwards compatibility, should be overridden.
|
||||
return getCompletionNode(CodeReaderAdapter.adapt(reader), scanInfo, CodeReaderFactoryAdapter
|
||||
.adapt(fileCreator), index, log, offset);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,10 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationListOwner;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
|
@ -36,7 +37,7 @@ import org.eclipse.core.runtime.IAdaptable;
|
|||
public interface ILanguage extends IAdaptable {
|
||||
|
||||
/**
|
||||
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
* Instructs the parser to skip function and method bodies.
|
||||
*/
|
||||
public final static int OPTION_SKIP_FUNCTION_BODIES= 0x1;
|
||||
|
@ -48,21 +49,21 @@ public interface ILanguage extends IAdaptable {
|
|||
public final static int OPTION_ADD_COMMENTS= 0x2;
|
||||
|
||||
/**
|
||||
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
* Performance optimization, allows the parser not to create image-locations.
|
||||
* When using this option {@link IASTName#getImageLocation()} will always return <code>null</code>.
|
||||
*/
|
||||
public final static int OPTION_NO_IMAGE_LOCATIONS= 0x4;
|
||||
|
||||
/**
|
||||
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
* Marks the ast as being based on a source-file rather than a header-file. This makes a difference
|
||||
* when bindings from the AST are used for searching the index, e.g. for static variables.
|
||||
*/
|
||||
public final static int OPTION_IS_SOURCE_UNIT= 0x8;
|
||||
|
||||
/**
|
||||
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
* Allows the parser not to create ast nodes for expressions within aggregate initializers
|
||||
* when they do not contain names.
|
||||
* @since 5.1
|
||||
|
@ -70,7 +71,7 @@ public interface ILanguage extends IAdaptable {
|
|||
public final static int OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS= 0x10;
|
||||
|
||||
/**
|
||||
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
* Instructs the parser to create ast nodes for inactive code branches, if possible. The parser
|
||||
* makes its best effort to create ast for the inactive code branches but may decide to skip parts
|
||||
* of the inactive code (e.g. function bodies, entire code branches, etc.).
|
||||
|
@ -103,19 +104,33 @@ public interface ILanguage extends IAdaptable {
|
|||
public String getName();
|
||||
|
||||
/**
|
||||
* Return the AST completion node for the given offset.
|
||||
* Construct an AST for the source code provided by <code>reader</code>.
|
||||
* As an option you can supply
|
||||
* @param content source code to be parsed.
|
||||
* @param scanInfo provides include paths and defined symbols.
|
||||
* @param fileCreator factory that provides file content for files included
|
||||
* @param index (optional) index to use to lookup symbols external to the tu.
|
||||
* @param options A combination of
|
||||
* {@link #OPTION_SKIP_FUNCTION_BODIES},
|
||||
* {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT},
|
||||
* or <code>0</code>.
|
||||
* @param log logger
|
||||
* @return an AST for the source code provided by reader.
|
||||
* @throws CoreException
|
||||
* @since 5.2
|
||||
*/
|
||||
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException;
|
||||
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(FileContent content, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, int options, IParserLogService log)
|
||||
throws CoreException;
|
||||
|
||||
/**
|
||||
* Gather the list of IASTNames that appear the selection with the given start offset
|
||||
* and length in the given ITranslationUnit.
|
||||
* @deprecated use {@link IASTTranslationUnit#getNodeSelector(String)}, instead.
|
||||
* Return the AST completion node for the given offset.
|
||||
* @since 5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length);
|
||||
public IASTCompletionNode getCompletionNode(FileContent reader, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, IParserLogService log, int offset)
|
||||
throws CoreException;
|
||||
|
||||
|
||||
/**
|
||||
* Used to override the default model building behavior for a translation unit.
|
||||
|
@ -127,43 +142,34 @@ public interface ILanguage extends IAdaptable {
|
|||
*/
|
||||
public IContributedModelBuilder createModelBuilder(ITranslationUnit tu);
|
||||
|
||||
/**
|
||||
* Construct an AST for the source code provided by <code>reader</code>.
|
||||
* Fully equivalent to
|
||||
* <code> getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log) </code>
|
||||
* @param reader source code to be parsed.
|
||||
* @param scanInfo provides include paths and defined symbols.
|
||||
* @param fileCreator factory that provides CodeReaders for files included
|
||||
* by the source code being parsed.
|
||||
* @param index (optional) index to use to provide support for ambiguity
|
||||
* resolution.
|
||||
* @param log logger
|
||||
* @return an AST for the source code provided by reader.
|
||||
* @throws CoreException
|
||||
*/
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log)
|
||||
throws CoreException;
|
||||
|
||||
/**
|
||||
* Construct an AST for the source code provided by <code>reader</code>.
|
||||
* As an option you can supply
|
||||
* @param reader source code to be parsed.
|
||||
* @param scanInfo provides include paths and defined symbols.
|
||||
* @param fileCreator factory that provides CodeReaders for files included
|
||||
* by the source code being parsed.
|
||||
* @param index (optional) index to use to provide support for ambiguity
|
||||
* resolution.
|
||||
* @param options A combination of
|
||||
* {@link #OPTION_SKIP_FUNCTION_BODIES},
|
||||
* {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT},
|
||||
* or <code>0</code>.
|
||||
* @param log logger
|
||||
* @return an AST for the source code provided by reader.
|
||||
* @throws CoreException
|
||||
* @deprecated replaced by {@link IASTTranslationUnit#getNodeSelector(String)}.
|
||||
*/
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log)
|
||||
@Deprecated
|
||||
IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length);
|
||||
/**
|
||||
* @deprecated replaced by {@link #getASTTranslationUnit(FileContent, IScannerInfo,
|
||||
* IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
*/
|
||||
@Deprecated
|
||||
IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log)
|
||||
throws CoreException;
|
||||
|
||||
/**
|
||||
* @deprecated replaced by {@link #getASTTranslationUnit(FileContent, IScannerInfo,
|
||||
* IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
*/
|
||||
@Deprecated
|
||||
IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, int options,
|
||||
IParserLogService log) throws CoreException;
|
||||
/**
|
||||
* @deprecated replaced by {@link #getCompletionNode(FileContent, IScannerInfo,
|
||||
* IncludeFileContentProvider, IIndex, IParserLogService, int)}.
|
||||
*/
|
||||
@Deprecated
|
||||
IASTCompletionNode getCompletionNode(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log,
|
||||
int offset) throws CoreException;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationListOwner;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -414,14 +414,6 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
|||
*/
|
||||
public IPath getLocation();
|
||||
|
||||
/**
|
||||
* Returns the code reader that can be used to parse the translation unit. If the translation unit is a
|
||||
* working copy the reader will read from the buffer.
|
||||
* @return a code reader for parsing the translation unit
|
||||
* @since 4.0
|
||||
*/
|
||||
public CodeReader getCodeReader();
|
||||
|
||||
/**
|
||||
* Returns the scanner info associated with this translation unit. May return <code>null</code> if no
|
||||
* configuration is available.
|
||||
|
@ -488,4 +480,11 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
|||
* @deprecated don't use this method.
|
||||
*/
|
||||
@Deprecated Map<?,?> parse();
|
||||
/**
|
||||
* @deprecated, use {@link FileContent#create(ITranslationUnit)}, instead.
|
||||
*/
|
||||
@Deprecated
|
||||
org.eclipse.cdt.core.parser.CodeReader getCodeReader();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -56,20 +56,19 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
|||
import org.eclipse.cdt.core.model.IUsing;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.NullCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserLogService;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerIncludeResolutionHeuristics;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
|
||||
import org.eclipse.cdt.internal.core.util.ICanceler;
|
||||
|
@ -770,14 +769,12 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return null;
|
||||
}
|
||||
|
||||
CodeReader reader;
|
||||
reader = getCodeReader();
|
||||
|
||||
if (reader != null) {
|
||||
FileContent fileContent= FileContent.create(this);
|
||||
if (fileContent != null) {
|
||||
ILanguage language= configureWith.getLanguage();
|
||||
fLanguageOfContext= language;
|
||||
if (language != null) {
|
||||
AbstractCodeReaderFactory crf= getCodeReaderFactory(style, index, language.getLinkageID());
|
||||
IncludeFileContentProvider crf= getIncludeFileContentProvider(style, index, language.getLinkageID());
|
||||
int options= 0;
|
||||
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
|
||||
options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
|
||||
|
@ -797,34 +794,36 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
} else {
|
||||
log= ParserUtil.getParserLogService();
|
||||
}
|
||||
return ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, crf, index, options, log);
|
||||
return ((AbstractLanguage)language).getASTTranslationUnit(fileContent, scanInfo, crf, index, options, log);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private AbstractCodeReaderFactory getCodeReaderFactory(int style, IIndex index, int linkageID) {
|
||||
private IncludeFileContentProvider getIncludeFileContentProvider(int style, IIndex index, int linkageID) {
|
||||
final ICProject cprj= getCProject();
|
||||
final ProjectIndexerInputAdapter pathResolver = new ProjectIndexerInputAdapter(cprj);
|
||||
final ProjectIndexerIncludeResolutionHeuristics heuristics = new ProjectIndexerIncludeResolutionHeuristics(cprj.getProject(), pathResolver);
|
||||
AbstractCodeReaderFactory codeReaderFactory;
|
||||
IncludeFileContentProvider fileContentsProvider;
|
||||
if ((style & AST_SKIP_NONINDEXED_HEADERS) != 0) {
|
||||
codeReaderFactory= NullCodeReaderFactory.getInstance();
|
||||
fileContentsProvider= IncludeFileContentProvider.getEmptyFilesProvider();
|
||||
} else {
|
||||
codeReaderFactory= SavedCodeReaderFactory.createInstance(heuristics);
|
||||
fileContentsProvider= IncludeFileContentProvider.getSavedFilesProvider();
|
||||
}
|
||||
|
||||
if (index != null && (style & AST_SKIP_INDEXED_HEADERS) != 0) {
|
||||
IndexBasedCodeReaderFactory ibcf= new IndexBasedCodeReaderFactory(index,
|
||||
heuristics,
|
||||
pathResolver, linkageID, codeReaderFactory);
|
||||
IndexBasedFileContentProvider ibcf= new IndexBasedFileContentProvider(index, pathResolver, linkageID, fileContentsProvider);
|
||||
if ((style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) {
|
||||
ibcf.setSupportFillGapFromContextToHeader(true);
|
||||
}
|
||||
codeReaderFactory= ibcf;
|
||||
fileContentsProvider= ibcf;
|
||||
}
|
||||
|
||||
return codeReaderFactory;
|
||||
|
||||
if (fileContentsProvider instanceof InternalFileContentProvider) {
|
||||
final ProjectIndexerIncludeResolutionHeuristics heuristics = new ProjectIndexerIncludeResolutionHeuristics(cprj.getProject(), pathResolver);
|
||||
((InternalFileContentProvider) fileContentsProvider).setIncludeResolutionHeuristics(heuristics);
|
||||
}
|
||||
|
||||
return fileContentsProvider;
|
||||
}
|
||||
|
||||
private static int[] CTX_LINKAGES= {ILinkage.CPP_LINKAGE_ID, ILinkage.C_LINKAGE_ID};
|
||||
|
@ -880,24 +879,24 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return null;
|
||||
}
|
||||
|
||||
CodeReader reader;
|
||||
reader = getCodeReader();
|
||||
FileContent fileContent= FileContent.create(this);
|
||||
|
||||
ILanguage language= configureWith.getLanguage();
|
||||
fLanguageOfContext= language;
|
||||
if (language != null) {
|
||||
AbstractCodeReaderFactory crf= getCodeReaderFactory(style, index, language.getLinkageID());
|
||||
return language.getCompletionNode(reader, scanInfo, crf, index, ParserUtil.getParserLogService(), offset);
|
||||
IncludeFileContentProvider crf= getIncludeFileContentProvider(style, index, language.getLinkageID());
|
||||
return language.getCompletionNode(fileContent, scanInfo, crf, index, ParserUtil.getParserLogService(), offset);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CodeReader getCodeReader() {
|
||||
@Deprecated
|
||||
public org.eclipse.cdt.core.parser.CodeReader getCodeReader() {
|
||||
IPath location= getLocation();
|
||||
if (location == null)
|
||||
return new CodeReader(getContents());
|
||||
return new org.eclipse.cdt.core.parser.CodeReader(getContents());
|
||||
if (isWorkingCopy()) {
|
||||
return new CodeReader(location.toOSString(), getContents());
|
||||
return new org.eclipse.cdt.core.parser.CodeReader(location.toOSString(), getContents());
|
||||
}
|
||||
|
||||
IResource res= getResource();
|
||||
|
|
|
@ -27,10 +27,11 @@ import org.eclipse.cdt.core.model.AbstractLanguage;
|
|||
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
||||
import org.eclipse.cdt.core.model.IContributedModelBuilder;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||
|
@ -101,24 +102,32 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
|||
protected abstract ParserLanguage getParserLanguage();
|
||||
|
||||
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException {
|
||||
@Deprecated
|
||||
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log)
|
||||
throws CoreException {
|
||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
|
||||
}
|
||||
|
||||
@Override @Deprecated
|
||||
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory codeReaderFactory, IIndex index, int options,
|
||||
IParserLogService log) throws CoreException {
|
||||
return getASTTranslationUnit(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider
|
||||
.adapt(codeReaderFactory), index, options, log);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException {
|
||||
|
||||
final IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log);
|
||||
public IASTTranslationUnit getASTTranslationUnit(FileContent reader, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, int options, IParserLogService log)
|
||||
throws CoreException {
|
||||
final IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
|
||||
scanner.setComputeImageLocations((options & OPTION_NO_IMAGE_LOCATIONS) == 0);
|
||||
scanner.setProcessInactiveCode((options & OPTION_PARSE_INACTIVE_CODE) != 0);
|
||||
|
||||
final ISourceCodeParser parser= createParser(scanner, log, index, false, options);
|
||||
|
||||
// make parser cancelable by reconciler - http://bugs.eclipse.org/226682
|
||||
// make it possible to cancel parser by reconciler - http://bugs.eclipse.org/226682
|
||||
ICanceler canceler= null;
|
||||
if (log instanceof ICanceler) {
|
||||
canceler= (ICanceler) log;
|
||||
|
@ -140,10 +149,18 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
|
||||
@Deprecated
|
||||
public IASTCompletionNode getCompletionNode(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log,
|
||||
int offset) throws CoreException {
|
||||
return getCompletionNode(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider
|
||||
.adapt(fileCreator), index, log, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTCompletionNode getCompletionNode(FileContent reader, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
|
||||
|
||||
IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
|
||||
scanner.setContentAssistMode(offset);
|
||||
|
@ -164,7 +181,7 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
|||
* @param log the parser log service
|
||||
* @param index the index to help resolve bindings
|
||||
* @param forCompletion whether the parser is used for code completion
|
||||
* @param options for valid options see {@link AbstractLanguage#getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* @param options for valid options see {@link AbstractLanguage#getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)}
|
||||
* @return an instance of ISourceCodeParser
|
||||
*/
|
||||
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) {
|
||||
|
@ -187,20 +204,25 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
|||
|
||||
|
||||
/**
|
||||
* Create the scanner to be used with the parser.
|
||||
*
|
||||
* @param reader the code reader for the main file
|
||||
* @param scanInfo the scanner information (macros, include pathes)
|
||||
* @param fileCreator the code reader factory for inclusions
|
||||
* @param log the log for debugging
|
||||
* @return an instance of IScanner
|
||||
* @deprecated replaced by {@link #createScanner(FileContent, IScannerInfo, IncludeFileContentProvider, IParserLogService)}
|
||||
*/
|
||||
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
|
||||
return new CPreprocessor(reader, scanInfo, getParserLanguage(), log, getScannerExtensionConfiguration(), fileCreator);
|
||||
@Deprecated
|
||||
protected IScanner createScanner(org.eclipse.cdt.core.parser.CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IParserLogService log) {
|
||||
return createScanner(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider
|
||||
.adapt(fileCreator), log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the scanner to be used with the parser.
|
||||
* @since 5.2
|
||||
*/
|
||||
protected final IScanner createScanner(FileContent content, IScannerInfo scanInfo, IncludeFileContentProvider fcp, IParserLogService log) {
|
||||
return new CPreprocessor(content, scanInfo, getParserLanguage(), log, getScannerExtensionConfiguration(), fcp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Deprecated
|
||||
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
|
||||
IASTNode selectedNode= ast.getNodeSelector(null).findNode(start, length);
|
||||
|
||||
|
|
|
@ -30,7 +30,9 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
* Reads the content of a file into a char[] buffer.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @deprecated replaced by {@link FileContent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class CodeReader {
|
||||
public static final String SYSTEM_DEFAULT_ENCODING = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.CharArray;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for representing the content of a file. This serves as the
|
||||
* input to the preprocessor.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @since 5.2
|
||||
*/
|
||||
public abstract class FileContent {
|
||||
|
||||
/**
|
||||
* Returns the location of this file content as it will appear in {@link IASTFileLocation#getFileName()}
|
||||
*/
|
||||
public abstract String getFileLocation();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a file content object for a fixed buffer.
|
||||
* @param filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()}
|
||||
* @param contents the actual content.
|
||||
*/
|
||||
public static FileContent create(String filePath, char[] contents) {
|
||||
return new InternalFileContent(filePath, new CharArray(contents));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file content object for a translation-unit, which may be a working copy.
|
||||
*/
|
||||
public static FileContent create(ITranslationUnit tu) {
|
||||
IPath location= tu.getLocation();
|
||||
if (location == null)
|
||||
return create(tu.getElementName(), tu.getContents());
|
||||
|
||||
if (tu.isWorkingCopy()) {
|
||||
return create(location.toOSString(), tu.getContents());
|
||||
}
|
||||
|
||||
IResource res= tu.getResource();
|
||||
if (res instanceof IFile) {
|
||||
return create((IFile) res);
|
||||
}
|
||||
return createForExternalFileLocation(location.toOSString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file content object for an index file location.
|
||||
*/
|
||||
public static FileContent create(IIndexFileLocation ifl) {
|
||||
return InternalParserUtil.createFileContent(ifl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file content for a workspace file
|
||||
*/
|
||||
public static FileContent create(IFile file) {
|
||||
return InternalParserUtil.createWorkspaceFileContent(file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a file content object for a file location that is not part of the workspace
|
||||
*/
|
||||
public static FileContent createForExternalFileLocation(String fileLocation) {
|
||||
return InternalParserUtil.createExternalFileContent(fileLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided to achieve backwards compatibility.
|
||||
*/
|
||||
@Deprecated
|
||||
public static FileContent adapt(CodeReader reader) {
|
||||
if (reader == null)
|
||||
return null;
|
||||
return create(reader.getPath(), reader.buffer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.EmptyFilesProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.FileContentProviderAdapter;
|
||||
import org.eclipse.cdt.internal.core.parser.SavedFilesProvider;
|
||||
|
||||
|
||||
/**
|
||||
* A file content provider is used to create file content objects for include
|
||||
* directives.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @since 5.2
|
||||
*/
|
||||
public abstract class IncludeFileContentProvider {
|
||||
|
||||
/**
|
||||
* Returns a provider that pretends that every include file is empty.
|
||||
*/
|
||||
public static IncludeFileContentProvider getEmptyFilesProvider() {
|
||||
return EmptyFilesProvider.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a provider for the content as saved in the file-system,
|
||||
* without using a cache.
|
||||
*/
|
||||
public static IncludeFileContentProvider getSavedFilesProvider() {
|
||||
return SavedFilesProvider.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Provided to achieve backwards compatibility.
|
||||
*/
|
||||
@Deprecated
|
||||
public static IncludeFileContentProvider adapt(ICodeReaderFactory factory) {
|
||||
return FileContentProviderAdapter.adapt(factory);
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
|
|||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -341,7 +341,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
||||
*/
|
||||
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
||||
public void skippedFile(int offset, InternalFileContent fileContent) {
|
||||
if (fIndexFileSet != null) {
|
||||
List<IIndexFile> files= fileContent.getFilesIncluded();
|
||||
for (IIndexFile indexFile : files) {
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
|
||||
/**
|
||||
* C++-specific implementation of a translation-unit.
|
||||
|
@ -146,7 +146,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
|
|||
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
||||
*/
|
||||
@Override
|
||||
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
||||
public void skippedFile(int offset, InternalFileContent fileContent) {
|
||||
super.skippedFile(offset, fileContent);
|
||||
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
@ -28,25 +27,20 @@ import org.eclipse.cdt.core.index.IIndexFile;
|
|||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IIndexBasedCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent.InclusionKind;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent.InclusionKind;
|
||||
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
|
||||
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
|
||||
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.FileContent;
|
||||
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.IndexFileContent;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Code reader factory, that fakes code readers for header files already stored in the
|
||||
* index.
|
||||
*/
|
||||
public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory implements IIndexBasedCodeReaderFactory {
|
||||
public final class IndexBasedFileContentProvider extends InternalFileContentProvider {
|
||||
private static final class NeedToParseException extends Exception {}
|
||||
private static final String GAP = "__gap__"; //$NON-NLS-1$
|
||||
|
||||
|
@ -54,22 +48,20 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
private int fLinkage;
|
||||
private Set<IIndexFileLocation> fIncludedFiles= new HashSet<IIndexFileLocation>();
|
||||
/** The fall-back code reader factory used in case a header file is not indexed */
|
||||
private final AbstractCodeReaderFactory fFallBackFactory;
|
||||
private final InternalFileContentProvider fFallBackFactory;
|
||||
private final ASTFilePathResolver fPathResolver;
|
||||
private final AbstractIndexerTask fRelatedIndexerTask;
|
||||
private boolean fSupportFillGapFromContextToHeader= false;
|
||||
|
||||
public IndexBasedCodeReaderFactory(IIndex index, IIncludeFileResolutionHeuristics heuristics,
|
||||
ASTFilePathResolver pathResolver, int linkage, AbstractCodeReaderFactory fallbackFactory) {
|
||||
this(index, heuristics, pathResolver, linkage, fallbackFactory, null);
|
||||
public IndexBasedFileContentProvider(IIndex index,
|
||||
ASTFilePathResolver pathResolver, int linkage, IncludeFileContentProvider fallbackFactory) {
|
||||
this(index, pathResolver, linkage, fallbackFactory, null);
|
||||
}
|
||||
|
||||
public IndexBasedCodeReaderFactory(IIndex index, IIncludeFileResolutionHeuristics heuristics,
|
||||
ASTFilePathResolver pathResolver, int linkage,
|
||||
AbstractCodeReaderFactory fallbackFactory, AbstractIndexerTask relatedIndexerTask) {
|
||||
super(heuristics);
|
||||
public IndexBasedFileContentProvider(IIndex index, ASTFilePathResolver pathResolver, int linkage,
|
||||
IncludeFileContentProvider fallbackFactory, AbstractIndexerTask relatedIndexerTask) {
|
||||
fIndex= index;
|
||||
fFallBackFactory= fallbackFactory;
|
||||
fFallBackFactory= (InternalFileContentProvider) fallbackFactory;
|
||||
fPathResolver= pathResolver;
|
||||
fRelatedIndexerTask= relatedIndexerTask;
|
||||
fLinkage= linkage;
|
||||
|
@ -87,52 +79,25 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
fIncludedFiles.clear();
|
||||
}
|
||||
|
||||
public int getUniqueIdentifier() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ICodeReaderCache getCodeReaderCache() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||
if (fFallBackFactory != null) {
|
||||
return fFallBackFactory.createCodeReaderForTranslationUnit(path);
|
||||
}
|
||||
return ParserUtil.createReader(path, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeReader createCodeReaderForInclusion(IIndexFileLocation ifl, String astPath) throws CoreException, IOException {
|
||||
if (fFallBackFactory != null) {
|
||||
return fFallBackFactory.createCodeReaderForInclusion(ifl, astPath);
|
||||
}
|
||||
return InternalParserUtil.createCodeReader(ifl, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
if (fFallBackFactory != null) {
|
||||
return fFallBackFactory.createCodeReaderForInclusion(path);
|
||||
}
|
||||
return ParserUtil.createReader(path, null);
|
||||
}
|
||||
|
||||
public boolean getInclusionExists(String path) {
|
||||
return fPathResolver.doesIncludeFileExist(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportTranslationUnitFile(String path) {
|
||||
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
||||
fIncludedFiles.add(ifl);
|
||||
}
|
||||
|
||||
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||
@Override
|
||||
public Boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
||||
return fIncludedFiles.contains(ifl);
|
||||
}
|
||||
|
||||
public IncludeFileContent getContentForInclusion(String path) {
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(String path) {
|
||||
IIndexFileLocation ifl= fPathResolver.resolveIncludeFile(path);
|
||||
if (ifl == null) {
|
||||
return null;
|
||||
|
@ -141,7 +106,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
|
||||
// include files once, only.
|
||||
if (!fIncludedFiles.add(ifl)) {
|
||||
return new IncludeFileContent(path, InclusionKind.SKIP_FILE);
|
||||
return new InternalFileContent(path, InclusionKind.SKIP_FILE);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -155,7 +120,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
collectFileContent(file, ifls, files, macros, directives, false);
|
||||
// add included files only, if no exception was thrown
|
||||
fIncludedFiles.addAll(ifls);
|
||||
return new IncludeFileContent(path, macros, directives, files);
|
||||
return new InternalFileContent(path, macros, directives, files);
|
||||
} catch (NeedToParseException e) {
|
||||
}
|
||||
}
|
||||
|
@ -164,21 +129,22 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
CCorePlugin.log(e);
|
||||
}
|
||||
|
||||
try {
|
||||
CodeReader codeReader= createCodeReaderForInclusion(ifl, path);
|
||||
if (codeReader != null) {
|
||||
IncludeFileContent ifc= new IncludeFileContent(codeReader);
|
||||
if (fFallBackFactory != null) {
|
||||
InternalFileContent ifc= getContentForInclusion(ifl, path);
|
||||
if (ifc != null)
|
||||
ifc.setIsSource(fPathResolver.isSource(path));
|
||||
return ifc;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
} catch (IOException e) {
|
||||
CCorePlugin.log(e);
|
||||
return ifc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(IIndexFileLocation ifl, String astPath) {
|
||||
if (fFallBackFactory != null) {
|
||||
return fFallBackFactory.getContentForInclusion(ifl, astPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void collectFileContent(IIndexFile file, Set<IIndexFileLocation> ifls, List<IIndexFile> files,
|
||||
List<IIndexMacro> macros, List<ICPPUsingDirective> usingDirectives, boolean checkIncluded)
|
||||
|
@ -187,14 +153,14 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
if (!ifls.add(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) {
|
||||
return;
|
||||
}
|
||||
FileContent content;
|
||||
IndexFileContent content;
|
||||
if (fRelatedIndexerTask != null) {
|
||||
content= fRelatedIndexerTask.getFileContent(fLinkage, ifl);
|
||||
if (content == null) {
|
||||
throw new NeedToParseException();
|
||||
}
|
||||
} else {
|
||||
content= new FileContent();
|
||||
content= new IndexFileContent();
|
||||
content.setPreprocessorDirectives(file.getIncludes(), file.getMacros());
|
||||
content.setUsingDirectives(file.getUsingDirectives());
|
||||
}
|
||||
|
@ -214,7 +180,8 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
}
|
||||
}
|
||||
|
||||
public IncludeFileContent getContentForContextToHeaderGap(String path) {
|
||||
@Override
|
||||
public InternalFileContent getContentForContextToHeaderGap(String path) {
|
||||
if (!fSupportFillGapFromContextToHeader) {
|
||||
return null;
|
||||
}
|
||||
|
@ -246,7 +213,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
for (IIndexFile file : filesIncluded) {
|
||||
fIncludedFiles.add(file.getLocation());
|
||||
}
|
||||
return new IncludeFileContent(GAP, macros, directives, new ArrayList<IIndexFile>(filesIncluded));
|
||||
return new InternalFileContent(GAP, macros, directives, new ArrayList<IIndexFile>(filesIncluded));
|
||||
}
|
||||
catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
|
@ -284,7 +251,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
|||
|
||||
final IIndexInclude[] ids= from.getIncludes();
|
||||
final IIndexMacro[] ms= from.getMacros();
|
||||
final Object[] dirs= FileContent.merge(ids, ms);
|
||||
final Object[] dirs= IndexFileContent.merge(ids, ms);
|
||||
IIndexInclude success= null;
|
||||
for (Object d : dirs) {
|
||||
if (d instanceof IIndexMacro) {
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 QNX Software Systems and others.
|
||||
* Copyright (c) 2006, 2009 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.indexer;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
|
||||
/**
|
||||
|
@ -36,8 +36,8 @@ public class StandaloneFastIndexerTask extends StandaloneIndexerTask {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
||||
return new StandaloneIndexerFallbackReaderFactory();
|
||||
protected IncludeFileContentProvider createReaderFactory() {
|
||||
return IncludeFileContentProvider.adapt(new StandaloneIndexerFallbackReaderFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 QNX Software Systems and others.
|
||||
* Copyright (c) 2006, 2009 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.indexer;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
|
||||
/**
|
||||
|
@ -37,8 +37,8 @@ public class StandaloneFullIndexerTask extends StandaloneIndexerTask {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
||||
return ((StandaloneFullIndexer)fIndexer).getCodeReaderFactory();
|
||||
protected IncludeFileContentProvider createReaderFactory() {
|
||||
return IncludeFileContentProvider.adapt(((StandaloneFullIndexer)fIndexer).getCodeReaderFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.HashMap;
|
|||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
|
||||
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
|
||||
|
@ -123,12 +123,8 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CodeReader getCodeReader(Object tu) {
|
||||
try {
|
||||
return new CodeReader((String) tu);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return null;
|
||||
public FileContent getCodeReader(Object tu) {
|
||||
return FileContent.createForExternalFileLocation((String) tu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.AbstractCharArray;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.CharArray;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
|
||||
public abstract class CodeReaderAdapter {
|
||||
/**
|
||||
* @deprecated avoid using the adapter, its for backwards compatibility, only.
|
||||
*/
|
||||
@Deprecated
|
||||
public static org.eclipse.cdt.core.parser.CodeReader adapt(FileContent content) {
|
||||
if (content == null)
|
||||
return null;
|
||||
return new org.eclipse.cdt.core.parser.CodeReader(content.getFileLocation(), extractBuffer(content));
|
||||
}
|
||||
|
||||
private static char[] extractBuffer(FileContent content) {
|
||||
if (!(content instanceof InternalFileContent)) {
|
||||
throw new IllegalArgumentException("Invalid file content object!"); //$NON-NLS-1$
|
||||
}
|
||||
AbstractCharArray source= ((InternalFileContent) content).getSource();
|
||||
if (source instanceof CharArray) {
|
||||
return ((CharArray)source).getArray();
|
||||
}
|
||||
int len= source.tryGetLength();
|
||||
if (len < 0) {
|
||||
len=0;
|
||||
while (source.isValidOffset(len))
|
||||
len++;
|
||||
}
|
||||
char[] result= new char[len];
|
||||
source.arraycopy(0, result, 0, len);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class CodeReaderFactoryAdapter extends AbstractCodeReaderFactory {
|
||||
|
||||
/**
|
||||
* @deprecated avoid using the adapter, its for backwards compatibility, only.
|
||||
*/
|
||||
@Deprecated
|
||||
public static ICodeReaderFactory adapt(IncludeFileContentProvider fileCreator) {
|
||||
if (fileCreator == null)
|
||||
return null;
|
||||
|
||||
if (!(fileCreator instanceof InternalFileContentProvider))
|
||||
throw new IllegalArgumentException("Invalid file content provider"); //$NON-NLS-1$
|
||||
|
||||
if (fileCreator instanceof FileContentProviderAdapter) {
|
||||
return ((FileContentProviderAdapter) fileCreator).getCodeReaderFactory();
|
||||
}
|
||||
return new CodeReaderFactoryAdapter((InternalFileContentProvider) fileCreator);
|
||||
}
|
||||
|
||||
private InternalFileContentProvider fDelegate;
|
||||
private CodeReaderFactoryAdapter(InternalFileContentProvider fcp) {
|
||||
super(fcp.getIncludeHeuristics());
|
||||
fDelegate= fcp;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public org.eclipse.cdt.core.parser.CodeReader createCodeReaderForInclusion(String path) {
|
||||
return CodeReaderAdapter.adapt(fDelegate.getContentForInclusion(path));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public org.eclipse.cdt.core.parser.CodeReader createCodeReaderForInclusion(IIndexFileLocation ifl, String astPath)
|
||||
throws CoreException, IOException {
|
||||
return CodeReaderAdapter.adapt(fDelegate.getContentForInclusion(ifl, astPath));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public org.eclipse.cdt.core.parser.CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||
return CodeReaderAdapter.adapt(fDelegate.getContentForInclusion(path));
|
||||
}
|
||||
|
||||
public ICodeReaderCache getCodeReaderCache() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getUniqueIdentifier() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public InternalFileContentProvider getFileContentProvider() {
|
||||
return fDelegate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
|
||||
public class EmptyFilesProvider extends InternalFileContentProvider {
|
||||
final private static EmptyFilesProvider INSTANCE= new EmptyFilesProvider();
|
||||
|
||||
public static InternalFileContentProvider getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private EmptyFilesProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(String path) {
|
||||
if (!getInclusionExists(path))
|
||||
return null;
|
||||
|
||||
return (InternalFileContent) FileContent.create(path, CharArrayUtils.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(IIndexFileLocation ifl, String astPath) {
|
||||
return (InternalFileContent) FileContent.create(astPath, CharArrayUtils.EMPTY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class FileContentProviderAdapter extends InternalFileContentProvider {
|
||||
|
||||
/**
|
||||
* @deprecated avoid using the adapter, its for backwards compatibility, only.
|
||||
*/
|
||||
@Deprecated
|
||||
public static InternalFileContentProvider adapt(ICodeReaderFactory fileCreator) {
|
||||
if (fileCreator == null)
|
||||
return null;
|
||||
|
||||
if (!(fileCreator instanceof AbstractCodeReaderFactory))
|
||||
throw new IllegalArgumentException("Invalid code reader factory"); //$NON-NLS-1$
|
||||
|
||||
if (fileCreator instanceof CodeReaderFactoryAdapter) {
|
||||
return ((CodeReaderFactoryAdapter) fileCreator).getFileContentProvider();
|
||||
}
|
||||
return new FileContentProviderAdapter((AbstractCodeReaderFactory) fileCreator);
|
||||
}
|
||||
|
||||
private AbstractCodeReaderFactory fDelegate;
|
||||
private FileContentProviderAdapter(AbstractCodeReaderFactory factory) {
|
||||
fDelegate= factory;
|
||||
setIncludeResolutionHeuristics((IIncludeFileResolutionHeuristics) factory.getAdapter(IIncludeFileResolutionHeuristics.class));
|
||||
}
|
||||
|
||||
public ICodeReaderFactory getCodeReaderFactory() {
|
||||
return fDelegate;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(String path) {
|
||||
return (InternalFileContent) FileContent.adapt(fDelegate.createCodeReaderForInclusion(path));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(IIndexFileLocation ifl, String astPath) {
|
||||
try {
|
||||
return (InternalFileContent) FileContent.adapt(fDelegate.createCodeReaderForInclusion(ifl, astPath));
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
} catch (IOException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,12 +12,16 @@
|
|||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.CharArray;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.cdt.internal.core.resources.PathCanonicalizationStrategy;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -31,6 +35,7 @@ import org.eclipse.core.runtime.Path;
|
|||
* Utility for creating code readers
|
||||
*/
|
||||
public class InternalParserUtil extends ParserFactory {
|
||||
private static final String SYSTEM_DEFAULT_ENCODING = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Normalizes the path by using the location of the file, if possible.
|
||||
|
@ -46,8 +51,10 @@ public class InternalParserUtil extends ParserFactory {
|
|||
/**
|
||||
* Creates a code reader for an external location, normalizing path to
|
||||
* canonical path. The cache is consulted after the path has been normalized.
|
||||
* @deprecated, use {@link FileContent}, instead.
|
||||
*/
|
||||
public static CodeReader createExternalFileReader(String externalLocation, CodeReaderLRUCache cache) throws IOException {
|
||||
@Deprecated
|
||||
public static org.eclipse.cdt.core.parser.CodeReader createExternalFileReader(String externalLocation, CodeReaderLRUCache cache) throws IOException {
|
||||
File includeFile = new File(externalLocation);
|
||||
if (includeFile.isFile()) {
|
||||
// Use the canonical path so that in case of non-case-sensitive OSs
|
||||
|
@ -55,12 +62,12 @@ public class InternalParserUtil extends ParserFactory {
|
|||
// no differences in case.
|
||||
final String path = PathCanonicalizationStrategy.getCanonicalPath(includeFile);
|
||||
if (cache != null) {
|
||||
CodeReader result= cache.get(path);
|
||||
org.eclipse.cdt.core.parser.CodeReader result= cache.get(path);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
|
||||
return new CodeReader(path);
|
||||
return new org.eclipse.cdt.core.parser.CodeReader(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -68,11 +75,13 @@ public class InternalParserUtil extends ParserFactory {
|
|||
/**
|
||||
* Creates a code reader for an external location, normalizing path to
|
||||
* canonical path.
|
||||
* @deprecated, use {@link FileContent}, instead.
|
||||
*/
|
||||
public static CodeReader createWorkspaceFileReader(String path, IFile file, CodeReaderLRUCache cache) throws CoreException, IOException{
|
||||
@Deprecated
|
||||
public static org.eclipse.cdt.core.parser.CodeReader createWorkspaceFileReader(String path, IFile file, CodeReaderLRUCache cache) throws CoreException, IOException{
|
||||
path = normalizePath(path, file);
|
||||
if (cache != null) {
|
||||
CodeReader result= cache.get(path);
|
||||
org.eclipse.cdt.core.parser.CodeReader result= cache.get(path);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
|
@ -91,7 +100,7 @@ public class InternalParserUtil extends ParserFactory {
|
|||
throw e;
|
||||
}
|
||||
try {
|
||||
return new CodeReader(path, file.getCharset(), in);
|
||||
return new org.eclipse.cdt.core.parser.CodeReader(path, file.getCharset(), in);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
|
@ -100,7 +109,13 @@ public class InternalParserUtil extends ParserFactory {
|
|||
}
|
||||
}
|
||||
|
||||
public static CodeReader createCodeReader(IIndexFileLocation ifl, CodeReaderLRUCache cache) throws CoreException, IOException {
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated, use {@link FileContent}, instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static org.eclipse.cdt.core.parser.CodeReader createCodeReader(IIndexFileLocation ifl, CodeReaderLRUCache cache) throws CoreException, IOException {
|
||||
String fullPath= ifl.getFullPath();
|
||||
if (fullPath != null) {
|
||||
IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(fullPath));
|
||||
|
@ -109,4 +124,85 @@ public class InternalParserUtil extends ParserFactory {
|
|||
}
|
||||
return createExternalFileReader(ifl.getURI().getPath(), cache);
|
||||
}
|
||||
|
||||
public static InternalFileContent createFileContent(IIndexFileLocation ifl) {
|
||||
String fullPath= ifl.getFullPath();
|
||||
if (fullPath != null) {
|
||||
IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(fullPath));
|
||||
if (res instanceof IFile)
|
||||
return createWorkspaceFileContent((IFile) res);
|
||||
}
|
||||
return createExternalFileContent(ifl.getURI().getPath());
|
||||
}
|
||||
|
||||
public static InternalFileContent createWorkspaceFileContent(IFile file) {
|
||||
String path= file.getLocationURI().getPath();
|
||||
path= normalizePath(path, file);
|
||||
|
||||
InputStream in;
|
||||
try {
|
||||
in= file.getContents(true);
|
||||
try {
|
||||
return createFileContent(path, file.getCharset(), in);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
switch (e.getStatus().getCode()) {
|
||||
case IResourceStatus.NOT_FOUND_LOCAL:
|
||||
case IResourceStatus.NO_LOCATION_LOCAL:
|
||||
case IResourceStatus.FAILED_READ_LOCAL:
|
||||
case IResourceStatus.RESOURCE_NOT_LOCAL:
|
||||
break;
|
||||
default:
|
||||
CCorePlugin.log(e);
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a code reader for an external location, normalizing path to
|
||||
* canonical path.
|
||||
*/
|
||||
public static InternalFileContent createExternalFileContent(String externalLocation) {
|
||||
File includeFile = new File(externalLocation);
|
||||
if (includeFile.isFile()) {
|
||||
// Use the canonical path so that in case of non-case-sensitive OSs
|
||||
// the CodeReader always has the same name as the file on disk with
|
||||
// no differences in case.
|
||||
final String path = PathCanonicalizationStrategy.getCanonicalPath(includeFile);
|
||||
FileInputStream in;
|
||||
try {
|
||||
in = new FileInputStream(includeFile);
|
||||
} catch (IOException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return createFileContent(path, SYSTEM_DEFAULT_ENCODING, in);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static InternalFileContent createFileContent(String path, String charset, InputStream in) {
|
||||
try {
|
||||
// replace with a better implementation
|
||||
org.eclipse.cdt.core.parser.CodeReader reader= new org.eclipse.cdt.core.parser.CodeReader(path, charset, in);
|
||||
return new InternalFileContent(path, new CharArray(reader.buffer));
|
||||
} catch (IOException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
|
||||
public class SavedFilesProvider extends InternalFileContentProvider {
|
||||
final private static SavedFilesProvider INSTANCE= new SavedFilesProvider();
|
||||
|
||||
public static InternalFileContentProvider getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private SavedFilesProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(String path) {
|
||||
if (!getInclusionExists(path))
|
||||
return null;
|
||||
|
||||
IResource file = ParserUtil.getResourceForFilename(path);
|
||||
if (file instanceof IFile) {
|
||||
return (InternalFileContent) FileContent.create((IFile) file);
|
||||
}
|
||||
return (InternalFileContent) FileContent.createForExternalFileLocation(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalFileContent getContentForInclusion(IIndexFileLocation ifl, String astPath) {
|
||||
return (InternalFileContent) FileContent.create(ifl);
|
||||
}
|
||||
}
|
|
@ -12,21 +12,29 @@ package org.eclipse.cdt.internal.core.parser.scanner;
|
|||
|
||||
/**
|
||||
* Abstract class for providing input to the lexer.
|
||||
* @since 5.2
|
||||
*/
|
||||
public abstract class AbstractCharArray {
|
||||
|
||||
/**
|
||||
* Returns the length of this array or -1 if it is yet, unknown. This method may be called
|
||||
* before the array has been traversed.
|
||||
*/
|
||||
public abstract int tryGetLength();
|
||||
|
||||
/**
|
||||
* Returns the length of the array. This method is called only after the lexer has worked its
|
||||
* way through the array. Therefore for subclasses it is efficient enough to read through to the
|
||||
* end of the array and provide the length.
|
||||
*/
|
||||
public abstract int getLength();
|
||||
|
||||
/**
|
||||
* Checks whether the given offset is valid for this array. Subclasses may assume
|
||||
* that offset is non-negative.
|
||||
*/
|
||||
public abstract boolean isValidOffset(int offset);
|
||||
|
||||
/**
|
||||
* Returns the limit for valid offsets or -1 if it is unknown. All offsets below
|
||||
* the given limit are guaranteed to be valid.
|
||||
*/
|
||||
public abstract int getLimit();
|
||||
|
||||
/**
|
||||
* Returns the character at the given position, subclasses do not have to do range checks.
|
||||
*/
|
||||
|
|
|
@ -20,15 +20,13 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IMacro;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
|
@ -37,6 +35,7 @@ import org.eclipse.cdt.core.parser.IProblem;
|
|||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
|
@ -45,8 +44,9 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
|||
import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
import org.eclipse.cdt.internal.core.parser.EmptyFilesProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent.InclusionKind;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent.InclusionKind;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.MacroDefinitionParser.InvalidMacroDefinitionException;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerContext.BranchKind;
|
||||
|
@ -98,9 +98,9 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
T checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath);
|
||||
}
|
||||
|
||||
final private IIncludeFileTester<IncludeFileContent> createCodeReaderTester= new IIncludeFileTester<IncludeFileContent>() {
|
||||
public IncludeFileContent checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
|
||||
final IncludeFileContent fc= fCodeReaderFactory.getContentForInclusion(path);
|
||||
final private IIncludeFileTester<InternalFileContent> createCodeReaderTester= new IIncludeFileTester<InternalFileContent>() {
|
||||
public InternalFileContent checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
|
||||
final InternalFileContent fc= fFileContentProvider.getContentForInclusion(path);
|
||||
if (fc != null) {
|
||||
fc.setFoundByHeuristics(isHeuristicMatch);
|
||||
fc.setFoundOnPath(onPath);
|
||||
|
@ -112,7 +112,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
private static class IncludeResolution {String fLocation; boolean fHeuristic;}
|
||||
final private IIncludeFileTester<IncludeResolution> createPathTester= new IIncludeFileTester<IncludeResolution>() {
|
||||
public IncludeResolution checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
|
||||
if (fCodeReaderFactory.getInclusionExists(path)) {
|
||||
if (fFileContentProvider.getInclusionExists(path)) {
|
||||
IncludeResolution res= new IncludeResolution();
|
||||
res.fHeuristic= isHeuristicMatch;
|
||||
res.fLocation= path;
|
||||
|
@ -154,7 +154,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
TokenSequence fLineInputToMacroExpansion= new TokenSequence(true);
|
||||
|
||||
final private IParserLogService fLog;
|
||||
final private IIndexBasedCodeReaderFactory fCodeReaderFactory;
|
||||
final private InternalFileContentProvider fFileContentProvider;
|
||||
|
||||
private IIncludeFileResolutionHeuristics fIncludeFileResolutionHeuristics;
|
||||
private final ExpressionEvaluator fExpressionEvaluator;
|
||||
|
@ -190,8 +190,22 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
private Token fLastToken;
|
||||
|
||||
|
||||
public CPreprocessor(CodeReader reader, IScannerInfo info, ParserLanguage language, IParserLogService log,
|
||||
IScannerExtensionConfiguration configuration, ICodeReaderFactory readerFactory) {
|
||||
public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language, IParserLogService log,
|
||||
IScannerExtensionConfiguration configuration, IncludeFileContentProvider readerFactory) {
|
||||
if (readerFactory instanceof InternalFileContentProvider) {
|
||||
fFileContentProvider= (InternalFileContentProvider) readerFactory;
|
||||
} else if (readerFactory == null) {
|
||||
fFileContentProvider= EmptyFilesProvider.getInstance();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal reader factory"); //$NON-NLS-1$
|
||||
}
|
||||
InternalFileContent content;
|
||||
if (fileContent instanceof InternalFileContent) {
|
||||
content= (InternalFileContent) fileContent;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal file content object"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
fLog = log;
|
||||
fAdditionalNumericLiteralSuffixes= nonNull(configuration.supportAdditionalNumericLiteralSuffixes());
|
||||
fLexOptions.fSupportDollarInIdentifiers= configuration.support$InIdentifiers();
|
||||
|
@ -207,20 +221,16 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
fExpressionEvaluator= new ExpressionEvaluator();
|
||||
fMacroDefinitionParser= new MacroDefinitionParser();
|
||||
fMacroExpander= new MacroExpander(this, fMacroDictionary, fLocationMap, fLexOptions);
|
||||
fCodeReaderFactory= wrapReaderFactory(readerFactory);
|
||||
if (readerFactory instanceof IAdaptable) {
|
||||
fIncludeFileResolutionHeuristics= (IIncludeFileResolutionHeuristics) ((IAdaptable) readerFactory).getAdapter(IIncludeFileResolutionHeuristics.class);
|
||||
}
|
||||
fIncludeFileResolutionHeuristics= fFileContentProvider.getIncludeHeuristics();
|
||||
|
||||
final String filePath= new String(reader.filename);
|
||||
final String filePath= content.getFileLocation();
|
||||
configureIncludeSearchPath(new File(filePath).getParentFile(), info);
|
||||
setupMacroDictionary(configuration, info, language);
|
||||
|
||||
ILocationCtx ctx= fLocationMap.pushTranslationUnit(filePath, content.getSource());
|
||||
fAllIncludedFiles.add(filePath);
|
||||
ILocationCtx ctx= fLocationMap.pushTranslationUnit(filePath, reader.buffer);
|
||||
fCodeReaderFactory.reportTranslationUnitFile(filePath);
|
||||
fAllIncludedFiles.add(filePath);
|
||||
fRootLexer= new Lexer(reader.buffer, fLexOptions, this, this);
|
||||
fFileContentProvider.reportTranslationUnitFile(filePath);
|
||||
fRootLexer= new Lexer(content.getSource(), fLexOptions, this, this);
|
||||
fRootContext= fCurrentContext= new ScannerContext(ctx, null, fRootLexer);
|
||||
if (info instanceof IExtendedScannerInfo) {
|
||||
final IExtendedScannerInfo einfo= (IExtendedScannerInfo) info;
|
||||
|
@ -228,44 +238,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
}
|
||||
}
|
||||
|
||||
private IIndexBasedCodeReaderFactory wrapReaderFactory(final ICodeReaderFactory readerFactory) {
|
||||
if (readerFactory instanceof IIndexBasedCodeReaderFactory) {
|
||||
return (IIndexBasedCodeReaderFactory) readerFactory;
|
||||
}
|
||||
return new IIndexBasedCodeReaderFactory() {
|
||||
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||
return readerFactory.createCodeReaderForTranslationUnit(path);
|
||||
}
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return readerFactory.createCodeReaderForInclusion(path);
|
||||
}
|
||||
public IncludeFileContent getContentForInclusion(String path) {
|
||||
CodeReader reader= readerFactory.createCodeReaderForInclusion(path);
|
||||
if (reader != null) {
|
||||
return new IncludeFileContent(reader);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void reportTranslationUnitFile(String path) {
|
||||
fAllIncludedFiles.add(path);
|
||||
}
|
||||
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||
return fAllIncludedFiles.contains(path);
|
||||
}
|
||||
public ICodeReaderCache getCodeReaderCache() {
|
||||
return readerFactory.getCodeReaderCache();
|
||||
}
|
||||
public int getUniqueIdentifier() {
|
||||
return readerFactory.getUniqueIdentifier();
|
||||
}
|
||||
public boolean getInclusionExists(String path) {
|
||||
return readerFactory.createCodeReaderForInclusion(path) != null;
|
||||
}
|
||||
public IncludeFileContent getContentForContextToHeaderGap(String fileLocation) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void setComputeImageLocations(boolean val) {
|
||||
fLexOptions.fCreateImageLocations= val;
|
||||
|
@ -383,7 +355,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
handlePreIncludedFiles();
|
||||
}
|
||||
final String location = fLocationMap.getTranslationUnitPath();
|
||||
IncludeFileContent content= fCodeReaderFactory.getContentForContextToHeaderGap(location);
|
||||
InternalFileContent content= fFileContentProvider.getContentForContextToHeaderGap(location);
|
||||
if (content != null && content.getKind() == InclusionKind.FOUND_IN_INDEX) {
|
||||
processInclusionFromIndex(0, location, content);
|
||||
}
|
||||
|
@ -393,7 +365,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
final String[] imacro= fPreIncludedFiles[0];
|
||||
if (imacro != null && imacro.length > 0) {
|
||||
final char[] buffer= createSyntheticFile(imacro);
|
||||
ILocationCtx ctx= fLocationMap.pushPreInclusion(buffer, 0, true);
|
||||
ILocationCtx ctx= fLocationMap.pushPreInclusion(new CharArray(buffer), 0, true);
|
||||
fCurrentContext= new ScannerContext(ctx, fCurrentContext, new Lexer(buffer, fLexOptions, this, this));
|
||||
ScannerContext preCtx= fCurrentContext;
|
||||
try {
|
||||
|
@ -410,7 +382,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
final String[] include= fPreIncludedFiles[1];
|
||||
if (include != null && include.length > 0) {
|
||||
final char[] buffer= createSyntheticFile(include);
|
||||
ILocationCtx ctx= fLocationMap.pushPreInclusion(buffer, 0, false);
|
||||
ILocationCtx ctx= fLocationMap.pushPreInclusion(new CharArray(buffer), 0, false);
|
||||
fCurrentContext= new ScannerContext(ctx, fCurrentContext, new Lexer(buffer, fLexOptions, this, this));
|
||||
}
|
||||
fPreIncludedFiles= null;
|
||||
|
@ -1099,6 +1071,14 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean hasFileBeenIncluded(String location) {
|
||||
Boolean itHas= fFileContentProvider.hasFileBeenIncludedInCurrentTranslationUnit(location);
|
||||
if (itHas != null) {
|
||||
return itHas.booleanValue();
|
||||
}
|
||||
return fAllIncludedFiles.contains(location);
|
||||
}
|
||||
|
||||
private void executeInclude(final Lexer lexer, int poundOffset, boolean include_next, boolean active, boolean withinExpansion) throws OffsetLimitReachedException {
|
||||
if (withinExpansion) {
|
||||
final char[] name= lexer.currentToken().getCharImage();
|
||||
|
@ -1182,12 +1162,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
// test if the include is inactive just because it was included before (bug 167100)
|
||||
final IncludeResolution resolved= findInclusion(includeDirective, userInclude, include_next,
|
||||
getCurrentFilename(), createPathTester);
|
||||
if (resolved != null && fCodeReaderFactory.hasFileBeenIncludedInCurrentTranslationUnit(resolved.fLocation)) {
|
||||
if (resolved != null && hasFileBeenIncluded(resolved.fLocation)) {
|
||||
path= resolved.fLocation;
|
||||
isHeuristic= resolved.fHeuristic;
|
||||
}
|
||||
} else {
|
||||
final IncludeFileContent fi= findInclusion(includeDirective, userInclude, include_next,
|
||||
final InternalFileContent fi= findInclusion(includeDirective, userInclude, include_next,
|
||||
getCurrentFilename(), createCodeReaderTester);
|
||||
if (fi != null) {
|
||||
path= fi.getFileLocation();
|
||||
|
@ -1196,14 +1176,14 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
case FOUND_IN_INDEX:
|
||||
processInclusionFromIndex(poundOffset, path, fi);
|
||||
break;
|
||||
case USE_CODE_READER:
|
||||
CodeReader reader= fi.getCodeReader();
|
||||
if (reader != null && !isCircularInclusion(path)) {
|
||||
case USE_SOURCE:
|
||||
AbstractCharArray source= fi.getSource();
|
||||
if (source != null && !isCircularInclusion(path)) {
|
||||
reported= true;
|
||||
fAllIncludedFiles.add(path);
|
||||
ILocationCtx ctx= fLocationMap.pushInclusion(poundOffset, nameOffsets[0], nameOffsets[1],
|
||||
condEndOffset, reader.buffer, path, headerName, userInclude, isHeuristic, fi.isSource());
|
||||
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(reader.buffer,
|
||||
condEndOffset, source, path, headerName, userInclude, isHeuristic, fi.isSource());
|
||||
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(source,
|
||||
fLexOptions, this, this));
|
||||
fctx.setFoundOnPath(fi.getFoundOnPath(), includeDirective);
|
||||
fCurrentContext= fctx;
|
||||
|
@ -1231,7 +1211,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
}
|
||||
}
|
||||
|
||||
private void processInclusionFromIndex(int offset, String path, IncludeFileContent fi) {
|
||||
private void processInclusionFromIndex(int offset, String path, InternalFileContent fi) {
|
||||
List<IIndexMacro> mdefs= fi.getMacroDefinitions();
|
||||
for (IIndexMacro macro : mdefs) {
|
||||
addMacroDefinition(macro);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper around char[] to implement {@link AbstractCharArray}.
|
||||
*/
|
||||
|
@ -21,8 +22,21 @@ public final class CharArray extends AbstractCharArray {
|
|||
fArray= array;
|
||||
}
|
||||
|
||||
public CharArray(String str) {
|
||||
fArray= str.toCharArray();
|
||||
}
|
||||
|
||||
public char[] getArray() {
|
||||
return fArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLimit() {
|
||||
public int getLength() {
|
||||
return fArray.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int tryGetLength() {
|
||||
return fArray.length;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent.InclusionKind;
|
||||
|
||||
/**
|
||||
* The index based code-reader factory fakes the inclusion of files that are already indexed.
|
||||
* When trying to figure out whether a specific header has been included or not, the factory
|
||||
* has to be consulted.
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public interface IIndexBasedCodeReaderFactory extends ICodeReaderFactory {
|
||||
/**
|
||||
* Returns whether or not the file has been included.
|
||||
*/
|
||||
boolean hasFileBeenIncludedInCurrentTranslationUnit(String path);
|
||||
|
||||
/**
|
||||
* Reports the path of the translation unit, such that it is known as included.
|
||||
*/
|
||||
void reportTranslationUnitFile(String path);
|
||||
|
||||
/**
|
||||
* Create an InclusionContent object for the given location.
|
||||
* return an inclusion content or <code>null</code> if the location does not exist.
|
||||
* @see IncludeFileContent
|
||||
*/
|
||||
public IncludeFileContent getContentForInclusion(String fileLocation);
|
||||
|
||||
/**
|
||||
* Check whether the specified inclusion exists.
|
||||
* @since 5.0
|
||||
*/
|
||||
boolean getInclusionExists(String finalPath);
|
||||
|
||||
/**
|
||||
* Returns a file-content object of kind {@link InclusionKind#FOUND_IN_INDEX}, representing
|
||||
* the content from the context of the given file up to where the file actually gets included.
|
||||
* @since 5.0
|
||||
*/
|
||||
IncludeFileContent getContentForContextToHeaderGap(String fileLocation);
|
||||
}
|
|
@ -23,5 +23,5 @@ public interface ISkippedIndexedFilesListener {
|
|||
* @param offset offset at which the file is included (see {@link ASTNode#getOffset()}
|
||||
* @param fileContent information about the skipped file.
|
||||
*/
|
||||
void skippedFile(int offset, IncludeFileContent fileContent);
|
||||
void skippedFile(int offset, InternalFileContent fileContent);
|
||||
}
|
||||
|
|
|
@ -15,13 +15,12 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
|
||||
/**
|
||||
* Instructs the preprocessor on how to handle a file-inclusion.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class IncludeFileContent {
|
||||
public class InternalFileContent extends FileContent {
|
||||
public enum InclusionKind {
|
||||
/**
|
||||
* Instruct the preprocessor to skip this inclusion.
|
||||
|
@ -33,13 +32,13 @@ public class IncludeFileContent {
|
|||
*/
|
||||
FOUND_IN_INDEX,
|
||||
/**
|
||||
* The file has to be scanned, a code reader is provided.
|
||||
* The file has to be scanned, source is provided.
|
||||
*/
|
||||
USE_CODE_READER
|
||||
USE_SOURCE
|
||||
}
|
||||
|
||||
private final InclusionKind fKind;
|
||||
private final CodeReader fCodeReader;
|
||||
private final AbstractCharArray fSource;
|
||||
private final List<IIndexMacro> fMacroDefinitions;
|
||||
private final List<ICPPUsingDirective> fUsingDirectives;
|
||||
private final String fFileLocation;
|
||||
|
@ -55,7 +54,7 @@ public class IncludeFileContent {
|
|||
* @throws IllegalArgumentException if fileLocation is <code>null</code> or the kind value is illegal for
|
||||
* this constructor.
|
||||
*/
|
||||
public IncludeFileContent(String fileLocation, InclusionKind kind) throws IllegalArgumentException {
|
||||
public InternalFileContent(String fileLocation, InclusionKind kind) throws IllegalArgumentException {
|
||||
if (fileLocation == null || kind != InclusionKind.SKIP_FILE) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
@ -63,21 +62,20 @@ public class IncludeFileContent {
|
|||
fFileLocation= fileLocation;
|
||||
fMacroDefinitions= null;
|
||||
fUsingDirectives= null;
|
||||
fCodeReader= null;
|
||||
fSource= null;
|
||||
}
|
||||
|
||||
/**
|
||||
* For reading include files from disk.
|
||||
* @param codeReader the code reader for the inclusion.
|
||||
* @throws IllegalArgumentException in case the codeReader or its location is <code>null</code>.
|
||||
*/
|
||||
public IncludeFileContent(CodeReader codeReader) throws IllegalArgumentException {
|
||||
if (codeReader == null) {
|
||||
public InternalFileContent(String filePath, AbstractCharArray content) throws IllegalArgumentException {
|
||||
if (content == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
fKind= InclusionKind.USE_CODE_READER;
|
||||
fFileLocation= codeReader.getPath();
|
||||
fCodeReader= codeReader;
|
||||
fKind= InclusionKind.USE_SOURCE;
|
||||
fFileLocation= filePath;
|
||||
fSource= content;
|
||||
fMacroDefinitions= null;
|
||||
fUsingDirectives= null;
|
||||
if (fFileLocation == null) {
|
||||
|
@ -92,11 +90,11 @@ public class IncludeFileContent {
|
|||
* @param files
|
||||
* @throws IllegalArgumentException in case the fileLocation or the macroDefinitions are <code>null</code>.
|
||||
*/
|
||||
public IncludeFileContent(String fileLocation, List<IIndexMacro> macroDefinitions, List<ICPPUsingDirective> usingDirectives,
|
||||
public InternalFileContent(String fileLocation, List<IIndexMacro> macroDefinitions, List<ICPPUsingDirective> usingDirectives,
|
||||
List<IIndexFile> files) {
|
||||
fKind= InclusionKind.FOUND_IN_INDEX;
|
||||
fFileLocation= fileLocation;
|
||||
fCodeReader= null;
|
||||
fSource= null;
|
||||
fUsingDirectives= usingDirectives;
|
||||
fMacroDefinitions= macroDefinitions;
|
||||
fFiles= files;
|
||||
|
@ -112,16 +110,17 @@ public class IncludeFileContent {
|
|||
/**
|
||||
* Returns the location of the file to be included.
|
||||
*/
|
||||
@Override
|
||||
public String getFileLocation() {
|
||||
return fFileLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid with {@link InclusionKind#USE_CODE_READER}.
|
||||
* @return the codeReader or <code>null</code> if kind is different to {@link InclusionKind#USE_CODE_READER}.
|
||||
* Valid with {@link InclusionKind#USE_SOURCE}.
|
||||
* @return the codeReader or <code>null</code> if kind is different to {@link InclusionKind#USE_SOURCE}.
|
||||
*/
|
||||
public CodeReader getCodeReader() {
|
||||
return fCodeReader;
|
||||
public AbstractCharArray getSource() {
|
||||
return fSource;
|
||||
}
|
||||
|
||||
/**
|
|
@ -0,0 +1,80 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent.InclusionKind;
|
||||
|
||||
/**
|
||||
* Internal implementation of the file content providers
|
||||
*/
|
||||
public abstract class InternalFileContentProvider extends IncludeFileContentProvider {
|
||||
|
||||
private IIncludeFileResolutionHeuristics fIncludeResolutionHeuristics;
|
||||
|
||||
/**
|
||||
* Check whether the specified inclusion exists.
|
||||
*/
|
||||
public boolean getInclusionExists(String path) {
|
||||
return new File(path).exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an InclusionContent object for the given location.
|
||||
* return an inclusion content or <code>null</code> if the location does not exist.
|
||||
* @see InternalFileContent
|
||||
*/
|
||||
public abstract InternalFileContent getContentForInclusion(String path);
|
||||
|
||||
/**
|
||||
* Called only when used as a delegate of the index file content provider.
|
||||
*/
|
||||
public abstract InternalFileContent getContentForInclusion(IIndexFileLocation ifl, String astPath);
|
||||
|
||||
/**
|
||||
* Returns a file-content object of kind {@link InclusionKind#FOUND_IN_INDEX}, representing
|
||||
* the content from the context of the given file up to where the file actually gets included,
|
||||
* or <code>null</code> if this cannot be done.
|
||||
*/
|
||||
public InternalFileContent getContentForContextToHeaderGap(String location) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the path of the translation unit, such that it is known as included.
|
||||
*/
|
||||
public void reportTranslationUnitFile(String filePath) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the file has been included, or <code>null</code> if the content provider
|
||||
* does not track that.
|
||||
*/
|
||||
public Boolean hasFileBeenIncludedInCurrentTranslationUnit(String location) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a strategy for heuristically resolving includes, or <code>null</code> if this shall not
|
||||
* be done.
|
||||
*/
|
||||
public final IIncludeFileResolutionHeuristics getIncludeHeuristics() {
|
||||
return fIncludeResolutionHeuristics;
|
||||
}
|
||||
|
||||
public final void setIncludeResolutionHeuristics(IIncludeFileResolutionHeuristics heuristics) {
|
||||
fIncludeResolutionHeuristics= heuristics;
|
||||
}
|
||||
}
|
|
@ -93,6 +93,10 @@ final public class Lexer implements ITokenSequence {
|
|||
this(new CharArray(input), 0, input.length, options, log, source);
|
||||
}
|
||||
|
||||
public Lexer(AbstractCharArray input, LexerOptions options, ILexerLog log, Object source) {
|
||||
this(input, 0, input.tryGetLength(), options, log, source);
|
||||
}
|
||||
|
||||
public Lexer(AbstractCharArray input, int start, int end, LexerOptions options, ILexerLog log, Object source) {
|
||||
fInput= input;
|
||||
fStart= fOffset= fEndOffset= start;
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Collections;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* Base class for all location contexts that can contain children.
|
||||
|
@ -31,10 +32,10 @@ class LocationCtxContainer extends LocationCtx {
|
|||
private int fChildSequenceLength;
|
||||
|
||||
private ArrayList<LocationCtx> fChildren;
|
||||
private char[] fSource;
|
||||
private AbstractCharArray fSource;
|
||||
private int[] fLineOffsets;
|
||||
|
||||
public LocationCtxContainer(LocationCtxContainer parent, char[] source, int parentOffset, int parentEndOffset, int sequenceNumber) {
|
||||
public LocationCtxContainer(LocationCtxContainer parent, AbstractCharArray source, int parentOffset, int parentEndOffset, int sequenceNumber) {
|
||||
super(parent, parentOffset, parentEndOffset, sequenceNumber);
|
||||
fSource= source;
|
||||
}
|
||||
|
@ -55,16 +56,17 @@ class LocationCtxContainer extends LocationCtx {
|
|||
}
|
||||
|
||||
public char[] getSource(int offset, int length) {
|
||||
offset= Math.max(0, Math.min(offset, fSource.length));
|
||||
length= Math.max(0, Math.min(length, fSource.length-offset));
|
||||
char[] result= new char[length];
|
||||
System.arraycopy(fSource, offset, result, 0, length);
|
||||
return result;
|
||||
if (fSource.isValidOffset(offset+length-1)) {
|
||||
char[] result= new char[length];
|
||||
fSource.arraycopy(offset, result, 0, length);
|
||||
return result;
|
||||
}
|
||||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getSequenceLength() {
|
||||
return fSource.length + fChildSequenceLength;
|
||||
return fSource.getLength() + fChildSequenceLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,12 +172,12 @@ class LocationCtxContainer extends LocationCtx {
|
|||
|
||||
// create the location after the last child.
|
||||
final int myEndNumber = fSequenceNumber + getSequenceLength();
|
||||
final int offset= fSource.length - (myEndNumber - sequenceNumber);
|
||||
final int offset= fSource.getLength() - (myEndNumber - sequenceNumber);
|
||||
if (endSequenceNumber <= myEndNumber) {
|
||||
addFileLocation(offset, endSequenceNumber-sequenceNumber, locations);
|
||||
return true;
|
||||
}
|
||||
addFileLocation(offset, fSource.length-offset, locations);
|
||||
addFileLocation(offset, fSource.getLength()-offset, locations);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -247,8 +249,9 @@ class LocationCtxContainer extends LocationCtx {
|
|||
|
||||
private int[] computeLineOffsets() {
|
||||
ArrayList<Integer> offsets= new ArrayList<Integer>();
|
||||
for (int i = 0; i < fSource.length; i++) {
|
||||
if (fSource[i] == '\n') {
|
||||
final int len= fSource.getLength();
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (fSource.get(i) == '\n') {
|
||||
offsets.add(new Integer(i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class LocationCtxFile extends LocationCtxContainer {
|
|||
private final ASTInclusionStatement fASTInclude;
|
||||
private final boolean fIsSource;
|
||||
|
||||
public LocationCtxFile(LocationCtxContainer parent, String filename, char[] source, int parentOffset,
|
||||
public LocationCtxFile(LocationCtxContainer parent, String filename, AbstractCharArray source, int parentOffset,
|
||||
int parentEndOffset, int sequenceNumber, ASTInclusionStatement inclusionStatement,
|
||||
boolean isSource) {
|
||||
super(parent, source, parentOffset, parentEndOffset, sequenceNumber);
|
||||
|
|
|
@ -93,7 +93,7 @@ public class LocationMap implements ILocationResolver {
|
|||
* The outermost context must be a translation unit. You must call this method exactly once and before
|
||||
* creating any other context.
|
||||
*/
|
||||
public ILocationCtx pushTranslationUnit(String filename, char[] buffer) {
|
||||
public ILocationCtx pushTranslationUnit(String filename, AbstractCharArray buffer) {
|
||||
assert fCurrentContext == null;
|
||||
fTranslationUnitPath= filename;
|
||||
fCurrentContext= fRootContext= new LocationCtxFile(null, filename, buffer, 0, 0, 0, null, true);
|
||||
|
@ -107,7 +107,7 @@ public class LocationMap implements ILocationResolver {
|
|||
* @param buffer a buffer containing the include directives.
|
||||
* @param isMacroFile whether the context is used for running the preprocessor, only.
|
||||
*/
|
||||
public ILocationCtx pushPreInclusion(char[] buffer, int offset, boolean isMacroFile) {
|
||||
public ILocationCtx pushPreInclusion(AbstractCharArray buffer, int offset, boolean isMacroFile) {
|
||||
assert fCurrentContext instanceof LocationCtxContainer;
|
||||
int sequenceNumber= getSequenceNumberForOffset(offset);
|
||||
fCurrentContext= new LocationCtxContainer((LocationCtxContainer) fCurrentContext, buffer, offset, offset, sequenceNumber);
|
||||
|
@ -126,7 +126,7 @@ public class LocationMap implements ILocationResolver {
|
|||
* @param userInclude <code>true</code> when specified with double-quotes.
|
||||
*/
|
||||
public ILocationCtx pushInclusion(int startOffset, int nameOffset, int nameEndOffset, int endOffset,
|
||||
char[] buffer, String filename, char[] name, boolean userInclude, boolean heuristic, boolean isSource) {
|
||||
AbstractCharArray buffer, String filename, char[] name, boolean userInclude, boolean heuristic, boolean isSource) {
|
||||
assert fCurrentContext instanceof LocationCtxContainer;
|
||||
int startNumber= getSequenceNumberForOffset(startOffset);
|
||||
int nameNumber= getSequenceNumberForOffset(nameOffset);
|
||||
|
@ -721,7 +721,7 @@ public class LocationMap implements ILocationResolver {
|
|||
public void cleanup() {
|
||||
}
|
||||
|
||||
public void skippedFile(int sequenceNumber, IncludeFileContent fi) {
|
||||
public void skippedFile(int sequenceNumber, InternalFileContent fi) {
|
||||
for (ISkippedIndexedFilesListener l : fSkippedFilesListeners) {
|
||||
l.skippedFile(sequenceNumber, fi);
|
||||
}
|
||||
|
|
|
@ -38,18 +38,19 @@ import org.eclipse.cdt.core.index.IIndexManager;
|
|||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
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.index.IndexBasedFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -90,7 +91,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
}
|
||||
|
||||
public static class FileContent {
|
||||
public static class IndexFileContent {
|
||||
private IIndexFile fIndexFile= null;
|
||||
private boolean fRequestUpdate= false;
|
||||
private boolean fRequestIsCounted= true;
|
||||
|
@ -167,7 +168,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
|
||||
private UnusedHeaderStrategy fIndexHeadersWithoutContext= UnusedHeaderStrategy.useDefaultLanguage;
|
||||
private boolean fIndexFilesWithoutConfiguration= true;
|
||||
private HashMap<FileKey, FileContent> fFileInfos= new HashMap<FileKey, FileContent>();
|
||||
private HashMap<FileKey, IndexFileContent> fFileInfos= new HashMap<FileKey, IndexFileContent>();
|
||||
|
||||
private Object[] fFilesToUpdate;
|
||||
private List<Object> fFilesToRemove = new ArrayList<Object>();
|
||||
|
@ -178,7 +179,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
protected IWritableIndex fIndex;
|
||||
private ITodoTaskUpdater fTodoTaskUpdater;
|
||||
private final boolean fIsFastIndexer;
|
||||
private AbstractCodeReaderFactory fCodeReaderFactory;
|
||||
private InternalFileContentProvider fCodeReaderFactory;
|
||||
|
||||
public AbstractIndexerTask(Object[] filesToUpdate, Object[] filesToRemove, IndexerInputAdapter resolver, boolean fastIndexer) {
|
||||
super(resolver);
|
||||
|
@ -212,7 +213,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
|
||||
protected abstract IWritableIndex createIndex();
|
||||
protected abstract IIncludeFileResolutionHeuristics createIncludeHeuristics();
|
||||
protected abstract AbstractCodeReaderFactory createReaderFactory();
|
||||
protected abstract IncludeFileContentProvider createReaderFactory();
|
||||
protected abstract AbstractLanguage[] getLanguages(String fileName);
|
||||
|
||||
protected ITodoTaskUpdater createTodoTaskUpdater() {
|
||||
|
@ -233,7 +234,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
if (dummyName != null) {
|
||||
IIndexFileLocation dummyLoc= fResolver.resolveASTPath(dummyName);
|
||||
setIndexed(lang.getLinkageID(), dummyLoc);
|
||||
CodeReader codeReader= new CodeReader(dummyName, code.toCharArray());
|
||||
FileContent codeReader= FileContent.create(dummyName, code.toCharArray());
|
||||
return createAST(lang, codeReader, scanInfo, options, monitor);
|
||||
}
|
||||
return null;
|
||||
|
@ -242,7 +243,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
|
||||
private final IASTTranslationUnit createAST(Object tu, AbstractLanguage language, IScannerInfo scanInfo, int options, IProgressMonitor pm)
|
||||
throws CoreException {
|
||||
final CodeReader codeReader= fResolver.getCodeReader(tu);
|
||||
final FileContent codeReader= fResolver.getCodeReader(tu);
|
||||
if (codeReader == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -252,19 +253,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
return createAST(language, codeReader, scanInfo, options, pm);
|
||||
}
|
||||
|
||||
private final IASTTranslationUnit createAST(AbstractLanguage language, CodeReader codeReader,
|
||||
private final IASTTranslationUnit createAST(AbstractLanguage language, FileContent codeReader,
|
||||
IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException {
|
||||
if (fCodeReaderFactory == null) {
|
||||
InternalFileContentProvider fileContentProvider = createInternalFileContentProvider();
|
||||
if (fIsFastIndexer) {
|
||||
fCodeReaderFactory= new IndexBasedCodeReaderFactory(fIndex, createIncludeHeuristics(),
|
||||
fResolver, language.getLinkageID(), createReaderFactory(), this);
|
||||
fCodeReaderFactory= new IndexBasedFileContentProvider(fIndex, fResolver, language.getLinkageID(), fileContentProvider, this);
|
||||
} else {
|
||||
fCodeReaderFactory= createReaderFactory();
|
||||
fCodeReaderFactory= fileContentProvider;
|
||||
}
|
||||
} else if (fIsFastIndexer) {
|
||||
((IndexBasedCodeReaderFactory) fCodeReaderFactory).setLinkage(language.getLinkageID());
|
||||
((IndexBasedFileContentProvider) fCodeReaderFactory).setLinkage(language.getLinkageID());
|
||||
}
|
||||
|
||||
fCodeReaderFactory.setIncludeResolutionHeuristics(createIncludeHeuristics());
|
||||
try {
|
||||
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory,
|
||||
fIndex, options, getLogService());
|
||||
|
@ -274,11 +275,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
return ast;
|
||||
} finally {
|
||||
if (fIsFastIndexer) {
|
||||
((IndexBasedCodeReaderFactory) fCodeReaderFactory).cleanupAfterTranslationUnit();
|
||||
((IndexBasedFileContentProvider) fCodeReaderFactory).cleanupAfterTranslationUnit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private InternalFileContentProvider createInternalFileContentProvider() {
|
||||
final IncludeFileContentProvider fileContentProvider = createReaderFactory();
|
||||
if (fileContentProvider instanceof InternalFileContentProvider)
|
||||
return (InternalFileContentProvider) fileContentProvider;
|
||||
|
||||
throw new IllegalArgumentException("Invalid file content provider"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected IParserLogService getLogService() {
|
||||
return ParserUtil.getParserLogService();
|
||||
}
|
||||
|
@ -417,7 +426,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
|
||||
private void requestUpdate(int linkageID, IIndexFileLocation ifl, IIndexFragmentFile ifile) {
|
||||
FileKey key= new FileKey(linkageID, ifl.getURI());
|
||||
FileContent info= fFileInfos.get(key);
|
||||
IndexFileContent info= fFileInfos.get(key);
|
||||
if (info == null) {
|
||||
info= createFileInfo(key, null);
|
||||
}
|
||||
|
@ -427,7 +436,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
|
||||
private void setIndexed(int linkageID, IIndexFileLocation ifl) {
|
||||
FileKey key= new FileKey(linkageID, ifl.getURI());
|
||||
FileContent info= fFileInfos.get(key);
|
||||
IndexFileContent info= fFileInfos.get(key);
|
||||
if (info == null) {
|
||||
info= createFileInfo(key, null);
|
||||
}
|
||||
|
@ -435,14 +444,14 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
info.clearCaches();
|
||||
}
|
||||
|
||||
private FileContent createFileInfo(FileKey key, IIndexFile ifile) {
|
||||
FileContent info = new FileContent();
|
||||
private IndexFileContent createFileInfo(FileKey key, IIndexFile ifile) {
|
||||
IndexFileContent info = new IndexFileContent();
|
||||
fFileInfos.put(key, info);
|
||||
info.fIndexFile= ifile;
|
||||
return info;
|
||||
}
|
||||
|
||||
private FileContent getFileInfo(int linkageID, IIndexFileLocation ifl) {
|
||||
private IndexFileContent getFileInfo(int linkageID, IIndexFileLocation ifl) {
|
||||
FileKey key= new FileKey(linkageID, ifl.getURI());
|
||||
return fFileInfos.get(key);
|
||||
}
|
||||
|
@ -557,7 +566,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
String found= p.getPath();
|
||||
if (found != null) {
|
||||
IIndexFileLocation ifl= fResolver.resolveASTPath(found);
|
||||
FileContent fileinfo = getFileInfo(linkageID, ifl);
|
||||
IndexFileContent fileinfo = getFileInfo(linkageID, ifl);
|
||||
if (fileinfo != null) {
|
||||
if (fileinfo.fIndexFile != null) {
|
||||
trace(filePath + " was not properly parsed up front for " + lang.getName()); //$NON-NLS-1$
|
||||
|
@ -591,7 +600,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
final IIndexFileLocation ifl = fResolver.resolveFile(tu);
|
||||
if (ifl == null)
|
||||
continue;
|
||||
final FileContent info= getFileInfo(linkageID, ifl);
|
||||
final IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||
info.fRequestIsCounted= false;
|
||||
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, tu);
|
||||
|
@ -613,7 +622,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
return;
|
||||
final Object header= iter.next();
|
||||
final IIndexFileLocation ifl = fResolver.resolveFile(header);
|
||||
final FileContent info= getFileInfo(linkageID, ifl);
|
||||
final IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||
if (info.fIndexFile != null && fIndex.isWritableFile(info.fIndexFile)) {
|
||||
Object tu= findContext((IIndexFragmentFile) info.fIndexFile, contextMap);
|
||||
|
@ -640,7 +649,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
return;
|
||||
final Object header= iter.next();
|
||||
final IIndexFileLocation ifl = fResolver.resolveFile(header);
|
||||
final FileContent info= getFileInfo(linkageID, ifl);
|
||||
final IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||
info.fRequestIsCounted= false;
|
||||
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header);
|
||||
|
@ -740,7 +749,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
collectOrderedIFLs(linkageID, inclusion, enteredFiles, orderedIFLs);
|
||||
}
|
||||
|
||||
FileContent info= getFileInfo(linkageID, topIfl);
|
||||
IndexFileContent info= getFileInfo(linkageID, topIfl);
|
||||
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||
orderedIFLs.add(topIfl);
|
||||
}
|
||||
|
@ -775,7 +784,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
|
||||
public final boolean needToUpdateHeader(int linkageID, IIndexFileLocation ifl) throws CoreException {
|
||||
FileContent info= getFileInfo(linkageID, ifl);
|
||||
IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||
if (info == null) {
|
||||
IIndexFile ifile= null;
|
||||
if (fResolver.canBePartOfSDK(ifl)) {
|
||||
|
@ -914,9 +923,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
return result*31 + key.hashCode();
|
||||
}
|
||||
|
||||
public final FileContent getFileContent(int linkageID, IIndexFileLocation ifl) throws CoreException {
|
||||
public final IndexFileContent getFileContent(int linkageID, IIndexFileLocation ifl) throws CoreException {
|
||||
if (!needToUpdateHeader(linkageID, ifl)) {
|
||||
FileContent info= getFileInfo(linkageID, ifl);
|
||||
IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||
Assert.isNotNull(info);
|
||||
if (info.fIndexFile == null) {
|
||||
info.fIndexFile= fIndex.getFile(linkageID, ifl);
|
||||
|
|
|
@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.core.pdom;
|
|||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
||||
/**
|
||||
|
@ -68,6 +68,6 @@ public abstract class IndexerInputAdapter extends ASTFilePathResolver {
|
|||
/**
|
||||
* Returns a code reader for the given input file.
|
||||
*/
|
||||
public abstract CodeReader getCodeReader(Object tu);
|
||||
public abstract FileContent getCodeReader(Object tu);
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
|
||||
/**
|
||||
|
@ -26,8 +26,8 @@ class PDOMFastIndexerTask extends PDOMIndexerTask {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
||||
return null;
|
||||
protected IncludeFileContentProvider createReaderFactory() {
|
||||
return IncludeFileContentProvider.getSavedFilesProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||
|
||||
|
@ -28,8 +28,8 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
||||
return SavedCodeReaderFactory.createInstance(createIncludeHeuristics());
|
||||
protected IncludeFileContentProvider createReaderFactory() {
|
||||
return IncludeFileContentProvider.adapt(SavedCodeReaderFactory.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
|
||||
|
@ -228,12 +228,12 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CodeReader getCodeReader(Object tuo) {
|
||||
public FileContent getCodeReader(Object tuo) {
|
||||
ITranslationUnit tu= (ITranslationUnit) tuo;
|
||||
final CodeReader reader= tu.getCodeReader();
|
||||
final FileContent reader= FileContent.create(tu);
|
||||
if (reader != null) {
|
||||
IIndexFileLocation ifl= IndexLocationFactory.getIFL(tu);
|
||||
fIflCache.put(reader.getPath(), ifl);
|
||||
fIflCache.put(reader.getFileLocation(), ifl);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,12 @@ import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
|
@ -46,8 +48,9 @@ import org.eclipse.core.resources.IStorage;
|
|||
import org.eclipse.core.runtime.content.IContentType;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||
|
||||
protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = GCCScannerExtensionConfiguration.getInstance();
|
||||
|
@ -234,7 +237,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
|||
private IScanner createScanner(CodeReader reader, IScannerInfo scanInfo,
|
||||
ParserMode mode, ParserLanguage lang, IParserLogService log,
|
||||
IScannerExtensionConfiguration scanConfig, ICodeReaderFactory fileCreator) {
|
||||
return new CPreprocessor(reader, scanInfo, lang, log, scanConfig, fileCreator);
|
||||
return new CPreprocessor(FileContent.adapt(reader), scanInfo, lang, log, scanConfig, IncludeFileContentProvider.adapt(fileCreator));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -27,10 +27,11 @@ import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
|||
import org.eclipse.cdt.core.model.IContributedModelBuilder;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.util.ASTPrinter;
|
||||
import org.eclipse.cdt.core.parser.util.DebugUtil;
|
||||
|
@ -77,9 +78,18 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
|||
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
|
||||
|
||||
|
||||
@Override @Deprecated
|
||||
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory codeReaderFactory, IIndex index, int options,
|
||||
IParserLogService log) throws CoreException {
|
||||
return getASTTranslationUnit(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider
|
||||
.adapt(codeReaderFactory), index, options, log);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) throws CoreException {
|
||||
public IASTTranslationUnit getASTTranslationUnit(FileContent reader, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, int options, IParserLogService log)
|
||||
throws CoreException {
|
||||
|
||||
IASTTranslationUnit gtu = null;
|
||||
if(DEBUG_PRINT_GCC_AST) {
|
||||
|
@ -100,7 +110,7 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
|||
preprocessor.setComputeImageLocations((options & ILanguage.OPTION_NO_IMAGE_LOCATIONS) == 0);
|
||||
|
||||
Map<String,String> parserProperties = new HashMap<String,String>();
|
||||
parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getPath());
|
||||
parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getFileLocation());
|
||||
if((options & OPTION_SKIP_FUNCTION_BODIES) != 0)
|
||||
parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
|
||||
if((options & OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0)
|
||||
|
@ -118,19 +128,26 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
|||
return tu;
|
||||
}
|
||||
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
|
||||
IIndex index, IParserLogService log) throws CoreException {
|
||||
|
||||
@Deprecated
|
||||
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log)
|
||||
throws CoreException {
|
||||
|
||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
|
||||
}
|
||||
|
||||
|
||||
public IASTCompletionNode getCompletionNode(CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
|
||||
IIndex index, IParserLogService log, int offset) throws CoreException {
|
||||
@Deprecated
|
||||
public IASTCompletionNode getCompletionNode(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log,
|
||||
int offset) throws CoreException {
|
||||
return getCompletionNode(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider
|
||||
.adapt(fileCreator), index, log, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTCompletionNode getCompletionNode(FileContent reader, IScannerInfo scanInfo,
|
||||
IncludeFileContentProvider fileCreator, IIndex index, IParserLogService log, int offset)
|
||||
throws CoreException {
|
||||
|
||||
IASTCompletionNode cn;
|
||||
if(DEBUG_PRINT_GCC_AST) {
|
||||
|
@ -151,7 +168,7 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
|||
|
||||
|
||||
Map<String,String> parserProperties = new HashMap<String,String>();
|
||||
parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getPath());
|
||||
parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getFileLocation());
|
||||
parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
|
||||
parserProperties.put(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS, "true");
|
||||
|
||||
|
@ -190,7 +207,7 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
|||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
|
||||
return GCCLanguage.getDefault().getSelectedNames(ast, start, length);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue