From 3e32b848a78f6aea3617683c31eb1e6486cdd742 Mon Sep 17 00:00:00 2001 From: Tobias Reiher Date: Fri, 6 Sep 2024 18:49:51 +0200 Subject: [PATCH] Rename argument to parameter in function declaration Ref. None --- rflx/ls/model.py | 2 +- rflx/model/declaration.py | 18 +++++++------ rflx/model/state_machine.py | 26 +++++++++---------- rflx/specification/parser.py | 2 +- tests/integration/specification_model_test.py | 2 +- tests/unit/model/state_machine_test.py | 26 +++++++++---------- tests/unit/specification/parser_test.py | 4 +-- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/rflx/ls/model.py b/rflx/ls/model.py index 89f7c1a24..e0b3b1fdc 100644 --- a/rflx/ls/model.py +++ b/rflx/ls/model.py @@ -202,7 +202,7 @@ def _to_symbols(declaration: UncheckedTopLevelDeclaration) -> list[Symbol]: ) for function in declaration.parameters if isinstance(function, FunctionDeclaration) - for argument in function.arguments + for argument in function.parameters ] declarations = [ Symbol( diff --git a/rflx/model/declaration.py b/rflx/model/declaration.py index d56654d59..b080f2f5e 100644 --- a/rflx/model/declaration.py +++ b/rflx/model/declaration.py @@ -215,7 +215,7 @@ def to_ir(self) -> ir.FormalDecl: raise NotImplementedError -class Argument(Base): +class Parameter(Base): def __init__(self, identifier: StrID, type_identifier: StrID, type_: rty.Type = rty.UNDEFINED): super().__init__() self._identifier = ID(identifier) @@ -243,19 +243,21 @@ class FunctionDeclaration(TypeCheckableDeclaration, FormalDeclaration): def __init__( self, identifier: StrID, - arguments: Sequence[Argument], + parameters: Sequence[Parameter], return_type: StrID, type_: rty.Type = rty.UNDEFINED, location: Location | None = None, ): super().__init__(identifier, return_type, type_, location) - self._arguments = arguments + self._parameters = parameters self._return_type = ID(return_type) def __str__(self) -> str: - arguments = (" (" + "; ".join(map(str, self._arguments)) + ")") if self._arguments else "" + parameters = ( + (" (" + "; ".join(map(str, self._parameters)) + ")") if self._parameters else "" + ) return ( - f"with function {self.identifier}{arguments} return {ada_type_name(self._return_type)}" + f"with function {self.identifier}{parameters} return {ada_type_name(self._return_type)}" ) def check_type( @@ -267,8 +269,8 @@ def check_type( return RecordFluxError() @property - def arguments(self) -> Sequence[Argument]: - return self._arguments + def parameters(self) -> Sequence[Parameter]: + return self._parameters @property def return_type(self) -> ID: @@ -277,7 +279,7 @@ def return_type(self) -> ID: def to_ir(self) -> ir.FuncDecl: return ir.FuncDecl( self.identifier, - [a.to_ir() for a in self.arguments], + [a.to_ir() for a in self.parameters], self.return_type, self.type_, self.location, diff --git a/rflx/model/state_machine.py b/rflx/model/state_machine.py index 602159aa1..86ab08e49 100644 --- a/rflx/model/state_machine.py +++ b/rflx/model/state_machine.py @@ -712,14 +712,14 @@ def undefined_type(type_identifier: StrID, location: Location | None) -> None: self._reference_variable_declaration(d.variables(), visible_declarations) if isinstance(d, decl.TypeCheckableDeclaration): - type_identifier = type_decl.internal_type_identifier( + declaration_id = type_decl.internal_type_identifier( d.type_identifier, self.package, ) - if type_identifier in self.types: + if declaration_id in self.types: self.error.extend( d.check_type( - self.types[type_identifier].type_, + self.types[declaration_id].type_, lambda x: self._typify_variable(x, visible_declarations), ).entries, ) @@ -728,18 +728,18 @@ def undefined_type(type_identifier: StrID, location: Location | None) -> None: d.type_ = rty.Any() if isinstance(d, decl.FunctionDeclaration): - for a in d.arguments: - type_identifier = type_decl.internal_type_identifier( - a.type_identifier, + for p in d.parameters: + parameter_id = type_decl.internal_type_identifier( + p.type_identifier, self.package, ) - if type_identifier in self.types: - argument_type = self.types[type_identifier] - a.type_ = argument_type.type_ - self._validate_function_parameter_type(type_identifier) + if parameter_id in self.types: + argument_type = self.types[parameter_id] + p.type_ = argument_type.type_ + self._validate_function_parameter_type(parameter_id) else: - a.type_ = rty.Any() - undefined_type(a.type_identifier, d.location) + p.type_ = rty.Any() + undefined_type(p.type_identifier, d.location) return_type_id = type_decl.internal_type_identifier( d.return_type, @@ -1019,7 +1019,7 @@ def _typify_variable( expression.type_ = declarations[identifier].type_ declaration = declarations[identifier] assert isinstance(declaration, decl.FunctionDeclaration) - expression.argument_types = [a.type_ for a in declaration.arguments] + expression.argument_types = [a.type_ for a in declaration.parameters] if isinstance(expression, expr.Conversion) and identifier in self.types: expression.type_ = self.types[identifier].type_ expression.argument_types = [ diff --git a/rflx/specification/parser.py b/rflx/specification/parser.py index 44e859496..f9ff67a8e 100644 --- a/rflx/specification/parser.py +++ b/rflx/specification/parser.py @@ -795,7 +795,7 @@ def create_function_decl( arguments = [] if declaration.f_parameters: arguments = [ - decl.Argument( + decl.Parameter( create_id(error, p.f_identifier, filename), model.internal_type_identifier( create_id(error, p.f_type_identifier, filename), diff --git a/tests/integration/specification_model_test.py b/tests/integration/specification_model_test.py index c437e51e4..9e0a9ac72 100644 --- a/tests/integration/specification_model_test.py +++ b/tests/integration/specification_model_test.py @@ -665,7 +665,7 @@ def test_consistency_specification_parsing_generation(tmp_path: Path) -> None: [ decl.ChannelDeclaration("X", readable=True, writable=True), decl.FunctionDeclaration("F", [], "Test::Tag"), - decl.FunctionDeclaration("G", [decl.Argument("P", "Test::Tag")], BOOLEAN.identifier), + decl.FunctionDeclaration("G", [decl.Parameter("P", "Test::Tag")], BOOLEAN.identifier), ], [BOOLEAN, OPAQUE, tag, length, message], ) diff --git a/tests/unit/model/state_machine_test.py b/tests/unit/model/state_machine_test.py index 7865d0a72..6286db8ad 100644 --- a/tests/unit/model/state_machine_test.py +++ b/tests/unit/model/state_machine_test.py @@ -71,7 +71,7 @@ def test_str() -> None: decl.FunctionDeclaration("F", [], BOOLEAN.identifier), decl.FunctionDeclaration( "G", - [decl.Argument("P", BOOLEAN.identifier)], + [decl.Parameter("P", BOOLEAN.identifier)], BOOLEAN.identifier, ), ], @@ -159,7 +159,7 @@ def test_identifier_normalization(monkeypatch: pytest.MonkeyPatch) -> None: decl.FunctionDeclaration("F", [], BOOLEAN.identifier), decl.FunctionDeclaration( "G", - [decl.Argument("P", BOOLEAN.identifier)], + [decl.Parameter("P", BOOLEAN.identifier)], BOOLEAN.identifier, ), ], @@ -305,7 +305,7 @@ def test_inconsistent_identifier_casing() -> None: ), decl.FunctionDeclaration( ID("G", location=Location((17, 17))), - [decl.Argument("P", BOOLEAN.identifier)], + [decl.Parameter("P", BOOLEAN.identifier)], BOOLEAN.identifier, ), ], @@ -872,7 +872,7 @@ def test_function_declaration_invalid_parameter_type( parameters=[ decl.FunctionDeclaration( "Function", - [decl.Argument("M", ID(parameter_type, location=Location((1, 2))))], + [decl.Parameter("M", ID(parameter_type, location=Location((1, 2))))], "Boolean", ), ], @@ -995,7 +995,7 @@ def test_call_undeclared_variable() -> None: decl.VariableDeclaration("Result", "Boolean"), ], parameters=[ - decl.FunctionDeclaration("SubProg", [decl.Argument("P", "Boolean")], "Boolean"), + decl.FunctionDeclaration("SubProg", [decl.Parameter("P", "Boolean")], "Boolean"), ], types=[BOOLEAN], regex=r'^:10:20: error: undefined variable "Undefined"$', @@ -1026,7 +1026,7 @@ def test_call_invalid_argument_type() -> None: decl.VariableDeclaration("Result", "Boolean"), ], parameters=[ - decl.FunctionDeclaration("Function", [decl.Argument("P", "Boolean")], "Boolean"), + decl.FunctionDeclaration("Function", [decl.Parameter("P", "Boolean")], "Boolean"), decl.ChannelDeclaration("Channel", readable=True, writable=False), ], types=[BOOLEAN], @@ -1062,7 +1062,7 @@ def test_call_missing_arguments() -> None: decl.VariableDeclaration("Result", "Boolean"), ], parameters=[ - decl.FunctionDeclaration("Function", [decl.Argument("P", "Boolean")], "Boolean"), + decl.FunctionDeclaration("Function", [decl.Parameter("P", "Boolean")], "Boolean"), ], types=[BOOLEAN], regex=r"^:10:20: error: missing function arguments$", @@ -1093,7 +1093,7 @@ def test_call_too_many_arguments() -> None: decl.VariableDeclaration("Result", "Boolean"), ], parameters=[ - decl.FunctionDeclaration("Function", [decl.Argument("P", "Boolean")], "Boolean"), + decl.FunctionDeclaration("Function", [decl.Parameter("P", "Boolean")], "Boolean"), ], types=[BOOLEAN], regex=r"^:10:20: error: too many function arguments$", @@ -1301,7 +1301,7 @@ def test_undeclared_variable_in_function_call() -> None: decl.VariableDeclaration("Result", "Boolean"), ], parameters=[ - decl.FunctionDeclaration("SubProg", [decl.Argument("P", "Boolean")], "Boolean"), + decl.FunctionDeclaration("SubProg", [decl.Parameter("P", "Boolean")], "Boolean"), ], types=[BOOLEAN], regex=r'^:10:20: error: undefined variable "Undefined"$', @@ -2007,7 +2007,7 @@ def test_conversion_invalid() -> None: [ decl.FunctionDeclaration( "X", - [decl.Argument("Y", "Boolean")], + [decl.Parameter("Y", "Boolean")], "Undefined", location=Location((10, 20)), ), @@ -2015,7 +2015,7 @@ def test_conversion_invalid() -> None: [ decl.FunctionDeclaration( "X", - [decl.Argument("Y", "Undefined")], + [decl.Parameter("Y", "Undefined")], "Boolean", location=Location((10, 20)), ), @@ -3200,7 +3200,7 @@ def test_unchecked_state_machine_checked() -> None: decl.FunctionDeclaration("F", [], BOOLEAN.identifier), decl.FunctionDeclaration( "G", - [decl.Argument("P", BOOLEAN.identifier)], + [decl.Parameter("P", BOOLEAN.identifier)], BOOLEAN.identifier, ), ], @@ -3250,7 +3250,7 @@ def test_unchecked_state_machine_checked() -> None: decl.FunctionDeclaration("F", [], BOOLEAN.identifier), decl.FunctionDeclaration( "G", - [decl.Argument("P", BOOLEAN.identifier)], + [decl.Parameter("P", BOOLEAN.identifier)], BOOLEAN.identifier, ), ], diff --git a/tests/unit/specification/parser_test.py b/tests/unit/specification/parser_test.py index a966716a6..3e4a11d5a 100644 --- a/tests/unit/specification/parser_test.py +++ b/tests/unit/specification/parser_test.py @@ -4568,7 +4568,7 @@ def test_expression_complex(string: str, expected: expr.Expr) -> None: "with function X (A : B; C : D) return Y", decl.FunctionDeclaration( "X", - [decl.Argument("A", "Package::B"), decl.Argument("C", "Package::D")], + [decl.Parameter("A", "Package::B"), decl.Parameter("C", "Package::D")], "Package::Y", ), ), @@ -4576,7 +4576,7 @@ def test_expression_complex(string: str, expected: expr.Expr) -> None: "with function X (A : Boolean) return Boolean", decl.FunctionDeclaration( "X", - [decl.Argument("A", str(model.BOOLEAN.identifier))], + [decl.Parameter("A", str(model.BOOLEAN.identifier))], str(model.BOOLEAN.identifier), ), ),