summaryrefslogtreecommitdiff
path: root/cpp/src/slice2php
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-08-08 21:45:20 +0200
committerJose <jose@zeroc.com>2018-08-08 21:45:20 +0200
commitbf855e9af3fa31da72d4d36ffb270f93cf85dacf (patch)
treef2365cbf05eb7b0d7b367095fe826f33eaa2e120 /cpp/src/slice2php
parentRuby test suite updates (diff)
downloadice-bf855e9af3fa31da72d4d36ffb270f93cf85dacf.tar.bz2
ice-bf855e9af3fa31da72d4d36ffb270f93cf85dacf.tar.xz
ice-bf855e9af3fa31da72d4d36ffb270f93cf85dacf.zip
PHP generate code cannot be required from a class method or function
Close #105
Diffstat (limited to 'cpp/src/slice2php')
-rw-r--r--cpp/src/slice2php/Main.cpp140
1 files changed, 110 insertions, 30 deletions
diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp
index 1905fc40372..4c6c4eebbaf 100644
--- a/cpp/src/slice2php/Main.cpp
+++ b/cpp/src/slice2php/Main.cpp
@@ -94,6 +94,7 @@ private:
// Emit the array for a Slice type.
//
void writeType(const TypePtr&);
+ string getType(const TypePtr&);
//
// Write a default value for a given type.
@@ -426,11 +427,37 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
}
}
+ {
+ string type;
+ vector<string> seenType;
+ _out << sp << nl << "global ";
+ if(!base || (isInterface && !p->isLocal()))
+ {
+ type = "$Ice__t_Value";
+ }
+ else
+ {
+ type = getTypeVar(base);
+ }
+ _out << type << ";";
+ seenType.push_back(type);
+
+ for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q)
+ {
+ string type = getType((*q)->type());
+ if(find(seenType.begin(), seenType.end(), type) == seenType.end())
+ {
+ seenType.push_back(type);
+ _out << nl << "global " << type << ";";
+ }
+ }
+ }
+
//
// Emit the type information.
//
const bool preserved = p->hasMetaData("preserve-slice") || p->inheritsMetaData("preserve-slice");
- _out << sp << nl << type << " = IcePHP_defineClass('" << scoped << "', '" << escapeName(abs) << "', "
+ _out << nl << type << " = IcePHP_defineClass('" << scoped << "', '" << escapeName(abs) << "', "
<< p->compactId() << ", " << (preserved ? "true" : "false") << ", "
<< (isInterface ? "true" : "false") << ", ";
if(!base || (isInterface && !p->isLocal()))
@@ -477,7 +504,17 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
if(!p->isLocal() && isAbstract)
{
- _out << sp << nl << prxType << " = IcePHP_defineProxy('" << scoped << "', ";
+ _out << sp << nl << "global ";
+ if(!base || base->allOperations().empty())
+ {
+ _out << "$Ice__t_ObjectPrx";
+ }
+ else
+ {
+ _out << getTypeVar(base, "Prx");
+ }
+ _out << ";";
+ _out << nl << prxType << " = IcePHP_defineProxy('" << scoped << "', ";
if(!base || base->allOperations().empty())
{
_out << "$Ice__t_ObjectPrx";
@@ -520,6 +557,31 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
if(!ops.empty())
{
_out << sp;
+ vector<string> seenTypes;
+ for(OperationList::const_iterator p = ops.begin(); p != ops.end(); ++p)
+ {
+ ParamDeclList params = (*p)->parameters();
+ for(ParamDeclList::const_iterator q = params.begin(); q != params.end(); ++q)
+ {
+ string type = getType((*q)->type());
+ if(find(seenTypes.begin(), seenTypes.end(), type) == seenTypes.end())
+ {
+ seenTypes.push_back(type);
+ _out << nl << "global " << type << ";";
+ }
+ }
+
+ if((*p)->returnType())
+ {
+ string type = getType((*p)->returnType());
+ if(find(seenTypes.begin(), seenTypes.end(), type) == seenTypes.end())
+ {
+ seenTypes.push_back(type);
+ _out << nl << "global " << type << ";";
+ }
+ }
+ }
+
for(OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli)
{
ParamDeclList params = (*oli)->parameters();
@@ -750,6 +812,17 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
_out << eb;
+ vector<string> seenType;
+ for(DataMemberList::iterator dmli = members.begin(); dmli != members.end(); ++dmli)
+ {
+ string type = getType((*dmli)->type());
+ if(find(seenType.begin(), seenType.end(), type) == seenType.end())
+ {
+ seenType.push_back(type);
+ _out << nl << "global " << type << ";";
+ }
+ }
+
//
// Emit the type information.
//
@@ -867,10 +940,21 @@ CodeVisitor::visitStructStart(const StructPtr& p)
_out << eb;
+ _out << sp;
+ vector<string> seenType;
+ for(MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r)
+ {
+ string type = getType(r->dataMember->type());
+ if(find(seenType.begin(), seenType.end(), type) == seenType.end())
+ {
+ seenType.push_back(type);
+ _out << nl << "global " << type << ";";
+ }
+ }
//
// Emit the type information.
//
- _out << sp << nl << type << " = IcePHP_defineStruct('" << scoped << "', '" << escapeName(abs) << "', array(";
+ _out << nl << type << " = IcePHP_defineStruct('" << scoped << "', '" << escapeName(abs) << "', array(";
//
// Data members are represented as an array:
//
@@ -921,6 +1005,7 @@ CodeVisitor::visitSequence(const SequencePtr& p)
_out << sp << nl << "global " << type << ';';
_out << sp << nl << "if(!isset(" << type << "))";
_out << sb;
+ _out << nl << "global " << getType(content) << ";";
_out << nl << type << " = IcePHP_defineSequence('" << scoped << "', ";
writeType(content);
_out << ");";
@@ -993,6 +1078,8 @@ CodeVisitor::visitDictionary(const DictionaryPtr& p)
_out << sp << nl << "global " << type << ';';
_out << sp << nl << "if(!isset(" << type << "))";
_out << sb;
+ _out << nl << "global " << getType(p->keyType()) << ";";
+ _out << nl << "global " << getType(p->valueType()) << ";";
_out << nl << type << " = IcePHP_defineDictionary('" << scoped << "', ";
writeType(p->keyType());
_out << ", ";
@@ -1137,6 +1224,12 @@ CodeVisitor::getName(const ContainedPtr& p, const string& suffix)
void
CodeVisitor::writeType(const TypePtr& p)
{
+ _out << getType(p);
+}
+
+string
+CodeVisitor::getType(const TypePtr& p)
+{
BuiltinPtr builtin = BuiltinPtr::dynamicCast(p);
if(builtin)
{
@@ -1144,62 +1237,50 @@ CodeVisitor::writeType(const TypePtr& p)
{
case Builtin::KindBool:
{
- _out << "$IcePHP__t_bool";
- break;
+ return "$IcePHP__t_bool";
}
case Builtin::KindByte:
{
- _out << "$IcePHP__t_byte";
- break;
+ return "$IcePHP__t_byte";
}
case Builtin::KindShort:
{
- _out << "$IcePHP__t_short";
- break;
+ return "$IcePHP__t_short";
}
case Builtin::KindInt:
{
- _out << "$IcePHP__t_int";
- break;
+ return "$IcePHP__t_int";
}
case Builtin::KindLong:
{
- _out << "$IcePHP__t_long";
- break;
+ return "$IcePHP__t_long";
}
case Builtin::KindFloat:
{
- _out << "$IcePHP__t_float";
- break;
+ return "$IcePHP__t_float";
}
case Builtin::KindDouble:
{
- _out << "$IcePHP__t_double";
- break;
+ return "$IcePHP__t_double";
}
case Builtin::KindString:
{
- _out << "$IcePHP__t_string";
- break;
+ return "$IcePHP__t_string";
}
case Builtin::KindObject:
case Builtin::KindValue:
{
- _out << "$Ice__t_Value";
- break;
+ return "$Ice__t_Value";
}
case Builtin::KindObjectProxy:
{
- _out << "$Ice__t_ObjectPrx";
- break;
+ return "$Ice__t_ObjectPrx";
}
case Builtin::KindLocalObject:
{
- _out << "$Ice__t_LocalObject";
- break;
+ return "$Ice__t_LocalObject";
}
}
- return;
}
ProxyPtr prx = ProxyPtr::dynamicCast(p);
@@ -1208,18 +1289,17 @@ CodeVisitor::writeType(const TypePtr& p)
ClassDefPtr def = prx->_class()->definition();
if(def->isInterface() || def->allOperations().size() > 0)
{
- _out << getTypeVar(prx->_class(), "Prx");
+ return getTypeVar(prx->_class(), "Prx");
}
else
{
- _out << "$Ice__t_ObjectPrx";
+ return "$Ice__t_ObjectPrx";
}
- return;
}
ContainedPtr cont = ContainedPtr::dynamicCast(p);
assert(cont);
- _out << getTypeVar(cont);
+ return getTypeVar(cont);
}
void