diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-07-04 17:03:41 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-07-04 17:03:41 +0000 |
commit | 3a2d0fb726aca3096b5c1ea9be734417060f34d7 (patch) | |
tree | 451c45a53e9e6ce4c70ba7135beea250034f700a | |
parent | ee3096a2d3092892d4c6f607a6323d9409714ed5 (diff) |
Split out the "empty" case for compound statement into a separate ctor.
Move the ASTContext-dependent version out of line.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159717 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Stmt.h | 19 | ||||
-rw-r--r-- | lib/AST/Stmt.cpp | 16 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaLambda.cpp | 4 |
4 files changed, 26 insertions, 20 deletions
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 904d56ed9a..3539c71634 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -545,20 +545,13 @@ class CompoundStmt : public Stmt { Stmt** Body; SourceLocation LBracLoc, RBracLoc; public: - CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts, - SourceLocation LB, SourceLocation RB) - : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { - CompoundStmtBits.NumStmts = NumStmts; - assert(CompoundStmtBits.NumStmts == NumStmts && - "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); - - if (NumStmts == 0) { - Body = 0; - return; - } + CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts, + SourceLocation LB, SourceLocation RB); - Body = new (C) Stmt*[NumStmts]; - memcpy(Body, StmtStart, NumStmts * sizeof(*Body)); + // \brief Build an empty compound statment with a location. + explicit CompoundStmt(SourceLocation Loc) + : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) { + CompoundStmtBits.NumStmts = 0; } // \brief Build an empty compound statement. diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 97eb4d579e..b6bb528220 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -244,6 +244,22 @@ SourceLocation Stmt::getLocEnd() const { llvm_unreachable("unknown statement kind"); } +CompoundStmt::CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts, + SourceLocation LB, SourceLocation RB) + : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { + CompoundStmtBits.NumStmts = NumStmts; + assert(CompoundStmtBits.NumStmts == NumStmts && + "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); + + if (NumStmts == 0) { + Body = 0; + return; + } + + Body = new (C) Stmt*[NumStmts]; + memcpy(Body, StmtStart, NumStmts * sizeof(*Body)); +} + void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) { if (this->Body) C.Deallocate(Body); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index ad650751d6..fc631d0d87 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -6801,7 +6801,7 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, } SourceLocation Loc = Constructor->getLocation(); - Constructor->setBody(new (Context) CompoundStmt(Context, 0, 0, Loc, Loc)); + Constructor->setBody(new (Context) CompoundStmt(Loc)); Constructor->setUsed(); MarkVTableUsed(CurrentLocation, ClassDecl); @@ -7162,7 +7162,7 @@ void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation, } SourceLocation Loc = Destructor->getLocation(); - Destructor->setBody(new (Context) CompoundStmt(Context, 0, 0, Loc, Loc)); + Destructor->setBody(new (Context) CompoundStmt(Loc)); Destructor->setImplicitlyDefined(true); Destructor->setUsed(); MarkVTableUsed(CurrentLocation, ClassDecl); @@ -8905,8 +8905,7 @@ void Sema::DefineImplicitLambdaToFunctionPointerConversion( // will fill in the actual details. Invoke->setUsed(); Invoke->setReferenced(); - Invoke->setBody(new (Context) CompoundStmt(Context, 0, 0, Conv->getLocation(), - Conv->getLocation())); + Invoke->setBody(new (Context) CompoundStmt(Conv->getLocation())); if (ASTMutationListener *L = getASTMutationListener()) { L->CompletedImplicitDefinition(Conv); diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index 6c78d83612..ab5640c2be 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -947,9 +947,7 @@ ExprResult Sema::BuildBlockForLambdaConversion(SourceLocation CurrentLocation, // Add a fake function body to the block. IR generation is responsible // for filling in the actual body, which cannot be expressed as an AST. - Block->setBody(new (Context) CompoundStmt(Context, 0, 0, - ConvLocation, - ConvLocation)); + Block->setBody(new (Context) CompoundStmt(ConvLocation)); // Create the block literal expression. Expr *BuildBlock = new (Context) BlockExpr(Block, Conv->getConversionType()); |