00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef id_h
00023 #define id_h
00024
00025 #include "Type.h"
00026 #include "Attr.h"
00027 #include "StateAccess.h"
00028 #include "TraverseTypes.h"
00029 #include <string>
00030
00031 class Val;
00032 class SerialInfo;
00033
00034 typedef enum { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, } init_class;
00035 typedef enum { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL } IDScope;
00036
00037 class ID : public BroObj {
00038 public:
00039 ID(const char* name, IDScope arg_scope, bool arg_is_export);
00040 ~ID();
00041
00042 const char* Name() const { return name; }
00043
00044 int Scope() const { return scope; }
00045 bool IsGlobal() const { return scope != SCOPE_FUNCTION; }
00046
00047 bool IsExport() const { return is_export; }
00048
00049 string ModuleName() const;
00050
00051 void SetType(BroType* t) { Unref(type); type = t; }
00052 BroType* Type() { return type; }
00053
00054 void MakeType() { is_type = 1; }
00055 BroType* AsType() { return is_type ? Type() : 0; }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 void SetVal(Val* v, Opcode op = OP_ASSIGN, bool weak_ref = false);
00066
00067 void SetVal(Val* v, init_class c);
00068 void SetVal(Expr* ev, init_class c);
00069
00070 int HasVal() const { return val != 0; }
00071 Val* ID_Val() { return val; }
00072 const Val* ID_Val() const { return val; }
00073 void ClearVal();
00074
00075 void SetConst() { is_const = 1; }
00076 int IsConst() const { return is_const; }
00077
00078 void SetEnumConst() { is_enum_const = 1; }
00079 int IsEnumConst() const { return is_enum_const; }
00080
00081 void SetOffset(int arg_offset) { offset = arg_offset; }
00082 int Offset() const { return offset; }
00083
00084 int IsRedefinable() const { return FindAttr(ATTR_REDEF) != 0; }
00085
00086
00087
00088 bool IsInternalGlobal() const { return name && name[0] == '#'; }
00089
00090 void SetAttrs(Attributes* attr);
00091 void AddAttrs(Attributes* attr);
00092 Attributes* Attrs() const { return attrs; }
00093
00094 Attr* FindAttr(attr_tag t) const
00095 { return attrs ? attrs->FindAttr(t) : 0; }
00096
00097 void Error(const char* msg, const BroObj* o2 = 0);
00098
00099 void Describe(ODesc* d) const;
00100
00101 void DescribeExtended(ODesc* d) const;
00102
00103 bool Serialize(SerialInfo* info) const;
00104 static ID* Unserialize(UnserialInfo* info);
00105
00106 bool DoInferReturnType() { return infer_return_type; }
00107 void SetInferReturnType(bool infer)
00108 { infer_return_type = infer; }
00109
00110 virtual TraversalCode Traverse(TraversalCallback* cb) const;
00111
00112 protected:
00113 ID() { name = 0; type = 0; val = 0; attrs = 0; }
00114
00115 void CheckAttr(Attr* attr);
00116 void EvalFunc(Expr* ef, Expr* ev);
00117
00118 #ifdef DEBUG
00119 void UpdateValID();
00120 #endif
00121
00122 DECLARE_SERIAL(ID);
00123
00124 const char* name;
00125 IDScope scope;
00126 bool is_export;
00127 BroType* type;
00128 int is_const, is_enum_const, is_type;
00129 int offset;
00130 Val* val;
00131 Attributes* attrs;
00132
00133 bool infer_return_type;
00134 bool weak_ref;
00135 };
00136
00137 #endif