From: Mark Slee Date: Wed, 7 Feb 2007 01:20:08 +0000 (+0000) Subject: xsd_attrs are a FieldList now, so you can have multiple of them and they are typed X-Git-Tag: 0.2.0~1488 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=748d83f65f7567415efda53f5cfd62c726737469;p=common%2Fthrift.git xsd_attrs are a FieldList now, so you can have multiple of them and they are typed Reviewed By: xsd git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664984 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc index 06803ec9..4c31d6c1 100644 --- a/compiler/cpp/src/generate/t_xsd_generator.cc +++ b/compiler/cpp/src/generate/t_xsd_generator.cc @@ -66,7 +66,7 @@ void t_xsd_generator::generate_struct(t_struct* tstruct) { void t_xsd_generator::generate_element(ostream& out, string name, t_type* ttype, - vector attrs, + t_struct* attrs, bool optional, bool nillable, bool list_element) { @@ -79,7 +79,7 @@ void t_xsd_generator::generate_element(ostream& out, indent(out) << "" << endl; indent_up(); - if (attrs.size() == 0 && ttype->is_void()) { + if (attrs == NULL && ttype->is_void()) { indent(out) << "" << endl; } else { @@ -97,14 +97,17 @@ void t_xsd_generator::generate_element(ostream& out, subname = type_name(subtype); } f_php_ << "$GLOBALS['" << program_->get_name() << "_xsd_elt_" << name << "'] = '" << subname << "';" << endl; - generate_element(out, subname, subtype, vector(), false, false, true); + generate_element(out, subname, subtype, NULL, false, false, true); indent_down(); indent(out) << "" << endl; indent(out) << "" << endl; } - vector::iterator a_iter; - for (a_iter = attrs.begin(); a_iter != attrs.end(); ++a_iter) { - indent(out) << "" << endl; + if (attrs != NULL) { + const vector& members = attrs->get_members(); + vector::const_iterator a_iter; + for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) { + indent(out) << "get_name() << "\" type=\"" << type_name((*a_iter)->get_type()) << "\" />" << endl; + } } indent_down(); indent(out) << @@ -114,7 +117,7 @@ void t_xsd_generator::generate_element(ostream& out, indent(out) << "" << endl; } else { - if (attrs.size() == 0) { + if (attrs == NULL) { indent(out) << "" << endl; } else { @@ -127,9 +130,10 @@ void t_xsd_generator::generate_element(ostream& out, indent_up(); indent(out) << "" << endl; indent_up(); - vector::iterator a_iter; - for (a_iter = attrs.begin(); a_iter != attrs.end(); ++a_iter) { - indent(out) << "" << endl; + const vector& members = attrs->get_members(); + vector::const_iterator a_iter; + for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) { + indent(out) << "get_name() << "\" type=\"" << type_name((*a_iter)->get_type()) << "\" />" << endl; } indent_down(); indent(out) << "" << endl; diff --git a/compiler/cpp/src/generate/t_xsd_generator.h b/compiler/cpp/src/generate/t_xsd_generator.h index 21e74fb1..2c633b9e 100644 --- a/compiler/cpp/src/generate/t_xsd_generator.h +++ b/compiler/cpp/src/generate/t_xsd_generator.h @@ -40,7 +40,7 @@ class t_xsd_generator : public t_generator { private: - void generate_element(std::ostream& out, std::string name, t_type* ttype, std::vector attrs=std::vector(), bool optional=false, bool nillable=false, bool list_element=false); + void generate_element(std::ostream& out, std::string name, t_type* ttype, t_struct* attrs=NULL, bool optional=false, bool nillable=false, bool list_element=false); std::string ns(std::string in, std::string ns) { return ns + ":" + in; diff --git a/compiler/cpp/src/parse/t_field.h b/compiler/cpp/src/parse/t_field.h index dfa5cacf..65a75d34 100644 --- a/compiler/cpp/src/parse/t_field.h +++ b/compiler/cpp/src/parse/t_field.h @@ -3,6 +3,9 @@ #include +// Forward declare for xsd_attrs +class t_struct; + /** * Class to represent a field in a thrift structure. A field has a data type, * a symbolic name, and a numeric identifier. @@ -17,7 +20,8 @@ class t_field { key_(0), value_(NULL), xsd_optional_(false), - xsd_nillable_(false) {} + xsd_nillable_(false), + xsd_attrs_(NULL) {} t_field(t_type* type, std::string name, int32_t key) : type_(type), @@ -25,7 +29,8 @@ class t_field { key_(key), value_(NULL), xsd_optional_(false), - xsd_nillable_(false) {} + xsd_nillable_(false), + xsd_attrs_(NULL) {} ~t_field() {} @@ -65,11 +70,11 @@ class t_field { return xsd_nillable_; } - void add_xsd_attr(std::string attr) { - xsd_attrs_.push_back(attr); + void set_xsd_attrs(t_struct* xsd_attrs) { + xsd_attrs_ = xsd_attrs; } - const std::vector& get_xsd_attrs() { + t_struct* get_xsd_attrs() { return xsd_attrs_; } @@ -94,7 +99,7 @@ class t_field { bool xsd_optional_; bool xsd_nillable_; - std::vector xsd_attrs_; + t_struct* xsd_attrs_; std::string doc_; bool has_doc_; diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index c1d383b6..19f1ba8e 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -157,7 +157,7 @@ int y_field_val = -1; %type XsdAll %type XsdOptional %type XsdNillable -%type XsdAttributes +%type XsdAttributes %type CppType %type DocTextOptional @@ -530,9 +530,9 @@ XsdNillable: } XsdAttributes: - tok_xsd_attrs tok_identifier + tok_xsd_attrs '{' FieldList '}' { - $$ = $2; + $$ = $3; } | { @@ -660,7 +660,7 @@ Field: $$->set_doc($1); } if ($8 != NULL) { - $$->add_xsd_attr($8); + $$->set_xsd_attrs($8); } }