Fix Thrift compiler to support reuse of enums and constants in later constants
Summary: So for example, you can make a constant map of enum values to string identifiers.
Reviewed By: dreiss
Test Plan: ConstantsDemo.thrift in the test folder
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665181 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/parse/t_const_value.h b/compiler/cpp/src/parse/t_const_value.h
index 6e8887c..fec2acc 100644
--- a/compiler/cpp/src/parse/t_const_value.h
+++ b/compiler/cpp/src/parse/t_const_value.h
@@ -30,6 +30,14 @@
t_const_value() {}
+ t_const_value(int val) {
+ set_integer(val);
+ }
+
+ t_const_value(std::string val) {
+ set_string(val);
+ }
+
void set_string(std::string val) {
valType_ = CV_STRING;
stringVal_ = val;
diff --git a/compiler/cpp/src/parse/t_scope.h b/compiler/cpp/src/parse/t_scope.h
index 3047e7d..c97f2d6 100644
--- a/compiler/cpp/src/parse/t_scope.h
+++ b/compiler/cpp/src/parse/t_scope.h
@@ -41,6 +41,14 @@
return services_[name];
}
+ void add_constant(std::string name, t_const* constant) {
+ constants_[name] = constant;
+ }
+
+ t_const* get_constant(std::string name) {
+ return constants_[name];
+ }
+
void print() {
std::map<std::string, t_type*>::iterator iter;
for (iter = types_.begin(); iter != types_.end(); ++iter) {
@@ -55,6 +63,9 @@
// Map of names to types
std::map<std::string, t_type*> types_;
+ // Map of names to constants
+ std::map<std::string, t_const*> constants_;
+
// Map of names to services
std::map<std::string, t_service*> services_;