1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Caches a step computed by the macro expansion explorer, bug 23540.

This commit is contained in:
Markus Schorn 2008-01-21 13:24:27 +00:00
parent 569d055fdf
commit ec3283c69d
2 changed files with 11 additions and 2 deletions

View file

@ -57,6 +57,8 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
private final SingleMacroExpansionExplorer[] fDelegates;
private final String fFilePath;
private final Map<IMacroBinding, IASTFileLocation> fMacroLocations;
private MacroExpansionStep fCachedStep;
private int fCachedStepID= -1;
public MultiMacroExpansionExplorer(IASTTranslationUnit tu, IASTFileLocation loc) {
if (tu == null || loc == null || loc.getNodeLength() == 0) {
@ -191,6 +193,9 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
if (step < 0) {
throw new IndexOutOfBoundsException();
}
if (fCachedStep != null && fCachedStepID == step) {
return fCachedStep;
}
int i;
MacroExpansionStep dresult= null;
StringBuilder before= new StringBuilder();
@ -218,7 +223,9 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
List<ReplaceEdit> replacements= new ArrayList<ReplaceEdit>();
shiftAndAddEdits(shift, dresult.getReplacements(), replacements);
return new MacroExpansionStep(before.toString(), dresult.getExpandedMacro(), dresult.getLocationOfExpandedMacroDefinition(), replacements.toArray(new ReplaceEdit[replacements.size()]));
fCachedStep= new MacroExpansionStep(before.toString(), dresult.getExpandedMacro(), dresult.getLocationOfExpandedMacroDefinition(), replacements.toArray(new ReplaceEdit[replacements.size()]));
fCachedStepID= step;
return fCachedStep;
}
private void appendGap(StringBuilder result, int i) {

View file

@ -156,7 +156,9 @@ public class CMacroExpansionInput {
if (node instanceof IASTName) {
IASTName macroName= (IASTName) node;
IBinding binding= macroName.getBinding();
if (binding instanceof IMacroBinding && !macroName.isDefinition()) {
// skip macro references that belong to a macro definition or an undef directive
if (binding instanceof IMacroBinding && !macroName.isDefinition() &&
macroName.getParent() instanceof IASTTranslationUnit) {
addExpansionNode(node);
createMacroExpansionExplorer(ast);
return Status.OK_STATUS;