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

Extract macro argument location

The previous commit in this series addresses the NPE that
can be hit. This code covers the case of the OP in #251
to actually find the correct expression to pass to GDB.

Improvement to #251
This commit is contained in:
Dominic Scharfe 2023-01-30 08:31:52 -05:00 committed by Jonah Graham
parent af9b7b5b69
commit d5001624cb

View file

@ -347,6 +347,25 @@ public abstract class AbstractDebugTextHover implements ICEditorTextHover, IText
if (nameOffset < startOffset && nameOffset > macroOffset) {
startOffset = nameOffset;
}
} else if (name.getNodeLocations() != null && name.getNodeLocations().length == 1
&& name.getNodeLocations()[0] instanceof IASTMacroExpansionLocation expansionLocation) {
// Node is completely generated within a macro expansion
IASTPreprocessorMacroExpansion expansion = expansionLocation.getExpansion();
if (expansion != null) {
IASTName[] nestedMacroReferences = expansion.getNestedMacroReferences();
if (nestedMacroReferences != null && nestedMacroReferences.length == 1) {
IASTImageLocation imageLocation = nestedMacroReferences[0].getImageLocation();
if (imageLocation != null) {
final int nameOffset = imageLocation.getNodeOffset();
// offset should be inside macro expansion
if (nameOffset < startOffset && nameOffset > macroOffset) {
startOffset = nameOffset;
}
}
}
}
}
}
}