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:
parent
569d055fdf
commit
ec3283c69d
2 changed files with 11 additions and 2 deletions
|
@ -57,6 +57,8 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
private final SingleMacroExpansionExplorer[] fDelegates;
|
private final SingleMacroExpansionExplorer[] fDelegates;
|
||||||
private final String fFilePath;
|
private final String fFilePath;
|
||||||
private final Map<IMacroBinding, IASTFileLocation> fMacroLocations;
|
private final Map<IMacroBinding, IASTFileLocation> fMacroLocations;
|
||||||
|
private MacroExpansionStep fCachedStep;
|
||||||
|
private int fCachedStepID= -1;
|
||||||
|
|
||||||
public MultiMacroExpansionExplorer(IASTTranslationUnit tu, IASTFileLocation loc) {
|
public MultiMacroExpansionExplorer(IASTTranslationUnit tu, IASTFileLocation loc) {
|
||||||
if (tu == null || loc == null || loc.getNodeLength() == 0) {
|
if (tu == null || loc == null || loc.getNodeLength() == 0) {
|
||||||
|
@ -191,6 +193,9 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
if (step < 0) {
|
if (step < 0) {
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
if (fCachedStep != null && fCachedStepID == step) {
|
||||||
|
return fCachedStep;
|
||||||
|
}
|
||||||
int i;
|
int i;
|
||||||
MacroExpansionStep dresult= null;
|
MacroExpansionStep dresult= null;
|
||||||
StringBuilder before= new StringBuilder();
|
StringBuilder before= new StringBuilder();
|
||||||
|
@ -218,7 +223,9 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
|
|
||||||
List<ReplaceEdit> replacements= new ArrayList<ReplaceEdit>();
|
List<ReplaceEdit> replacements= new ArrayList<ReplaceEdit>();
|
||||||
shiftAndAddEdits(shift, dresult.getReplacements(), replacements);
|
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) {
|
private void appendGap(StringBuilder result, int i) {
|
||||||
|
|
|
@ -156,7 +156,9 @@ public class CMacroExpansionInput {
|
||||||
if (node instanceof IASTName) {
|
if (node instanceof IASTName) {
|
||||||
IASTName macroName= (IASTName) node;
|
IASTName macroName= (IASTName) node;
|
||||||
IBinding binding= macroName.getBinding();
|
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);
|
addExpansionNode(node);
|
||||||
createMacroExpansionExplorer(ast);
|
createMacroExpansionExplorer(ast);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
|
Loading…
Add table
Reference in a new issue