Fixes for declared type ID tracking & adding DescribeReST()'s

Changed BroType to track a char* instead of an ID* that represents
the declared type's identifier.  It was also necessary to serialize
this information or else it can be lost (e.g. FieldDecl's in RecordType
always seem to get serialized at some point).

DescribeReST() functions added to many classes to get the output
closer to being reST compatible; still needs tweaking for Sphinx
(reST->HTML) compatibility.
This commit is contained in:
Jon Siwek 2011-03-10 16:22:45 -06:00
parent 287a3a3cb8
commit 15fd5297a3
10 changed files with 214 additions and 6 deletions

View file

@ -108,6 +108,11 @@ BroType::BroType(TypeTag t, bool arg_base_type)
}
BroType::~BroType()
{
if ( type_id ) delete [] type_id;
}
int BroType::MatchesIndex(ListExpr*& /* index */) const
{
return DOES_NOT_MATCH_INDEX;
@ -142,6 +147,11 @@ void BroType::Describe(ODesc* d) const
}
}
void BroType::DescribeReST(ODesc* d) const
{
Describe(d);
}
void BroType::SetError()
{
tag = TYPE_ERROR;
@ -234,6 +244,11 @@ bool BroType::DoSerialize(SerialInfo* info) const
void* null = NULL;
SERIALIZE(null);
if ( generate_documentation )
{
SERIALIZE_OPTIONAL_STR(type_id);
}
info->s->WriteCloseTag("Type");
return true;
@ -264,6 +279,11 @@ bool BroType::DoUnserialize(UnserialInfo* info)
// attributes_type" for backwards compatibility.
UNSERIALIZE_OPTIONAL(not_used_either, BroType::Unserialize(info, TYPE_RECORD));
if ( generate_documentation )
{
UNSERIALIZE_OPTIONAL_STR(type_id);
}
return true;
}
@ -417,6 +437,44 @@ void IndexType::Describe(ODesc* d) const
}
}
void IndexType::DescribeReST(ODesc* d) const
{
if ( IsSet() )
d->Add("set");
else
d->Add(type_name(Tag()));
d->Add("[");
loop_over_list(*IndexTypes(), i)
{
if ( i > 0 )
d->Add(",");
const BroType* t = (*IndexTypes())[i];
if ( t->GetTypeID() )
{
d->Add("`");
d->Add(t->GetTypeID());
d->Add("`");
}
else
t->DescribeReST(d);
}
d->Add("]");
if ( yield_type )
{
d->Add(" of ");
if ( yield_type->GetTypeID() )
{
d->Add("`");
d->Add(yield_type->GetTypeID());
d->Add("`");
}
else
yield_type->DescribeReST(d);
}
}
bool IndexType::IsSubNetIndex() const
{
const type_list* types = indices->Types();
@ -651,6 +709,26 @@ void FuncType::Describe(ODesc* d) const
}
}
void FuncType::DescribeReST(ODesc* d) const
{
d->Add(is_event ? "event" : "function");
d->Add("(");
args->DescribeFieldsReST(d, true);
d->Add(")");
if ( yield )
{
d->AddSP(" :");
if ( yield->GetTypeID() )
{
d->Add("`");
d->Add(yield->GetTypeID());
d->Add("`");
}
else
yield->DescribeReST(d);
}
}
IMPLEMENT_SERIAL(FuncType, SER_FUNC_TYPE);
bool FuncType::DoSerialize(SerialInfo* info) const
@ -902,6 +980,12 @@ void RecordType::Describe(ODesc* d) const
}
}
void RecordType::DescribeReST(ODesc* d) const
{
d->Add("record");
DescribeFieldsReST(d, false);
}
void RecordType::DescribeFields(ODesc* d) const
{
if ( d->IsReadable() )
@ -941,6 +1025,37 @@ void RecordType::DescribeFields(ODesc* d) const
}
}
void RecordType::DescribeFieldsReST(ODesc* d, bool func_args) const
{
if ( ! func_args )
d->PushIndent();
for ( int i = 0; i < num_fields; ++i )
{
const TypeDecl* td = FieldDecl(i);
if ( ! func_args )
d->Add(":bro:field: ");
d->Add(td->id);
d->Add(": ");
d->Add(":bro:type: ");
if ( td->type->GetTypeID() )
{
d->Add("`");
d->Add(td->type->GetTypeID());
d->Add("`");
}
else
td->type->DescribeReST(d);
if ( i + 1 != num_fields )
if ( func_args )
d->Add(", ");
else
d->NL();
}
}
IMPLEMENT_SERIAL(RecordType, SER_RECORD_TYPE)
bool RecordType::DoSerialize(SerialInfo* info) const
@ -1176,6 +1291,19 @@ const char* EnumType::Lookup(bro_int_t value)
return 0;
}
void EnumType::DescribeReST(ODesc* d) const
{
d->Add(type_name(Tag()));
d->PushIndent();
for ( NameMap::const_iterator it = names.begin(); it != names.end(); )
{
d->Add(".. bro:enum:: ");
d->Add(it->first);
if ( ++it != names.end() )
d->NL();
}
}
IMPLEMENT_SERIAL(EnumType, SER_ENUM_TYPE);
bool EnumType::DoSerialize(SerialInfo* info) const