Skip to content

Commit

Permalink
Remove String from AST. Related to #31
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Aug 17, 2024
1 parent b936463 commit 020c58f
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "semantic-analyzer"
version = "0.4.4"
version = "0.4.5"
authors = ["Evgeny Ukhanov <mrlsd@ya.ru>"]
description = "Semantic analyzer library for compilers written in Rust for semantic analysis of programming languages AST"
keywords = ["compiler", "semantic-analisis", "semantic-alalyzer", "compiler-design", "semantic"]
Expand Down
4 changes: 0 additions & 4 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ pub enum PrimitiveTypes {
I64,
F32,
F64,
String,
Bool,
Char,
Ptr,
Expand All @@ -347,7 +346,6 @@ impl GetName for PrimitiveTypes {
Self::I64 => "i64".to_string(),
Self::F32 => "f32".to_string(),
Self::F64 => "f64".to_string(),
Self::String => "string".to_string(),
Self::Bool => "bool".to_string(),
Self::Char => "char".to_string(),
Self::Ptr => "ptr".to_string(),
Expand Down Expand Up @@ -589,7 +587,6 @@ pub enum PrimitiveValue {
I64(i64),
F32(f32),
F64(f64),
String(String),
Bool(bool),
Char(char),
Ptr,
Expand All @@ -610,7 +607,6 @@ impl PrimitiveValue {
Self::I64(_) => Type::Primitive(PrimitiveTypes::I64),
Self::F32(_) => Type::Primitive(PrimitiveTypes::F32),
Self::F64(_) => Type::Primitive(PrimitiveTypes::F64),
Self::String(_) => Type::Primitive(PrimitiveTypes::String),
Self::Char(_) => Type::Primitive(PrimitiveTypes::Char),
Self::Bool(_) => Type::Primitive(PrimitiveTypes::Bool),
Self::Ptr => Type::Primitive(PrimitiveTypes::Ptr),
Expand Down
3 changes: 0 additions & 3 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ pub enum PrimitiveValue {
F32(f32),
F64(f64),
Bool(bool),
String(String),
Char(char),
Ptr,
None,
Expand All @@ -434,7 +433,6 @@ impl From<ast::PrimitiveValue> for PrimitiveValue {
ast::PrimitiveValue::I64(v) => Self::I64(v),
ast::PrimitiveValue::F32(v) => Self::F32(v),
ast::PrimitiveValue::F64(v) => Self::F64(v),
ast::PrimitiveValue::String(v) => Self::String(v),
ast::PrimitiveValue::Bool(v) => Self::Bool(v),
ast::PrimitiveValue::Char(v) => Self::Char(v),
ast::PrimitiveValue::Ptr => Self::Ptr,
Expand All @@ -457,7 +455,6 @@ impl Display for PrimitiveValue {
Self::F32(val) => val.clone().to_string(),
Self::F64(val) => val.clone().to_string(),
Self::Bool(val) => val.to_string(),
Self::String(s) => s.clone(),
Self::Char(c) => format!("{c}"),
Self::Ptr => "ptr".to_string(),
Self::None => "None".to_string(),
Expand Down
3 changes: 0 additions & 3 deletions src/types/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ pub enum PrimitiveTypes {
I64,
F32,
F64,
String,
Bool,
Char,
Ptr,
Expand All @@ -175,7 +174,6 @@ impl Display for PrimitiveTypes {
Self::I64 => "i64",
Self::F32 => "f32",
Self::F64 => "f64",
Self::String => "string",
Self::Bool => "bool",
Self::Char => "char",
Self::Ptr => "ptr",
Expand All @@ -198,7 +196,6 @@ impl From<ast::PrimitiveTypes> for PrimitiveTypes {
ast::PrimitiveTypes::I64 => Self::I64,
ast::PrimitiveTypes::F32 => Self::F32,
ast::PrimitiveTypes::F64 => Self::F64,
ast::PrimitiveTypes::String => Self::String,
ast::PrimitiveTypes::Bool => Self::Bool,
ast::PrimitiveTypes::Char => Self::Char,
ast::PrimitiveTypes::Ptr => Self::Ptr,
Expand Down
22 changes: 0 additions & 22 deletions tests/expressions_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,28 +289,6 @@ fn expression_ast_transform_primitive_value_f64() {
assert_eq!(expr.to_string(), "3.1");
}

#[test]
fn expression_ast_transform_primitive_value_string() {
let test_res = "test".to_string();
let val = ast::PrimitiveValue::String(test_res.clone());
assert_eq!(
val.get_type(),
ast::Type::Primitive(ast::PrimitiveTypes::String)
);
let expr_val: PrimitiveValue = val.clone().into();
assert_eq!(PrimitiveValue::String(test_res.clone()), expr_val);
assert_eq!(expr_val.to_string(), test_res);
let expr: Expression = ast::Expression {
expression_value: ast::ExpressionValue::<
CustomExpressionInstruction,
CustomExpression<CustomExpressionInstruction>,
>::PrimitiveValue(val),
operation: None,
}
.into();
assert_eq!(expr.to_string(), test_res);
}

#[test]
fn expression_ast_transform_primitive_value_bool() {
let val = ast::PrimitiveValue::Bool(true);
Expand Down
15 changes: 1 addition & 14 deletions tests/types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ fn types_ast_transform() {
attributes: vec![],
}),
};
let ty18 = ast::StructType {
attr_name: Ident::new("attr18"),
attr_type: ast::Type::Primitive(ast::PrimitiveTypes::String),
};
let type_ast = ast::StructTypes {
name: Ident::new("type2"),
attributes: vec![
Expand All @@ -115,12 +111,11 @@ fn types_ast_transform() {
ty15.clone(),
ty16.clone(),
ty17.clone(),
ty18.clone(),
],
};
let type_into2: StructTypes = type_ast.clone().into();
assert_eq!(type_into2.name, "type2");
assert_eq!(type_into2.attributes.len(), 17);
assert_eq!(type_into2.attributes.len(), 16);

// Index=0 the same, so we can check directly
assert_eq!(ty1.attr_type.name(), "u8");
Expand Down Expand Up @@ -258,14 +253,6 @@ fn types_ast_transform() {
assert_eq!(attr17.attr_type.to_string(), "type5");
assert_eq!(attr17.attr_index, 15);

let attr18 = type_into2.attributes.get(&("attr18".into())).unwrap();
assert_eq!(ty18.attr_type.name(), "string");
let ty18: StructAttributeType = ty18.into();
assert_eq!(attr18.attr_name, ty18.attr_name);
assert_eq!(attr18.attr_type, ty18.attr_type);
assert_eq!(attr18.attr_type.to_string(), "string");
assert_eq!(attr18.attr_index, 16);

//=======================
// Common type tests
let pty = Type::Primitive(PrimitiveTypes::U16);
Expand Down

0 comments on commit 020c58f

Please sign in to comment.