Skip to content

Commit

Permalink
Simplify generated code (#3425)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jan 25, 2025
1 parent 3d84b3c commit f1927f4
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 122 deletions.
8 changes: 4 additions & 4 deletions cpp/src/Ice/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Ice/SlicedData.h"

#include <algorithm>
#include <array>
#include <sstream>

using namespace std;
Expand Down Expand Up @@ -110,19 +111,18 @@ Ice::Object::_iceD_ice_id(
void
Ice::Object::dispatch(IncomingRequest& request, std::function<void(OutgoingResponse)> sendResponse)
{
static constexpr string_view allOperations[] = {"ice_id", "ice_ids", "ice_isA", "ice_ping"};
static constexpr std::array<string_view, 4> allOperations{"ice_id", "ice_ids", "ice_isA", "ice_ping"};

const Current& current = request.current();

pair<const string_view*, const string_view*> r = equal_range(allOperations, allOperations + 4, current.operation);
auto r = equal_range(allOperations.begin(), allOperations.end(), current.operation);

if (r.first == r.second)
{
sendResponse(makeOutgoingResponse(make_exception_ptr(OperationNotExistException{__FILE__, __LINE__}), current));
return;
}

switch (r.first - allOperations)
switch (r.first - allOperations.begin())
{
case 0:
{
Expand Down
20 changes: 10 additions & 10 deletions cpp/src/slice2cpp/CPlusPlusUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ Slice::typeToString(
"float",
"double",
"****", // string or wstring, see below
"::Ice::ValuePtr",
"::std::optional<::Ice::ObjectPrx>",
"::Ice::ValuePtr"};
"Ice::ValuePtr",
"::std::optional<Ice::ObjectPrx>",
"Ice::ValuePtr"};

BuiltinPtr builtin = dynamic_pointer_cast<Builtin>(type);
if (builtin)
Expand All @@ -512,11 +512,11 @@ Slice::typeToString(
{
if (builtin->kind() == Builtin::KindObject)
{
return getUnqualified(string{builtinTable[Builtin::KindValue]}, scope);
return string{builtinTable[Builtin::KindValue]};
}
else
{
return getUnqualified(string{builtinTable[builtin->kind()]}, scope);
return string{builtinTable[builtin->kind()]};
}
}
}
Expand Down Expand Up @@ -605,12 +605,12 @@ Slice::operationModeToString(Operation::Mode mode)
{
case Operation::Normal:
{
return "::Ice::OperationMode::Normal";
return "Ice::OperationMode::Normal";
}

case Operation::Idempotent:
{
return "::Ice::OperationMode::Idempotent";
return "Ice::OperationMode::Idempotent";
}
default:
{
Expand All @@ -630,9 +630,9 @@ Slice::opFormatTypeToString(const OperationPtr& op)
switch (*opFormat)
{
case CompactFormat:
return "::Ice::FormatType::CompactFormat";
return "Ice::FormatType::CompactFormat";
case SlicedFormat:
return "::Ice::FormatType::SlicedFormat";
return "Ice::FormatType::SlicedFormat";

default:
assert(false);
Expand Down Expand Up @@ -768,7 +768,7 @@ Slice::writeDataMembers(Output& out, const DataMemberList& dataMembers)
}

void
Slice::writeIceTuple(::IceInternal::Output& out, const DataMemberList& dataMembers, TypeContext typeCtx)
Slice::writeIceTuple(IceInternal::Output& out, const DataMemberList& dataMembers, TypeContext typeCtx)
{
// Use an empty scope to get full qualified names from calls to typeToString.
const string scope = "";
Expand Down
20 changes: 8 additions & 12 deletions cpp/src/slice2cpp/CPlusPlusUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace Slice
char operator()(char);
};

void printHeader(::IceInternal::Output&);
void printVersionCheck(::IceInternal::Output&);
void printDllExportStuff(::IceInternal::Output&, const std::string&);
void printHeader(IceInternal::Output&);
void printVersionCheck(IceInternal::Output&);
void printDllExportStuff(IceInternal::Output&, const std::string&);

bool isMovable(const TypePtr&);

Expand Down Expand Up @@ -53,14 +53,10 @@ namespace Slice
std::string operationModeToString(Operation::Mode);
std::string opFormatTypeToString(const OperationPtr&);

void writeMarshalCode(::IceInternal::Output&, const ParameterList&, const OperationPtr&);
void writeUnmarshalCode(::IceInternal::Output&, const ParameterList&, const OperationPtr&);
void writeAllocateCode(
::IceInternal::Output&,
const ParameterList&,
const OperationPtr&,
const std::string&,
TypeContext);
void writeMarshalCode(IceInternal::Output&, const ParameterList&, const OperationPtr&);
void writeUnmarshalCode(IceInternal::Output&, const ParameterList&, const OperationPtr&);
void
writeAllocateCode(IceInternal::Output&, const ParameterList&, const OperationPtr&, const std::string&, TypeContext);

// TODO: remove from header file.
void writeMarshalUnmarshalAllInHolder(IceInternal::Output&, const std::string&, const DataMemberList&, bool, bool);
Expand All @@ -72,7 +68,7 @@ namespace Slice
void readDataMembers(IceInternal::Output&, const DataMemberList&);
void writeDataMembers(IceInternal::Output&, const DataMemberList&);

void writeIceTuple(::IceInternal::Output&, const DataMemberList&, TypeContext);
void writeIceTuple(IceInternal::Output&, const DataMemberList&, TypeContext);

std::string findMetadata(const MetadataList&, TypeContext = TypeContext::None);
bool inWstringModule(const SequencePtr&);
Expand Down
Loading

0 comments on commit f1927f4

Please sign in to comment.