Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purpose of stored-definition with several class definitions, and the within-clause #3466

Open
henrikt-ma opened this issue Jan 18, 2024 · 7 comments

Comments

@henrikt-ma
Copy link
Collaborator

What is the purpose of allowing stored-definition to have zero or several class definitions?

If we are to keep it this way, the definition of the within-clause would need to be updated to better cover the case of not just a single class definition.

@HansOlsson
Copy link
Collaborator

What is the purpose of allowing stored-definition to have zero or several class definitions?

Historically it has been used (e.g., for "SaveTotal") - especially without within. Really annoying users can use it combination with within.

If we are to keep it this way, the definition of the within-clause would need to be updated to better cover the case of not just a single class definition.

I don't see that within causes a problem for it. Consider the following silly example of a package P containing a mo file as follows on Windows:

within P;
model MA
end MA;

model ma
end ma;

I don't know if there's a more relevant use case for this.

@HansOlsson
Copy link
Collaborator

Basically within allows tools to detect if files have just been moved around in the directory; thus it makes sense that there's only one within per file.

@henrikt-ma
Copy link
Collaborator Author

I don't see that within causes a problem for it. Consider the following silly example of a package P containing a mo file as follows on Windows:

within P;
model MA
end MA;

model ma
end ma;

There wouldn't be a clear way to name that file. So in addition to generalizing the within-clause to applying to every class in the stored-definition, we'd also have to say something about the filename-class mapping.

I don't know if there's a more relevant use case for this.

I'd prefer steering away from stored-definition with anything but a single class definition, rather than trying agree on exactly how it should work. As usual, tools would still keep support for legacy files with multiple classes for a long time. :)

@HansOlsson
Copy link
Collaborator

What is the purpose of allowing stored-definition to have zero or several class definitions?

If we are to keep it this way, the definition of the within-clause would need to be updated to better cover the case of not just a single class definition.

I checked https://specification.modelica.org/master/packages.html#mapping-a-package-class-hierarchy-into-a-single-file-nonstructured-entity and already in Modelica 3.0 (possibly earlier) it is split into three cases:

  • A file stored inside a package: Here within is required and stored-definition may only contain one class.
  • A top-level class loaded from ModelicaPath: within can be omitted (or include empty name), but stored-definition may only contain one class
  • A top-level class loaded explicitly. within can be omitted (or include empty name) and stored-definition may contain multiple classes.

So, I don't see a major issue with the within-clause in combination with several class definitions.

@henrikt-ma
Copy link
Collaborator Author

  • A file stored inside a package: Here within is required and stored-definition may only contain one class.

This is only when mapping a package hierarchy to the file system.

  • A top-level class loaded from ModelicaPath: within can be omitted (or include empty name), but stored-definition may only contain one class

Right, so no need to worry about ModelicaPath here.

  • A top-level class loaded explicitly. within can be omitted (or include empty name) and stored-definition may contain multiple classes.

What prevents MyClasses.mo from placing classes within some package?

Anyway, at least I have a difficulty extracting the rules and purpose of files with non-1 class definitions from the current text. Wouldn't it be easier to express clearly by describing such files in a separate paragraph somewhere?

@HansOlsson
Copy link
Collaborator

  • A file stored inside a package: Here within is required and stored-definition may only contain one class.

This is only when mapping a package hierarchy to the file system.

Yes, that is the meaning of storing a file inside a package. Note that within is defined in this context.

  • A top-level class loaded explicitly. within can be omitted (or include empty name) and stored-definition may contain multiple classes.

What prevents MyClasses.mo from placing classes within some package?

That within should correspond to the enclosing structure and there isn't any. Is there a need to clarify that within is used for consistency checking and not to move classes arbitrarily?

Anyway, at least I have a difficulty extracting the rules and purpose of files with non-1 class definitions from the current text. Wouldn't it be easier to express clearly by describing such files in a separate paragraph somewhere?

@henrikt-ma
Copy link
Collaborator Author

What prevents MyClasses.mo from placing classes within some package?

That within should correspond to the enclosing structure and there isn't any. Is there a need to clarify that within is used for consistency checking and not to move classes arbitrarily?

Yes, I think that would be helpful, especially if combined with something along the following lines in a separate section before File System Mapping of Package/Class:

A stored-definition not containing exactly one class definition can only be used to define top-level classes, cannot be used for mapping packages or class-hierarchies to files, and cannot be located using the MODELICAPATH. It follows that any within-clause (see below) in such a stored-definition shall not contain a name.

Any suggestions for what would be a good title of that section? How about Stored Definitions Containing Multiple Class Definitions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants