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

Attributes Class Reference

#include <Attr.h>

Inheritance diagram for Attributes:

Inheritance graph
[legend]
Collaboration diagram for Attributes:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Attributes (attr_list *a, BroType *t)
 ~Attributes ()
void AddAttr (Attr *a)
void AddAttrs (Attributes *a)
AttrFindAttr (attr_tag t) const
void RemoveAttr (attr_tag t)
void Describe (ODesc *d) const
attr_list * Attrs ()
bool Serialize (SerialInfo *info) const

Static Public Member Functions

AttributesUnserialize (UnserialInfo *info)

Protected Member Functions

 Attributes ()
void CheckAttr (Attr *attr)
 DECLARE_SERIAL (Attributes)

Protected Attributes

BroTypetype
attr_list * attrs

Constructor & Destructor Documentation

Attributes::Attributes attr_list *  a,
BroType t
 

Definition at line 75 of file Attr.cc.

References AddAttr(), attrs, end_location, loop_over_list, BroType::Ref(), BroObj::SetLocationInfo(), start_location, and type.

00076         {
00077         attrs = new attr_list(a->length());
00078         type = t->Ref();
00079 
00080         SetLocationInfo(&start_location, &end_location);
00081 
00082         // We loop through 'a' and add each attribute individually,
00083         // rather than just taking over 'a' for ourselves, so that
00084         // the necessary checking gets done.
00085 
00086         loop_over_list(*a, i)
00087                 AddAttr((*a)[i]);
00088 
00089         delete a;
00090         }

Attributes::~Attributes  ) 
 

Definition at line 92 of file Attr.cc.

References attrs, loop_over_list, type, and BroObj::Unref.

00093         {
00094         loop_over_list(*attrs, i)
00095                 Unref((*attrs)[i]);
00096 
00097         delete attrs;
00098 
00099         Unref(type);
00100         }

Attributes::Attributes  )  [inline, protected]
 

Definition at line 94 of file Attr.h.

References attrs, and type.

00094 { type = 0; attrs = 0; }


Member Function Documentation

void Attributes::AddAttr Attr a  ) 
 

Definition at line 102 of file Attr.cc.

References ATTR_ADD_FUNC, ATTR_DEFAULT, ATTR_DEL_FUNC, ATTR_OPTIONAL, ATTR_REDEF, attrs, CheckAttr(), FindAttr(), Attr::RedundantAttrOkay(), BroObj::Ref, RemoveAttr(), and Attr::Tag().

Referenced by AddAttrs(), and Attributes().

00103         {
00104         if ( ! attrs )
00105                 attrs = new attr_list;
00106 
00107         if ( ! attr->RedundantAttrOkay() )
00108                 // We overwrite old attributes by deleting them first.
00109                 RemoveAttr(attr->Tag());
00110 
00111         attrs->append(attr);
00112         Ref(attr);
00113 
00114         // We only check the attribute after we've added it, to facilitate
00115         // generating error messages via Attributes::Describe.
00116         CheckAttr(attr);
00117 
00118         // For ADD_FUNC or DEL_FUNC, add in an implicit REDEF, since
00119         // those attributes only have meaning for a redefinable value.
00120         if ( (attr->Tag() == ATTR_ADD_FUNC || attr->Tag() == ATTR_DEL_FUNC) &&
00121              ! FindAttr(ATTR_REDEF) )
00122                 attrs->append(new Attr(ATTR_REDEF));
00123 
00124         // For DEFAULT, add an implicit OPTIONAL.
00125         if ( attr->Tag() == ATTR_DEFAULT && ! FindAttr(ATTR_OPTIONAL) )
00126                 attrs->append(new Attr(ATTR_OPTIONAL));
00127         }

void Attributes::AddAttrs Attributes a  ) 
 

Definition at line 129 of file Attr.cc.

References AddAttr(), Attrs(), loop_over_list, and BroObj::Unref.

Referenced by ID::AddAttrs().

00130         {
00131         attr_list* as = a->Attrs();
00132         loop_over_list(*as, i)
00133                 AddAttr((*as)[i]);
00134 
00135         Unref(a);
00136         }

attr_list* Attributes::Attrs  )  [inline]
 

Definition at line 88 of file Attr.h.

References attrs.

Referenced by AddAttrs().

00088 { return attrs; }

void Attributes::CheckAttr Attr attr  )  [protected]
 

Definition at line 179 of file Attr.cc.

References FuncType::Args(), BroType::AsFuncType(), BroType::AsTableType(), ATTR_ADD_FUNC, ATTR_DEFAULT, ATTR_DEL_FUNC, ATTR_ENCRYPT, ATTR_EXPIRE_CREATE, ATTR_EXPIRE_FUNC, ATTR_EXPIRE_READ, ATTR_EXPIRE_WRITE, ATTR_MATCH, ATTR_OPTIONAL, ATTR_PERSISTENT, ATTR_POSTPROCESSOR, ATTR_REDEF, ATTR_ROTATE_INTERVAL, ATTR_ROTATE_SIZE, ATTR_SYNCHRONIZED, Attr::AttrExpr(), BroObj::BadTag(), FuncType::CheckArgs(), BroObj::Error(), IndexType::IndexTypes(), BroType::IsSet(), RecordType::NumFields(), same_type(), BroType::Tag(), Attr::Tag(), type, Expr::Type(), TYPE_FILE, TYPE_FUNC, TYPE_INTERVAL, TYPE_TABLE, IndexType::YieldType(), and FuncType::YieldType().

Referenced by AddAttr().

00180         {
00181         switch ( a->Tag() ) {
00182         case ATTR_OPTIONAL:
00183         case ATTR_REDEF:
00184                 break;
00185 
00186         case ATTR_ADD_FUNC:
00187         case ATTR_DEL_FUNC:
00188                 {
00189                 int is_add = a->Tag() == ATTR_ADD_FUNC;
00190 
00191                 BroType* at = a->AttrExpr()->Type();
00192                 if ( at->Tag() != TYPE_FUNC )
00193                         {
00194                         a->AttrExpr()->Error(
00195                                 is_add ?
00196                                         "&add_func must be a function" :
00197                                         "&delete_func must be a function");
00198                         break;
00199                         }
00200 
00201                 FuncType* aft = at->AsFuncType();
00202                 if ( ! same_type(aft->YieldType(), type) )
00203                         {
00204                         a->AttrExpr()->Error(
00205                                 is_add ?
00206                                         "&add_func function must yield same type as variable" :
00207                                         "&delete_func function must yield same type as variable");
00208                         break;
00209                         }
00210                 }
00211                 break;
00212 
00213         case ATTR_DEFAULT:
00214                 {
00215                 BroType* atype = a->AttrExpr()->Type();
00216 
00217                 if ( type->Tag() != TYPE_TABLE || type->IsSet() )
00218                         {
00219                         if ( ! same_type(atype, type) )
00220                                 a->AttrExpr()->Error("&default value has inconsistent type", type);
00221                         break;
00222                         }
00223 
00224                 TableType* tt = type->AsTableType();
00225 
00226                 if ( ! same_type(atype, tt->YieldType()) )
00227                         {
00228                         // It can still be a default function.
00229                         if ( atype->Tag() == TYPE_FUNC )
00230                                 {
00231                                 FuncType* f = atype->AsFuncType();
00232                                 if ( ! f->CheckArgs(tt->IndexTypes()) ||
00233                                      ! same_type(f->YieldType(), tt->YieldType()) )
00234                                         Error("&default function type clash");
00235                                 }
00236                         else
00237                                 Error("&default value has inconsistent type");
00238                         }
00239                 }
00240                 break;
00241 
00242         case ATTR_ROTATE_INTERVAL:
00243                 if ( type->Tag() != TYPE_FILE )
00244                         Error("&rotate_interval only applicable to files");
00245                 break;
00246 
00247         case ATTR_ROTATE_SIZE:
00248                 if ( type->Tag() != TYPE_FILE )
00249                         Error("&rotate_size only applicable to files");
00250                 break;
00251 
00252         case ATTR_POSTPROCESSOR:
00253                 if ( type->Tag() != TYPE_FILE )
00254                         Error("&postprocessor only applicable to files");
00255                 break;
00256 
00257         case ATTR_ENCRYPT:
00258                 if ( type->Tag() != TYPE_FILE )
00259                         Error("&encrypt only applicable to files");
00260                 break;
00261 
00262         case ATTR_EXPIRE_READ:
00263         case ATTR_EXPIRE_WRITE:
00264         case ATTR_EXPIRE_CREATE:
00265                 if ( type->Tag() != TYPE_TABLE )
00266                         {
00267                         Error("expiration only applicable to tables");
00268                         break;
00269                         }
00270 
00271 #if 0
00272                 //### not easy to test this w/o knowing the ID.
00273                 if ( ! IsGlobal() )
00274                         Error("expiration not supported for local variables");
00275 #endif
00276                 break;
00277 
00278         case ATTR_EXPIRE_FUNC:
00279                 {
00280                 if ( type->Tag() != TYPE_TABLE )
00281                         {
00282                         Error("expiration only applicable to tables");
00283                         break;
00284                         }
00285 
00286                 const Expr* expire_func = a->AttrExpr();
00287                 const FuncType* e_ft = expire_func->Type()->AsFuncType();
00288 
00289                 if ( ((const BroType*) e_ft)->YieldType()->Tag() != TYPE_INTERVAL )
00290                         {
00291                         Error("&expire_func must yield a value of type interval");
00292                         break;
00293                         }
00294 
00295                 if ( e_ft->Args()->NumFields() != 2 )
00296                         {
00297                         Error("&expire_func function must take exactly two arguments");
00298                         break;
00299                         }
00300                 }
00301                 break;
00302 
00303         case ATTR_PERSISTENT:
00304         case ATTR_SYNCHRONIZED:
00305                 // FIXME: Check here for global ID?
00306                 break;
00307 
00308         case ATTR_MATCH:
00309                 // FIXME: Should only be on record types, but I don't
00310                 // know how to enforce this --US
00311                 break;
00312 
00313         default:
00314                 BadTag("Attributes::CheckAttr");
00315         }
00316         }

Attributes::DECLARE_SERIAL Attributes   )  [protected]
 

void Attributes::Describe ODesc d  )  const [virtual]
 

Implements BroObj.

Definition at line 160 of file Attr.cc.

References ODesc::Add(), ODesc::AddCount(), attrs, ODesc::IsPortable(), ODesc::IsReadable(), and loop_over_list.

00161         {
00162         if ( ! attrs )
00163                 {
00164                 d->AddCount(0);
00165                 return;
00166                 }
00167 
00168         d->AddCount(attrs->length());
00169 
00170         loop_over_list(*attrs, i)
00171                 {
00172                 if ( (d->IsReadable() || d->IsPortable()) && i > 0 )
00173                         d->Add(", ");
00174 
00175                 (*attrs)[i]->Describe(d);
00176                 }
00177         }

Attr * Attributes::FindAttr attr_tag  t  )  const
 

Definition at line 138 of file Attr.cc.

References attrs, loop_over_list, and Attr::Tag().

Referenced by AddAttr(), ID::AddAttrs(), TableVal::Assign(), TableVal::CheckExpireAttr(), TableVal::FindAttr(), TypeDecl::FindAttr(), ID::FindAttr(), TableVal::Lookup(), RecordVal::RecordVal(), TableVal::SetAttrs(), BroFile::SetAttrs(), BroFile::SetDefaultRotation(), ID::SetVal(), and TypeDecl::TypeDecl().

00139         {
00140         if ( ! attrs )
00141                 return 0;
00142 
00143         loop_over_list(*attrs, i)
00144                 {
00145                 Attr* a = (*attrs)[i];
00146                 if ( a->Tag() == t )
00147                         return a;
00148                 }
00149 
00150         return 0;
00151         }

void Attributes::RemoveAttr attr_tag  t  ) 
 

Definition at line 153 of file Attr.cc.

References attrs.

Referenced by AddAttr().

00154         {
00155         for ( int i = 0; i < attrs->length(); i++ )
00156                 if ( (*attrs)[i]->Tag() == t )
00157                         attrs->remove_nth(i--);
00158         }

bool Attributes::Serialize SerialInfo info  )  const
 

Reimplemented from SerialObj.

Definition at line 318 of file Attr.cc.

References SerialObj::Serialize().

00319         {
00320         return SerialObj::Serialize(info);
00321         }

Attributes * Attributes::Unserialize UnserialInfo info  )  [static]
 

Definition at line 323 of file Attr.cc.

References SerialObj::Unserialize().

00324         {
00325         return (Attributes*) SerialObj::Unserialize(info, SER_ATTRIBUTES);
00326         }


Member Data Documentation

attr_list* Attributes::attrs [protected]
 

Definition at line 100 of file Attr.h.

Referenced by AddAttr(), Attributes(), Attrs(), Describe(), FindAttr(), RemoveAttr(), and ~Attributes().

BroType* Attributes::type [protected]
 

Definition at line 99 of file Attr.h.

Referenced by Attributes(), CheckAttr(), and ~Attributes().


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