Revising format of initialization values in generated script docs.

Fixed the obvious things: reduced the space taken up by empty tables
and allowed record values to span multiple lines (one for each record field).
This commit is contained in:
Jon Siwek 2011-04-01 15:21:15 -05:00
parent 2d17ca0942
commit 758172120b
3 changed files with 59 additions and 19 deletions

View file

@ -681,20 +681,30 @@ void ID::DescribeReST(ODesc* d, bool is_role) const
type->Tag() != TYPE_FUNC && type->Tag() != TYPE_FUNC &&
type->InternalType() != TYPE_INTERNAL_VOID ) type->InternalType() != TYPE_INTERNAL_VOID )
{ {
d->Add(":Default:");
if ( type->InternalType() == TYPE_INTERNAL_OTHER ) if ( type->InternalType() == TYPE_INTERNAL_OTHER )
{ {
d->Add(":Init:"); switch ( type->Tag() ) {
d->NL(); case TYPE_TABLE:
d->NL(); if ( val->AsTable()->Length() == 0 )
d->Add("::"); {
d->NL(); d->Add(" ``{}``");
d->PushIndent(); d->NL();
val->DescribeReST(d); break;
d->PopIndent(); }
default:
d->NL();
d->NL();
d->Add("::");
d->NL();
d->PushIndent();
val->DescribeReST(d);
d->PopIndent();
}
} }
else else
{ {
d->Add(":Init: "); d->SP();
val->DescribeReST(d); val->DescribeReST(d);
d->NL(); d->NL();
} }

View file

@ -576,14 +576,7 @@ void Val::Describe(ODesc* d) const
void Val::DescribeReST(ODesc* d) const void Val::DescribeReST(ODesc* d) const
{ {
if ( type->InternalType() == TYPE_INTERNAL_OTHER ) ValDescribeReST(d);
Describe(d);
else
{
d->Add("``");
ValDescribeReST(d);
d->Add("``");
}
} }
void Val::ValDescribe(ODesc* d) const void Val::ValDescribe(ODesc* d) const
@ -629,7 +622,15 @@ void Val::ValDescribe(ODesc* d) const
void Val::ValDescribeReST(ODesc* d) const void Val::ValDescribeReST(ODesc* d) const
{ {
ValDescribe(d); switch ( type->InternalType() ) {
case TYPE_INTERNAL_OTHER:
Describe(d);
break;
default:
d->Add("``");
ValDescribe(d);
d->Add("``");
}
} }
MutableVal::~MutableVal() MutableVal::~MutableVal()
@ -2946,6 +2947,34 @@ void RecordVal::Describe(ODesc* d) const
d->Add("]"); d->Add("]");
} }
void RecordVal::DescribeReST(ODesc* d) const
{
const val_list* vl = AsRecord();
int n = vl->length();
d->Add("{");
d->PushIndent();
loop_over_list(*vl, i)
{
if ( i > 0 )
d->NL();
d->Add(record_type->FieldName(i));
d->Add("=");
Val* v = (*vl)[i];
if ( v )
v->Describe(d);
else
d->Add("<uninitialized>");
}
d->PopIndent();
d->Add("}");
}
IMPLEMENT_SERIAL(RecordVal, SER_RECORD_VAL); IMPLEMENT_SERIAL(RecordVal, SER_RECORD_VAL);
bool RecordVal::DoSerialize(SerialInfo* info) const bool RecordVal::DoSerialize(SerialInfo* info) const

View file

@ -313,7 +313,7 @@ public:
} }
void Describe(ODesc* d) const; void Describe(ODesc* d) const;
void DescribeReST(ODesc* d) const; virtual void DescribeReST(ODesc* d) const;
bool Serialize(SerialInfo* info) const; bool Serialize(SerialInfo* info) const;
static Val* Unserialize(UnserialInfo* info, TypeTag type = TYPE_ANY) static Val* Unserialize(UnserialInfo* info, TypeTag type = TYPE_ANY)
@ -904,6 +904,7 @@ public:
BroObj* GetOrigin() const { return origin; } BroObj* GetOrigin() const { return origin; }
unsigned int MemoryAllocation() const; unsigned int MemoryAllocation() const;
void DescribeReST(ODesc* d) const;
protected: protected:
friend class Val; friend class Val;