Skip to content

Commit 335c604

Browse files
committed
[Review] Disable and Restore the Preprocessor's macro expansion in
FrontendAction's BeginSourceFileAction and EndSourceFileAction
1 parent df8c331 commit 335c604

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
@@ -1837,10 +1837,7 @@ class Preprocessor {
18371837
MacroExpansionInDirectivesOverride = true;
18381838
}
18391839

1840-
void SetDisableMacroExpansion() {
1841-
DisableMacroExpansion = true;
1842-
MacroExpansionInDirectivesOverride = false;
1843-
}
1840+
void SetEnableMacroExpansion(bool Enable) { DisableMacroExpansion = !Enable; }
18441841

18451842
/// Peeks ahead N tokens and returns that token without consuming any
18461843
/// tokens.

0 commit comments

Comments
 (0)