|
1 | 1 | use rusty_common::{AtPos, Position}; |
2 | 2 | use rusty_parser::{ |
3 | | - AsBareName, BuiltInFunction, BuiltInStyle, DimType, Expression, ExpressionType, Name, TypeQualifier, VariableInfo |
| 3 | + AsBareName, BuiltInFunction, BuiltInStyle, DimType, Expression, ExpressionType, Name, TypeQualifier |
4 | 4 | }; |
5 | 5 | use rusty_variant::Variant; |
6 | 6 |
|
7 | 7 | use crate::converter::common::{ExprContext, ExprContextPos}; |
8 | 8 | use crate::converter::expr_rules::qualify_name::*; |
9 | 9 | 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 |
11 | 11 | }; |
12 | 12 |
|
13 | 13 | pub fn convert( |
14 | 14 | ctx: &mut LinterContext, |
15 | 15 | extra: ExprContextPos, |
16 | 16 | name: Name, |
17 | | - variable_info: VariableInfo, |
| 17 | + expression_type: ExpressionType, |
18 | 18 | ) -> Result<Expression, LintErrorPos> { |
19 | 19 | // validation rules |
20 | 20 | validate(ctx, &name, extra.pos)?; |
@@ -42,7 +42,7 @@ pub fn convert( |
42 | 42 | Ok(add_as_new_implicit_var(ctx, extra, name)) |
43 | 43 | } else { |
44 | 44 | // repack as unresolved |
45 | | - Ok(Expression::Variable(name, variable_info)) |
| 45 | + Ok(Expression::Variable(name, expression_type)) |
46 | 46 | } |
47 | 47 | } |
48 | 48 |
|
@@ -70,12 +70,12 @@ pub fn add_as_new_implicit_var( |
70 | 70 | None, |
71 | 71 | ); |
72 | 72 |
|
73 | | - let var_info = VariableInfo::new_built_in(q, false); |
| 73 | + let expression_type = ExpressionType::BuiltIn(q); |
74 | 74 | let pos = extra.pos; |
75 | 75 | ctx.names |
76 | 76 | .get_implicit_vars_mut() |
77 | 77 | .push(resolved_name.clone().demand_qualified().at_pos(pos)); |
78 | | - Expression::Variable(resolved_name, var_info) |
| 78 | + Expression::Variable(resolved_name, expression_type) |
79 | 79 | } |
80 | 80 |
|
81 | 81 | pub trait VarResolve { |
@@ -114,9 +114,9 @@ impl VarResolve for ExistingVar { |
114 | 114 | name: Name, |
115 | 115 | ) -> Result<Expression, LintErrorPos> { |
116 | 116 | 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)) |
120 | 120 | } |
121 | 121 | } |
122 | 122 |
|
@@ -211,15 +211,15 @@ impl VarResolve for AssignToFunction { |
211 | 211 | if ctx.names.is_in_function(name.as_bare_name()) { |
212 | 212 | let converted_name = try_qualify(name, function_qualifier).with_err_at(&extra.pos)?; |
213 | 213 | 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()); |
215 | 215 |
|
216 | 216 | // store this in the name context too to make it easier for instruction generator |
217 | 217 | // TODO add unit test |
218 | 218 | // TODO what if the name already exists? |
219 | 219 | 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); |
221 | 221 |
|
222 | | - let expr = Expression::Variable(converted_name, variable_info); |
| 222 | + let expr = Expression::Variable(converted_name, expr_type); |
223 | 223 |
|
224 | 224 | Ok(expr) |
225 | 225 | } else { |
|
0 commit comments