Convert a bunch of actions to smart pointers, and also bring PrintParserCallbacks a bit more in line with reality.

llvm-svn: 67029
This commit is contained in:
Sebastian Redl 2009-03-15 17:47:39 +00:00
parent afd7c9c855
commit 6d4256c3c1
13 changed files with 617 additions and 402 deletions

View File

@ -584,58 +584,235 @@ namespace {
//===--------------------- GNU Extension Expressions ------------------===//
virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
IdentifierInfo *LabelII) { // "&&foo"
virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc,
SourceLocation LabLoc,
IdentifierInfo *LabelII) {// "&&foo"
llvm::cout << __FUNCTION__ << "\n";
return 0;
return ExprEmpty();
}
virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
SourceLocation RPLoc) { // "({..})"
virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc,
StmtArg SubStmt,
SourceLocation RPLoc) { // "({..})"
llvm::cout << __FUNCTION__ << "\n";
return 0;
return ExprEmpty();
}
virtual ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc,
SourceLocation TypeLoc, TypeTy *Arg1,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RParenLoc) {
virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S,
SourceLocation BuiltinLoc,
SourceLocation TypeLoc,
TypeTy *Arg1,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return 0;
return ExprEmpty();
}
// __builtin_types_compatible_p(type1, type2)
virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1, TypeTy *arg2,
SourceLocation RPLoc) {
virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1,TypeTy *arg2,
SourceLocation RPLoc) {
llvm::cout << __FUNCTION__ << "\n";
return 0;
return ExprEmpty();
}
// __builtin_choose_expr(constExpr, expr1, expr2)
virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
SourceLocation RPLoc) {
virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
ExprArg cond, ExprArg expr1,
ExprArg expr2,
SourceLocation RPLoc) {
llvm::cout << __FUNCTION__ << "\n";
return 0;
return ExprEmpty();
}
// __builtin_overload(...)
virtual ExprResult ActOnOverloadExpr(ExprTy **Args, unsigned NumArgs,
SourceLocation *CommaLocs,
SourceLocation BuiltinLoc,
SourceLocation RPLoc) {
llvm::cout << __FUNCTION__ << "\n";
return 0;
}
// __builtin_va_arg(expr, type)
virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
ExprTy *expr, TypeTy *type,
virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc,
ExprArg expr, TypeTy *type,
SourceLocation RPLoc) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
StmtArg Body,
Scope *CurScope) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
IdentifierInfo *Ident,
SourceLocation LBrace) {
llvm::cout << __FUNCTION__ << "\n";
return 0;
}
virtual void ActOnFinishNamespaceDef(DeclTy *Dcl,SourceLocation RBrace) {
llvm::cout << __FUNCTION__ << "\n";
return;
}
#if 0
// FIXME: AttrList should be deleted by this function, but the definition
// would have to be available.
virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
SourceLocation UsingLoc,
SourceLocation NamespcLoc,
const CXXScopeSpec &SS,
SourceLocation IdentLoc,
IdentifierInfo *NamespcName,
AttributeList *AttrList) {
llvm::cout << __FUNCTION__ << "\n";
return 0;
}
#endif
virtual void ActOnParamDefaultArgument(DeclTy *param,
SourceLocation EqualLoc,
ExprArg defarg) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
SourceLocation EqualLoc) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual void ActOnParamDefaultArgumentError(DeclTy *param) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
SourceLocation LParenLoc,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return;
}
virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method)
{
llvm::cout << __FUNCTION__ << "\n";
}
virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S,
DeclTy *Method) {
llvm::cout << __FUNCTION__ << "\n";
}
virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
ExprArg AssertExpr,
ExprArg AssertMessageExpr,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return 0;
}
virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
tok::TokenKind Kind,
SourceLocation LAngleBracketLoc,
TypeTy *Ty,
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc,
ExprArg Op,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc,
SourceLocation LParenLoc,
bool isType, void *TyOrExpr,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
tok::TokenKind Kind) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc, ExprArg Op) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
TypeTy *TypeRep,
SourceLocation LParenLoc,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
SourceLocation StartLoc,
Declarator &D,
SourceLocation EqualLoc,
ExprArg AssignExprVal) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc,
bool UseGlobal,
SourceLocation PlacementLParen,
MultiExprArg PlacementArgs,
SourceLocation PlacementRParen,
bool ParenTypeId, Declarator &D,
SourceLocation ConstructorLParen,
MultiExprArg ConstructorArgs,
SourceLocation ConstructorRParen) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc,
bool UseGlobal, bool ArrayForm,
ExprArg Operand) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
SourceLocation KWLoc,
SourceLocation LParen,
TypeTy *Ty,
SourceLocation RParen) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
};
}

View File

@ -730,16 +730,17 @@ public:
//===---------------------- GNU Extension Expressions -------------------===//
virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
IdentifierInfo *LabelII) { // "&&foo"
return 0;
virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc,
SourceLocation LabLoc,
IdentifierInfo *LabelII) { // "&&foo"
return ExprEmpty();
}
virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
SourceLocation RPLoc) { // "({..})"
return 0;
virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtArg SubStmt,
SourceLocation RPLoc) { // "({..})"
return ExprEmpty();
}
// __builtin_offsetof(type, identifier(.identifier|[expr])*)
struct OffsetOfComponent {
SourceLocation LocStart, LocEnd;
@ -749,39 +750,41 @@ public:
ExprTy *E;
} U;
};
virtual ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc,
SourceLocation TypeLoc, TypeTy *Arg1,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RParenLoc) {
return 0;
virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S,
SourceLocation BuiltinLoc,
SourceLocation TypeLoc,
TypeTy *Arg1,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RParenLoc) {
return ExprEmpty();
}
// __builtin_types_compatible_p(type1, type2)
virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1, TypeTy *arg2,
SourceLocation RPLoc) {
return 0;
virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1, TypeTy *arg2,
SourceLocation RPLoc) {
return ExprEmpty();
}
// __builtin_choose_expr(constExpr, expr1, expr2)
virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
SourceLocation RPLoc) {
return 0;
virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
ExprArg cond, ExprArg expr1,
ExprArg expr2, SourceLocation RPLoc){
return ExprEmpty();
}
// __builtin_va_arg(expr, type)
virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
ExprTy *expr, TypeTy *type,
SourceLocation RPLoc) {
return 0;
virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc,
ExprArg expr, TypeTy *type,
SourceLocation RPLoc) {
return ExprEmpty();
}
/// ActOnGNUNullExpr - Parsed the GNU __null expression, the token
/// for which is at position TokenLoc.
virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc) {
return 0;
virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc) {
return ExprEmpty();
}
//===------------------------- "Block" Extension ------------------------===//
@ -793,15 +796,18 @@ public:
/// ActOnBlockArguments - This callback allows processing of block arguments.
/// If there are no arguments, this is still invoked.
virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {}
/// ActOnBlockError - If there is an error parsing a block, this callback
/// is invoked to pop the information about the block from the action impl.
virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) {}
/// ActOnBlockStmtExpr - This is called when the body of a block statement
/// literal was successfully completed. ^(int x){...}
virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
Scope *CurScope) { return 0; }
virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
StmtArg Body,
Scope *CurScope) {
return ExprEmpty();
}
//===------------------------- C++ Declarations -------------------------===//
@ -831,7 +837,7 @@ public:
/// ActOnParamDefaultArgument - Parse default argument for function parameter
virtual void ActOnParamDefaultArgument(DeclTy *param,
SourceLocation EqualLoc,
ExprTy *defarg) {
ExprArg defarg) {
}
/// ActOnParamUnparsedDefaultArgument - We've seen a default
@ -850,12 +856,12 @@ public:
/// e.g: "int x(1);"
virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
SourceLocation LParenLoc,
ExprTy **Exprs, unsigned NumExprs,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
return;
}
/// ActOnStartDelayedCXXMethodDeclaration - We have completed
/// parsing a top-level (non-nested) C++ class, and we are now
/// parsing those parts of the given Method declaration that could
@ -881,76 +887,78 @@ public:
/// ActOnStartOfFunctionDef action later (not necessarily
/// immediately!) for this method, if it was also defined inside the
/// class body.
virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method) {
virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method){
}
/// ActOnStaticAssertDeclaration - Parse a C++0x static_assert declaration.
virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
ExprArg AssertExpr,
ExprArg AssertMessageExpr,
SourceLocation RParenLoc) {
return 0;
}
//===------------------------- C++ Expressions --------------------------===//
/// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
SourceLocation LAngleBracketLoc, TypeTy *Ty,
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc, ExprTy *Op,
SourceLocation RParenLoc) {
return 0;
virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
tok::TokenKind Kind,
SourceLocation LAngleBracketLoc,
TypeTy *Ty,
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc,
ExprArg Op,
SourceLocation RParenLoc) {
return ExprEmpty();
}
/// ActOnCXXTypeidOfType - Parse typeid( type-id ).
virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
SourceLocation LParenLoc, bool isType,
void *TyOrExpr, SourceLocation RParenLoc) {
return 0;
virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc,
SourceLocation LParenLoc, bool isType,
void *TyOrExpr,
SourceLocation RParenLoc) {
return ExprEmpty();
}
/// ActOnCXXThis - Parse the C++ 'this' pointer.
virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc) {
return 0;
virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc) {
return ExprEmpty();
}
/// ActOnCXXBoolLiteral - Parse {true,false} literals.
virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
tok::TokenKind Kind) {
return 0;
return ExprEmpty();
}
/// ActOnCXXThrow - Parse throw expressions.
virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
ExprTy *Op = 0) {
return 0;
virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc, ExprArg Op) {
return ExprEmpty();
}
/// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
/// Can be interpreted either as function-style casting ("int(x)")
/// or class type construction ("ClassType(x,y,z)")
/// or creation of a value-initialized type ("int()").
virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
TypeTy *TypeRep,
SourceLocation LParenLoc,
ExprTy **Exprs,
unsigned NumExprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
return 0;
virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
TypeTy *TypeRep,
SourceLocation LParenLoc,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
return ExprEmpty();
}
/// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
/// C++ if/switch/while/for statement.
/// e.g: "if (int x = f()) {...}"
virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
virtual OwningExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
SourceLocation StartLoc,
Declarator &D,
SourceLocation EqualLoc,
ExprTy *AssignExprVal) {
return 0;
ExprArg AssignExprVal) {
return ExprEmpty();
}
/// ActOnCXXNew - Parsed a C++ 'new' expression. UseGlobal is true if the
@ -958,23 +966,24 @@ public:
/// @code new (p1, p2) type(c1, c2) @endcode
/// the p1 and p2 expressions will be in PlacementArgs and the c1 and c2
/// expressions in ConstructorArgs. The type is passed as a declarator.
virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
SourceLocation PlacementLParen,
ExprTy **PlacementArgs, unsigned NumPlaceArgs,
SourceLocation PlacementRParen,
bool ParenTypeId, Declarator &D,
SourceLocation ConstructorLParen,
ExprTy **ConstructorArgs, unsigned NumConsArgs,
SourceLocation ConstructorRParen) {
return 0;
virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
SourceLocation PlacementLParen,
MultiExprArg PlacementArgs,
SourceLocation PlacementRParen,
bool ParenTypeId, Declarator &D,
SourceLocation ConstructorLParen,
MultiExprArg ConstructorArgs,
SourceLocation ConstructorRParen) {
return ExprEmpty();
}
/// ActOnCXXDelete - Parsed a C++ 'delete' expression. UseGlobal is true if
/// the delete was qualified (::delete). ArrayForm is true if the array form
/// was used (delete[]).
virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
bool ArrayForm, ExprTy *Operand) {
return 0;
virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc,
bool UseGlobal, bool ArrayForm,
ExprArg Operand) {
return ExprEmpty();
}
virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,

View File

@ -19,7 +19,7 @@
#include "llvm/Support/raw_ostream.h"
using namespace clang;
/// Out-of-line virtual destructor to provide home for Action class.
/// Out-of-line virtual destructor to provide home for ActionBase class.
ActionBase::~ActionBase() {}
/// Out-of-line virtual destructor to provide home for Action class.

View File

@ -98,7 +98,7 @@ void Parser::ParseLexedMethodDeclarations() {
Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param);
else
Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
DefArgResult.release());
move(DefArgResult));
delete Toks;
LM.DefaultArgs[I].Toks = 0;
}

View File

@ -346,7 +346,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
"Unexpected number of commas!");
Actions.AddCXXDirectInitializerToDecl(LastDeclInGroup, LParenLoc,
Exprs.take(), Exprs.size(),
move_arg(Exprs),
&CommaLocs[0], RParenLoc);
}
} else {
@ -2184,7 +2184,7 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
} else {
// Inform the actions module about the default argument
Actions.ActOnParamDefaultArgument(Param, EqualLoc,
DefArgResult.release());
move(DefArgResult));
}
}
}

View File

@ -625,7 +625,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,
case tok::kw___builtin_types_compatible_p:
return ParseBuiltinPrimaryExpression();
case tok::kw___null:
return Owned(Actions.ActOnGNUNullExpr(ConsumeToken()));
return Actions.ActOnGNUNullExpr(ConsumeToken());
break;
case tok::plusplus: // unary-expression: '++' unary-expression
case tok::minusminus: { // unary-expression: '--' unary-expression
@ -995,8 +995,7 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() {
if (Ty.isInvalid())
Res = ExprError();
else
Res = Actions.ActOnVAArg(StartLoc, Expr.release(), Ty.get(),
ConsumeParen());
Res = Actions.ActOnVAArg(StartLoc, move(Expr), Ty.get(), ConsumeParen());
break;
}
case tok::kw___builtin_offsetof: {
@ -1092,8 +1091,8 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() {
Diag(Tok, diag::err_expected_rparen);
return ExprError();
}
Res = Actions.ActOnChooseExpr(StartLoc, Cond.release(), Expr1.release(),
Expr2.release(), ConsumeParen());
Res = Actions.ActOnChooseExpr(StartLoc, move(Cond), move(Expr1),
move(Expr2), ConsumeParen());
break;
}
case tok::kw___builtin_types_compatible_p:
@ -1151,8 +1150,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType,
// If the substmt parsed correctly, build the AST node.
if (!Stmt.isInvalid() && Tok.is(tok::r_paren))
Result = Actions.ActOnStmtExpr(
OpenLoc, Stmt.release(), Tok.getLocation());
Result = Actions.ActOnStmtExpr(OpenLoc, move(Stmt), Tok.getLocation());
} else if (ExprType >= CompoundLiteral && isTypeIdInParens()) {
// Otherwise, this is a compound literal expression or cast expression.
@ -1344,7 +1342,7 @@ Parser::OwningExprResult Parser::ParseBlockLiteralExpression() {
if (Tok.is(tok::l_brace)) {
OwningStmtResult Stmt(ParseCompoundStatementBody());
if (!Stmt.isInvalid()) {
Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.release(), CurScope);
Result = Actions.ActOnBlockStmtExpr(CaretLoc, move(Stmt), CurScope);
} else {
Actions.ActOnBlockError(CaretLoc, CurScope);
}

View File

@ -328,9 +328,9 @@ Parser::OwningExprResult Parser::ParseCXXCasts() {
if (!Result.isInvalid() && !CastTy.isInvalid())
Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
LAngleBracketLoc, CastTy.get(),
LAngleBracketLoc, CastTy.get(),
RAngleBracketLoc,
LParenLoc, Result.release(), RParenLoc);
LParenLoc, move(Result), RParenLoc);
return move(Result);
}
@ -390,7 +390,7 @@ Parser::OwningExprResult Parser::ParseCXXTypeid() {
/// 'false'
Parser::OwningExprResult Parser::ParseCXXBoolLiteral() {
tok::TokenKind Kind = Tok.getKind();
return Owned(Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind));
return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind);
}
/// ParseThrowExpression - This handles the C++ throw expression.
@ -411,12 +411,12 @@ Parser::OwningExprResult Parser::ParseThrowExpression() {
case tok::r_brace:
case tok::colon:
case tok::comma:
return Owned(Actions.ActOnCXXThrow(ThrowLoc));
return Actions.ActOnCXXThrow(ThrowLoc, ExprArg(Actions));
default:
OwningExprResult Expr(ParseAssignmentExpression());
if (Expr.isInvalid()) return move(Expr);
return Owned(Actions.ActOnCXXThrow(ThrowLoc, Expr.release()));
return Actions.ActOnCXXThrow(ThrowLoc, move(Expr));
}
}
@ -428,7 +428,7 @@ Parser::OwningExprResult Parser::ParseThrowExpression() {
Parser::OwningExprResult Parser::ParseCXXThis() {
assert(Tok.is(tok::kw_this) && "Not 'this'!");
SourceLocation ThisLoc = ConsumeToken();
return Owned(Actions.ActOnCXXThis(ThisLoc));
return Actions.ActOnCXXThis(ThisLoc);
}
/// ParseCXXTypeConstructExpression - Parse construction of a specified type.
@ -463,10 +463,9 @@ Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) {
assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&&
"Unexpected number of commas!");
return Owned(Actions.ActOnCXXTypeConstructExpr(DS.getSourceRange(), TypeRep,
LParenLoc,
Exprs.take(), Exprs.size(),
&CommaLocs[0], RParenLoc));
return Actions.ActOnCXXTypeConstructExpr(DS.getSourceRange(), TypeRep,
LParenLoc, move_arg(Exprs),
&CommaLocs[0], RParenLoc);
}
/// ParseCXXCondition - if/switch/while/for condition expression.
@ -518,9 +517,9 @@ Parser::OwningExprResult Parser::ParseCXXCondition() {
if (AssignExpr.isInvalid())
return ExprError();
return Owned(Actions.ActOnCXXConditionDeclarationExpr(CurScope, StartLoc,
DeclaratorInfo,EqualLoc,
AssignExpr.release()));
return Actions.ActOnCXXConditionDeclarationExpr(CurScope, StartLoc,
DeclaratorInfo,EqualLoc,
move(AssignExpr));
}
/// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
@ -883,11 +882,10 @@ Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) {
}
}
return Owned(Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
PlacementArgs.take(), PlacementArgs.size(),
PlacementRParen, ParenTypeId, DeclaratorInfo,
ConstructorLParen, ConstructorArgs.take(),
ConstructorArgs.size(), ConstructorRParen));
return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
move_arg(PlacementArgs), PlacementRParen,
ParenTypeId, DeclaratorInfo, ConstructorLParen,
move_arg(ConstructorArgs), ConstructorRParen);
}
/// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be
@ -977,8 +975,7 @@ Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) {
if (Operand.isInvalid())
return move(Operand);
return Owned(Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.release()));
return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, move(Operand));
}
static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind)

View File

@ -326,9 +326,9 @@ public:
bool IsFunctionDefinition,
bool& InvalidDecl, bool &Redeclaration);
virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
virtual void ActOnParamDefaultArgument(DeclTy *param,
virtual void ActOnParamDefaultArgument(DeclTy *param,
SourceLocation EqualLoc,
ExprTy *defarg);
ExprArg defarg);
virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
SourceLocation EqualLoc);
virtual void ActOnParamDefaultArgumentError(DeclTy *param);
@ -1266,63 +1266,65 @@ public:
ExprArg RHS);
/// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
IdentifierInfo *LabelII);
virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
SourceLocation RPLoc); // "({..})"
virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc,
SourceLocation LabLoc,
IdentifierInfo *LabelII);
virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtArg SubStmt,
SourceLocation RPLoc); // "({..})"
/// __builtin_offsetof(type, a.b[123][456].c)
virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
SourceLocation BuiltinLoc,
SourceLocation TypeLoc, TypeTy *Arg1,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RParenLoc);
virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S,
SourceLocation BuiltinLoc,
SourceLocation TypeLoc,
TypeTy *Arg1,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RParenLoc);
// __builtin_types_compatible_p(type1, type2)
virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1, TypeTy *arg2,
SourceLocation RPLoc);
virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1, TypeTy *arg2,
SourceLocation RPLoc);
// __builtin_choose_expr(constExpr, expr1, expr2)
virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
SourceLocation RPLoc);
virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
ExprArg cond, ExprArg expr1,
ExprArg expr2, SourceLocation RPLoc);
// __builtin_va_arg(expr, type)
virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
ExprTy *expr, TypeTy *type,
SourceLocation RPLoc);
virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc,
ExprArg expr, TypeTy *type,
SourceLocation RPLoc);
// __null
virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
//===------------------------- "Block" Extension ------------------------===//
/// ActOnBlockStart - This callback is invoked when a block literal is
/// started.
virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
/// ActOnBlockArguments - This callback allows processing of block arguments.
/// If there are no arguments, this is still invoked.
virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
/// ActOnBlockError - If there is an error parsing a block, this callback
/// is invoked to pop the information about the block from the action impl.
virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
/// ActOnBlockStmtExpr - This is called when the body of a block statement
/// literal was successfully completed. ^(int x){...}
virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
Scope *CurScope);
virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
StmtArg Body, Scope *CurScope);
//===---------------------------- C++ Features --------------------------===//
// Act on C++ namespaces
virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
IdentifierInfo *Ident,
SourceLocation LBrace);
IdentifierInfo *Ident,
SourceLocation LBrace);
virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
@ -1340,7 +1342,7 @@ public:
/// e.g: "int x(1);"
virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
SourceLocation LParenLoc,
ExprTy **Exprs, unsigned NumExprs,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc);
@ -1360,49 +1362,52 @@ public:
InitializationKind Kind);
/// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
SourceLocation LAngleBracketLoc, TypeTy *Ty,
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc, ExprTy *E,
SourceLocation RParenLoc);
virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
tok::TokenKind Kind,
SourceLocation LAngleBracketLoc,
TypeTy *Ty,
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc,
ExprArg E,
SourceLocation RParenLoc);
/// ActOnCXXTypeidOfType - Parse typeid( type-id ).
virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
SourceLocation LParenLoc, bool isType,
void *TyOrExpr, SourceLocation RParenLoc);
/// ActOnCXXTypeid - Parse typeid( something ).
virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc,
SourceLocation LParenLoc, bool isType,
void *TyOrExpr,
SourceLocation RParenLoc);
//// ActOnCXXThis - Parse 'this' pointer.
virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc);
/// ActOnCXXBoolLiteral - Parse {true,false} literals.
virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
tok::TokenKind Kind);
virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
tok::TokenKind Kind);
//// ActOnCXXThrow - Parse throw expressions.
virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
ExprTy *expr);
virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc,
ExprArg expr);
/// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
/// Can be interpreted either as function-style casting ("int(x)")
/// or class type construction ("ClassType(x,y,z)")
/// or creation of a value-initialized type ("int()").
virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
TypeTy *TypeRep,
SourceLocation LParenLoc,
ExprTy **Exprs,
unsigned NumExprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc);
virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
TypeTy *TypeRep,
SourceLocation LParenLoc,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc);
/// ActOnCXXNew - Parsed a C++ 'new' expression.
virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
SourceLocation PlacementLParen,
ExprTy **PlacementArgs, unsigned NumPlaceArgs,
SourceLocation PlacementRParen,
bool ParenTypeId, Declarator &D,
SourceLocation ConstructorLParen,
ExprTy **ConstructorArgs, unsigned NumConsArgs,
SourceLocation ConstructorRParen);
virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
SourceLocation PlacementLParen,
MultiExprArg PlacementArgs,
SourceLocation PlacementRParen,
bool ParenTypeId, Declarator &D,
SourceLocation ConstructorLParen,
MultiExprArg ConstructorArgs,
SourceLocation ConstructorRParen);
bool CheckAllocatedType(QualType AllocType, const Declarator &D);
bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
bool UseGlobal, QualType AllocType, bool IsArray,
@ -1418,17 +1423,18 @@ public:
QualType Argument);
/// ActOnCXXDelete - Parsed a C++ 'delete' expression
virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
bool ArrayForm, ExprTy *Operand);
virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc,
bool UseGlobal, bool ArrayForm,
ExprArg Operand);
/// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
/// C++ if/switch/while/for statement.
/// e.g: "if (int x = f()) {...}"
virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
virtual OwningExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
SourceLocation StartLoc,
Declarator &D,
SourceLocation EqualLoc,
ExprTy *AssignExprVal);
ExprArg AssignExprVal);
/// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
/// pseudo-functions.

View File

@ -105,9 +105,9 @@ namespace {
/// to the parameter declaration.
void
Sema::ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc,
ExprTy *defarg) {
ExprArg defarg) {
ParmVarDecl *Param = (ParmVarDecl *)param;
ExprOwningPtr<Expr> DefaultArg(this, (Expr *)defarg);
ExprOwningPtr<Expr> DefaultArg(this, (Expr *)defarg.release());
QualType ParamType = Param->getType();
// Default arguments are only permitted in C++
@ -1448,17 +1448,16 @@ void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) {
/// ActOnDeclarator, when a C++ direct initializer is present.
/// e.g: "int x(1);"
void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc,
ExprTy **ExprTys, unsigned NumExprs,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
assert(NumExprs != 0 && ExprTys && "missing expressions");
unsigned NumExprs = Exprs.size();
assert(NumExprs != 0 && Exprs.get() && "missing expressions");
Decl *RealDecl = static_cast<Decl *>(Dcl);
// If there is no declaration, there was an error parsing it. Just ignore
// the initializer.
if (RealDecl == 0) {
for (unsigned i = 0; i != NumExprs; ++i)
static_cast<Expr *>(ExprTys[i])->Destroy(Context);
return;
}
@ -1489,16 +1488,17 @@ void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc,
if (VDecl->getType()->isRecordType()) {
CXXConstructorDecl *Constructor
= PerformInitializationByConstructor(DeclInitType,
(Expr **)ExprTys, NumExprs,
= PerformInitializationByConstructor(DeclInitType,
(Expr **)Exprs.get(), NumExprs,
VDecl->getLocation(),
SourceRange(VDecl->getLocation(),
RParenLoc),
VDecl->getDeclName(),
IK_Direct);
if (!Constructor) {
if (!Constructor)
RealDecl->setInvalidDecl();
}
else
Exprs.release();
// Let clients know that initialization was done with a direct
// initializer.
@ -1521,7 +1521,8 @@ void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc,
assert(NumExprs == 1 && "Expected 1 expression");
// Set the init expression, handles conversions.
AddInitializerToDecl(Dcl, ExprArg(*this, ExprTys[0]), /*DirectInit=*/true);
AddInitializerToDecl(Dcl, ExprArg(*this, Exprs.release()[0]),
/*DirectInit=*/true);
}
/// PerformInitializationByConstructor - Perform initialization by

View File

@ -4152,9 +4152,9 @@ Action::OwningExprResult Sema::ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
}
/// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Sema::ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc,
SourceLocation LabLoc,
IdentifierInfo *LabelII) {
Sema::OwningExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc,
SourceLocation LabLoc,
IdentifierInfo *LabelII) {
// Look up the record for this label identifier.
LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[LabelII] :
LabelMap[LabelII];
@ -4165,19 +4165,20 @@ Sema::ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc,
LabelDecl = new (Context) LabelStmt(LabLoc, LabelII, 0);
// Create the AST node. The address of a label always has type 'void*'.
return new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl,
Context.getPointerType(Context.VoidTy));
return Owned(new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl,
Context.getPointerType(Context.VoidTy)));
}
Sema::ExprResult Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtTy *substmt,
SourceLocation RPLoc) { // "({..})"
Stmt *SubStmt = static_cast<Stmt*>(substmt);
Sema::OwningExprResult
Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtArg substmt,
SourceLocation RPLoc) { // "({..})"
Stmt *SubStmt = static_cast<Stmt*>(substmt.get());
assert(SubStmt && isa<CompoundStmt>(SubStmt) && "Invalid action invocation!");
CompoundStmt *Compound = cast<CompoundStmt>(SubStmt);
bool isFileScope = getCurFunctionOrMethodDecl() == 0;
if (isFileScope) {
return Diag(LPLoc, diag::err_stmtexpr_file_scope);
return ExprError(Diag(LPLoc, diag::err_stmtexpr_file_scope));
}
// FIXME: there are a variety of strange constraints to enforce here, for
@ -4201,16 +4202,19 @@ Sema::ExprResult Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtTy *substmt,
Ty = LastExpr->getType();
}
return new (Context) StmtExpr(Compound, Ty, LPLoc, RPLoc);
substmt.release();
return Owned(new (Context) StmtExpr(Compound, Ty, LPLoc, RPLoc));
}
Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
SourceLocation BuiltinLoc,
SourceLocation TypeLoc,
TypeTy *argty,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RPLoc) {
Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
SourceLocation BuiltinLoc,
SourceLocation TypeLoc,
TypeTy *argty,
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RPLoc) {
// FIXME: This function leaks all expressions in the offset components on
// error.
QualType ArgTy = QualType::getFromOpaquePtr(argty);
assert(!ArgTy.isNull() && "Missing type argument!");
@ -4220,7 +4224,7 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
// one is known to be a field designator. Verify that the ArgTy represents
// a struct/union/class.
if (!Dependent && !ArgTy->isRecordType())
return Diag(TypeLoc, diag::err_offsetof_record_type) << ArgTy;
return ExprError(Diag(TypeLoc, diag::err_offsetof_record_type) << ArgTy);
// FIXME: Does the type need to be complete?
@ -4228,7 +4232,7 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
// the offsetof designators.
QualType ArgTyPtr = Context.getPointerType(ArgTy);
Expr* Res = new (Context) ImplicitValueInitExpr(ArgTyPtr);
Res = new (Context) UnaryOperator(Res, UnaryOperator::Deref,
Res = new (Context) UnaryOperator(Res, UnaryOperator::Deref,
ArgTy, SourceLocation());
// offsetof with non-identifier designators (e.g. "offsetof(x, a.b[c])") are a
@ -4249,8 +4253,8 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
const ArrayType *AT = Context.getAsArrayType(Res->getType());
if (!AT) {
Res->Destroy(Context);
return Diag(OC.LocEnd, diag::err_offsetof_array_type)
<< Res->getType();
return ExprError(Diag(OC.LocEnd, diag::err_offsetof_array_type)
<< Res->getType());
}
// FIXME: C++: Verify that operator[] isn't overloaded.
@ -4261,9 +4265,11 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
// C99 6.5.2.1p1
Expr *Idx = static_cast<Expr*>(OC.U.E);
// FIXME: Leaks Res
if (!Idx->isTypeDependent() && !Idx->getType()->isIntegerType())
return Diag(Idx->getLocStart(), diag::err_typecheck_subscript)
<< Idx->getSourceRange();
return ExprError(Diag(Idx->getLocStart(),
diag::err_typecheck_subscript)
<< Idx->getSourceRange());
Res = new (Context) ArraySubscriptExpr(Res, Idx, AT->getElementType(),
OC.LocEnd);
@ -4273,8 +4279,8 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
const RecordType *RC = Res->getType()->getAsRecordType();
if (!RC) {
Res->Destroy(Context);
return Diag(OC.LocEnd, diag::err_offsetof_record_type)
<< Res->getType();
return ExprError(Diag(OC.LocEnd, diag::err_offsetof_record_type)
<< Res->getType());
}
// Get the decl corresponding to this.
@ -4283,9 +4289,10 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
= dyn_cast_or_null<FieldDecl>(LookupQualifiedName(RD, OC.U.IdentInfo,
LookupMemberName)
.getAsDecl());
// FIXME: Leaks Res
if (!MemberDecl)
return Diag(BuiltinLoc, diag::err_typecheck_no_member)
<< OC.U.IdentInfo << SourceRange(OC.LocStart, OC.LocEnd);
return ExprError(Diag(BuiltinLoc, diag::err_typecheck_no_member)
<< OC.U.IdentInfo << SourceRange(OC.LocStart, OC.LocEnd));
// FIXME: C++: Verify that MemberDecl isn't a static field.
// FIXME: Verify that MemberDecl isn't a bitfield.
@ -4296,29 +4303,30 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
}
}
return new (Context) UnaryOperator(Res, UnaryOperator::OffsetOf,
Context.getSizeType(), BuiltinLoc);
return Owned(new (Context) UnaryOperator(Res, UnaryOperator::OffsetOf,
Context.getSizeType(), BuiltinLoc));
}
Sema::ExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1, TypeTy *arg2,
SourceLocation RPLoc) {
Sema::OwningExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1,TypeTy *arg2,
SourceLocation RPLoc) {
QualType argT1 = QualType::getFromOpaquePtr(arg1);
QualType argT2 = QualType::getFromOpaquePtr(arg2);
assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)");
return new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc, argT1,
argT2, RPLoc);
return Owned(new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc,
argT1, argT2, RPLoc));
}
Sema::ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, ExprTy *cond,
ExprTy *expr1, ExprTy *expr2,
SourceLocation RPLoc) {
Expr *CondExpr = static_cast<Expr*>(cond);
Expr *LHSExpr = static_cast<Expr*>(expr1);
Expr *RHSExpr = static_cast<Expr*>(expr2);
Sema::OwningExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc,
ExprArg cond,
ExprArg expr1, ExprArg expr2,
SourceLocation RPLoc) {
Expr *CondExpr = static_cast<Expr*>(cond.get());
Expr *LHSExpr = static_cast<Expr*>(expr1.get());
Expr *RHSExpr = static_cast<Expr*>(expr2.get());
assert((CondExpr && LHSExpr && RHSExpr) && "Missing type argument(s)");
@ -4330,15 +4338,17 @@ Sema::ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, ExprTy *cond,
llvm::APSInt condEval(32);
SourceLocation ExpLoc;
if (!CondExpr->isIntegerConstantExpr(condEval, Context, &ExpLoc))
return Diag(ExpLoc, diag::err_typecheck_choose_expr_requires_constant)
<< CondExpr->getSourceRange();
return ExprError(Diag(ExpLoc,
diag::err_typecheck_choose_expr_requires_constant)
<< CondExpr->getSourceRange());
// If the condition is > zero, then the AST type is the same as the LSHExpr.
resType = condEval.getZExtValue() ? LHSExpr->getType() : RHSExpr->getType();
}
return new (Context) ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr,
resType, RPLoc);
cond.release(); expr1.release(); expr2.release();
return Owned(new (Context) ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr,
resType, RPLoc));
}
//===----------------------------------------------------------------------===//
@ -4440,11 +4450,10 @@ void Sema::ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) {
/// ActOnBlockStmtExpr - This is called when the body of a block statement
/// literal was successfully completed. ^(int x){...}
Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body,
Scope *CurScope) {
Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
StmtArg body, Scope *CurScope) {
// Ensure that CurBlock is deleted.
llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock);
ExprOwningPtr<CompoundStmt> Body(this, static_cast<CompoundStmt*>(body));
PopDeclContext();
@ -4468,14 +4477,14 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body,
BlockTy = Context.getBlockPointerType(BlockTy);
BSI->TheDecl->setBody(Body.take());
return new (Context) BlockExpr(BSI->TheDecl, BlockTy, BSI->hasBlockDeclRefExprs);
BSI->TheDecl->setBody(static_cast<CompoundStmt*>(body.release()));
return Owned(new (Context) BlockExpr(BSI->TheDecl, BlockTy,
BSI->hasBlockDeclRefExprs));
}
Sema::ExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc,
ExprTy *expr, TypeTy *type,
SourceLocation RPLoc) {
Expr *E = static_cast<Expr*>(expr);
Sema::OwningExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc,
ExprArg expr, TypeTy *type,
SourceLocation RPLoc) {
QualType T = QualType::getFromOpaquePtr(type);
InitBuiltinVaListType();
@ -4488,19 +4497,22 @@ Sema::ExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc,
if (VaListType->isArrayType())
VaListType = Context.getArrayDecayedType(VaListType);
// Make sure the input expression also decays appropriately.
Expr *E = static_cast<Expr*>(expr.get());
UsualUnaryConversions(E);
if (CheckAssignmentConstraints(VaListType, E->getType()) != Compatible)
return Diag(E->getLocStart(),
diag::err_first_argument_to_va_arg_not_of_type_va_list)
<< E->getType() << E->getSourceRange();
return ExprError(Diag(E->getLocStart(),
diag::err_first_argument_to_va_arg_not_of_type_va_list)
<< E->getType() << E->getSourceRange());
// FIXME: Warn if a non-POD type is passed in.
return new (Context) VAArgExpr(BuiltinLoc, E, T.getNonReferenceType(), RPLoc);
expr.release();
return Owned(new (Context) VAArgExpr(BuiltinLoc, E, T.getNonReferenceType(),
RPLoc));
}
Sema::ExprResult Sema::ActOnGNUNullExpr(SourceLocation TokenLoc) {
Sema::OwningExprResult Sema::ActOnGNUNullExpr(SourceLocation TokenLoc) {
// The type of __null will be int or long, depending on the size of
// pointers on the target.
QualType Ty;
@ -4509,7 +4521,7 @@ Sema::ExprResult Sema::ActOnGNUNullExpr(SourceLocation TokenLoc) {
else
Ty = Context.LongTy;
return new (Context) GNUNullExpr(Ty, TokenLoc);
return Owned(new (Context) GNUNullExpr(Ty, TokenLoc));
}
bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,

View File

@ -56,76 +56,81 @@ Sema::ActOnCXXOperatorFunctionIdExpr(Scope *S, SourceLocation OperatorLoc,
}
/// ActOnCXXTypeidOfType - Parse typeid( type-id ).
Action::ExprResult
Action::OwningExprResult
Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc,
bool isType, void *TyOrExpr, SourceLocation RParenLoc) {
NamespaceDecl *StdNs = GetStdNamespace();
if (!StdNs)
return Diag(OpLoc, diag::err_need_header_before_typeid);
return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid));
IdentifierInfo *TypeInfoII = &PP.getIdentifierTable().get("type_info");
Decl *TypeInfoDecl = LookupQualifiedName(StdNs, TypeInfoII, LookupTagName);
RecordDecl *TypeInfoRecordDecl = dyn_cast_or_null<RecordDecl>(TypeInfoDecl);
if (!TypeInfoRecordDecl)
return Diag(OpLoc, diag::err_need_header_before_typeid);
return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid));
QualType TypeInfoType = Context.getTypeDeclType(TypeInfoRecordDecl);
return new (Context) CXXTypeidExpr(isType, TyOrExpr, TypeInfoType.withConst(),
SourceRange(OpLoc, RParenLoc));
return Owned(new (Context) CXXTypeidExpr(isType, TyOrExpr,
TypeInfoType.withConst(),
SourceRange(OpLoc, RParenLoc)));
}
/// ActOnCXXBoolLiteral - Parse {true,false} literals.
Action::ExprResult
Action::OwningExprResult
Sema::ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
assert((Kind == tok::kw_true || Kind == tok::kw_false) &&
"Unknown C++ Boolean value!");
return new (Context) CXXBoolLiteralExpr(Kind == tok::kw_true, Context.BoolTy, OpLoc);
return Owned(new (Context) CXXBoolLiteralExpr(Kind == tok::kw_true,
Context.BoolTy, OpLoc));
}
/// ActOnCXXThrow - Parse throw expressions.
Action::ExprResult
Sema::ActOnCXXThrow(SourceLocation OpLoc, ExprTy *E) {
return new (Context) CXXThrowExpr((Expr*)E, Context.VoidTy, OpLoc);
Action::OwningExprResult
Sema::ActOnCXXThrow(SourceLocation OpLoc, ExprArg E) {
return Owned(new (Context) CXXThrowExpr((Expr*)E.release(), Context.VoidTy,
OpLoc));
}
Action::ExprResult Sema::ActOnCXXThis(SourceLocation ThisLoc) {
Action::OwningExprResult Sema::ActOnCXXThis(SourceLocation ThisLoc) {
/// C++ 9.3.2: In the body of a non-static member function, the keyword this
/// is a non-lvalue expression whose value is the address of the object for
/// which the function is called.
if (!isa<FunctionDecl>(CurContext)) {
Diag(ThisLoc, diag::err_invalid_this_use);
return ExprResult(true);
}
if (!isa<FunctionDecl>(CurContext))
return ExprError(Diag(ThisLoc, diag::err_invalid_this_use));
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext))
if (MD->isInstance())
return new (Context) CXXThisExpr(ThisLoc, MD->getThisType(Context));
return Owned(new (Context) CXXThisExpr(ThisLoc,
MD->getThisType(Context)));
return Diag(ThisLoc, diag::err_invalid_this_use);
return ExprError(Diag(ThisLoc, diag::err_invalid_this_use));
}
/// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
/// Can be interpreted either as function-style casting ("int(x)")
/// or class type construction ("ClassType(x,y,z)")
/// or creation of a value-initialized type ("int()").
Action::ExprResult
Action::OwningExprResult
Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
SourceLocation LParenLoc,
ExprTy **ExprTys, unsigned NumExprs,
MultiExprArg exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
assert(TypeRep && "Missing type!");
QualType Ty = QualType::getFromOpaquePtr(TypeRep);
Expr **Exprs = (Expr**)ExprTys;
unsigned NumExprs = exprs.size();
Expr **Exprs = (Expr**)exprs.get();
SourceLocation TyBeginLoc = TypeRange.getBegin();
SourceRange FullRange = SourceRange(TyBeginLoc, RParenLoc);
if (Ty->isDependentType() ||
if (Ty->isDependentType() ||
CallExpr::hasAnyTypeDependentArguments(Exprs, NumExprs)) {
return new (Context) CXXTemporaryObjectExpr(0, Ty, TyBeginLoc,
Exprs, NumExprs, RParenLoc);
exprs.release();
return Owned(new (Context) CXXTemporaryObjectExpr(0, Ty, TyBeginLoc,
Exprs, NumExprs,
RParenLoc));
}
@ -136,14 +141,16 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
//
if (NumExprs == 1) {
if (CheckCastTypes(TypeRange, Ty, Exprs[0]))
return true;
return new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(), Ty,
TyBeginLoc, Exprs[0], RParenLoc);
return ExprError();
exprs.release();
return Owned(new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(),
Ty, TyBeginLoc, Exprs[0],
RParenLoc));
}
if (const RecordType *RT = Ty->getAsRecordType()) {
CXXRecordDecl *Record = cast<CXXRecordDecl>(RT->getDecl());
if (NumExprs > 1 || Record->hasUserDeclaredConstructor()) {
CXXConstructorDecl *Constructor
= PerformInitializationByConstructor(Ty, Exprs, NumExprs,
@ -152,12 +159,14 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
RParenLoc),
DeclarationName(),
IK_Direct);
if (!Constructor)
return true;
return new (Context) CXXTemporaryObjectExpr(Constructor, Ty, TyBeginLoc,
Exprs, NumExprs, RParenLoc);
if (!Constructor)
return ExprError();
exprs.release();
return Owned(new (Context) CXXTemporaryObjectExpr(Constructor, Ty,
TyBeginLoc, Exprs,
NumExprs, RParenLoc));
}
// Fall through to value-initialize an object of class type that
@ -169,8 +178,9 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
// be a class with a suitably declared constructor.
//
if (NumExprs > 1)
return Diag(CommaLocs[0], diag::err_builtin_func_cast_more_than_one_arg)
<< FullRange;
return ExprError(Diag(CommaLocs[0],
diag::err_builtin_func_cast_more_than_one_arg)
<< FullRange);
assert(NumExprs == 0 && "Expected 0 expressions");
@ -180,13 +190,15 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
// rvalue of the specified type, which is value-initialized.
//
if (Ty->isArrayType())
return Diag(TyBeginLoc, diag::err_value_init_for_array_type) << FullRange;
return ExprError(Diag(TyBeginLoc,
diag::err_value_init_for_array_type) << FullRange);
if (!Ty->isDependentType() && !Ty->isVoidType() &&
RequireCompleteType(TyBeginLoc, Ty,
diag::err_invalid_incomplete_type_use, FullRange))
return true;
RequireCompleteType(TyBeginLoc, Ty,
diag::err_invalid_incomplete_type_use, FullRange))
return ExprError();
return new (Context) CXXZeroInitValueExpr(Ty, TyBeginLoc, RParenLoc);
exprs.release();
return Owned(new (Context) CXXZeroInitValueExpr(Ty, TyBeginLoc, RParenLoc));
}
@ -195,13 +207,12 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
/// or
/// @code ::new Foo(23, "hello") @endcode
/// For the interpretation of this heap of arguments, consult the base version.
Action::ExprResult
Action::OwningExprResult
Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
SourceLocation PlacementLParen,
ExprTy **PlacementArgs, unsigned NumPlaceArgs,
SourceLocation PlacementLParen, MultiExprArg PlacementArgs,
SourceLocation PlacementRParen, bool ParenTypeId,
Declarator &D, SourceLocation ConstructorLParen,
ExprTy **ConstructorArgs, unsigned NumConsArgs,
MultiExprArg ConstructorArgs,
SourceLocation ConstructorRParen)
{
Expr *ArraySize = 0;
@ -211,21 +222,21 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
D.getTypeObject(0).Kind == DeclaratorChunk::Array) {
DeclaratorChunk &Chunk = D.getTypeObject(0);
if (Chunk.Arr.hasStatic)
return Diag(Chunk.Loc, diag::err_static_illegal_in_new)
<< D.getSourceRange();
return ExprError(Diag(Chunk.Loc, diag::err_static_illegal_in_new)
<< D.getSourceRange());
if (!Chunk.Arr.NumElts)
return Diag(Chunk.Loc, diag::err_array_new_needs_size)
<< D.getSourceRange();
return ExprError(Diag(Chunk.Loc, diag::err_array_new_needs_size)
<< D.getSourceRange());
ArraySize = static_cast<Expr*>(Chunk.Arr.NumElts);
Skip = 1;
}
QualType AllocType = GetTypeForDeclarator(D, /*Scope=*/0, Skip);
if (D.getInvalidType())
return true;
return ExprError();
if (CheckAllocatedType(AllocType, D))
return true;
return ExprError();
QualType ResultType = AllocType->isDependentType()
? Context.DependentTy
@ -239,9 +250,9 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
if (ArraySize && !ArraySize->isTypeDependent()) {
QualType SizeType = ArraySize->getType();
if (!SizeType->isIntegralType() && !SizeType->isEnumeralType())
return Diag(ArraySize->getSourceRange().getBegin(),
diag::err_array_size_not_integral)
<< SizeType << ArraySize->getSourceRange();
return ExprError(Diag(ArraySize->getSourceRange().getBegin(),
diag::err_array_size_not_integral)
<< SizeType << ArraySize->getSourceRange());
// Let's see if this is a constant < 0. If so, we reject it out of hand.
// We don't care about special rules, so we tell the machinery it's not
// evaluated - it gives us a result in more cases.
@ -250,23 +261,24 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
if (ArraySize->isIntegerConstantExpr(Value, Context, 0, false)) {
if (Value < llvm::APSInt(
llvm::APInt::getNullValue(Value.getBitWidth()), false))
return Diag(ArraySize->getSourceRange().getBegin(),
diag::err_typecheck_negative_array_size)
<< ArraySize->getSourceRange();
return ExprError(Diag(ArraySize->getSourceRange().getBegin(),
diag::err_typecheck_negative_array_size)
<< ArraySize->getSourceRange());
}
}
}
FunctionDecl *OperatorNew = 0;
FunctionDecl *OperatorDelete = 0;
Expr **PlaceArgs = (Expr**)PlacementArgs;
Expr **PlaceArgs = (Expr**)PlacementArgs.get();
unsigned NumPlaceArgs = PlacementArgs.size();
if (!AllocType->isDependentType() &&
!Expr::hasAnyTypeDependentArguments(PlaceArgs, NumPlaceArgs) &&
FindAllocationFunctions(StartLoc,
SourceRange(PlacementLParen, PlacementRParen),
UseGlobal, AllocType, ArraySize, PlaceArgs,
NumPlaceArgs, OperatorNew, OperatorDelete))
return true;
return ExprError();
bool Init = ConstructorLParen.isValid();
// --- Choosing a constructor ---
@ -287,7 +299,8 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
// to C++0x rules.
// 2) Otherwise, the object is direct-initialized.
CXXConstructorDecl *Constructor = 0;
Expr **ConsArgs = (Expr**)ConstructorArgs;
Expr **ConsArgs = (Expr**)ConstructorArgs.get();
unsigned NumConsArgs = ConstructorArgs.size();
if (AllocType->isDependentType()) {
// Skip all the checks.
}
@ -303,15 +316,13 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
RT->getDecl()->getDeclName(),
NumConsArgs != 0 ? IK_Direct : IK_Default);
if (!Constructor)
return true;
return ExprError();
} else {
if (!Init) {
// FIXME: Check that no subpart is const.
if (AllocType.isConstQualified()) {
Diag(StartLoc, diag::err_new_uninitialized_const)
<< D.getSourceRange();
return true;
}
if (AllocType.isConstQualified())
return ExprError(Diag(StartLoc, diag::err_new_uninitialized_const)
<< D.getSourceRange());
} else if (NumConsArgs == 0) {
// Object is value-initialized. Do nothing.
} else if (NumConsArgs == 1) {
@ -320,19 +331,22 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
if (CheckInitializerTypes(ConsArgs[0], AllocType, StartLoc,
DeclarationName() /*AllocType.getAsString()*/,
/*DirectInit=*/true))
return true;
return ExprError();
} else {
Diag(StartLoc, diag::err_builtin_direct_init_more_than_one_arg)
<< SourceRange(ConstructorLParen, ConstructorRParen);
return ExprError(Diag(StartLoc,
diag::err_builtin_direct_init_more_than_one_arg)
<< SourceRange(ConstructorLParen, ConstructorRParen));
}
}
// FIXME: Also check that the destructor is accessible. (C++ 5.3.4p16)
return new (Context) CXXNewExpr(UseGlobal, OperatorNew, PlaceArgs,
PlacementArgs.release();
ConstructorArgs.release();
return Owned(new (Context) CXXNewExpr(UseGlobal, OperatorNew, PlaceArgs,
NumPlaceArgs, ParenTypeId, ArraySize, Constructor, Init,
ConsArgs, NumConsArgs, OperatorDelete, ResultType,
StartLoc, Init ? ConstructorRParen : SourceLocation());
StartLoc, Init ? ConstructorRParen : SourceLocation()));
}
/// CheckAllocatedType - Checks that a type is suitable as the allocated type
@ -576,16 +590,16 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
/// @code ::delete ptr; @endcode
/// or
/// @code delete [] ptr; @endcode
Action::ExprResult
Action::OwningExprResult
Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
bool ArrayForm, ExprTy *Operand)
bool ArrayForm, ExprArg Operand)
{
// C++ 5.3.5p1: "The operand shall have a pointer type, or a class type
// having a single conversion function to a pointer type. The result has
// type void."
// DR599 amends "pointer type" to "pointer to object type" in both cases.
Expr *Ex = (Expr *)Operand;
Expr *Ex = (Expr *)Operand.get();
if (!Ex->isTypeDependent()) {
QualType Type = Ex->getType();
@ -593,41 +607,39 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
// FIXME: Find that one conversion function and amend the type.
}
if (!Type->isPointerType()) {
Diag(StartLoc, diag::err_delete_operand) << Type << Ex->getSourceRange();
return true;
}
if (!Type->isPointerType())
return ExprError(Diag(StartLoc, diag::err_delete_operand)
<< Type << Ex->getSourceRange());
QualType Pointee = Type->getAsPointerType()->getPointeeType();
if (!Pointee->isVoidType() &&
if (!Pointee->isVoidType() &&
RequireCompleteType(StartLoc, Pointee, diag::warn_delete_incomplete,
Ex->getSourceRange()))
return true;
else if (!Pointee->isObjectType()) {
Diag(StartLoc, diag::err_delete_operand)
<< Type << Ex->getSourceRange();
return true;
}
return ExprError();
else if (!Pointee->isObjectType())
return ExprError(Diag(StartLoc, diag::err_delete_operand)
<< Type << Ex->getSourceRange());
// FIXME: Look up the correct operator delete overload and pass a pointer
// along.
// FIXME: Check access and ambiguity of operator delete and destructor.
}
return new (Context) CXXDeleteExpr(Context.VoidTy, UseGlobal, ArrayForm, 0,
Ex, StartLoc);
Operand.release();
return Owned(new (Context) CXXDeleteExpr(Context.VoidTy, UseGlobal, ArrayForm,
0, Ex, StartLoc));
}
/// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
/// C++ if/switch/while/for statement.
/// e.g: "if (int x = f()) {...}"
Action::ExprResult
Action::OwningExprResult
Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc,
Declarator &D,
SourceLocation EqualLoc,
ExprTy *AssignExprVal) {
assert(AssignExprVal && "Null assignment expression");
ExprArg AssignExprVal) {
assert(AssignExprVal.get() && "Null assignment expression");
// C++ 6.4p2:
// The declarator shall not specify a function or an array.
@ -642,8 +654,8 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc,
if (Ty->isFunctionType()) { // The declarator shall not specify a function...
// We exit without creating a CXXConditionDeclExpr because a FunctionDecl
// would be created and CXXConditionDeclExpr wants a VarDecl.
return Diag(StartLoc, diag::err_invalid_use_of_function_type)
<< SourceRange(StartLoc, EqualLoc);
return ExprError(Diag(StartLoc, diag::err_invalid_use_of_function_type)
<< SourceRange(StartLoc, EqualLoc));
} else if (Ty->isArrayType()) { // ...or an array.
Diag(StartLoc, diag::err_invalid_use_of_array_type)
<< SourceRange(StartLoc, EqualLoc);
@ -661,15 +673,15 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc,
DeclTy *Dcl = ActOnDeclarator(S, D, 0);
if (!Dcl)
return true;
AddInitializerToDecl(Dcl, ExprArg(*this, AssignExprVal));
return ExprError();
AddInitializerToDecl(Dcl, move(AssignExprVal));
// Mark this variable as one that is declared within a conditional.
if (VarDecl *VD = dyn_cast<VarDecl>((Decl *)Dcl))
VD->setDeclaredInCondition(true);
return new (Context) CXXConditionDeclExpr(StartLoc, EqualLoc,
cast<VarDecl>(static_cast<Decl *>(Dcl)));
return Owned(new (Context) CXXConditionDeclExpr(StartLoc, EqualLoc,
cast<VarDecl>(static_cast<Decl *>(Dcl))));
}
/// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.

View File

@ -55,13 +55,13 @@ static TryStaticCastResult TryStaticImplicitCast(Sema &Self, Expr *SrcExpr,
const SourceRange &OpRange);
/// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
Action::ExprResult
Action::OwningExprResult
Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
SourceLocation LAngleBracketLoc, TypeTy *Ty,
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc, ExprTy *E,
SourceLocation LParenLoc, ExprArg E,
SourceLocation RParenLoc) {
Expr *Ex = (Expr*)E;
Expr *Ex = (Expr*)E.release();
QualType DestType = QualType::getFromOpaquePtr(Ty);
SourceRange OpRange(OpLoc, RParenLoc);
SourceRange DestRange(LAngleBracketLoc, RAngleBracketLoc);
@ -76,29 +76,30 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
case tok::kw_const_cast:
if (!TypeDependent)
CheckConstCast(*this, Ex, DestType, OpRange, DestRange);
return new (Context) CXXConstCastExpr(DestType.getNonReferenceType(), Ex,
DestType, OpLoc);
return Owned(new (Context) CXXConstCastExpr(DestType.getNonReferenceType(),
Ex, DestType, OpLoc));
case tok::kw_dynamic_cast:
if (!TypeDependent)
CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
return new (Context)CXXDynamicCastExpr(DestType.getNonReferenceType(), Ex,
DestType, OpLoc);
return Owned(new (Context)CXXDynamicCastExpr(DestType.getNonReferenceType(),
Ex, DestType, OpLoc));
case tok::kw_reinterpret_cast:
if (!TypeDependent)
CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
return new (Context) CXXReinterpretCastExpr(DestType.getNonReferenceType(),
Ex, DestType, OpLoc);
return Owned(new (Context) CXXReinterpretCastExpr(
DestType.getNonReferenceType(),
Ex, DestType, OpLoc));
case tok::kw_static_cast:
if (!TypeDependent)
CheckStaticCast(*this, Ex, DestType, OpRange);
return new (Context) CXXStaticCastExpr(DestType.getNonReferenceType(), Ex,
DestType, OpLoc);
return Owned(new (Context) CXXStaticCastExpr(DestType.getNonReferenceType(),
Ex, DestType, OpLoc));
}
return true;
return ExprError();
}
/// CheckConstCast - Check that a const_cast\<DestType\>(SrcExpr) is valid.

View File

@ -847,16 +847,18 @@ TemplateExprInstantiator::VisitCXXTemporaryObjectExpr(
if (Args.size() > 1)
CommaLoc
= SemaRef.PP.getLocForEndOfToken(Args[0]->getSourceRange().getEnd());
Sema::ExprResult Result
= SemaRef.ActOnCXXTypeConstructExpr(SourceRange(E->getTypeBeginLoc()
/*, FIXME*/),
T.getAsOpaquePtr(),
/*FIXME*/E->getTypeBeginLoc(),
(void**)&Args[0], Args.size(),
/*HACK*/&CommaLoc,
E->getSourceRange().getEnd());
if (!Result.isInvalid())
return SemaRef.Owned(Result);
Sema::OwningExprResult Result(
SemaRef.ActOnCXXTypeConstructExpr(SourceRange(E->getTypeBeginLoc()
/*, FIXME*/),
T.getAsOpaquePtr(),
/*FIXME*/E->getTypeBeginLoc(),
Sema::MultiExprArg(SemaRef,
(void**)&Args[0],
Args.size()),
/*HACK*/&CommaLoc,
E->getSourceRange().getEnd()));
// At this point, Args no longer owns the arguments, no matter what.
return move(Result);
}
// Clean up the instantiated arguments.