GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||
GeezerVison is showing github.com — [modelica] Initial implementation for PMD by atrosinenko · Pull Request #2041 · pmd/pmd Conversation
|
Generated by 🚫 Danger |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hmm... Maybe it is worth to re-implement it using JavaCC, because I'm planning implementing some static analysis. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Depending on how urgent you need static analysis for modelica, you might wait for PMD 7. There we have full antlr support for languages. On PMD 6 (master), we only support it with javacc (or with wrapping an external parser). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
471af3a to
53376f9
Compare
|
I have manually translated |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hi, the amount of work you put in there is impressive, kudos! I'd like to point out some possible improvements
The vanilla JJTree generation is unfortunately very awkward. Much information is lost if you don't segment productions enough. This happens eg when a production may match several tokens, and the type of the token is semantically important (eg your production RelOp or Primary). This also happens when sub clauses of some nodes are just flat and don't have their own node (eg in your IfEquation, WhenEquation).
There's also the problem, that your grammar pushes too many nodes. For example, a simple expression like 1 is parsed as the humongous
Expression
+ SimpleExpression
+ LogicalExpression
+ LogicalTerm
+ LogicalFactor
+ Relation
+ ArithmeticExpression
+ Term
+ Factor
+ Primary
(and even there, the Primary node has no information about whether this is a number or a string).
The root of the problem is that the grammar you converted is meant to parse the language, not really to produce an AST. So the AST is impractically big, and doesn't provide any abstractions to work with.
See also https://github.com/pmd/pmd/wiki/PMD-7.0.0-Java#identifying-abstractions. I don't know modelica, but by the looks of it, you could at least have an interface for Equation, Statement, and Expression, and not nodes.
I've included some comments to point out some of what's wrong.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should probably be wrapped in a node like EquationList. With the current grammar, your IfEquation nodes will have many Equation children, with no structure (you can't figure out which equation is part of the then and which is part of an elseif, or else clause (unless you look at the tokens, but then what good is the tree).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Similarly, this whole construct in parenthesis is more complex than just a list of equations, it's an expression + a list of equations. It looks like the AST would be structured much better if there was a node ElseIfClause in there. You just need to extract the contents of the parentheses into another production
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is it really allowed to write elseif (...) then else, with no equation between the then and else? This looks weird but again, i don't know modelica. If it's not the case, change the * to a +. The comment about wrapping that all into a list node applies again.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks like at least OpenModelica allows empty statement lists in if-statements, so
if time > 10 then end if;
seems to be a correct algorithm. This even seems not very weird. With equations, there are restrictions on their number (number of equations == number of state variables) but that's another story, not about grammar...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same, can the list really be empty?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same, this looks like it deserves its own node.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
FunctionCallExpression?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This looks like it needs its own node, eq RegularEquation or whatever that is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should be different nodes
ComponentReference() ((<ASSIGN> Expression()) #AssignmentStatement(2) | FunctionCallArgs() #FunctionCallStatement(2))
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actually, there is no "misc" category. This ruleset should probably live under tests (somewhere under src/test/resources).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yet another try... Now, it parses the attached file successfully, but has some general lookahead-related issues. The AST now seems significantly less deep. Not sure on its usability yet, though, now it is quite simple to test new Notifying @JKRT |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks very much @oowekyala for thorough explanation! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I must say this addition to PMD makes me really happy! I have just eyeballed your PR, but I have been going around thinking the same thing for a time.. Currently, I am a bit short on time... I have subscribed to the thread and will follow up on this sometime next week |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Now it seems to be able to parse the entire Modelica Standard Library and execute a trivial rule on it: It validates that the start and end markers of a class has the same name inside. This preview is intended for testing of AST structure by those who know Modelica better. Inviting @sjoelund @adrpo as well, who were spotted among persons made some of the latest commits to OpenModelica parser. :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Maybe, we can include the module in the next release under a "beta" status, so that you can make further changes to the grammar to refine it a bit before advertising it as stable |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I supposed something similar: wait for some feedback from OpenModelica developers a bit, if any (this is a Modelica implementation I'm most familiar with), then merge it, so others could populate the rulesets using regular development process. This would allow others to "test drive" new language implementation more widely and spot issues before officially stabilizing AST. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Just for fun: msl-copy-paste.txt. At least the first instance is not a CPD implementation bug: (This is from copy-pasted |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
New preview build is published: it has Modelica syntax highlighting in the Designer and initial support for File/Class scopes and Component list. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This hackish flattening process definitely needs some debugging. But it passes some simple tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
fddc2cb to
a1d957f
Compare
There was an error while loading. Please reload this page.
|
Squashed and rebased onto new |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a1d957f to
b038295
Compare
I am still busy with other stuff. However, I do applaud this effort! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@atrosinenko First, thanks for the significant time investment. In comparison this is a quite partial review, and I'm sorry I can't go more in-depth for now. The following are possible improvement points, that can be worked on incrementally, mainly about general API design:
.internal package. Those guidelines can be found on the website.ClassNameDeclaration, SymbolFacade. I'd advise for using a common language-specific prefix like MoClassNameDeclaration, MoSymbolFacade, or another prefix. It makes it harder to jump to a class in the IDE when so many have the same name.Scope and the stuff that's in the symboltable package of pmd-core.
Keep up the good work!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thank you very much for suggestions! For now, I'm more Scala developer than Java one (and so, for example, not very familiar with Java enumerations) and I'm completely new to designing public APIs, so the suggestions are very valuable. Now I'm completely rewriting, simplifying and documenting the symbol resolution machinery and aligning it with the Modelica Language Specification (with some refs in javadoc). Meanwhile, is there some interface I can implement, so this information would at least show up in the Rule Designer? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Good to hear :)
The designer uses Scope and VariableNameDeclaration for now. I think, we need to abstract it away (since even the java module won't use those with 7.0). I'll give it a try |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This just pushed commit is merely a safepoint and still WIP. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
3c79b43 to
c5cf183
Compare
|
Fixed most of the review issues. Small refinement of class flattening is pending, then it would be great if someone familiar with the Modelica semantics would glance at it. I have detangled my code from the deprecated Scope and Declaration APIs but used a homegrown API for now. It abstracts various notions of Modelica with different interfaces:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ChildrenAccept is not a useful method, it makes stack traces longer, and the logic for combining children results should belong to the visitor. See also 68cd554
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How is this better than getImage? It still is on all modelica nodes, and returns null nearly 100% of the time. I suggest introducing an interface eg NamedModelicaNode for this method. The only usage is also for class definitions, so it could simply be a method of that class.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't really like what these internal interfaces are doing. The usages of the methods they introduce are very rare, yet the methods are still on the public API of the nodes...
What the Java module is doing, is to have a utility class that exposes some package private methods. For example:
@InternalApi public final class InternalModelicaNodeApi { private InternalModelicaNodeApi() {} public static void setOwnScope(ModelicaNode node, ModelicaScope scope) { ((AbstractModelicaNode) node).setOwnScope(scope); // where this method is package-private on AbstractModelicaNode } }
This avoids API leaks and groups all the internal API in one place instead of several interfaces.
See also #1856
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with modelica semantics. What is a restriction exactly? Does it have something to do with the syntactic context the name node appears in/the type of node a declaration is? I feel like this should be documented
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hmm this looks like something that shouldn't be on the interface... Maybe we need another designer binding
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If it's for testing purposes then it can probably be package private?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@atrosinenko I really salute this work : ), How is the progress |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Mostly awaiting review (from PMD maintainers and Modelica folks) and maybe some testing (from Modelica folks). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@atrosinenko Thanks for your work!
I'd like to merge your PR rather sooner than later, even if it might not be fully finished. It's easier to continue working on it, if it's already integrated - then it's also easier for testing by Modelica folks, because it would be shipped with the next official PMD release.
So I suggest the following:
Thanks again for this great contribution!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
33227fd to
20bf4ad
Compare
|
Thanks! I have squashed my commits, rebased them onto fresh master and added two small changes:
On mergeability: since it will be experimental anyway, I think it can be merged now and then improved by subsequent commits (provided Windows build will be OK). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.