diff options
-rw-r--r-- | Driver/PrintParserCallbacks.cpp | 34 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 33 | ||||
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 31 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 27 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 118 |
5 files changed, 130 insertions, 113 deletions
diff --git a/Driver/PrintParserCallbacks.cpp b/Driver/PrintParserCallbacks.cpp index 7999da01d9..c04dbdc3ac 100644 --- a/Driver/PrintParserCallbacks.cpp +++ b/Driver/PrintParserCallbacks.cpp @@ -312,29 +312,31 @@ namespace { return StmtEmpty(); } - virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, - StmtTy *Body) { + virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, + ExprArg Cond, StmtArg Body) { llvm::cout << __FUNCTION__ << "\n"; - return 0; + return StmtEmpty(); } - virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, - SourceLocation WhileLoc, ExprTy *Cond) { + virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, + SourceLocation WhileLoc, ExprArg Cond){ llvm::cout << __FUNCTION__ << "\n"; - return 0; + return StmtEmpty(); } - virtual StmtResult ActOnForStmt(SourceLocation ForLoc, - SourceLocation LParenLoc, - StmtTy *First, ExprTy *Second, ExprTy *Third, - SourceLocation RParenLoc, StmtTy *Body) { + virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc, + SourceLocation LParenLoc, + StmtArg First, ExprArg Second, + ExprArg Third, SourceLocation RParenLoc, + StmtArg Body) { llvm::cout << __FUNCTION__ << "\n"; - return 0; + return StmtEmpty(); } - virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, - SourceLocation LParenLoc, - StmtTy *First, ExprTy *Second, - SourceLocation RParenLoc, StmtTy *Body) { + virtual OwningStmtResult ActOnObjCForCollectionStmt( + SourceLocation ForColLoc, + SourceLocation LParenLoc, + StmtArg First, ExprArg Second, + SourceLocation RParenLoc, StmtArg Body) { llvm::cout << __FUNCTION__ << "\n"; - return 0; + return StmtEmpty(); } virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 009858959e..d0891bb350 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -416,25 +416,26 @@ public: return StmtEmpty(); } - virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, - StmtTy *Body) { - return 0; + virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, + StmtArg Body) { + return StmtEmpty(); } - virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, - SourceLocation WhileLoc, ExprTy *Cond) { - return 0; + virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, + SourceLocation WhileLoc, ExprArg Cond) { + return StmtEmpty(); } - virtual StmtResult ActOnForStmt(SourceLocation ForLoc, - SourceLocation LParenLoc, - StmtTy *First, ExprTy *Second, ExprTy *Third, - SourceLocation RParenLoc, StmtTy *Body) { - return 0; + virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc, + SourceLocation LParenLoc, + StmtArg First, ExprArg Second, + ExprArg Third, SourceLocation RParenLoc, + StmtArg Body) { + return StmtEmpty(); } - virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, - SourceLocation LParenLoc, - StmtTy *First, ExprTy *Second, - SourceLocation RParenLoc, StmtTy *Body) { - return 0; + virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, + SourceLocation LParenLoc, + StmtArg First, ExprArg Second, + SourceLocation RParenLoc, StmtArg Body) { + return StmtEmpty(); } virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 153aeb824e..1bc78583ed 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -722,7 +722,8 @@ Parser::OwningStmtResult Parser::ParseWhileStatement() { if (Cond.isInvalid() || Body.isInvalid()) return StmtError(); - return Owned(Actions.ActOnWhileStmt(WhileLoc, Cond.release(),Body.release())); + return Actions.ActOnWhileStmt(WhileLoc, move_convert(Cond), + move_convert(Body)); } /// ParseDoStatement @@ -786,8 +787,8 @@ Parser::OwningStmtResult Parser::ParseDoStatement() { if (Cond.isInvalid() || Body.isInvalid()) return StmtError(); - return Owned(Actions.ActOnDoStmt(DoLoc, Body.release(), WhileLoc, - Cond.release())); + return Actions.ActOnDoStmt(DoLoc, move_convert(Body), WhileLoc, + move_convert(Cond)); } /// ParseForStatement @@ -843,8 +844,8 @@ Parser::OwningStmtResult Parser::ParseForStatement() { OwningExprResult Value(Actions); bool ForEach = false; - OwningStmtResult FirstPart(Actions), ThirdPart(Actions); - OwningExprResult SecondPart(Actions); + OwningStmtResult FirstPart(Actions); + OwningExprResult SecondPart(Actions), ThirdPart(Actions); // Parse the first part of the for specifier. if (Tok.is(tok::semi)) { // for (; @@ -903,11 +904,7 @@ Parser::OwningStmtResult Parser::ParseForStatement() { if (Tok.is(tok::r_paren)) { // for (...;...;) // no third part. } else { - Value = ParseExpression(); - if (!Value.isInvalid()) { - // Turn the expression into a stmt. - ThirdPart = Actions.ActOnExprStmt(move_convert(Value)); - } + ThirdPart = ParseExpression(); } } // Match the ')'. @@ -940,14 +937,14 @@ Parser::OwningStmtResult Parser::ParseForStatement() { return StmtError(); if (!ForEach) - return Owned(Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart.release(), - SecondPart.release(), ThirdPart.release(), - RParenLoc, Body.release())); + return Actions.ActOnForStmt(ForLoc, LParenLoc, move_convert(FirstPart), + move_convert(SecondPart), move_convert(ThirdPart), + RParenLoc, move_convert(Body)); else - return Owned(Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc, - FirstPart.release(), - SecondPart.release(), - RParenLoc, Body.release())); + return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc, + move_convert(FirstPart), + move_convert(SecondPart), + RParenLoc, move_convert(Body)); } /// ParseGotoStatement diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 668cf5b7c4..be9da6bd80 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -873,19 +873,20 @@ public: virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond); virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, StmtArg Body); - virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, - StmtTy *Body); - virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, - SourceLocation WhileLoc, ExprTy *Cond); - - virtual StmtResult ActOnForStmt(SourceLocation ForLoc, - SourceLocation LParenLoc, - StmtTy *First, ExprTy *Second, ExprTy *Third, - SourceLocation RParenLoc, StmtTy *Body); - virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, - SourceLocation LParenLoc, - StmtTy *First, ExprTy *Second, - SourceLocation RParenLoc, StmtTy *Body); + virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, + StmtArg Body); + virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, + SourceLocation WhileLoc, ExprArg Cond); + + virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc, + SourceLocation LParenLoc, + StmtArg First, ExprArg Second, + ExprArg Third, SourceLocation RParenLoc, + StmtArg Body); + virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, + SourceLocation LParenLoc, + StmtArg First, ExprArg Second, + SourceLocation RParenLoc, StmtArg Body); virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 34f9f65cd7..7a41f4d976 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -532,52 +532,57 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, return Owned(SS); } -Action::StmtResult -Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body) { - Expr *condExpr = (Expr *)Cond; +Action::OwningStmtResult +Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) { + Expr *condExpr = (Expr *)Cond.release(); assert(condExpr && "ActOnWhileStmt(): missing expression"); - + DefaultFunctionArrayConversion(condExpr); + Cond = condExpr; QualType condType = condExpr->getType(); - + if (getLangOptions().CPlusPlus) { if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 - return true; + return StmtError(); } else if (!condType->isScalarType()) // C99 6.8.5p2 - return Diag(WhileLoc, diag::err_typecheck_statement_requires_scalar) - << condType << condExpr->getSourceRange(); + return StmtError(Diag(WhileLoc, + diag::err_typecheck_statement_requires_scalar) + << condType << condExpr->getSourceRange()); - return new WhileStmt(condExpr, (Stmt*)Body, WhileLoc); + Cond.release(); + return Owned(new WhileStmt(condExpr, (Stmt*)Body.release(), WhileLoc)); } -Action::StmtResult -Sema::ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, - SourceLocation WhileLoc, ExprTy *Cond) { - Expr *condExpr = (Expr *)Cond; +Action::OwningStmtResult +Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, + SourceLocation WhileLoc, ExprArg Cond) { + Expr *condExpr = (Expr *)Cond.release(); assert(condExpr && "ActOnDoStmt(): missing expression"); - + DefaultFunctionArrayConversion(condExpr); + Cond = condExpr; QualType condType = condExpr->getType(); - + if (getLangOptions().CPlusPlus) { if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 - return true; + return StmtError(); } else if (!condType->isScalarType()) // C99 6.8.5p2 - return Diag(DoLoc, diag::err_typecheck_statement_requires_scalar) - << condType << condExpr->getSourceRange(); + return StmtError(Diag(DoLoc, diag::err_typecheck_statement_requires_scalar) + << condType << condExpr->getSourceRange()); - return new DoStmt((Stmt*)Body, condExpr, DoLoc); + Cond.release(); + return Owned(new DoStmt((Stmt*)Body.release(), condExpr, DoLoc)); } -Action::StmtResult -Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, - StmtTy *first, ExprTy *second, ExprTy *third, - SourceLocation RParenLoc, StmtTy *body) { - Stmt *First = static_cast<Stmt*>(first); - Expr *Second = static_cast<Expr*>(second); - Expr *Third = static_cast<Expr*>(third); - Stmt *Body = static_cast<Stmt*>(body); - +Action::OwningStmtResult +Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, + StmtArg first, ExprArg second, ExprArg third, + SourceLocation RParenLoc, StmtArg body) { + Stmt *First = static_cast<Stmt*>(first.get()); + Expr *Second = static_cast<Expr*>(second.get()); + Expr *Third = static_cast<Expr*>(third.get()); + Stmt *Body = static_cast<Stmt*>(body.get()); + if (!getLangOptions().CPlusPlus) { if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) { // C99 6.8.5p3: The declaration part of a 'for' statement shall only @@ -597,32 +602,37 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, if (Second) { DefaultFunctionArrayConversion(Second); QualType SecondType = Second->getType(); - + if (getLangOptions().CPlusPlus) { if (CheckCXXBooleanCondition(Second)) // C++ 6.4p4 - return true; + return StmtError(); } else if (!SecondType->isScalarType()) // C99 6.8.5p2 - return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar) - << SecondType << Second->getSourceRange(); - } - return new ForStmt(First, Second, Third, Body, ForLoc); + return StmtError(Diag(ForLoc, + diag::err_typecheck_statement_requires_scalar) + << SecondType << Second->getSourceRange()); + } + first.release(); + second.release(); + third.release(); + body.release(); + return Owned(new ForStmt(First, Second, Third, Body, ForLoc)); } -Action::StmtResult -Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, - SourceLocation LParenLoc, - StmtTy *first, ExprTy *second, - SourceLocation RParenLoc, StmtTy *body) { - Stmt *First = static_cast<Stmt*>(first); - Expr *Second = static_cast<Expr*>(second); - Stmt *Body = static_cast<Stmt*>(body); +Action::OwningStmtResult +Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, + SourceLocation LParenLoc, + StmtArg first, ExprArg second, + SourceLocation RParenLoc, StmtArg body) { + Stmt *First = static_cast<Stmt*>(first.get()); + Expr *Second = static_cast<Expr*>(second.get()); + Stmt *Body = static_cast<Stmt*>(body.get()); if (First) { QualType FirstType; if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) { if (!DS->hasSolitaryDecl()) - return Diag((*DS->decl_begin())->getLocation(), - diag::err_toomany_element_decls); - + return StmtError(Diag((*DS->decl_begin())->getLocation(), + diag::err_toomany_element_decls)); + ScopedDecl *D = DS->getSolitaryDecl(); FirstType = cast<ValueDecl>(D)->getType(); // C99 6.8.5p3: The declaration part of a 'for' statement shall only @@ -630,15 +640,17 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, // 'register'. VarDecl *VD = cast<VarDecl>(D); if (VD->isBlockVarDecl() && !VD->hasLocalStorage()) - return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for); + return StmtError(Diag(VD->getLocation(), + diag::err_non_variable_decl_in_for)); } else { Expr::isLvalueResult lval = cast<Expr>(First)->isLvalue(Context); - + if (lval != Expr::LV_Valid) - return Diag(First->getLocStart(), diag::err_selector_element_not_lvalue) - << First->getSourceRange(); + return StmtError(Diag(First->getLocStart(), + diag::err_selector_element_not_lvalue) + << First->getSourceRange()); - FirstType = static_cast<Expr*>(first)->getType(); + FirstType = static_cast<Expr*>(First)->getType(); } if (!Context.isObjCObjectPointerType(FirstType)) Diag(ForLoc, diag::err_selector_element_type) @@ -651,7 +663,11 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, Diag(ForLoc, diag::err_collection_expr_type) << SecondType << Second->getSourceRange(); } - return new ObjCForCollectionStmt(First, Second, Body, ForLoc, RParenLoc); + first.release(); + second.release(); + body.release(); + return Owned(new ObjCForCollectionStmt(First, Second, Body, + ForLoc, RParenLoc)); } Action::StmtResult |