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

Adds changes for sequence data type #144

Open
wants to merge 3 commits into
base: new-model-changes
Choose a base branch
from

Conversation

desaikd
Copy link
Contributor

@desaikd desaikd commented Sep 18, 2024

Issue #, if available:

Description of changes:

This PR works on adding new model changes following up on #135. This Pr only contains changes for Sequence. This PR disables Rust support until the entire functionality for the new model change is supported and uses feature branch new-model-changes as target.

List of changes:

  • Generator changes:

    • Adds build_wrapped_sequence_from_constraints which is used for constructing named sequence data type as data model.
    • Adds build_sequence_from_constraints which is used for constructing nested sequence data type as data model. (Doesn't have a name)
    • Adds is_nested flag in convert_isl_type_def_to_data_model_node which can be used to either call wrapped sequence or sequence ADT construction.
    • Modified sequence construction to move the common logic at the beginning of the method.
  • Model changes:

    • Changes Sequence and WrappedSequence ADT to represent the underlying sequence type with base_type and its name with name field.
    • Adds doc comment changes for the same
  • Adds templates changes for java/sequence.templ

Generated code:

The generated code still stays the same only the template changes to use the new model. (Only added sequence files for checking this change, other files remain same)

Generated Java code can be found here.

Tests:

  • Adds tests for ISL to model conversion.
  • Modifies roundtrip code gen tests for sequence test cases.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

src/bin/ion/commands/generate/generator.rs Show resolved Hide resolved
src/bin/ion/commands/generate/generator.rs Show resolved Hide resolved
src/bin/ion/commands/generate/generator.rs Show resolved Hide resolved
src/bin/ion/commands/generate/generator.rs Show resolved Hide resolved
src/bin/ion/commands/generate/model.rs Outdated Show resolved Hide resolved
Sequence(Sequence),
// Represents a sequence type which also has anme attached to it and is nominally distinct from its element type.
WrappedSequence(WrappedSequence),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to have to create corresponding Wrapped* variants for all of the non-wrapped variants? Why/why not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I think its in general there are only 3 types structure, sequence and scalar. Where only nested structure would have a name but scalar and sequence would not have name. Hence to separate out whether they are named or not I have them as a separate variant. I think having them separate allows us to perform specific operations for these types which will be stored as property instead of entirely different class in the generated code.

e.g. For below ISL:

type::{
   name: my_type,
   fields: {
        foo: {type: list, element: string} // this will not create a new nested class in the generated code
   }
}

Here's the generated code in Java:

class MyType {
   private java.util.ArrayList<String> foo;
   ...
}

whereas for structure type like following:

type::{
   name: my_type,
   fields: {
        foo: {
           fields: {
               bar: string
           }
        } 
   }
}

Here's the generated code in Java, which creates a new nested type for this nested structure:

class MyType {
   private NestedType1 foo;
   ...
   
   class NestedType1 {
       private String bar;
       ...
   }
}

Copy link
Contributor

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending changes to the issues Matt raised.

* Sequences should store the fully qualified type reference with
appropriate sequence data type. e.g. For Java, it should store the
element type in an `ArrayList` in the `FullyqualifiedtypeReference`.
* Adds checks for duplicate `element` and `type` constraint
* Adds doc comment changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants