summaryrefslogtreecommitdiff
path: root/cpp/src/slice2php/Main.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/slice2php/Main.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/slice2php/Main.cpp')
-rw-r--r--cpp/src/slice2php/Main.cpp267
1 files changed, 137 insertions, 130 deletions
diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp
index 4e05affbaf7..53904232da5 100644
--- a/cpp/src/slice2php/Main.cpp
+++ b/cpp/src/slice2php/Main.cpp
@@ -102,7 +102,7 @@ private:
//
// Write constant value.
//
- void writeConstantValue(const TypePtr&, const string&);
+ void writeConstantValue(const TypePtr&, const SyntaxTreeBasePtr&, const string&);
//
// Write constructor parameters with default values.
@@ -939,8 +939,6 @@ CodeVisitor::visitConst(const ConstPtr& p)
string name = getName(p);
string type = getTypeVar(p);
string abs = getAbsolute(p, _ns);
- string value = p->value();
- Slice::TypePtr valueType = p->type();
startNamespace(p);
@@ -955,7 +953,7 @@ CodeVisitor::visitConst(const ConstPtr& p)
_out << sp << nl << "define('" << name << "', ";
}
- writeConstantValue(valueType, value);
+ writeConstantValue(p->type(), p->valueType(), p->value());
_out << ");";
_out << eb;
@@ -1168,153 +1166,161 @@ CodeVisitor::writeAssign(const MemberInfo& info)
}
void
-CodeVisitor::writeConstantValue(const TypePtr& type, const string& value)
+CodeVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePtr& valueType, const string& value)
{
- Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type);
- Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type);
- if(b)
+ ConstPtr constant = ConstPtr::dynamicCast(valueType);
+ if(constant)
{
- switch(b->kind())
- {
- case Slice::Builtin::KindBool:
- case Slice::Builtin::KindByte:
- case Slice::Builtin::KindShort:
- case Slice::Builtin::KindInt:
- case Slice::Builtin::KindFloat:
- case Slice::Builtin::KindDouble:
- {
- _out << value;
- break;
- }
- case Slice::Builtin::KindLong:
+ _out << getAbsolute(constant, _ns);
+ }
+ else
+ {
+ Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type);
+ Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type);
+ if(b)
{
- IceUtil::Int64 l;
- IceUtilInternal::stringToInt64(value, l);
- //
- // The platform's 'long' type may not be 64 bits, so we store 64-bit
- // values as a string.
- //
- if(sizeof(IceUtil::Int64) > sizeof(long) && (l < LONG_MIN || l > LONG_MAX))
+ switch(b->kind())
{
- _out << "'" << value << "'";
- }
- else
+ case Slice::Builtin::KindBool:
+ case Slice::Builtin::KindByte:
+ case Slice::Builtin::KindShort:
+ case Slice::Builtin::KindInt:
+ case Slice::Builtin::KindFloat:
+ case Slice::Builtin::KindDouble:
{
_out << value;
+ break;
}
- break;
- }
- case Slice::Builtin::KindString:
- {
- //
- // 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());
-
- _out << "\""; // Opening "
-
- for(string::const_iterator c = value.begin(); c != value.end(); ++c)
+ case Slice::Builtin::KindLong:
{
- switch(*c)
- {
- case '$':
+ IceUtil::Int64 l;
+ IceUtilInternal::stringToInt64(value, l);
+ //
+ // The platform's 'long' type may not be 64 bits, so we store 64-bit
+ // values as a string.
+ //
+ if(sizeof(IceUtil::Int64) > sizeof(long) && (l < LONG_MIN || l > LONG_MAX))
{
- _out << "\\$";
- break;
+ _out << "'" << value << "'";
}
- case '"':
- {
- _out << "\\\"";
- break;
- }
- case '\\':
- {
- _out << "\\\\";
- break;
- }
- case '\r':
- {
- _out << "\\r";
- break;
- }
- case '\n':
- {
- _out << "\\n";
- break;
- }
- case '\t':
- {
- _out << "\\t";
- break;
- }
- case '\b':
- {
- _out << "\\b";
- break;
- }
- case '\f':
+ else
{
- _out << "\\f";
- break;
+ _out << value;
}
- default:
+ break;
+ }
+ case Slice::Builtin::KindString:
+ {
+ //
+ // 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());
+
+ _out << "\""; // Opening "
+
+ for(string::const_iterator c = value.begin(); c != value.end(); ++c)
{
- if(charSet.find(*c) == charSet.end())
+ switch(*c)
+ {
+ case '$':
{
- unsigned char uc = *c; // Char may be signed, so make it positive.
- stringstream s;
- s << "\\"; // Print as octal if not in basic source character set.
- s.flags(ios_base::oct);
- s.width(3);
- s.fill('0');
- s << static_cast<unsigned>(uc);
- _out << s.str();
+ _out << "\\$";
+ break;
}
- else
+ case '"':
{
- _out << *c; // Print normally if in basic source character set.
+ _out << "\\\"";
+ break;
+ }
+ case '\\':
+ {
+ _out << "\\\\";
+ break;
+ }
+ case '\r':
+ {
+ _out << "\\r";
+ break;
+ }
+ case '\n':
+ {
+ _out << "\\n";
+ break;
+ }
+ case '\t':
+ {
+ _out << "\\t";
+ break;
+ }
+ case '\b':
+ {
+ _out << "\\b";
+ break;
+ }
+ case '\f':
+ {
+ _out << "\\f";
+ break;
+ }
+ default:
+ {
+ if(charSet.find(*c) == charSet.end())
+ {
+ unsigned char uc = *c; // Char may be signed, so make it positive.
+ stringstream s;
+ s << "\\"; // Print as octal if not in basic source character set.
+ s.flags(ios_base::oct);
+ s.width(3);
+ s.fill('0');
+ s << static_cast<unsigned>(uc);
+ _out << s.str();
+ }
+ else
+ {
+ _out << *c; // Print normally if in basic source character set.
+ }
+ break;
+ }
}
- break;
- }
}
- }
- _out << "\""; // Closing "
- break;
- }
- case Slice::Builtin::KindObject:
- case Slice::Builtin::KindObjectProxy:
- case Slice::Builtin::KindLocalObject:
- assert(false);
- }
- }
- else if(en)
- {
- string val = value;
- string::size_type colon = val.rfind(':');
- if(colon != string::npos)
- {
- val = val.substr(colon + 1);
+ _out << "\""; // Closing "
+ break;
+ }
+ case Slice::Builtin::KindObject:
+ case Slice::Builtin::KindObjectProxy:
+ case Slice::Builtin::KindLocalObject:
+ assert(false);
+ }
}
- Slice::EnumeratorList l = en->getEnumerators();
- Slice::EnumeratorList::iterator q;
- for(q = l.begin(); q != l.end(); ++q)
+ else if(en)
{
- if((*q)->name() == val)
+ string val = value;
+ string::size_type colon = val.rfind(':');
+ if(colon != string::npos)
{
- _out << getAbsolute(en, _ns) << "::" << fixIdent(val);
- break;
+ val = val.substr(colon + 1);
+ }
+ Slice::EnumeratorList l = en->getEnumerators();
+ Slice::EnumeratorList::iterator q;
+ for(q = l.begin(); q != l.end(); ++q)
+ {
+ if((*q)->name() == val)
+ {
+ _out << getAbsolute(en, _ns) << "::" << fixIdent(val);
+ break;
+ }
}
}
- }
- else
- {
- assert(false); // Unknown const type.
+ else
+ {
+ assert(false); // Unknown const type.
+ }
}
}
@@ -1329,13 +1335,14 @@ CodeVisitor::writeConstructorParams(const MemberInfoList& members)
}
_out << '$' << p->fixedName << "=";
- if(p->dataMember->hasDefaultValue())
+ const DataMemberPtr member = p->dataMember;
+ if(member->defaultValueType())
{
- writeConstantValue(p->dataMember->type(), p->dataMember->defaultValue());
+ writeConstantValue(member->type(), member->defaultValueType(), member->defaultValue());
}
else
{
- writeDefaultValue(p->dataMember->type());
+ writeDefaultValue(member->type());
}
}
}