зеркало из https://github.com/microsoft/clang-1.git
Convert more expression actions to smart pointers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62537 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
95389dd073
Коммит
b8a6aca87d
|
@ -542,42 +542,45 @@ namespace {
|
|||
llvm::cout << __FUNCTION__ << "\n";
|
||||
return ExprEmpty();
|
||||
}
|
||||
|
||||
virtual ExprResult ActOnCompoundLiteral(SourceLocation LParen, TypeTy *Ty,
|
||||
SourceLocation RParen, ExprTy *Op) {
|
||||
|
||||
virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParen,
|
||||
TypeTy *Ty,
|
||||
SourceLocation RParen,
|
||||
ExprArg Op) {
|
||||
llvm::cout << __FUNCTION__ << "\n";
|
||||
return 0;
|
||||
return ExprEmpty();
|
||||
}
|
||||
virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
|
||||
ExprTy **InitList, unsigned NumInit,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RParenLoc) {
|
||||
virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
|
||||
MultiExprArg InitList,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RParenLoc) {
|
||||
llvm::cout << __FUNCTION__ << "\n";
|
||||
return 0;
|
||||
return ExprEmpty();
|
||||
}
|
||||
virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprTy *Op) {
|
||||
virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc,ExprArg Op){
|
||||
llvm::cout << __FUNCTION__ << "\n";
|
||||
return 0;
|
||||
return ExprEmpty();
|
||||
}
|
||||
|
||||
virtual ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprTy *LHS, ExprTy *RHS) {
|
||||
|
||||
virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprArg LHS, ExprArg RHS) {
|
||||
llvm::cout << __FUNCTION__ << "\n";
|
||||
return 0;
|
||||
return ExprEmpty();
|
||||
}
|
||||
|
||||
/// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
|
||||
/// in the case of a the GNU conditional expr extension.
|
||||
virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprTy *Cond, ExprTy *LHS, ExprTy *RHS){
|
||||
virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprArg Cond, ExprArg LHS,
|
||||
ExprArg RHS) {
|
||||
llvm::cout << __FUNCTION__ << "\n";
|
||||
return 0;
|
||||
return ExprEmpty();
|
||||
}
|
||||
|
||||
//===---------------------- GNU Extension Expressions -------------------===//
|
||||
|
||||
//===--------------------- GNU Extension Expressions ------------------===//
|
||||
|
||||
virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
|
||||
IdentifierInfo *LabelII) { // "&&foo"
|
||||
|
|
|
@ -629,35 +629,38 @@ public:
|
|||
return ExprEmpty();
|
||||
}
|
||||
|
||||
virtual ExprResult ActOnCompoundLiteral(SourceLocation LParen, TypeTy *Ty,
|
||||
SourceLocation RParen, ExprTy *Op) {
|
||||
return 0;
|
||||
virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParen,
|
||||
TypeTy *Ty,
|
||||
SourceLocation RParen,
|
||||
ExprArg Op) {
|
||||
return ExprEmpty();
|
||||
}
|
||||
virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
|
||||
ExprTy **InitList, unsigned NumInit,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RParenLoc) {
|
||||
return 0;
|
||||
virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
|
||||
MultiExprArg InitList,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RParenLoc) {
|
||||
return ExprEmpty();
|
||||
}
|
||||
virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprTy *Op) {
|
||||
return 0;
|
||||
virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprArg Op) {
|
||||
return ExprEmpty();
|
||||
}
|
||||
|
||||
virtual ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprTy *LHS, ExprTy *RHS) {
|
||||
return 0;
|
||||
|
||||
virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprArg LHS, ExprArg RHS) {
|
||||
return ExprEmpty();
|
||||
}
|
||||
|
||||
/// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
|
||||
/// in the case of a the GNU conditional expr extension.
|
||||
virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprTy *Cond, ExprTy *LHS, ExprTy *RHS){
|
||||
return 0;
|
||||
virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprArg Cond, ExprArg LHS,
|
||||
ExprArg RHS) {
|
||||
return ExprEmpty();
|
||||
}
|
||||
|
||||
|
||||
//===---------------------- GNU Extension Expressions -------------------===//
|
||||
|
||||
virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
|
||||
|
|
|
@ -315,12 +315,12 @@ Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, unsigned MinPrec) {
|
|||
// Combine the LHS and RHS into the LHS (e.g. build AST).
|
||||
if (TernaryMiddle.isInvalid())
|
||||
LHS = Actions.ActOnBinOp(CurScope, OpToken.getLocation(),
|
||||
OpToken.getKind(), LHS.release(),
|
||||
RHS.release());
|
||||
OpToken.getKind(), move_arg(LHS),
|
||||
move_arg(RHS));
|
||||
else
|
||||
LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc,
|
||||
LHS.release(), TernaryMiddle.release(),
|
||||
RHS.release());
|
||||
move_arg(LHS), move_arg(TernaryMiddle),
|
||||
move_arg(RHS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
|
|||
Res = ParseCastExpression(false);
|
||||
if (!Res.isInvalid())
|
||||
Res = Actions.ActOnCastExpr(LParenLoc, CastTy, RParenLoc,
|
||||
Res.release());
|
||||
move_arg(Res));
|
||||
return move(Res);
|
||||
}
|
||||
|
||||
|
@ -1097,11 +1097,11 @@ Parser::ParseParenExpression(ParenParseOption &ExprType,
|
|||
Result = ParseInitializer();
|
||||
ExprType = CompoundLiteral;
|
||||
if (!Result.isInvalid())
|
||||
return Owned(Actions.ActOnCompoundLiteral(OpenLoc, Ty, RParenLoc,
|
||||
Result.release()));
|
||||
return Actions.ActOnCompoundLiteral(OpenLoc, Ty, RParenLoc,
|
||||
move_arg(Result));
|
||||
return move(Result);
|
||||
}
|
||||
|
||||
|
||||
if (ExprType == CastExpr) {
|
||||
// Note that this doesn't parse the subsequence cast-expression, it just
|
||||
// returns the parsed type to the callee.
|
||||
|
@ -1109,7 +1109,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType,
|
|||
CastTy = Ty;
|
||||
return OwningExprResult(Actions);
|
||||
}
|
||||
|
||||
|
||||
Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
|
||||
return ExprError();
|
||||
} else {
|
||||
|
|
|
@ -253,8 +253,8 @@ Parser::OwningExprResult Parser::ParseBraceInitializer() {
|
|||
if (Tok.is(tok::r_brace)) {
|
||||
Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
|
||||
// Match the '}'.
|
||||
return Owned(Actions.ActOnInitList(LBraceLoc, 0, 0, InitExprDesignations,
|
||||
ConsumeBrace()));
|
||||
return Actions.ActOnInitList(LBraceLoc, Action::MultiExprArg(Actions),
|
||||
InitExprDesignations, ConsumeBrace());
|
||||
}
|
||||
|
||||
bool InitExprsOk = true;
|
||||
|
@ -309,9 +309,8 @@ Parser::OwningExprResult Parser::ParseBraceInitializer() {
|
|||
if (Tok.is(tok::r_brace)) break;
|
||||
}
|
||||
if (InitExprsOk && Tok.is(tok::r_brace))
|
||||
return Owned(Actions.ActOnInitList(LBraceLoc, InitExprs.take(),
|
||||
InitExprs.size(),
|
||||
InitExprDesignations, ConsumeBrace()));
|
||||
return Actions.ActOnInitList(LBraceLoc, move_arg(InitExprs),
|
||||
InitExprDesignations, ConsumeBrace());
|
||||
|
||||
// Match the '}'.
|
||||
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
|
||||
|
|
|
@ -255,7 +255,7 @@ public:
|
|||
OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
|
||||
|
||||
virtual void ActOnEndOfTranslationUnit();
|
||||
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Type Analysis / Processing: SemaType.cpp.
|
||||
//
|
||||
|
@ -310,7 +310,7 @@ public:
|
|||
virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
|
||||
virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
|
||||
virtual void ObjCActOnStartOfMethodDef(Scope *S, DeclTy *D);
|
||||
|
||||
|
||||
virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
|
||||
virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
|
||||
|
||||
|
@ -1029,29 +1029,31 @@ public:
|
|||
SourceLocation *CommaLocs,
|
||||
SourceLocation RParenLoc);
|
||||
|
||||
virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprTy *Op);
|
||||
|
||||
virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprTy *Op);
|
||||
|
||||
virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
|
||||
ExprTy **InitList, unsigned NumInit,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RParenLoc);
|
||||
|
||||
virtual ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprTy *LHS,ExprTy *RHS);
|
||||
ExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
|
||||
unsigned Opc,
|
||||
Expr *lhs, Expr *rhs);
|
||||
virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprArg Op);
|
||||
|
||||
virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
|
||||
TypeTy *Ty,
|
||||
SourceLocation RParenLoc,
|
||||
ExprArg Op);
|
||||
|
||||
virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
|
||||
MultiExprArg InitList,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RParenLoc);
|
||||
|
||||
virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprArg LHS, ExprArg RHS);
|
||||
OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
|
||||
unsigned Opc, Expr *lhs, Expr *rhs);
|
||||
|
||||
/// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
|
||||
/// in the case of a the GNU conditional expr extension.
|
||||
virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
|
||||
virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprArg Cond, ExprArg LHS,
|
||||
ExprArg RHS);
|
||||
|
||||
/// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
|
||||
virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
|
||||
|
|
|
@ -1896,50 +1896,52 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
|
|||
return Owned(TheCall.take());
|
||||
}
|
||||
|
||||
Action::ExprResult Sema::
|
||||
ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprTy *InitExpr) {
|
||||
Action::OwningExprResult
|
||||
Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprArg InitExpr) {
|
||||
assert((Ty != 0) && "ActOnCompoundLiteral(): missing type");
|
||||
QualType literalType = QualType::getFromOpaquePtr(Ty);
|
||||
// FIXME: put back this assert when initializers are worked out.
|
||||
//assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression");
|
||||
Expr *literalExpr = static_cast<Expr*>(InitExpr);
|
||||
Expr *literalExpr = static_cast<Expr*>(InitExpr.get());
|
||||
|
||||
if (literalType->isArrayType()) {
|
||||
if (literalType->isVariableArrayType())
|
||||
return Diag(LParenLoc, diag::err_variable_object_no_init)
|
||||
<< SourceRange(LParenLoc, literalExpr->getSourceRange().getEnd());
|
||||
return ExprError(Diag(LParenLoc, diag::err_variable_object_no_init)
|
||||
<< SourceRange(LParenLoc, literalExpr->getSourceRange().getEnd()));
|
||||
} else if (DiagnoseIncompleteType(LParenLoc, literalType,
|
||||
diag::err_typecheck_decl_incomplete_type,
|
||||
SourceRange(LParenLoc, literalExpr->getSourceRange().getEnd())))
|
||||
return true;
|
||||
return ExprError();
|
||||
|
||||
if (CheckInitializerTypes(literalExpr, literalType, LParenLoc,
|
||||
if (CheckInitializerTypes(literalExpr, literalType, LParenLoc,
|
||||
DeclarationName(), /*FIXME:DirectInit=*/false))
|
||||
return true;
|
||||
return ExprError();
|
||||
|
||||
bool isFileScope = getCurFunctionOrMethodDecl() == 0;
|
||||
if (isFileScope) { // 6.5.2.5p3
|
||||
if (CheckForConstantInitializer(literalExpr, literalType))
|
||||
return true;
|
||||
return ExprError();
|
||||
}
|
||||
return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr,
|
||||
isFileScope);
|
||||
InitExpr.release();
|
||||
return Owned(new CompoundLiteralExpr(LParenLoc, literalType, literalExpr,
|
||||
isFileScope));
|
||||
}
|
||||
|
||||
Action::ExprResult Sema::
|
||||
ActOnInitList(SourceLocation LBraceLoc, ExprTy **initlist, unsigned NumInit,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RBraceLoc) {
|
||||
Expr **InitList = reinterpret_cast<Expr**>(initlist);
|
||||
Action::OwningExprResult
|
||||
Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist,
|
||||
InitListDesignations &Designators,
|
||||
SourceLocation RBraceLoc) {
|
||||
unsigned NumInit = initlist.size();
|
||||
Expr **InitList = reinterpret_cast<Expr**>(initlist.release());
|
||||
|
||||
// Semantic analysis for initializers is done by ActOnDeclarator() and
|
||||
// CheckInitializer() - it requires knowledge of the object being intialized.
|
||||
|
||||
|
||||
InitListExpr *E = new InitListExpr(LBraceLoc, InitList, NumInit, RBraceLoc,
|
||||
Designators.hasAnyDesignators());
|
||||
E->setType(Context.VoidTy); // FIXME: just a place holder for now.
|
||||
return E;
|
||||
return Owned(E);
|
||||
}
|
||||
|
||||
/// CheckCastTypes - Check type constraints for casting between types.
|
||||
|
@ -2013,17 +2015,19 @@ bool Sema::CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty) {
|
|||
return false;
|
||||
}
|
||||
|
||||
Action::ExprResult Sema::
|
||||
ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprTy *Op) {
|
||||
assert((Ty != 0) && (Op != 0) && "ActOnCastExpr(): missing type or expr");
|
||||
Action::OwningExprResult
|
||||
Sema::ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
SourceLocation RParenLoc, ExprArg Op) {
|
||||
assert((Ty != 0) && (Op.get() != 0) &&
|
||||
"ActOnCastExpr(): missing type or expr");
|
||||
|
||||
Expr *castExpr = static_cast<Expr*>(Op);
|
||||
Expr *castExpr = static_cast<Expr*>(Op.release());
|
||||
QualType castType = QualType::getFromOpaquePtr(Ty);
|
||||
|
||||
if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr))
|
||||
return true;
|
||||
return new CStyleCastExpr(castType, castExpr, castType, LParenLoc, RParenLoc);
|
||||
return ExprError();
|
||||
return Owned(new CStyleCastExpr(castType, castExpr, castType,
|
||||
LParenLoc, RParenLoc));
|
||||
}
|
||||
|
||||
/// Note that lex is not null here, even if this is the gnu "x ?: y" extension.
|
||||
|
@ -2221,25 +2225,29 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
|
|||
|
||||
/// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
|
||||
/// in the case of a the GNU conditional expr extension.
|
||||
Action::ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprTy *Cond, ExprTy *LHS,
|
||||
ExprTy *RHS) {
|
||||
Expr *CondExpr = (Expr *) Cond;
|
||||
Expr *LHSExpr = (Expr *) LHS, *RHSExpr = (Expr *) RHS;
|
||||
Action::OwningExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
|
||||
SourceLocation ColonLoc,
|
||||
ExprArg Cond, ExprArg LHS,
|
||||
ExprArg RHS) {
|
||||
Expr *CondExpr = (Expr *) Cond.get();
|
||||
Expr *LHSExpr = (Expr *) LHS.get(), *RHSExpr = (Expr *) RHS.get();
|
||||
|
||||
// If this is the gnu "x ?: y" extension, analyze the types as though the LHS
|
||||
// was the condition.
|
||||
bool isLHSNull = LHSExpr == 0;
|
||||
if (isLHSNull)
|
||||
LHSExpr = CondExpr;
|
||||
|
||||
QualType result = CheckConditionalOperands(CondExpr, LHSExpr,
|
||||
|
||||
QualType result = CheckConditionalOperands(CondExpr, LHSExpr,
|
||||
RHSExpr, QuestionLoc);
|
||||
if (result.isNull())
|
||||
return true;
|
||||
return new ConditionalOperator(CondExpr, isLHSNull ? 0 : LHSExpr,
|
||||
RHSExpr, result);
|
||||
return ExprError();
|
||||
|
||||
Cond.release();
|
||||
LHS.release();
|
||||
RHS.release();
|
||||
return Owned(new ConditionalOperator(CondExpr, isLHSNull ? 0 : LHSExpr,
|
||||
RHSExpr, result));
|
||||
}
|
||||
|
||||
|
||||
|
@ -3420,9 +3428,9 @@ static inline UnaryOperator::Opcode ConvertTokenKindToUnaryOpcode(
|
|||
/// CreateBuiltinBinOp - Creates a new built-in binary operation with
|
||||
/// operator @p Opc at location @c TokLoc. This routine only supports
|
||||
/// built-in operations; ActOnBinOp handles overloaded operators.
|
||||
Action::ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
|
||||
unsigned Op,
|
||||
Expr *lhs, Expr *rhs) {
|
||||
Action::OwningExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
|
||||
unsigned Op,
|
||||
Expr *lhs, Expr *rhs) {
|
||||
QualType ResultTy; // Result type of the binary operator.
|
||||
QualType CompTy; // Computation type for compound assignments (e.g. '+=')
|
||||
BinaryOperator::Opcode Opc = (BinaryOperator::Opcode)Op;
|
||||
|
@ -3508,19 +3516,20 @@ Action::ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
|
|||
break;
|
||||
}
|
||||
if (ResultTy.isNull())
|
||||
return true;
|
||||
return ExprError();
|
||||
if (CompTy.isNull())
|
||||
return new BinaryOperator(lhs, rhs, Opc, ResultTy, OpLoc);
|
||||
return Owned(new BinaryOperator(lhs, rhs, Opc, ResultTy, OpLoc));
|
||||
else
|
||||
return new CompoundAssignOperator(lhs, rhs, Opc, ResultTy, CompTy, OpLoc);
|
||||
return Owned(new CompoundAssignOperator(lhs, rhs, Opc, ResultTy,
|
||||
CompTy, OpLoc));
|
||||
}
|
||||
|
||||
// Binary Operators. 'Tok' is the token for the operator.
|
||||
Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprTy *LHS, ExprTy *RHS) {
|
||||
Action::OwningExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
||||
tok::TokenKind Kind,
|
||||
ExprArg LHS, ExprArg RHS) {
|
||||
BinaryOperator::Opcode Opc = ConvertTokenKindToBinaryOpcode(Kind);
|
||||
Expr *lhs = (Expr *)LHS, *rhs = (Expr*)RHS;
|
||||
Expr *lhs = (Expr *)LHS.release(), *rhs = (Expr*)RHS.release();
|
||||
|
||||
assert((lhs != 0) && "ActOnBinOp(): missing left expression");
|
||||
assert((rhs != 0) && "ActOnBinOp(): missing right expression");
|
||||
|
@ -3530,10 +3539,12 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
|||
// lookup for operator+.
|
||||
if (lhs->isTypeDependent() || rhs->isTypeDependent()) {
|
||||
if (Opc > BinaryOperator::Assign && Opc <= BinaryOperator::OrAssign)
|
||||
return new CompoundAssignOperator(lhs, rhs, Opc, Context.DependentTy,
|
||||
Context.DependentTy, TokLoc);
|
||||
return Owned(new CompoundAssignOperator(lhs, rhs, Opc,
|
||||
Context.DependentTy,
|
||||
Context.DependentTy, TokLoc));
|
||||
else
|
||||
return new BinaryOperator(lhs, rhs, Opc, Context.DependentTy, TokLoc);
|
||||
return Owned(new BinaryOperator(lhs, rhs, Opc, Context.DependentTy,
|
||||
TokLoc));
|
||||
}
|
||||
|
||||
if (getLangOptions().CPlusPlus &&
|
||||
|
@ -3546,7 +3557,7 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
|||
!(lhs->getType()->isRecordType() || lhs->getType()->isEnumeralType())) {
|
||||
return CreateBuiltinBinOp(TokLoc, Opc, lhs, rhs);
|
||||
}
|
||||
|
||||
|
||||
// Determine which overloaded operator we're dealing with.
|
||||
static const OverloadedOperatorKind OverOps[] = {
|
||||
OO_Star, OO_Slash, OO_Percent,
|
||||
|
@ -3591,27 +3602,27 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
|||
if (PerformObjectArgumentInitialization(lhs, Method) ||
|
||||
PerformCopyInitialization(rhs, FnDecl->getParamDecl(0)->getType(),
|
||||
"passing"))
|
||||
return true;
|
||||
return ExprError();
|
||||
} else {
|
||||
// Convert the arguments.
|
||||
if (PerformCopyInitialization(lhs, FnDecl->getParamDecl(0)->getType(),
|
||||
"passing") ||
|
||||
PerformCopyInitialization(rhs, FnDecl->getParamDecl(1)->getType(),
|
||||
"passing"))
|
||||
return true;
|
||||
return ExprError();
|
||||
}
|
||||
|
||||
// Determine the result type
|
||||
QualType ResultTy
|
||||
QualType ResultTy
|
||||
= FnDecl->getType()->getAsFunctionType()->getResultType();
|
||||
ResultTy = ResultTy.getNonReferenceType();
|
||||
|
||||
|
||||
// Build the actual expression node.
|
||||
Expr *FnExpr = new DeclRefExpr(FnDecl, FnDecl->getType(),
|
||||
Expr *FnExpr = new DeclRefExpr(FnDecl, FnDecl->getType(),
|
||||
SourceLocation());
|
||||
UsualUnaryConversions(FnExpr);
|
||||
|
||||
return new CXXOperatorCallExpr(FnExpr, Args, 2, ResultTy, TokLoc);
|
||||
return Owned(new CXXOperatorCallExpr(FnExpr, Args, 2, ResultTy,TokLoc));
|
||||
} else {
|
||||
// We matched a built-in operator. Convert the arguments, then
|
||||
// break out so that we will build the appropriate built-in
|
||||
|
@ -3620,10 +3631,10 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
|||
Best->Conversions[0], "passing") ||
|
||||
PerformImplicitConversion(rhs, Best->BuiltinTypes.ParamTypes[1],
|
||||
Best->Conversions[1], "passing"))
|
||||
return true;
|
||||
return ExprError();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case OR_No_Viable_Function:
|
||||
|
@ -3636,14 +3647,14 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
|
|||
<< BinaryOperator::getOpcodeStr(Opc)
|
||||
<< lhs->getSourceRange() << rhs->getSourceRange();
|
||||
PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/true);
|
||||
return true;
|
||||
return ExprError();
|
||||
}
|
||||
|
||||
// Either we found no viable overloaded operator or we matched a
|
||||
// built-in operator. In either case, fall through to trying to
|
||||
// build a built-in operation.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Build a built-in binary operation.
|
||||
return CreateBuiltinBinOp(TokLoc, Opc, lhs, rhs);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче