Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup slice2cpp metadata #1867

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 7 additions & 39 deletions cpp/include/Ice/StreamHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ const StreamHelperCategory StreamHelperCategoryBuiltinValue = 1;
const StreamHelperCategory StreamHelperCategoryBuiltin = 2;
/** For struct types. */
const StreamHelperCategory StreamHelperCategoryStruct = 3;
/** For struct types with cpp:class metadata. */
const StreamHelperCategory StreamHelperCategoryStructClass = 4;
/** For enum types. */
const StreamHelperCategory StreamHelperCategoryEnum = 5;
const StreamHelperCategory StreamHelperCategoryEnum = 4;
/** For sequence types. */
const StreamHelperCategory StreamHelperCategorySequence = 6;
const StreamHelperCategory StreamHelperCategorySequence = 5;
/** For dictionary types. */
const StreamHelperCategory StreamHelperCategoryDictionary = 7;
const StreamHelperCategory StreamHelperCategoryDictionary = 6;
/** For proxy types. */
const StreamHelperCategory StreamHelperCategoryProxy = 8;
const StreamHelperCategory StreamHelperCategoryProxy = 7;
/** For class types. */
const StreamHelperCategory StreamHelperCategoryClass = 9;
const StreamHelperCategory StreamHelperCategoryClass = 8;
/** For exception types. */
const StreamHelperCategory StreamHelperCategoryUserException = 10;
const StreamHelperCategory StreamHelperCategoryUserException = 9;

/**
* The optional format.
Expand Down Expand Up @@ -432,7 +430,7 @@ struct StreamHelper<T, StreamHelperCategoryBuiltin>
};

//
// "helpers" for the StreamHelper<T, StreamHelperCategoryStruct[Class]> below
// "helpers" for the StreamHelper<T, StreamHelperCategoryStruct> below
// slice2cpp generates specializations as needed
//

Expand Down Expand Up @@ -482,27 +480,6 @@ struct StreamHelper<T, StreamHelperCategoryStruct>
}
};

/**
* Helper for class structs.
* \headerfile Ice/Ice.h
*/
template<typename T>
struct StreamHelper<T, StreamHelperCategoryStructClass>
{
template<class S> static inline void
write(S* stream, const T& v)
{
StreamWriter<T, S>::write(stream, v);
}

template<class S> static inline void
read(S* stream, T& v)
{
v = new typename T::element_type;
StreamReader<T, S>::read(stream, v);
}
};

/**
* Helper for enums.
* \headerfile Ice/Ice.h
Expand Down Expand Up @@ -845,15 +822,6 @@ struct StreamOptionalHelper<T, StreamHelperCategoryStruct, false>
}
};

/**
* Class structs are encoded like structs.
* \headerfile Ice/Ice.h
*/
template<typename T, bool fixedLength>
struct StreamOptionalHelper<T, StreamHelperCategoryStructClass, fixedLength> : StreamOptionalHelper<T, StreamHelperCategoryStruct, fixedLength>
{
};

// InputStream and OutputStream have special logic for optional (tagged) proxies that does not rely on the
// StreamOptional helpers.

Expand Down
137 changes: 11 additions & 126 deletions cpp/src/slice2cpp/CPlusPlusUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,6 @@ sequenceTypeToString(const SequencePtr& seq, const string& scope, const StringLi
typeCtx | (inWstringModule(seq) ? TypeContextUseWstring : 0));
return "::std::pair<const " + s + "*, const " + s + "*>";
}
else if(seqType.find("%range") == 0)
{
string s;
if(seqType.find("%range:") == 0)
{
s = seqType.substr(strlen("%range:"));
}
else
{
s = getUnqualified(fixKwd(seq->scoped()), scope);
}

if(typeCtx & TypeContextAMIPrivateEnd)
{
return s;
}

if(s[0] == ':')
{
s = " " + s;
}
return "::std::pair<" + s + "::const_iterator, " + s + "::const_iterator>";
}
else
{
return seqType;
Expand Down Expand Up @@ -172,8 +149,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
// array as well now to ensure they are always in the same scope.
// If using a array we need to allocate the array as well now to ensure they are always in the same scope.
//
SequencePtr seq = dynamic_pointer_cast<Sequence>(type);
if(seq)
Expand All @@ -189,15 +165,6 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st
{
str = typeToString(seq, scope, metaData, TypeContextAMIPrivateEnd);
}
else if(seqType.find("%range") == 0)
{
StringList md;
if(seqType.find("%range:") == 0)
{
md.push_back("cpp:type:" + seqType.substr(strlen("%range:")));
}
str = typeToString(seq, scope, md, 0);
}

if(!str.empty())
{
Expand Down Expand Up @@ -285,23 +252,6 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string&
}
}
}
else if(seqType.find("%range") == 0)
{
if(optional)
{
out << nl << "if(" << escapedParamName << ")";
out << sb;
out << nl << paramName << ".emplace();";
out << nl << paramName << "->first = (*" << escapedParamName << ").begin();";
out << nl << paramName << "->second = (*" << escapedParamName << ").end();";
out << eb;
}
else
{
out << nl << paramName << ".first = " << escapedParamName << ".begin();";
out << nl << paramName << ".second = " << escapedParamName << ".end();";
}
}
}
}

Expand Down Expand Up @@ -720,17 +670,7 @@ Slice::typeToString(const TypePtr& type, const string& scope, const StringList&
StructPtr st = dynamic_pointer_cast<Struct>(type);
if(st)
{
//
// C++11 mapping doesn't accept cpp:class metadata
//
if(!cpp11 && findMetaData(st->getMetaData()) == "%class")
{
return getUnqualified(fixKwd(st->scoped() + "Ptr"), scope);
}
else
{
return getUnqualified(fixKwd(st->scoped()), scope);
}
return getUnqualified(fixKwd(st->scoped()), scope);
}

InterfaceDeclPtr proxy = dynamic_pointer_cast<InterfaceDecl>(type);
Expand Down Expand Up @@ -855,21 +795,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const string& scope
StructPtr st = dynamic_pointer_cast<Struct>(type);
if(st)
{
if(cpp11)
{
return "const " + getUnqualified(fixKwd(st->scoped()), scope) + "&";
}
else
{
if(findMetaData(st->getMetaData()) == "%class")
{
return "const " + getUnqualified(fixKwd(st->scoped() + "Ptr"), scope) + "&";
}
else
{
return "const " + getUnqualified(fixKwd(st->scoped()), scope) + "&";
}
}
return "const " + getUnqualified(fixKwd(st->scoped()), scope) + "&";
}

InterfaceDeclPtr proxy = dynamic_pointer_cast<InterfaceDecl>(type);
Expand Down Expand Up @@ -961,14 +887,7 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const string& scop
StructPtr st = dynamic_pointer_cast<Struct>(type);
if(st)
{
if(!cpp11 && findMetaData(st->getMetaData()) == "%class")
{
return getUnqualified(fixKwd(st->scoped() + "Ptr&"), scope);
}
else
{
return getUnqualified(fixKwd(st->scoped()), scope) + "&";
}
return getUnqualified(fixKwd(st->scoped()), scope) + "&";
}

InterfaceDeclPtr proxy = dynamic_pointer_cast<InterfaceDecl>(type);
Expand Down Expand Up @@ -1167,12 +1086,6 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional
writeParamEndCode(out, seq, optional, param, metaData, obj);
return;
}
else if(seqType.find("%range") == 0)
{
out << nl << func << objPrefix << param << "_tmp_);";
writeParamEndCode(out, seq, optional, param, metaData, obj);
return;
}
}
}

Expand Down Expand Up @@ -1247,15 +1160,6 @@ Slice::getEndArg(const TypePtr& type, const StringList& metaData, const string&
endArg += "_tmp_";
}
}
else if(seqType.find("%range") == 0)
{
StringList md;
if(seqType.find("%range:") == 0)
{
md.push_back("cpp:type:" + seqType.substr(strlen("%range:")));
}
endArg += "_tmp_";
}
}
return endArg;
}
Expand Down Expand Up @@ -1332,7 +1236,6 @@ Slice::writeStreamHelpers(Output& out,
const ContainedPtr& c,
DataMemberList dataMembers,
bool hasBaseDataMembers,
bool checkClassMetaData,
bool cpp11)
{
// If c is a C++11 class/exception whose base class contains data members (recursively), then we need to generate
Expand Down Expand Up @@ -1371,9 +1274,8 @@ Slice::writeStreamHelpers(Output& out,
optionalMembers.sort(SortFn::compare);

string scoped = c->scoped();
bool classMetaData = checkClassMetaData ? (findMetaData(c->getMetaData(), false) == "%class") : false;
string fullName = classMetaData ? fixKwd(scoped + "Ptr") : fixKwd(scoped);
string holder = classMetaData ? "v->" : "v.";
string fullName = fixKwd(scoped);
string holder = "v.";

//
// Generate StreamWriter
Expand Down Expand Up @@ -1535,12 +1437,11 @@ Slice::findMetaData(const StringList& metaData, int typeCtx)
// is returned.
// If the form is cpp:view-type:<...> the data after the
// cpp:view-type: is returned
// If the form is cpp:range[:<...>], cpp:array or cpp:class,
// the return value is % followed by the string after cpp:.
// If the form is cpp:array, the return value is % followed by the string after cpp:.
//
// The priority of the metadata is as follows:
// 1: array, range (C++98 only), view-type for "view" parameters
// 2: class (C++98 only), scoped (C++98 only), unscoped (C++11 only)
// 1: array view-type for "view" parameters
// 2: unscoped
//

if(pos != string::npos)
Expand All @@ -1553,10 +1454,6 @@ Slice::findMetaData(const StringList& metaData, int typeCtx)
{
return str.substr(pos + 1);
}
else if(ss.find("range:") == 0 && !(typeCtx & TypeContextCpp11))
{
return string("%") + str.substr(prefix.size());
}
}

if(ss.find("type:") == 0)
Expand All @@ -1571,26 +1468,14 @@ Slice::findMetaData(const StringList& metaData, int typeCtx)
{
return "%array";
}
else if(ss == "range" && !(typeCtx & TypeContextCpp11))
{
return "%range";
}
}
//
// Otherwise if the data is "class", "scoped" or "unscoped" it is returned.
// Otherwise if the data is "unscoped" it is returned.
//
else
{
string ss = str.substr(prefix.size());
if(ss == "class" && !(typeCtx & TypeContextCpp11))
{
return "%class";
}
else if(ss == "scoped" && !(typeCtx & TypeContextCpp11))
{
return "%scoped";
}
else if(ss == "unscoped" && (typeCtx & TypeContextCpp11))
if(ss == "unscoped" && (typeCtx & TypeContextCpp11))
{
return "%unscoped";
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/slice2cpp/CPlusPlusUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::string getEndArg(const TypePtr&, const StringList&, const std::string&);
void writeEndCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool = false);
void writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberPtr&, bool);
void writeMarshalUnmarshalAllInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberList&, bool, bool);
void writeStreamHelpers(::IceUtilInternal::Output&, const ContainedPtr&, DataMemberList, bool, bool, bool);
void writeStreamHelpers(::IceUtilInternal::Output&, const ContainedPtr&, DataMemberList, bool, bool);
void writeIceTuple(::IceUtilInternal::Output&, DataMemberList, int);

bool findMetaData(const std::string&, const ClassDeclPtr&, std::string&);
Expand Down
Loading