summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Gen.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2010-07-23 16:02:04 -0700
committerMark Spruiell <mes@zeroc.com>2010-07-23 16:02:04 -0700
commit2414545a397baa35e90fbc04c807b2b96ed7cc93 (patch)
tree271b74750e65d3eb64ef39299b14658b420eb6d9 /cpp/src/slice2cpp/Gen.cpp
parentBug-fix for 4793. As well as some refactoring. (diff)
downloadice-2414545a397baa35e90fbc04c807b2b96ed7cc93.tar.bz2
ice-2414545a397baa35e90fbc04c807b2b96ed7cc93.tar.xz
ice-2414545a397baa35e90fbc04c807b2b96ed7cc93.zip
bug 4794 - allow default values to refer to constants
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp107
1 files changed, 60 insertions, 47 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 9442aea8675..a20ab684b07 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -39,63 +39,75 @@ getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
}
static void
-writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const string& value, int useWstring,
- const StringList& metaData)
+writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const SyntaxTreeBasePtr& valueType,
+ const string& value, int useWstring, const StringList& metaData)
{
- BuiltinPtr bp = BuiltinPtr::dynamicCast(type);
- if(bp && bp->kind() == Builtin::KindString)
+ ConstPtr constant = ConstPtr::dynamicCast(valueType);
+ if(constant)
{
- //
- // Expand strings into the basic source character set. We can't use isalpha() and the like
- // here because they are sensitive to the current locale.
- //
- static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789"
- "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' ";
- static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end());
-
- if((useWstring & TypeContextUseWstring) || findMetaData(metaData) == "wstring")
+ out << fixKwd(constant->scoped());
+ }
+ else
+ {
+ BuiltinPtr bp = BuiltinPtr::dynamicCast(type);
+ if(bp && bp->kind() == Builtin::KindString)
{
- out << 'L';
- }
- out << "\""; // Opening "
+ //
+ // Expand strings into the basic source character set. We can't use isalpha() and the like
+ // here because they are sensitive to the current locale.
+ //
+ static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789"
+ "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' ";
+ static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end());
- for(string::const_iterator c = value.begin(); c != value.end(); ++c)
- {
- if(charSet.find(*c) == charSet.end())
+ if((useWstring & TypeContextUseWstring) || findMetaData(metaData) == "wstring")
{
- unsigned char uc = *c; // char may be signed, so make it positive
- ostringstream s;
- s << "\\"; // Print as octal if not in basic source character set
- s.width(3);
- s.fill('0');
- s << oct;
- s << static_cast<unsigned>(uc);
- out << s.str();
+ out << 'L';
}
- else
+ out << "\""; // Opening "
+
+ for(string::const_iterator c = value.begin(); c != value.end(); ++c)
{
- out << *c; // Print normally if in basic source character set
+ if(charSet.find(*c) == charSet.end())
+ {
+ unsigned char uc = *c; // char may be signed, so make it positive
+ ostringstream s;
+ s << "\\"; // Print as octal if not in basic source character set
+ s.width(3);
+ s.fill('0');
+ s << oct;
+ s << static_cast<unsigned>(uc);
+ out << s.str();
+ }
+ else
+ {
+ out << *c; // Print normally if in basic source character set
+ }
}
- }
- out << "\""; // Closing "
- }
- else if(bp && bp->kind() == Builtin::KindLong)
- {
- out << "ICE_INT64(" << value << ")";
- }
- else
- {
- EnumPtr ep = EnumPtr::dynamicCast(type);
- if(ep)
+ out << "\""; // Closing "
+ }
+ else if(bp && bp->kind() == Builtin::KindLong)
{
- out << fixKwd(value);
+ out << "ICE_INT64(" << value << ")";
+ }
+ else if(bp && bp->kind() == Builtin::KindFloat)
+ {
+ out << value << "F";
}
else
{
- out << value;
+ EnumPtr ep = EnumPtr::dynamicCast(type);
+ if(ep)
+ {
+ out << fixKwd(value);
+ }
+ else
+ {
+ out << value;
+ }
}
}
}
@@ -106,7 +118,7 @@ writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& me
bool first = true;
for(DataMemberList::const_iterator p = members.begin(); p != members.end(); ++p)
{
- if((*p)->hasDefaultValue())
+ if((*p)->defaultValueType())
{
string memberName = fixKwd((*p)->name());
@@ -119,7 +131,8 @@ writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& me
C << ',';
}
C << nl << memberName << '(';
- writeConstantValue(C, (*p)->type(), (*p)->defaultValue(), useWstring, (*p)->getMetaData());
+ writeConstantValue(C, (*p)->type(), (*p)->defaultValueType(), (*p)->defaultValue(), useWstring,
+ (*p)->getMetaData());
C << ')';
}
}
@@ -1842,7 +1855,7 @@ Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p)
H << sp;
H << nl << "const " << typeToString(p->type(), p->typeMetaData(), _useWstring) << " " << fixKwd(p->name())
<< " = ";
- writeConstantValue(H, p->type(), p->value(), _useWstring, p->typeMetaData());
+ writeConstantValue(H, p->type(), p->valueType(), p->value(), _useWstring, p->typeMetaData());
H << ';';
}