From 27148dee980b396afee80bc7e5ce704443de4408 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Fri, 4 Oct 2013 19:10:16 +0200 Subject: [PATCH] THRIFT-2215 Generated HTML/Graphviz lists referenced enum identifiers as UNKNOWN. Patch: Jens Geyer --- compiler/cpp/src/generate/t_gv_generator.cc | 21 +++++++++++------ compiler/cpp/src/generate/t_html_generator.cc | 23 ++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/compiler/cpp/src/generate/t_gv_generator.cc b/compiler/cpp/src/generate/t_gv_generator.cc index ff6bca1d..46c9d385 100644 --- a/compiler/cpp/src/generate/t_gv_generator.cc +++ b/compiler/cpp/src/generate/t_gv_generator.cc @@ -80,7 +80,7 @@ class t_gv_generator : public t_generator { * Helpers */ void print_type(t_type* ttype, string struct_field_ref); - void print_const_value(t_const_value* tvalue); + void print_const_value(t_type* type, t_const_value* tvalue); private: std::ofstream f_out_; @@ -162,7 +162,7 @@ void t_gv_generator::generate_const (t_const* tconst) { f_out_ << escape_string(name); f_out_ << " = "; - print_const_value(tconst->get_value()); + print_const_value( tconst->get_type(), tconst->get_value()); f_out_ << " :: "; print_type(tconst->get_type(), "const_" + name); @@ -232,7 +232,7 @@ void t_gv_generator::print_type(t_type* ttype, string struct_field_ref) { /** * Prints out an string representation of the provided constant value */ -void t_gv_generator::print_const_value(t_const_value* tvalue) { +void t_gv_generator::print_const_value(t_type* type, t_const_value* tvalue) { bool first = true; switch (tvalue->get_type()) { case t_const_value::CV_INTEGER: @@ -254,9 +254,9 @@ void t_gv_generator::print_const_value(t_const_value* tvalue) { f_out_ << ", "; } first = false; - print_const_value(map_iter->first); + print_const_value( ((t_map*)type)->get_key_type(), map_iter->first); f_out_ << " = "; - print_const_value(map_iter->second); + print_const_value( ((t_map*)type)->get_val_type(), map_iter->second); } f_out_ << " \\}"; } @@ -271,11 +271,18 @@ void t_gv_generator::print_const_value(t_const_value* tvalue) { f_out_ << ", "; } first = false; - print_const_value(*list_iter); + if (type->is_list()) { + print_const_value( ((t_list*)type)->get_elem_type(), *list_iter); + } else { + print_const_value( ((t_set*)type)->get_elem_type(), *list_iter); + } } f_out_ << " \\}"; } break; + case t_const_value::CV_IDENTIFIER: + f_out_ << escape_string(type->get_name()) << "." << escape_string(tvalue->get_identifier_name()); + break; default: f_out_ << "UNKNOWN"; break; @@ -308,7 +315,7 @@ void t_gv_generator::generate_service (t_service* tservice) { f_out_ << (*arg_iter)->get_name(); if ((*arg_iter)->get_value() != NULL) { f_out_ << " = "; - print_const_value((*arg_iter)->get_value()); + print_const_value((*arg_iter)->get_type(), (*arg_iter)->get_value()); } f_out_ << " :: "; print_type((*arg_iter)->get_type(), diff --git a/compiler/cpp/src/generate/t_html_generator.cc b/compiler/cpp/src/generate/t_html_generator.cc index 0d0115d7..ef1f3125 100644 --- a/compiler/cpp/src/generate/t_html_generator.cc +++ b/compiler/cpp/src/generate/t_html_generator.cc @@ -99,7 +99,7 @@ class t_html_generator : public t_generator { void print_doc (t_doc* tdoc); int print_type (t_type* ttype); - void print_const_value(t_const_value* tvalue); + void print_const_value(t_type* type, t_const_value* tvalue); void print_fn_args_doc(t_function* tfunction); private: @@ -594,7 +594,7 @@ int t_html_generator::print_type(t_type* ttype) { /** * Prints out an HTML representation of the provided constant value */ -void t_html_generator::print_const_value(t_const_value* tvalue) { +void t_html_generator::print_const_value(t_type* type, t_const_value* tvalue) { bool first = true; switch (tvalue->get_type()) { case t_const_value::CV_INTEGER: @@ -616,9 +616,9 @@ void t_html_generator::print_const_value(t_const_value* tvalue) { f_out_ << ", "; } first = false; - print_const_value(map_iter->first); + print_const_value( ((t_map*)type)->get_key_type(), map_iter->first); f_out_ << " = "; - print_const_value(map_iter->second); + print_const_value( ((t_map*)type)->get_val_type(), map_iter->second); } f_out_ << " }"; } @@ -633,11 +633,18 @@ void t_html_generator::print_const_value(t_const_value* tvalue) { f_out_ << ", "; } first = false; - print_const_value(*list_iter); + if (type->is_list()) { + print_const_value( ((t_list*)type)->get_elem_type(), *list_iter); + } else { + print_const_value( ((t_set*)type)->get_elem_type(), *list_iter); + } } f_out_ << " }"; } break; + case t_const_value::CV_IDENTIFIER: + f_out_ << escape_html(type->get_name()) << "." << escape_html(tvalue->get_identifier_name()); + break; default: f_out_ << "UNKNOWN"; break; @@ -749,7 +756,7 @@ void t_html_generator::generate_const(t_const* tconst) { << ""; print_type(tconst->get_type()); f_out_ << ""; - print_const_value(tconst->get_value()); + print_const_value(tconst->get_type(), tconst->get_value()); f_out_ << ""; if (tconst->has_doc()) { f_out_ << "
"; @@ -798,7 +805,7 @@ void t_html_generator::generate_struct(t_struct* tstruct) { f_out_ << ""; t_const_value* default_val = (*mem_iter)->get_value(); if (default_val != NULL) { - print_const_value(default_val); + print_const_value((*mem_iter)->get_type(), default_val); } f_out_ << "" << endl; } @@ -858,7 +865,7 @@ void t_html_generator::generate_service(t_service* tservice) { f_out_ << " " << (*arg_iter)->get_name(); if ((*arg_iter)->get_value() != NULL) { f_out_ << " = "; - print_const_value((*arg_iter)->get_value()); + print_const_value((*arg_iter)->get_type(), (*arg_iter)->get_value()); } } f_out_ << ")" << endl; -- 2.17.1