summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp18
-rw-r--r--cpp/src/Slice/JavaUtil.cpp2
-rw-r--r--cpp/src/Slice/PythonUtil.cpp33
-rw-r--r--cpp/src/Slice/RubyUtil.cpp5
-rw-r--r--cpp/src/slice2cpp/Gen.cpp62
5 files changed, 70 insertions, 50 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 5624801b8e5..03e1a85bc18 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -329,7 +329,7 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList&
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
if(cl)
{
- return "const " + fixKwd(cl->scoped()) + "Ptr&";
+ return "const " + fixKwd(cl->scoped() + "Ptr&");
}
StructPtr st = StructPtr::dynamicCast(type);
@@ -337,7 +337,7 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList&
{
if(findMetaData(st->getMetaData(), false) == "class")
{
- return "const " + fixKwd(st->scoped()) + "Ptr&";
+ return "const " + fixKwd(st->scoped() + "Ptr&");
}
return "const " + fixKwd(st->scoped()) + "&";
}
@@ -345,7 +345,7 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList&
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
- return "const " + fixKwd(proxy->_class()->scoped()) + "Prx&";
+ return "const " + fixKwd(proxy->_class()->scoped() + "Prx&");
}
EnumPtr en = EnumPtr::dynamicCast(type);
@@ -445,7 +445,7 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
if(cl)
{
- return fixKwd(cl->scoped()) + "Ptr&";
+ return fixKwd(cl->scoped() + "Ptr&");
}
StructPtr st = StructPtr::dynamicCast(type);
@@ -453,7 +453,7 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList
{
if(findMetaData(st->getMetaData(), false) == "class")
{
- return fixKwd(st->scoped()) + "Ptr&";
+ return fixKwd(st->scoped() + "Ptr&");
}
return fixKwd(st->scoped()) + "&";
}
@@ -461,7 +461,7 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
- return fixKwd(proxy->_class()->scoped()) + "Prx&";
+ return fixKwd(proxy->_class()->scoped() + "Prx&");
}
SequencePtr seq = SequencePtr::dynamicCast(type);
@@ -526,6 +526,12 @@ lookupKwd(const string& name)
//
// Keyword list. *Must* be kept in alphabetical order.
//
+ // Note that this keyword list unnecessarily contains C++ keywords
+ // that are illegal slice identifiers -- namely identifiers that
+ // contain underscores (and_eq, for example), and slice keywords
+ // (class, int, etc.). They have not been removed so that the
+ // keyword list is kept complete.
+ //
static const string keywordList[] =
{
"and", "and_eq", "asm", "auto", "bit_and", "bit_or", "bool", "break", "case", "catch", "char",
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 4ad55ef7432..8f27fb78708 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -216,7 +216,7 @@ lookupKwd(const string& name)
// NOTE: Any changes made to this list must also be made in BasicStream.java.
//
static const string keywordList[] =
- {
+ {
"abstract", "assert", "boolean", "break", "byte", "case", "catch",
"char", "checkedCast", "class", "clone", "const", "continue", "default", "do",
"double", "else", "enum", "equals", "extends", "false", "final", "finalize",
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index 0261e7aa516..fdc6449285d 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -107,7 +107,7 @@ private:
//
// Return a Python symbol for the given parser element.
//
- string getSymbol(const ContainedPtr&);
+ string getSymbol(const ContainedPtr&, const string& = string());
//
// Emit Python code to assign the given symbol in the current module.
@@ -367,7 +367,7 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p)
_out << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')";
if(!p->isLocal())
{
- _out << nl << "_M_" << type << "Prx = IcePy.declareProxy('" << scoped << "')";
+ _out << nl << "_M_" << getAbsolute(p, "_t_", "Prx") << " = IcePy.declareProxy('" << scoped << "')";
}
_out.dec();
_classHistory.insert(scoped); // Avoid redundant declarations.
@@ -381,6 +381,9 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
string type = getAbsolute(p, "_t_");
string abs = getAbsolute(p);
string name = fixIdent(p->name());
+ string prxAbs = getAbsolute(p, "", "Prx");
+ string prxName = fixIdent(p->name() + "Prx");
+ string prxType = getAbsolute(p, "_t_", "Prx");
ClassList bases = p->bases();
ClassDefPtr base;
OperationList ops = p->operations();
@@ -590,8 +593,8 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
//
if(!p->isLocal())
{
- _out << sp << nl << "_M_" << abs << "Prx = Ice.createTempClass()";
- _out << nl << "class " << name << "Prx(";
+ _out << sp << nl << "_M_" << prxAbs << " = Ice.createTempClass()";
+ _out << nl << "class " << prxName << "(";
if(bases.empty())
{
_out << "Ice.ObjectPrx";
@@ -601,7 +604,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
ClassList::const_iterator q = bases.begin();
while(q != bases.end())
{
- _out << getSymbol(*q) << "Prx";
+ _out << getSymbol(*q, "Prx");
if(++q != bases.end())
{
_out << ", ";
@@ -671,19 +674,19 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
_out << sp << nl << "def checkedCast(proxy, facetOrCtx=None, _ctx=None):";
_out.inc();
- _out << nl << "return _M_" << abs << "Prx.ice_checkedCast(proxy, '" << scoped << "', facetOrCtx, _ctx)";
+ _out << nl << "return _M_" << prxAbs << ".ice_checkedCast(proxy, '" << scoped << "', facetOrCtx, _ctx)";
_out.dec();
_out << nl << "checkedCast = staticmethod(checkedCast)";
_out << sp << nl << "def uncheckedCast(proxy, facet=None):";
_out.inc();
- _out << nl << "return _M_" << abs << "Prx.ice_uncheckedCast(proxy, facet)";
+ _out << nl << "return _M_" << prxAbs << ".ice_uncheckedCast(proxy, facet)";
_out.dec();
_out << nl << "uncheckedCast = staticmethod(uncheckedCast)";
_out.dec();
- _out << sp << nl << "_M_" << type << "Prx = IcePy.defineProxy('" << scoped << "', " << name << "Prx)";
+ _out << sp << nl << "_M_" << prxType << " = IcePy.defineProxy('" << scoped << "', " << prxName << ")";
}
if(_classHistory.count(scoped) == 0 && p->canBeCyclic())
@@ -882,7 +885,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
if(!p->isLocal())
{
- registerName(name + "Prx");
+ registerName(prxName);
}
_out.dec();
@@ -1455,12 +1458,12 @@ Slice::Python::CodeVisitor::visitConst(const ConstPtr& p)
}
string
-Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p)
+Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p, const string& nameSuffix)
{
//
// An explicit reference to another type must always be prefixed with "_M_".
//
- return "_M_" + getAbsolute(p);
+ return "_M_" + getAbsolute(p, "", nameSuffix);
}
void
@@ -1541,7 +1544,7 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p)
ProxyPtr prx = ProxyPtr::dynamicCast(p);
if(prx)
{
- _out << "_M_" << getAbsolute(prx->_class(), "_t_") << "Prx";
+ _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx");
return;
}
@@ -1951,7 +1954,7 @@ Slice::Python::getPackageMetadata(const ContainedPtr& cont)
}
string
-Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix)
+Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix, const string& nameSuffix)
{
string scope = scopedToName(cont->scope());
@@ -1970,11 +1973,11 @@ Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix)
if(suffix.empty())
{
- return scope + fixIdent(cont->name());
+ return scope + fixIdent(cont->name() + nameSuffix);
}
else
{
- return scope + suffix + fixIdent(cont->name());
+ return scope + suffix + fixIdent(cont->name() + nameSuffix);
}
}
diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp
index bd995ce21aa..07bdebd46d6 100644
--- a/cpp/src/Slice/RubyUtil.cpp
+++ b/cpp/src/Slice/RubyUtil.cpp
@@ -1738,6 +1738,11 @@ Slice::Ruby::fixIdent(const string& ident, IdentStyle style)
case IdentNormal:
break;
case IdentToUpper:
+ // Special case BEGIN & END for class/module names.
+ if(id == "BEGIN" || id == "END")
+ {
+ return id + "_";
+ }
if(id[0] >= 'a' && id[0] <= 'z')
{
id[0] += 'A' - 'a';
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 986d5269f77..0d70727d44f 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -450,9 +450,7 @@ Slice::Gen::TypesVisitor::visitModuleStart(const ModulePtr& p)
_useWstring = setUseWstring(p, _useWstringHist, _useWstring);
- string name = fixKwd(p->name());
-
- H << sp << nl << "namespace " << name << nl << '{';
+ H << sp << nl << "namespace " << fixKwd(p->name()) << nl << '{';
return true;
}
@@ -498,7 +496,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
{
string typeName = inputTypeToString((*q)->type(), _useWstring, (*q)->getMetaData());
allTypes.push_back(typeName);
- allParamDecls.push_back(typeName + " __ice_" + (*q)->name());
+ allParamDecls.push_back(typeName + " __ice_" + fixKwd((*q)->name()));
}
if(base)
@@ -506,7 +504,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
DataMemberList baseDataMembers = base->allDataMembers();
for(q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q)
{
- baseParams.push_back("__ice_" + (*q)->name());
+ baseParams.push_back("__ice_" + fixKwd((*q)->name()));
}
}
@@ -891,7 +889,8 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p)
}
H << name << spar << types << epar << ';';
- C << sp << nl << p->scoped().substr(2) << "::" << fixKwd(p->name()) << spar << paramDecls << epar << " :";
+ C << sp << nl << fixKwd(p->scoped()).substr(2) << "::"
+ << fixKwd(p->name()) << spar << paramDecls << epar << " :";
C.inc();
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
@@ -1053,23 +1052,23 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
H << eb << ';';
if(findMetaData(p->getMetaData(), false) == "class")
{
- H << sp << nl << "typedef ::IceUtil::Handle< " << scoped << "> " << name << "Ptr;";
+ H << sp << nl << "typedef ::IceUtil::Handle< " << scoped << "> " << p->name() + "Ptr;";
if(!p->isLocal() && _stream)
{
H << sp << nl << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const "
- << name << "Ptr&);";
- H << nl << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name
+ << p->name() << "Ptr&);";
+ H << nl << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << p->name()
<< "Ptr&);";
C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "Ptr& __v)";
+ << "(const ::Ice::OutputStreamPtr& __outS, const " << fixKwd(p->scoped() + "Ptr") << "& __v)";
C << sb;
C << nl << "__v->ice_write(__outS);";
C << eb;
C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << scoped << "Ptr& __v)";
+ << "(const ::Ice::InputStreamPtr& __inS, " << fixKwd(p->scoped() + "Ptr") << "& __v)";
C << sb;
C << nl << "__v->ice_read(__inS);";
C << eb;
@@ -1882,7 +1881,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
}
H << fixKwd(name) << spar << args << "0" << epar << ';';
H << eb;
- H << nl << deprecateSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << "const ::Ice::Context& __ctx" << epar;
+ H << nl << deprecateSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << "const ::Ice::Context& __ctx"
+ << epar;
H << sb;
H << nl;
if(ret)
@@ -1896,7 +1896,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
H.dec();
H << nl << "private:";
H.inc();
- H << sp << nl << _dllExport << retS << ' ' << fixKwd(name) << spar << params << "const ::Ice::Context*" << epar << ';';
+ H << sp << nl << _dllExport << retS << ' ' << fixKwd(name) << spar << params << "const ::Ice::Context*" << epar
+ << ';';
H << nl;
H.dec();
H << nl << "public:";
@@ -1952,19 +1953,22 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
string classScope = fixKwd(cl->scope());
string classScopedAMI = classScope + classNameAMI;
- H << nl << _dllExport << "void " << name << "_async" << spar << ("const " + classScopedAMI + '_' + name + "Ptr&")
+ H << nl << _dllExport << "void " << name << "_async" << spar
+ << ("const " + classScopedAMI + '_' + p->name() + "Ptr&")
<< paramsAMI << epar << ';';
- H << nl << _dllExport << "void " << name << "_async" << spar << ("const " + classScopedAMI + '_' + name + "Ptr&")
+ H << nl << _dllExport << "void " << name << "_async" << spar
+ << ("const " + classScopedAMI + '_' + p->name() + "Ptr&")
<< paramsAMI << "const ::Ice::Context&" << epar << ';';
C << sp << nl << "void" << nl << "IceProxy" << scope << name << "_async" << spar
- << ("const " + classScopedAMI + '_' + name + "Ptr& __cb") << paramsDeclAMI << epar;
+ << ("const " + classScopedAMI + '_' + p->name() + "Ptr& __cb") << paramsDeclAMI << epar;
C << sb;
C << nl << "__cb->__invoke" << spar << "this" << argsAMI << "0" << epar << ';';
C << eb;
C << sp << nl << "void" << nl << "IceProxy" << scope << name << "_async" << spar
- << ("const " + classScopedAMI + '_' + name + "Ptr& __cb") << paramsDeclAMI << "const ::Ice::Context& __ctx"
+ << ("const " + classScopedAMI + '_' + p->name() + "Ptr& __cb")
+ << paramsDeclAMI << "const ::Ice::Context& __ctx"
<< epar;
C << sb;
C << nl << "__cb->__invoke" << spar << "this" << argsAMI << "&__ctx" << epar << ';';
@@ -2809,9 +2813,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
if(!p->isLocal())
{
- H << nl << "typedef " << name << "Prx ProxyType;";
+ H << nl << "typedef " << p->name() << "Prx ProxyType;";
}
- H << nl << "typedef " << name << "Ptr PointerType;";
+ H << nl << "typedef " << p->name() << "Ptr PointerType;";
H << nl;
vector<string> params;
@@ -2969,11 +2973,11 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << sp;
C << nl << "::Ice::ObjectPtr";
- C << nl << fixKwd(p->scoped()).substr(2) << "::ice_clone() const";
+ C << nl << scoped.substr(2) << "::ice_clone() const";
C << sb;
if(!p->isAbstract())
{
- C << nl << fixKwd(p->scope()) << p->name() << "Ptr __p = new " << fixKwd(p->scoped()) << "(*this);";
+ C << nl << fixKwd(p->scope()) << p->name() << "Ptr __p = new " << scoped << "(*this);";
C << nl << "return __p;";
}
else
@@ -3036,14 +3040,14 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << eb << ';';
C << sp;
- C << nl << "bool" << nl << fixKwd(p->scoped()).substr(2)
+ C << nl << "bool" << nl << scoped.substr(2)
<< "::ice_isA(const ::std::string& _s, const ::Ice::Current&) const";
C << sb;
C << nl << "return ::std::binary_search(" << flatName << ", " << flatName << " + " << ids.size() << ", _s);";
C << eb;
C << sp;
- C << nl << "::std::vector< ::std::string>" << nl << fixKwd(p->scoped()).substr(2)
+ C << nl << "::std::vector< ::std::string>" << nl << scoped.substr(2)
<< "::ice_ids(const ::Ice::Current&) const";
C << sb;
C << nl << "return ::std::vector< ::std::string>(&" << flatName << "[0], &" << flatName
@@ -3051,14 +3055,14 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << eb;
C << sp;
- C << nl << "const ::std::string&" << nl << fixKwd(p->scoped()).substr(2)
+ C << nl << "const ::std::string&" << nl << scoped.substr(2)
<< "::ice_id(const ::Ice::Current&) const";
C << sb;
C << nl << "return " << flatName << '[' << scopedPos << "];";
C << eb;
C << sp;
- C << nl << "const ::std::string&" << nl << fixKwd(p->scoped()).substr(2) << "::ice_staticId()";
+ C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_staticId()";
C << sb;
C << nl << "return " << flatName << '[' << scopedPos << "];";
C << eb;
@@ -3135,7 +3139,8 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
<< ", current.operation);";
C << nl << "if(r.first == r.second)";
C << sb;
- C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);";
+ C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, "
+ << "current.facet, current.operation);";
C << eb;
C << sp;
C << nl << "switch(r.first - " << flatName << ')';
@@ -3151,7 +3156,8 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
C << eb;
C << sp;
C << nl << "assert(false);";
- C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);";
+ C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, "
+ << "current.facet, current.operation);";
C << eb;
@@ -4284,7 +4290,7 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p)
C << sp;
C << nl << "void" << nl << scope.substr(2) << "ice_read" << name << "(const ::Ice::InputStreamPtr& __inS, "
- << scoped << "Ptr& __v)";
+ << scope << name << "Ptr& __v)";
C << sb;
C << nl << "::Ice::ReadObjectCallbackPtr __cb = new ::Ice::ReadObjectCallbackI(" << scope << "__patch__"
<< name << "Ptr, &__v);";