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

Modifies DataModel and Language implementations for code generator #81

Merged
merged 5 commits into from
Feb 19, 2024
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
2,030 changes: 0 additions & 2,030 deletions Cargo.lock

This file was deleted.

78 changes: 62 additions & 16 deletions src/bin/ion/commands/beta/generate/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,86 @@ use std::fmt::{Display, Formatter};

/// Represents a context that will be used for code generation
pub struct CodeGenContext {
// Initially the data_model field is set to None.
// Once an ISL type definition is mapped to a data model this will have Some value.
pub(crate) data_model: Option<DataModel>,
// Initially the abstract_data_type field is set to None.
// Once an ISL type definition is mapped to an abstract data type this will have Some value.
pub(crate) abstract_data_type: Option<AbstractDataType>,
}

impl CodeGenContext {
pub fn new() -> Self {
Self { data_model: None }
Self {
abstract_data_type: None,
}
}

pub fn with_data_model(&mut self, data_model: DataModel) {
self.data_model = Some(data_model);
pub fn with_abstract_data_type(&mut self, abstract_data_type: AbstractDataType) {
self.abstract_data_type = Some(abstract_data_type);
}
}

/// Represents a data model type that can be used to determine which templates can be used for code generation.
/// A target-language-agnostic data type that determines which template(s) to use for code generation.
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum DataModel {
Value, // a struct with a scalar value (used for `type` constraint)
// TODO: Make Sequence parameterized over data type.
// add a data type for sequence here that can be used to read elements for that data type.
Sequence, // a struct with a sequence/collection value (used for `element` constraint)
pub enum AbstractDataType {
Copy link
Contributor Author

@desaikd desaikd Feb 7, 2024

Choose a reason for hiding this comment

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

(🗺️ PR tour) Renames DataModel to AbstractDataType. Also modifies Sequence enum variant to store information about sequence data type. (#69)

// A scalar value (e.g. a string or integer or user defined type)
desaikd marked this conversation as resolved.
Show resolved Hide resolved
// e.g. Given below ISL,
// ```
// type::{
// name: value_type,
// type: int
// }
// ```
// Corresponding abstract type in Rust would look like following:
// ```
// struct ValueType {
// value: i64
// }
// ```
Value,
// A series of zero or more values whose type is described by the nested `String` (e.g. a list)
// e.g. Given below ISL,
// ```
// type::{
// name: sequence_type,
// element: int
// }
// ```
// Corresponding abstract type in Rust would look like following:
// ```
// struct SequenceType {
// value: Vec<i64>
// }
// ```
Sequence(String),
// A collection of field name/value pairs (e.g. a map)
// e.g. Given below ISL,
// ```
// type::{
// name: struct_type,
// fields: {
// a: int,
// b: string,
// }
// }
// ```
// Corresponding abstract type in Rust would look like following:
// ```
// struct StructType {
// a: i64,
// b: String,
// }
// ```
Struct,
}

impl Display for DataModel {
impl Display for AbstractDataType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
DataModel::Value => "single value struct",
DataModel::Sequence => "sequence value struct",
DataModel::Struct => "struct",
AbstractDataType::Value => "scalar value struct",
AbstractDataType::Sequence(_) => "sequence",
AbstractDataType::Struct => "struct",
}
)
}
Expand Down
Loading
Loading