Skip to content

Commit

Permalink
Rename qualified_type_identifier to internal_type_identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l authored and treiher committed May 10, 2022
1 parent f519c73 commit 8ccbe74
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions rflx/generator/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ def _ada_type(self, identifier: rid.ID) -> ID:
if model.is_builtin_type(identifier):
return ID(identifier.name)

return ID(model.qualified_type_identifier(identifier, self._session.package))
return ID(model.internal_type_identifier(identifier, self._session.package))

def _model_type(self, identifier: rid.ID) -> model.Type:
return self._session.types[
model.qualified_type_identifier(identifier, self._session.package)
model.internal_type_identifier(identifier, self._session.package)
]

def _create(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion rflx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Scalar as Scalar,
Sequence as Sequence,
Type as Type,
internal_type_identifier as internal_type_identifier,
is_builtin_type as is_builtin_type,
is_internal_type as is_internal_type,
qualified_type_identifier as qualified_type_identifier,
)
2 changes: 1 addition & 1 deletion rflx/model/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __str__(self) -> str:
[
f"{parameter_field.identifier} : {parameter_type_identifier}"
for parameter_field, parameter_type in self.parameter_types.items()
for parameter_type_identifier in (parameter_type.qualified_identifier)
for parameter_type_identifier in (parameter_type.qualified_identifier,)
]
)
if parameters:
Expand Down
4 changes: 1 addition & 3 deletions rflx/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def create_specifications(self) -> Dict[ID, str]:
return {id: str(pkg) for id, pkg in pkgs.items()}

def write_specification_files(self, output_dir: Path) -> None:
"""
Write corresponding specification files (one per package) into given directory.
"""
"""Write corresponding specification files (one per package) into given directory."""
for package, specification in self.create_specifications().items():
(output_dir / f"{package.flat.lower()}.rflx").write_text(specification)

Expand Down
8 changes: 4 additions & 4 deletions rflx/model/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,15 @@ def undefined_type(type_identifier: StrID, location: Optional[Location]) -> None
self.__reference_variable_declaration(d.variables(), visible_declarations)

if isinstance(d, decl.TypeDeclaration):
type_identifier = mty.qualified_type_identifier(k, self.package)
type_identifier = mty.internal_type_identifier(k, self.package)
if type_identifier in self.types:
self.error.extend(
[(f'type "{k}" shadows type', Subsystem.MODEL, Severity.ERROR, d.location)],
)
self.types[type_identifier] = d.type_definition

elif isinstance(d, decl.TypeCheckableDeclaration):
type_identifier = mty.qualified_type_identifier(d.type_identifier, self.package)
type_identifier = mty.internal_type_identifier(d.type_identifier, self.package)
if type_identifier in self.types:
self.error.extend(
d.check_type(
Expand All @@ -438,7 +438,7 @@ def undefined_type(type_identifier: StrID, location: Optional[Location]) -> None

if isinstance(d, decl.FunctionDeclaration):
for a in d.arguments:
type_identifier = mty.qualified_type_identifier(
type_identifier = mty.internal_type_identifier(
a.type_identifier, self.package
)
if type_identifier in self.types:
Expand Down Expand Up @@ -643,7 +643,7 @@ def __typify_variable(
if isinstance(t, Refinement) and t.sdu.identifier == identifier
]
if isinstance(expression, expr.MessageAggregate):
type_identifier = mty.qualified_type_identifier(identifier, self.package)
type_identifier = mty.internal_type_identifier(identifier, self.package)
if type_identifier in self.types:
expression.type_ = self.types[type_identifier].type_

Expand Down
19 changes: 14 additions & 5 deletions rflx/model/type_.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def type_(self) -> rty.Type:
@property
def direct_dependencies(self) -> ty.List["Type"]:
"""
Return a list consisting of the type and all the types on which the
type directly depends.
Return a list consisting of the type and all the types on which the type directly depends.
The dependencies are not determined recursively, i.e. the dependencies
of dependencies are not considered.
Expand All @@ -39,9 +38,12 @@ def dependencies(self) -> ty.List["Type"]:
@property
def qualified_identifier(self) -> ID:
"""
Return the
Return the qualified identifier of this type.
The qualified identifier of a type is defined as its complete package
path followed by the type name, or just the type name if the type is
builtin or internal.
"""
# TODO: Handle name collision with `type_.qualified_type_identifier`.
identifier = self.identifier
return (
ID(self.name, location=identifier.location)
Expand Down Expand Up @@ -704,7 +706,14 @@ def is_builtin_type(identifier: StrID) -> bool:
)


def qualified_type_identifier(identifier: ID, package: ID = None) -> ID:
def internal_type_identifier(identifier: ID, package: ID = None) -> ID:
"""
Return the internal identifier of a type.
The internal identifier is defined as its complete package path
(`__BUILTINS__` for builtin types, and `__INTERNAL__` for internal types)
followed by the type name.
"""
if is_builtin_type(identifier):
return ID(const.BUILTINS_PACKAGE * identifier.name, location=identifier.location)

Expand Down
26 changes: 11 additions & 15 deletions rflx/specification/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def create_sequence(
filename: Path,
) -> model.Type:
assert isinstance(sequence, lang.SequenceTypeDef)
element_identifier = model.qualified_type_identifier(
element_identifier = model.internal_type_identifier(
create_id(sequence.f_element_type, filename), identifier.parent
)

Expand Down Expand Up @@ -507,9 +507,7 @@ def create_variable_decl(
)
return decl.VariableDeclaration(
create_id(declaration.f_identifier, filename),
model.qualified_type_identifier(
create_id(declaration.f_type_identifier, filename), package
),
model.internal_type_identifier(create_id(declaration.f_type_identifier, filename), package),
initializer,
location=node_location(declaration, filename),
)
Expand All @@ -521,7 +519,7 @@ def create_private_type_decl(
assert isinstance(declaration, lang.FormalPrivateTypeDecl)
return decl.TypeDeclaration(
model.Private(
model.qualified_type_identifier(create_id(declaration.f_identifier, filename), package),
model.internal_type_identifier(create_id(declaration.f_identifier, filename), package),
location=node_location(declaration, filename),
)
)
Expand Down Expand Up @@ -558,9 +556,7 @@ def create_renaming_decl(
assert isinstance(selected, expr.Selected)
return decl.RenamingDeclaration(
create_id(declaration.f_identifier, filename),
model.qualified_type_identifier(
create_id(declaration.f_type_identifier, filename), package
),
model.internal_type_identifier(create_id(declaration.f_type_identifier, filename), package),
selected,
location=node_location(declaration, filename),
)
Expand All @@ -578,15 +574,15 @@ def create_function_decl(
arguments.append(
decl.Argument(
create_id(p.f_identifier, filename),
model.qualified_type_identifier(
model.internal_type_identifier(
create_id(p.f_type_identifier, filename), package
),
)
)
return decl.FunctionDeclaration(
create_id(declaration.f_identifier, filename),
arguments,
model.qualified_type_identifier(
model.internal_type_identifier(
create_id(declaration.f_return_type_identifier, filename), package
),
location=node_location(declaration, filename),
Expand Down Expand Up @@ -868,7 +864,7 @@ def get_parameters(param: lang.Parameters) -> Optional[lang.ParameterList]:
for field in fields.f_fields
),
):
qualified_type_identifier = model.qualified_type_identifier(
qualified_type_identifier = model.internal_type_identifier(
create_id(type_identifier, filename), identifier.parent
)
field_type = next((t for t in types if t.identifier == qualified_type_identifier), None)
Expand Down Expand Up @@ -1207,7 +1203,7 @@ def create_derived_message(
# pylint: disable=too-many-arguments
assert isinstance(derivation, lang.TypeDerivationDef)
base_id = create_id(derivation.f_base, filename)
base_name = model.qualified_type_identifier(base_id, identifier.parent)
base_name = model.internal_type_identifier(base_id, identifier.parent)

base_types: Sequence[model.Type] = [t for t in types if t.identifier == base_name]

Expand Down Expand Up @@ -1346,7 +1342,7 @@ def create_refinement(
) -> model.Refinement:
messages = {t.identifier: t for t in types if isinstance(t, model.Message)}

pdu = model.qualified_type_identifier(create_id(refinement.f_pdu, filename), package)
pdu = model.internal_type_identifier(create_id(refinement.f_pdu, filename), package)
if pdu not in messages:
fail(
f'undefined type "{pdu}" in refinement',
Expand All @@ -1355,7 +1351,7 @@ def create_refinement(
node_location(refinement, filename),
)

sdu = model.qualified_type_identifier(create_id(refinement.f_sdu, filename), package)
sdu = model.internal_type_identifier(create_id(refinement.f_sdu, filename), package)
if sdu not in messages:
fail(
f'undefined type "{sdu}" in refinement of "{pdu}"',
Expand Down Expand Up @@ -1639,7 +1635,7 @@ def __evaluate_specification(

for t in spec.f_package_declaration.f_declarations:
if isinstance(t, lang.TypeDecl):
identifier = model.qualified_type_identifier(
identifier = model.internal_type_identifier(
create_id(t.f_identifier, filename), package_id
)
try:
Expand Down

0 comments on commit 8ccbe74

Please sign in to comment.