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

Use _choice suffix consistently in Protobuf #534

Merged
merged 62 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4ec5294
excluded generated output from git
Apr 4, 2024
9bb7c74
created package structure for protobuf-generator containing the requi…
Apr 4, 2024
4a05ae0
corrected naming of "pascal case" to "snake case"
Apr 4, 2024
c633781
using renamed "snake case" method in naming.py
Apr 4, 2024
013ce88
adapted naming.py and common.py methods for ProtoBuf generator
Apr 4, 2024
c4af68d
created _generate.py for ProtoBuf constants (there will be none)
Apr 4, 2024
21c06b0
adapted method generate_enum in _generate.py
Apr 4, 2024
53c4334
added generate_class method to _generate.py
Apr 4, 2024
d94fe54
added generate method to _generate.py
Apr 4, 2024
ceb4e1d
added main function to ProtoBuf generator
Apr 4, 2024
2b3a50e
created new case for choosing the protobuf entry point
Apr 4, 2024
a360a0c
finalized ProtoBuf type #3 and enum generation #1
Apr 4, 2024
afa0822
added protobuf target to README
Apr 4, 2024
6b55cce
corrected keyword stacking of "optional" and "repeated"
Apr 4, 2024
9f7b9de
fixed syntax error in generated enums
Apr 4, 2024
5c234bc
fixed syntax error for last literal in generated enums
Apr 4, 2024
7f44e42
prefixing enum literals with enum name
Apr 5, 2024
6056b5b
do not generate proto-messages for Has* classes
Apr 5, 2024
b689657
added TODO for proto generation
Apr 16, 2024
0c7e955
adding a field message_type to each proto message that shall distingu…
Apr 19, 2024
199ade3
Merge branch 'main' into protobuf
TomGneuss Apr 19, 2024
7bfe5e3
reformatted code according to pre-commit guide
Apr 22, 2024
320fead
generating properties with interface types as "oneof"
Apr 22, 2024
c1d78c1
also considering properties of interfaces of a concrete type
Apr 22, 2024
beac72a
introduced choice-message for repeated oneof's
Apr 22, 2024
f44e71f
code-formatting
Apr 22, 2024
c3b9a4a
only generating each *choice message once
Apr 22, 2024
7811085
extracted local "oneof" (within message) to choice-object;
Apr 22, 2024
baa828e
code-formatting
Apr 22, 2024
e008f25
Update README.rst
g1zzm0 Apr 22, 2024
7937d42
Update common.py
g1zzm0 Apr 22, 2024
95af49a
Update common.py
g1zzm0 Apr 22, 2024
6b8e294
Update description.py
g1zzm0 Apr 22, 2024
b1d8795
Update live_test_main.py
g1zzm0 Apr 22, 2024
b191980
Update common.py
g1zzm0 Apr 22, 2024
e20b33b
Update aas_core_codegen/cpp/constants/_generate.py
g1zzm0 Apr 22, 2024
0aa360e
Update aas_core_codegen/cpp/main.py
g1zzm0 Apr 22, 2024
23e0e39
Update aas_core_codegen/cpp/description.py
g1zzm0 Apr 22, 2024
67b19b9
Update aas_core_codegen/cpp/optionaling.py
g1zzm0 Apr 22, 2024
f231a90
Update aas_core_codegen/cpp/enhancing/__init__.py
g1zzm0 Apr 22, 2024
4dfd1ac
Update aas_core_codegen/csharp/unrolling.py
g1zzm0 Apr 22, 2024
81fb62e
Apply suggestions from code review
g1zzm0 Apr 23, 2024
4fcd0a2
Merge branch 'main' into protobuf
g1zzm0 Apr 23, 2024
33ee108
Fix interface missmatch
g1zzm0 Apr 23, 2024
02a8f2e
Merge branch 'main' into protobuf
g1zzm0 Apr 23, 2024
b30b3a6
commented unimplemented methods in naming.py
Apr 23, 2024
9f830d9
commented unimplemented methods in common.py
Apr 23, 2024
c0cd860
removed constants generation
Apr 23, 2024
967f259
corrected f-strings
Apr 23, 2024
78e1272
Fix Todos and f-string error
g1zzm0 Apr 23, 2024
f6e0663
Merg f-string
g1zzm0 Apr 23, 2024
bb00a99
fixed too long lines
Apr 23, 2024
a66ed76
Merge branch 'protobuf' of github.com:TomGneuss/aas-core-codegen into…
Apr 23, 2024
c274998
Removed unnecessary generation of MessageType enum
May 3, 2024
af2da7b
Merge branch 'main' into protobuf
TomGneuss May 3, 2024
958186b
Merge remote-tracking branch 'refs/remotes/upstream/main' into gh-pro…
May 8, 2024
d45e7dc
Merge branch 'refs/heads/gh-main' into gh-protobuf
Oct 28, 2024
a3f37b6
Use suffix _choice consistently
Oct 28, 2024
5bce352
Update code comment
Oct 28, 2024
16000d3
Update test_data
Oct 28, 2024
fba795e
Fix typo in test_data
Oct 28, 2024
9585f4d
Update aas_core_codegen/protobuf/common.py
mristin Oct 28, 2024
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
14 changes: 6 additions & 8 deletions aas_core_codegen/protobuf/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,12 @@ def generate_type(type_annotation: intermediate.TypeAnnotationUnion) -> Stripped

elif isinstance(our_type, intermediate.Class):
message_name = proto_naming.class_name(our_type.name)
if (
isinstance(our_type, intermediate.ConcreteClass)
and len(our_type.concrete_descendants) > 0
):
# NOTE (mristin):
# We have to add the suffix ``_choice`` since this field points
# to one of the concrete descendants of the class as well as
# the concrete class itself.
if len(our_type.concrete_descendants) > 0:
# NOTE (TomGneuss):
# add the suffix "_choice" to the type name because this type
# (either abstract or concrete) has concrete subtypes.
# Thus, a choice-object (with that suffix) will be generated and must
# be used here.
message_name = Identifier(message_name + "_choice")

return Stripped(message_name)
Expand Down
15 changes: 1 addition & 14 deletions aas_core_codegen/protobuf/structure/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,7 @@ def _generate_choice_class(cls: intermediate.ClassUnion) -> Stripped:
subtype_name = proto_naming.property_name(subtype.name)
fields.append(Stripped(f"{subtype_type} {subtype_name} = {j + 1};"))

if isinstance(cls, intermediate.AbstractClass):
message_name = proto_naming.class_name(cls.name)
elif isinstance(cls, intermediate.ConcreteClass):
# NOTE (mristin):
# We have to append the ``_choice`` suffix for concrete classes with descendants
# to distinguish between the concrete classes and one-of choice classes.
# Protocol Buffers do not support inheritance, so we have to work around that
# circumstance.

message_name = Identifier(proto_naming.class_name(cls.name) + "_choice")

else:
assert_never(cls)
raise AssertionError("Unexpected execution path")
message_name = Identifier(proto_naming.class_name(cls.name) + "_choice")

fields_joined = "\n".join(fields)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ message Submodel {
/// <summary>
/// A submodel consists of zero or more submodel elements.
/// </summary>
repeated SubmodelElement submodel_elements = 13;
repeated SubmodelElement_choice submodel_elements = 13;
}

/// <summary>
Expand Down Expand Up @@ -1028,7 +1028,7 @@ message SubmodelElementList {
/// <remarks>
/// The list is ordered.
/// </remarks>
repeated SubmodelElement value = 14;
repeated SubmodelElement_choice value = 14;
}

/// <summary>
Expand Down Expand Up @@ -1135,7 +1135,7 @@ message SubmodelElementCollection {
/// <summary>
/// Submodel element contained in the collection.
/// </summary>
repeated SubmodelElement value = 10;
repeated SubmodelElement_choice value = 10;
}

/// <summary>
Expand Down Expand Up @@ -1992,7 +1992,7 @@ message AnnotatedRelationshipElement {
/// A data element that represents an annotation that holds for the relationship
/// between the two elements
/// </summary>
repeated DataElement annotations = 12;
repeated DataElement_choice annotations = 12;
}

/// <summary>
Expand Down Expand Up @@ -2112,7 +2112,7 @@ message Entity {
/// Describes statements applicable to the entity by a set of submodel elements,
/// typically with a qualified value.
/// </summary>
repeated SubmodelElement statements = 10;
repeated SubmodelElement_choice statements = 10;

/// <summary>
/// Describes whether the entity is a co-managed entity or a self-managed entity.
Expand Down Expand Up @@ -2590,7 +2590,7 @@ message OperationVariable {
/// <summary>
/// Describes an argument or result of an operation via a submodel element
/// </summary>
SubmodelElement value = 1;
SubmodelElement_choice value = 1;
}

/// <summary>
Expand Down Expand Up @@ -3284,7 +3284,7 @@ message EmbeddedDataSpecification {
/// <summary>
/// Actual content of the data specification
/// </summary>
DataSpecificationContent data_specification_content = 1;
DataSpecificationContent_choice data_specification_content = 1;

/// <summary>
/// Reference to the data specification
Expand Down Expand Up @@ -3738,7 +3738,7 @@ message DataSpecificationIec61360 {
optional LevelType level_type = 12;
}

message HasSemantics {
message HasSemantics_choice {
oneof value {
RelationshipElement relationship_element = 1;
AnnotatedRelationshipElement annotated_relationship_element = 2;
Expand All @@ -3761,7 +3761,7 @@ message HasSemantics {
}
}

message HasExtensions {
message HasExtensions_choice {
oneof value {
RelationshipElement relationship_element = 1;
AnnotatedRelationshipElement annotated_relationship_element = 2;
Expand All @@ -3783,7 +3783,7 @@ message HasExtensions {
}
}

message Referable {
message Referable_choice {
oneof value {
RelationshipElement relationship_element = 1;
AnnotatedRelationshipElement annotated_relationship_element = 2;
Expand All @@ -3805,21 +3805,21 @@ message Referable {
}
}

message Identifiable {
message Identifiable_choice {
oneof value {
AssetAdministrationShell asset_administration_shell = 1;
ConceptDescription concept_description = 2;
Submodel submodel = 3;
}
}

message HasKind {
message HasKind_choice {
oneof value {
Submodel submodel = 1;
}
}

message HasDataSpecification {
message HasDataSpecification_choice {
oneof value {
AdministrativeInformation administrative_information = 1;
RelationshipElement relationship_element = 2;
Expand All @@ -3842,7 +3842,7 @@ message HasDataSpecification {
}
}

message Qualifiable {
message Qualifiable_choice {
oneof value {
RelationshipElement relationship_element = 1;
AnnotatedRelationshipElement annotated_relationship_element = 2;
Expand All @@ -3862,7 +3862,7 @@ message Qualifiable {
}
}

message SubmodelElement {
message SubmodelElement_choice {
oneof value {
RelationshipElement relationship_element = 1;
AnnotatedRelationshipElement annotated_relationship_element = 2;
Expand All @@ -3888,7 +3888,7 @@ message RelationshipElement_choice {
}
}

message DataElement {
message DataElement_choice {
oneof value {
Blob blob = 1;
File file = 2;
Expand All @@ -3899,13 +3899,13 @@ message DataElement {
}
}

message EventElement {
message EventElement_choice {
oneof value {
BasicEventElement basic_event_element = 1;
}
}

message AbstractLangString {
message AbstractLangString_choice {
oneof value {
LangStringDefinitionTypeIec61360 lang_string_definition_type_iec_61360 = 1;
LangStringNameType lang_string_name_type = 2;
Expand All @@ -3915,7 +3915,7 @@ message AbstractLangString {
}
}

message DataSpecificationContent {
message DataSpecificationContent_choice {
oneof value {
DataSpecificationIec61360 data_specification_iec_61360 = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ message AnotherConcrete {
}

message Container {
SomethingAbstract something_abstract = 1;
SomethingAbstract_choice something_abstract = 1;
}

message SomethingAbstract {
message SomethingAbstract_choice {
oneof value {
AnotherConcrete another_concrete = 1;
SomethingConcrete something_concrete = 2;
Expand Down
Loading