LCOV - code coverage report
Current view: top level - src - ID.h (source / functions) Hit Total Coverage
Test: app.info Lines: 25 26 96.2 %
Date: 2010-12-13 Functions: 23 24 95.8 %
Branches: 6 8 75.0 %

           Branch data     Line data    Source code
       1                 :            : // $Id: ID.h 6219 2008-10-01 05:39:07Z vern $
       2                 :            : //
       3                 :            : // See the file "COPYING" in the main distribution directory for copyright.
       4                 :            : 
       5                 :            : #ifndef id_h
       6                 :            : #define id_h
       7                 :            : 
       8                 :            : #include "Type.h"
       9                 :            : #include "Attr.h"
      10                 :            : #include "StateAccess.h"
      11                 :            : #include "TraverseTypes.h"
      12                 :            : #include <string>
      13                 :            : 
      14                 :            : class Val;
      15                 :            : class SerialInfo;
      16                 :            : 
      17                 :            : typedef enum { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, } init_class;
      18                 :            : typedef enum { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL } IDScope;
      19                 :            : 
      20                 :            : class ID : public BroObj {
      21                 :            : public:
      22                 :            :         ID(const char* name, IDScope arg_scope, bool arg_is_export);
      23                 :            :         ~ID();
      24                 :            : 
      25                 :      30873 :         const char* Name() const        { return name; }
      26                 :            : 
      27                 :            :         int Scope() const               { return scope; }
      28                 :    1303682 :         bool IsGlobal() const           { return scope != SCOPE_FUNCTION; }
      29                 :            : 
      30                 :        248 :         bool IsExport() const           { return is_export; }
      31                 :            : 
      32                 :            :         string ModuleName() const;
      33                 :            : 
      34                 :       9718 :         void SetType(BroType* t)        { Unref(type); type = t; }
      35                 :     257277 :         BroType* Type()                 { return type; }
      36                 :            : 
      37                 :        389 :         void MakeType()                 { is_type = 1; }
      38         [ +  + ]:    1108035 :         BroType* AsType()               { return is_type ? Type() : 0; }
      39                 :            : 
      40                 :            :         // If weak_ref is false, the Val is assumed to be already ref'ed
      41                 :            :         // and will be deref'ed when the ID is deleted.
      42                 :            :         //
      43                 :            :         // If weak_ref is true, we store the Val but don't ref/deref it.
      44                 :            :         // That means that when the ID becomes the only one holding a
      45                 :            :         // reference to the Val, the Val will be destroyed (naturally,
      46                 :            :         // you have to take care that it will not be accessed via
      47                 :            :         // the ID afterwards).
      48                 :            :         void SetVal(Val* v, Opcode op = OP_ASSIGN, bool weak_ref = false);
      49                 :            : 
      50                 :            :         void SetVal(Val* v, init_class c);
      51                 :            :         void SetVal(Expr* ev, init_class c);
      52                 :            : 
      53                 :       2988 :         int HasVal() const              { return val != 0; }
      54                 :     335643 :         Val* ID_Val()                   { return val; }
      55                 :         16 :         const Val* ID_Val() const       { return val; }
      56                 :            :         void ClearVal();
      57                 :            : 
      58                 :       2284 :         void SetConst()                 { is_const = 1; }
      59                 :       1058 :         int IsConst() const             { return is_const; }
      60                 :            : 
      61                 :        446 :         void SetEnumConst()             { is_enum_const = 1; }
      62                 :      18832 :         int IsEnumConst() const         { return is_enum_const; }
      63                 :            : 
      64                 :       3691 :         void SetOffset(int arg_offset)  { offset = arg_offset; }
      65                 :    1011743 :         int Offset() const              { return offset; }
      66                 :            : 
      67                 :        283 :         int IsRedefinable() const       { return FindAttr(ATTR_REDEF) != 0; }
      68                 :            : 
      69                 :            :         // Returns true if ID is one of those internal globally unique IDs
      70                 :            :         // to which MutableVals are bound (there name start with a '#').
      71 [ +  - ][ -  + ]:       2730 :         bool IsInternalGlobal() const   { return name && name[0] == '#'; }
      72                 :            : 
      73                 :            :         void SetAttrs(Attributes* attr);
      74                 :            :         void AddAttrs(Attributes* attr);
      75                 :            :         void RemoveAttr(attr_tag a);
      76                 :            :         void UpdateValAttrs();
      77                 :       2856 :         Attributes* Attrs() const       { return attrs; }
      78                 :            : 
      79                 :      10937 :         Attr* FindAttr(attr_tag t) const
      80         [ +  + ]:      10937 :                 { return attrs ? attrs->FindAttr(t) : 0; }
      81                 :            : 
      82                 :            :         void Error(const char* msg, const BroObj* o2 = 0);
      83                 :            : 
      84                 :            :         void Describe(ODesc* d) const;
      85                 :            :         // Adds type and value to description.
      86                 :            :         void DescribeExtended(ODesc* d) const;
      87                 :            : 
      88                 :            :         bool Serialize(SerialInfo* info) const;
      89                 :            :         static ID* Unserialize(UnserialInfo* info);
      90                 :            : 
      91                 :        816 :         bool DoInferReturnType()        { return infer_return_type; }
      92                 :         10 :         void SetInferReturnType(bool infer)
      93                 :         10 :                 { infer_return_type = infer; }
      94                 :            : 
      95                 :            :         virtual TraversalCode Traverse(TraversalCallback* cb) const;
      96                 :            : 
      97                 :            : protected:
      98                 :          0 :         ID()    { name = 0; type = 0; val = 0; attrs = 0; }
      99                 :            : 
     100                 :            :         void CheckAttr(Attr* attr);
     101                 :            :         void EvalFunc(Expr* ef, Expr* ev);
     102                 :            : 
     103                 :            : #ifdef DEBUG
     104                 :            :         void UpdateValID();
     105                 :            : #endif
     106                 :            : 
     107                 :          2 :         DECLARE_SERIAL(ID);
     108                 :            : 
     109                 :            :         const char* name;
     110                 :            :         IDScope scope;
     111                 :            :         bool is_export;
     112                 :            :         BroType* type;
     113                 :            :         int is_const, is_enum_const, is_type;
     114                 :            :         int offset;
     115                 :            :         Val* val;
     116                 :            :         Attributes* attrs;
     117                 :            : 
     118                 :            :         bool infer_return_type;
     119                 :            :         bool weak_ref;
     120                 :            : };
     121                 :            : 
     122                 :            : #endif

Generated by: LCOV version 1.8