mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Performance Improvement for the CPreprocessor, avoid calling some methods on IIndexMacros.
This commit is contained in:
parent
617af77992
commit
880c51737f
6 changed files with 56 additions and 34 deletions
|
@ -50,6 +50,35 @@ import org.eclipse.cdt.internal.core.parser.scanner.ImageLocationInfo;
|
|||
import org.eclipse.cdt.internal.core.parser.scanner.LocationMap;
|
||||
|
||||
public class LocationMapTests extends BaseTestCase {
|
||||
public class Loc implements IASTFileLocation {
|
||||
private String fFile;
|
||||
private int fOffset;
|
||||
private int fEndOffset;
|
||||
public Loc(String file, int offset, int endOffset) {
|
||||
fFile= file;
|
||||
fOffset= offset;
|
||||
fEndOffset= endOffset;
|
||||
}
|
||||
public int getEndingLineNumber() {
|
||||
return 0;
|
||||
}
|
||||
public String getFileName() {
|
||||
return fFile;
|
||||
}
|
||||
public int getNodeLength() {
|
||||
return fEndOffset-fOffset;
|
||||
}
|
||||
public int getNodeOffset() {
|
||||
return fOffset;
|
||||
}
|
||||
public int getStartingLineNumber() {
|
||||
return 0;
|
||||
}
|
||||
public IASTFileLocation asFileLocation() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String FN = "filename";
|
||||
private static final int ROLE_DEFINITION = IASTNameOwner.r_definition;
|
||||
private static final int ROLE_UNCLEAR = IASTNameOwner.r_unclear;
|
||||
|
@ -419,8 +448,8 @@ public class LocationMapTests extends BaseTestCase {
|
|||
final String[] params = new String[]{"p1", "p2"};
|
||||
IMacroBinding macro2= new TestMacro("n2", "exp2", params);
|
||||
init(DIGITS);
|
||||
fLocationMap.registerMacroFromIndex(macro1, "fidx1", 0, 0, 0);
|
||||
fLocationMap.registerMacroFromIndex(macro2, "fidx2", 1, 4, 8);
|
||||
fLocationMap.registerMacroFromIndex(macro1, new Loc("fidx1", 0, 0), 0);
|
||||
fLocationMap.registerMacroFromIndex(macro2, new Loc("fidx2", 1, 4), 8);
|
||||
IASTPreprocessorMacroDefinition[] prep= fLocationMap.getBuiltinMacroDefinitions();
|
||||
assertEquals(2, prep.length);
|
||||
checkMacroDefinition(prep[0], macro1, "", "n1", "n1", "exp1", null, "fidx1", -1, 0, 0, 0, 0);
|
||||
|
@ -447,7 +476,7 @@ public class LocationMapTests extends BaseTestCase {
|
|||
assertEquals(1, fLocationMap.getCurrentLineNumber('\n'));
|
||||
assertEquals(2, fLocationMap.getCurrentLineNumber('\n'+1));
|
||||
fLocationMap.registerPredefinedMacro(macro1);
|
||||
fLocationMap.registerMacroFromIndex(macro2, "ifile", 2, 12, 32);
|
||||
fLocationMap.registerMacroFromIndex(macro2, new Loc("ifile", 2, 12), 32);
|
||||
fLocationMap.encounterPoundDefine(3, 13, 33, 63, 103, macro3);
|
||||
IASTName name1= fLocationMap.encounterImplicitMacroExpansion(macro1, null);
|
||||
IASTName name2= fLocationMap.encounterImplicitMacroExpansion(macro2, null);
|
||||
|
|
|
@ -79,16 +79,11 @@ class ASTPreprocessorDefinition extends ASTPreprocessorName {
|
|||
|
||||
|
||||
class ASTBuiltinName extends ASTPreprocessorDefinition {
|
||||
private final ASTFileLocationForBuiltins fFileLocation;
|
||||
private final IASTFileLocation fFileLocation;
|
||||
|
||||
public ASTBuiltinName(IASTNode parent, ASTNodeProperty property, String filename, int nameOffset, int nameEndOffset, char[] name, IBinding binding) {
|
||||
public ASTBuiltinName(IASTNode parent, ASTNodeProperty property, IASTFileLocation floc, char[] name, IBinding binding) {
|
||||
super(parent, property, -1, -1, name, binding);
|
||||
if (filename != null) {
|
||||
fFileLocation= new ASTFileLocationForBuiltins(filename, nameOffset, nameEndOffset-nameOffset);
|
||||
}
|
||||
else {
|
||||
fFileLocation= null;
|
||||
}
|
||||
fFileLocation= floc;
|
||||
}
|
||||
|
||||
public boolean contains(IASTNode node) {
|
||||
|
|
|
@ -266,7 +266,7 @@ class ASTInclusionStatement extends ASTPreprocessorNode implements IASTPreproces
|
|||
}
|
||||
}
|
||||
|
||||
class ASTMacro extends ASTPreprocessorNode implements IASTPreprocessorObjectStyleMacroDefinition {
|
||||
class ASTObjectStyleMacroDefinition extends ASTPreprocessorNode implements IASTPreprocessorObjectStyleMacroDefinition {
|
||||
private final ASTPreprocessorName fName;
|
||||
private final int fExpansionNumber;
|
||||
private final int fExpansionOffset;
|
||||
|
@ -274,7 +274,7 @@ class ASTMacro extends ASTPreprocessorNode implements IASTPreprocessorObjectStyl
|
|||
/**
|
||||
* Regular constructor.
|
||||
*/
|
||||
public ASTMacro(IASTTranslationUnit parent, IMacroBinding macro,
|
||||
public ASTObjectStyleMacroDefinition(IASTTranslationUnit parent, IMacroBinding macro,
|
||||
int startNumber, int nameNumber, int nameEndNumber, int expansionNumber, int endNumber) {
|
||||
super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, startNumber, endNumber);
|
||||
fExpansionNumber= expansionNumber;
|
||||
|
@ -286,9 +286,9 @@ class ASTMacro extends ASTPreprocessorNode implements IASTPreprocessorObjectStyl
|
|||
* Constructor for built-in macros
|
||||
* @param expansionOffset
|
||||
*/
|
||||
public ASTMacro(IASTTranslationUnit parent, IMacroBinding macro, String filename, int nameOffset, int nameEndOffset, int expansionOffset) {
|
||||
public ASTObjectStyleMacroDefinition(IASTTranslationUnit parent, IMacroBinding macro, IASTFileLocation floc, int expansionOffset) {
|
||||
super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, -1, -1);
|
||||
fName= new ASTBuiltinName(this, IASTPreprocessorMacroDefinition.MACRO_NAME, filename, nameOffset, nameEndOffset, macro.getNameCharArray(), macro);
|
||||
fName= new ASTBuiltinName(this, IASTPreprocessorMacroDefinition.MACRO_NAME, floc, macro.getNameCharArray(), macro);
|
||||
fExpansionNumber= -1;
|
||||
fExpansionOffset= expansionOffset;
|
||||
}
|
||||
|
@ -356,11 +356,11 @@ class ASTMacroParameter extends ASTPreprocessorNode implements IASTFunctionStyle
|
|||
public void setParameter(String value) {assert false;}
|
||||
}
|
||||
|
||||
class ASTFunctionMacro extends ASTMacro implements IASTPreprocessorFunctionStyleMacroDefinition {
|
||||
class ASTFunctionStyleMacroDefinition extends ASTObjectStyleMacroDefinition implements IASTPreprocessorFunctionStyleMacroDefinition {
|
||||
/**
|
||||
* Regular constructor.
|
||||
*/
|
||||
public ASTFunctionMacro(IASTTranslationUnit parent, IMacroBinding macro,
|
||||
public ASTFunctionStyleMacroDefinition(IASTTranslationUnit parent, IMacroBinding macro,
|
||||
int startNumber, int nameNumber, int nameEndNumber, int expansionNumber, int endNumber) {
|
||||
super(parent, macro, startNumber, nameNumber, nameEndNumber, expansionNumber, endNumber);
|
||||
}
|
||||
|
@ -368,9 +368,9 @@ class ASTFunctionMacro extends ASTMacro implements IASTPreprocessorFunctionStyle
|
|||
/**
|
||||
* Constructor for builtins
|
||||
*/
|
||||
public ASTFunctionMacro(IASTTranslationUnit parent, IMacroBinding macro,
|
||||
String filename, int nameOffset, int nameEndOffset, int expansionOffset) {
|
||||
super(parent, macro, filename, nameOffset, nameEndOffset, expansionOffset);
|
||||
public ASTFunctionStyleMacroDefinition(IASTTranslationUnit parent, IMacroBinding macro,
|
||||
IASTFileLocation nameLoc, int expansionOffset) {
|
||||
super(parent, macro, nameLoc, expansionOffset);
|
||||
}
|
||||
|
||||
public IASTFunctionStyleMacroParameter[] getParameters() {
|
||||
|
|
|
@ -817,9 +817,7 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
try {
|
||||
PreprocessorMacro result= fMacroDefinitionParser.parseMacroDefinition(macro.getName(), macro.getParameterList(), macro.getExpansion());
|
||||
final IASTFileLocation loc= macro.getFileLocation();
|
||||
int offset= loc.getNodeOffset();
|
||||
int endOffset= offset + loc.getNodeLength();
|
||||
fLocationMap.registerMacroFromIndex(result, loc.getFileName(), offset, endOffset, -1);
|
||||
fLocationMap.registerMacroFromIndex(result, loc, -1);
|
||||
fMacroDictionary.put(result.getNameCharArray(), result);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
@ -59,20 +59,20 @@ public class LocationMap implements ILocationResolver {
|
|||
|
||||
|
||||
public void registerPredefinedMacro(IMacroBinding macro) {
|
||||
registerPredefinedMacro(macro, null, -1, -1, -1);
|
||||
registerPredefinedMacro(macro, null, -1);
|
||||
}
|
||||
|
||||
public void registerMacroFromIndex(IMacroBinding macro, String filename, int nameOffset, int nameEndOffset, int expansionOffset) {
|
||||
registerPredefinedMacro(macro, filename, nameOffset, nameEndOffset, expansionOffset);
|
||||
public void registerMacroFromIndex(IMacroBinding macro, IASTFileLocation nameLocation, int expansionOffset) {
|
||||
registerPredefinedMacro(macro, nameLocation, expansionOffset);
|
||||
}
|
||||
|
||||
private void registerPredefinedMacro(IMacroBinding macro, String filename, int nameOffset, int nameEndOffset, int expansionOffset) {
|
||||
ASTMacro astmacro;
|
||||
private void registerPredefinedMacro(IMacroBinding macro, IASTFileLocation nameloc, int expansionOffset) {
|
||||
ASTObjectStyleMacroDefinition astmacro;
|
||||
if (macro.isFunctionStyle()) {
|
||||
astmacro= new ASTFunctionMacro(fTranslationUnit, macro, filename, nameOffset, nameEndOffset, expansionOffset);
|
||||
astmacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
||||
}
|
||||
else {
|
||||
astmacro= new ASTMacro(fTranslationUnit, macro, filename, nameOffset, nameEndOffset, expansionOffset);
|
||||
astmacro= new ASTObjectStyleMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
||||
}
|
||||
fBuiltinMacros.add(astmacro);
|
||||
}
|
||||
|
@ -294,10 +294,10 @@ public class LocationMap implements ILocationResolver {
|
|||
endOffset= getSequenceNumberForOffset(endOffset);
|
||||
ASTPreprocessorNode astMacro;
|
||||
if (!macrodef.isFunctionStyle()) {
|
||||
astMacro= new ASTMacro(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset);
|
||||
astMacro= new ASTObjectStyleMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset);
|
||||
}
|
||||
else {
|
||||
astMacro= new ASTFunctionMacro(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset);
|
||||
astMacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset);
|
||||
}
|
||||
fDirectives.add(astMacro);
|
||||
}
|
||||
|
|
|
@ -425,8 +425,8 @@ public class PDOMASTAdapter {
|
|||
* Otherwise if the provided name is not empty, it is returned unchanged.
|
||||
*/
|
||||
public static IASTName getAdapterIfAnonymous(IASTName name) {
|
||||
if (name.getFileLocation() == null) {
|
||||
if (name.toCharArray().length == 0) {
|
||||
if (name.toCharArray().length == 0) {
|
||||
if (name.getFileLocation() == null) {
|
||||
IASTNode parent= name.getParent();
|
||||
if (parent != null) {
|
||||
IASTFileLocation loc= parent.getFileLocation();
|
||||
|
|
Loading…
Add table
Reference in a new issue