Skip to content

Commit

Permalink
Replace FormatType's DefaultFormat by null (#2602)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Aug 2, 2024
1 parent dd468f0 commit 5d4f24b
Show file tree
Hide file tree
Showing 35 changed files with 173 additions and 173 deletions.
10 changes: 5 additions & 5 deletions cpp/src/Slice/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,10 @@ Slice::Contained::setMetaData(const list<string>& metaData)
_metaData = metaData;
}

FormatType
std::optional<FormatType>
Slice::Contained::parseFormatMetaData(const list<string>& metaData)
{
FormatType result = DefaultFormat;
std::optional<FormatType> result;

string tag;
string prefix = "format:";
Expand Down Expand Up @@ -4670,11 +4670,11 @@ Slice::Operation::sendsOptionals() const
return false;
}

FormatType
std::optional<FormatType>
Slice::Operation::format() const
{
FormatType format = parseFormatMetaData(getMetaData());
if (format == DefaultFormat)
std::optional<FormatType> format = parseFormatMetaData(getMetaData());
if (!format)
{
ContainedPtr cont = dynamic_pointer_cast<Contained>(container());
assert(cont);
Expand Down
7 changes: 3 additions & 4 deletions cpp/src/Slice/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ namespace Slice
};

//
// Format preference for classes and exceptions.
// Format to use when marshaling a class instance.
//
enum FormatType
{
DefaultFormat, // No preference was specified.
CompactFormat, // Minimal format.
SlicedFormat // Full format.
};
Expand Down Expand Up @@ -390,7 +389,7 @@ namespace Slice
std::list<std::string> getMetaData() const;
void setMetaData(const std::list<std::string>&);

static FormatType parseFormatMetaData(const std::list<std::string>&);
static std::optional<FormatType> parseFormatMetaData(const std::list<std::string>&);

/// Returns true if this item is deprecated (due to the presence of 'deprecated' metadata).
/// @param checkParent If true, this item's immediate container will also be checked for 'deprecated' metadata.
Expand Down Expand Up @@ -677,7 +676,7 @@ namespace Slice
bool returnsData() const;
bool returnsMultipleValues() const;
bool sendsOptionals() const;
FormatType format() const;
std::optional<FormatType> format() const;
std::string kindOf() const final;
void visit(ParserVisitor*, bool) final;

Expand Down
27 changes: 16 additions & 11 deletions cpp/src/slice2cpp/CPlusPlusUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,20 +604,25 @@ Slice::operationModeToString(Operation::Mode mode)
string
Slice::opFormatTypeToString(const OperationPtr& op)
{
switch (op->format())
optional<FormatType> opFormat = op->format();
if (opFormat)
{
case DefaultFormat:
return "::std::nullopt";
case CompactFormat:
return "::Ice::FormatType::CompactFormat";
case SlicedFormat:
return "::Ice::FormatType::SlicedFormat";
switch (*opFormat)
{
case CompactFormat:
return "::Ice::FormatType::CompactFormat";
case SlicedFormat:
return "::Ice::FormatType::SlicedFormat";

default:
assert(false);
default:
assert(false);
return "???";
}
}
else
{
return "::std::nullopt";
}

return "???";
}

//
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2cpp/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3168,7 +3168,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p)
}
C << eb << ",";
C << nl << "request.current()";
if (p->format() != DefaultFormat)
if (p->format())
{
C << ",";
C << nl << opFormatTypeToString(p);
Expand Down Expand Up @@ -3201,7 +3201,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p)
C << nl << "ostr->writePendingValues();";
}
C << eb;
if (p->format() != DefaultFormat)
if (p->format())
{
C << ",";
C << nl << opFormatTypeToString(p);
Expand Down
33 changes: 15 additions & 18 deletions cpp/src/slice2cs/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,24 @@ namespace

string opFormatTypeToString(const OperationPtr& op)
{
switch (op->format())
optional<FormatType> opFormat = op->format();
if (opFormat)
{
case DefaultFormat:
switch (*opFormat)
{
return "null";
}
case CompactFormat:
{
return "Ice.FormatType.CompactFormat";
}
case SlicedFormat:
{
return "Ice.FormatType.SlicedFormat";
}
default:
{
assert(false);
case CompactFormat:
return "Ice.FormatType.CompactFormat";
case SlicedFormat:
return "Ice.FormatType.SlicedFormat";
default:
assert(false);
return "???";
}
}

return "???";
else
{
return "null";
}
}

string getDeprecationMessageForComment(const ContainedPtr& p1, const string& type)
Expand Down Expand Up @@ -2753,7 +2750,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op)
_out << nl << "ostr.writePendingValues();";
}
_out << eb;
if (op->format() != DefaultFormat)
if (op->format())
{
_out << "," << nl << opFormatTypeToString(op);
}
Expand Down
31 changes: 16 additions & 15 deletions cpp/src/slice2java/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,24 @@ namespace

string opFormatTypeToString(const OperationPtr& op)
{
string format = "com.zeroc.Ice.FormatType.";
switch (op->format())
optional<FormatType> opFormat = op->format();
if (opFormat)
{
case DefaultFormat:
format += "DefaultFormat";
break;
case CompactFormat:
format += "CompactFormat";
break;
case SlicedFormat:
format += "SlicedFormat";
break;
default:
assert(false);
break;
switch (*opFormat)
{
case CompactFormat:
return "com.zeroc.Ice.FormatType.CompactFormat";
case SlicedFormat:
return "com.zeroc.Ice.FormatType.SlicedFormat";
default:
assert(false);
return "???";
}
}
else
{
return "null";
}
return format;
}

string getEscapedParamName(const OperationPtr& p, const string& name)
Expand Down
17 changes: 7 additions & 10 deletions cpp/src/slice2js/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,18 @@ namespace
return "???";
}

string opFormatTypeToString(const OperationPtr& op)
string opFormatTypeToString(FormatType opFormat)
{
switch (op->format())
switch (opFormat)
{
case DefaultFormat:
return "0";
case CompactFormat:
return "1";
return "0";
case SlicedFormat:
return "2";
return "1";
default:
assert(false);
return "???";
}

return "???";
}

void printHeader(IceInternal::Output& out)
Expand Down Expand Up @@ -1487,9 +1484,9 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
}
_out << ", ";

if (op->format() != DefaultFormat)
if (op->format())
{
_out << opFormatTypeToString(op); // Format.
_out << opFormatTypeToString(*op->format()); // Format.
}
_out << ", ";

Expand Down
17 changes: 7 additions & 10 deletions cpp/src/slice2matlab/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2152,13 +2152,13 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)

if (!allInParams.empty())
{
if (op->format() == DefaultFormat)
if (op->format())
{
out << nl << "os_ = " << self << ".iceStartWriteParams([]);";
out << nl << "os_ = " << self << ".iceStartWriteParams(" << getFormatType(*op->format()) << ");";
}
else
{
out << nl << "os_ = " << self << ".iceStartWriteParams(" << getFormatType(op->format()) << ");";
out << nl << "os_ = " << self << ".iceStartWriteParams([]);";
}
for (ParamInfoList::const_iterator r = requiredInParams.begin(); r != requiredInParams.end(); ++r)
{
Expand Down Expand Up @@ -2315,13 +2315,13 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)

if (!allInParams.empty())
{
if (op->format() == DefaultFormat)
if (op->format())
{
out << nl << "os_ = " << self << ".iceStartWriteParams([]);";
out << nl << "os_ = " << self << ".iceStartWriteParams(" << getFormatType(*op->format()) << ");";
}
else
{
out << nl << "os_ = " << self << ".iceStartWriteParams(" << getFormatType(op->format()) << ");";
out << nl << "os_ = " << self << ".iceStartWriteParams([]);";
}
for (ParamInfoList::const_iterator r = requiredInParams.begin(); r != requiredInParams.end(); ++r)
{
Expand Down Expand Up @@ -3851,17 +3851,14 @@ CodeVisitor::getFormatType(FormatType type)
{
switch (type)
{
case DefaultFormat:
return "Ice.FormatType.DefaultFormat";
case CompactFormat:
return "Ice.FormatType.CompactFormat";
case SlicedFormat:
return "Ice.FormatType.SlicedFormat";
default:
assert(false);
return "???";
}

return "???";
}

void
Expand Down
11 changes: 10 additions & 1 deletion cpp/src/slice2php/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
//
// where InParams and OutParams are arrays of type descriptions, and Exceptions
// is an array of exception type ids.

if (!ops.empty())
{
_out << sp;
Expand Down Expand Up @@ -466,8 +467,16 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
ParamDeclList::iterator t;
int count;

// We encode nullopt as -1.
optional<FormatType> opFormat = (*oli)->format();
int phpFormat = -1;
if (opFormat)
{
phpFormat = static_cast<int>(*opFormat);
}

_out << nl << "IcePHP_defineOperation(" << prxType << ", '" << (*oli)->name() << "', "
<< getOperationMode((*oli)->mode()) << ", " << static_cast<int>((*oli)->format()) << ", ";
<< getOperationMode((*oli)->mode()) << ", " << phpFormat << ", ";
for (t = params.begin(), count = 0; t != params.end(); ++t)
{
if (!(*t)->isOutParam())
Expand Down
27 changes: 17 additions & 10 deletions cpp/src/slice2py/PythonUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,17 +1029,24 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
ParamDeclList::iterator t;
int count;
string format;
switch (operation->format())
optional<FormatType> opFormat = operation->format();
if (opFormat)
{
case DefaultFormat:
format = "None";
break;
case CompactFormat:
format = "Ice.FormatType.CompactFormat";
break;
case SlicedFormat:
format = "Ice.FormatType.SlicedFormat";
break;
switch (*opFormat)
{
case CompactFormat:
format = "Ice.FormatType.CompactFormat";
break;
case SlicedFormat:
format = "Ice.FormatType.SlicedFormat";
break;
default:
assert(false);
}
}
else
{
format = "None";
}

_out << nl << className << "._op_" << operation->name() << " = IcePy.Operation('" << operation->name() << "', "
Expand Down
27 changes: 17 additions & 10 deletions cpp/src/slice2rb/RubyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,24 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
ParamDeclList::iterator t;
int count;
string format;
switch ((*s)->format())
optional<FormatType> opFormat = (*s)->format();
if (opFormat)
{
case DefaultFormat:
format = "nil";
break;
case CompactFormat:
format = "::Ice::FormatType::CompactFormat";
break;
case SlicedFormat:
format = "::Ice::FormatType::SlicedFormat";
break;
switch (*opFormat)
{
case CompactFormat:
format = "::Ice::FormatType::CompactFormat";
break;
case SlicedFormat:
format = "::Ice::FormatType::SlicedFormat";
break;
default:
assert(false);
}
}
else
{
format = "nil";
}

_out << nl << name << "Prx_mixin::OP_" << (*s)->name() << " = ::Ice::__defineOperation('" << (*s)->name()
Expand Down
Loading

0 comments on commit 5d4f24b

Please sign in to comment.