Skip to content

Commit 52b54f9

Browse files
authored
Feat: Remove String from AST (#35)
* Remove String from AST. Related to #31 * Updated to new clippy rules for - ast::ExpressionValue::_marker
1 parent b936463 commit 52b54f9

File tree

9 files changed

+8
-56
lines changed

9 files changed

+8
-56
lines changed

Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "semantic-analyzer"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
authors = ["Evgeny Ukhanov <[email protected]>"]
55
description = "Semantic analyzer library for compilers written in Rust for semantic analysis of programming languages AST"
66
keywords = ["compiler", "semantic-analisis", "semantic-alalyzer", "compiler-design", "semantic"]
@@ -13,11 +13,6 @@ repository = "https://github.com/mrLSD/semantic-analyzer-rs"
1313
[lib]
1414
doctest = false
1515

16-
# It requieres MSRV: 1.74
17-
# [lints.clippy]
18-
# pedantic = "deny"
19-
# nursery = "deny"
20-
2116
[dependencies]
2217
nom_locate = "4.2"
2318
serde = { version = "1", features = ["derive"], optional = true }

src/ast.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ pub enum PrimitiveTypes {
327327
I64,
328328
F32,
329329
F64,
330-
String,
331330
Bool,
332331
Char,
333332
Ptr,
@@ -347,7 +346,6 @@ impl GetName for PrimitiveTypes {
347346
Self::I64 => "i64".to_string(),
348347
Self::F32 => "f32".to_string(),
349348
Self::F64 => "f64".to_string(),
350-
Self::String => "string".to_string(),
351349
Self::Bool => "bool".to_string(),
352350
Self::Char => "char".to_string(),
353351
Self::Ptr => "ptr".to_string(),
@@ -589,7 +587,6 @@ pub enum PrimitiveValue {
589587
I64(i64),
590588
F32(f32),
591589
F64(f64),
592-
String(String),
593590
Bool(bool),
594591
Char(char),
595592
Ptr,
@@ -610,7 +607,6 @@ impl PrimitiveValue {
610607
Self::I64(_) => Type::Primitive(PrimitiveTypes::I64),
611608
Self::F32(_) => Type::Primitive(PrimitiveTypes::F32),
612609
Self::F64(_) => Type::Primitive(PrimitiveTypes::F64),
613-
Self::String(_) => Type::Primitive(PrimitiveTypes::String),
614610
Self::Char(_) => Type::Primitive(PrimitiveTypes::Char),
615611
Self::Bool(_) => Type::Primitive(PrimitiveTypes::Bool),
616612
Self::Ptr => Type::Primitive(PrimitiveTypes::Ptr),
@@ -649,7 +645,8 @@ pub enum ExpressionValue<'a, I: SemanticContextInstruction, E: ExtendedExpressio
649645
/// Extended expression
650646
ExtendedExpression(Box<E>),
651647
#[cfg_attr(feature = "codec", serde(skip))]
652-
_Marker(Infallible, PhantomData<I>),
648+
#[allow(non_camel_case_types)]
649+
_marker(Infallible, PhantomData<I>),
653650
}
654651

655652
/// `ExpressionOperations` expression operation element of AST.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(clippy::pedantic, clippy::nursery)]
1+
#![deny(clippy::pedantic, clippy::nursery, clippy::as_conversions)]
22
#![allow(clippy::module_name_repetitions, clippy::doc_lazy_continuation)]
33
//! # Semantic Analyzer
44
//! The semantic analyzer consists of the following basic elements:

src/semantic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ where
12401240
// If expression return error immediately return error
12411241
// because next analyzer should use success result.
12421242
let right_value = match &right_expression.expression_value {
1243-
ast::ExpressionValue::_Marker(..) => unreachable!(),
1243+
ast::ExpressionValue::_marker(..) => unreachable!(),
12441244
// Check is expression Value entity
12451245
ast::ExpressionValue::ValueName(value) => {
12461246
// Get value from block state

src/types/expression.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ impl<I: SemanticContextInstruction, E: ExtendedExpression<I>> From<ast::Expressi
8585
{
8686
fn from(value: ast::ExpressionValue<'_, I, E>) -> Self {
8787
match value {
88-
ast::ExpressionValue::_Marker(..) => unreachable!(),
88+
#[allow(unreachable_patterns)]
89+
ast::ExpressionValue::_marker(..) => unreachable!(),
8990
ast::ExpressionValue::ValueName(v) => Self::ValueName(v.into()),
9091
ast::ExpressionValue::PrimitiveValue(v) => Self::PrimitiveValue(v.into()),
9192
ast::ExpressionValue::StructValue(v) => Self::StructValue(v.into()),

src/types/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ pub enum PrimitiveValue {
415415
F32(f32),
416416
F64(f64),
417417
Bool(bool),
418-
String(String),
419418
Char(char),
420419
Ptr,
421420
None,
@@ -434,7 +433,6 @@ impl From<ast::PrimitiveValue> for PrimitiveValue {
434433
ast::PrimitiveValue::I64(v) => Self::I64(v),
435434
ast::PrimitiveValue::F32(v) => Self::F32(v),
436435
ast::PrimitiveValue::F64(v) => Self::F64(v),
437-
ast::PrimitiveValue::String(v) => Self::String(v),
438436
ast::PrimitiveValue::Bool(v) => Self::Bool(v),
439437
ast::PrimitiveValue::Char(v) => Self::Char(v),
440438
ast::PrimitiveValue::Ptr => Self::Ptr,
@@ -457,7 +455,6 @@ impl Display for PrimitiveValue {
457455
Self::F32(val) => val.clone().to_string(),
458456
Self::F64(val) => val.clone().to_string(),
459457
Self::Bool(val) => val.to_string(),
460-
Self::String(s) => s.clone(),
461458
Self::Char(c) => format!("{c}"),
462459
Self::Ptr => "ptr".to_string(),
463460
Self::None => "None".to_string(),

src/types/types.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ pub enum PrimitiveTypes {
155155
I64,
156156
F32,
157157
F64,
158-
String,
159158
Bool,
160159
Char,
161160
Ptr,
@@ -175,7 +174,6 @@ impl Display for PrimitiveTypes {
175174
Self::I64 => "i64",
176175
Self::F32 => "f32",
177176
Self::F64 => "f64",
178-
Self::String => "string",
179177
Self::Bool => "bool",
180178
Self::Char => "char",
181179
Self::Ptr => "ptr",
@@ -198,7 +196,6 @@ impl From<ast::PrimitiveTypes> for PrimitiveTypes {
198196
ast::PrimitiveTypes::I64 => Self::I64,
199197
ast::PrimitiveTypes::F32 => Self::F32,
200198
ast::PrimitiveTypes::F64 => Self::F64,
201-
ast::PrimitiveTypes::String => Self::String,
202199
ast::PrimitiveTypes::Bool => Self::Bool,
203200
ast::PrimitiveTypes::Char => Self::Char,
204201
ast::PrimitiveTypes::Ptr => Self::Ptr,

tests/expressions_tests.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -289,28 +289,6 @@ fn expression_ast_transform_primitive_value_f64() {
289289
assert_eq!(expr.to_string(), "3.1");
290290
}
291291

292-
#[test]
293-
fn expression_ast_transform_primitive_value_string() {
294-
let test_res = "test".to_string();
295-
let val = ast::PrimitiveValue::String(test_res.clone());
296-
assert_eq!(
297-
val.get_type(),
298-
ast::Type::Primitive(ast::PrimitiveTypes::String)
299-
);
300-
let expr_val: PrimitiveValue = val.clone().into();
301-
assert_eq!(PrimitiveValue::String(test_res.clone()), expr_val);
302-
assert_eq!(expr_val.to_string(), test_res);
303-
let expr: Expression = ast::Expression {
304-
expression_value: ast::ExpressionValue::<
305-
CustomExpressionInstruction,
306-
CustomExpression<CustomExpressionInstruction>,
307-
>::PrimitiveValue(val),
308-
operation: None,
309-
}
310-
.into();
311-
assert_eq!(expr.to_string(), test_res);
312-
}
313-
314292
#[test]
315293
fn expression_ast_transform_primitive_value_bool() {
316294
let val = ast::PrimitiveValue::Bool(true);

tests/types_tests.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ fn types_ast_transform() {
9292
attributes: vec![],
9393
}),
9494
};
95-
let ty18 = ast::StructType {
96-
attr_name: Ident::new("attr18"),
97-
attr_type: ast::Type::Primitive(ast::PrimitiveTypes::String),
98-
};
9995
let type_ast = ast::StructTypes {
10096
name: Ident::new("type2"),
10197
attributes: vec![
@@ -115,12 +111,11 @@ fn types_ast_transform() {
115111
ty15.clone(),
116112
ty16.clone(),
117113
ty17.clone(),
118-
ty18.clone(),
119114
],
120115
};
121116
let type_into2: StructTypes = type_ast.clone().into();
122117
assert_eq!(type_into2.name, "type2");
123-
assert_eq!(type_into2.attributes.len(), 17);
118+
assert_eq!(type_into2.attributes.len(), 16);
124119

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

261-
let attr18 = type_into2.attributes.get(&("attr18".into())).unwrap();
262-
assert_eq!(ty18.attr_type.name(), "string");
263-
let ty18: StructAttributeType = ty18.into();
264-
assert_eq!(attr18.attr_name, ty18.attr_name);
265-
assert_eq!(attr18.attr_type, ty18.attr_type);
266-
assert_eq!(attr18.attr_type.to_string(), "string");
267-
assert_eq!(attr18.attr_index, 16);
268-
269256
//=======================
270257
// Common type tests
271258
let pty = Type::Primitive(PrimitiveTypes::U16);

0 commit comments

Comments
 (0)