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

Expr.h File Reference

#include "BroList.h"
#include "ID.h"
#include "Timer.h"
#include "Val.h"
#include "Debug.h"
#include "EventHandler.h"
#include "TraverseTypes.h"

Include dependency graph for Expr.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Classes

class  AddExpr
class  ArithCoerceExpr
class  AssignExpr
class  BinaryExpr
class  BoolExpr
class  CallExpr
class  CondExpr
class  ConstExpr
class  DivideExpr
class  EqExpr
class  EventExpr
class  Expr
class  FieldAssignExpr
class  FieldExpr
class  FlattenExpr
class  HasFieldExpr
class  IncrExpr
class  IndexExpr
class  InExpr
class  ListExpr
class  ModExpr
class  NameExpr
class  NegExpr
class  NotExpr
class  PosExpr
class  RecordAssignExpr
class  RecordCoerceExpr
class  RecordConstructorExpr
class  RecordMatchExpr
class  RefExpr
class  RelExpr
class  ScheduleExpr
class  ScheduleTimer
class  SubExpr
class  TimesExpr
class  UnaryExpr

Defines

#define NUM_EXPRS   (int(EXPR_FLATTEN) + 1)

Enumerations

enum  BroExprTag {
  EXPR_ANY = -1, EXPR_NAME, EXPR_CONST, EXPR_INCR,
  EXPR_DECR, EXPR_NOT, EXPR_POSITIVE, EXPR_NEGATE,
  EXPR_ADD, EXPR_SUB, EXPR_TIMES, EXPR_DIVIDE,
  EXPR_MOD, EXPR_AND, EXPR_OR, EXPR_LT,
  EXPR_LE, EXPR_EQ, EXPR_NE, EXPR_GE,
  EXPR_GT, EXPR_COND, EXPR_REF, EXPR_ASSIGN,
  EXPR_MATCH, EXPR_INDEX, EXPR_FIELD, EXPR_HAS_FIELD,
  EXPR_RECORD_CONSTRUCTOR, EXPR_FIELD_ASSIGN, EXPR_IN, EXPR_LIST,
  EXPR_CALL, EXPR_EVENT, EXPR_SCHEDULE, EXPR_ARITH_COERCE,
  EXPR_RECORD_COERCE, EXPR_FLATTEN, NUM_EXPRS
}
enum  SimplifyType { SIMPLIFY_GENERAL, SIMPLIFY_LHS }

Functions

Exprget_assign_expr (Expr *op1, Expr *op2, int is_init)
int check_and_promote_expr (Expr *&e, BroType *t)
int check_and_promote_exprs (ListExpr *&elements, TypeList *types)
Exprsimplify_expr (Expr *e, SimplifyType simp_type)
ListExprsimplify_expr_list (ListExpr *l, SimplifyType simp_type)
val_list * eval_list (Frame *f, const ListExpr *l)
int same_expr (const Expr *e1, const Expr *e2)
int expr_greater (const Expr *e1, const Expr *e2)
Exprmake_zero (BroType *t)
Exprmake_one (BroType *t)
bool is_vector (Expr *e)


Define Documentation

#define NUM_EXPRS   (int(EXPR_FLATTEN) + 1)
 

Referenced by expr_name().


Enumeration Type Documentation

enum BroExprTag
 

Enumeration values:
EXPR_ANY 
EXPR_NAME 
EXPR_CONST 
EXPR_INCR 
EXPR_DECR 
EXPR_NOT 
EXPR_POSITIVE 
EXPR_NEGATE 
EXPR_ADD 
EXPR_SUB 
EXPR_TIMES 
EXPR_DIVIDE 
EXPR_MOD 
EXPR_AND 
EXPR_OR 
EXPR_LT 
EXPR_LE 
EXPR_EQ 
EXPR_NE 
EXPR_GE 
EXPR_GT 
EXPR_COND 
EXPR_REF 
EXPR_ASSIGN 
EXPR_MATCH 
EXPR_INDEX 
EXPR_FIELD 
EXPR_HAS_FIELD 
EXPR_RECORD_CONSTRUCTOR 
EXPR_FIELD_ASSIGN 
EXPR_IN 
EXPR_LIST 
EXPR_CALL 
EXPR_EVENT 
EXPR_SCHEDULE 
EXPR_ARITH_COERCE 
EXPR_RECORD_COERCE 
EXPR_FLATTEN 
NUM_EXPRS 

Definition at line 35 of file Expr.h.

Referenced by Expr::Tag().

00035              {
00036         EXPR_ANY = -1,
00037         EXPR_NAME, EXPR_CONST,
00038         EXPR_INCR, EXPR_DECR, EXPR_NOT, EXPR_POSITIVE, EXPR_NEGATE,
00039         EXPR_ADD, EXPR_SUB, EXPR_TIMES, EXPR_DIVIDE, EXPR_MOD,
00040         EXPR_AND, EXPR_OR,
00041         EXPR_LT, EXPR_LE, EXPR_EQ, EXPR_NE, EXPR_GE, EXPR_GT,
00042         EXPR_COND,
00043         EXPR_REF,
00044         EXPR_ASSIGN,
00045         EXPR_MATCH,
00046         EXPR_INDEX,
00047         EXPR_FIELD, EXPR_HAS_FIELD,
00048         EXPR_RECORD_CONSTRUCTOR, EXPR_FIELD_ASSIGN,
00049         EXPR_IN,
00050         EXPR_LIST,
00051         EXPR_CALL,
00052         EXPR_EVENT,
00053         EXPR_SCHEDULE,
00054         EXPR_ARITH_COERCE, EXPR_RECORD_COERCE,
00055         EXPR_FLATTEN,
00056 #define NUM_EXPRS (int(EXPR_FLATTEN) + 1)
00057 } BroExprTag;

enum SimplifyType
 

Enumeration values:
SIMPLIFY_GENERAL 
SIMPLIFY_LHS 

Definition at line 59 of file Expr.h.

00059              {
00060         SIMPLIFY_GENERAL,       // regular simplification
00061         SIMPLIFY_LHS,           // simplify as the LHS of an assignment
00062 } SimplifyType;


Function Documentation

int check_and_promote_expr Expr *&  e,
BroType t
 

Definition at line 4509 of file Expr.cc.

References BroType::AsRecordType(), BothArithmetic, EitherArithmetic, BroObj::Error(), max_type(), record_promotion_compatible(), same_type(), BroType::Tag(), Expr::Type(), TYPE_ANY, TYPE_RECORD, and TypeTag.

Referenced by check_and_promote_exprs(), RecordMatchExpr::RecordMatchExpr(), and ReturnStmt::ReturnStmt().

04510         {
04511         BroType* et = e->Type();
04512         TypeTag e_tag = et->Tag();
04513         TypeTag t_tag = t->Tag();
04514 
04515         if ( t->Tag() == TYPE_ANY )
04516                 return 1;
04517 
04518         if ( EitherArithmetic(t_tag, e_tag) )
04519                 {
04520                 if ( e_tag == t_tag )
04521                         return 1;
04522 
04523                 if ( ! BothArithmetic(t_tag, e_tag) )
04524                         {
04525                         t->Error("arithmetic mixed with non-arithmetic", e);
04526                         return 0;
04527                         }
04528 
04529                 TypeTag mt = max_type(t_tag, e_tag);
04530                 if ( mt != t_tag )
04531                         {
04532                         t->Error("over-promotion of arithmetic value", e);
04533                         return 0;
04534                         }
04535 
04536                 e = new ArithCoerceExpr(e, t_tag);
04537                 return 1;
04538                 }
04539 
04540         else if ( ! same_type(t, et) )
04541                 {
04542                 if ( t->Tag() == TYPE_RECORD && et->Tag() == TYPE_RECORD )
04543                         {
04544                         RecordType* t_r = t->AsRecordType();
04545                         RecordType* et_r = et->AsRecordType();
04546 
04547                         if ( record_promotion_compatible(t_r, et_r) )
04548                                 {
04549                                 e = new RecordCoerceExpr(e, t_r);
04550                                 return 1;
04551                                 }
04552                         }
04553 
04554                 t->Error("type clash", e);
04555                 return 0;
04556                 }
04557 
04558         return 1;
04559         }

int check_and_promote_exprs ListExpr *&  elements,
TypeList types
 

Definition at line 4561 of file Expr.cc.

References check_and_promote_expr(), BroObj::Error(), ListExpr::Exprs(), loop_over_list, TYPE_ANY, and TypeList::Types().

Referenced by FuncType::MatchesIndex(), IndexType::MatchesIndex(), and SetType::SetType().

04562         {
04563         expr_list& el = elements->Exprs();
04564         const type_list* tl = types->Types();
04565 
04566         if ( tl->length() == 1 && (*tl)[0]->Tag() == TYPE_ANY )
04567                 return 1;
04568 
04569         if ( el.length() != tl->length() )
04570                 {
04571                 types->Error("indexing mismatch", elements);
04572                 return 0;
04573                 }
04574 
04575         loop_over_list(el, i)
04576                 {
04577                 Expr* e = el[i];
04578                 if ( ! check_and_promote_expr(e, (*tl)[i]) )
04579                         {
04580                         e->Error("type mismatch", (*tl)[i]);
04581                         return 0;
04582                         }
04583                 if ( e != el[i] )
04584                         el.replace(i, e);
04585                 }
04586 
04587         return 1;
04588         }

val_list* eval_list Frame f,
const ListExpr l
 

Definition at line 4609 of file Expr.cc.

References ListExpr::Exprs(), loop_over_list, and Unref().

Referenced by EventExpr::Eval(), CallExpr::Eval(), ScheduleExpr::Eval(), EventStmt::Exec(), and ExprListStmt::Exec().

04610         {
04611         const expr_list& e = l->Exprs();
04612         val_list* v = new val_list(e.length());
04613 
04614         loop_over_list(e, i)
04615                 {
04616                 Val* ev = e[i]->Eval(f);
04617                 if ( ! ev )
04618                         break;
04619                 v->append(ev);
04620                 }
04621 
04622         if ( i < e.length() )
04623                 { // Failure.
04624                 loop_over_list(*v, j)
04625                         Unref((*v)[j]);
04626                 delete v;
04627                 return 0;
04628                 }
04629 
04630         else
04631                 return v;
04632         }

int expr_greater const Expr e1,
const Expr e2
 

Definition at line 4751 of file Expr.cc.

References int, and Expr::Tag().

Referenced by EqExpr::Canonicize(), TimesExpr::Canonicize(), and AddExpr::Canonicize().

04752         {
04753         return int(e1->Tag()) > int(e2->Tag());
04754         }

Expr* get_assign_expr Expr op1,
Expr op2,
int  is_init
 

Definition at line 4499 of file Expr.cc.

References BroType::Tag(), Expr::Type(), TYPE_LIST, and TYPE_RECORD.

Referenced by RecordAssignExpr::RecordAssignExpr(), and yyparse().

04500         {
04501         if ( op1->Type()->Tag() == TYPE_RECORD &&
04502              op2->Type()->Tag() == TYPE_LIST )
04503                 return new RecordAssignExpr(op1, op2, is_init);
04504         else
04505                 return new AssignExpr(op1, op2, is_init);
04506         }

bool is_vector Expr e  )  [inline]
 

Definition at line 988 of file Expr.h.

References BroType::Tag(), Expr::Type(), and TYPE_VECTOR.

Referenced by BinaryExpr::PromoteType().

00988 { return e->Type()->Tag() == TYPE_VECTOR; }

Expr* make_one BroType t  ) 
 

Definition at line 4776 of file Expr.cc.

References make_constant().

Referenced by RelExpr::DoSimplify(), EqExpr::DoSimplify(), BoolExpr::DoSimplify(), and DivideExpr::DoSimplify().

04777         {
04778         return make_constant(t, 1.0);
04779         }

Expr* make_zero BroType t  ) 
 

Definition at line 4771 of file Expr.cc.

References make_constant().

Referenced by RelExpr::DoSimplify(), EqExpr::DoSimplify(), BoolExpr::DoSimplify(), ModExpr::DoSimplify(), and TimesExpr::DoSimplify().

04772         {
04773         return make_constant(t, 0.0);
04774         }

int same_expr const Expr e1,
const Expr e2
 

Definition at line 4634 of file Expr.cc.

References CallExpr::Args(), b1, ScheduleExpr::Event(), EXPR_ADD, EXPR_AND, EXPR_ARITH_COERCE, EXPR_ASSIGN, EXPR_CALL, EXPR_CONST, EXPR_DECR, EXPR_DIVIDE, EXPR_EQ, EXPR_FIELD, EXPR_FIELD_ASSIGN, EXPR_FLATTEN, EXPR_GE, EXPR_GT, EXPR_IN, EXPR_INCR, EXPR_INDEX, EXPR_LE, EXPR_LIST, EXPR_LT, EXPR_MATCH, EXPR_MOD, EXPR_NAME, EXPR_NE, EXPR_NEGATE, EXPR_NOT, EXPR_OR, EXPR_POSITIVE, EXPR_RECORD_COERCE, EXPR_RECORD_CONSTRUCTOR, EXPR_REF, EXPR_SCHEDULE, EXPR_SUB, EXPR_TIMES, ListExpr::Exprs(), FieldExpr::Field(), CallExpr::Func(), NameExpr::Id(), internal_error(), Expr::IsError(), CallExpr::IsPure(), loop_over_list, UnaryExpr::Op(), BinaryExpr::Op1(), BinaryExpr::Op2(), same_type(), same_val(), Expr::Tag(), Expr::Type(), ConstExpr::Value(), and ScheduleExpr::When().

Referenced by RelExpr::DoSimplify(), EqExpr::DoSimplify(), BoolExpr::DoSimplify(), ModExpr::DoSimplify(), DivideExpr::DoSimplify(), and same_stmt().

04635         {
04636         if ( e1 == e2 )
04637                 return 1;
04638 
04639         if ( e1->Tag() != e2->Tag() || ! same_type(e1->Type(), e2->Type()) )
04640                 return 0;
04641 
04642         if ( e1->IsError() || e2->IsError() )
04643                 return 0;
04644 
04645         switch ( e1->Tag() ) {
04646         case EXPR_NAME:
04647                 {
04648                 const NameExpr* n1 = (NameExpr*) e1;
04649                 const NameExpr* n2 = (NameExpr*) e2;
04650                 return n1->Id() == n2->Id();
04651                 }
04652 
04653         case EXPR_CONST:
04654                 {
04655                 const ConstExpr* c1 = (ConstExpr*) e1;
04656                 const ConstExpr* c2 = (ConstExpr*) e2;
04657                 return same_val(c1->Value(), c2->Value());
04658                 }
04659 
04660         case EXPR_INCR:
04661         case EXPR_DECR:
04662         case EXPR_NOT:
04663         case EXPR_NEGATE:
04664         case EXPR_POSITIVE:
04665         case EXPR_REF:
04666         case EXPR_RECORD_CONSTRUCTOR:
04667         case EXPR_FIELD_ASSIGN:
04668         case EXPR_ARITH_COERCE:
04669         case EXPR_RECORD_COERCE:
04670         case EXPR_FLATTEN:
04671                 {
04672                 const UnaryExpr* u1 = (UnaryExpr*) e1;
04673                 const UnaryExpr* u2 = (UnaryExpr*) e2;
04674                 return same_expr(u1->Op(), u2->Op());
04675                 }
04676 
04677         case EXPR_FIELD:
04678                 {
04679                 const FieldExpr* f1 = (FieldExpr*) e1;
04680                 const FieldExpr* f2 = (FieldExpr*) e2;
04681                 return same_expr(f1->Op(), f2->Op()) &&
04682                         f1->Field() == f2->Field();
04683                 }
04684 
04685         case EXPR_SCHEDULE:
04686                 {
04687                 const ScheduleExpr* s1 = (ScheduleExpr*) e1;
04688                 const ScheduleExpr* s2 = (ScheduleExpr*) e2;
04689                 return same_expr(s1->When(), s2->When()) &&
04690                         same_expr(s1->Event(), s2->Event());
04691                 }
04692 
04693         case EXPR_ADD:
04694         case EXPR_SUB:
04695         case EXPR_TIMES:
04696         case EXPR_DIVIDE:
04697         case EXPR_MOD:
04698         case EXPR_AND:
04699         case EXPR_OR:
04700         case EXPR_LT:
04701         case EXPR_LE:
04702         case EXPR_EQ:
04703         case EXPR_NE:
04704         case EXPR_GE:
04705         case EXPR_GT:
04706         case EXPR_ASSIGN:
04707         case EXPR_MATCH:
04708         case EXPR_INDEX:
04709         case EXPR_IN:
04710                 {
04711                 const BinaryExpr* b1 = (BinaryExpr*) e1;
04712                 const BinaryExpr* b2 = (BinaryExpr*) e2;
04713                 return same_expr(b1->Op1(), b2->Op1()) &&
04714                         same_expr(b1->Op2(), b2->Op2());
04715                 }
04716 
04717         case EXPR_LIST:
04718                 {
04719                 const ListExpr* l1 = (ListExpr*) e1;
04720                 const ListExpr* l2 = (ListExpr*) e2;
04721 
04722                 const expr_list& le1 = l1->Exprs();
04723                 const expr_list& le2 = l2->Exprs();
04724 
04725                 if ( le1.length() != le2.length() )
04726                         return 0;
04727 
04728                 loop_over_list(le1, i)
04729                         if ( ! same_expr(le1[i], le2[i]) )
04730                                 return 0;
04731 
04732                 return 1;
04733                 }
04734 
04735         case EXPR_CALL:
04736                 {
04737                 const CallExpr* c1 = (CallExpr*) e1;
04738                 const CallExpr* c2 = (CallExpr*) e2;
04739 
04740                 return same_expr(c1->Func(), c2->Func()) &&
04741                         c1->IsPure() && same_expr(c1->Args(), c2->Args());
04742                 }
04743 
04744         default:
04745                 internal_error("bad tag in same_expr()");
04746         }
04747 
04748         return 0;
04749         }

Expr* simplify_expr Expr e,
SimplifyType  simp_type
 

Definition at line 4590 of file Expr.cc.

References Expr::Simplify(), and Unref().

Referenced by NegExpr::DoSimplify(), PosExpr::DoSimplify(), NotExpr::DoSimplify(), ExprStmt::Simplify(), ListExpr::Simplify(), CallExpr::Simplify(), FieldExpr::Simplify(), IndexExpr::Simplify(), AssignExpr::Simplify(), CondExpr::Simplify(), UnaryExpr::Simplify(), simplify_expr_list(), and BinaryExpr::SimplifyOps().

04591         {
04592         if ( ! e )
04593                 return 0;
04594 
04595         for ( Expr* s = e->Simplify(simp_type); s != e; s = e->Simplify(simp_type) )
04596                 {
04597                 Unref(e);
04598                 e = s;
04599                 }
04600 
04601         return e;
04602         }

ListExpr* simplify_expr_list ListExpr l,
SimplifyType  simp_type
 

Definition at line 4604 of file Expr.cc.

References simplify_expr().

Referenced by SwitchStmt::DoSimplify(), ExprListStmt::Simplify(), EventExpr::Simplify(), and CallExpr::Simplify().

04605         {
04606         return (ListExpr*) simplify_expr(l, simp_type);
04607         }


Generated on Wed Sep 14 02:59:37 2005 for bro_docs by doxygen 1.3.5