Add xsd_all keyword to Thrift

Summary: Makes a struct an xsd_all instead of a sequence

Reviewed By: dave


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664929 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Slee 2007-01-19 00:17:02 +00:00
parent 0e0ff7e003
commit 782abbb756
4 changed files with 43 additions and 7 deletions

View File

@ -26,10 +26,15 @@ void t_xsd_generator::generate_typedef(t_typedef* ttypedef) {
void t_xsd_generator::generate_struct(t_struct* tstruct) {
vector<t_field*>::const_iterator m_iter;
const vector<t_field*>& members = tstruct->get_members();
bool xsd_all = tstruct->get_xsd_all();
indent(s_xsd_types_) << "<xsd:complexType name=\"" << tstruct->get_name() << "\">" << endl;
indent_up();
indent(s_xsd_types_) << "<xsd:sequence>" << endl;
if (xsd_all) {
indent(s_xsd_types_) << "<xsd:all minOccurs=\"0\" maxOccurs=\"1\">" << endl;
} else {
indent(s_xsd_types_) << "<xsd:sequence>" << endl;
}
indent_up();
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
@ -37,7 +42,11 @@ void t_xsd_generator::generate_struct(t_struct* tstruct) {
}
indent_down();
indent(s_xsd_types_) << "</xsd:sequence>" << endl;
if (xsd_all) {
indent(s_xsd_types_) << "</xsd:all>" << endl;
} else {
indent(s_xsd_types_) << "</xsd:sequence>" << endl;
}
indent_down();
indent(s_xsd_types_) <<
"</xsd:complexType>" << endl <<

View File

@ -20,11 +20,13 @@ class t_struct : public t_type {
public:
t_struct(t_program* program) :
t_type(program),
is_xception_(false) {}
is_xception_(false),
xsd_all_(false) {}
t_struct(t_program* program, const std::string& name) :
t_type(program, name),
is_xception_(false) {}
is_xception_(false),
xsd_all_(false) {}
void set_name(const std::string& name) {
name_ = name;
@ -34,6 +36,14 @@ class t_struct : public t_type {
is_xception_ = is_xception;
}
void set_xsd_all(bool xsd_all) {
xsd_all_ = xsd_all;
}
bool get_xsd_all() const {
return xsd_all_;
}
void append(t_field* elem) {
members_.push_back(elem);
}
@ -53,6 +63,9 @@ class t_struct : public t_type {
private:
std::vector<t_field*> members_;
bool is_xception_;
bool xsd_all_;
};
#endif

View File

@ -59,6 +59,7 @@ sliteral ("'"[^']*"'")
"cpp_type" { return tok_cpp_type; }
"java_package" { return tok_java_package; }
"php_namespace" { return tok_php_namespace; }
"xsd_all" { return tok_xsd_all; }
"include" { return tok_include; }
"void" { return tok_void; }

View File

@ -66,6 +66,7 @@ int y_field_val = -1;
%token tok_cpp_type
%token tok_php_namespace
%token tok_java_package
%token tok_xsd_all
/**
* Base datatype keywords
@ -144,6 +145,7 @@ int y_field_val = -1;
%type<tstruct> ThrowsOptional
%type<tservice> ExtendsOptional
%type<tbool> AsyncOptional
%type<tbool> XsdAllOptional
%type<id> CppTypeOptional
%%
@ -440,14 +442,25 @@ ConstMapContents:
}
Struct:
tok_struct tok_identifier '{' FieldList '}'
tok_struct tok_identifier XsdAllOptional '{' FieldList '}'
{
pdebug("Struct -> tok_struct tok_identifier { FieldList }");
$4->set_name($2);
$$ = $4;
$5->set_name($2);
$5->set_xsd_all($3);
$$ = $5;
y_field_val = -1;
}
XsdAllOptional:
tok_xsd_all
{
$$ = true;
}
|
{
$$ = false;
}
Xception:
tok_xception tok_identifier '{' FieldList '}'
{