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
/**
* 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<t_typedef*>& typedefs = program->get_typedefs();
vector<t_typedef*>::const_iterator t_iter;
for (t_iter = typedefs.begin(); t_iter != typedefs.end(); ++t_iter) {
class t_doc {
public:
+ t_doc() : has_doc_(false) {}
+
void set_doc(const std::string& doc) {
doc_ = doc;
has_doc_ = true;
// For program_name()
#include "main.h"
+#include "t_doc.h"
#include "t_scope.h"
#include "t_base_type.h"
#include "t_typedef.h"
*
* @author Mark Slee <mcslee@facebook.com>
*/
-class t_program {
+class t_program : public t_doc {
public:
t_program(std::string path, std::string name) :
path_(path),
*/
Program:
- HeaderList DefinitionList
+ DocTextOptional HeaderList DefinitionList
{
pdebug("Program -> Headers DefinitionList");
+ if ($1 != NULL) {
+ g_program->set_doc($1);
+ }
}
HeaderList:
+/**
+ * Program doctext.
+ *
+ * Seriously, this is the documentation for this whole program.
+ */
+
java_package thrift.test
cpp_namespace thrift.test
2: Xtruct struct_thing
}
+/* C1 */
+/** Doc */
+/* C2 */
+/* C3 */
struct EmptyStruct {}
struct OneField {
* }
*/
typedef i32 BigDog
+
+/**
+*
+*
+*/
+typedef i32 TotallyDegenerate
+
+/* THE END */