19 using namespace clang;
20 using namespace arcmt;
21 using namespace trans;
34 if (D->getDeclContext()->getRedeclContext()->isFunctionOrMethod())
49 CaseInfo() : SC(nullptr), State(St_Unchecked) {}
51 : SC(S), Range(Range), State(St_Unchecked) {}
60 : PMap(PMap), Cases(Cases) { }
70 if (getCaseParent(Curr) != Parent)
89 while (Parent && (isa<SwitchCase>(Parent) || isa<LabelStmt>(Parent)))
95 class ProtectedScopeFixer {
103 : Pass(BodyCtx.getMigrationContext().Pass),
104 SM(Pass.Ctx.getSourceManager()) {
108 LocalRefsCollector(LocalRefs).TraverseStmt(BodyCtx.
getTopStmt());
115 StoredDiags.append(DiagList.
begin(), DiagList.
end());
117 I = StoredDiags.begin(), E = StoredDiags.end();
119 if (I->getID() == diag::err_switch_into_protected_scope &&
120 isInRange(I->getLocation(), BodyRange)) {
121 handleProtectedScopeError(I, E);
128 void handleProtectedScopeError(
132 assert(DiagI->getID() == diag::err_switch_into_protected_scope);
134 bool handledAllNotes =
true;
138 if (!handleProtectedNote(*DiagI))
139 handledAllNotes =
false;
149 for (
unsigned i = 0;
i != Cases.size();
i++) {
150 CaseInfo &info = Cases[
i];
153 if (info.State == CaseInfo::St_Unchecked)
155 assert(info.State != CaseInfo::St_Unchecked);
157 if (info.State == CaseInfo::St_Fixed) {
168 void tryFixing(CaseInfo &info) {
169 assert(info.State == CaseInfo::St_Unchecked);
170 if (hasVarReferencedOutside(info)) {
171 info.State = CaseInfo::St_CannotFix;
176 Pass.
TA.
insert(info.Range.getEnd(),
"}\n");
177 info.State = CaseInfo::St_Fixed;
180 bool hasVarReferencedOutside(CaseInfo &info) {
181 for (
unsigned i = 0, e = LocalRefs.size();
i != e; ++
i) {
201 ProtectedScopeFixer Fix(BodyCtx);
SourceLocation getEndLoc() const LLVM_READONLY
Defines the clang::ASTContext interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Stmt - This represents one statement.
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
Stmt * getParent(Stmt *) const
const CapturedDiagList & getDiags() const
ParentMap & getParentMap()
TextDiagnosticBuffer::DiagList DiagList
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
SourceLocation getLocation() const
void traverseBody(BodyContext &BodyCtx) override
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
DiagnosticsEngine::Level getLevel() const
SwitchCase * getSwitchCaseList()
SourceLocation getEnd() const
Encodes a location in the source.
Dataflow Directional Tag Classes.
const FullSourceLoc & getLocation() const
SwitchStmt - This represents a 'switch' stmt.
const SwitchCase * getNextSwitchCase() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
A reference to a declared variable, function, enum, etc.
SourceLocation getBeginLoc() const
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
This class handles loading and caching of source files into memory.
SourceLocation getLocation() const