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

add codegen support for std::function and std::optional #658

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions StructFields.pm
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ my %custom_container_handlers = (
header_ref("map");
return "std::map<$key, $item>";
},
'stl-function' => sub {
my $item = get_container_item_type($_, -void => 'void');
header_ref("functional");
return "std::function<$item() >"; # TODO: get the full prototype
},
'stl-optional' => sub {
my $item = get_container_item_type($_, -void => 'void');
header_ref("optional");
return "std::optional<$item >";
},
'stl-shared-ptr' => sub {
my $item = get_container_item_type($_, -void => 'void');
header_ref("memory");
return "std::shared_ptr<$item >";
},
'df-flagarray' => sub {
my $type = decode_type_name_ref($_, -attr_name => 'index-enum', -force_type => 'enum-type') || 'int';
return "BitArray<$type>";
Expand Down
21 changes: 21 additions & 0 deletions data-definition.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@
<xs:element name="stl-mutex" type="OpaqueField" />
<xs:element name="stl-condition-variable" type="OpaqueField" />
<xs:element name="stl-future" type="OpaqueField" />
<xs:element name="stl-optional" type="StlOptionalField" />
<xs:element name="stl-shared-ptr" type="StlSharedPtrField" />
<xs:element name="stl-function" type="StlFunctionField" />
<xs:element name="df-linked-list" type="DfLinkedListField" />
<xs:element name="df-array" type="DfArrayField" />
<xs:element name="df-flagarray" type="DfFlagArrayField" />
Expand Down Expand Up @@ -392,6 +395,24 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="StlOptionalField">
<xs:complexContent>
<xs:extension base="ContainerFieldType">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="StlSharedPtrField">
<xs:complexContent>
<xs:extension base="ContainerFieldType">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="StlFunctionField">
<xs:complexContent>
<xs:extension base="ContainerFieldType">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="OpaqueField">
<xs:complexContent>
<xs:extension base="SimpleFieldType">
Expand Down
2 changes: 1 addition & 1 deletion lower-1.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Error: field <xsl:value-of select='$enum-key'/> corresponds to an enum value of
</xsl:template>

<!-- Misc containers: meta='container' subtype='$tag' -->
<xsl:template match='stl-vector|stl-deque|stl-set|stl-bit-vector|stl-map|df-flagarray|df-static-flagarray|df-array|df-linked-list'>
<xsl:template match='stl-vector|stl-deque|stl-set|stl-bit-vector|stl-map|stl-optional|stl-shared-ptr|stl-function|df-flagarray|df-static-flagarray|df-array|df-linked-list'>
<xsl:param name='level' select='-1'/>
<ld:field ld:meta='container'>
<xsl:attribute name='ld:level'><xsl:value-of select='$level'/></xsl:attribute>
Expand Down