#include <Expr.h>
Inheritance diagram for AddExpr:


Public Member Functions | |
| AddExpr (Expr *op1, Expr *op2) | |
| void | Canonicize () |
Protected Member Functions | |
| AddExpr () | |
| Expr * | DoSimplify () |
| DECLARE_SERIAL (AddExpr) | |
Friends | |
| class | Expr |
|
||||||||||||
|
Definition at line 1208 of file Expr.cc. References BroType::AsVectorType(), base_type(), BothArithmetic, EXPR_ADD, Expr::ExprError(), is_vector(), Expr::IsError(), IsVector, max_type(), BinaryExpr::PromoteType(), Expr::SetType(), BroType::Tag(), Expr::Type(), TYPE_INTERVAL, TYPE_TIME, TypeTag, and VectorType::YieldType().
01209 : BinaryExpr(EXPR_ADD, arg_op1, arg_op2) 01210 { 01211 if ( IsError() ) 01212 return; 01213 01214 TypeTag bt1 = op1->Type()->Tag(); 01215 if ( IsVector(bt1) ) 01216 bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); 01217 01218 TypeTag bt2 = op2->Type()->Tag(); 01219 if ( IsVector(bt2) ) 01220 bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); 01221 01222 BroType* base_result_type = 0; 01223 01224 if ( bt1 == TYPE_TIME && bt2 == TYPE_INTERVAL ) 01225 base_result_type = base_type(bt1); 01226 else if ( bt2 == TYPE_TIME && bt1 == TYPE_INTERVAL ) 01227 base_result_type = base_type(bt2); 01228 else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL ) 01229 base_result_type = base_type(bt1); 01230 else if ( BothArithmetic(bt1, bt2) ) 01231 PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); 01232 else 01233 ExprError("requires arithmetic operands"); 01234 01235 if ( base_result_type ) 01236 { 01237 if ( is_vector(op1) || is_vector(op2) ) 01238 SetType(new VectorType(base_result_type)); 01239 else 01240 SetType(base_result_type); 01241 } 01242 } |
|
|
Definition at line 421 of file Expr.h. Referenced by DoSimplify().
00421 { }
|
|
|
Reimplemented from Expr. Definition at line 1262 of file Expr.cc. References expr_greater(), Expr::ExprVal(), is_vector(), Expr::IsConst(), BinaryExpr::SwapOps(), BroType::Tag(), Expr::Type(), TYPE_INTERVAL, and TYPE_TIME.
|
|
|
|
|
|
Reimplemented from BinaryExpr. Definition at line 1244 of file Expr.cc. References AddExpr(), EXPR_NEGATE, Expr::IsZero(), Expr::Ref(), and Expr::Tag().
01245 {
01246 // If there's a constant, then it's in op1, since Canonicize()
01247 // makes sure of that.
01248 if ( op1->IsZero() )
01249 return op2->Ref();
01250
01251 else if ( op1->Tag() == EXPR_NEGATE )
01252 // (-a)+b = b-a
01253 return new AddExpr(op2->Ref(), ((NegExpr*) op1)->Op()->Ref());
01254
01255 else if ( op2->Tag() == EXPR_NEGATE )
01256 // a+(-b) == a-b
01257 return new SubExpr(op1->Ref(), ((NegExpr*) op2)->Op()->Ref());
01258
01259 return this;
01260 }
|
|
|
Reimplemented from BinaryExpr. |
1.3.5