This PR works on generating nested sequence and scalar types in the same class/struct.
What is the change?
Previously, code generator would generate nested sequence or scalar types as a separate nested class or struct in a nested module. But this new change does not create a new class rather maps these nested sequence or scalar type in the same class/struct that uses it.
e.g. For a schema as below:
type::{
name: struct_type,
fields: {
foo: { type: list, element: int }, // nested sequence type
bar: { type: string } // nested scalar type
}
}
Previously generated code:
class StructType {
private NestedType1 foo;
private NestedType2 bar;
...
class NestedType1 {
private ArrayList<Integer> value;
...
}
class NestedType1 {
private String value;
...
}
}
(Note: For example purpose I have only used java code but same is the case with Rust. Also, top level sequence/scalar top would still generate a separate class/struct. For more information on complete newly generated code see here)
Note for reviewer:
This PR also adds a new data model that can be used by code generator to render templates. The current approach can not generate nested sequence types like {type: list, element: {type: sexp, element: int} }. This will be resolved with the new data model as well as the new data model makes it easier to store all the information used by templates in a single place. This Pr just introduces the model but doesn't use it in implementation yet. The change for usage will be added in a separate PR.
Generated code:
Generated code for Java can be found here.
Generated code for Rust can be found here.
(You can find corresponding ISL files and Ion files in code-gen-projects directory)
Issue #110:
Description of changes:
This PR works on generating nested sequence and scalar types in the same class/struct.
What is the change?
Previously, code generator would generate nested sequence or scalar types as a separate nested class or struct in a nested module. But this new change does not create a new class rather maps these nested sequence or scalar type in the same class/struct that uses it.
e.g. For a schema as below:
Previously generated code:
Code generated with this PR changes:
(Note: For example purpose I have only used java code but same is the case with Rust. Also, top level sequence/scalar top would still generate a separate class/struct. For more information on complete newly generated code see here)
Note for reviewer:
This PR also adds a new data model that can be used by code generator to render templates. The current approach can not generate nested sequence types like
{type: list, element: {type: sexp, element: int} }
. This will be resolved with the new data model as well as the new data model makes it easier to store all the information used by templates in a single place. This Pr just introduces the model but doesn't use it in implementation yet. The change for usage will be added in a separate PR.Generated code:
Generated code for Java can be found here. Generated code for Rust can be found here. (You can find corresponding ISL files and Ion files in code-gen-projects directory)
List of changes:
Field
to storeAbstractDataType
information of the field valuemap_constraint_to_abstract_data_type
to consider nested sequence/scalar type and changeAsbtractDataType
andtera_fields
accordinglyutil_macros
for reading or writing a field as sequenceutil_macros
when reading or writing a nested sequence typeTest:
Added new test schema and input files for this change.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.