clang: lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

26

27using namespace clang;

28using namespace arcmt;

29using namespace trans;

30

32 std::vector &MacroLocs,

34 if (!S->hasLeadingEmptyMacro())

35 return false;

36

39 return false;

40

41 if (MacroLocs.empty())

42 return false;

43

45 std::vector::iterator I = llvm::upper_bound(

47 --I;

50 assert(AfterMacroLoc.isFileID());

51

52 if (AfterMacroLoc == SemiLoc)

53 return true;

54

56 if (SM.isInSameSLocAddrSpace(AfterMacroLoc, SemiLoc, &RelOffs))

57 return false;

58 if (RelOffs < 0)

59 return false;

60

61

62

63

64

66 return false;

67

69 return AfterMacroSemiLoc == SemiLoc;

70}

71

72namespace {

73

74

75

76class EmptyChecker : public StmtVisitor<EmptyChecker, bool> {

78 std::vector &MacroLocs;

79

80public:

81 EmptyChecker(ASTContext &ctx, std::vector &macroLocs)

82 : Ctx(ctx), MacroLocs(macroLocs) { }

83

84 bool VisitNullStmt(NullStmt *S) {

86 }

88 if (S->body_empty())

89 return false;

90 for (auto *I : S->body())

92 return false;

93 return true;

94 }

95 bool VisitIfStmt(IfStmt *S) {

96 if (S->getConditionVariable())

97 return false;

98 Expr *condE = S->getCond();

99 if (!condE)

100 return false;

102 return false;

103 if (!S->getThen() || !Visit(S->getThen()))

104 return false;

105 return !S->getElse() || Visit(S->getElse());

106 }

107 bool VisitWhileStmt(WhileStmt *S) {

108 if (S->getConditionVariable())

109 return false;

110 Expr *condE = S->getCond();

111 if (!condE)

112 return false;

114 return false;

115 if (!S->getBody())

116 return false;

117 return Visit(S->getBody());

118 }

119 bool VisitDoStmt(DoStmt *S) {

120 Expr *condE = S->getCond();

121 if (!condE)

122 return false;

124 return false;

125 if (!S->getBody())

126 return false;

127 return Visit(S->getBody());

128 }

130 Expr *Exp = S->getCollection();

131 if (!Exp)

132 return false;

134 return false;

135 if (!S->getBody())

136 return false;

137 return Visit(S->getBody());

138 }

140 if (!S->getSubStmt())

141 return false;

142 return Visit(S->getSubStmt());

143 }

144};

145

146class EmptyStatementsRemover :

149

150public:

151 EmptyStatementsRemover(MigrationPass &pass) : Pass(pass) { }

152

153 bool TraverseStmtExpr(StmtExpr *E) {

156 I = S->body_begin(), E = S->body_end(); I != E; ++I) {

157 if (I != E - 1)

158 check(*I);

160 }

161 return true;

162 }

163

165 for (auto *I : S->body())

166 check(I);

167 return true;

168 }

169

171

172private:

173 void check(Stmt *S) {

174 if (!S) return;

178 }

179 }

180};

181

182}

183

185 std::vector &MacroLocs) {

186 for (auto *I : body->body())

187 if (!EmptyChecker(Ctx, MacroLocs).Visit(I))

188 return false;

189

190 return true;

191}

192

199

201 impl_iterator;

202 for (impl_iterator I = impl_iterator(DC->decls_begin()),

203 E = impl_iterator(DC->decls_end()); I != E; ++I) {

206 for (auto *MD : I->instance_methods()) {

207 if (!MD->hasBody())

208 continue;

209

210 if (MD->getMethodFamily() == OMF_dealloc) {

211 DeallocM = MD;

212 } else if (MD->isInstanceMethod() && MD->getSelector() == FinalizeSel) {

213 FinalizeM = MD;

214 }

215 }

216

217 if (DeallocM) {

221 }

222

223 if (FinalizeM) {

226 }

227

228 } else if (FinalizeM) {

232 } else {

235 }

236 }

237 }

238}

239

242

244

245 for (unsigned i = 0, e = pass.ARCMTMacroLocs.size(); i != e; ++i) {

248 }

249}

Defines the clang::ASTContext interface.

Defines the SourceManager interface.

static bool isEmptyARCMTMacroStatement(NullStmt *S, std::vector< SourceLocation > &MacroLocs, ASTContext &Ctx)

static bool isBodyEmpty(CompoundStmt *body, ASTContext &Ctx, std::vector< SourceLocation > &MacroLocs)

static void cleanupDeallocOrFinalize(MigrationPass &pass)

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

SourceManager & getSourceManager()

TranslationUnitDecl * getTranslationUnitDecl() const

SelectorTable & Selectors

Comparison function object.

CompoundStmt - This represents a group of statements like { stmt stmt }.

specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...

DeclContext - This is used only as base class of specific decl types that can act as declaration cont...

decl_iterator decls_end() const

decl_iterator decls_begin() const

DoStmt - This represents a 'do/while' stmt.

This represents one expression.

IdentifierInfo & get(StringRef Name)

Return the identifier token info for the specified named identifier.

IfStmt - This represents an if/then/else.

NullStmt - This is the null statement ";": C99 6.8.3p3.

Represents Objective-C's @autoreleasepool Statement.

Represents Objective-C's collection statement.

ObjCMethodDecl - Represents an instance or class method declaration.

CompoundStmt * getCompoundBody()

SourceLocation getSelectorStartLoc() const

SourceRange getSourceRange() const override LLVM_READONLY

Source range that this declaration covers.

A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...

bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue=nullptr)

Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...

Selector getNullarySelector(const IdentifierInfo *ID)

Smart pointer class that efficiently represents Objective-C method names.

Encodes a location in the source.

SourceLocation getLocWithOffset(IntTy Offset) const

Return a source location with the specified offset from this SourceLocation.

This class handles loading and caching of source files into memory.

StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).

RetTy Visit(PTR(Stmt) S, ParamTys... P)

StmtVisitor - This class implements a simple visitor for Stmt subclasses.

Stmt - This represents one statement.

WhileStmt - This represents a 'while' stmt.

std::vector< SourceLocation > & ARCMTMacroLocs

void remove(SourceRange range)

void replaceText(SourceLocation loc, StringRef text, StringRef replacementText)

bool hasSideEffects(Expr *E, ASTContext &Ctx)

void removeEmptyStatementsAndDeallocFinalize(MigrationPass &pass)

SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)

'Loc' is the end of a statement range.

static StringRef getARCMTMacroName()

The JSON file list parser is used to communicate input to InstallAPI.