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

ID.h

Go to the documentation of this file.
00001 // $Id: ID.h,v 1.6 2004/12/06 00:16:05 vern Exp $
00002 //
00003 // Copyright (c) 1995, 1996, 1997, 1998, 1999, 2002
00004 //      The Regents of the University of California.  All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that: (1) source code distributions
00008 // retain the above copyright notice and this paragraph in its entirety, (2)
00009 // distributions including binary code include the above copyright notice and
00010 // this paragraph in its entirety in the documentation or other materials
00011 // provided with the distribution, and (3) all advertising materials mentioning
00012 // features or use of this software display the following acknowledgement:
00013 // ``This product includes software developed by the University of California,
00014 // Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
00015 // the University nor the names of its contributors may be used to endorse
00016 // or promote products derived from this software without specific prior
00017 // written permission.
00018 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
00019 // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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         // If weak_ref is false, the Val is assumed to be already ref'ed
00058         // and will be deref'ed when the ID is deleted.
00059         //
00060         // If weak_ref is true, we store the Val but don't ref/deref it.
00061         // That means that when the ID becomes the only one holding a
00062         // reference to the Val, the Val will be destroyed (naturally,
00063         // you have to take care that it will not be accessed via
00064         // the ID afterwards).
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         // Returns true if ID is one of those internal globally unique IDs
00087         // to which MutableVals are bound (there name start with a '#').
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         // Adds type and value to description.
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

Generated on Wed Sep 14 02:56:13 2005 for bro_docs by doxygen 1.3.5