1
0
Fork 0
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:
Markus Schorn 2007-11-14 11:06:55 +00:00
parent be2b763cd5
commit 7411260aef
10 changed files with 35 additions and 70 deletions

View file

@ -23,7 +23,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IInclude; import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.ITranslationUnit; 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 * @author bnicolle
@ -38,7 +38,7 @@ public class IIncludeTests extends IntegratedCModelTest {
*/ */
public IIncludeTests(String string) { public IIncludeTests(String string) {
super( string ); super( string );
fUseCPreprocessor= CPreprocessor.PROP_VALUE.equals(System.getProperty("scanner")); fUseCPreprocessor= !DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"));
} }
/** /**

View file

@ -162,7 +162,7 @@ public class AST2BaseTest extends BaseTestCase {
else else
configuration = new GPPScannerExtensionConfiguration(); configuration = new GPPScannerExtensionConfiguration();
IScanner scanner; 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, scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration,
FileCodeReaderFactory.getInstance()); FileCodeReaderFactory.getInstance());
} }

View file

@ -125,32 +125,15 @@ public class LocationMapTests extends BaseTestCase {
assertSame(parent, node.getParent()); assertSame(parent, node.getParent());
assertEquals(property, node.getPropertyInParent()); assertEquals(property, node.getPropertyInParent());
assertSame(parent.getTranslationUnit(), node.getTranslationUnit()); assertSame(parent.getTranslationUnit(), node.getTranslationUnit());
assertEquals(filename, node.getContainingFilename());
if (offset >= 0) { if (offset >= 0) {
assertEquals(filename, node.getContainingFilename());
IASTFileLocation loc= node.getFileLocation(); IASTFileLocation loc= node.getFileLocation();
checkLocation(loc, filename, offset, length, line, endline); checkLocation(loc, filename, offset, length, line, endline);
assertEquals(sig, node.getRawSignature()); assertEquals(sig, node.getRawSignature());
} }
else { else {
try { assertNull(node.getFileLocation());
node.getContainingFilename();
fail();
}
catch (UnsupportedOperationException e) {
}
try {
node.getFileLocation();
fail();
}
catch (UnsupportedOperationException e) {
}
try {
node.getRawSignature();
fail();
}
catch (UnsupportedOperationException e) {
}
} }
} }
@ -287,12 +270,9 @@ public class LocationMapTests extends BaseTestCase {
checkASTNode(mp, fd, IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER, filename, -1, 0, -1, 0, null); checkASTNode(mp, fd, IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER, filename, -1, 0, -1, 0, null);
} }
} }
int expectCount= offset >= 0 ? 1 : 0;
IASTName[] decls= fLocationMap.getDeclarations(binding); IASTName[] decls= fLocationMap.getDeclarations(binding);
assertEquals(expectCount, decls.length); assertEquals(1, decls.length);
if (expectCount > 0) { assertSame(macro.getName(), decls[0]);
assertSame(macro.getName(), decls[0]);
}
} }
private void checkMacroUndef(IASTPreprocessorStatement s, IBinding binding, String image, String name, String nameImage, 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); fLocationMap.registerPredefinedMacro(macro2);
IASTPreprocessorMacroDefinition[] prep= fLocationMap.getBuiltinMacroDefinitions(); IASTPreprocessorMacroDefinition[] prep= fLocationMap.getBuiltinMacroDefinitions();
assertEquals(2, prep.length); assertEquals(2, prep.length);
checkMacroDefinition(prep[0], macro1, "", "n1", "n1", "exp1", null, 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, FN, -1, 0, 0, -1, 0); checkMacroDefinition(prep[1], macro2, "", "n2", "n2", "exp2", params, "", -1, 0, 0, -1, 0);
} }
public void testIndexDefine() { public void testIndexDefine() {

View file

@ -152,7 +152,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
* @return an instance of IScanner * @return an instance of IScanner
*/ */
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) { 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 CPreprocessor(reader, scanInfo, ParserLanguage.C, log, getScannerExtensionConfiguration(), fileCreator);
} }
return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.C, return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.C,

View file

@ -148,7 +148,7 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
* @return an instance of IScanner * @return an instance of IScanner
*/ */
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) { 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 CPreprocessor(reader, scanInfo, ParserLanguage.CPP, log, getScannerExtensionConfiguration(), fileCreator);
} }
return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP,

View file

@ -126,13 +126,23 @@ public abstract class ASTNode implements IASTNode {
} }
public String getContainingFilename() { 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); return getTranslationUnit().getContainingFilename(offset);
} }
public IASTFileLocation getFileLocation() { public IASTFileLocation getFileLocation() {
if( fileLocation != null ) if( fileLocation != null )
return fileLocation; return fileLocation;
if (offset == 0 && length == 0) { if (offset <= 0 && (length == 0 || offset < 0)) {
return null; return null;
} }
IASTTranslationUnit ast = getTranslationUnit(); IASTTranslationUnit ast = getTranslationUnit();

View file

@ -92,7 +92,7 @@ class ASTBuiltinName extends ASTPreprocessorDefinition {
public String getContainingFilename() { public String getContainingFilename() {
if (fFileLocation == null) { if (fFileLocation == null) {
throw new UnsupportedOperationException(); return ""; //$NON-NLS-1$
} }
return fFileLocation.getFileName(); return fFileLocation.getFileName();
} }

View file

@ -68,42 +68,6 @@ abstract class ASTPreprocessorNode extends ASTNode {
return CharArrayUtils.EMPTY; 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. * Returns a subnode surrounding the given range or this.
*/ */
@ -293,6 +257,14 @@ class ASTObjectStyleMacroDefinition extends ASTPreprocessorNode implements IASTP
fExpansionOffset= expansionOffset; fExpansionOffset= expansionOffset;
} }
public String getContainingFilename() {
if (fName instanceof ASTBuiltinName) {
return fName.getContainingFilename();
}
return super.getContainingFilename();
}
protected IMacroBinding getMacro() { protected IMacroBinding getMacro() {
return (IMacroBinding) fName.getBinding(); return (IMacroBinding) fName.getBinding();
} }

View file

@ -36,10 +36,13 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
/** /**
* @author jcamelon * @author jcamelon
* @deprecated will be removed in 5.0
*/ */
public class DOMScanner extends BaseScanner { public class DOMScanner extends BaseScanner {
private static final Class CHAR_ARRAY_CLASS = new char[]{}.getClass(); 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 IScannerPreprocessorLog locationMap = new LocationMap();
private final IIncludeFileTester createPathTester= new IIncludeFileTester() { private final IIncludeFileTester createPathTester= new IIncludeFileTester() {
public Object checkFile(String path, String fileName) { public Object checkFile(String path, String fileName) {

View file

@ -231,7 +231,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) {
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 CPreprocessor(reader, scanInfo, lang, log, scanConfig, fileCreator);
} }
return new DOMScanner(reader, scanInfo, mode, lang, log, scanConfig, fileCreator); return new DOMScanner(reader, scanInfo, mode, lang, log, scanConfig, fileCreator);