Author: dreiss
Date: Mon Sep 13 17:32:14 2010
New Revision: 996610
URL: http://svn.apache.org/viewvc?rev=996610&view=rev
Log:
Fix enum value lookups in C++
The recent enum change was causing enums to break if used as constant
values by the C++ generator. The problem was that we were searching for
the fully-qualified constant name (enum_name.VALUE_NAME) in the enum
values. This didn't affect Java because it just uses symbolic names in
the generated code. Fix it by grabbing the base name before doing the
search.
Modified:
incubator/thrift/trunk/compiler/cpp/src/parse/t_const_value.h
Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_const_value.h
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/t_const_value.h?rev=996610&r1=996609&r2=996610&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/t_const_value.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/t_const_value.h Mon Sep 13
17:32:14 2010
@@ -71,10 +71,15 @@ class t_const_value {
if (enum_ == NULL) {
throw "have identifier \"" + get_identifier() + "\", but unset enum on
line!";
}
- t_enum_value* val = enum_->get_constant_by_name(get_identifier());
+ std::string identifier = get_identifier();
+ std::string::size_type dot = identifier.rfind('.');
+ if (dot != std::string::npos) {
+ identifier = identifier.substr(dot+1);
+ }
+ t_enum_value* val = enum_->get_constant_by_name(identifier);
if (val == NULL) {
throw
- "Unable to find enum value \"" + get_identifier() +
+ "Unable to find enum value \"" + identifier +
"\" in enum \"" + enum_->get_name() + "\"";
}
return val->get_value();