Skip to content

Commit

Permalink
Re-enable the Swift test thing.
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere committed Sep 30, 2024
1 parent fe55cc6 commit 0696ca4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
6 changes: 1 addition & 5 deletions cpp/src/slice2js/JsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ lookupKwd(const string& name)
"interface", "let", "new", "null", "package", "private", "protected", "public",
"return", "static", "super", "switch", "this", "throw", "true", "try",
"typeof", "var", "void", "while", "with", "yield"};
bool found = binary_search(
&keywordList[0],
&keywordList[sizeof(keywordList) / sizeof(*keywordList)],
name,
Slice::CICompare());
bool found = binary_search(&keywordList[0], &keywordList[sizeof(keywordList) / sizeof(*keywordList)], name);
if (found)
{
return "_" + name;
Expand Down
34 changes: 16 additions & 18 deletions cpp/src/slice2swift/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ Gen::TypesVisitor::visitStructStart(const StructPtr& p)
out << nl << "func read() throws -> " << name;
out << sb;
out << nl << (usesClasses ? "let" : "var") << " v = " << name << "()";
for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q)
for (const auto& member : members)
{
writeMarshalUnmarshalCode(out, (*q)->type(), p, "v." + fixIdent((*q)->name()), false);
writeMarshalUnmarshalCode(out, member->type(), p, "v." + fixIdent(member->name()), false);
}
out << nl << "return v";
out << eb;
Expand Down Expand Up @@ -566,9 +566,9 @@ Gen::TypesVisitor::visitStructStart(const StructPtr& p)
out << nl << "///";
out << nl << "/// - parameter _: `" << name << "` - The value to write to the stream.";
out << nl << "func write(_ v: " << name << ")" << sb;
for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q)
for (const auto& member : members)
{
writeMarshalUnmarshalCode(out, (*q)->type(), p, "v." + fixIdent((*q)->name()), true);
writeMarshalUnmarshalCode(out, member->type(), p, "v." + fixIdent(member->name()), true);
}
out << eb;

Expand Down Expand Up @@ -632,7 +632,7 @@ Gen::TypesVisitor::visitSequence(const SequencePtr& p)
const string ostr = getUnqualified("Ice.OutputStream", swiftModule);
const string istr = getUnqualified("Ice.InputStream", swiftModule);

const string optionalFormat = getUnqualified(getOptionalFormat(p), swiftModule);
const string optionalFormat = getOptionalFormat(p);

out << sp;
out << nl << "/// Helper class to read and write `" << fixIdent(name) << "` sequence values from";
Expand Down Expand Up @@ -774,7 +774,7 @@ Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
const string ostr = getUnqualified("Ice.OutputStream", swiftModule);
const string istr = getUnqualified("Ice.InputStream", swiftModule);

const string optionalFormat = getUnqualified(getOptionalFormat(p), swiftModule);
const string optionalFormat = getOptionalFormat(p);
const bool isVariableLength = p->keyType()->isVariableLength() || p->valueType()->isVariableLength();
const size_t minWireSize = p->keyType()->minWireSize() + p->valueType()->minWireSize();

Expand Down Expand Up @@ -925,16 +925,16 @@ Gen::TypesVisitor::visitEnum(const EnumPtr& p)
out << nl << "public enum " << name << ": " << enumType;
out << sb;

for (EnumeratorList::const_iterator en = enumerators.begin(); en != enumerators.end(); ++en)
for (const auto& enumerator : enumerators)
{
StringList sl = splitComment((*en)->comment());
out << nl << "/// " << fixIdent((*en)->name());
StringList sl = splitComment(enumerator->comment());
out << nl << "/// " << fixIdent(enumerator->name());
if (!sl.empty())
{
out << " ";
writeDocLines(out, sl, false);
}
out << nl << "case " << fixIdent((*en)->name()) << " = " << (*en)->value();
out << nl << "case " << fixIdent(enumerator->name()) << " = " << enumerator->value();
}

out << nl << "public init()";
Expand Down Expand Up @@ -1325,17 +1325,16 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p)
<< ") throws";
out << sb;
out << nl << "_ = try istr.startSlice()";
for (DataMemberList::const_iterator i = members.begin(); i != members.end(); ++i)
for (const auto& member : members)
{
DataMemberPtr member = *i;
if (!member->optional())
{
writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), false);
}
}
for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d)
for (const auto& member : optionalMembers)
{
writeMarshalUnmarshalCode(out, (*d)->type(), p, "self." + fixIdent((*d)->name()), false, (*d)->tag());
writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), false, member->tag());
}
out << nl << "try istr.endSlice()";
if (base)
Expand All @@ -1349,18 +1348,17 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p)
out << sb;
out << nl << "ostr.startSlice(typeId: " << fixIdent(name) << ".ice_staticId(), compactId: " << p->compactId()
<< ", last: " << (!base ? "true" : "false") << ")";
for (DataMemberList::const_iterator i = members.begin(); i != members.end(); ++i)
for (const auto& member : members)
{
DataMemberPtr member = *i;
TypePtr type = member->type();
if (!member->optional())
{
writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), true);
}
}
for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d)
for (const auto& member : optionalMembers)
{
writeMarshalUnmarshalCode(out, (*d)->type(), p, "self." + fixIdent((*d)->name()), true, (*d)->tag());
writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), true, member->tag());
}
out << nl << "ostr.endSlice()";
if (base)
Expand Down
32 changes: 19 additions & 13 deletions cpp/src/slice2swift/SwiftUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,27 +156,32 @@ namespace
}
}

//
// Check the given identifier against Swift's list of reserved words. If it matches
// a reserved word, then an escaped version is returned with a leading underscore.
//
// The provided identifier must be a _Swift_ identifier (Ice.Foo) and not a Slice identifier (Ice::Foo).
string
Slice::fixIdent(const string& ident)
{
if (ident[0] != ':')
{
return lookupKwd(ident);
}
vector<string> ids = splitScopedName(ident);
assert(ident.find(':' == string::npos));

transform(ids.begin(), ids.end(), ids.begin(), [](const string& id) -> string { return lookupKwd(id); });
// Swift namespaces are flat, so we don't need to check for multiple periods, there can be at most 1.
string::size_type separator_pos = ident.find('.');
if (separator_pos != string::npos)
{
// If this identifier is scoped, we break it up and escape each piece separately.
auto scope = ident.substr(0, separator_pos);
auto name = ident.substr(separator_pos + 1);

ostringstream result;
for (vector<string>::const_iterator i = ids.begin(); i != ids.end(); ++i)
ostringstream result;
result << lookupKwd(scope) << "." << lookupKwd(name);
return result.str();
}
else
{
result << "::" + *i;
// If this identifier isn't scoped, we directly escape it.
return lookupKwd(ident);
}
return result.str();
}

string
Expand Down Expand Up @@ -2224,9 +2229,10 @@ SwiftGenerator::writeUnmarshalUserException(::IceInternal::Output& out, const Op
out << sb;
out << nl << "throw ex";
out << eb;
for (ExceptionList::const_iterator q = throws.begin(); q != throws.end(); ++q)

for (const auto& thrown : throws)
{
out << " catch let error as " << getRelativeTypeString(*q, swiftModule) << sb;
out << " catch let error as " << fixIdent(getRelativeTypeString(thrown, swiftModule)) << sb;
out << nl << "throw error";
out << eb;
}
Expand Down
2 changes: 1 addition & 1 deletion js/test/Slice/macros/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Client extends TestHelper {
const out = this.getWriter();
out.write("testing Slice predefined macros... ");

const d = new Test._Default();
const d = new Test.Default();
test(d.x == 10);
test(d.y == 10);

Expand Down
2 changes: 0 additions & 2 deletions swift/test/Slice/escape/Key.ice
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ exception as extends return
int static; int switch;
}

/* TODO: reenable when #1617 is fixed
interface friend
{
guard goto(continue if, guard d, defer inline, switch private, do mutable, break* namespace,
func* new, switch* not, do* operator, int or, int protected, int public, int register)
throws return, as;
}
*/

const int is = 0;
const int self = 0;
Expand Down

0 comments on commit 0696ca4

Please sign in to comment.