Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 685ac66

Browse files
committed
FrontendAction: Track active file kind.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105581 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent eb58d83 commit 685ac66

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Diff for: include/clang/Frontend/FrontendAction.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#include <string>
1616

1717
namespace clang {
18-
class ASTUnit;
1918
class ASTConsumer;
20-
class CompilerInstance;
2119
class ASTMergeAction;
20+
class ASTUnit;
21+
class CompilerInstance;
2222

2323
enum InputKind {
2424
IK_None,
@@ -40,6 +40,7 @@ enum InputKind {
4040
/// the frontend.
4141
class FrontendAction {
4242
std::string CurrentFile;
43+
InputKind CurrentFileKind;
4344
llvm::OwningPtr<ASTUnit> CurrentASTUnit;
4445
CompilerInstance *Instance;
4546
friend class ASTMergeAction;
@@ -117,6 +118,11 @@ class FrontendAction {
117118
return CurrentFile;
118119
}
119120

121+
InputKind getCurrentFileKind() const {
122+
assert(!CurrentFile.empty() && "No current file!");
123+
return CurrentFileKind;
124+
}
125+
120126
ASTUnit &getCurrentASTUnit() const {
121127
assert(!CurrentASTUnit && "No current AST unit!");
122128
return *CurrentASTUnit;
@@ -126,7 +132,7 @@ class FrontendAction {
126132
return CurrentASTUnit.take();
127133
}
128134

129-
void setCurrentFile(llvm::StringRef Value, ASTUnit *AST = 0);
135+
void setCurrentFile(llvm::StringRef Value, InputKind Kind, ASTUnit *AST = 0);
130136

131137
/// @}
132138
/// @name Supported Modes

Diff for: lib/Frontend/ASTMerge.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI,
2626
// FIXME: This is a hack. We need a better way to communicate the
2727
// AST file, compiler instance, and file name than member variables
2828
// of FrontendAction.
29-
AdaptedAction->setCurrentFile(getCurrentFile(), takeCurrentASTUnit());
29+
AdaptedAction->setCurrentFile(getCurrentFile(), getCurrentFileKind(),
30+
takeCurrentASTUnit());
3031
AdaptedAction->setCompilerInstance(&CI);
3132
return AdaptedAction->BeginSourceFileAction(CI, Filename);
3233
}

Diff for: lib/Frontend/FrontendAction.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ FrontendAction::FrontendAction() : Instance(0) {}
2525

2626
FrontendAction::~FrontendAction() {}
2727

28-
void FrontendAction::setCurrentFile(llvm::StringRef Value, ASTUnit *AST) {
28+
void FrontendAction::setCurrentFile(llvm::StringRef Value, InputKind Kind,
29+
ASTUnit *AST) {
2930
CurrentFile = Value;
31+
CurrentFileKind = Kind;
3032
CurrentASTUnit.reset(AST);
3133
}
3234

@@ -35,7 +37,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
3537
InputKind InputKind) {
3638
assert(!Instance && "Already processing a source file!");
3739
assert(!Filename.empty() && "Unexpected empty filename!");
38-
setCurrentFile(Filename);
40+
setCurrentFile(Filename, InputKind);
3941
setCompilerInstance(&CI);
4042

4143
// AST files follow a very different path, since they share objects via the
@@ -52,7 +54,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
5254
if (!AST)
5355
goto failure;
5456

55-
setCurrentFile(Filename, AST);
57+
setCurrentFile(Filename, InputKind, AST);
5658

5759
// Set the shared objects, these are reset when we finish processing the
5860
// file, otherwise the CompilerInstance will happily destroy them.
@@ -127,7 +129,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
127129
}
128130

129131
CI.getDiagnosticClient().EndSourceFile();
130-
setCurrentFile("");
132+
setCurrentFile("", IK_None);
131133
setCompilerInstance(0);
132134
return false;
133135
}
@@ -206,7 +208,7 @@ void FrontendAction::EndSourceFile() {
206208
}
207209

208210
setCompilerInstance(0);
209-
setCurrentFile("");
211+
setCurrentFile("", IK_None);
210212
}
211213

212214
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)