THRIFT-787. compiler: Enums are not read correctly
This patch removes unnecessary enum value resolution code from all the individual generators. It's been unnecessary since forever ago when we made the compiler force the global resolution of values.
Patch: Christian Lavoie
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1001966 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_as3_generator.cc b/compiler/cpp/src/generate/t_as3_generator.cc
index d7fbb51..fa0a1fe 100644
--- a/compiler/cpp/src/generate/t_as3_generator.cc
+++ b/compiler/cpp/src/generate/t_as3_generator.cc
@@ -315,14 +315,8 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
indent(f_enum) <<
"public static const " << (*c_iter)->get_name() <<
":int = " << value << ";" << endl;
@@ -336,10 +330,8 @@
bool firstValue = true;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
// populate set
- if ((*c_iter)->has_value()) {
- f_enum << (firstValue ? "" : ", ") << (*c_iter)->get_name();
- firstValue = false;
- }
+ f_enum << (firstValue ? "" : ", ") << (*c_iter)->get_name();
+ firstValue = false;
}
indent_down();
f_enum << ");" << endl;
diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc
index 57a753b..d9b53f6 100644
--- a/compiler/cpp/src/generate/t_cocoa_generator.cc
+++ b/compiler/cpp/src/generate/t_cocoa_generator.cc
@@ -333,10 +333,8 @@
}
f_header_ <<
indent() << tenum->get_name() << "_" << (*c_iter)->get_name();
- if ((*c_iter)->has_value()) {
- f_header_ <<
- " = " << (*c_iter)->get_value();
- }
+ f_header_ <<
+ " = " << (*c_iter)->get_value();
}
indent_down();
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index 8d35b6d..59749b7 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -394,10 +394,8 @@
}
f_types_ <<
indent() << (*c_iter)->get_name();
- if ((*c_iter)->has_value()) {
- f_types_ <<
- " = " << (*c_iter)->get_value();
- }
+ f_types_ <<
+ " = " << (*c_iter)->get_value();
}
indent_down();
diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc
index 2d8545b..4b26c98 100644
--- a/compiler/cpp/src/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/generate/t_csharp_generator.cc
@@ -193,18 +193,9 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
- for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter)
- {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
- indent(f_enum) <<
- (*c_iter)->get_name() <<
- " = " << value << "," << endl;
+ for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
+ int value = (*c_iter)->get_value();
+ indent(f_enum) << (*c_iter)->get_name() << " = " << value << "," << endl;
}
scope_down(f_enum);
diff --git a/compiler/cpp/src/generate/t_erl_generator.cc b/compiler/cpp/src/generate/t_erl_generator.cc
index 2ed0315..f8bfde3 100644
--- a/compiler/cpp/src/generate/t_erl_generator.cc
+++ b/compiler/cpp/src/generate/t_erl_generator.cc
@@ -286,19 +286,11 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
-
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
string name = capitalize((*c_iter)->get_name());
-
- f_types_hrl_file_ <<
- indent() << "-define(" << program_name_ << "_" << tenum->get_name() << "_" << name << ", " << value << ")."<< endl;
+ indent(f_types_hrl_file_) <<
+ "-define(" << program_name_ << "_" << tenum->get_name() << "_" << name << ", " << value << ")."<< endl;
}
f_types_hrl_file_ << endl;
diff --git a/compiler/cpp/src/generate/t_hs_generator.cc b/compiler/cpp/src/generate/t_hs_generator.cc
index 6117f08..43bc397 100644
--- a/compiler/cpp/src/generate/t_hs_generator.cc
+++ b/compiler/cpp/src/generate/t_hs_generator.cc
@@ -279,36 +279,23 @@
indent(f_types_) << "deriving (Show,Eq, Typeable, Ord)" << endl;
indent_down();
- int value = -1;
indent(f_types_) << "instance Enum " << capitalize(tenum->get_name()) << " where" << endl;
indent_up();
indent(f_types_) << "fromEnum t = case t of" << endl;
indent_up();
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
+ int value = (*c_iter)->get_value();
string name = capitalize((*c_iter)->get_name());
-
- f_types_ <<
- indent() << name << " -> " << value << endl;
+ indent(f_types_) << name << " -> " << value << endl;
}
indent_down();
indent(f_types_) << "toEnum t = case t of" << endl;
indent_up();
for(c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
+ int value = (*c_iter)->get_value();
string name = capitalize((*c_iter)->get_name());
-
- f_types_ <<
- indent() << value << " -> " << name << endl;
+ indent(f_types_) << value << " -> " << name << endl;
}
indent(f_types_) << "_ -> throw ThriftException" << endl;
indent_down();
@@ -377,14 +364,9 @@
t_enum* tenum = (t_enum*)type;
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int val = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- val = (*c_iter)->get_value();
- } else {
- ++val;
- }
- if(val == value->get_integer()){
+ int val = (*c_iter)->get_value();
+ if (val == value->get_integer()) {
indent(out) << capitalize((*c_iter)->get_name());
break;
}
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index d93eb67..073828b 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -388,13 +388,8 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
bool first = true;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
+ int value = (*c_iter)->get_value();
if (first) {
first = false;
@@ -432,15 +427,8 @@
indent(f_enum) << "switch (value) {" << endl;
indent_up();
- value = -1;
-
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
indent(f_enum) << "case " << value << ":" << endl;
indent(f_enum) << " return " << (*c_iter)->get_name() << ";" << endl;
}
diff --git a/compiler/cpp/src/generate/t_javame_generator.cc b/compiler/cpp/src/generate/t_javame_generator.cc
index 1bd720a..696db69 100644
--- a/compiler/cpp/src/generate/t_javame_generator.cc
+++ b/compiler/cpp/src/generate/t_javame_generator.cc
@@ -339,14 +339,8 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
generate_java_doc(f_enum, *c_iter);
indent(f_enum) << "public static final " << tenum->get_name() <<
" " << (*c_iter)->get_name() << " = new " << tenum->get_name() <<
@@ -379,15 +373,8 @@
indent(f_enum) << "switch (value) {" << endl;
indent_up();
- value = -1;
-
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
indent(f_enum) << "case " << value << ":" << endl;
indent(f_enum) << " return " << (*c_iter)->get_name() << ";" << endl;
}
diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc
index bc4242c..c330657 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -276,22 +276,15 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
- if(c_iter != constants.begin())
+ int value = (*c_iter)->get_value();
+ if (c_iter != constants.begin())
f_types_ << ",";
f_types_ << "'" << (*c_iter)->get_name() << "' : " << value << endl;
}
f_types_ << "}"<<endl;
-
}
/**
diff --git a/compiler/cpp/src/generate/t_ocaml_generator.cc b/compiler/cpp/src/generate/t_ocaml_generator.cc
index e1875f4..1db77b3 100644
--- a/compiler/cpp/src/generate/t_ocaml_generator.cc
+++ b/compiler/cpp/src/generate/t_ocaml_generator.cc
@@ -313,7 +313,6 @@
indent_up();
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
string name = capitalize((*c_iter)->get_name());
indent(f_types_) << "| " << name << endl;
@@ -325,15 +324,9 @@
indent(f_types_i_) << "val to_i : t -> int" << endl;
indent_up();
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
+ int value = (*c_iter)->get_value();
string name = capitalize((*c_iter)->get_name());
-
- f_types_ <<
- indent() << "| " << name << " -> " << value << endl;
+ indent(f_types_) << "| " << name << " -> " << value << endl;
}
indent_down();
@@ -341,15 +334,9 @@
indent(f_types_i_) << "val of_i : int -> t" << endl;
indent_up();
for(c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
+ int value = (*c_iter)->get_value();
string name = capitalize((*c_iter)->get_name());
-
- f_types_ <<
- indent() << "| " << value << " -> " << name << endl;
+ indent(f_types_) << "| " << value << " -> " << name << endl;
}
indent(f_types_) << "| _ -> raise Thrift_error" << endl;
indent_down();
@@ -410,14 +397,9 @@
t_enum* tenum = (t_enum*)type;
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int val = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- val = (*c_iter)->get_value();
- } else {
- ++val;
- }
- if(val == value->get_integer()){
+ int val = (*c_iter)->get_value();
+ if (val == value->get_integer()) {
indent(out) << capitalize(tenum->get_name()) << "." << capitalize((*c_iter)->get_name());
break;
}
diff --git a/compiler/cpp/src/generate/t_perl_generator.cc b/compiler/cpp/src/generate/t_perl_generator.cc
index cbfc786..d3d8236 100644
--- a/compiler/cpp/src/generate/t_perl_generator.cc
+++ b/compiler/cpp/src/generate/t_perl_generator.cc
@@ -304,15 +304,9 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
- f_types_ << "use constant "<<(*c_iter)->get_name() << " => " << value << ";" << endl;
+ int value = (*c_iter)->get_value();
+ f_types_ << "use constant "<< (*c_iter)->get_name() << " => " << value << ";" << endl;
}
}
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index 3532eb0..f95c046 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -307,14 +307,8 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
f_types_ <<
" '" << (*c_iter)->get_name() << "' => " << value << "," << endl;
}
@@ -330,28 +324,16 @@
"final class " << php_namespace(tenum->get_program()) << tenum->get_name() << " {" << endl;
indent_up();
- value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
indent(f_types_) <<
"const " << (*c_iter)->get_name() << " = " << value << ";" << endl;
}
indent(f_types_) <<
"static public $__names = array(" << endl;
- value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
indent(f_types_) <<
" " << value << " => '" << (*c_iter)->get_name() << "'," << endl;
}
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 38eb20e..315cde2 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -388,16 +388,9 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
- f_types_ <<
- indent() << (*c_iter)->get_name() << " = " << value << endl;
+ int value = (*c_iter)->get_value();
+ indent(f_types_) << (*c_iter)->get_name() << " = " << value << endl;
// Dictionaries to/from string names of enums
to_string_mapping <<
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index 70c9c7a..a7836c7 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -297,13 +297,8 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
+ int value = (*c_iter)->get_value();
// Ruby class constants have to be capitalized... omg i am so on the fence
// about languages strictly enforcing capitalization why can't we just all
@@ -311,24 +306,17 @@
string name = capitalize((*c_iter)->get_name());
generate_rdoc(f_types_, *c_iter);
- f_types_ <<
- indent() << name << " = " << value << endl;
+ indent(f_types_) << name << " = " << value << endl;
}
- //Create a hash mapping values back to their names (as strings) since ruby has no native enum type
+ // Create a hash mapping values back to their names (as strings) since ruby has no native enum type
indent(f_types_) << "VALUE_MAP = {";
bool first = true;
- value = -1;
for(c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- //Populate the hash
- //If no value is given, use the next available one
- if ((*c_iter)->has_value())
- value = (*c_iter)->get_value();
- else ++value;
-
+ // Populate the hash
+ int value = (*c_iter)->get_value();
first ? first = false : f_types_ << ", ";
f_types_ << value << " => \"" << capitalize((*c_iter)->get_name()) << "\"";
-
}
f_types_ << "}" << endl;
@@ -337,7 +325,7 @@
first = true;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
// Populate the set
- first ? first = false: f_types_ << ", ";
+ first ? first = false : f_types_ << ", ";
f_types_ << capitalize((*c_iter)->get_name());
}
f_types_ << "]).freeze" << endl;
diff --git a/compiler/cpp/src/generate/t_st_generator.cc b/compiler/cpp/src/generate/t_st_generator.cc
index d94a563..27b5449 100644
--- a/compiler/cpp/src/generate/t_st_generator.cc
+++ b/compiler/cpp/src/generate/t_st_generator.cc
@@ -329,14 +329,8 @@
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
- int value = -1;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if ((*c_iter)->has_value()) {
- value = (*c_iter)->get_value();
- } else {
- ++value;
- }
-
+ int value = (*c_iter)->get_value();
f_ << "\tat: '" << (*c_iter)->get_name() << "' put: " << value << ";" << endl;
}