amazon-ion / ion-cli

Apache License 2.0
31 stars 15 forks source link

Adds a new model for code generator #123

Closed desaikd closed 2 months ago

desaikd commented 2 months ago

Issue #, if available:

Description of changes:

This PR is adds a new model for code generator to make it simpler for getting information on nested types and element type in sequence.

List of changes:


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

desaikd commented 2 months ago

The model you have for an "entity" (type, struct, class, whatever) is a struct with common fields and an enum for the things that are different.

You may want to consider refactoring so that you have an enum as an "umbrella", and all of the data in the structs for the variants, even if there is some duplication.

I have changed the model to store all information on a data type with its own implementation (e.g. Scalar, WrappedScalar, Sequence, Structure). A new variant WrappedScalar is added that can be used to represent a top level scalar type definition. A top level scalar type definition can have a name which is why its better to have it as a separate variant to have specific methods to it in WrappedScalar.

For example given below ISL,

type::{
  name: wrapped_scalar_type,
  type: int
}

Corresponding generated code in Rust would look like following:

struct WrappedScalarType {
    value: i64
 }