Skip to content

Commit 1c9b89b

Browse files
committed
[WIP] Disable and Restore the Preprocessor's macro expansion in
FrontendAction's BeginSourceFileAction and EndSourceFileAction
1 parent 415bfaf commit 1c9b89b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

clang/include/clang/Frontend/FrontendAction.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class FrontendAction {
8585
/// EndSourceFileAction() will not be called.
8686
virtual bool BeginSourceFileAction(CompilerInstance &CI) {
8787
if (CurrentInput.isPreprocessed())
88-
CI.getPreprocessor().SetDisableMacroExpansion();
88+
CI.getPreprocessor().SetEnableMacroExpansion(false);
8989
return true;
9090
}
9191

@@ -100,7 +100,11 @@ class FrontendAction {
100100
///
101101
/// This is guaranteed to only be called following a successful call to
102102
/// BeginSourceFileAction (and BeginSourceFile).
103-
virtual void EndSourceFileAction() {}
103+
virtual void EndSourceFileAction() {
104+
if (CurrentInput.isPreprocessed())
105+
// reset the preprocessor macro expansion to the default
106+
getCompilerInstance().getPreprocessor().SetEnableMacroExpansion(true);
107+
}
104108

105109
/// Callback at the end of processing a single input, to determine
106110
/// if the output files should be erased or not.

clang/include/clang/Lex/Preprocessor.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,10 +1831,7 @@ class Preprocessor {
18311831
MacroExpansionInDirectivesOverride = true;
18321832
}
18331833

1834-
void SetDisableMacroExpansion() {
1835-
DisableMacroExpansion = true;
1836-
MacroExpansionInDirectivesOverride = false;
1837-
}
1834+
void SetEnableMacroExpansion(bool Enable) { DisableMacroExpansion = !Enable; }
18381835

18391836
/// Peeks ahead N tokens and returns that token without consuming any
18401837
/// tokens.

0 commit comments

Comments
 (0)