Skip to content

Commit

Permalink
Rename argument to parameter in function declaration
Browse files Browse the repository at this point in the history
Ref. None
  • Loading branch information
treiher committed Sep 13, 2024
1 parent 49f8edf commit 3e32b84
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion rflx/ls/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 10 additions & 8 deletions rflx/model/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand All @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions rflx/model/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion rflx/specification/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/specification_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/model/state_machine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
],
Expand Down Expand Up @@ -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,
),
],
Expand Down Expand Up @@ -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,
),
],
Expand Down Expand Up @@ -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",
),
],
Expand Down Expand Up @@ -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'^<stdin>:10:20: error: undefined variable "Undefined"$',
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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"^<stdin>:10:20: error: missing function arguments$",
Expand Down Expand Up @@ -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"^<stdin>:10:20: error: too many function arguments$",
Expand Down Expand Up @@ -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'^<stdin>:10:20: error: undefined variable "Undefined"$',
Expand Down Expand Up @@ -2007,15 +2007,15 @@ def test_conversion_invalid() -> None:
[
decl.FunctionDeclaration(
"X",
[decl.Argument("Y", "Boolean")],
[decl.Parameter("Y", "Boolean")],
"Undefined",
location=Location((10, 20)),
),
],
[
decl.FunctionDeclaration(
"X",
[decl.Argument("Y", "Undefined")],
[decl.Parameter("Y", "Undefined")],
"Boolean",
location=Location((10, 20)),
),
Expand Down Expand Up @@ -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,
),
],
Expand Down Expand Up @@ -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,
),
],
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/specification/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4568,15 +4568,15 @@ 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",
),
),
(
"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),
),
),
Expand Down

0 comments on commit 3e32b84

Please sign in to comment.