From c2532a9ac4168778c581cff235943eb270df6dbc Mon Sep 17 00:00:00 2001 From: David Reiss Date: Mon, 30 Jul 2007 23:46:11 +0000 Subject: [PATCH] Thrift: Allow whole program doctext. Summary: Allow docstrings at the top of the program. Blame Rev: 52687 Reviewed By: mcslee Test Plan: ../compiler/cpp/thrift -cpp DocTest.thrift (with dump_docs on) and looked at the output. Generated C++ is identical to installed thrift. Revert Plan: Do 52687 also. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665183 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/main.cc | 6 +++++- compiler/cpp/src/parse/t_doc.h | 2 ++ compiler/cpp/src/parse/t_program.h | 3 ++- compiler/cpp/src/thrifty.yy | 5 ++++- test/DocTest.thrift | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 4d00306c..ed38b074 100644 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -433,9 +433,13 @@ static bool dump_docs = false; /** * Dumps docstrings to stdout - * Only works for typedefs + * Only works for typedefs and whole program */ void dump_docstrings(t_program* program) { + string progdoc = g_program->get_doc(); + if (!progdoc.empty()) { + printf("Whole program doc:\n%s\n", progdoc.c_str()); + } const vector& typedefs = program->get_typedefs(); vector::const_iterator t_iter; for (t_iter = typedefs.begin(); t_iter != typedefs.end(); ++t_iter) { diff --git a/compiler/cpp/src/parse/t_doc.h b/compiler/cpp/src/parse/t_doc.h index 9e3795aa..bfa66eff 100644 --- a/compiler/cpp/src/parse/t_doc.h +++ b/compiler/cpp/src/parse/t_doc.h @@ -15,6 +15,8 @@ class t_doc { public: + t_doc() : has_doc_(false) {} + void set_doc(const std::string& doc) { doc_ = doc; has_doc_ = true; diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h index 8b4f59cd..f54ed714 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -14,6 +14,7 @@ // For program_name() #include "main.h" +#include "t_doc.h" #include "t_scope.h" #include "t_base_type.h" #include "t_typedef.h" @@ -41,7 +42,7 @@ * * @author Mark Slee */ -class t_program { +class t_program : public t_doc { public: t_program(std::string path, std::string name) : path_(path), diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index 68384be0..1ad0c35f 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -186,9 +186,12 @@ int y_field_val = -1; */ Program: - HeaderList DefinitionList + DocTextOptional HeaderList DefinitionList { pdebug("Program -> Headers DefinitionList"); + if ($1 != NULL) { + g_program->set_doc($1); + } } HeaderList: diff --git a/test/DocTest.thrift b/test/DocTest.thrift index c06bd212..361bdded 100755 --- a/test/DocTest.thrift +++ b/test/DocTest.thrift @@ -1,3 +1,9 @@ +/** + * Program doctext. + * + * Seriously, this is the documentation for this whole program. + */ + java_package thrift.test cpp_namespace thrift.test @@ -67,6 +73,10 @@ exception Xception2 { 2: Xtruct struct_thing } +/* C1 */ +/** Doc */ +/* C2 */ +/* C3 */ struct EmptyStruct {} struct OneField { @@ -211,3 +221,11 @@ typedef i32 TrailingWhitespace * } */ typedef i32 BigDog + +/** +* +* +*/ +typedef i32 TotallyDegenerate + +/* THE END */ -- 2.17.1