mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-14 20:45:22 +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.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
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.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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
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.NullLogService;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.tests.ASTComparer;
|
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.CTestPlugin;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
|
@ -93,6 +93,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
public class AST2BaseTest extends BaseTestCase {
|
public class AST2BaseTest extends BaseTestCase {
|
||||||
|
protected final static String TEST_CODE = "<testcode>";
|
||||||
protected static final IParserLogService NULL_LOG = new NullLogService();
|
protected static final IParserLogService NULL_LOG = new NullLogService();
|
||||||
protected static boolean sValidateCopy;
|
protected static boolean sValidateCopy;
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ public class AST2BaseTest extends BaseTestCase {
|
||||||
|
|
||||||
protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
|
protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
|
||||||
boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
|
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());
|
new ScannerInfo());
|
||||||
configureScanner(scanner);
|
configureScanner(scanner);
|
||||||
AbstractGNUSourceCodeParser parser = null;
|
AbstractGNUSourceCodeParser parser = null;
|
||||||
|
@ -179,7 +180,7 @@ public class AST2BaseTest extends BaseTestCase {
|
||||||
protected void configureScanner(IScanner scanner) {
|
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) {
|
IScannerInfo scannerInfo) {
|
||||||
IScannerExtensionConfiguration configuration = null;
|
IScannerExtensionConfiguration configuration = null;
|
||||||
if (lang == ParserLanguage.C)
|
if (lang == ParserLanguage.C)
|
||||||
|
@ -188,7 +189,7 @@ public class AST2BaseTest extends BaseTestCase {
|
||||||
configuration= GPPScannerExtensionConfiguration.getInstance();
|
configuration= GPPScannerExtensionConfiguration.getInstance();
|
||||||
IScanner scanner;
|
IScanner scanner;
|
||||||
scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration,
|
scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration,
|
||||||
FileCodeReaderFactory.getInstance());
|
IncludeFileContentProvider.getSavedFilesProvider());
|
||||||
return scanner;
|
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.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
|
@ -80,8 +80,7 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest {
|
||||||
* @throws ParserException
|
* @throws ParserException
|
||||||
*/
|
*/
|
||||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||||
CodeReader codeReader = new CodeReader(code
|
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||||
.toCharArray());
|
|
||||||
ScannerInfo scannerInfo = new ScannerInfo();
|
ScannerInfo scannerInfo = new ScannerInfo();
|
||||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, 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.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
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.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
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 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...
|
// 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);
|
return parse(codeReader, lang, useGNUExtensions, expectNoProblems, checkBindings, expectedProblemBindings, problems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class AST2SpecBaseTest extends AST2BaseTest {
|
||||||
// return parse(codeReader, lang, useGNUExtensions, expectNoProblems);
|
// 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,
|
boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings,
|
||||||
int expectedProblemBindings, String[] problems) throws ParserException {
|
int expectedProblemBindings, String[] problems) throws ParserException {
|
||||||
ScannerInfo scannerInfo = new ScannerInfo();
|
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.IASTPreprocessorMacroExpansion;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
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.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
@ -53,7 +53,7 @@ public class ASTNodeSelectorTest extends AST2BaseTest {
|
||||||
|
|
||||||
protected void createTranslationUnit() throws IOException {
|
protected void createTranslationUnit() throws IOException {
|
||||||
fCode= getContents(1)[0].toString();
|
fCode= getContents(1)[0].toString();
|
||||||
CodeReader codeReader = new CodeReader(fCode.toCharArray());
|
FileContent codeReader = FileContent.create("<test-code>", fCode.toCharArray());
|
||||||
ScannerInfo scannerInfo = new ScannerInfo();
|
ScannerInfo scannerInfo = new ScannerInfo();
|
||||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo);
|
IScanner scanner= AST2BaseTest.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
GNUCPPSourceParser parser= new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, new NullLogService(), new GPPParserExtensionConfiguration());
|
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.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
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.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
@ -176,8 +176,7 @@ public class CompleteParser2Tests extends BaseTestCase {
|
||||||
ParserLanguage lang, boolean gcc) throws Exception {
|
ParserLanguage lang, boolean gcc) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
CodeReader codeReader = new CodeReader(code
|
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||||
.toCharArray());
|
|
||||||
ScannerInfo scannerInfo = new ScannerInfo();
|
ScannerInfo scannerInfo = new ScannerInfo();
|
||||||
ISourceCodeParser parser2 = null;
|
ISourceCodeParser parser2 = null;
|
||||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
|
|
|
@ -78,8 +78,6 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
public DOMLocationTests() {
|
public DOMLocationTests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String _TEXT_ = "<text>"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
public DOMLocationTests(String name) {
|
public DOMLocationTests(String name) {
|
||||||
setName(name);
|
setName(name);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +95,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
assertEquals(nodeLocations.length, 1);
|
assertEquals(nodeLocations.length, 1);
|
||||||
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
||||||
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
||||||
assertEquals(fileLocation.getFileName(), _TEXT_);
|
assertEquals(fileLocation.getFileName(), TEST_CODE);
|
||||||
assertEquals(fileLocation.getNodeOffset(), 0);
|
assertEquals(fileLocation.getNodeOffset(), 0);
|
||||||
assertEquals(fileLocation.getNodeLength(), 6);
|
assertEquals(fileLocation.getNodeLength(), 6);
|
||||||
IASTNodeLocation[] tuLocations = tu.getNodeLocations();
|
IASTNodeLocation[] tuLocations = tu.getNodeLocations();
|
||||||
|
@ -120,7 +118,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
assertEquals(nodeLocations.length, 1);
|
assertEquals(nodeLocations.length, 1);
|
||||||
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
||||||
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
||||||
assertEquals(fileLocation.getFileName(), _TEXT_);
|
assertEquals(fileLocation.getFileName(), TEST_CODE);
|
||||||
assertEquals(fileLocation.getNodeOffset(), 0);
|
assertEquals(fileLocation.getNodeOffset(), 0);
|
||||||
assertEquals(fileLocation.getNodeLength(), code.indexOf(";") + 1); //$NON-NLS-1$
|
assertEquals(fileLocation.getNodeLength(), code.indexOf(";") + 1); //$NON-NLS-1$
|
||||||
IASTDeclarator[] declarators = declaration.getDeclarators();
|
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.ICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.POPCPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.POPCPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.POPCPPScannerExtensionConfiguration;
|
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.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
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.c.GNUCSourceParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
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,
|
protected IASTTranslationUnit parse(String code, IScannerExtensionConfiguration sext,
|
||||||
ICPPParserExtensionConfiguration pext) throws Exception {
|
ICPPParserExtensionConfiguration pext) throws Exception {
|
||||||
IScanner scanner=
|
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||||
new CPreprocessor(new CodeReader(code.toCharArray()), new ScannerInfo(), ParserLanguage.CPP, NULL_LOG,
|
IScanner scanner = new CPreprocessor(codeReader, new ScannerInfo(), ParserLanguage.CPP, NULL_LOG,
|
||||||
sext, FileCodeReaderFactory.getInstance());
|
sext, IncludeFileContentProvider.getSavedFilesProvider());
|
||||||
GNUCPPSourceParser parser= new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
GNUCPPSourceParser parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
||||||
return parse(parser);
|
return parse(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IASTTranslationUnit parse(String code, IScannerExtensionConfiguration sext,
|
protected IASTTranslationUnit parse(String code, IScannerExtensionConfiguration sext,
|
||||||
ICParserExtensionConfiguration pext) throws Exception {
|
ICParserExtensionConfiguration pext) throws Exception {
|
||||||
IScanner scanner=
|
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||||
new CPreprocessor(new CodeReader(code.toCharArray()), new ScannerInfo(), ParserLanguage.C, NULL_LOG,
|
IScanner scanner = new CPreprocessor(codeReader, new ScannerInfo(), ParserLanguage.C, NULL_LOG, sext,
|
||||||
sext, FileCodeReaderFactory.getInstance());
|
IncludeFileContentProvider.getSavedFilesProvider());
|
||||||
GNUCSourceParser parser= new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
GNUCSourceParser parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, pext);
|
||||||
return parse(parser);
|
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.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
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.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
|
@ -1363,7 +1363,7 @@ public class QuickParser2Tests extends TestCase {
|
||||||
protected void parse(String code, boolean expectedToPass,
|
protected void parse(String code, boolean expectedToPass,
|
||||||
ParserLanguage lang, boolean gcc) throws Exception {
|
ParserLanguage lang, boolean gcc) throws Exception {
|
||||||
|
|
||||||
CodeReader codeReader = new CodeReader( code.toCharArray() );
|
FileContent codeReader = FileContent.create("<test-code>", code.toCharArray());
|
||||||
IScannerInfo scannerInfo = new ScannerInfo();
|
IScannerInfo scannerInfo = new ScannerInfo();
|
||||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
ISourceCodeParser parser2 = null;
|
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.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
|
@ -51,7 +51,7 @@ public class CompletionTestBase extends BaseTestCase {
|
||||||
private static final IParserLogService NULL_LOG = new NullLogService();
|
private static final IParserLogService NULL_LOG = new NullLogService();
|
||||||
|
|
||||||
protected IASTCompletionNode getCompletionNode(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException {
|
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();
|
ScannerInfo scannerInfo = new ScannerInfo();
|
||||||
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, 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.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
|
@ -89,8 +89,8 @@ public class ASTWriterTest extends RewriteBaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ISourceCodeParser getParser(TestSourceFile testFile) throws Exception {
|
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();
|
ScannerInfo scannerInfo = new ScannerInfo();
|
||||||
ParserLanguage language = getLanguage(testFile);
|
ParserLanguage language = getLanguage(testFile);
|
||||||
boolean useGNUExtensions = getGNUExtension(testFile);
|
boolean useGNUExtensions = getGNUExtension(testFile);
|
||||||
|
|
|
@ -13,7 +13,8 @@ package org.eclipse.cdt.core.parser.tests.scanner;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
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.IToken;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
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.CTestPlugin;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
import org.eclipse.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.CPreprocessor;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.MacroExpander;
|
import org.eclipse.cdt.internal.core.parser.scanner.MacroExpander;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.MacroExpansionTracker;
|
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 {
|
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(),
|
new ScannerInfo(), ParserLanguage.C, new NullLogService(),
|
||||||
GCCScannerExtensionConfiguration.getInstance(), NullCodeReaderFactory.getInstance());
|
GCCScannerExtensionConfiguration.getInstance(), IncludeFileContentProvider.getEmptyFilesProvider());
|
||||||
int type;
|
int type;
|
||||||
do {
|
do {
|
||||||
type= cpp.nextTokenRaw().getType();
|
type= cpp.nextTokenRaw().getType();
|
||||||
|
|
|
@ -10,60 +10,32 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.scanner;
|
package org.eclipse.cdt.core.parser.tests.scanner;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.parser.FileContent;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.EmptyCodeReaderCache;
|
|
||||||
|
|
||||||
/**
|
public class FileCodeReaderFactory extends InternalFileContentProvider {
|
||||||
* @author jcamelon
|
|
||||||
*/
|
|
||||||
public class FileCodeReaderFactory implements ICodeReaderFactory {
|
|
||||||
|
|
||||||
private static FileCodeReaderFactory instance;
|
private static FileCodeReaderFactory instance;
|
||||||
private ICodeReaderCache cache = null;
|
|
||||||
|
|
||||||
private FileCodeReaderFactory(ICodeReaderCache cache)
|
private FileCodeReaderFactory() {}
|
||||||
{
|
|
||||||
this.cache = cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
@Override
|
||||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier()
|
public InternalFileContent getContentForInclusion(String path) {
|
||||||
*/
|
return (InternalFileContent) FileContent.createForExternalFileLocation(path);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
public static FileCodeReaderFactory getInstance() {
|
||||||
if( instance == null )
|
if (instance == null)
|
||||||
instance = new FileCodeReaderFactory(new EmptyCodeReaderCache());
|
instance = new FileCodeReaderFactory();
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICodeReaderCache getCodeReaderCache() {
|
@Override
|
||||||
return cache;
|
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 junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
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.ExtendedScannerInfo;
|
||||||
|
import org.eclipse.cdt.core.parser.FileContent;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
@ -99,7 +99,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
f0.getLocation().removeLastSegments(1) + "/__framework__.framework/__header__"
|
f0.getLocation().removeLastSegments(1) + "/__framework__.framework/__header__"
|
||||||
};
|
};
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
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);
|
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
|
|
||||||
// first file is not picked up (no framework)
|
// first file is not picked up (no framework)
|
||||||
|
@ -130,7 +130,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
path[2] = oneThree.getLocation().toOSString();
|
path[2] = oneThree.getLocation().toOSString();
|
||||||
|
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
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);
|
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
|
|
||||||
validateToken(IToken.t_int);
|
validateToken(IToken.t_int);
|
||||||
|
@ -170,7 +170,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
path[1] = two.getLocation().toOSString();
|
path[1] = two.getLocation().toOSString();
|
||||||
|
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
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);
|
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
|
|
||||||
validateInteger("0");
|
validateInteger("0");
|
||||||
|
@ -208,7 +208,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
path[1] = threef.getLocation().toOSString();
|
path[1] = threef.getLocation().toOSString();
|
||||||
|
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[]{}, null );
|
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);
|
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
|
|
||||||
validateToken(IToken.t_int);
|
validateToken(IToken.t_int);
|
||||||
|
@ -236,7 +236,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
buffer.append( "int var = FOUND;\n"); //$NON-NLS-1$
|
buffer.append( "int var = FOUND;\n"); //$NON-NLS-1$
|
||||||
IFile base = importFile( "base.cpp", buffer.toString() ); //$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};
|
ParserLanguage lang[]= {ParserLanguage.C, ParserLanguage.CPP};
|
||||||
for (ParserLanguage element : lang) {
|
for (ParserLanguage element : lang) {
|
||||||
initializeScanner(reader, element, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
initializeScanner(reader, element, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
||||||
|
@ -254,7 +254,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
StringBuffer buffer = new StringBuffer( "#include \"file.h\"" );
|
StringBuffer buffer = new StringBuffer( "#include \"file.h\"" );
|
||||||
IFile base = importFile( "base.cpp", buffer.toString() ); //$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);
|
||||||
initializeScanner(reader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
initializeScanner(reader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
||||||
validateIdentifier("ok");
|
validateIdentifier("ok");
|
||||||
validateEOF();
|
validateEOF();
|
||||||
|
@ -272,7 +272,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
|
|
||||||
String[] path = {"f2"}; // relative include
|
String[] path = {"f2"}; // relative include
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
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);
|
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||||
|
|
||||||
validateInteger("1");
|
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.core.testplugin.util.TestSourceReader;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
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.ILocationCtx;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ImageLocationInfo;
|
import org.eclipse.cdt.internal.core.parser.scanner.ImageLocationInfo;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.LocationMap;
|
import org.eclipse.cdt.internal.core.parser.scanner.LocationMap;
|
||||||
|
@ -118,7 +119,7 @@ public class LocationMapTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(char[] content) {
|
private void init(char[] content) {
|
||||||
fLocationMap.pushTranslationUnit(FN, content);
|
fLocationMap.pushTranslationUnit(FN, new CharArray(content));
|
||||||
fTu= new CPPASTTranslationUnit();
|
fTu= new CPPASTTranslationUnit();
|
||||||
fTu.setLocationResolver(fLocationMap);
|
fTu.setLocationResolver(fLocationMap);
|
||||||
}
|
}
|
||||||
|
@ -489,18 +490,18 @@ public class LocationMapTests extends BaseTestCase {
|
||||||
assertEquals(FN, fLocationMap.getTranslationUnitPath());
|
assertEquals(FN, fLocationMap.getTranslationUnitPath());
|
||||||
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||||
// number: [30,36)[46,50)
|
// 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());
|
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||||
// number: [0,6)[26,30)
|
// 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());
|
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||||
fLocationMap.encounteredComment(0,2,true);
|
fLocationMap.encounteredComment(0,2,true);
|
||||||
// number: [6,15)[25,26)
|
// 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());
|
assertEquals("pre1", fLocationMap.getCurrentFilePath());
|
||||||
fLocationMap.encounteredComment(2,4,true);
|
fLocationMap.encounteredComment(2,4,true);
|
||||||
// number: [15,25)
|
// 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());
|
assertEquals("pre11", fLocationMap.getCurrentFilePath());
|
||||||
fLocationMap.encounteredComment(2,6,true);
|
fLocationMap.encounteredComment(2,6,true);
|
||||||
fLocationMap.popContext(i2);
|
fLocationMap.popContext(i2);
|
||||||
|
@ -513,7 +514,7 @@ public class LocationMapTests extends BaseTestCase {
|
||||||
fLocationMap.popContext(pre2);
|
fLocationMap.popContext(pre2);
|
||||||
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
assertEquals(FN, fLocationMap.getCurrentFilePath());
|
||||||
// number [36, 46)
|
// 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());
|
assertEquals("pre2", fLocationMap.getCurrentFilePath());
|
||||||
fLocationMap.encounteredComment(0,2,true);
|
fLocationMap.encounteredComment(0,2,true);
|
||||||
fLocationMap.popContext(i3);
|
fLocationMap.popContext(i3);
|
||||||
|
|
|
@ -16,11 +16,10 @@ import java.io.PrintStream;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map;
|
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.IScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
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.EndOfFileException;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
|
@ -62,7 +61,7 @@ public class PreprocessorSpeedTest {
|
||||||
"#include <stdio.h>\n" +
|
"#include <stdio.h>\n" +
|
||||||
"#include <iostream>\n";
|
"#include <iostream>\n";
|
||||||
|
|
||||||
CodeReader reader = new CodeReader(code.toCharArray());
|
FileContent reader = FileContent.create("<test-code>", code.toCharArray());
|
||||||
IScannerInfo info = getScannerInfo();
|
IScannerInfo info = getScannerInfo();
|
||||||
long totalTime = 0;
|
long totalTime = 0;
|
||||||
for (int i = 0; i < n; ++i) {
|
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 {
|
protected long testScan(FileContent reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
||||||
ICodeReaderFactory readerFactory= FileCodeReaderFactory.getInstance();
|
FileCodeReaderFactory readerFactory= FileCodeReaderFactory.getInstance();
|
||||||
IScannerExtensionConfiguration scannerConfig;
|
IScannerExtensionConfiguration scannerConfig;
|
||||||
if (lang == ParserLanguage.C) {
|
if (lang == ParserLanguage.C) {
|
||||||
scannerConfig= GCCScannerExtensionConfiguration.getInstance();
|
scannerConfig= GCCScannerExtensionConfiguration.getInstance();
|
||||||
|
|
|
@ -14,13 +14,13 @@ import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.ComparisonFailure;
|
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.IASTProblem;
|
||||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
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.EndOfFileException;
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
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 {
|
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 {
|
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 {
|
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);
|
initializeScanner(input, lang, mode, scannerInfo, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initializeScanner(CodeReader input, ParserLanguage lang, ParserMode mode, IScannerInfo scannerInfo, IScannerExtensionConfiguration scannerConfig) throws IOException {
|
protected void initializeScanner(FileContent input, ParserLanguage lang, ParserMode mode, IScannerInfo scannerInfo, IScannerExtensionConfiguration scannerConfig) throws IOException {
|
||||||
ICodeReaderFactory readerFactory= FileCodeReaderFactory.getInstance();
|
IncludeFileContentProvider readerFactory= FileCodeReaderFactory.getInstance();
|
||||||
//IScannerExtensionConfiguration scannerConfig;
|
//IScannerExtensionConfiguration scannerConfig;
|
||||||
|
|
||||||
if(scannerConfig == null) {
|
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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -12,11 +12,15 @@
|
||||||
package org.eclipse.cdt.core.model;
|
package org.eclipse.cdt.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
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.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
|
||||||
|
@ -36,9 +40,40 @@ public abstract class AbstractLanguage extends PlatformObject implements ILangua
|
||||||
return getId();
|
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 {
|
throws CoreException {
|
||||||
// for backwards compatibility
|
// For backwards compatibility, should be overridden.
|
||||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, log);
|
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.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ import org.eclipse.core.runtime.IAdaptable;
|
||||||
public interface ILanguage extends 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.
|
* Instructs the parser to skip function and method bodies.
|
||||||
*/
|
*/
|
||||||
public final static int OPTION_SKIP_FUNCTION_BODIES= 0x1;
|
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;
|
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.
|
* Performance optimization, allows the parser not to create image-locations.
|
||||||
* When using this option {@link IASTName#getImageLocation()} will always return <code>null</code>.
|
* When using this option {@link IASTName#getImageLocation()} will always return <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public final static int OPTION_NO_IMAGE_LOCATIONS= 0x4;
|
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
|
* 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.
|
* 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;
|
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
|
* Allows the parser not to create ast nodes for expressions within aggregate initializers
|
||||||
* when they do not contain names.
|
* when they do not contain names.
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
|
@ -70,7 +71,7 @@ public interface ILanguage extends IAdaptable {
|
||||||
public final static int OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS= 0x10;
|
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
|
* 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
|
* 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.).
|
* of the inactive code (e.g. function bodies, entire code branches, etc.).
|
||||||
|
@ -103,19 +104,33 @@ public interface ILanguage extends IAdaptable {
|
||||||
public String getName();
|
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
|
* @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
|
* Return the AST completion node for the given offset.
|
||||||
* and length in the given ITranslationUnit.
|
* @since 5.2
|
||||||
* @deprecated use {@link IASTTranslationUnit#getNodeSelector(String)}, instead.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public IASTCompletionNode getCompletionNode(FileContent reader, IScannerInfo scanInfo,
|
||||||
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length);
|
IncludeFileContentProvider fileCreator, IIndex index, IParserLogService log, int offset)
|
||||||
|
throws CoreException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to override the default model building behavior for a translation unit.
|
* 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);
|
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>.
|
* @deprecated replaced by {@link IASTTranslationUnit#getNodeSelector(String)}.
|
||||||
* 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
|
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
@Deprecated
|
||||||
ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log)
|
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;
|
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.IASTDeclarationListOwner;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
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.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -414,14 +414,6 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
||||||
*/
|
*/
|
||||||
public IPath getLocation();
|
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
|
* Returns the scanner info associated with this translation unit. May return <code>null</code> if no
|
||||||
* configuration is available.
|
* configuration is available.
|
||||||
|
@ -488,4 +480,11 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
||||||
* @deprecated don't use this method.
|
* @deprecated don't use this method.
|
||||||
*/
|
*/
|
||||||
@Deprecated Map<?,?> parse();
|
@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.IUsing;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.core.model.LanguageManager;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
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.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
||||||
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.parser.InternalParserUtil;
|
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserLogService;
|
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.ProjectIndexerIncludeResolutionHeuristics;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
|
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
|
||||||
import org.eclipse.cdt.internal.core.util.ICanceler;
|
import org.eclipse.cdt.internal.core.util.ICanceler;
|
||||||
|
@ -770,14 +769,12 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeReader reader;
|
FileContent fileContent= FileContent.create(this);
|
||||||
reader = getCodeReader();
|
if (fileContent != null) {
|
||||||
|
|
||||||
if (reader != null) {
|
|
||||||
ILanguage language= configureWith.getLanguage();
|
ILanguage language= configureWith.getLanguage();
|
||||||
fLanguageOfContext= language;
|
fLanguageOfContext= language;
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
AbstractCodeReaderFactory crf= getCodeReaderFactory(style, index, language.getLinkageID());
|
IncludeFileContentProvider crf= getIncludeFileContentProvider(style, index, language.getLinkageID());
|
||||||
int options= 0;
|
int options= 0;
|
||||||
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
|
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
|
||||||
options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
|
options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
|
||||||
|
@ -797,34 +794,36 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
} else {
|
} else {
|
||||||
log= ParserUtil.getParserLogService();
|
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;
|
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 ICProject cprj= getCProject();
|
||||||
final ProjectIndexerInputAdapter pathResolver = new ProjectIndexerInputAdapter(cprj);
|
final ProjectIndexerInputAdapter pathResolver = new ProjectIndexerInputAdapter(cprj);
|
||||||
final ProjectIndexerIncludeResolutionHeuristics heuristics = new ProjectIndexerIncludeResolutionHeuristics(cprj.getProject(), pathResolver);
|
IncludeFileContentProvider fileContentsProvider;
|
||||||
AbstractCodeReaderFactory codeReaderFactory;
|
|
||||||
if ((style & AST_SKIP_NONINDEXED_HEADERS) != 0) {
|
if ((style & AST_SKIP_NONINDEXED_HEADERS) != 0) {
|
||||||
codeReaderFactory= NullCodeReaderFactory.getInstance();
|
fileContentsProvider= IncludeFileContentProvider.getEmptyFilesProvider();
|
||||||
} else {
|
} else {
|
||||||
codeReaderFactory= SavedCodeReaderFactory.createInstance(heuristics);
|
fileContentsProvider= IncludeFileContentProvider.getSavedFilesProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index != null && (style & AST_SKIP_INDEXED_HEADERS) != 0) {
|
if (index != null && (style & AST_SKIP_INDEXED_HEADERS) != 0) {
|
||||||
IndexBasedCodeReaderFactory ibcf= new IndexBasedCodeReaderFactory(index,
|
IndexBasedFileContentProvider ibcf= new IndexBasedFileContentProvider(index, pathResolver, linkageID, fileContentsProvider);
|
||||||
heuristics,
|
|
||||||
pathResolver, linkageID, codeReaderFactory);
|
|
||||||
if ((style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) {
|
if ((style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) {
|
||||||
ibcf.setSupportFillGapFromContextToHeader(true);
|
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};
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeReader reader;
|
FileContent fileContent= FileContent.create(this);
|
||||||
reader = getCodeReader();
|
|
||||||
|
|
||||||
ILanguage language= configureWith.getLanguage();
|
ILanguage language= configureWith.getLanguage();
|
||||||
fLanguageOfContext= language;
|
fLanguageOfContext= language;
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
AbstractCodeReaderFactory crf= getCodeReaderFactory(style, index, language.getLinkageID());
|
IncludeFileContentProvider crf= getIncludeFileContentProvider(style, index, language.getLinkageID());
|
||||||
return language.getCompletionNode(reader, scanInfo, crf, index, ParserUtil.getParserLogService(), offset);
|
return language.getCompletionNode(fileContent, scanInfo, crf, index, ParserUtil.getParserLogService(), offset);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodeReader getCodeReader() {
|
@Deprecated
|
||||||
|
public org.eclipse.cdt.core.parser.CodeReader getCodeReader() {
|
||||||
IPath location= getLocation();
|
IPath location= getLocation();
|
||||||
if (location == null)
|
if (location == null)
|
||||||
return new CodeReader(getContents());
|
return new org.eclipse.cdt.core.parser.CodeReader(getContents());
|
||||||
if (isWorkingCopy()) {
|
if (isWorkingCopy()) {
|
||||||
return new CodeReader(location.toOSString(), getContents());
|
return new org.eclipse.cdt.core.parser.CodeReader(location.toOSString(), getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
IResource res= getResource();
|
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.ICLanguageKeywords;
|
||||||
import org.eclipse.cdt.core.model.IContributedModelBuilder;
|
import org.eclipse.cdt.core.model.IContributedModelBuilder;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
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.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||||
|
@ -101,24 +102,32 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
||||||
protected abstract ParserLanguage getParserLanguage();
|
protected abstract ParserLanguage getParserLanguage();
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||||
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException {
|
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log)
|
||||||
|
throws CoreException {
|
||||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
|
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
|
@Override
|
||||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
public IASTTranslationUnit getASTTranslationUnit(FileContent reader, IScannerInfo scanInfo,
|
||||||
ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException {
|
IncludeFileContentProvider fileCreator, IIndex index, int options, IParserLogService log)
|
||||||
|
throws CoreException {
|
||||||
final IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log);
|
final IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
|
||||||
scanner.setComputeImageLocations((options & OPTION_NO_IMAGE_LOCATIONS) == 0);
|
scanner.setComputeImageLocations((options & OPTION_NO_IMAGE_LOCATIONS) == 0);
|
||||||
scanner.setProcessInactiveCode((options & OPTION_PARSE_INACTIVE_CODE) != 0);
|
scanner.setProcessInactiveCode((options & OPTION_PARSE_INACTIVE_CODE) != 0);
|
||||||
|
|
||||||
final ISourceCodeParser parser= createParser(scanner, log, index, false, options);
|
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;
|
ICanceler canceler= null;
|
||||||
if (log instanceof ICanceler) {
|
if (log instanceof ICanceler) {
|
||||||
canceler= (ICanceler) log;
|
canceler= (ICanceler) log;
|
||||||
|
@ -140,10 +149,18 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
|
@Deprecated
|
||||||
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
|
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);
|
IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
|
||||||
scanner.setContentAssistMode(offset);
|
scanner.setContentAssistMode(offset);
|
||||||
|
@ -164,7 +181,7 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
||||||
* @param log the parser log service
|
* @param log the parser log service
|
||||||
* @param index the index to help resolve bindings
|
* @param index the index to help resolve bindings
|
||||||
* @param forCompletion whether the parser is used for code completion
|
* @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
|
* @return an instance of ISourceCodeParser
|
||||||
*/
|
*/
|
||||||
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) {
|
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.
|
* @deprecated replaced by {@link #createScanner(FileContent, IScannerInfo, IncludeFileContentProvider, IParserLogService)}
|
||||||
*
|
|
||||||
* @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
|
|
||||||
*/
|
*/
|
||||||
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
|
@Deprecated
|
||||||
return new CPreprocessor(reader, scanInfo, getParserLanguage(), log, getScannerExtensionConfiguration(), fileCreator);
|
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) {
|
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
|
||||||
IASTNode selectedNode= ast.getNodeSelector(null).findNode(start, 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.
|
* Reads the content of a file into a char[] buffer.
|
||||||
*
|
*
|
||||||
* @noextend This class is not intended to be subclassed by clients.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
|
* @deprecated replaced by {@link FileContent}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class CodeReader {
|
public class CodeReader {
|
||||||
public static final String SYSTEM_DEFAULT_ENCODING = System.getProperty("file.encoding"); //$NON-NLS-1$
|
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.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
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.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.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
* @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) {
|
if (fIndexFileSet != null) {
|
||||||
List<IIndexFile> files= fileContent.getFilesIncluded();
|
List<IIndexFile> files= fileContent.getFilesIncluded();
|
||||||
for (IIndexFile indexFile : files) {
|
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.IASTAmbiguityParent;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
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.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.
|
* 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)
|
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
public void skippedFile(int offset, InternalFileContent fileContent) {
|
||||||
super.skippedFile(offset, fileContent);
|
super.skippedFile(offset, fileContent);
|
||||||
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.index;
|
package org.eclipse.cdt.internal.core.index;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
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.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IIndexInclude;
|
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||||
import org.eclipse.cdt.internal.core.dom.AbstractCodeReaderFactory;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent.InclusionKind;
|
||||||
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.internal.core.pdom.ASTFilePathResolver;
|
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
|
||||||
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
|
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;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Code reader factory, that fakes code readers for header files already stored in the
|
* Code reader factory, that fakes code readers for header files already stored in the
|
||||||
* index.
|
* 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 class NeedToParseException extends Exception {}
|
||||||
private static final String GAP = "__gap__"; //$NON-NLS-1$
|
private static final String GAP = "__gap__"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -54,22 +48,20 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
private int fLinkage;
|
private int fLinkage;
|
||||||
private Set<IIndexFileLocation> fIncludedFiles= new HashSet<IIndexFileLocation>();
|
private Set<IIndexFileLocation> fIncludedFiles= new HashSet<IIndexFileLocation>();
|
||||||
/** The fall-back code reader factory used in case a header file is not indexed */
|
/** 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 ASTFilePathResolver fPathResolver;
|
||||||
private final AbstractIndexerTask fRelatedIndexerTask;
|
private final AbstractIndexerTask fRelatedIndexerTask;
|
||||||
private boolean fSupportFillGapFromContextToHeader= false;
|
private boolean fSupportFillGapFromContextToHeader= false;
|
||||||
|
|
||||||
public IndexBasedCodeReaderFactory(IIndex index, IIncludeFileResolutionHeuristics heuristics,
|
public IndexBasedFileContentProvider(IIndex index,
|
||||||
ASTFilePathResolver pathResolver, int linkage, AbstractCodeReaderFactory fallbackFactory) {
|
ASTFilePathResolver pathResolver, int linkage, IncludeFileContentProvider fallbackFactory) {
|
||||||
this(index, heuristics, pathResolver, linkage, fallbackFactory, null);
|
this(index, pathResolver, linkage, fallbackFactory, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexBasedCodeReaderFactory(IIndex index, IIncludeFileResolutionHeuristics heuristics,
|
public IndexBasedFileContentProvider(IIndex index, ASTFilePathResolver pathResolver, int linkage,
|
||||||
ASTFilePathResolver pathResolver, int linkage,
|
IncludeFileContentProvider fallbackFactory, AbstractIndexerTask relatedIndexerTask) {
|
||||||
AbstractCodeReaderFactory fallbackFactory, AbstractIndexerTask relatedIndexerTask) {
|
|
||||||
super(heuristics);
|
|
||||||
fIndex= index;
|
fIndex= index;
|
||||||
fFallBackFactory= fallbackFactory;
|
fFallBackFactory= (InternalFileContentProvider) fallbackFactory;
|
||||||
fPathResolver= pathResolver;
|
fPathResolver= pathResolver;
|
||||||
fRelatedIndexerTask= relatedIndexerTask;
|
fRelatedIndexerTask= relatedIndexerTask;
|
||||||
fLinkage= linkage;
|
fLinkage= linkage;
|
||||||
|
@ -87,52 +79,25 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
fIncludedFiles.clear();
|
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
|
@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) {
|
public boolean getInclusionExists(String path) {
|
||||||
return fPathResolver.doesIncludeFileExist(path);
|
return fPathResolver.doesIncludeFileExist(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void reportTranslationUnitFile(String path) {
|
public void reportTranslationUnitFile(String path) {
|
||||||
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
||||||
fIncludedFiles.add(ifl);
|
fIncludedFiles.add(ifl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
@Override
|
||||||
|
public Boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||||
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
||||||
return fIncludedFiles.contains(ifl);
|
return fIncludedFiles.contains(ifl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IncludeFileContent getContentForInclusion(String path) {
|
@Override
|
||||||
|
public InternalFileContent getContentForInclusion(String path) {
|
||||||
IIndexFileLocation ifl= fPathResolver.resolveIncludeFile(path);
|
IIndexFileLocation ifl= fPathResolver.resolveIncludeFile(path);
|
||||||
if (ifl == null) {
|
if (ifl == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -141,7 +106,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
|
|
||||||
// include files once, only.
|
// include files once, only.
|
||||||
if (!fIncludedFiles.add(ifl)) {
|
if (!fIncludedFiles.add(ifl)) {
|
||||||
return new IncludeFileContent(path, InclusionKind.SKIP_FILE);
|
return new InternalFileContent(path, InclusionKind.SKIP_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -155,7 +120,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
collectFileContent(file, ifls, files, macros, directives, false);
|
collectFileContent(file, ifls, files, macros, directives, false);
|
||||||
// add included files only, if no exception was thrown
|
// add included files only, if no exception was thrown
|
||||||
fIncludedFiles.addAll(ifls);
|
fIncludedFiles.addAll(ifls);
|
||||||
return new IncludeFileContent(path, macros, directives, files);
|
return new InternalFileContent(path, macros, directives, files);
|
||||||
} catch (NeedToParseException e) {
|
} catch (NeedToParseException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,21 +129,22 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (fFallBackFactory != null) {
|
||||||
CodeReader codeReader= createCodeReaderForInclusion(ifl, path);
|
InternalFileContent ifc= getContentForInclusion(ifl, path);
|
||||||
if (codeReader != null) {
|
if (ifc != null)
|
||||||
IncludeFileContent ifc= new IncludeFileContent(codeReader);
|
|
||||||
ifc.setIsSource(fPathResolver.isSource(path));
|
ifc.setIsSource(fPathResolver.isSource(path));
|
||||||
return ifc;
|
return ifc;
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
}
|
}
|
||||||
return null;
|
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,
|
private void collectFileContent(IIndexFile file, Set<IIndexFileLocation> ifls, List<IIndexFile> files,
|
||||||
List<IIndexMacro> macros, List<ICPPUsingDirective> usingDirectives, boolean checkIncluded)
|
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))) {
|
if (!ifls.add(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileContent content;
|
IndexFileContent content;
|
||||||
if (fRelatedIndexerTask != null) {
|
if (fRelatedIndexerTask != null) {
|
||||||
content= fRelatedIndexerTask.getFileContent(fLinkage, ifl);
|
content= fRelatedIndexerTask.getFileContent(fLinkage, ifl);
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
throw new NeedToParseException();
|
throw new NeedToParseException();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
content= new FileContent();
|
content= new IndexFileContent();
|
||||||
content.setPreprocessorDirectives(file.getIncludes(), file.getMacros());
|
content.setPreprocessorDirectives(file.getIncludes(), file.getMacros());
|
||||||
content.setUsingDirectives(file.getUsingDirectives());
|
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) {
|
if (!fSupportFillGapFromContextToHeader) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +213,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
for (IIndexFile file : filesIncluded) {
|
for (IIndexFile file : filesIncluded) {
|
||||||
fIncludedFiles.add(file.getLocation());
|
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) {
|
catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
|
@ -284,7 +251,7 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
|
|
||||||
final IIndexInclude[] ids= from.getIncludes();
|
final IIndexInclude[] ids= from.getIncludes();
|
||||||
final IIndexMacro[] ms= from.getMacros();
|
final IIndexMacro[] ms= from.getMacros();
|
||||||
final Object[] dirs= FileContent.merge(ids, ms);
|
final Object[] dirs= IndexFileContent.merge(ids, ms);
|
||||||
IIndexInclude success= null;
|
IIndexInclude success= null;
|
||||||
for (Object d : dirs) {
|
for (Object d : dirs) {
|
||||||
if (d instanceof IIndexMacro) {
|
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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.indexer;
|
||||||
|
|
||||||
import java.util.List;
|
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;
|
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,8 +36,8 @@ public class StandaloneFastIndexerTask extends StandaloneIndexerTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
protected IncludeFileContentProvider createReaderFactory() {
|
||||||
return new StandaloneIndexerFallbackReaderFactory();
|
return IncludeFileContentProvider.adapt(new StandaloneIndexerFallbackReaderFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.indexer;
|
||||||
|
|
||||||
import java.util.List;
|
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;
|
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,8 +37,8 @@ public class StandaloneFullIndexerTask extends StandaloneIndexerTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
protected IncludeFileContentProvider createReaderFactory() {
|
||||||
return ((StandaloneFullIndexer)fIndexer).getCodeReaderFactory();
|
return IncludeFileContentProvider.adapt(((StandaloneFullIndexer)fIndexer).getCodeReaderFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.util.HashMap;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
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.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
|
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
|
||||||
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
|
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
|
||||||
|
@ -123,12 +123,8 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodeReader getCodeReader(Object tu) {
|
public FileContent getCodeReader(Object tu) {
|
||||||
try {
|
return FileContent.createForExternalFileLocation((String) tu);
|
||||||
return new CodeReader((String) tu);
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
package org.eclipse.cdt.internal.core.parser;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
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.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.cdt.internal.core.resources.PathCanonicalizationStrategy;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -31,6 +35,7 @@ import org.eclipse.core.runtime.Path;
|
||||||
* Utility for creating code readers
|
* Utility for creating code readers
|
||||||
*/
|
*/
|
||||||
public class InternalParserUtil extends ParserFactory {
|
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.
|
* 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
|
* Creates a code reader for an external location, normalizing path to
|
||||||
* canonical path. The cache is consulted after the path has been normalized.
|
* 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);
|
File includeFile = new File(externalLocation);
|
||||||
if (includeFile.isFile()) {
|
if (includeFile.isFile()) {
|
||||||
// Use the canonical path so that in case of non-case-sensitive OSs
|
// 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.
|
// no differences in case.
|
||||||
final String path = PathCanonicalizationStrategy.getCanonicalPath(includeFile);
|
final String path = PathCanonicalizationStrategy.getCanonicalPath(includeFile);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
CodeReader result= cache.get(path);
|
org.eclipse.cdt.core.parser.CodeReader result= cache.get(path);
|
||||||
if (result != null)
|
if (result != null)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CodeReader(path);
|
return new org.eclipse.cdt.core.parser.CodeReader(path);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -68,11 +75,13 @@ public class InternalParserUtil extends ParserFactory {
|
||||||
/**
|
/**
|
||||||
* Creates a code reader for an external location, normalizing path to
|
* Creates a code reader for an external location, normalizing path to
|
||||||
* canonical path.
|
* 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);
|
path = normalizePath(path, file);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
CodeReader result= cache.get(path);
|
org.eclipse.cdt.core.parser.CodeReader result= cache.get(path);
|
||||||
if (result != null)
|
if (result != null)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +100,7 @@ public class InternalParserUtil extends ParserFactory {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return new CodeReader(path, file.getCharset(), in);
|
return new org.eclipse.cdt.core.parser.CodeReader(path, file.getCharset(), in);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
in.close();
|
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();
|
String fullPath= ifl.getFullPath();
|
||||||
if (fullPath != null) {
|
if (fullPath != null) {
|
||||||
IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(fullPath));
|
IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(fullPath));
|
||||||
|
@ -109,4 +124,85 @@ public class InternalParserUtil extends ParserFactory {
|
||||||
}
|
}
|
||||||
return createExternalFileReader(ifl.getURI().getPath(), cache);
|
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.
|
* Abstract class for providing input to the lexer.
|
||||||
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractCharArray {
|
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
|
* Checks whether the given offset is valid for this array. Subclasses may assume
|
||||||
* that offset is non-negative.
|
* that offset is non-negative.
|
||||||
*/
|
*/
|
||||||
public abstract boolean isValidOffset(int offset);
|
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.
|
* 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.List;
|
||||||
import java.util.Map;
|
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.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
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.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.IExtendedScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IMacro;
|
import org.eclipse.cdt.core.parser.IMacro;
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
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.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
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.Keywords;
|
||||||
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
||||||
import org.eclipse.cdt.core.parser.ParseError;
|
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.CharArrayMap;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
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.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.Lexer.LexerOptions;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.MacroDefinitionParser.InvalidMacroDefinitionException;
|
import org.eclipse.cdt.internal.core.parser.scanner.MacroDefinitionParser.InvalidMacroDefinitionException;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerContext.BranchKind;
|
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);
|
T checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
final private IIncludeFileTester<IncludeFileContent> createCodeReaderTester= new IIncludeFileTester<IncludeFileContent>() {
|
final private IIncludeFileTester<InternalFileContent> createCodeReaderTester= new IIncludeFileTester<InternalFileContent>() {
|
||||||
public IncludeFileContent checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
|
public InternalFileContent checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
|
||||||
final IncludeFileContent fc= fCodeReaderFactory.getContentForInclusion(path);
|
final InternalFileContent fc= fFileContentProvider.getContentForInclusion(path);
|
||||||
if (fc != null) {
|
if (fc != null) {
|
||||||
fc.setFoundByHeuristics(isHeuristicMatch);
|
fc.setFoundByHeuristics(isHeuristicMatch);
|
||||||
fc.setFoundOnPath(onPath);
|
fc.setFoundOnPath(onPath);
|
||||||
|
@ -112,7 +112,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
private static class IncludeResolution {String fLocation; boolean fHeuristic;}
|
private static class IncludeResolution {String fLocation; boolean fHeuristic;}
|
||||||
final private IIncludeFileTester<IncludeResolution> createPathTester= new IIncludeFileTester<IncludeResolution>() {
|
final private IIncludeFileTester<IncludeResolution> createPathTester= new IIncludeFileTester<IncludeResolution>() {
|
||||||
public IncludeResolution checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
|
public IncludeResolution checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
|
||||||
if (fCodeReaderFactory.getInclusionExists(path)) {
|
if (fFileContentProvider.getInclusionExists(path)) {
|
||||||
IncludeResolution res= new IncludeResolution();
|
IncludeResolution res= new IncludeResolution();
|
||||||
res.fHeuristic= isHeuristicMatch;
|
res.fHeuristic= isHeuristicMatch;
|
||||||
res.fLocation= path;
|
res.fLocation= path;
|
||||||
|
@ -154,7 +154,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
TokenSequence fLineInputToMacroExpansion= new TokenSequence(true);
|
TokenSequence fLineInputToMacroExpansion= new TokenSequence(true);
|
||||||
|
|
||||||
final private IParserLogService fLog;
|
final private IParserLogService fLog;
|
||||||
final private IIndexBasedCodeReaderFactory fCodeReaderFactory;
|
final private InternalFileContentProvider fFileContentProvider;
|
||||||
|
|
||||||
private IIncludeFileResolutionHeuristics fIncludeFileResolutionHeuristics;
|
private IIncludeFileResolutionHeuristics fIncludeFileResolutionHeuristics;
|
||||||
private final ExpressionEvaluator fExpressionEvaluator;
|
private final ExpressionEvaluator fExpressionEvaluator;
|
||||||
|
@ -190,8 +190,22 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
private Token fLastToken;
|
private Token fLastToken;
|
||||||
|
|
||||||
|
|
||||||
public CPreprocessor(CodeReader reader, IScannerInfo info, ParserLanguage language, IParserLogService log,
|
public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language, IParserLogService log,
|
||||||
IScannerExtensionConfiguration configuration, ICodeReaderFactory readerFactory) {
|
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;
|
fLog = log;
|
||||||
fAdditionalNumericLiteralSuffixes= nonNull(configuration.supportAdditionalNumericLiteralSuffixes());
|
fAdditionalNumericLiteralSuffixes= nonNull(configuration.supportAdditionalNumericLiteralSuffixes());
|
||||||
fLexOptions.fSupportDollarInIdentifiers= configuration.support$InIdentifiers();
|
fLexOptions.fSupportDollarInIdentifiers= configuration.support$InIdentifiers();
|
||||||
|
@ -207,20 +221,16 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
fExpressionEvaluator= new ExpressionEvaluator();
|
fExpressionEvaluator= new ExpressionEvaluator();
|
||||||
fMacroDefinitionParser= new MacroDefinitionParser();
|
fMacroDefinitionParser= new MacroDefinitionParser();
|
||||||
fMacroExpander= new MacroExpander(this, fMacroDictionary, fLocationMap, fLexOptions);
|
fMacroExpander= new MacroExpander(this, fMacroDictionary, fLocationMap, fLexOptions);
|
||||||
fCodeReaderFactory= wrapReaderFactory(readerFactory);
|
fIncludeFileResolutionHeuristics= fFileContentProvider.getIncludeHeuristics();
|
||||||
if (readerFactory instanceof IAdaptable) {
|
|
||||||
fIncludeFileResolutionHeuristics= (IIncludeFileResolutionHeuristics) ((IAdaptable) readerFactory).getAdapter(IIncludeFileResolutionHeuristics.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String filePath= new String(reader.filename);
|
final String filePath= content.getFileLocation();
|
||||||
configureIncludeSearchPath(new File(filePath).getParentFile(), info);
|
configureIncludeSearchPath(new File(filePath).getParentFile(), info);
|
||||||
setupMacroDictionary(configuration, info, language);
|
setupMacroDictionary(configuration, info, language);
|
||||||
|
|
||||||
|
ILocationCtx ctx= fLocationMap.pushTranslationUnit(filePath, content.getSource());
|
||||||
fAllIncludedFiles.add(filePath);
|
fAllIncludedFiles.add(filePath);
|
||||||
ILocationCtx ctx= fLocationMap.pushTranslationUnit(filePath, reader.buffer);
|
fFileContentProvider.reportTranslationUnitFile(filePath);
|
||||||
fCodeReaderFactory.reportTranslationUnitFile(filePath);
|
fRootLexer= new Lexer(content.getSource(), fLexOptions, this, this);
|
||||||
fAllIncludedFiles.add(filePath);
|
|
||||||
fRootLexer= new Lexer(reader.buffer, fLexOptions, this, this);
|
|
||||||
fRootContext= fCurrentContext= new ScannerContext(ctx, null, fRootLexer);
|
fRootContext= fCurrentContext= new ScannerContext(ctx, null, fRootLexer);
|
||||||
if (info instanceof IExtendedScannerInfo) {
|
if (info instanceof IExtendedScannerInfo) {
|
||||||
final IExtendedScannerInfo einfo= (IExtendedScannerInfo) info;
|
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) {
|
public void setComputeImageLocations(boolean val) {
|
||||||
fLexOptions.fCreateImageLocations= val;
|
fLexOptions.fCreateImageLocations= val;
|
||||||
|
@ -383,7 +355,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
handlePreIncludedFiles();
|
handlePreIncludedFiles();
|
||||||
}
|
}
|
||||||
final String location = fLocationMap.getTranslationUnitPath();
|
final String location = fLocationMap.getTranslationUnitPath();
|
||||||
IncludeFileContent content= fCodeReaderFactory.getContentForContextToHeaderGap(location);
|
InternalFileContent content= fFileContentProvider.getContentForContextToHeaderGap(location);
|
||||||
if (content != null && content.getKind() == InclusionKind.FOUND_IN_INDEX) {
|
if (content != null && content.getKind() == InclusionKind.FOUND_IN_INDEX) {
|
||||||
processInclusionFromIndex(0, location, content);
|
processInclusionFromIndex(0, location, content);
|
||||||
}
|
}
|
||||||
|
@ -393,7 +365,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
final String[] imacro= fPreIncludedFiles[0];
|
final String[] imacro= fPreIncludedFiles[0];
|
||||||
if (imacro != null && imacro.length > 0) {
|
if (imacro != null && imacro.length > 0) {
|
||||||
final char[] buffer= createSyntheticFile(imacro);
|
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));
|
fCurrentContext= new ScannerContext(ctx, fCurrentContext, new Lexer(buffer, fLexOptions, this, this));
|
||||||
ScannerContext preCtx= fCurrentContext;
|
ScannerContext preCtx= fCurrentContext;
|
||||||
try {
|
try {
|
||||||
|
@ -410,7 +382,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
final String[] include= fPreIncludedFiles[1];
|
final String[] include= fPreIncludedFiles[1];
|
||||||
if (include != null && include.length > 0) {
|
if (include != null && include.length > 0) {
|
||||||
final char[] buffer= createSyntheticFile(include);
|
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));
|
fCurrentContext= new ScannerContext(ctx, fCurrentContext, new Lexer(buffer, fLexOptions, this, this));
|
||||||
}
|
}
|
||||||
fPreIncludedFiles= null;
|
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 {
|
private void executeInclude(final Lexer lexer, int poundOffset, boolean include_next, boolean active, boolean withinExpansion) throws OffsetLimitReachedException {
|
||||||
if (withinExpansion) {
|
if (withinExpansion) {
|
||||||
final char[] name= lexer.currentToken().getCharImage();
|
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)
|
// test if the include is inactive just because it was included before (bug 167100)
|
||||||
final IncludeResolution resolved= findInclusion(includeDirective, userInclude, include_next,
|
final IncludeResolution resolved= findInclusion(includeDirective, userInclude, include_next,
|
||||||
getCurrentFilename(), createPathTester);
|
getCurrentFilename(), createPathTester);
|
||||||
if (resolved != null && fCodeReaderFactory.hasFileBeenIncludedInCurrentTranslationUnit(resolved.fLocation)) {
|
if (resolved != null && hasFileBeenIncluded(resolved.fLocation)) {
|
||||||
path= resolved.fLocation;
|
path= resolved.fLocation;
|
||||||
isHeuristic= resolved.fHeuristic;
|
isHeuristic= resolved.fHeuristic;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final IncludeFileContent fi= findInclusion(includeDirective, userInclude, include_next,
|
final InternalFileContent fi= findInclusion(includeDirective, userInclude, include_next,
|
||||||
getCurrentFilename(), createCodeReaderTester);
|
getCurrentFilename(), createCodeReaderTester);
|
||||||
if (fi != null) {
|
if (fi != null) {
|
||||||
path= fi.getFileLocation();
|
path= fi.getFileLocation();
|
||||||
|
@ -1196,14 +1176,14 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
case FOUND_IN_INDEX:
|
case FOUND_IN_INDEX:
|
||||||
processInclusionFromIndex(poundOffset, path, fi);
|
processInclusionFromIndex(poundOffset, path, fi);
|
||||||
break;
|
break;
|
||||||
case USE_CODE_READER:
|
case USE_SOURCE:
|
||||||
CodeReader reader= fi.getCodeReader();
|
AbstractCharArray source= fi.getSource();
|
||||||
if (reader != null && !isCircularInclusion(path)) {
|
if (source != null && !isCircularInclusion(path)) {
|
||||||
reported= true;
|
reported= true;
|
||||||
fAllIncludedFiles.add(path);
|
fAllIncludedFiles.add(path);
|
||||||
ILocationCtx ctx= fLocationMap.pushInclusion(poundOffset, nameOffsets[0], nameOffsets[1],
|
ILocationCtx ctx= fLocationMap.pushInclusion(poundOffset, nameOffsets[0], nameOffsets[1],
|
||||||
condEndOffset, reader.buffer, path, headerName, userInclude, isHeuristic, fi.isSource());
|
condEndOffset, source, path, headerName, userInclude, isHeuristic, fi.isSource());
|
||||||
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(reader.buffer,
|
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(source,
|
||||||
fLexOptions, this, this));
|
fLexOptions, this, this));
|
||||||
fctx.setFoundOnPath(fi.getFoundOnPath(), includeDirective);
|
fctx.setFoundOnPath(fi.getFoundOnPath(), includeDirective);
|
||||||
fCurrentContext= fctx;
|
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();
|
List<IIndexMacro> mdefs= fi.getMacroDefinitions();
|
||||||
for (IIndexMacro macro : mdefs) {
|
for (IIndexMacro macro : mdefs) {
|
||||||
addMacroDefinition(macro);
|
addMacroDefinition(macro);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around char[] to implement {@link AbstractCharArray}.
|
* Wrapper around char[] to implement {@link AbstractCharArray}.
|
||||||
*/
|
*/
|
||||||
|
@ -21,8 +22,21 @@ public final class CharArray extends AbstractCharArray {
|
||||||
fArray= array;
|
fArray= array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CharArray(String str) {
|
||||||
|
fArray= str.toCharArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public char[] getArray() {
|
||||||
|
return fArray;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLimit() {
|
public int getLength() {
|
||||||
|
return fArray.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int tryGetLength() {
|
||||||
return fArray.length;
|
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 offset offset at which the file is included (see {@link ASTNode#getOffset()}
|
||||||
* @param fileContent information about the skipped file.
|
* @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.dom.ast.cpp.ICPPUsingDirective;
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
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.
|
* Instructs the preprocessor on how to handle a file-inclusion.
|
||||||
* @since 5.0
|
|
||||||
*/
|
*/
|
||||||
public class IncludeFileContent {
|
public class InternalFileContent extends FileContent {
|
||||||
public enum InclusionKind {
|
public enum InclusionKind {
|
||||||
/**
|
/**
|
||||||
* Instruct the preprocessor to skip this inclusion.
|
* Instruct the preprocessor to skip this inclusion.
|
||||||
|
@ -33,13 +32,13 @@ public class IncludeFileContent {
|
||||||
*/
|
*/
|
||||||
FOUND_IN_INDEX,
|
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 InclusionKind fKind;
|
||||||
private final CodeReader fCodeReader;
|
private final AbstractCharArray fSource;
|
||||||
private final List<IIndexMacro> fMacroDefinitions;
|
private final List<IIndexMacro> fMacroDefinitions;
|
||||||
private final List<ICPPUsingDirective> fUsingDirectives;
|
private final List<ICPPUsingDirective> fUsingDirectives;
|
||||||
private final String fFileLocation;
|
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
|
* @throws IllegalArgumentException if fileLocation is <code>null</code> or the kind value is illegal for
|
||||||
* this constructor.
|
* 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) {
|
if (fileLocation == null || kind != InclusionKind.SKIP_FILE) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
@ -63,21 +62,20 @@ public class IncludeFileContent {
|
||||||
fFileLocation= fileLocation;
|
fFileLocation= fileLocation;
|
||||||
fMacroDefinitions= null;
|
fMacroDefinitions= null;
|
||||||
fUsingDirectives= null;
|
fUsingDirectives= null;
|
||||||
fCodeReader= null;
|
fSource= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For reading include files from disk.
|
* 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>.
|
* @throws IllegalArgumentException in case the codeReader or its location is <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public IncludeFileContent(CodeReader codeReader) throws IllegalArgumentException {
|
public InternalFileContent(String filePath, AbstractCharArray content) throws IllegalArgumentException {
|
||||||
if (codeReader == null) {
|
if (content == null) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
fKind= InclusionKind.USE_CODE_READER;
|
fKind= InclusionKind.USE_SOURCE;
|
||||||
fFileLocation= codeReader.getPath();
|
fFileLocation= filePath;
|
||||||
fCodeReader= codeReader;
|
fSource= content;
|
||||||
fMacroDefinitions= null;
|
fMacroDefinitions= null;
|
||||||
fUsingDirectives= null;
|
fUsingDirectives= null;
|
||||||
if (fFileLocation == null) {
|
if (fFileLocation == null) {
|
||||||
|
@ -92,11 +90,11 @@ public class IncludeFileContent {
|
||||||
* @param files
|
* @param files
|
||||||
* @throws IllegalArgumentException in case the fileLocation or the macroDefinitions are <code>null</code>.
|
* @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) {
|
List<IIndexFile> files) {
|
||||||
fKind= InclusionKind.FOUND_IN_INDEX;
|
fKind= InclusionKind.FOUND_IN_INDEX;
|
||||||
fFileLocation= fileLocation;
|
fFileLocation= fileLocation;
|
||||||
fCodeReader= null;
|
fSource= null;
|
||||||
fUsingDirectives= usingDirectives;
|
fUsingDirectives= usingDirectives;
|
||||||
fMacroDefinitions= macroDefinitions;
|
fMacroDefinitions= macroDefinitions;
|
||||||
fFiles= files;
|
fFiles= files;
|
||||||
|
@ -112,16 +110,17 @@ public class IncludeFileContent {
|
||||||
/**
|
/**
|
||||||
* Returns the location of the file to be included.
|
* Returns the location of the file to be included.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getFileLocation() {
|
public String getFileLocation() {
|
||||||
return fFileLocation;
|
return fFileLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valid with {@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_CODE_READER}.
|
* @return the codeReader or <code>null</code> if kind is different to {@link InclusionKind#USE_SOURCE}.
|
||||||
*/
|
*/
|
||||||
public CodeReader getCodeReader() {
|
public AbstractCharArray getSource() {
|
||||||
return fCodeReader;
|
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);
|
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) {
|
public Lexer(AbstractCharArray input, int start, int end, LexerOptions options, ILexerLog log, Object source) {
|
||||||
fInput= input;
|
fInput= input;
|
||||||
fStart= fOffset= fEndOffset= start;
|
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.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
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.
|
* Base class for all location contexts that can contain children.
|
||||||
|
@ -31,10 +32,10 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
private int fChildSequenceLength;
|
private int fChildSequenceLength;
|
||||||
|
|
||||||
private ArrayList<LocationCtx> fChildren;
|
private ArrayList<LocationCtx> fChildren;
|
||||||
private char[] fSource;
|
private AbstractCharArray fSource;
|
||||||
private int[] fLineOffsets;
|
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);
|
super(parent, parentOffset, parentEndOffset, sequenceNumber);
|
||||||
fSource= source;
|
fSource= source;
|
||||||
}
|
}
|
||||||
|
@ -55,16 +56,17 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[] getSource(int offset, int length) {
|
public char[] getSource(int offset, int length) {
|
||||||
offset= Math.max(0, Math.min(offset, fSource.length));
|
if (fSource.isValidOffset(offset+length-1)) {
|
||||||
length= Math.max(0, Math.min(length, fSource.length-offset));
|
char[] result= new char[length];
|
||||||
char[] result= new char[length];
|
fSource.arraycopy(offset, result, 0, length);
|
||||||
System.arraycopy(fSource, offset, result, 0, length);
|
return result;
|
||||||
return result;
|
}
|
||||||
|
return CharArrayUtils.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getSequenceLength() {
|
public final int getSequenceLength() {
|
||||||
return fSource.length + fChildSequenceLength;
|
return fSource.getLength() + fChildSequenceLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,12 +172,12 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
|
|
||||||
// create the location after the last child.
|
// create the location after the last child.
|
||||||
final int myEndNumber = fSequenceNumber + getSequenceLength();
|
final int myEndNumber = fSequenceNumber + getSequenceLength();
|
||||||
final int offset= fSource.length - (myEndNumber - sequenceNumber);
|
final int offset= fSource.getLength() - (myEndNumber - sequenceNumber);
|
||||||
if (endSequenceNumber <= myEndNumber) {
|
if (endSequenceNumber <= myEndNumber) {
|
||||||
addFileLocation(offset, endSequenceNumber-sequenceNumber, locations);
|
addFileLocation(offset, endSequenceNumber-sequenceNumber, locations);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
addFileLocation(offset, fSource.length-offset, locations);
|
addFileLocation(offset, fSource.getLength()-offset, locations);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,8 +249,9 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
|
|
||||||
private int[] computeLineOffsets() {
|
private int[] computeLineOffsets() {
|
||||||
ArrayList<Integer> offsets= new ArrayList<Integer>();
|
ArrayList<Integer> offsets= new ArrayList<Integer>();
|
||||||
for (int i = 0; i < fSource.length; i++) {
|
final int len= fSource.getLength();
|
||||||
if (fSource[i] == '\n') {
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (fSource.get(i) == '\n') {
|
||||||
offsets.add(new Integer(i));
|
offsets.add(new Integer(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class LocationCtxFile extends LocationCtxContainer {
|
||||||
private final ASTInclusionStatement fASTInclude;
|
private final ASTInclusionStatement fASTInclude;
|
||||||
private final boolean fIsSource;
|
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,
|
int parentEndOffset, int sequenceNumber, ASTInclusionStatement inclusionStatement,
|
||||||
boolean isSource) {
|
boolean isSource) {
|
||||||
super(parent, source, parentOffset, parentEndOffset, sequenceNumber);
|
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
|
* The outermost context must be a translation unit. You must call this method exactly once and before
|
||||||
* creating any other context.
|
* creating any other context.
|
||||||
*/
|
*/
|
||||||
public ILocationCtx pushTranslationUnit(String filename, char[] buffer) {
|
public ILocationCtx pushTranslationUnit(String filename, AbstractCharArray buffer) {
|
||||||
assert fCurrentContext == null;
|
assert fCurrentContext == null;
|
||||||
fTranslationUnitPath= filename;
|
fTranslationUnitPath= filename;
|
||||||
fCurrentContext= fRootContext= new LocationCtxFile(null, filename, buffer, 0, 0, 0, null, true);
|
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 buffer a buffer containing the include directives.
|
||||||
* @param isMacroFile whether the context is used for running the preprocessor, only.
|
* @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;
|
assert fCurrentContext instanceof LocationCtxContainer;
|
||||||
int sequenceNumber= getSequenceNumberForOffset(offset);
|
int sequenceNumber= getSequenceNumberForOffset(offset);
|
||||||
fCurrentContext= new LocationCtxContainer((LocationCtxContainer) fCurrentContext, buffer, offset, offset, sequenceNumber);
|
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.
|
* @param userInclude <code>true</code> when specified with double-quotes.
|
||||||
*/
|
*/
|
||||||
public ILocationCtx pushInclusion(int startOffset, int nameOffset, int nameEndOffset, int endOffset,
|
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;
|
assert fCurrentContext instanceof LocationCtxContainer;
|
||||||
int startNumber= getSequenceNumberForOffset(startOffset);
|
int startNumber= getSequenceNumberForOffset(startOffset);
|
||||||
int nameNumber= getSequenceNumberForOffset(nameOffset);
|
int nameNumber= getSequenceNumberForOffset(nameOffset);
|
||||||
|
@ -721,7 +721,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void skippedFile(int sequenceNumber, IncludeFileContent fi) {
|
public void skippedFile(int sequenceNumber, InternalFileContent fi) {
|
||||||
for (ISkippedIndexedFilesListener l : fSkippedFilesListeners) {
|
for (ISkippedIndexedFilesListener l : fSkippedFilesListeners) {
|
||||||
l.skippedFile(sequenceNumber, fi);
|
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.index.IndexLocationFactory;
|
||||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
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.IExtendedScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
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.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
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.dom.IIncludeFileResolutionHeuristics;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
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.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||||
import org.eclipse.core.runtime.Assert;
|
import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
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 IIndexFile fIndexFile= null;
|
||||||
private boolean fRequestUpdate= false;
|
private boolean fRequestUpdate= false;
|
||||||
private boolean fRequestIsCounted= true;
|
private boolean fRequestIsCounted= true;
|
||||||
|
@ -167,7 +168,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
|
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
|
||||||
private UnusedHeaderStrategy fIndexHeadersWithoutContext= UnusedHeaderStrategy.useDefaultLanguage;
|
private UnusedHeaderStrategy fIndexHeadersWithoutContext= UnusedHeaderStrategy.useDefaultLanguage;
|
||||||
private boolean fIndexFilesWithoutConfiguration= true;
|
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 Object[] fFilesToUpdate;
|
||||||
private List<Object> fFilesToRemove = new ArrayList<Object>();
|
private List<Object> fFilesToRemove = new ArrayList<Object>();
|
||||||
|
@ -178,7 +179,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
protected IWritableIndex fIndex;
|
protected IWritableIndex fIndex;
|
||||||
private ITodoTaskUpdater fTodoTaskUpdater;
|
private ITodoTaskUpdater fTodoTaskUpdater;
|
||||||
private final boolean fIsFastIndexer;
|
private final boolean fIsFastIndexer;
|
||||||
private AbstractCodeReaderFactory fCodeReaderFactory;
|
private InternalFileContentProvider fCodeReaderFactory;
|
||||||
|
|
||||||
public AbstractIndexerTask(Object[] filesToUpdate, Object[] filesToRemove, IndexerInputAdapter resolver, boolean fastIndexer) {
|
public AbstractIndexerTask(Object[] filesToUpdate, Object[] filesToRemove, IndexerInputAdapter resolver, boolean fastIndexer) {
|
||||||
super(resolver);
|
super(resolver);
|
||||||
|
@ -212,7 +213,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
|
|
||||||
protected abstract IWritableIndex createIndex();
|
protected abstract IWritableIndex createIndex();
|
||||||
protected abstract IIncludeFileResolutionHeuristics createIncludeHeuristics();
|
protected abstract IIncludeFileResolutionHeuristics createIncludeHeuristics();
|
||||||
protected abstract AbstractCodeReaderFactory createReaderFactory();
|
protected abstract IncludeFileContentProvider createReaderFactory();
|
||||||
protected abstract AbstractLanguage[] getLanguages(String fileName);
|
protected abstract AbstractLanguage[] getLanguages(String fileName);
|
||||||
|
|
||||||
protected ITodoTaskUpdater createTodoTaskUpdater() {
|
protected ITodoTaskUpdater createTodoTaskUpdater() {
|
||||||
|
@ -233,7 +234,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
if (dummyName != null) {
|
if (dummyName != null) {
|
||||||
IIndexFileLocation dummyLoc= fResolver.resolveASTPath(dummyName);
|
IIndexFileLocation dummyLoc= fResolver.resolveASTPath(dummyName);
|
||||||
setIndexed(lang.getLinkageID(), dummyLoc);
|
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 createAST(lang, codeReader, scanInfo, options, monitor);
|
||||||
}
|
}
|
||||||
return null;
|
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)
|
private final IASTTranslationUnit createAST(Object tu, AbstractLanguage language, IScannerInfo scanInfo, int options, IProgressMonitor pm)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
final CodeReader codeReader= fResolver.getCodeReader(tu);
|
final FileContent codeReader= fResolver.getCodeReader(tu);
|
||||||
if (codeReader == null) {
|
if (codeReader == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -252,19 +253,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
return createAST(language, codeReader, scanInfo, options, pm);
|
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 {
|
IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException {
|
||||||
if (fCodeReaderFactory == null) {
|
if (fCodeReaderFactory == null) {
|
||||||
|
InternalFileContentProvider fileContentProvider = createInternalFileContentProvider();
|
||||||
if (fIsFastIndexer) {
|
if (fIsFastIndexer) {
|
||||||
fCodeReaderFactory= new IndexBasedCodeReaderFactory(fIndex, createIncludeHeuristics(),
|
fCodeReaderFactory= new IndexBasedFileContentProvider(fIndex, fResolver, language.getLinkageID(), fileContentProvider, this);
|
||||||
fResolver, language.getLinkageID(), createReaderFactory(), this);
|
|
||||||
} else {
|
} else {
|
||||||
fCodeReaderFactory= createReaderFactory();
|
fCodeReaderFactory= fileContentProvider;
|
||||||
}
|
}
|
||||||
} else if (fIsFastIndexer) {
|
} else if (fIsFastIndexer) {
|
||||||
((IndexBasedCodeReaderFactory) fCodeReaderFactory).setLinkage(language.getLinkageID());
|
((IndexBasedFileContentProvider) fCodeReaderFactory).setLinkage(language.getLinkageID());
|
||||||
}
|
}
|
||||||
|
fCodeReaderFactory.setIncludeResolutionHeuristics(createIncludeHeuristics());
|
||||||
try {
|
try {
|
||||||
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory,
|
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory,
|
||||||
fIndex, options, getLogService());
|
fIndex, options, getLogService());
|
||||||
|
@ -274,11 +275,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
return ast;
|
return ast;
|
||||||
} finally {
|
} finally {
|
||||||
if (fIsFastIndexer) {
|
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() {
|
protected IParserLogService getLogService() {
|
||||||
return ParserUtil.getParserLogService();
|
return ParserUtil.getParserLogService();
|
||||||
}
|
}
|
||||||
|
@ -417,7 +426,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
|
|
||||||
private void requestUpdate(int linkageID, IIndexFileLocation ifl, IIndexFragmentFile ifile) {
|
private void requestUpdate(int linkageID, IIndexFileLocation ifl, IIndexFragmentFile ifile) {
|
||||||
FileKey key= new FileKey(linkageID, ifl.getURI());
|
FileKey key= new FileKey(linkageID, ifl.getURI());
|
||||||
FileContent info= fFileInfos.get(key);
|
IndexFileContent info= fFileInfos.get(key);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
info= createFileInfo(key, null);
|
info= createFileInfo(key, null);
|
||||||
}
|
}
|
||||||
|
@ -427,7 +436,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
|
|
||||||
private void setIndexed(int linkageID, IIndexFileLocation ifl) {
|
private void setIndexed(int linkageID, IIndexFileLocation ifl) {
|
||||||
FileKey key= new FileKey(linkageID, ifl.getURI());
|
FileKey key= new FileKey(linkageID, ifl.getURI());
|
||||||
FileContent info= fFileInfos.get(key);
|
IndexFileContent info= fFileInfos.get(key);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
info= createFileInfo(key, null);
|
info= createFileInfo(key, null);
|
||||||
}
|
}
|
||||||
|
@ -435,14 +444,14 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
info.clearCaches();
|
info.clearCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileContent createFileInfo(FileKey key, IIndexFile ifile) {
|
private IndexFileContent createFileInfo(FileKey key, IIndexFile ifile) {
|
||||||
FileContent info = new FileContent();
|
IndexFileContent info = new IndexFileContent();
|
||||||
fFileInfos.put(key, info);
|
fFileInfos.put(key, info);
|
||||||
info.fIndexFile= ifile;
|
info.fIndexFile= ifile;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileContent getFileInfo(int linkageID, IIndexFileLocation ifl) {
|
private IndexFileContent getFileInfo(int linkageID, IIndexFileLocation ifl) {
|
||||||
FileKey key= new FileKey(linkageID, ifl.getURI());
|
FileKey key= new FileKey(linkageID, ifl.getURI());
|
||||||
return fFileInfos.get(key);
|
return fFileInfos.get(key);
|
||||||
}
|
}
|
||||||
|
@ -557,7 +566,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
String found= p.getPath();
|
String found= p.getPath();
|
||||||
if (found != null) {
|
if (found != null) {
|
||||||
IIndexFileLocation ifl= fResolver.resolveASTPath(found);
|
IIndexFileLocation ifl= fResolver.resolveASTPath(found);
|
||||||
FileContent fileinfo = getFileInfo(linkageID, ifl);
|
IndexFileContent fileinfo = getFileInfo(linkageID, ifl);
|
||||||
if (fileinfo != null) {
|
if (fileinfo != null) {
|
||||||
if (fileinfo.fIndexFile != null) {
|
if (fileinfo.fIndexFile != null) {
|
||||||
trace(filePath + " was not properly parsed up front for " + lang.getName()); //$NON-NLS-1$
|
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);
|
final IIndexFileLocation ifl = fResolver.resolveFile(tu);
|
||||||
if (ifl == null)
|
if (ifl == null)
|
||||||
continue;
|
continue;
|
||||||
final FileContent info= getFileInfo(linkageID, ifl);
|
final IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||||
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||||
info.fRequestIsCounted= false;
|
info.fRequestIsCounted= false;
|
||||||
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, tu);
|
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, tu);
|
||||||
|
@ -613,7 +622,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
return;
|
return;
|
||||||
final Object header= iter.next();
|
final Object header= iter.next();
|
||||||
final IIndexFileLocation ifl = fResolver.resolveFile(header);
|
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 != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||||
if (info.fIndexFile != null && fIndex.isWritableFile(info.fIndexFile)) {
|
if (info.fIndexFile != null && fIndex.isWritableFile(info.fIndexFile)) {
|
||||||
Object tu= findContext((IIndexFragmentFile) info.fIndexFile, contextMap);
|
Object tu= findContext((IIndexFragmentFile) info.fIndexFile, contextMap);
|
||||||
|
@ -640,7 +649,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
return;
|
return;
|
||||||
final Object header= iter.next();
|
final Object header= iter.next();
|
||||||
final IIndexFileLocation ifl = fResolver.resolveFile(header);
|
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 != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||||
info.fRequestIsCounted= false;
|
info.fRequestIsCounted= false;
|
||||||
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header);
|
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header);
|
||||||
|
@ -740,7 +749,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
collectOrderedIFLs(linkageID, inclusion, enteredFiles, orderedIFLs);
|
collectOrderedIFLs(linkageID, inclusion, enteredFiles, orderedIFLs);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileContent info= getFileInfo(linkageID, topIfl);
|
IndexFileContent info= getFileInfo(linkageID, topIfl);
|
||||||
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||||
orderedIFLs.add(topIfl);
|
orderedIFLs.add(topIfl);
|
||||||
}
|
}
|
||||||
|
@ -775,7 +784,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean needToUpdateHeader(int linkageID, IIndexFileLocation ifl) throws CoreException {
|
public final boolean needToUpdateHeader(int linkageID, IIndexFileLocation ifl) throws CoreException {
|
||||||
FileContent info= getFileInfo(linkageID, ifl);
|
IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
IIndexFile ifile= null;
|
IIndexFile ifile= null;
|
||||||
if (fResolver.canBePartOfSDK(ifl)) {
|
if (fResolver.canBePartOfSDK(ifl)) {
|
||||||
|
@ -914,9 +923,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
return result*31 + key.hashCode();
|
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)) {
|
if (!needToUpdateHeader(linkageID, ifl)) {
|
||||||
FileContent info= getFileInfo(linkageID, ifl);
|
IndexFileContent info= getFileInfo(linkageID, ifl);
|
||||||
Assert.isNotNull(info);
|
Assert.isNotNull(info);
|
||||||
if (info.fIndexFile == null) {
|
if (info.fIndexFile == null) {
|
||||||
info.fIndexFile= fIndex.getFile(linkageID, ifl);
|
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.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
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;
|
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.
|
* 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;
|
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
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.IIncludeFileResolutionHeuristics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,8 +26,8 @@ class PDOMFastIndexerTask extends PDOMIndexerTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
protected IncludeFileContentProvider createReaderFactory() {
|
||||||
return null;
|
return IncludeFileContentProvider.getSavedFilesProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
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.IIncludeFileResolutionHeuristics;
|
||||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractCodeReaderFactory createReaderFactory() {
|
protected IncludeFileContentProvider createReaderFactory() {
|
||||||
return SavedCodeReaderFactory.createInstance(createIncludeHeuristics());
|
return IncludeFileContentProvider.adapt(SavedCodeReaderFactory.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.LanguageManager;
|
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.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
|
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
|
||||||
|
@ -228,12 +228,12 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodeReader getCodeReader(Object tuo) {
|
public FileContent getCodeReader(Object tuo) {
|
||||||
ITranslationUnit tu= (ITranslationUnit) tuo;
|
ITranslationUnit tu= (ITranslationUnit) tuo;
|
||||||
final CodeReader reader= tu.getCodeReader();
|
final FileContent reader= FileContent.create(tu);
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
IIndexFileLocation ifl= IndexLocationFactory.getIFL(tu);
|
IIndexFileLocation ifl= IndexLocationFactory.getIFL(tu);
|
||||||
fIflCache.put(reader.getPath(), ifl);
|
fIflCache.put(reader.getFileLocation(), ifl);
|
||||||
}
|
}
|
||||||
return reader;
|
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.GPPScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
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.ParserFactory;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
@ -46,8 +48,9 @@ import org.eclipse.core.resources.IStorage;
|
||||||
import org.eclipse.core.runtime.content.IContentType;
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class InternalASTServiceProvider implements IASTServiceProvider {
|
public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
|
|
||||||
protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = GCCScannerExtensionConfiguration.getInstance();
|
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,
|
private IScanner createScanner(CodeReader reader, IScannerInfo scanInfo,
|
||||||
ParserMode mode, ParserLanguage lang, IParserLogService log,
|
ParserMode mode, ParserLanguage lang, IParserLogService log,
|
||||||
IScannerExtensionConfiguration scanConfig, ICodeReaderFactory fileCreator) {
|
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.IContributedModelBuilder;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
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.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
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.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.util.ASTPrinter;
|
import org.eclipse.cdt.core.parser.util.ASTPrinter;
|
||||||
import org.eclipse.cdt.core.parser.util.DebugUtil;
|
import org.eclipse.cdt.core.parser.util.DebugUtil;
|
||||||
|
@ -77,9 +78,18 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
||||||
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
|
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
|
@Override
|
||||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
public IASTTranslationUnit getASTTranslationUnit(FileContent reader, IScannerInfo scanInfo,
|
||||||
ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) throws CoreException {
|
IncludeFileContentProvider fileCreator, IIndex index, int options, IParserLogService log)
|
||||||
|
throws CoreException {
|
||||||
|
|
||||||
IASTTranslationUnit gtu = null;
|
IASTTranslationUnit gtu = null;
|
||||||
if(DEBUG_PRINT_GCC_AST) {
|
if(DEBUG_PRINT_GCC_AST) {
|
||||||
|
@ -100,7 +110,7 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
||||||
preprocessor.setComputeImageLocations((options & ILanguage.OPTION_NO_IMAGE_LOCATIONS) == 0);
|
preprocessor.setComputeImageLocations((options & ILanguage.OPTION_NO_IMAGE_LOCATIONS) == 0);
|
||||||
|
|
||||||
Map<String,String> parserProperties = new HashMap<String,String>();
|
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)
|
if((options & OPTION_SKIP_FUNCTION_BODIES) != 0)
|
||||||
parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
|
parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
|
||||||
if((options & OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0)
|
if((options & OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0)
|
||||||
|
@ -118,19 +128,26 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
||||||
return tu;
|
return tu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader,
|
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
|
IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log)
|
||||||
IIndex index, IParserLogService log) throws CoreException {
|
throws CoreException {
|
||||||
|
|
||||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
|
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IASTCompletionNode getCompletionNode(CodeReader reader,
|
@Deprecated
|
||||||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
|
public IASTCompletionNode getCompletionNode(org.eclipse.cdt.core.parser.CodeReader reader,
|
||||||
IIndex index, IParserLogService log, int offset) throws CoreException {
|
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;
|
IASTCompletionNode cn;
|
||||||
if(DEBUG_PRINT_GCC_AST) {
|
if(DEBUG_PRINT_GCC_AST) {
|
||||||
|
@ -151,7 +168,7 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
||||||
|
|
||||||
|
|
||||||
Map<String,String> parserProperties = new HashMap<String,String>();
|
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_FUNCTION_BODIES, "true");
|
||||||
parserProperties.put(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS, "true");
|
parserProperties.put(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS, "true");
|
||||||
|
|
||||||
|
@ -190,7 +207,7 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
|
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
|
||||||
return GCCLanguage.getDefault().getSelectedNames(ast, start, length);
|
return GCCLanguage.getDefault().getSelectedNames(ast, start, length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue