Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

AddExpr Class Reference

#include <Expr.h>

Inheritance diagram for AddExpr:

Inheritance graph
[legend]
Collaboration diagram for AddExpr:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AddExpr (Expr *op1, Expr *op2)
void Canonicize ()

Protected Member Functions

 AddExpr ()
ExprDoSimplify ()
 DECLARE_SERIAL (AddExpr)

Friends

class Expr

Constructor & Destructor Documentation

AddExpr::AddExpr Expr op1,
Expr op2
 

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         }

AddExpr::AddExpr  )  [inline, protected]
 

Definition at line 421 of file Expr.h.

Referenced by DoSimplify().

00421 { }


Member Function Documentation

void AddExpr::Canonicize  )  [virtual]
 

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.

01263         {
01264         if ( expr_greater(op2, op1) ||
01265              (op1->Type()->Tag() == TYPE_INTERVAL &&
01266               op2->Type()->Tag() == TYPE_TIME) ||
01267              (op2->IsConst() && ! is_vector(op2->ExprVal()) && ! op1->IsConst()))
01268                 SwapOps();
01269         }

AddExpr::DECLARE_SERIAL AddExpr   )  [protected]
 

Expr * AddExpr::DoSimplify  )  [protected, virtual]
 

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         }


Friends And Related Function Documentation

friend class Expr [friend]
 

Reimplemented from BinaryExpr.

Definition at line 420 of file Expr.h.


The documentation for this class was generated from the following files:
Generated on Wed Sep 14 03:07:31 2005 for bro_docs by doxygen 1.3.5