You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Builtin (most of these are already supported by virtue of being mapped to primitive types)
Class
Interface (really proxy)
Struct
Sequence
Dictionary
Enum
What should we do for exceptions?
Since exceptions are not types, they can't be held in any of the above Slice definitions.
Additionally, all the generated exceptions inherit support for operator<< from Ice::Exception:
For example, printing an instance of a class generated from this:
class Device
{
int uid;
string modelName;
}
could look like:
Device@0x7683478 {uid:12, modelName:foobar}
One interesting note about classes is that they could possibly be recursive.
We can handle this by keeping a stack (vector) of ValuePtr and pushing/popping classes to it as we deeply traverse a class tree for printing. If we encounter a cycle (ie. we hit a class that'si already in our stack), instead of printing it's fields we instead print:
Structs would work in the exact same way as classes. Same representation, and we'd generate the same 2 functions.
The only difference is that we won't push/pop structs onto the classStack, since there's no risk of having a recursive struct.
Sequences & Dictionaries
Still thinking of what to do here.
Enum
For enums we would generate the enumerator name (if possible), and the raw underlying value otherwise.
For example, for this Slice definition:
enum Foo { Hello, There };
we would generate this implementation directly under the enum's generated definition:
ostream& operator<<(ostream& os, <SELF> value)
{
switch (value)
{
case Foo::Hello:
return os << "Foo::Hello";
case Foo::There:
return os << "Foo::There";
default:
return os << "Foo {" << static_cast<uint8_t>(value) >> "}"; // the compiler knows to generate `uint8_t` or `int32_t`.
}
}
Otherwise it will be impossible to tell when 2 classes are the same instance as opposed to copies,
or in the case of recursive classes, impossible to tell exactly which instance was recursive.
I know that we're basing it on C#, but other languages like Python do include memory addresses when printing non-primitive types like these.
As discussed in https://github.com/orgs/zeroc-ice/discussions/2980, we should add support for printing generated Slice types.
We should add support for printing the following:
What should we do for exceptions?
Since exceptions are not types, they can't be held in any of the above Slice definitions.
Additionally, all the generated exceptions inherit support for
operator<<
fromIce::Exception
:ice/cpp/src/Ice/Exception.cpp
Lines 503 to 524 in 7b37d63
and we have the
cpp:ice_print
metadata, allowing users to provide their ownice_print
implementations.The text was updated successfully, but these errors were encountered: