diff --git a/src/broxygen/Document.cc b/src/broxygen/Document.cc index ab8aca08aa..6b3a7309ce 100644 --- a/src/broxygen/Document.cc +++ b/src/broxygen/Document.cc @@ -15,19 +15,22 @@ PackageDocument::PackageDocument(const string& arg_name) IdentifierDocument::IdentifierDocument(ID* arg_id) : Document(), - comments(), id(arg_id), initial_val(), redefs(), fields(), + comments(), id(arg_id), initial_val_desc(), redefs(), fields(), last_field_seen() { Ref(id); if ( id->ID_Val() ) - initial_val = id->ID_Val()->Clone(); + { + ODesc d; + id->ID_Val()->Describe(&d); + initial_val_desc = d.Description(); + } } IdentifierDocument::~IdentifierDocument() { Unref(id); - //Unref(initial_val); // TODO: problematic w/ PatternVals for ( RedefList::const_iterator it = redefs.begin(); it != redefs.end(); ++it ) @@ -42,7 +45,14 @@ void IdentifierDocument::AddRedef(const string& script, { Redefinition* redef = new Redefinition(); redef->from_script = script; - redef->new_val = id->ID_Val() ? id->ID_Val()->Clone() : 0; + + if ( id->ID_Val() ) + { + ODesc d; + id->ID_Val()->Describe(&d); + redef->new_val_desc = d.Description(); + } + redef->comments = comments; redefs.push_back(redef); } diff --git a/src/broxygen/Document.h b/src/broxygen/Document.h index 34742f8069..9010dd0a38 100644 --- a/src/broxygen/Document.h +++ b/src/broxygen/Document.h @@ -81,11 +81,8 @@ public: private: struct Redefinition { - ~Redefinition() - { Unref(new_val); } - std::string from_script; - Val* new_val; + string new_val_desc; std::vector comments; }; @@ -106,7 +103,7 @@ private: std::vector comments; ID* id; - Val* initial_val; + string initial_val_desc; RedefList redefs; std::vector fields; RecordField* last_field_seen; diff --git a/src/broxygen/Manager.cc b/src/broxygen/Manager.cc index 8d01c51224..c886973269 100644 --- a/src/broxygen/Manager.cc +++ b/src/broxygen/Manager.cc @@ -84,9 +84,11 @@ static string PrettifyParams(const string& s) } Manager::Manager(const string& config) - : comment_buffer(), packages(), scripts(), identifiers(), all_docs(), - last_doc_seen(), incomplete_type() + : disabled(), comment_buffer(), packages(), scripts(), identifiers(), + all_docs(), last_doc_seen(), incomplete_type() { + if ( getenv("BRO_DISABLE_BROXYGEN") ) + disabled = true; // TODO config file stuff } @@ -99,16 +101,22 @@ Manager::~Manager() void Manager::InitPreScript() { + if ( disabled ) + return; // TODO: create file/proto analyzer doc } void Manager::InitPostScript() { + if ( disabled ) + return; // TODO: dependency resolution stuff? } void Manager::GenerateDocs() const { + if ( disabled ) + return; // TODO // may be a no-op if no config file @@ -116,6 +124,9 @@ void Manager::GenerateDocs() const void Manager::File(const string& path) { + if ( disabled ) + return; + string name = without_bropath_component(path); if ( scripts.find(name) != scripts.end() ) @@ -144,6 +155,9 @@ void Manager::File(const string& path) void Manager::ScriptDependency(const string& path, const string& dep) { + if ( disabled ) + return; + if ( dep.empty() ) { DbgAndWarn(fmt("Empty script doc dependency: %s", path.c_str())); @@ -173,6 +187,9 @@ void Manager::ScriptDependency(const string& path, const string& dep) void Manager::ModuleUsage(const string& path, const string& module) { + if ( disabled ) + return; + string name = without_bropath_component(path); ScriptMap::const_iterator it = scripts.find(name); @@ -189,6 +206,9 @@ void Manager::ModuleUsage(const string& path, const string& module) void Manager::StartType(ID* id) { + if ( disabled ) + return; + if ( id->GetLocationInfo() == &no_location ) { DbgAndWarn(fmt("Can't document %s, no location available", id->Name())); @@ -218,6 +238,9 @@ void Manager::StartType(ID* id) void Manager::Identifier(ID* id) { + if ( disabled ) + return; + if ( incomplete_type && incomplete_type->Name() == id->Name() ) { DBG_LOG(DBG_BROXYGEN, "Finished document for type %s", id->Name()); @@ -273,6 +296,9 @@ void Manager::Identifier(ID* id) void Manager::RecordField(const ID* id, const TypeDecl* field, const string& path) { + if ( disabled ) + return; + IdentifierDocument* idd = 0; if ( incomplete_type ) @@ -311,6 +337,9 @@ void Manager::RecordField(const ID* id, const TypeDecl* field, void Manager::Redef(const ID* id, const string& path) { + if ( disabled ) + return; + if ( path == "" ) // This is a redef defined on the command line. return; @@ -342,6 +371,9 @@ void Manager::Redef(const ID* id, const string& path) void Manager::SummaryComment(const string& script, const string& comment) { + if ( disabled ) + return; + string name = without_bropath_component(script); ScriptMap::const_iterator it = scripts.find(name); @@ -357,11 +389,17 @@ void Manager::SummaryComment(const string& script, const string& comment) void Manager::PreComment(const string& comment) { + if ( disabled ) + return; + comment_buffer.push_back(PrettifyParams(RemoveLeadingSpace(comment))); } void Manager::PostComment(const string& comment) { + if ( disabled ) + return; + IdentifierDocument* doc = dynamic_cast(last_doc_seen); if ( ! doc ) diff --git a/src/broxygen/Manager.h b/src/broxygen/Manager.h index 10b63af945..94ba2dec8e 100644 --- a/src/broxygen/Manager.h +++ b/src/broxygen/Manager.h @@ -13,7 +13,6 @@ namespace broxygen { // TODO: documentation... -// TODO: optimize parse time... maybe an env. option to disable doc collection? class Manager { @@ -60,6 +59,7 @@ private: void RegisterDoc(Document* d); + bool disabled; CommentBuffer comment_buffer; PackageMap packages; ScriptMap scripts; diff --git a/src/main.cc b/src/main.cc index 764b508749..2ab25460d4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -227,6 +227,7 @@ void usage() fprintf(stderr, " $BRO_SEED_FILE | file to load seeds from (not set)\n"); fprintf(stderr, " $BRO_LOG_SUFFIX | ASCII log file extension (.%s)\n", logging::writer::Ascii::LogExt().c_str()); fprintf(stderr, " $BRO_PROFILER_FILE | Output file for script execution statistics (not set)\n"); + fprintf(stderr, " $BRO_DISABLE_BROXYGEN | Disable Broxygen documentation support (%s)\n", getenv("BRO_DISABLE_BROXYGEN") ? "set" : "not set"); fprintf(stderr, "\n"); fprintf(stderr, " Supported log formats: "); diff --git a/src/parse.y b/src/parse.y index 75be472853..5dc43a8476 100644 --- a/src/parse.y +++ b/src/parse.y @@ -963,7 +963,7 @@ type_decl: set_location(@1, @4); $$ = new TypeDecl($3, $1, $4, (in_record > 0)); - if ( in_record > 0 ) + if ( in_record > 0 && cur_decl_type_id ) broxygen_mgr->RecordField(cur_decl_type_id, $$, ::filename); } ;