Revise autodoc tracking of public vs private script interfaces

A bro script's public interface is taken to mean any identifier declared
in the global scope that optionally is exported from some namespace/module.
Or more simply: ID::IsGlobal()
This commit is contained in:
Jon Siwek 2011-03-24 12:32:32 -05:00
parent c2f0332b5f
commit 2e88c5100c
4 changed files with 20 additions and 24 deletions

View file

@ -152,6 +152,7 @@ void BroDoc::WriteDocFile() const
WriteBroDocObjList(redefs, true, "Redefinitions", '~'); WriteBroDocObjList(redefs, true, "Redefinitions", '~');
WriteSectionHeading("Private Interface", '-'); WriteSectionHeading("Private Interface", '-');
WriteBroDocObjList(options, false, "Options", '~');
WriteBroDocObjList(state_vars, false, "State Variables", '~'); WriteBroDocObjList(state_vars, false, "State Variables", '~');
WriteBroDocObjList(types, false, "Types", '~'); WriteBroDocObjList(types, false, "Types", '~');
WriteBroDocObjList(events, false, "Events", '~'); WriteBroDocObjList(events, false, "Events", '~');
@ -177,7 +178,7 @@ void BroDoc::WriteStringList(const char* format,
} }
void BroDoc::WriteBroDocObjList(const std::list<const BroDocObj*>& l, void BroDoc::WriteBroDocObjList(const std::list<const BroDocObj*>& l,
bool exportCond, bool wantPublic,
const char* heading, const char* heading,
char underline) const char underline) const
{ {
@ -185,18 +186,12 @@ void BroDoc::WriteBroDocObjList(const std::list<const BroDocObj*>& l,
std::list<const BroDocObj*>::const_iterator it; std::list<const BroDocObj*>::const_iterator it;
for ( it = l.begin(); it != l.end(); ++it ) for ( it = l.begin(); it != l.end(); ++it )
{ {
if ( exportCond ) if ( wantPublic )
{
// write out only those in an export section
if ( (*it)->IsPublicAPI() ) if ( (*it)->IsPublicAPI() )
(*it)->WriteReST(reST_file); (*it)->WriteReST(reST_file);
}
else else
{ if ( ! (*it)->IsPublicAPI() )
// write out only those that have comments and are not exported
if ( !(*it)->IsPublicAPI() && (*it)->HasDocumentation() )
(*it)->WriteReST(reST_file); (*it)->WriteReST(reST_file);
}
} }
} }

View file

@ -198,15 +198,15 @@ protected:
/** /**
* Writes out a list of BroDocObj objects to the reST document * Writes out a list of BroDocObj objects to the reST document
* @param l A list of BroDocObj pointers * @param l A list of BroDocObj pointers
* @param exportCond If true, filter out objects that are not in an * @param wantPublic If true, filter out objects that are not declared
* export section. If false, filter out those that are in * in the global scope. If false, filter out those that are in
* an export section. * the global scope.
* @param heading The title of the section to create in the reST doc. * @param heading The title of the section to create in the reST doc.
* @param underline The character to use to underline the reST * @param underline The character to use to underline the reST
* section heading. * section heading.
*/ */
void WriteBroDocObjList(const std::list<const BroDocObj*>& l, void WriteBroDocObjList(const std::list<const BroDocObj*>& l,
bool exportCond, bool wantPublic,
const char* heading, const char* heading,
char underline) const; char underline) const;

View file

@ -37,11 +37,13 @@ public:
void WriteReST(FILE* file) const; void WriteReST(FILE* file) const;
/** /**
* Check whether this documentation is part of the public API * Check whether this documentation is part of the public API. In
* (The declaration was while in an export section). * other words, this means that the identifier is declared as part of
* the global scope (has GLOBAL namespace or is exported from another
* namespace).
* @return true if the ID was declared in an export section, else false * @return true if the ID was declared in an export section, else false
*/ */
bool IsPublicAPI() const { return broID->IsExport(); } bool IsPublicAPI() const { return broID->IsGlobal(); }
/** /**
* Return whether this object has documentation (## comments) * Return whether this object has documentation (## comments)

View file

@ -157,13 +157,12 @@ static void add_enum_comment (std::list<std::string>* comments)
cur_enum_type_doc->AddComment(current_module, cur_enum_elem_id, comments); cur_enum_type_doc->AddComment(current_module, cur_enum_elem_id, comments);
} }
static ID* create_dummy_id (const char* name, BroType* type) static ID* create_dummy_id (const ID* id, BroType* type)
{ {
// normally, install_ID() figures out the right IDScope ID* fake_id = new ID(copy_string(id->Name()), (IDScope) id->Scope(),
// but it doesn't matter for the dummy ID so use SCOPE_GLOBAL is_export);
ID* fake_id = new ID(copy_string(name), SCOPE_GLOBAL, is_export);
fake_id->SetType(type); fake_id->SetType(type);
type->SetTypeID(copy_string(name)); type->SetTypeID(copy_string(id->Name()));
fake_id->MakeType(); fake_id->MakeType();
return fake_id; return fake_id;
} }
@ -1009,7 +1008,7 @@ decl:
do_doc_token_stop(); do_doc_token_stop();
if ( generate_documentation ) if ( generate_documentation )
{ {
ID* fake_id = create_dummy_id($3->Name(), cur_enum_type_doc); ID* fake_id = create_dummy_id($3, cur_enum_type_doc);
cur_enum_type_doc = 0; cur_enum_type_doc = 0;
BroDocObj* o = new BroDocObj(fake_id, reST_doc_comments, true); BroDocObj* o = new BroDocObj(fake_id, reST_doc_comments, true);
o->SetRole(true); o->SetRole(true);
@ -1028,7 +1027,7 @@ decl:
TypeTag t = $2->AsType()->Tag(); TypeTag t = $2->AsType()->Tag();
if ( t == TYPE_ENUM && cur_enum_type_doc ) if ( t == TYPE_ENUM && cur_enum_type_doc )
{ {
ID* fake = create_dummy_id($2->Name(), cur_enum_type_doc); ID* fake = create_dummy_id($2, cur_enum_type_doc);
cur_enum_type_doc = 0; cur_enum_type_doc = 0;
current_reST_doc->AddType( current_reST_doc->AddType(
new BroDocObj(fake, reST_doc_comments, true)); new BroDocObj(fake, reST_doc_comments, true));
@ -1036,7 +1035,7 @@ decl:
else if ( t == TYPE_RECORD && fake_type_decl_list ) else if ( t == TYPE_RECORD && fake_type_decl_list )
{ {
BroType* fake_record = new RecordType(fake_type_decl_list); BroType* fake_record = new RecordType(fake_type_decl_list);
ID* fake = create_dummy_id($2->Name(), fake_record); ID* fake = create_dummy_id($2, fake_record);
fake_type_decl_list = 0; fake_type_decl_list = 0;
current_reST_doc->AddType( current_reST_doc->AddType(
new BroDocObj(fake, reST_doc_comments, true)); new BroDocObj(fake, reST_doc_comments, true));