mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Generate inactive macros only when requested, bug 264666
This commit is contained in:
parent
be63b5194a
commit
cbff20cfc3
5 changed files with 39 additions and 16 deletions
|
@ -23,4 +23,10 @@ public interface IASTPreprocessorUndefStatement extends IASTPreprocessorStatemen
|
|||
* Returns the reference to the macro, or <code>null</code>.
|
||||
*/
|
||||
public IASTName getMacroName();
|
||||
|
||||
/**
|
||||
* Returns whether this macro definition occurs in active code.
|
||||
* @since 5.1
|
||||
*/
|
||||
public boolean isActive();
|
||||
}
|
||||
|
|
|
@ -433,14 +433,20 @@ class ASTFunctionStyleMacroDefinition extends ASTMacroDefinition implements IAST
|
|||
|
||||
class ASTUndef extends ASTPreprocessorNode implements IASTPreprocessorUndefStatement {
|
||||
private final ASTPreprocessorName fName;
|
||||
public ASTUndef(IASTTranslationUnit parent, char[] name, int startNumber, int nameNumber, int nameEndNumber, IBinding binding) {
|
||||
private final boolean fActive;
|
||||
public ASTUndef(IASTTranslationUnit parent, char[] name, int startNumber, int nameNumber, int nameEndNumber, IBinding binding, boolean isActive) {
|
||||
super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, startNumber, nameEndNumber);
|
||||
fName= new ASTPreprocessorName(this, IASTPreprocessorStatement.MACRO_NAME, nameNumber, nameEndNumber, name, binding);
|
||||
fActive= isActive;
|
||||
}
|
||||
|
||||
public ASTPreprocessorName getMacroName() {
|
||||
return fName;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return fActive;
|
||||
}
|
||||
}
|
||||
|
||||
class ASTInclusionNode implements IASTInclusionNode {
|
||||
|
|
|
@ -993,10 +993,20 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
executeInclude(lexer, startOffset, true, fCurrentContext.getCodeState() == CodeState.eActive, withinExpansion);
|
||||
break;
|
||||
case IPreprocessorDirective.ppDefine:
|
||||
executeDefine(lexer, startOffset, fCurrentContext.getCodeState() == CodeState.eActive);
|
||||
CodeState state= fCurrentContext.getCodeState();
|
||||
if (state == CodeState.eSkipInactive) {
|
||||
lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
|
||||
} else {
|
||||
executeDefine(lexer, startOffset, state == CodeState.eActive);
|
||||
}
|
||||
break;
|
||||
case IPreprocessorDirective.ppUndef:
|
||||
executeUndefine(lexer, startOffset);
|
||||
state= fCurrentContext.getCodeState();
|
||||
if (state == CodeState.eSkipInactive) {
|
||||
lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
|
||||
} else {
|
||||
executeUndefine(lexer, startOffset, fCurrentContext.getCodeState() == CodeState.eActive);
|
||||
}
|
||||
break;
|
||||
case IPreprocessorDirective.ppIfdef:
|
||||
if (executeIfdef(lexer, startOffset, false, withinExpansion) == CodeState.eSkipInactive)
|
||||
|
@ -1232,8 +1242,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
}
|
||||
}
|
||||
|
||||
private void executeUndefine(Lexer lexer, int startOffset) throws OffsetLimitReachedException {
|
||||
final Token name= lexer.nextToken();
|
||||
private void executeUndefine(Lexer lexer, int startOffset, boolean isActive) throws OffsetLimitReachedException {
|
||||
final Token name= lexer.nextToken();
|
||||
final int tt= name.getType();
|
||||
if (tt != IToken.tIDENTIFIER) {
|
||||
if (tt == IToken.tCOMPLETION) {
|
||||
|
@ -1243,11 +1253,16 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
handleProblem(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, name.getCharImage(), startOffset, name.getEndOffset());
|
||||
return;
|
||||
}
|
||||
lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
|
||||
lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
|
||||
final int endOffset= lexer.currentToken().getEndOffset();
|
||||
final char[] namechars= name.getCharImage();
|
||||
PreprocessorMacro definition= fMacroDictionary.remove(namechars, 0, namechars.length);
|
||||
fLocationMap.encounterPoundUndef(definition, startOffset, name.getOffset(), name.getEndOffset(), endOffset, namechars);
|
||||
PreprocessorMacro definition;
|
||||
if (isActive) {
|
||||
definition= fMacroDictionary.remove(namechars, 0, namechars.length);
|
||||
} else {
|
||||
definition= fMacroDictionary.get(namechars);
|
||||
}
|
||||
fLocationMap.encounterPoundUndef(definition, startOffset, name.getOffset(), name.getEndOffset(), endOffset, namechars, isActive);
|
||||
}
|
||||
|
||||
private CodeState executeIfdef(Lexer lexer, int offset, boolean isIfndef, boolean withinExpansion) throws OffsetLimitReachedException {
|
||||
|
@ -1434,9 +1449,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
case IPreprocessorDirective.ppInclude_next:
|
||||
executeInclude(lexer, ident.getOffset(), true, false, withinExpansion);
|
||||
break;
|
||||
case IPreprocessorDirective.ppDefine:
|
||||
executeDefine(lexer, pound.getOffset(), false);
|
||||
break;
|
||||
case IPreprocessorDirective.ppIfdef:
|
||||
return executeIfdef(lexer, pound.getOffset(), false, withinExpansion);
|
||||
case IPreprocessorDirective.ppIfndef:
|
||||
|
|
|
@ -347,12 +347,12 @@ public class LocationMap implements ILocationResolver {
|
|||
fDirectives.add(astMacro);
|
||||
}
|
||||
|
||||
public void encounterPoundUndef(IMacroBinding definition, int startOffset, int nameOffset, int nameEndOffset, int endOffset, char[] name) {
|
||||
public void encounterPoundUndef(IMacroBinding definition, int startOffset, int nameOffset, int nameEndOffset, int endOffset, char[] name, boolean isActive) {
|
||||
startOffset= getSequenceNumberForOffset(startOffset);
|
||||
nameOffset= getSequenceNumberForOffset(nameOffset);
|
||||
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
||||
// not using endOffset, compatible with 4.0: endOffset= getSequenceNumberForOffset(endOffset);
|
||||
final ASTUndef undef = new ASTUndef(fTranslationUnit, name, startOffset, nameOffset, nameEndOffset, definition);
|
||||
final ASTUndef undef = new ASTUndef(fTranslationUnit, name, startOffset, nameOffset, nameEndOffset, definition, isActive);
|
||||
fDirectives.add(undef);
|
||||
addMacroReference(undef.getMacroName());
|
||||
}
|
||||
|
|
|
@ -316,9 +316,8 @@ abstract public class PDOMWriter {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// macros
|
||||
else if (stmt instanceof IASTPreprocessorMacroDefinition || stmt instanceof IASTPreprocessorUndefStatement) {
|
||||
} else if ((stmt instanceof IASTPreprocessorUndefStatement && ((IASTPreprocessorUndefStatement) stmt).isActive())
|
||||
|| (stmt instanceof IASTPreprocessorMacroDefinition && ((IASTPreprocessorMacroDefinition) stmt).isActive())) {
|
||||
IASTFileLocation sourceLoc = stmt.getFileLocation();
|
||||
if (sourceLoc != null) { // skip built-ins and command line macros
|
||||
IIndexFileLocation path2 = fResolver.resolveASTPath(sourceLoc.getFileName());
|
||||
|
|
Loading…
Add table
Reference in a new issue