Revise enum documentation autogeneration.

This adds a new subclass of EnumType, CommentedEnumType, and removes
any previous changes to EnumType that were done to support the
autodoc framework.

Dummy CommentedEnumType and ID's are constructed in parallel with the
real EnumType ID's during parsing and passed on to the autodoc framework.

This allows the generated documentation to track enum redefs, with
a special case being the "Notice" enum type.
This commit is contained in:
Jon Siwek 2011-03-15 14:51:50 -05:00
parent b1dc5d3a1c
commit f67c0892e5
7 changed files with 107 additions and 56 deletions

View file

@ -1235,7 +1235,10 @@ EnumType::~EnumType()
{
for ( NameMap::iterator iter = names.begin(); iter != names.end(); ++iter )
delete [] iter->first;
}
CommentedEnumType::~CommentedEnumType()
{
for ( CommentMap::iterator iter = comments.begin(); iter != comments.end(); ++iter )
{
delete [] iter->first;
@ -1272,7 +1275,7 @@ void EnumType::AddName(const string& module_name, const char* name, bro_int_t va
AddNameInternal(module_name, name, val, is_export);
}
void EnumType::AddComment(const string& module_name, const char* name, const char* comment)
void CommentedEnumType::AddComment(const string& module_name, const char* name, const char* comment)
{
if ( ! comment ) return;
@ -1323,6 +1326,12 @@ void EnumType::AddNameInternal(const string& module_name, const char* name, bro_
names[copy_string(fullname.c_str())] = val;
}
void CommentedEnumType::AddNameInternal(const string& module_name, const char* name, bro_int_t val, bool is_export)
{
string fullname = make_full_var_name(module_name.c_str(), name);
names[copy_string(fullname.c_str())] = val;
}
bro_int_t EnumType::Lookup(const string& module_name, const char* name)
{
NameMap::iterator pos =
@ -1344,7 +1353,7 @@ const char* EnumType::Lookup(bro_int_t value)
return 0;
}
void EnumType::DescribeReST(ODesc* d) const
void CommentedEnumType::DescribeReST(ODesc* d) const
{
// create temporary, reverse name map so that enums can be documented
// in ascending order of their actual integral value instead of by name
@ -1384,10 +1393,6 @@ bool EnumType::DoSerialize(SerialInfo* info) const
SERIALIZE(false)) )
return false;
if ( generate_documentation )
if ( ! (SERIALIZE((unsigned int) comments.size())) )
return false;
for ( NameMap::const_iterator iter = names.begin();
iter != names.end(); ++iter )
{
@ -1395,14 +1400,6 @@ bool EnumType::DoSerialize(SerialInfo* info) const
return false;
}
if ( generate_documentation )
for ( CommentMap::const_iterator it = comments.begin();
it != comments.end(); ++ it )
{
if ( ! SERIALIZE(it->first) || ! SERIALIZE(it->second) )
return false;
}
return true;
}
@ -1411,7 +1408,6 @@ bool EnumType::DoUnserialize(UnserialInfo* info)
DO_UNSERIALIZE(BroType);
unsigned int len;
unsigned int cmnt_len;
bool dummy;
if ( ! UNSERIALIZE(&counter) ||
! UNSERIALIZE(&len) ||
@ -1419,10 +1415,6 @@ bool EnumType::DoUnserialize(UnserialInfo* info)
! UNSERIALIZE(&dummy) )
return false;
if ( generate_documentation )
if ( ! UNSERIALIZE(&cmnt_len) )
return false;
while ( len-- )
{
const char* name;
@ -1433,16 +1425,6 @@ bool EnumType::DoUnserialize(UnserialInfo* info)
names[name] = val;
}
if ( generate_documentation )
while ( cmnt_len-- )
{
const char* cmnt;
const char* name;
if ( ! (UNSERIALIZE_STR(&name, 0) && UNSERIALIZE_STR(&cmnt, 0)) )
return false;
comments[name] = cmnt;
}
return true;
}