summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/CPlusPlusUtil.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2015-02-20 13:10:58 -0330
committerDwayne Boone <dwayne@zeroc.com>2015-02-20 13:10:58 -0330
commitc3c9c00ed22af11f8b99c750fdb958b42821753a (patch)
tree687b002fac3a3c0374230e664d215ea0cf55d64e /cpp/src/Slice/CPlusPlusUtil.cpp
parentRemove python/ruby dev dependency from Ubuntu packages (diff)
downloadice-c3c9c00ed22af11f8b99c750fdb958b42821753a.tar.bz2
ice-c3c9c00ed22af11f8b99c750fdb958b42821753a.tar.xz
ice-c3c9c00ed22af11f8b99c750fdb958b42821753a.zip
ICE-5814 change C++ generated code to prevent shadow warnigns
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp105
1 files changed, 54 insertions, 51 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 7389ae8463f..e04291a02ee 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -65,7 +65,7 @@ stringTypeToString(const TypePtr& type, const StringList& metaData, int typeCtx)
{
return "::std::string";
}
-}
+}
string
sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typeCtx)
@@ -83,8 +83,8 @@ sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typ
string s = typeToString(seq->type());
return "::std::pair<const " + s + "*, const " + s + "*>";
}
- else if(builtin &&
- builtin->kind() != Builtin::KindString &&
+ else if(builtin &&
+ builtin->kind() != Builtin::KindString &&
builtin->kind() != Builtin::KindObject &&
builtin->kind() != Builtin::KindObjectProxy)
{
@@ -94,7 +94,7 @@ sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typ
}
else
{
- string s = toTemplateArg(typeToString(seq->type(), seq->typeMetaData(),
+ string s = toTemplateArg(typeToString(seq->type(), seq->typeMetaData(),
inWstringModule(seq) ? TypeContextUseWstring : 0));
return "::std::vector<" + s + '>';
}
@@ -166,7 +166,7 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st
}
//
- // If using a range or array we need to allocate the range container, or
+ // If using a range or array we need to allocate the range container, or
// array as well now to ensure they are always in the same scope.
//
SequencePtr seq = SequencePtr::dynamicCast(type);
@@ -177,7 +177,7 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st
{
seqType = findMetaData(seq->getMetaData(), typeCtx);
}
-
+
string s;
if(seqType == "%array")
{
@@ -192,7 +192,7 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st
}
s = typeToString(seq, md);
}
-
+
if(!s.empty())
{
if(optional)
@@ -215,11 +215,11 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string&
{
seqType = findMetaData(seq->getMetaData(), TypeContextInParam);
}
-
+
if(seqType == "%array")
{
BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
- if(builtin &&
+ if(builtin &&
builtin->kind() != Builtin::KindByte &&
builtin->kind() != Builtin::KindString &&
builtin->kind() != Builtin::KindObject &&
@@ -237,8 +237,8 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string&
out << nl << fixedName << " = ___" << fixedName << ".second;";
}
}
- else if(!builtin ||
- builtin->kind() == Builtin::KindString ||
+ else if(!builtin ||
+ builtin->kind() == Builtin::KindString ||
builtin->kind() == Builtin::KindObject ||
builtin->kind() == Builtin::KindObjectProxy)
{
@@ -250,7 +250,7 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string&
out << nl << "if(!___" << fixedName << "->empty())";
out << sb;
out << nl << fixedName << "->first" << " = &(*___" << fixedName << ")[0];";
- out << nl << fixedName << "->second" << " = " << fixedName << "->first + " << "___"
+ out << nl << fixedName << "->second" << " = " << fixedName << "->first + " << "___"
<< fixedName << "->size();";
out << eb;
out << nl << "else";
@@ -264,7 +264,7 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string&
out << nl << "if(!___" << fixedName << ".empty())";
out << sb;
out << nl << fixedName << ".first" << " = &___" << fixedName << "[0];";
- out << nl << fixedName << ".second" << " = " << fixedName << ".first + " << "___"
+ out << nl << fixedName << ".second" << " = " << fixedName << ".first + " << "___"
<< fixedName << ".size();";
out << eb;
out << nl << "else";
@@ -295,8 +295,10 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string&
}
void
-writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const OperationPtr& op, bool marshal, int typeCtx)
+writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const OperationPtr& op, bool marshal, bool prepend, int typeCtx)
{
+ string prefix = prepend ? "__p_" : "";
+
//
// Marshal non optional parameters.
//
@@ -309,7 +311,7 @@ writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const Oper
}
else
{
- writeMarshalUnmarshalCode(out, (*p)->type(), false, 0, fixKwd((*p)->name()), marshal, (*p)->getMetaData(),
+ writeMarshalUnmarshalCode(out, (*p)->type(), false, 0, fixKwd(prefix + (*p)->name()), marshal, (*p)->getMetaData(),
typeCtx);
}
}
@@ -342,16 +344,16 @@ writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const Oper
{
if(checkReturnType && op->returnTag() < (*p)->tag())
{
- writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), "__ret", marshal,
+ writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), "__ret", marshal,
op->getMetaData(), typeCtx);
checkReturnType = false;
}
- writeMarshalUnmarshalCode(out, (*p)->type(), true, (*p)->tag(), fixKwd((*p)->name()), marshal,
+ writeMarshalUnmarshalCode(out, (*p)->type(), true, (*p)->tag(), fixKwd(prefix + (*p)->name()), marshal,
(*p)->getMetaData(), typeCtx);
}
if(checkReturnType)
{
- writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), "__ret", marshal, op->getMetaData(),
+ writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), "__ret", marshal, op->getMetaData(),
typeCtx);
}
}
@@ -414,14 +416,14 @@ Slice::printVersionCheck(Output& out)
out << "\n# if ICE_INT_VERSION / 100 != " << ICE_INT_VERSION / 100;
out << "\n# error Ice version mismatch!";
out << "\n# endif";
-
+
//
// Generated code is release; reject beta header
//
out << "\n# if ICE_INT_VERSION % 100 > 50";
out << "\n# error Beta header file detected";
out << "\n# endif";
-
+
out << "\n# if ICE_INT_VERSION % 100 < " << ICE_INT_VERSION % 100;
out << "\n# error Ice patch level mismatch!";
out << "\n# endif";
@@ -492,7 +494,7 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
}
return fixKwd(st->scoped());
}
-
+
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
@@ -504,7 +506,7 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
{
return sequenceTypeToString(seq, metaData, typeCtx);
}
-
+
DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
if(dict)
{
@@ -522,7 +524,7 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
{
return fixKwd(en->scoped());
}
-
+
return "???";
}
@@ -608,13 +610,13 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
}
return "const " + fixKwd(st->scoped()) + "&";
}
-
+
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
return "const " + fixKwd(proxy->_class()->scoped() + "Prx&");
}
-
+
EnumPtr en = EnumPtr::dynamicCast(type);
if(en)
{
@@ -632,7 +634,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
{
return "const " + dictionaryTypeToString(dict, metaData, typeCtx) + "&";
}
-
+
ContainedPtr contained = ContainedPtr::dynamicCast(type);
if(contained)
{
@@ -664,7 +666,7 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
{
return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) +">&";
}
-
+
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
if(builtin)
{
@@ -693,13 +695,13 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
}
return fixKwd(st->scoped()) + "&";
}
-
+
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
return fixKwd(proxy->_class()->scoped() + "Prx&");
}
-
+
SequencePtr seq = SequencePtr::dynamicCast(type);
if(seq)
{
@@ -730,7 +732,7 @@ Slice::operationModeToString(Operation::Mode mode)
{
return "::Ice::Normal";
}
-
+
case Operation::Nonmutating:
{
return "::Ice::Nonmutating";
@@ -746,8 +748,8 @@ Slice::operationModeToString(Operation::Mode mode)
assert(false);
}
}
-
- return "???";
+
+ return "???";
}
string
@@ -785,8 +787,8 @@ lookupKwd(const string& name)
// are Slice keywords (class, int, etc.). They have not been removed
// so that the keyword list is kept complete.
//
- static const string keywordList[] =
- {
+ static const string keywordList[] =
+ {
"and", "and_eq", "asm", "auto", "bit_and", "bit_or", "bool", "break", "case", "catch", "char",
"class", "compl", "const", "const_cast", "continue", "default", "delete", "do", "double",
"dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for",
@@ -862,7 +864,7 @@ Slice::fixKwd(const string& name)
}
void
-Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional, int tag, const string& param,
+Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional, int tag, const string& param,
bool marshal, const StringList& metaData, int typeCtx, const string& str, bool pointer)
{
ostringstream os;
@@ -874,7 +876,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional
{
os << str;
}
-
+
string deref;
if(pointer)
{
@@ -932,28 +934,29 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional
}
void
-Slice::writeMarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, int typeCtx)
+Slice::writeMarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx)
{
- writeMarshalUnmarshalParams(out, params, op, true, typeCtx);
+ writeMarshalUnmarshalParams(out, params, op, true, prepend, typeCtx);
}
void
-Slice::writeUnmarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, int typeCtx)
+Slice::writeUnmarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx)
{
- writeMarshalUnmarshalParams(out, params, op, false, typeCtx);
+ writeMarshalUnmarshalParams(out, params, op, false, prepend, typeCtx);
}
void
-Slice::writeAllocateCode(Output& out, const ParamDeclList& params, const OperationPtr& op, int typeCtx)
+Slice::writeAllocateCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx)
{
+ string prefix = prepend ? "__p_" : "";
for(ParamDeclList::const_iterator p = params.begin(); p != params.end(); ++p)
{
- writeParamAllocateCode(out, (*p)->type(), (*p)->optional(), fixKwd((*p)->name()), (*p)->getMetaData(), typeCtx,
- getEndArg((*p)->type(),(*p)->getMetaData(), (*p)->name()) != (*p)->name());
+ writeParamAllocateCode(out, (*p)->type(), (*p)->optional(), fixKwd(prefix + (*p)->name()), (*p)->getMetaData(),
+ typeCtx, getEndArg((*p)->type(),(*p)->getMetaData(), (*p)->name()) != (*p)->name());
}
if(op && op->returnType())
- {
- writeParamAllocateCode(out, op->returnType(), op->returnIsOptional(), "__ret", op->getMetaData(), typeCtx,
+ {
+ writeParamAllocateCode(out, op->returnType(), op->returnIsOptional(), "__ret", op->getMetaData(), typeCtx,
getEndArg(op->returnType(), op->getMetaData(), "__ret") != "__ret");
}
}
@@ -970,11 +973,11 @@ Slice::getEndArg(const TypePtr& type, const StringList& metaData, const string&
{
seqType = findMetaData(seq->getMetaData(), TypeContextInParam);
}
-
+
if(seqType == "%array")
{
BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
- if(builtin &&
+ if(builtin &&
builtin->kind() != Builtin::KindByte &&
builtin->kind() != Builtin::KindString &&
builtin->kind() != Builtin::KindObject &&
@@ -1037,15 +1040,15 @@ Slice::findMetaData(const StringList& metaData, int typeCtx)
// 1: protobuf
// 2: array, range, view-type for "view" parameters
// 3: class
-
+
if(pos != string::npos)
{
string ss = str.substr(prefix.size());
-
+
if(ss.find("protobuf:") == 0)
{
return str.substr(pos + 1);
- }
+ }
if(typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd))
{
@@ -1058,7 +1061,7 @@ Slice::findMetaData(const StringList& metaData, int typeCtx)
return str.substr(pos + 1);
}
}
-
+
if(ss.find("type:") == 0)
{
return str.substr(pos + 1);