16 using namespace clang;
29 bool isSemicolonRequiredAfter(
const Stmt *S) {
30 if (isa<CompoundStmt>(S))
32 if (
const auto *If = dyn_cast<IfStmt>(S))
33 return isSemicolonRequiredAfter(If->getElse() ? If->getElse()
35 if (
const auto *While = dyn_cast<WhileStmt>(S))
36 return isSemicolonRequiredAfter(While->getBody());
37 if (
const auto *For = dyn_cast<ForStmt>(S))
38 return isSemicolonRequiredAfter(For->getBody());
39 if (
const auto *CXXFor = dyn_cast<CXXForRangeStmt>(S))
40 return isSemicolonRequiredAfter(CXXFor->getBody());
41 if (
const auto *ObjCFor = dyn_cast<ObjCForCollectionStmt>(S))
42 return isSemicolonRequiredAfter(ObjCFor->getBody());
43 if(
const auto *Switch = dyn_cast<SwitchStmt>(S))
44 return isSemicolonRequiredAfter(Switch->getBody());
45 if(
const auto *Case = dyn_cast<SwitchCase>(S))
46 return isSemicolonRequiredAfter(Case->getSubStmt());
48 case Stmt::DeclStmtClass:
49 case Stmt::CXXTryStmtClass:
50 case Stmt::ObjCAtSynchronizedStmtClass:
51 case Stmt::ObjCAutoreleasePoolStmtClass:
52 case Stmt::ObjCAtTryStmtClass:
71 ExtractionSemicolonPolicy
75 auto neededInExtractedFunction = []() {
78 auto neededInOriginalFunction = []() {
86 return neededInExtractedFunction();
91 bool NeedsSemi = isSemicolonRequiredAfter(S);
93 return neededInOriginalFunction();
98 if (isSemicolonAtLocation(End, SM, LangOpts))
99 return neededInOriginalFunction();
104 if (NextToken && NextToken->is(tok::semi) &&
105 areOnSameLine(NextToken->getLocation(),
End,
SM)) {
106 ExtractedRange.
setEnd(NextToken->getLocation());
107 return neededInOriginalFunction();
Stmt - This represents one statement.
Defines the SourceManager interface.
static CharSourceRange getTokenRange(SourceRange R)
Defines the Objective-C statement AST node classes.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
SourceLocation getEnd() const
Encodes a location in the source.
static Optional< Token > findNextToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Finds the token that comes right after the given location.
Dataflow Directional Tag Classes.
StmtClass getStmtClass() const
void setEnd(SourceLocation e)
A trivial tuple used to represent a source range.
This class handles loading and caching of source files into memory.