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

Option to record defined macros during expansion.

This commit is contained in:
Markus Schorn 2011-10-07 10:56:14 +02:00
parent 22a089aca4
commit 535d90cc7d
2 changed files with 22 additions and 15 deletions

View file

@ -101,11 +101,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private static final DynamicMacro __LINE__ = new LineMacro("__LINE__".toCharArray()); //$NON-NLS-1$
private static final char[] ONCE = "once".toCharArray(); //$NON-NLS-1$
private static final int NO_EXPANSION = 0x01;
private static final int PROTECT_DEFINED = 0x02;
private static final int STOP_AT_NL = 0x04;
private static final int CHECK_NUMBERS = 0x08;
private static final int REPORT_SIGNIFICANT_MACROS = 0x10;
static final int NO_EXPANSION = 0x01;
static final int PROTECT_DEFINED = 0x02;
static final int STOP_AT_NL = 0x04;
static final int CHECK_NUMBERS = 0x08;
static final int REPORT_SIGNIFICANT_MACROS = 0x10;
static final int IGNORE_UNDEFINED_SIGNIFICANT_MACROS = 0x20;
private static final int MAX_INCLUSION_DEPTH = 200;
@ -1821,7 +1822,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
}
PreprocessorMacro macro= fMacroDictionary.get(name);
if (macro == null) {
if (reportSignificant)
if ((options & IGNORE_UNDEFINED_SIGNIFICANT_MACROS) == 0)
fCurrentContext.significantMacroUndefined(name);
return false;
}
@ -1843,9 +1844,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
final ITokenSequence input= stopAtNewline ? fLineInputToMacroExpansion : fInputToMacroExpansion;
final MacroExpander expander = withinExpansion ? new MacroExpander(this, fMacroDictionary,
fLocationMap, fLexOptions) : fMacroExpander;
TokenList replacement= expander.expand(input, (options & PROTECT_DEFINED) != 0, macro,
identifier, contentAssist,
reportSignificant ? fCurrentContext : null);
TokenList replacement= expander.expand(input, options, macro, identifier, contentAssist, fCurrentContext);
final IASTName[] expansions= expander.clearImplicitExpansions();
final ImageLocationInfo[] ili= expander.clearImageLocationInfos();
final Token last= replacement.last();

View file

@ -137,6 +137,7 @@ public class MacroExpander {
private int fFixedLineNumber;
private char[] fFixedInput;
private ScannerContext fReportMacros;
private boolean fReportUndefined;
public MacroExpander(ILexerLog log, CharArrayMap<PreprocessorMacro> macroDictionary, LocationMap locationMap, LexerOptions lexOptions) {
fDictionary= macroDictionary;
@ -150,10 +151,17 @@ public class MacroExpander {
* Expects that the identifier has been consumed, stores the result in the list provided.
* @param scannerContext
*/
public TokenList expand(ITokenSequence lexer, final boolean isPPCondition,
public TokenList expand(ITokenSequence lexer, final int ppOptions,
PreprocessorMacro macro, Token identifier, boolean completionMode,
ScannerContext scannerContext) throws OffsetLimitReachedException {
fReportMacros= scannerContext;
final boolean protectDefined= (ppOptions & CPreprocessor.PROTECT_DEFINED) != 0;
if ((ppOptions & CPreprocessor.REPORT_SIGNIFICANT_MACROS) != 0) {
fReportMacros= scannerContext;
fReportUndefined= (ppOptions & CPreprocessor.IGNORE_UNDEFINED_SIGNIFICANT_MACROS) == 0;
} else {
fReportMacros= null;
}
fImplicitMacroExpansions.clear();
fImageLocationInfos.clear();
@ -175,7 +183,7 @@ public class MacroExpander {
input.prepend(firstExpansion);
result= expandAll(input, forbidden, isPPCondition, null);
result= expandAll(input, forbidden, protectDefined, null);
} catch (CompletionInMacroExpansionException e) {
// for content assist in macro expansions, we return the list of tokens of the
// parameter at the current cursor position and hope that they make sense if
@ -362,10 +370,10 @@ public class MacroExpander {
} else if (macro == null || (macro.isFunctionStyle() && !input.findLParenthesis())) {
// Tricky: Don't mark function-style macros if you don't find the left parenthesis
if (fReportMacros != null) {
if (macro == null) {
fReportMacros.significantMacroUndefined(image);
} else {
if (macro != null) {
fReportMacros.significantMacro(macro);
} else if (fReportUndefined){
fReportMacros.significantMacroUndefined(image);
}
}
result.append(t);