summaryrefslogtreecommitdiff
path: root/contrib/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp')
-rw-r--r--contrib/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp107
1 files changed, 43 insertions, 64 deletions
diff --git a/contrib/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp b/contrib/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
index e0ddadb12306..5967e40bfed9 100644
--- a/contrib/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ b/contrib/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -37,7 +37,6 @@ using llvm::utostr;
namespace {
class RewriteObjC : public ASTConsumer {
protected:
-
enum {
BLOCK_FIELD_IS_OBJECT = 3, /* id, NSObject, __attribute__((NSObject)),
block, ... */
@@ -72,7 +71,7 @@ namespace {
Stmt *CurrentBody;
ParentMap *PropParentMap; // created lazily.
std::string InFileName;
- raw_ostream* OutFile;
+ std::unique_ptr<raw_ostream> OutFile;
std::string Preamble;
TypeDecl *ProtocolTypeDecl;
@@ -158,14 +157,15 @@ namespace {
: R(R), SavedValue(R.DisableReplaceStmt) {
R.DisableReplaceStmt = true;
}
+
~DisableReplaceStmtScope() {
R.DisableReplaceStmt = SavedValue;
}
};
+
void InitializeCommon(ASTContext &context);
public:
-
// Top Level Driver code.
bool HandleTopLevelDecl(DeclGroupRef D) override {
for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
@@ -187,9 +187,10 @@ namespace {
}
return true;
}
+
void HandleTopLevelSingleDecl(Decl *D);
void HandleDeclInMainFile(Decl *D);
- RewriteObjC(std::string inFile, raw_ostream *OS,
+ RewriteObjC(std::string inFile, std::unique_ptr<raw_ostream> OS,
DiagnosticsEngine &D, const LangOptions &LOpts,
bool silenceMacroWarn);
@@ -505,12 +506,10 @@ namespace {
class RewriteObjCFragileABI : public RewriteObjC {
public:
-
- RewriteObjCFragileABI(std::string inFile, raw_ostream *OS,
- DiagnosticsEngine &D, const LangOptions &LOpts,
- bool silenceMacroWarn) : RewriteObjC(inFile, OS,
- D, LOpts,
- silenceMacroWarn) {}
+ RewriteObjCFragileABI(std::string inFile, std::unique_ptr<raw_ostream> OS,
+ DiagnosticsEngine &D, const LangOptions &LOpts,
+ bool silenceMacroWarn)
+ : RewriteObjC(inFile, std::move(OS), D, LOpts, silenceMacroWarn) {}
~RewriteObjCFragileABI() override {}
void Initialize(ASTContext &context) override;
@@ -540,7 +539,7 @@ namespace {
std::string &Result) override;
Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) override;
};
-}
+} // end anonymous namespace
void RewriteObjC::RewriteBlocksInFunctionProtoType(QualType funcType,
NamedDecl *D) {
@@ -575,11 +574,11 @@ static bool IsHeaderFile(const std::string &Filename) {
return Ext == "h" || Ext == "hh" || Ext == "H";
}
-RewriteObjC::RewriteObjC(std::string inFile, raw_ostream* OS,
+RewriteObjC::RewriteObjC(std::string inFile, std::unique_ptr<raw_ostream> OS,
DiagnosticsEngine &D, const LangOptions &LOpts,
bool silenceMacroWarn)
- : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS),
- SilenceRewriteMacroWarning(silenceMacroWarn) {
+ : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(std::move(OS)),
+ SilenceRewriteMacroWarning(silenceMacroWarn) {
IsHeader = IsHeaderFile(inFile);
RewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning,
"rewriting sub-expression within a macro (may not be correct)");
@@ -590,11 +589,12 @@ RewriteObjC::RewriteObjC(std::string inFile, raw_ostream* OS,
}
std::unique_ptr<ASTConsumer>
-clang::CreateObjCRewriter(const std::string &InFile, raw_ostream *OS,
+clang::CreateObjCRewriter(const std::string &InFile,
+ std::unique_ptr<raw_ostream> OS,
DiagnosticsEngine &Diags, const LangOptions &LOpts,
bool SilenceRewriteMacroWarning) {
- return llvm::make_unique<RewriteObjCFragileABI>(InFile, OS, Diags, LOpts,
- SilenceRewriteMacroWarning);
+ return llvm::make_unique<RewriteObjCFragileABI>(
+ InFile, std::move(OS), Diags, LOpts, SilenceRewriteMacroWarning);
}
void RewriteObjC::InitializeCommon(ASTContext &context) {
@@ -969,7 +969,7 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
// FIXME: handle category headers that are declared across multiple lines.
ReplaceText(LocStart, 0, "// ");
- for (auto *I : CatDecl->properties())
+ for (auto *I : CatDecl->instance_properties())
RewriteProperty(I);
for (auto *I : CatDecl->instance_methods())
RewriteMethodDeclaration(I);
@@ -992,7 +992,7 @@ void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
RewriteMethodDeclaration(I);
for (auto *I : PDecl->class_methods())
RewriteMethodDeclaration(I);
- for (auto *I : PDecl->properties())
+ for (auto *I : PDecl->instance_properties())
RewriteProperty(I);
// Lastly, comment out the @end.
@@ -1118,7 +1118,7 @@ void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
ResultStr += " _cmd";
// Method arguments.
- for (const auto *PDecl : OMD->params()) {
+ for (const auto *PDecl : OMD->parameters()) {
ResultStr += ", ";
if (PDecl->getType()->isObjCQualifiedIdType()) {
ResultStr += "id ";
@@ -1159,6 +1159,7 @@ void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
}
}
}
+
void RewriteObjC::RewriteImplementationDecl(Decl *OID) {
ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OID);
ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID);
@@ -1210,7 +1211,7 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) {
}
RewriteObjCInternalStruct(ClassDecl, ResultStr);
- for (auto *I : ClassDecl->properties())
+ for (auto *I : ClassDecl->instance_properties())
RewriteProperty(I);
for (auto *I : ClassDecl->instance_methods())
RewriteMethodDeclaration(I);
@@ -1720,7 +1721,6 @@ void RewriteObjC::WarnAboutReturnGotoStmts(Stmt *S)
Diags.Report(Context->getFullLoc(S->getLocStart()),
TryFinallyContainsReturnDiag);
}
- return;
}
void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns)
@@ -1730,32 +1730,29 @@ void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns)
if (SubStmt)
HasReturnStmts(SubStmt, hasReturns);
- if (isa<ReturnStmt>(S))
- hasReturns = true;
- return;
+ if (isa<ReturnStmt>(S))
+ hasReturns = true;
}
void RewriteObjC::RewriteTryReturnStmts(Stmt *S) {
- // Perform a bottom up traversal of all children.
- for (Stmt *SubStmt : S->children())
- if (SubStmt) {
- RewriteTryReturnStmts(SubStmt);
- }
- if (isa<ReturnStmt>(S)) {
- SourceLocation startLoc = S->getLocStart();
- const char *startBuf = SM->getCharacterData(startLoc);
-
- const char *semiBuf = strchr(startBuf, ';');
- assert((*semiBuf == ';') && "RewriteTryReturnStmts: can't find ';'");
- SourceLocation onePastSemiLoc = startLoc.getLocWithOffset(semiBuf-startBuf+1);
+ // Perform a bottom up traversal of all children.
+ for (Stmt *SubStmt : S->children())
+ if (SubStmt) {
+ RewriteTryReturnStmts(SubStmt);
+ }
+ if (isa<ReturnStmt>(S)) {
+ SourceLocation startLoc = S->getLocStart();
+ const char *startBuf = SM->getCharacterData(startLoc);
+ const char *semiBuf = strchr(startBuf, ';');
+ assert((*semiBuf == ';') && "RewriteTryReturnStmts: can't find ';'");
+ SourceLocation onePastSemiLoc = startLoc.getLocWithOffset(semiBuf-startBuf+1);
- std::string buf;
- buf = "{ objc_exception_try_exit(&_stack); return";
+ std::string buf;
+ buf = "{ objc_exception_try_exit(&_stack); return";
- ReplaceText(startLoc, 6, buf);
- InsertText(onePastSemiLoc, "}");
- }
- return;
+ ReplaceText(startLoc, 6, buf);
+ InsertText(onePastSemiLoc, "}");
+ }
}
void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) {
@@ -1780,7 +1777,6 @@ void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) {
ReplaceText(startLoc, 6, buf);
InsertText(onePastSemiLoc, "}");
}
- return;
}
Stmt *RewriteObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
@@ -2287,7 +2283,6 @@ void RewriteObjC::RewriteBlockPointerTypeVariable(std::string& Str,
}
}
-
void RewriteObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {
SourceLocation FunLocStart = FD->getTypeSpecStartLoc();
const FunctionType *funcType = FD->getType()->getAs<FunctionType>();
@@ -2615,10 +2610,8 @@ CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavo
CallExpr *STCE = new (Context) CallExpr(
*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, SourceLocation());
return STCE;
-
}
-
Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp,
SourceLocation StartLoc,
SourceLocation EndLoc) {
@@ -2924,7 +2917,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp,
ArgTypes.push_back(Context->getObjCSelType());
if (ObjCMethodDecl *OMD = Exp->getMethodDecl()) {
// Push any user argument types.
- for (const auto *PI : OMD->params()) {
+ for (const auto *PI : OMD->parameters()) {
QualType t = PI->getType()->isObjCQualifiedIdType()
? Context->getObjCIdType()
: PI->getType();
@@ -3059,7 +3052,6 @@ Stmt *RewriteObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) {
ProtocolExprDecls.insert(Exp->getProtocol()->getCanonicalDecl());
// delete Exp; leak for now, see RewritePropertyOrImplicitSetter() usage for more info.
return castExpr;
-
}
bool RewriteObjC::BufferContainsPPDirectives(const char *startBuf,
@@ -3224,7 +3216,6 @@ void RewriteObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl,
// Meta Data Emission
//===----------------------------------------------------------------------===//
-
/// RewriteImplementations - This routine rewrites all method implementations
/// and emits meta-data.
@@ -3665,8 +3656,6 @@ void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) {
HasLocalVariableExternalStorage(DRE->getDecl()))
// FIXME: Handle enums.
BlockDeclRefs.push_back(DRE);
-
- return;
}
void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S,
@@ -3694,8 +3683,6 @@ void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S,
ImportedLocalExternalDecls.insert(Var);
}
}
-
- return;
}
/// convertFunctionTypeOfBlocks - This routine converts a function type
@@ -3761,7 +3748,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) {
= dyn_cast<PseudoObjectExpr>(BlockExp)) {
CPT = POE->getType()->castAs<BlockPointerType>();
} else {
- assert(1 && "RewriteBlockClass: Bad type");
+ assert(false && "RewriteBlockClass: Bad type");
}
assert(CPT && "RewriteBlockClass: Bad type");
const FunctionType *FT = CPT->getPointeeType()->getAs<FunctionType>();
@@ -3931,7 +3918,6 @@ void RewriteObjC::RewriteCastExpr(CStyleCastExpr *CE) {
break;
}
}
- return;
}
void RewriteObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) {
@@ -3966,7 +3952,6 @@ void RewriteObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) {
break;
}
}
- return;
}
bool RewriteObjC::PointerTypeTakesAnyBlockArguments(QualType QT) {
@@ -4103,11 +4088,8 @@ void RewriteObjC::RewriteBlockPointerDecl(NamedDecl *ND) {
OrigLength++;
}
ReplaceText(Start, OrigLength, buf);
-
- return;
}
-
/// SynthesizeByrefCopyDestroyHelper - This routine synthesizes:
/// void __Block_byref_id_object_copy(struct Block_byref_id_object *dst,
/// struct Block_byref_id_object *src) {
@@ -4328,7 +4310,6 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
InsertText(semiLoc, "}");
}
- return;
}
void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
@@ -4494,7 +4475,6 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
Exp = new (Context) UnaryOperator(Exp, UO_AddrOf, QT, VK_RValue,
OK_Ordinary, SourceLocation());
}
-
}
InitExprs.push_back(Exp);
}
@@ -5241,7 +5221,6 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData(
// Mark this protocol as having been generated.
if (!ObjCSynthesizedProtocols.insert(PDecl->getCanonicalDecl()).second)
llvm_unreachable("protocol already synthesized");
-
}
void RewriteObjCFragileABI::RewriteObjCProtocolListMetaData(
@@ -5910,4 +5889,4 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
return Replacement;
}
-#endif
+#endif // CLANG_ENABLE_OBJC_REWRITER