Skip to content

Commit f1380e7

Browse files
committed
Moved variable_info from parser to linter
1 parent 4a83651 commit f1380e7

26 files changed

Lines changed: 76 additions & 180 deletions

File tree

rusty_basic/src/instruction_generator/expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rusty_common::*;
2+
use rusty_linter::VariableInfo;
23
use rusty_parser::*;
34
use rusty_variant::Variant;
45

rusty_linter/src/built_ins/arg_validation.rs

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rusty_common::{AtPos, Position};
22
use rusty_parser::{
3-
Expression, ExpressionPos, ExpressionTrait, ExpressionType, Expressions, HasExpressionType, TypeQualifier, VariableInfo
3+
Expression, ExpressionPos, ExpressionTrait, ExpressionType, Expressions, HasExpressionType, TypeQualifier
44
};
55

66
use crate::core::{CanCastTo, LintError, LintErrorPos};
@@ -105,33 +105,16 @@ impl ArgValidation for Expressions {
105105

106106
fn require_string_variable(&self, index: usize) -> Result<(), LintErrorPos> {
107107
match self.expr(index) {
108-
Expression::Variable(
109-
_,
110-
VariableInfo {
111-
expression_type: ExpressionType::BuiltIn(TypeQualifier::DollarString),
112-
..
113-
},
114-
) => Ok(()),
108+
Expression::Variable(_, ExpressionType::BuiltIn(TypeQualifier::DollarString)) => Ok(()),
115109
Expression::Variable(_, _) => Err(LintError::ArgumentTypeMismatch.at(&self[index])),
116110
_ => Err(LintError::VariableRequired.at(&self[index])),
117111
}
118112
}
119113

120114
fn require_string_ref(&self, index: usize) -> Result<(), LintErrorPos> {
121115
match self.expr(index) {
122-
Expression::Variable(
123-
_,
124-
VariableInfo {
125-
expression_type, ..
126-
},
127-
)
128-
| Expression::ArrayElement(
129-
_,
130-
_,
131-
VariableInfo {
132-
expression_type, ..
133-
},
134-
)
116+
Expression::Variable(_, expression_type)
117+
| Expression::ArrayElement(_, _, expression_type)
135118
| Expression::Property(_, _, expression_type) => {
136119
if expression_type.can_cast_to(&TypeQualifier::DollarString) {
137120
Ok(())
@@ -145,19 +128,8 @@ impl ArgValidation for Expressions {
145128

146129
fn require_variable_of_built_in_type(&self, index: usize) -> Result<(), LintErrorPos> {
147130
match self.expr(index) {
148-
Expression::Variable(
149-
_,
150-
VariableInfo {
151-
expression_type, ..
152-
},
153-
)
154-
| Expression::ArrayElement(
155-
_,
156-
_,
157-
VariableInfo {
158-
expression_type, ..
159-
},
160-
)
131+
Expression::Variable(_, expression_type)
132+
| Expression::ArrayElement(_, _, expression_type)
161133
| Expression::Property(_, _, expression_type) => match expression_type {
162134
ExpressionType::BuiltIn(_) | ExpressionType::FixedLengthString(_) => Ok(()),
163135
_ => Err(LintError::ArgumentTypeMismatch.at(&self[index])),

rusty_linter/src/built_ins/lbound.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rusty_common::{AtPos, Position, Positioned};
2-
use rusty_parser::{Expression, ExpressionType, Expressions, TypeQualifier, VariableInfo};
2+
use rusty_parser::{Expression, ExpressionType, Expressions, TypeQualifier};
33

44
use crate::core::{CanCastTo, LintError, LintErrorPos};
55

@@ -14,14 +14,7 @@ pub fn lint(args: &Expressions, pos: Position) -> Result<(), LintErrorPos> {
1414
element: first,
1515
pos: first_pos,
1616
} = args.first().unwrap();
17-
if let Expression::Variable(
18-
_,
19-
VariableInfo {
20-
expression_type: ExpressionType::Array(_),
21-
..
22-
},
23-
) = first
24-
{
17+
if let Expression::Variable(_, ExpressionType::Array(_)) = first {
2518
if args.len() == 2 {
2619
if args[1].can_cast_to(&TypeQualifier::PercentInteger) {
2720
Ok(())

rusty_linter/src/converter/dim_rules/redim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rusty_parser::*;
33

44
use crate::converter::common::{Convertible, DimNameState};
55
use crate::core::{
6-
IntoTypeQualifier, LintError, LintErrorPos, LinterContext, ValidateStringLength
6+
IntoTypeQualifier, LintError, LintErrorPos, LinterContext, RedimInfo, ValidateStringLength, VariableInfo
77
};
88

99
pub fn on_redim_type(

rusty_linter/src/converter/expr_rules/function.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use rusty_common::{AtPos, Position};
2-
use rusty_parser::{
3-
AsBareName, BareName, Expression, ExpressionType, Expressions, Name, VariableInfo
4-
};
2+
use rusty_parser::{AsBareName, BareName, Expression, ExpressionType, Expressions, Name};
53

64
use crate::converter::common::{ConvertibleIn, ExprContext, ExprContextPos};
75
use crate::converter::expr_rules::qualify_name::*;
86
use crate::core::{
9-
IntoQualified, IntoTypeQualifier, LintError, LintErrorPos, LintResult, LinterContext
7+
IntoQualified, IntoTypeQualifier, LintError, LintErrorPos, LintResult, LinterContext, VariableInfo
108
};
119

1210
pub fn convert(
@@ -116,9 +114,7 @@ impl FuncResolve for ExistingArrayWithParenthesis {
116114
let converted_args = args.convert_in(ctx, extra.element)?;
117115
// convert name
118116
let VariableInfo {
119-
expression_type,
120-
shared,
121-
redim_info,
117+
expression_type, ..
122118
} = self.var_info.clone().unwrap();
123119
match expression_type {
124120
ExpressionType::Array(element_type) => {
@@ -128,11 +124,7 @@ impl FuncResolve for ExistingArrayWithParenthesis {
128124
let result_expr = Expression::ArrayElement(
129125
converted_name,
130126
converted_args,
131-
VariableInfo {
132-
expression_type: element_type.as_ref().clone(),
133-
shared,
134-
redim_info,
135-
},
127+
element_type.as_ref().clone(),
136128
);
137129
Ok(result_expr)
138130
}

rusty_linter/src/converter/expr_rules/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ impl ConvertibleIn<ExprContextPos> for Expression {
6464
binary::convert(ctx, extra, binary_operator, *left, *right)
6565
}
6666
// variables
67-
Self::Variable(name, variable_info) => {
68-
variable::convert(ctx, extra, name, variable_info)
67+
Self::Variable(name, expression_type) => {
68+
variable::convert(ctx, extra, name, expression_type)
6969
}
70-
Self::ArrayElement(_name, _indices, _variable_info) => {
70+
Self::ArrayElement(_name, _indices, _expression_type) => {
7171
panic!(
7272
"Parser is not supposed to produce any ArrayElement expressions, only FunctionCall"
7373
)

rusty_linter/src/converter/expr_rules/property.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rusty_common::{AtPos, Position, Positioned};
22
use rusty_parser::{
3-
AsBareName, BareName, ElementType, Expression, ExpressionType, HasExpressionType, Name, ToBareName, UserDefinedType, VariableInfo
3+
AsBareName, BareName, ElementType, Expression, ExpressionType, HasExpressionType, Name, ToBareName, UserDefinedType
44
};
55

66
use crate::converter::common::{ConvertibleIn, ExprContext, ExprContextPos};
@@ -48,12 +48,7 @@ pub fn convert(
4848

4949
// functions cannot return udf so no need to check them
5050
match &resolved_left_side {
51-
Expression::Variable(
52-
_name,
53-
VariableInfo {
54-
expression_type, ..
55-
},
56-
) => {
51+
Expression::Variable(_name, expression_type) => {
5752
let temp_expression_type = expression_type.clone();
5853
existing_property_expression_type(
5954
ctx,
@@ -64,13 +59,7 @@ pub fn convert(
6459
true,
6560
)
6661
}
67-
Expression::ArrayElement(
68-
_name,
69-
_indices,
70-
VariableInfo {
71-
expression_type, ..
72-
},
73-
) => {
62+
Expression::ArrayElement(_name, _indices, expression_type) => {
7463
let temp_expression_type = expression_type.clone();
7564
existing_property_expression_type(
7665
ctx,

rusty_linter/src/converter/expr_rules/variable.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use rusty_common::{AtPos, Position};
22
use rusty_parser::{
3-
AsBareName, BuiltInFunction, BuiltInStyle, DimType, Expression, ExpressionType, Name, TypeQualifier, VariableInfo
3+
AsBareName, BuiltInFunction, BuiltInStyle, DimType, Expression, ExpressionType, Name, TypeQualifier
44
};
55
use rusty_variant::Variant;
66

77
use crate::converter::common::{ExprContext, ExprContextPos};
88
use crate::converter::expr_rules::qualify_name::*;
99
use crate::core::{
10-
ConstLookup, IntoQualified, IntoTypeQualifier, LintError, LintErrorPos, LintResult, LinterContext, qualifier_of_const_variant
10+
ConstLookup, IntoQualified, IntoTypeQualifier, LintError, LintErrorPos, LintResult, LinterContext, VariableInfo, qualifier_of_const_variant
1111
};
1212

1313
pub fn convert(
1414
ctx: &mut LinterContext,
1515
extra: ExprContextPos,
1616
name: Name,
17-
variable_info: VariableInfo,
17+
expression_type: ExpressionType,
1818
) -> Result<Expression, LintErrorPos> {
1919
// validation rules
2020
validate(ctx, &name, extra.pos)?;
@@ -42,7 +42,7 @@ pub fn convert(
4242
Ok(add_as_new_implicit_var(ctx, extra, name))
4343
} else {
4444
// repack as unresolved
45-
Ok(Expression::Variable(name, variable_info))
45+
Ok(Expression::Variable(name, expression_type))
4646
}
4747
}
4848

@@ -70,12 +70,12 @@ pub fn add_as_new_implicit_var(
7070
None,
7171
);
7272

73-
let var_info = VariableInfo::new_built_in(q, false);
73+
let expression_type = ExpressionType::BuiltIn(q);
7474
let pos = extra.pos;
7575
ctx.names
7676
.get_implicit_vars_mut()
7777
.push(resolved_name.clone().demand_qualified().at_pos(pos));
78-
Expression::Variable(resolved_name, var_info)
78+
Expression::Variable(resolved_name, expression_type)
7979
}
8080

8181
pub trait VarResolve {
@@ -114,9 +114,9 @@ impl VarResolve for ExistingVar {
114114
name: Name,
115115
) -> Result<Expression, LintErrorPos> {
116116
let variable_info = self.var_info.clone().unwrap();
117-
let expression_type = &variable_info.expression_type;
118-
let converted_name = qualify_name(expression_type, name).with_err_at(&extra.pos)?;
119-
Ok(Expression::Variable(converted_name, variable_info))
117+
let expression_type = variable_info.expression_type;
118+
let converted_name = qualify_name(&expression_type, name).with_err_at(&extra.pos)?;
119+
Ok(Expression::Variable(converted_name, expression_type))
120120
}
121121
}
122122

@@ -211,15 +211,15 @@ impl VarResolve for AssignToFunction {
211211
if ctx.names.is_in_function(name.as_bare_name()) {
212212
let converted_name = try_qualify(name, function_qualifier).with_err_at(&extra.pos)?;
213213
let expr_type = ExpressionType::BuiltIn(function_qualifier);
214-
let variable_info = VariableInfo::new_local(expr_type);
214+
let variable_info = VariableInfo::new_local(expr_type.clone());
215215

216216
// store this in the name context too to make it easier for instruction generator
217217
// TODO add unit test
218218
// TODO what if the name already exists?
219219
ctx.names
220-
.insert_compact(converted_name.as_bare_name().clone(), variable_info.clone());
220+
.insert_compact(converted_name.as_bare_name().clone(), variable_info);
221221

222-
let expr = Expression::Variable(converted_name, variable_info);
222+
let expr = Expression::Variable(converted_name, expr_type);
223223

224224
Ok(expr)
225225
} else {

rusty_linter/src/core/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod signature;
1212
mod string_length;
1313
mod type_resolver;
1414
mod type_resolver_impl;
15+
mod variable_info;
1516
mod visitor;
1617

1718
pub use self::can_cast_to::*;
@@ -28,4 +29,5 @@ pub use self::signature::*;
2829
pub use self::string_length::*;
2930
pub use self::type_resolver::*;
3031
pub use self::type_resolver_impl::*;
32+
pub use self::variable_info::*;
3133
pub use self::visitor::*;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{BareName, ExpressionType, TypeQualifier};
1+
use rusty_parser::{BareName, ExpressionType, TypeQualifier};
22

33
/// Additional info for variable expression
44
#[derive(Clone, Debug, PartialEq)]

0 commit comments

Comments
 (0)