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

Var.h File Reference

#include "ID.h"
#include "Expr.h"
#include "Type.h"

Include dependency graph for Var.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.

Enumerations

enum  decl_type { VAR_REGULAR, VAR_CONST, VAR_REDEF }

Functions

void add_global (ID *id, BroType *t, init_class c, Expr *init, attr_list *attr, decl_type dt)
Stmtadd_local (ID *id, BroType *t, init_class c, Expr *init, attr_list *attr, decl_type dt)
void add_type (ID *id, BroType *t, attr_list *attr, int is_event)
void begin_func (ID *id, const char *module_name, function_flavor flavor, int is_redef, FuncType *t)
void end_func (Stmt *body)
Valinternal_val (const char *name)
Valopt_internal_val (const char *name)
double opt_internal_double (const char *name)
bro_int_t opt_internal_int (const char *name)
StringValopt_internal_string (const char *name)
TableValopt_internal_table (const char *name)
ListValinternal_list_val (const char *name)
BroTypeinternal_type (const char *name)
Funcinternal_func (const char *name)
EventHandlerPtr internal_handler (const char *name)

Variables

EventHandlerPtr bro_signal
int signal_val


Enumeration Type Documentation

enum decl_type
 

Enumeration values:
VAR_REGULAR 
VAR_CONST 
VAR_REDEF 

Definition at line 32 of file Var.h.


Function Documentation

void add_global ID id,
BroType t,
init_class  c,
Expr init,
attr_list *  attr,
decl_type  dt
 

Definition at line 292 of file Var.cc.

References id, and make_var().

Referenced by yyparse().

00294         {
00295         make_var(id, t, c, init, attr, dt, 1);
00296         }

Stmt* add_local ID id,
BroType t,
init_class  c,
Expr init,
attr_list *  attr,
decl_type  dt
 

Definition at line 298 of file Var.cc.

References Scope::AddInit(), current_scope(), BroObj::GetLocationInfo(), id, INIT_FULL, make_var(), Ref(), Stmt::SetLocationInfo(), BroType::Tag(), TYPE_RECORD, TYPE_TABLE, and TYPE_VECTOR.

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

00300         {
00301         make_var(id, t, c, init, attr, dt, 0);
00302 
00303         if ( init )
00304                 {
00305                 if ( c != INIT_FULL )
00306                         id->Error("can't use += / -= for initializations of local variables");
00307 
00308                 Ref(id);
00309 
00310                 Stmt* stmt =
00311                         new ExprStmt(new AssignExpr(new NameExpr(id), init, 0));
00312                 stmt->SetLocationInfo(init->GetLocationInfo());
00313 
00314                 return stmt;
00315                 }
00316 
00317         else
00318                 {
00319                 if ( t->Tag() == TYPE_RECORD || t->Tag() == TYPE_TABLE ||
00320                      t->Tag() == TYPE_VECTOR )
00321                         current_scope()->AddInit(id);
00322 
00323                 return new NullStmt;
00324                 }
00325         }

void add_type ID id,
BroType t,
attr_list *  attr,
int  is_event
 

Definition at line 327 of file Var.cc.

References id.

Referenced by yyparse().

00328         {
00329         id->SetType(t);
00330         id->MakeType();
00331 
00332         if ( attr )
00333                 id->SetAttrs(new Attributes(attr, t));
00334         }

void begin_func ID id,
const char *  module_name,
function_flavor  flavor,
int  is_redef,
FuncType t
 

Definition at line 336 of file Var.cc.

References FuncType::Args(), args, FuncType::ClearYieldType(), copy_string(), ID::Error(), FUNC_FLAVOR_EVENT, TypeDecl::id, id, install_ID(), ID::IsGlobal(), lookup_ID(), push_scope(), same_type(), ID::SetType(), BroType::Tag(), TypeDecl::type, TYPE_VOID, and FuncType::YieldType().

Referenced by yyparse().

00338         {
00339         if ( flavor == FUNC_FLAVOR_EVENT )
00340                 {
00341                 const BroType* yt = t->YieldType();
00342 
00343                 if ( yt && yt->Tag() != TYPE_VOID )
00344                         id->Error("event cannot yield a value", t);
00345 
00346                 t->ClearYieldType();
00347                 }
00348 
00349         if ( id->Type() )
00350                 {
00351                 if ( ! same_type(id->Type(), t) )
00352                         id->Type()->Error("incompatible types", t);
00353                 }
00354 
00355         else if ( is_redef )
00356                 id->Error("redef of not-previously-declared value");
00357 
00358         if ( id->HasVal() )
00359                 {
00360                 int id_is_event = id->ID_Val()->AsFunc()->IsEvent();
00361 
00362                 if ( id_is_event != (flavor == FUNC_FLAVOR_EVENT) )
00363                         id->Error("inconsistency between event and function", t);
00364                 if ( id_is_event )
00365                         {
00366                         if ( is_redef )
00367                                 // Clear out value so it will be replaced.
00368                                 id->SetVal(0);
00369                         }
00370                 else
00371                         {
00372                         if ( ! id->IsRedefinable() )
00373                                 id->Error("already defined");
00374                         }
00375                 }
00376         else
00377                 id->SetType(t);
00378 
00379         push_scope(id);
00380 
00381         RecordType* args = t->Args();
00382         int num_args = args->NumFields();
00383         for ( int i = 0; i < num_args; ++i )
00384                 {
00385                 TypeDecl* arg_i = args->FieldDecl(i);
00386                 ID* arg_id = lookup_ID(arg_i->id, module_name);
00387 
00388                 if ( arg_id && ! arg_id->IsGlobal() )
00389                         arg_id->Error("argument name used twice");
00390 
00391                 arg_id = install_ID(copy_string(arg_i->id), module_name,
00392                                         false, false);
00393                 arg_id->SetType(arg_i->type->Ref());
00394                 }
00395         }

void end_func Stmt body  ) 
 

Definition at line 397 of file Var.cc.

References current_scope(), Scope::GetInits(), id, Scope::Length(), pop_scope(), Scope::ScopeID(), and Val.

Referenced by yyparse().

00398         {
00399         int frame_size = current_scope()->Length();
00400         id_list* inits = current_scope()->GetInits();
00401 
00402         Scope* scope = pop_scope();
00403         ID* id = scope->ScopeID();
00404 
00405         if ( id->HasVal() )
00406                 id->ID_Val()->AsFunc()->AddBody(body, inits, frame_size);
00407         else
00408                 {
00409                 Func* f = new BroFunc(id, body, inits, frame_size);
00410                 id->SetVal(new Val(f));
00411                 id->SetConst();
00412                 }
00413 
00414         id->ID_Val()->AsFunc()->SetScope(scope);
00415         }

Func* internal_func const char *  name  ) 
 

Definition at line 491 of file Var.cc.

References internal_val(), and name.

Referenced by Discarder::Discarder(), and main().

00492         {
00493         Val* v = internal_val(name);
00494         if ( v )
00495                 return v->AsFunc();
00496         else
00497                 return 0;
00498         }

EventHandlerPtr internal_handler const char *  name  ) 
 

Definition at line 500 of file Var.cc.

References event_registry, EventRegistry::Lookup(), name, EventRegistry::Register(), and EventHandler::SetUsed().

Referenced by DNS_Mgr::Init(), main(), and terminate_bro().

00501         {
00502         // If there already is an entry in the registry, we have a
00503         // local handler on the script layer.
00504         EventHandler* h = event_registry->Lookup(name);
00505         if ( h )
00506                 {
00507                 h->SetUsed();
00508                 return h;
00509                 }
00510 
00511         h = new EventHandler(name);
00512         event_registry->Register(h);
00513 
00514         h->SetUsed();
00515 
00516         return h;
00517         }

ListVal* internal_list_val const char *  name  ) 
 

Definition at line 456 of file Var.cc.

References TableVal::ConvertToPureList(), GLOBAL_MODULE_NAME, id, internal_error(), BroType::IsSet(), lookup_ID(), name, BroType::Tag(), Val::Type(), and TYPE_LIST.

Referenced by init_net_var().

00457         {
00458         ID* id = lookup_ID(name, GLOBAL_MODULE_NAME);
00459         if ( ! id )
00460                 return 0;
00461 
00462         Val* v = id->ID_Val();
00463         if ( v )
00464                 {
00465                 if ( v->Type()->Tag() == TYPE_LIST )
00466                         return (ListVal*) v;
00467 
00468                 else if ( v->Type()->IsSet() )
00469                         {
00470                         TableVal* tv = v->AsTableVal();
00471                         ListVal* lv = tv->ConvertToPureList();
00472                         return lv;
00473                         }
00474 
00475                 else
00476                         internal_error("internal variable %s is not a list", name);
00477                 }
00478 
00479         return 0;
00480         }

BroType* internal_type const char *  name  ) 
 

Definition at line 482 of file Var.cc.

References GLOBAL_MODULE_NAME, id, internal_error(), lookup_ID(), and name.

Referenced by NetSessions::BuildHeader(), Discarder::Discarder(), DNS_Mgr::Init(), init_builtin_funcs(), init_general_global_var(), and init_net_var().

00483         {
00484         ID* id = lookup_ID(name, GLOBAL_MODULE_NAME);
00485         if ( ! id )
00486                 internal_error("internal type %s missing", name);
00487 
00488         return id->Type();
00489         }

Val* internal_val const char *  name  ) 
 

Definition at line 417 of file Var.cc.

References GLOBAL_MODULE_NAME, id, internal_error(), lookup_ID(), and name.

Referenced by init_general_global_var(), init_net_var(), internal_func(), main(), OSFingerprint::OSFingerprint(), and SecondaryPath::SecondaryPath().

00418         {
00419         ID* id = lookup_ID(name, GLOBAL_MODULE_NAME);
00420         if ( ! id )
00421                 internal_error("internal variable %s missing", name);
00422 
00423         return id->ID_Val();
00424         }

double opt_internal_double const char *  name  ) 
 

Definition at line 432 of file Var.cc.

References Val::InternalDouble(), name, and opt_internal_val().

Referenced by init_general_global_var(), and init_net_var().

00433         {
00434         Val* v = opt_internal_val(name);
00435         return v ? v->InternalDouble() : 0.0;
00436         }

bro_int_t opt_internal_int const char *  name  ) 
 

Definition at line 438 of file Var.cc.

References bro_int_t, Val::InternalInt(), name, and opt_internal_val().

Referenced by Discarder::Discarder(), init_general_global_var(), and init_net_var().

00439         {
00440         Val* v = opt_internal_val(name);
00441         return v ? v->InternalInt() : 0;
00442         }

StringVal* opt_internal_string const char *  name  ) 
 

Definition at line 444 of file Var.cc.

References name, and opt_internal_val().

Referenced by init_general_global_var(), and init_net_var().

00445         {
00446         Val* v = opt_internal_val(name);
00447         return v ? v->AsStringVal() : 0;
00448         }

TableVal* opt_internal_table const char *  name  ) 
 

Definition at line 450 of file Var.cc.

References name, and opt_internal_val().

Referenced by init_net_var().

00451         {
00452         Val* v = opt_internal_val(name);
00453         return v ? v->AsTableVal() : 0;
00454         }

Val* opt_internal_val const char *  name  ) 
 

Definition at line 426 of file Var.cc.

References GLOBAL_MODULE_NAME, id, lookup_ID(), and name.

Referenced by init_net_var(), opt_internal_double(), opt_internal_int(), opt_internal_string(), and opt_internal_table().

00427         {
00428         ID* id = lookup_ID(name, GLOBAL_MODULE_NAME);
00429         return id ? id->ID_Val() : 0;
00430         }


Variable Documentation

EventHandlerPtr bro_signal
 

Definition at line 56 of file Var.h.

Referenced by main().

int signal_val
 

Definition at line 57 of file Var.h.

Referenced by net_run(), sig_handler(), and termination_signal().


Generated on Wed Sep 14 03:07:22 2005 for bro_docs by doxygen 1.3.5