clang: lib/Tooling/Refactoring/Extract/SourceExtraction.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
15#include
16
17using namespace clang;
18
19namespace {
20
21
26 LangOpts) == ";";
27}
28
29
30bool isSemicolonRequiredAfter(const Stmt *S) {
31 if (isa(S))
32 return false;
33 if (const auto *If = dyn_cast(S))
34 return isSemicolonRequiredAfter(If->getElse() ? If->getElse()
35 : If->getThen());
36 if (const auto *While = dyn_cast(S))
37 return isSemicolonRequiredAfter(While->getBody());
38 if (const auto *For = dyn_cast(S))
39 return isSemicolonRequiredAfter(For->getBody());
40 if (const auto *CXXFor = dyn_cast(S))
41 return isSemicolonRequiredAfter(CXXFor->getBody());
42 if (const auto *ObjCFor = dyn_cast(S))
43 return isSemicolonRequiredAfter(ObjCFor->getBody());
44 if(const auto *Switch = dyn_cast(S))
45 return isSemicolonRequiredAfter(Switch->getBody());
46 if(const auto *Case = dyn_cast(S))
47 return isSemicolonRequiredAfter(Case->getSubStmt());
48 switch (S->getStmtClass()) {
49 case Stmt::DeclStmtClass:
50 case Stmt::CXXTryStmtClass:
51 case Stmt::ObjCAtSynchronizedStmtClass:
52 case Stmt::ObjCAutoreleasePoolStmtClass:
53 case Stmt::ObjCAtTryStmtClass:
54 return false;
55 default:
56 return true;
57 }
58}
59
60
64 SM.getSpellingLineNumber(Loc1) == SM.getSpellingLineNumber(Loc2);
65}
66
67}
68
70namespace tooling {
71
72ExtractionSemicolonPolicy
76 auto neededInExtractedFunction = []() {
78 };
79 auto neededInOriginalFunction = []() {
81 };
82
83
84
85
86 if (isa(S))
87 return neededInExtractedFunction();
88
89
90
91
92 bool NeedsSemi = isSemicolonRequiredAfter(S);
93 if (!NeedsSemi)
94 return neededInOriginalFunction();
95
96
97
99 if (isSemicolonAtLocation(End, SM, LangOpts))
100 return neededInOriginalFunction();
101
102
103
105 if (NextToken && NextToken->is(tok::semi) &&
106 areOnSameLine(NextToken->getLocation(), End, SM)) {
107 ExtractedRange.setEnd(NextToken->getLocation());
108 return neededInOriginalFunction();
109 }
110
111
113}
114
115}
116}
Defines the SourceManager interface.
Defines the Objective-C statement AST node classes.
static CharSourceRange getTokenRange(SourceRange R)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
static std::optional< Token > findNextToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeComments=false)
Finds the token that comes right after the given location.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
void setEnd(SourceLocation e)
Stmt - This represents one statement.
The JSON file list parser is used to communicate input to InstallAPI.
@ If
'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...