Skip to content

Commit 20525f7

Browse files
committed
Rename linter Context to LinterContext
1 parent 0df96d8 commit 20525f7

36 files changed

Lines changed: 173 additions & 145 deletions

rusty_basic/src/bin/rusty_basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs::File;
33

44
use rusty_basic::instruction_generator::{generate_instructions, unwrap_linter_context};
55
use rusty_basic::interpreter::{InterpreterTrait, new_default_interpreter};
6-
use rusty_linter::{Context, lint};
6+
use rusty_linter::{LinterContext, lint};
77
use rusty_parser::{Program, parse_main_file};
88

99
fn main() {
@@ -33,7 +33,7 @@ fn on_parsed(program: Program, run_options: RunOptions) {
3333
}
3434
}
3535

36-
fn on_linted(program: Program, linter_context: Context, run_options: RunOptions) {
36+
fn on_linted(program: Program, linter_context: LinterContext, run_options: RunOptions) {
3737
let (linter_names, user_defined_types) = unwrap_linter_context(linter_context);
3838
let instruction_generator_result = generate_instructions(program, linter_names);
3939
let mut interpreter = new_default_interpreter(user_defined_types);

rusty_basic/src/instruction_generator/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rusty_common::{AtPos, CaseInsensitiveString, Position, Positioned};
2-
use rusty_linter::{Context, Names, ScopeName};
2+
use rusty_linter::{LinterContext, Names, ScopeName};
33
use rusty_parser::{
44
Assignment, BareName, BuiltInFunction, BuiltInSub, DimVar, Expression, ExpressionType, FileHandle, FunctionImplementation, GlobalStatement, HasExpressionType, Name, Parameter, Program, Statement, Statements, SubImplementation, TypeQualifier, UserDefinedTypes
55
};
@@ -11,7 +11,7 @@ use crate::instruction_generator::subprogram_info::{
1111
SubprogramInfoCollector, SubprogramInfoRepository
1212
};
1313

14-
pub fn unwrap_linter_context(linter_context: Context) -> (Names, UserDefinedTypes) {
14+
pub fn unwrap_linter_context(linter_context: LinterContext) -> (Names, UserDefinedTypes) {
1515
(linter_context.names, linter_context.user_defined_types)
1616
}
1717

rusty_linter/src/converter/common/convertible.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use rusty_common::{AtPos, Position, Positioned};
22

3-
use crate::core::{Context, LintErrorPos};
3+
use crate::core::{LintErrorPos, LinterContext};
44

55
/// Convert from the current type into the target type O.
66
/// By default, O is the same as the current type.
77
pub trait Convertible<O = Self>: Sized {
8-
fn convert(self, ctx: &mut Context) -> Result<O, LintErrorPos>;
8+
fn convert(self, ctx: &mut LinterContext) -> Result<O, LintErrorPos>;
99
}
1010

1111
// Blanket implementation for Option
@@ -14,7 +14,7 @@ impl<T, O> Convertible<Option<O>> for Option<T>
1414
where
1515
T: Convertible<O>,
1616
{
17-
fn convert(self, ctx: &mut Context) -> Result<Option<O>, LintErrorPos> {
17+
fn convert(self, ctx: &mut LinterContext) -> Result<Option<O>, LintErrorPos> {
1818
match self {
1919
Some(t) => t.convert(ctx).map(Some),
2020
None => Ok(None),
@@ -28,7 +28,7 @@ impl<T, O> Convertible<Vec<O>> for Vec<T>
2828
where
2929
T: Convertible<O>,
3030
{
31-
fn convert(self, ctx: &mut Context) -> Result<Vec<O>, LintErrorPos> {
31+
fn convert(self, ctx: &mut LinterContext) -> Result<Vec<O>, LintErrorPos> {
3232
self.into_iter().map(|t| t.convert(ctx)).collect()
3333
}
3434
}
@@ -39,7 +39,7 @@ impl<T, O> Convertible<Positioned<O>> for Positioned<T>
3939
where
4040
T: ConvertibleIn<Position, O>,
4141
{
42-
fn convert(self, ctx: &mut Context) -> Result<Positioned<O>, LintErrorPos> {
42+
fn convert(self, ctx: &mut LinterContext) -> Result<Positioned<O>, LintErrorPos> {
4343
let Self {
4444
element: statement,
4545
pos,
@@ -54,9 +54,9 @@ where
5454
/// using additional information in the value U.
5555
/// By default, O is the same as the current type.
5656
pub trait ConvertibleIn<U, O = Self>: Sized {
57-
fn convert_in(self, ctx: &mut Context, value: U) -> Result<O, LintErrorPos>;
57+
fn convert_in(self, ctx: &mut LinterContext, value: U) -> Result<O, LintErrorPos>;
5858

59-
fn convert_in_default(self, ctx: &mut Context) -> Result<O, LintErrorPos>
59+
fn convert_in_default(self, ctx: &mut LinterContext) -> Result<O, LintErrorPos>
6060
where
6161
U: Default,
6262
{
@@ -70,7 +70,7 @@ impl<U, T, O> ConvertibleIn<U, Option<O>> for Option<T>
7070
where
7171
T: ConvertibleIn<U, O>,
7272
{
73-
fn convert_in(self, ctx: &mut Context, extra: U) -> Result<Option<O>, LintErrorPos> {
73+
fn convert_in(self, ctx: &mut LinterContext, extra: U) -> Result<Option<O>, LintErrorPos> {
7474
match self {
7575
Some(t) => t.convert_in(ctx, extra).map(Some),
7676
None => Ok(None),
@@ -85,7 +85,7 @@ where
8585
T: ConvertibleIn<U, O>,
8686
U: Clone,
8787
{
88-
fn convert_in(self, ctx: &mut Context, extra: U) -> Result<Vec<O>, LintErrorPos> {
88+
fn convert_in(self, ctx: &mut LinterContext, extra: U) -> Result<Vec<O>, LintErrorPos> {
8989
self.into_iter()
9090
.map(|t| t.convert_in(ctx, extra.clone()))
9191
.collect()

rusty_linter/src/converter/common/program_rules.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use rusty_parser::{
44
};
55

66
use crate::converter::common::{Convertible, ConvertibleIn};
7-
use crate::core::{Context, IntoQualified, LintErrorPos, ScopeName};
7+
use crate::core::{IntoQualified, LintErrorPos, LinterContext, ScopeName};
88
use crate::names::ImplicitVars;
99

1010
impl Convertible for Program {
11-
fn convert(self, ctx: &mut Context) -> Result<Self, LintErrorPos> {
11+
fn convert(self, ctx: &mut LinterContext) -> Result<Self, LintErrorPos> {
1212
// collect the global statements
1313
let mut global_statements: Self = vec![];
1414
for Positioned { element, pos } in self {
@@ -36,7 +36,7 @@ impl Convertible for Program {
3636
impl ConvertibleIn<Position, Vec<GlobalStatementPos>> for GlobalStatement {
3737
fn convert_in(
3838
self,
39-
ctx: &mut Context,
39+
ctx: &mut LinterContext,
4040
pos: Position,
4141
) -> Result<Vec<GlobalStatementPos>, LintErrorPos> {
4242
match self {
@@ -59,7 +59,7 @@ impl ConvertibleIn<Position, Vec<GlobalStatementPos>> for GlobalStatement {
5959

6060
fn on_function_implementation(
6161
function_implementation: FunctionImplementation,
62-
ctx: &mut Context,
62+
ctx: &mut LinterContext,
6363
) -> Result<FunctionImplementation, LintErrorPos> {
6464
let FunctionImplementation {
6565
name: Positioned {
@@ -93,7 +93,7 @@ fn on_function_implementation(
9393

9494
fn on_sub_implementation(
9595
sub_implementation: SubImplementation,
96-
ctx: &mut Context,
96+
ctx: &mut LinterContext,
9797
) -> Result<SubImplementation, LintErrorPos> {
9898
let SubImplementation {
9999
name,
@@ -127,7 +127,7 @@ fn on_sub_implementation(
127127
// A = B + C
128128
fn convert_block_hoisting_implicit_vars_and_pop_scope(
129129
statements: Statements,
130-
ctx: &mut Context,
130+
ctx: &mut LinterContext,
131131
) -> Result<Statements, LintErrorPos> {
132132
let mut result = statements.convert(ctx)?;
133133
let implicit_vars = collect_implicit_vars_and_pop_scope(ctx);
@@ -147,7 +147,7 @@ fn convert_block_hoisting_implicit_vars_and_pop_scope(
147147

148148
fn on_statement(
149149
statement: Statement,
150-
ctx: &mut Context,
150+
ctx: &mut LinterContext,
151151
pos: Position,
152152
) -> Result<Vec<GlobalStatementPos>, LintErrorPos> {
153153
// a statement might be converted into multiple statements due to implicit vars
@@ -159,7 +159,7 @@ fn on_statement(
159159
.collect())
160160
}
161161

162-
fn collect_implicit_vars_and_pop_scope(ctx: &mut Context) -> ImplicitVars {
162+
fn collect_implicit_vars_and_pop_scope(ctx: &mut LinterContext) -> ImplicitVars {
163163
// collect implicit vars
164164
let mut implicit_vars = ImplicitVars::new();
165165
implicit_vars.append(ctx.names.get_implicit_vars_mut());

rusty_linter/src/converter/dim_rules/array_dimension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use rusty_parser::ArrayDimension;
22

33
use crate::converter::common::{Convertible, ConvertibleIn};
4-
use crate::core::{Context, LintErrorPos};
4+
use crate::core::{LintErrorPos, LinterContext};
55

66
impl Convertible for ArrayDimension {
7-
fn convert(self, ctx: &mut Context) -> Result<Self, LintErrorPos> {
7+
fn convert(self, ctx: &mut LinterContext) -> Result<Self, LintErrorPos> {
88
Ok(Self {
99
lbound: self.lbound.convert_in_default(ctx)?,
1010
ubound: self.ubound.convert_in_default(ctx)?,

rusty_linter/src/converter/dim_rules/dim_type_rules.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use rusty_common::*;
22
use rusty_parser::*;
33

44
use crate::converter::common::{Convertible, DimContext, DimNameState};
5-
use crate::core::{Context, IntoTypeQualifier, LintError, LintErrorPos, ValidateStringLength};
5+
use crate::core::{
6+
IntoTypeQualifier, LintError, LintErrorPos, LinterContext, ValidateStringLength
7+
};
68

79
pub fn on_dim_type(
810
dim_type: DimType,
911
bare_name: &BareName,
10-
ctx: &mut Context,
12+
ctx: &mut LinterContext,
1113
extra: DimNameState,
1214
) -> Result<DimType, LintErrorPos> {
1315
match dim_type {
@@ -27,7 +29,7 @@ pub fn on_dim_type(
2729
}
2830

2931
pub fn bare_to_dim_type<T: VarType>(
30-
ctx: &mut Context,
32+
ctx: &mut LinterContext,
3133
bare_name: &BareName,
3234
pos: Position,
3335
) -> Result<T, LintErrorPos> {
@@ -37,7 +39,7 @@ pub fn bare_to_dim_type<T: VarType>(
3739
}
3840

3941
fn require_compact_can_be_defined(
40-
ctx: &Context,
42+
ctx: &LinterContext,
4143
bare_name: &BareName,
4244
q: TypeQualifier,
4345
pos: Position,
@@ -60,7 +62,7 @@ fn require_compact_can_be_defined(
6062
}
6163

6264
pub fn built_in_to_dim_type<T: VarType>(
63-
ctx: &mut Context,
65+
ctx: &mut LinterContext,
6466
bare_name: &BareName,
6567
q: TypeQualifier,
6668
built_in_style: BuiltInStyle,
@@ -79,7 +81,7 @@ pub fn built_in_to_dim_type<T: VarType>(
7981
}
8082

8183
fn require_extended_can_be_defined(
82-
ctx: &Context,
84+
ctx: &LinterContext,
8385
bare_name: &BareName,
8486
pos: Position,
8587
) -> Result<(), LintErrorPos> {
@@ -90,7 +92,7 @@ fn require_extended_can_be_defined(
9092
}
9193

9294
fn fixed_length_string_to_dim_type(
93-
ctx: &mut Context,
95+
ctx: &mut LinterContext,
9496
bare_name: &BareName,
9597
length_expression: &ExpressionPos,
9698
) -> Result<DimType, LintErrorPos> {
@@ -103,7 +105,7 @@ fn fixed_length_string_to_dim_type(
103105
}
104106

105107
pub fn user_defined_to_dim_type<T: VarType>(
106-
ctx: &mut Context,
108+
ctx: &mut LinterContext,
107109
bare_name: &BareName,
108110
user_defined_type: BareNamePos,
109111
pos: Position,
@@ -113,7 +115,7 @@ pub fn user_defined_to_dim_type<T: VarType>(
113115
}
114116

115117
fn array_to_dim_type(
116-
ctx: &mut Context,
118+
ctx: &mut LinterContext,
117119
extra: DimNameState,
118120
bare_name: &BareName,
119121
array_dimensions: ArrayDimensions,

rusty_linter/src/converter/dim_rules/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ use crate::converter::common::{ConvertibleIn, DimContext, DimNameState};
55
use crate::converter::dim_rules::dim_type_rules::on_dim_type;
66
use crate::converter::dim_rules::redim::on_redim_type;
77
use crate::converter::dim_rules::validation;
8-
use crate::core::{Context, LintError, LintErrorPos};
8+
use crate::core::{LintError, LintErrorPos, LinterContext};
99

1010
impl ConvertibleIn<DimContext> for DimList {
11-
fn convert_in(self, ctx: &mut Context, dim_context: DimContext) -> Result<Self, LintErrorPos> {
11+
fn convert_in(
12+
self,
13+
ctx: &mut LinterContext,
14+
dim_context: DimContext,
15+
) -> Result<Self, LintErrorPos> {
1216
let Self { variables, shared } = self;
1317
let mut new_variables = DimVars::new();
1418
for Positioned { element, pos } in variables {
@@ -28,7 +32,11 @@ impl ConvertibleIn<DimContext> for DimList {
2832
}
2933

3034
impl ConvertibleIn<DimNameState> for DimVar {
31-
fn convert_in(self, ctx: &mut Context, extra: DimNameState) -> Result<Self, LintErrorPos> {
35+
fn convert_in(
36+
self,
37+
ctx: &mut LinterContext,
38+
extra: DimNameState,
39+
) -> Result<Self, LintErrorPos> {
3240
validation::validate(&self, ctx, extra.pos)?;
3341
let shared = extra.shared;
3442
shared_illegal_in_sub_function(ctx, shared, extra.pos)?;
@@ -46,7 +54,7 @@ impl ConvertibleIn<DimNameState> for DimVar {
4654
}
4755

4856
fn shared_illegal_in_sub_function(
49-
ctx: &Context,
57+
ctx: &LinterContext,
5058
shared: bool,
5159
pos: Position,
5260
) -> Result<(), LintErrorPos> {

rusty_linter/src/converter/dim_rules/param_rules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use rusty_parser::Parameter;
44
use crate::converter::common::ConvertibleIn;
55
use crate::converter::dim_rules::param_type_rules::on_param_type;
66
use crate::converter::dim_rules::validation;
7-
use crate::core::{Context, LintErrorPos};
7+
use crate::core::{LintErrorPos, LinterContext};
88

99
impl ConvertibleIn<Position> for Parameter {
10-
fn convert_in(self, ctx: &mut Context, pos: Position) -> Result<Self, LintErrorPos> {
10+
fn convert_in(self, ctx: &mut LinterContext, pos: Position) -> Result<Self, LintErrorPos> {
1111
validation::validate(&self, ctx, pos)?;
1212
let (bare_name, var_type) = self.into();
1313
let var_type = on_param_type(var_type, &bare_name, ctx, pos)?;

rusty_linter/src/converter/dim_rules/param_type_rules.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use rusty_common::Position;
22
use rusty_parser::{BareName, ParamType};
33

44
use crate::converter::dim_rules::dim_type_rules;
5-
use crate::core::{Context, LintErrorPos};
5+
use crate::core::{LintErrorPos, LinterContext};
66

77
pub fn on_param_type(
88
dim_type: ParamType,
99
bare_name: &BareName,
10-
ctx: &mut Context,
10+
ctx: &mut LinterContext,
1111
pos: Position,
1212
) -> Result<ParamType, LintErrorPos> {
1313
match dim_type {
@@ -25,7 +25,7 @@ pub fn on_param_type(
2525
}
2626

2727
fn param_array_to_param_type(
28-
ctx: &mut Context,
28+
ctx: &mut LinterContext,
2929
pos: Position,
3030
bare_name: &BareName,
3131
element_type: ParamType,

0 commit comments

Comments
 (0)