mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 01:28:20 +00:00
Changes to make declared types track their identifier.
Only occurs when in documentation mode.
This commit is contained in:
parent
1bad6e3a95
commit
1c962cbb89
3 changed files with 51 additions and 5 deletions
|
@ -10,6 +10,8 @@
|
||||||
#include "Scope.h"
|
#include "Scope.h"
|
||||||
#include "Serializer.h"
|
#include "Serializer.h"
|
||||||
|
|
||||||
|
extern int generate_documentation;
|
||||||
|
|
||||||
const char* type_name(TypeTag t)
|
const char* type_name(TypeTag t)
|
||||||
{
|
{
|
||||||
static char errbuf[512];
|
static char errbuf[512];
|
||||||
|
@ -44,6 +46,7 @@ BroType::BroType(TypeTag t, bool arg_base_type)
|
||||||
tag = t;
|
tag = t;
|
||||||
is_network_order = 0;
|
is_network_order = 0;
|
||||||
base_type = arg_base_type;
|
base_type = arg_base_type;
|
||||||
|
type_id = 0;
|
||||||
|
|
||||||
switch ( tag ) {
|
switch ( tag ) {
|
||||||
case TYPE_VOID:
|
case TYPE_VOID:
|
||||||
|
@ -195,8 +198,9 @@ BroType* BroType::Unserialize(UnserialInfo* info, TypeTag want)
|
||||||
if ( ! t )
|
if ( ! t )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// For base types, we return our current instance.
|
// For base types, we return our current instance
|
||||||
if ( t->base_type )
|
// if not in "documentation mode".
|
||||||
|
if ( t->base_type && ! generate_documentation )
|
||||||
{
|
{
|
||||||
BroType* t2 = ::base_type(TypeTag(t->tag));
|
BroType* t2 = ::base_type(TypeTag(t->tag));
|
||||||
Unref(t);
|
Unref(t);
|
||||||
|
|
|
@ -206,8 +206,11 @@ public:
|
||||||
bool Serialize(SerialInfo* info) const;
|
bool Serialize(SerialInfo* info) const;
|
||||||
static BroType* Unserialize(UnserialInfo* info, TypeTag want = TYPE_ANY);
|
static BroType* Unserialize(UnserialInfo* info, TypeTag want = TYPE_ANY);
|
||||||
|
|
||||||
|
void SetTypeID(const ID* id) { type_id = id; }
|
||||||
|
const ID* GetTypeID() const { return type_id; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BroType() { }
|
BroType() { type_id = 0; }
|
||||||
|
|
||||||
void SetError();
|
void SetError();
|
||||||
|
|
||||||
|
@ -218,6 +221,10 @@ private:
|
||||||
InternalTypeTag internal_tag;
|
InternalTypeTag internal_tag;
|
||||||
bool is_network_order;
|
bool is_network_order;
|
||||||
bool base_type;
|
bool base_type;
|
||||||
|
|
||||||
|
// This type_id field is only used by the documentation framework to
|
||||||
|
// track the names of declared types.
|
||||||
|
const ID* type_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeList : public BroType {
|
class TypeList : public BroType {
|
||||||
|
|
39
src/Var.cc
39
src/Var.cc
|
@ -12,6 +12,8 @@
|
||||||
#include "RemoteSerializer.h"
|
#include "RemoteSerializer.h"
|
||||||
#include "EventRegistry.h"
|
#include "EventRegistry.h"
|
||||||
|
|
||||||
|
extern int generate_documentation;
|
||||||
|
|
||||||
static Val* init_val(Expr* init, const BroType* t, Val* aggr)
|
static Val* init_val(Expr* init, const BroType* t, Val* aggr)
|
||||||
{
|
{
|
||||||
return init->InitVal(t, aggr);
|
return init->InitVal(t, aggr);
|
||||||
|
@ -217,11 +219,44 @@ extern Expr* add_and_assign_local(ID* id, Expr* init, Val* val)
|
||||||
|
|
||||||
void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */)
|
void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */)
|
||||||
{
|
{
|
||||||
id->SetType(t);
|
BroType* tnew = t;
|
||||||
|
|
||||||
|
// In "documentation mode", we'd like to to be able to associate
|
||||||
|
// an identifier name with a declared type. Dealing with declared
|
||||||
|
// types that are "aliases" to a builtin type requires that the BroType
|
||||||
|
// is cloned before setting the identifier name that resolves to it.
|
||||||
|
// And still this is not enough to document cases where the declared type
|
||||||
|
// is an alias for another declared type -- but that's not a natural/common
|
||||||
|
// practice. If documenting that corner case is desired, one way
|
||||||
|
// is to add an ID* to class ID that tracks aliases and set it here if
|
||||||
|
// t->GetTypeID() is true.
|
||||||
|
if ( generate_documentation )
|
||||||
|
{
|
||||||
|
SerializationFormat* form = new BinarySerializationFormat();
|
||||||
|
form->StartWrite();
|
||||||
|
CloneSerializer ss(form);
|
||||||
|
SerialInfo sinfo(&ss);
|
||||||
|
sinfo.cache = false;
|
||||||
|
|
||||||
|
t->Serialize(&sinfo);
|
||||||
|
char* data;
|
||||||
|
uint32 len = form->EndWrite(&data);
|
||||||
|
form->StartRead(data, len);
|
||||||
|
|
||||||
|
UnserialInfo uinfo(&ss);
|
||||||
|
uinfo.cache = false;
|
||||||
|
tnew = t->Unserialize(&uinfo);
|
||||||
|
|
||||||
|
delete [] data;
|
||||||
|
|
||||||
|
tnew->SetTypeID(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
id->SetType(tnew);
|
||||||
id->MakeType();
|
id->MakeType();
|
||||||
|
|
||||||
if ( attr )
|
if ( attr )
|
||||||
id->SetAttrs(new Attributes(attr, t));
|
id->SetAttrs(new Attributes(attr, tnew));
|
||||||
}
|
}
|
||||||
|
|
||||||
void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue