Skip to content

Commit 2c0367e

Browse files
committed
Move depth to AuxParams struct for node info
1 parent a222dee commit 2c0367e

File tree

6 files changed

+44
-38
lines changed

6 files changed

+44
-38
lines changed

src/analysis/parsing/expression.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ use crate::analysis::structure::expressions::DMLString;
1717
use crate::analysis::{DeclarationSpan, LocalDMLError};
1818

1919

20-
use crate::lint::rules::spacing::{NspFunparArgs,
21-
NspInparenArgs,
22-
NspUnaryArgs,
23-
SpPunctArgs};
24-
use crate::lint::rules::CurrentRules;
20+
use crate::lint::{rules::{spacing::{NspFunparArgs,
21+
NspInparenArgs,
22+
NspUnaryArgs,
23+
SpPunctArgs},
24+
CurrentRules},
25+
AuxParams};
2526

2627
#[derive(Debug, Clone, PartialEq)]
2728
pub struct UnaryExpressionContent {
@@ -36,7 +37,7 @@ impl TreeElement for UnaryExpressionContent {
3637
fn subs(&self) -> TreeElements<'_> {
3738
create_subs!(&self.operation, &self.expr)
3839
}
39-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
40+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
4041
rules.nsp_unary.check(acc, NspUnaryArgs::from_unary_expr(self));
4142
}
4243
}
@@ -70,7 +71,7 @@ impl TreeElement for PostUnaryExpressionContent {
7071
fn subs(&self) -> TreeElements<'_> {
7172
create_subs!(&self.expr, &self.operation)
7273
}
73-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
74+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
7475
rules.nsp_unary.check(acc, NspUnaryArgs::from_postunary_expr(self));
7576
}
7677
}
@@ -208,7 +209,7 @@ impl TreeElement for FunctionCallContent {
208209
noderef, ReferenceKind::Callable));
209210
}
210211
}
211-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
212+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
212213
rules.nsp_funpar.check(acc, NspFunparArgs::from_function_call(self));
213214
rules.nsp_inparen.check(acc, NspInparenArgs::from_function_call(self));
214215
rules.sp_punct.check(acc, SpPunctArgs::from_function_call(self));
@@ -419,7 +420,7 @@ impl TreeElement for IndexContent {
419420
fn subs(&self) -> TreeElements<'_> {
420421
create_subs!(&self.array, &self.lbracket, &self.index, &self.rbracket)
421422
}
422-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
423+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
423424
rules.nsp_inparen.check(acc, NspInparenArgs::from_index(self));
424425
}
425426
}

src/analysis/parsing/statement.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ use crate::analysis::parsing::misc::{Initializer, InitializerContent, CDecl,
2121
ident_filter, objident_filter};
2222
use crate::analysis::parsing::structure::{parse_vardecl, VarDecl};
2323
use crate::analysis::LocalDMLError;
24-
use crate::lint::rules::{CurrentRules,
24+
use crate::lint::{rules::{CurrentRules,
2525
indentation::{IN3Args, IN9Args},
2626
spacing::{NspInparenArgs,
2727
SpBracesArgs,
28-
SpPunctArgs},
29-
};
28+
SpPunctArgs}},
29+
AuxParams};
3030
use crate::vfs::TextFile;
3131

3232
fn statement_contexts(context: &ParseContext)
@@ -141,9 +141,9 @@ impl TreeElement for CompoundContent {
141141
fn subs(&self) -> TreeElements<'_> {
142142
create_subs!(&self.lbrace, &self.statements, &self.rbrace)
143143
}
144-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, depth: &mut u32) {
144+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, aux: &mut AuxParams) {
145145
rules.sp_brace.check(acc, SpBracesArgs::from_compound(self));
146-
rules.in3.check(acc, IN3Args::from_compound_content(self, depth));
146+
rules.in3.check(acc, IN3Args::from_compound_content(self, &mut aux.depth));
147147
}
148148
}
149149

@@ -195,7 +195,7 @@ impl TreeElement for VariableDeclContent {
195195
fn post_parse_sanity(&self, _file: &TextFile) -> Vec<LocalDMLError> {
196196
self.decls.ensure_named()
197197
}
198-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
198+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
199199
rules.sp_punct.check(acc, SpPunctArgs::from_variable_decl(self));
200200
}
201201
}
@@ -427,7 +427,7 @@ impl TreeElement for IfContent {
427427
&self.truebranch,
428428
&self.elsebranch)
429429
}
430-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
430+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
431431
rules.nsp_inparen.check(acc, NspInparenArgs::from_if(self));
432432
}
433433
}
@@ -1003,8 +1003,8 @@ impl TreeElement for SwitchCase {
10031003
Self::Default(default, colon) => create_subs!(default, colon),
10041004
}
10051005
}
1006-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, depth: &mut u32) {
1007-
rules.in9.check(acc, IN9Args::from_switch_case(self, depth));
1006+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, aux: &mut AuxParams) {
1007+
rules.in9.check(acc, IN9Args::from_switch_case(self, &mut aux.depth));
10081008
}
10091009
}
10101010

@@ -1715,7 +1715,7 @@ impl TreeElement for ExpressionStmtContent {
17151715
fn subs(&self) -> TreeElements<'_> {
17161716
create_subs!(&self.expression, &self.semi)
17171717
}
1718-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
1718+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
17191719
rules.sp_punct.check(acc, SpPunctArgs::from_expression_stmt(self));
17201720
}
17211721
}

src/analysis/parsing/structure.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::lint::rules::spacing::{SpBracesArgs,
2121
NspFunparArgs,
2222
SpPunctArgs};
2323
use crate::lint::rules::indentation::{IN3Args};
24-
use crate::lint::rules::CurrentRules;
24+
use crate::lint::{rules::CurrentRules, AuxParams};
2525
use crate::analysis::reference::{Reference, ReferenceKind};
2626
use crate::analysis::FileSpec;
2727
use crate::span::Range;
@@ -235,7 +235,7 @@ impl TreeElement for MethodContent {
235235
}
236236
errors
237237
}
238-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
238+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
239239
rules.nsp_funpar.check(acc, NspFunparArgs::from_method(self));
240240
rules.nsp_inparen.check(acc, NspInparenArgs::from_method(self));
241241
rules.sp_punct.check(acc, SpPunctArgs::from_method(self));
@@ -704,9 +704,9 @@ impl TreeElement for ObjectStatementsContent {
704704
create_subs!(left, vect, right)
705705
}
706706
}
707-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, depth: &mut u32) {
707+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, aux: &mut AuxParams) {
708708
rules.sp_brace.check(acc, SpBracesArgs::from_obj_stmts(self));
709-
rules.in3.check(acc, IN3Args::from_obj_stmts_content(self, depth));
709+
rules.in3.check(acc, IN3Args::from_obj_stmts_content(self, &mut aux.depth));
710710
}
711711
}
712712

src/analysis/parsing/tree.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::analysis::reference::{Reference, NodeRef, MaybeIsNodeRef,
77
use crate::analysis::FileSpec;
88
use crate::analysis::structure::expressions::DMLString;
99

10-
use crate::lint::rules::CurrentRules;
10+
use crate::lint::{rules::CurrentRules, AuxParams};
1111
use crate::span::{Range, Span, ZeroIndexed, Position, FilePosition};
1212
use crate::vfs::{Vfs as GenVfs, TextFile};
1313

@@ -91,13 +91,13 @@ pub trait TreeElement {
9191
self.default_references(accumulator, file);
9292
}
9393

94-
fn style_check(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, mut depth: u32) {
95-
self.evaluate_rules(acc, rules, &mut depth);
94+
fn style_check(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, mut aux: AuxParams) {
95+
self.evaluate_rules(acc, rules, &mut aux);
9696
for sub in self.subs() {
97-
sub.style_check(acc, rules, depth);
97+
sub.style_check(acc, rules, aux);
9898
}
9999
}
100-
fn evaluate_rules(&self, _acc: &mut Vec<LocalDMLError>, _rules: &CurrentRules, _depth: &mut u32) {} // default NOOP
100+
fn evaluate_rules(&self, _acc: &mut Vec<LocalDMLError>, _rules: &CurrentRules, _aux: &mut AuxParams) {} // default NOOP
101101
}
102102

103103
impl <T: ?Sized + TreeElement> ReferenceContainer for T {

src/analysis/parsing/types.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// © 2024 Intel Corporation
22
// SPDX-License-Identifier: Apache-2.0 and MIT
3-
use crate::lint::rules::{indentation::IN3Args,
4-
spacing::SpBracesArgs,
5-
CurrentRules};
3+
use crate::lint::{rules::{indentation::IN3Args,
4+
spacing::SpBracesArgs,
5+
CurrentRules},
6+
AuxParams};
67
use crate::span::Range;
78
use crate::analysis::parsing::lexer::TokenKind;
89
use crate::analysis::parsing::parser::{doesnt_understand_tokens,
@@ -51,8 +52,8 @@ impl TreeElement for StructTypeContent {
5152
}
5253
errors
5354
}
54-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, depth: &mut u32) {
55-
rules.in3.check(acc, IN3Args::from_struct_type_content(self, depth));
55+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, aux: &mut AuxParams) {
56+
rules.in3.check(acc, IN3Args::from_struct_type_content(self, &mut aux.depth));
5657
rules.sp_brace.check(acc, SpBracesArgs::from_struct_type_content(self));
5758
}
5859
}
@@ -130,8 +131,8 @@ impl TreeElement for LayoutContent {
130131
}
131132
errors
132133
}
133-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, depth: &mut u32) {
134-
rules.in3.check(acc, IN3Args::from_layout_content(self, depth));
134+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, aux: &mut AuxParams) {
135+
rules.in3.check(acc, IN3Args::from_layout_content(self, &mut aux.depth));
135136
rules.sp_brace.check(acc, SpBracesArgs::from_layout_content(self));
136137
}
137138
}
@@ -303,7 +304,7 @@ impl TreeElement for BitfieldsContent {
303304
}
304305
errors
305306
}
306-
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _depth: &mut u32) {
307+
fn evaluate_rules(&self, acc: &mut Vec<LocalDMLError>, rules: &CurrentRules, _aux: &mut AuxParams) {
307308
rules.sp_brace.check(acc, SpBracesArgs::from_bitfields_content(self));
308309
}
309310
}

src/lint/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ impl LinterAnalysis {
121121

122122
pub fn begin_style_check(ast: TopAst, file: String, rules: &CurrentRules) -> Result<Vec<LocalDMLError>, Error> {
123123
let mut linting_errors: Vec<LocalDMLError> = vec![];
124-
let initial_indentation: u32 = 0;
125-
ast.style_check(&mut linting_errors, rules, initial_indentation);
124+
ast.style_check(&mut linting_errors, rules, AuxParams { depth: 0 });
126125

127126
// Per line checks
128127
let lines: Vec<&str> = file.lines().collect();
@@ -137,6 +136,11 @@ pub fn begin_style_check(ast: TopAst, file: String, rules: &CurrentRules) -> Res
137136
Ok(linting_errors)
138137
}
139138

139+
#[derive(Copy, Clone)]
140+
pub struct AuxParams {
141+
pub depth: u32,
142+
}
143+
140144

141145
pub mod rules;
142146
pub mod tests {

0 commit comments

Comments
 (0)