mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Minor interface changes to provide more accessor methods for class
information. In particular, adding a few const versions of methods.
This commit is contained in:
parent
b6c1b35bb8
commit
f0fe270029
4 changed files with 39 additions and 6 deletions
|
@ -24,6 +24,8 @@ public:
|
|||
SourceID Source() const { return src; }
|
||||
analyzer::ID Analyzer() const { return aid; }
|
||||
TimerMgr* Mgr() const { return mgr; }
|
||||
EventHandlerPtr Handler() const { return handler; }
|
||||
val_list* Args() const { return args; }
|
||||
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
|
|
2
src/ID.h
2
src/ID.h
|
@ -32,9 +32,11 @@ public:
|
|||
|
||||
void SetType(BroType* t) { Unref(type); type = t; }
|
||||
BroType* Type() { return type; }
|
||||
const BroType* Type() const { return type; }
|
||||
|
||||
void MakeType() { is_type = 1; }
|
||||
BroType* AsType() { return is_type ? Type() : 0; }
|
||||
const BroType* AsType() const { return is_type ? Type() : 0; }
|
||||
|
||||
// If weak_ref is false, the Val is assumed to be already ref'ed
|
||||
// and will be deref'ed when the ID is deleted.
|
||||
|
|
28
src/Type.cc
28
src/Type.cc
|
@ -430,6 +430,11 @@ BroType* IndexType::YieldType()
|
|||
return yield_type;
|
||||
}
|
||||
|
||||
const BroType* IndexType::YieldType() const
|
||||
{
|
||||
return yield_type;
|
||||
}
|
||||
|
||||
void IndexType::Describe(ODesc* d) const
|
||||
{
|
||||
BroType::Describe(d);
|
||||
|
@ -723,6 +728,11 @@ BroType* FuncType::YieldType()
|
|||
return yield;
|
||||
}
|
||||
|
||||
const BroType* FuncType::YieldType() const
|
||||
{
|
||||
return yield;
|
||||
}
|
||||
|
||||
int FuncType::MatchesIndex(ListExpr*& index) const
|
||||
{
|
||||
return check_and_promote_args(index, args) ?
|
||||
|
@ -1444,9 +1454,9 @@ void CommentedEnumType::AddNameInternal(const string& module_name, const char* n
|
|||
names[copy_string(fullname.c_str())] = val;
|
||||
}
|
||||
|
||||
bro_int_t EnumType::Lookup(const string& module_name, const char* name)
|
||||
bro_int_t EnumType::Lookup(const string& module_name, const char* name) const
|
||||
{
|
||||
NameMap::iterator pos =
|
||||
NameMap::const_iterator pos =
|
||||
names.find(make_full_var_name(module_name.c_str(), name).c_str());
|
||||
|
||||
if ( pos == names.end() )
|
||||
|
@ -1455,9 +1465,9 @@ bro_int_t EnumType::Lookup(const string& module_name, const char* name)
|
|||
return pos->second;
|
||||
}
|
||||
|
||||
const char* EnumType::Lookup(bro_int_t value)
|
||||
const char* EnumType::Lookup(bro_int_t value) const
|
||||
{
|
||||
for ( NameMap::iterator iter = names.begin();
|
||||
for ( NameMap::const_iterator iter = names.begin();
|
||||
iter != names.end(); ++iter )
|
||||
if ( iter->second == value )
|
||||
return iter->first;
|
||||
|
@ -1465,6 +1475,16 @@ const char* EnumType::Lookup(bro_int_t value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
EnumType::enum_name_list EnumType::Names() const
|
||||
{
|
||||
enum_name_list n;
|
||||
for ( NameMap::const_iterator iter = names.begin();
|
||||
iter != names.end(); ++iter )
|
||||
n.push_back(std::make_pair(iter->first, iter->second));
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void EnumType::DescribeReST(ODesc* d) const
|
||||
{
|
||||
d->Add(":bro:type:`");
|
||||
|
|
13
src/Type.h
13
src/Type.h
|
@ -304,6 +304,7 @@ public:
|
|||
TypeList* Indices() const { return indices; }
|
||||
const type_list* IndexTypes() const { return indices->Types(); }
|
||||
BroType* YieldType();
|
||||
const BroType* YieldType() const;
|
||||
|
||||
void Describe(ODesc* d) const;
|
||||
void DescribeReST(ODesc* d) const;
|
||||
|
@ -366,6 +367,7 @@ public:
|
|||
|
||||
RecordType* Args() const { return args; }
|
||||
BroType* YieldType();
|
||||
const BroType* YieldType() const;
|
||||
void SetYieldType(BroType* arg_yield) { yield = arg_yield; }
|
||||
function_flavor Flavor() const { return flavor; }
|
||||
string FlavorString() const;
|
||||
|
@ -522,6 +524,8 @@ protected:
|
|||
|
||||
class EnumType : public BroType {
|
||||
public:
|
||||
typedef std::list<std::pair<string, bro_int_t> > enum_name_list;
|
||||
|
||||
EnumType(const string& arg_name);
|
||||
EnumType(EnumType* e);
|
||||
~EnumType();
|
||||
|
@ -536,11 +540,15 @@ public:
|
|||
void AddName(const string& module_name, const char* name, bro_int_t val, bool is_export);
|
||||
|
||||
// -1 indicates not found.
|
||||
bro_int_t Lookup(const string& module_name, const char* name);
|
||||
const char* Lookup(bro_int_t value); // Returns 0 if not found
|
||||
bro_int_t Lookup(const string& module_name, const char* name) const;
|
||||
const char* Lookup(bro_int_t value) const; // Returns 0 if not found
|
||||
|
||||
string Name() const { return name; }
|
||||
|
||||
// Returns the list of defined names with their values. The names
|
||||
// will be fully qualified with their module name.
|
||||
enum_name_list Names() const;
|
||||
|
||||
void DescribeReST(ODesc* d) const;
|
||||
|
||||
protected:
|
||||
|
@ -592,6 +600,7 @@ public:
|
|||
VectorType(BroType* t);
|
||||
virtual ~VectorType();
|
||||
BroType* YieldType() { return yield_type; }
|
||||
const BroType* YieldType() const { return yield_type; }
|
||||
|
||||
int MatchesIndex(ListExpr*& index) const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue