mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Makes CPreprocessor the default scanner.
This commit is contained in:
parent
be2b763cd5
commit
7411260aef
10 changed files with 35 additions and 70 deletions
|
@ -23,7 +23,7 @@ import junit.framework.TestSuite;
|
|||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IInclude;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||
|
||||
/**
|
||||
* @author bnicolle
|
||||
|
@ -38,7 +38,7 @@ public class IIncludeTests extends IntegratedCModelTest {
|
|||
*/
|
||||
public IIncludeTests(String string) {
|
||||
super( string );
|
||||
fUseCPreprocessor= CPreprocessor.PROP_VALUE.equals(System.getProperty("scanner"));
|
||||
fUseCPreprocessor= !DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -162,7 +162,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
else
|
||||
configuration = new GPPScannerExtensionConfiguration();
|
||||
IScanner scanner;
|
||||
if (CPreprocessor.PROP_VALUE.equals(System.getProperty("scanner"))) {
|
||||
if (!DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"))) {
|
||||
scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration,
|
||||
FileCodeReaderFactory.getInstance());
|
||||
}
|
||||
|
|
|
@ -125,32 +125,15 @@ public class LocationMapTests extends BaseTestCase {
|
|||
assertSame(parent, node.getParent());
|
||||
assertEquals(property, node.getPropertyInParent());
|
||||
assertSame(parent.getTranslationUnit(), node.getTranslationUnit());
|
||||
assertEquals(filename, node.getContainingFilename());
|
||||
|
||||
if (offset >= 0) {
|
||||
assertEquals(filename, node.getContainingFilename());
|
||||
IASTFileLocation loc= node.getFileLocation();
|
||||
checkLocation(loc, filename, offset, length, line, endline);
|
||||
assertEquals(sig, node.getRawSignature());
|
||||
}
|
||||
else {
|
||||
try {
|
||||
node.getContainingFilename();
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException e) {
|
||||
}
|
||||
try {
|
||||
node.getFileLocation();
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException e) {
|
||||
}
|
||||
try {
|
||||
node.getRawSignature();
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException e) {
|
||||
}
|
||||
assertNull(node.getFileLocation());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,12 +270,9 @@ public class LocationMapTests extends BaseTestCase {
|
|||
checkASTNode(mp, fd, IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER, filename, -1, 0, -1, 0, null);
|
||||
}
|
||||
}
|
||||
int expectCount= offset >= 0 ? 1 : 0;
|
||||
IASTName[] decls= fLocationMap.getDeclarations(binding);
|
||||
assertEquals(expectCount, decls.length);
|
||||
if (expectCount > 0) {
|
||||
assertSame(macro.getName(), decls[0]);
|
||||
}
|
||||
assertEquals(1, decls.length);
|
||||
assertSame(macro.getName(), decls[0]);
|
||||
}
|
||||
|
||||
private void checkMacroUndef(IASTPreprocessorStatement s, IBinding binding, String image, String name, String nameImage,
|
||||
|
@ -439,8 +419,8 @@ public class LocationMapTests extends BaseTestCase {
|
|||
fLocationMap.registerPredefinedMacro(macro2);
|
||||
IASTPreprocessorMacroDefinition[] prep= fLocationMap.getBuiltinMacroDefinitions();
|
||||
assertEquals(2, prep.length);
|
||||
checkMacroDefinition(prep[0], macro1, "", "n1", "n1", "exp1", null, FN, -1, 0, 0, -1, 0);
|
||||
checkMacroDefinition(prep[1], macro2, "", "n2", "n2", "exp2", params, FN, -1, 0, 0, -1, 0);
|
||||
checkMacroDefinition(prep[0], macro1, "", "n1", "n1", "exp1", null, "", -1, 0, 0, -1, 0);
|
||||
checkMacroDefinition(prep[1], macro2, "", "n2", "n2", "exp2", params, "", -1, 0, 0, -1, 0);
|
||||
}
|
||||
|
||||
public void testIndexDefine() {
|
||||
|
|
|
@ -152,7 +152,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
|
|||
* @return an instance of IScanner
|
||||
*/
|
||||
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
|
||||
if (CPreprocessor.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
|
||||
if (!DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
|
||||
return new CPreprocessor(reader, scanInfo, ParserLanguage.C, log, getScannerExtensionConfiguration(), fileCreator);
|
||||
}
|
||||
return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.C,
|
||||
|
|
|
@ -148,7 +148,7 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
|
|||
* @return an instance of IScanner
|
||||
*/
|
||||
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
|
||||
if (CPreprocessor.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
|
||||
if (!DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
|
||||
return new CPreprocessor(reader, scanInfo, ParserLanguage.CPP, log, getScannerExtensionConfiguration(), fileCreator);
|
||||
}
|
||||
return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP,
|
||||
|
|
|
@ -126,13 +126,23 @@ public abstract class ASTNode implements IASTNode {
|
|||
}
|
||||
|
||||
public String getContainingFilename() {
|
||||
if (offset <= 0 && (length == 0 || offset < 0)) {
|
||||
final IASTNode parent = getParent();
|
||||
if (parent == null) {
|
||||
if (this instanceof IASTTranslationUnit) {
|
||||
return ((IASTTranslationUnit) this).getFilePath();
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
return parent.getContainingFilename();
|
||||
}
|
||||
return getTranslationUnit().getContainingFilename(offset);
|
||||
}
|
||||
|
||||
public IASTFileLocation getFileLocation() {
|
||||
if( fileLocation != null )
|
||||
return fileLocation;
|
||||
if (offset == 0 && length == 0) {
|
||||
if (offset <= 0 && (length == 0 || offset < 0)) {
|
||||
return null;
|
||||
}
|
||||
IASTTranslationUnit ast = getTranslationUnit();
|
||||
|
|
|
@ -92,7 +92,7 @@ class ASTBuiltinName extends ASTPreprocessorDefinition {
|
|||
|
||||
public String getContainingFilename() {
|
||||
if (fFileLocation == null) {
|
||||
throw new UnsupportedOperationException();
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
return fFileLocation.getFileName();
|
||||
}
|
||||
|
|
|
@ -68,42 +68,6 @@ abstract class ASTPreprocessorNode extends ASTNode {
|
|||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
|
||||
public String getContainingFilename() {
|
||||
if (super.getOffset() == -1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return super.getContainingFilename();
|
||||
}
|
||||
|
||||
public IASTFileLocation getFileLocation() {
|
||||
if (super.getOffset() == -1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return super.getFileLocation();
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
if (super.getOffset() == -1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return super.getLength();
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
final int offset = super.getOffset();
|
||||
if (offset == -1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
public String getRawSignature() {
|
||||
if (super.getOffset() == -1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return super.getRawSignature();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a subnode surrounding the given range or this.
|
||||
*/
|
||||
|
@ -293,6 +257,14 @@ class ASTObjectStyleMacroDefinition extends ASTPreprocessorNode implements IASTP
|
|||
fExpansionOffset= expansionOffset;
|
||||
}
|
||||
|
||||
|
||||
public String getContainingFilename() {
|
||||
if (fName instanceof ASTBuiltinName) {
|
||||
return fName.getContainingFilename();
|
||||
}
|
||||
return super.getContainingFilename();
|
||||
}
|
||||
|
||||
protected IMacroBinding getMacro() {
|
||||
return (IMacroBinding) fName.getBinding();
|
||||
}
|
||||
|
|
|
@ -36,10 +36,13 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
|
||||
/**
|
||||
* @author jcamelon
|
||||
* @deprecated will be removed in 5.0
|
||||
*/
|
||||
public class DOMScanner extends BaseScanner {
|
||||
private static final Class CHAR_ARRAY_CLASS = new char[]{}.getClass();
|
||||
|
||||
public static final String PROP_VALUE = "DOMScanner"; //$NON-NLS-1$
|
||||
|
||||
private final IScannerPreprocessorLog locationMap = new LocationMap();
|
||||
private final IIncludeFileTester createPathTester= new IIncludeFileTester() {
|
||||
public Object checkFile(String path, String fileName) {
|
||||
|
|
|
@ -231,7 +231,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
|||
private IScanner createScanner(CodeReader reader, IScannerInfo scanInfo,
|
||||
ParserMode mode, ParserLanguage lang, IParserLogService log,
|
||||
IScannerExtensionConfiguration scanConfig, ICodeReaderFactory fileCreator) {
|
||||
if (CPreprocessor.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
|
||||
if (!DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
|
||||
return new CPreprocessor(reader, scanInfo, lang, log, scanConfig, fileCreator);
|
||||
}
|
||||
return new DOMScanner(reader, scanInfo, mode, lang, log, scanConfig, fileCreator);
|
||||
|
|
Loading…
Add table
Reference in a new issue