From 39a85eea0a6f51e7384d9cb21161780280ad998c Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@41a61cd8-c433-0410-bb1c-e256eeef9e11> Date: Mon, 14 Jan 2008 23:06:44 +0000 Subject: [PATCH] r1465@opsdev009 (orig r77666): mcslee | 2008-01-14 15:04:43 -0800 Generate structs/exceptions in declared order Summary: Otherwise you're liable to get forward declaration problems in the generated C++ code. Reviewed By: dreiss Test Plan: Generate some code that mixes exceptions/structs and has methods potentially return a list of exceptions git-svn-id: http://svn.facebook.com/svnroot/thrift/trunk@751 41a61cd8-c433-0410-bb1c-e256eeef9e11 --- compiler/cpp/src/generate/t_generator.cc | 21 +++++++++------------ compiler/cpp/src/parse/t_program.h | 10 +++++++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler/cpp/src/generate/t_generator.cc b/compiler/cpp/src/generate/t_generator.cc index 068822c..98ed6ee 100644 --- a/compiler/cpp/src/generate/t_generator.cc +++ b/compiler/cpp/src/generate/t_generator.cc @@ -37,18 +37,15 @@ void t_generator::generate_program() { vector consts = program_->get_consts(); generate_consts(consts); - // Generate structs - vector structs = program_->get_structs(); - vector::iterator st_iter; - for (st_iter = structs.begin(); st_iter != structs.end(); ++st_iter) { - generate_struct(*st_iter); - } - - // Generate xceptions - vector xceptions = program_->get_xceptions(); - vector::iterator x_iter; - for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) { - generate_xception(*x_iter); + // Generate structs and exceptions in declared order + vector objects = program_->get_objects(); + vector::iterator o_iter; + for (o_iter = objects.begin(); o_iter != objects.end(); ++o_iter) { + if ((*o_iter)->is_xception()) { + generate_xception(*o_iter); + } else { + generate_struct(*o_iter); + } } // Generate services diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h index 66f0620..62528e6 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -76,14 +76,17 @@ class t_program : public t_doc { const std::vector& get_consts() const { return consts_; } const std::vector& get_structs() const { return structs_; } const std::vector& get_xceptions() const { return xceptions_; } + const std::vector& get_objects() const { return objects_; } const std::vector& get_services() const { return services_; } // Program elements void add_typedef (t_typedef* td) { typedefs_.push_back(td); } void add_enum (t_enum* te) { enums_.push_back(te); } void add_const (t_const* tc) { consts_.push_back(tc); } - void add_struct (t_struct* ts) { structs_.push_back(ts); } - void add_xception (t_struct* tx) { xceptions_.push_back(tx); } + void add_struct (t_struct* ts) { objects_.push_back(ts); + structs_.push_back(ts); } + void add_xception (t_struct* tx) { objects_.push_back(tx); + xceptions_.push_back(tx); } void add_service (t_service* ts) { services_.push_back(ts); } // Programs to include @@ -211,7 +214,7 @@ class t_program : public t_doc { void set_smalltalk_prefix(std::string smalltalk_prefix) { smalltalk_prefix_ = smalltalk_prefix; } - + const std::string& get_smalltalk_prefix() const { return smalltalk_prefix_; } @@ -240,6 +243,7 @@ class t_program : public t_doc { std::vector typedefs_; std::vector enums_; std::vector consts_; + std::vector objects_; std::vector structs_; std::vector xceptions_; std::vector services_; -- 2.11.4.GIT