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
39
src/Var.cc
39
src/Var.cc
|
@ -12,6 +12,8 @@
|
|||
#include "RemoteSerializer.h"
|
||||
#include "EventRegistry.h"
|
||||
|
||||
extern int generate_documentation;
|
||||
|
||||
static Val* init_val(Expr* init, const BroType* t, Val* 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 */)
|
||||
{
|
||||
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();
|
||||
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue