GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [modelica] Initial implementation for PMD by atrosinenko · Pull Request #2041 · pmd/pmd

Conversation

@atrosinenko

@atrosinenko atrosinenko commented Sep 28, 2019 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR introduces initial support of Modelica language for CPD. It passes existing tests (although not yet adds its own). It seems to basically work when tested on the Modelica Standard Library.

Its grammar is modelica.g4 taken from https://github.com/antlr/grammars-v4 and (textually) significantly rewritten to eliminate usage of anonymous string literals (I tried to retain all the original meaning of the grammar). Though, I'm not experienced with Antlr at all, so please feel free to point me to any silly mistakes / non-idiomatic constructs. :)

PS: Is it "correctly processed" copyright notice that reside in Modelica.g4? I left it intact except for adding a note that I have modified it, since I easily could introduce some mistakes not existing in the original version.


Modelica: https://modelica.org/modelicalanguage

The Modelica Language is a non-proprietary, object-oriented, equation based language to conveniently model complex physical systems containing, e.g., mechanical, electrical, electronic, hydraulic, thermal, control, electric power or process-oriented subcomponents.

Language Specification: https://specification.modelica.org/v3.4/MLS.html
Documentation: https://doc.modelica.org/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JKRT reacted with hooray emoji JKRT reacted with heart emoji JKRT reacted with rocket emoji
All reactions
  • 🎉 1 reaction
  • ❤️ 1 reaction
  • 🚀 1 reaction
@ghost

ghost commented Sep 28, 2019

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko

atrosinenko commented Sep 29, 2019

Copy link
Copy Markdown
Contributor Author

Hmm... Maybe it is worth to re-implement it using JavaCC, because I'm planning implementing some static analysis.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko atrosinenko changed the title [modelica] Initial implementation for CPD [WIP] [modelica] Initial implementation for CPD Sep 29, 2019
@adangel

adangel commented Sep 29, 2019

Copy link
Copy Markdown
Member

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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko
atrosinenko force-pushed the cpd-modelica branch from 471af3a to 53376f9 Compare September 30, 2019 18:14
@atrosinenko

atrosinenko commented Sep 30, 2019

Copy link
Copy Markdown
Contributor Author

I have manually translated Modelica.g4 to JavaCC and, surprisingly, it still basically works for CPD... Here is a Modelica skeleton for PMD.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko atrosinenko changed the title [WIP] [modelica] Initial implementation for CPD [WIP] [modelica] Initial implementation for PMD Sep 30, 2019
oowekyala
oowekyala reviewed Sep 30, 2019
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

atrosinenko reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@atrosinenko atrosinenko Oct 6, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunctionCallExpression?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Outdated

@oowekyala oowekyala Sep 30, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adangel adangel added the a:new-language Proposal to add a new PMD or CPD language to the main distribution label Oct 5, 2019
@atrosinenko atrosinenko mentioned this pull request Oct 5, 2019
[doc] Update the docs on adding a new language #2051
Merged
@adangel adangel added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Oct 5, 2019
adangel
adangel reviewed Oct 5, 2019
View reviewed changes
Comment thread pmd-modelica/src/main/resources/category/modelica/misc.xml Outdated

@adangel adangel Oct 5, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@atrosinenko

atrosinenko commented Oct 6, 2019

Copy link
Copy Markdown
Contributor Author

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 jjt grammars, since it requires modification of two adapter implementations only.

Notifying @JKRT

Test.mo.txt

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko

atrosinenko commented Oct 6, 2019

Copy link
Copy Markdown
Contributor Author

Thanks very much @oowekyala for thorough explanation!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JKRT

JKRT commented Oct 6, 2019

Copy link
Copy Markdown

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 jjt grammars, since it requires modification of two adapter implementations only.

Notifying @JKRT

Test.mo.txt

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko

atrosinenko commented Oct 7, 2019

Copy link
Copy Markdown
Contributor Author

Now it seems to be able to parse the entire Modelica Standard Library and execute a trivial rule on it:

//ClassSpecifier/*[SimpleName[1]/@Image != SimpleName[last()]/@Image]

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. :)

JKRT reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala
oowekyala reviewed Oct 7, 2019
View reviewed changes
Comment thread pmd-modelica/etc/grammar/Modelica.jjt Resolved

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala

oowekyala commented Oct 7, 2019

Copy link
Copy Markdown
Member

Not sure on its usability yet, though

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

atrosinenko reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala
oowekyala self-requested a review October 7, 2019 14:43
@atrosinenko

atrosinenko commented Oct 7, 2019

Copy link
Copy Markdown
Contributor Author

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

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.

oowekyala and adangel reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko

atrosinenko commented Oct 8, 2019

Copy link
Copy Markdown
Contributor Author

Just for fun: msl-copy-paste.txt.

At least the first instance is not a CPD implementation bug:

Found a 180 line (3474 tokens) duplication in the following files: 
Starting at line 1745 of /tmp/Modelica/Media/Air/ReferenceMoistAir.mo
Starting at line 1808 of /tmp/Modelica/Media/Water/IF97_Utilities.mo

(This is from copy-pasted function g2 "Gibbs function for region 2: g(p,T)")

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko atrosinenko mentioned this pull request Oct 12, 2019
Add a trivial Modelica syntax highlighter pmd/pmd-designer#30
Merged
@atrosinenko

atrosinenko commented Oct 12, 2019

Copy link
Copy Markdown
Contributor Author

New preview build is published: it has Modelica syntax highlighting in the Designer and initial support for File/Class scopes and Component list.

adangel and JKRT reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko

atrosinenko commented Oct 14, 2019

Copy link
Copy Markdown
Contributor Author

This hackish flattening process definitely needs some debugging. But it passes some simple tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko atrosinenko mentioned this pull request Nov 9, 2019
[core] Feature request: compiler-crashing test case minimization #2103
Open
@atrosinenko
atrosinenko force-pushed the cpd-modelica branch from fddc2cb to a1d957f Compare November 9, 2019 13:55
@atrosinenko

atrosinenko commented Nov 9, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Squashed and rebased onto new master. (still WIP)

JKRT reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko
atrosinenko force-pushed the cpd-modelica branch from a1d957f to b038295 Compare November 9, 2019 13:59
@JKRT

JKRT commented Nov 11, 2019

Copy link
Copy Markdown

Squashed and rebased onto new master. (still WIP)

I am still busy with other stuff. However, I do applaud this effort!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala
oowekyala reviewed Nov 15, 2019
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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:

  • Please avoid making everything public by default. If something is not meant to be used outside of PMD, at best make it package private, at most move it into an .internal package. Those guidelines can be found on the website.
  • If you must publish something for other packages to use, prefer publishing an interface rather than an abstract class (in particular here, for the AST). Generally, all abstract classes in AST packages should be package-private. We don't publish and don't intend to support APIs to extend the AST of existing language modules.
  • Please document your code at least a bit. It's kind of hard to go through it. Eg what's your Watchdog class supposed to be used for, etc
  • Please avoid mutating global state, like what you're doing with your enum. This may work but it's probably not thread-safe and unnecessary, and is hard to debug.
  • Avoid naming classes with names identical to those that are found in other language modules. Eg 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.
  • I would strongly advise against relying on Scope and the stuff that's in the symboltable package of pmd-core.
    • The design this package forces on you is very old, and will not scale to future efforts to improve PMD. In particular, storing AST nodes in maps is a quite weak abstraction, as it doesn't account for symbols that are declared outside of the current compilation unit (for which there's no AST). There are no cross-linguistic features that use this design and so there's no use to conforming to the interfaces of pmd-core here. I expect these interfaces will be removed in the not-near future
    • I suggest you try a design similar to what #1566 is talking about (publish interfaces to describe declarations, implement them privately, and implement a language-specific symbol resolver). Of course this requires some more work and I don't expect this to be done immediately

Keep up the good work!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

atrosinenko reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTName.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaNode.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractClassNode.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractImportClause.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/symboltable/ClassRestriction.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...delica/src/main/java/net/sourceforge/pmd/lang/modelica/symboltable/ClassNameDeclaration.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko

atrosinenko commented Nov 15, 2019

Copy link
Copy Markdown
Contributor Author

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala

oowekyala commented Nov 17, 2019

Copy link
Copy Markdown
Member

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)

Good to hear :)

Meanwhile, is there some interface I can implement, so this information would at least show up in the Rule Designer?

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala oowekyala mentioned this pull request Nov 17, 2019
[core] Add designer bindings interface #2118
Merged
@atrosinenko

atrosinenko commented Nov 17, 2019

Copy link
Copy Markdown
Contributor Author

This just pushed commit is merely a safepoint and still WIP.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko
atrosinenko force-pushed the cpd-modelica branch from 3c79b43 to c5cf183 Compare November 19, 2019 10:24
@atrosinenko

atrosinenko commented Nov 19, 2019

Copy link
Copy Markdown
Contributor Author

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:

  • ModelicaScope -- a lexical scope of source file
  • ModelicaDeclaration -- something that is explicitly declared with some name inside some scope
  • ModelicaType -- something that can be used to specify a type of some component, either explicitly declared class or built-in
  • SubcomponentResolver -- something that can be queried "from the outside" for further resolution (that is, not lexically)
  • ResolvableEntity -- something that resolver can find as a result of resolution process
JKRT reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala
oowekyala reviewed Nov 20, 2019
View reviewed changes
Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaNode.java Outdated

@oowekyala oowekyala Nov 19, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaNode.java Outdated

@oowekyala oowekyala Nov 19, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalModelicaNodeApi.java Outdated

@oowekyala oowekyala Nov 19, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ClassRestriction.java Outdated

@oowekyala oowekyala Nov 19, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ResolvableModelicaNode.java Outdated

@oowekyala oowekyala Nov 19, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaScope.java Outdated

@oowekyala oowekyala Nov 19, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@JKRT

JKRT commented Dec 14, 2019

Copy link
Copy Markdown

@atrosinenko I really salute this work : ), How is the progress

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko

atrosinenko commented Dec 15, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

How is the progress

Mostly awaiting review (from PMD maintainers and Modelica folks) and maybe some testing (from Modelica folks).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel approved these changes Dec 16, 2019
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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:

  • Can you clarify, that you have no more changes at the moment for this PR planned? -> Then simply change the title and remove [WIP], thanks!
  • I'll merge this PR this week. We can announce modelica support as "experimental" first, meaning, that you/we are still free to change any API/AST structures. This means, modelica would be ready to be used for creating rules, but we might change some parts slightly.
  • Once this is merged, please have a look at my review comments. They can be addressed in a separate PR and are not that urgent.

Thanks again for this great contribution!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JKRT reacted with hooray emoji JKRT reacted with rocket emoji
All reactions
  • 🎉 1 reaction
  • 🚀 1 reaction
Comment thread pmd-modelica/pom.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTClassDefinition.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTElementList.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTStoredDefinition.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-modelica/src/main/resources/category/modelica/bestpractices.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...t/resources/net/sourceforge/pmd/lang/modelica/rule/bestpractices/xml/AmbiguousResolution.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-test/src/main/resources/rule-tests_1_0_0.xsd Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added this to the 6.21.0 milestone Dec 16, 2019
@atrosinenko
[modelica] Initial implementation of Modelica support for PMD
20bf4ad
@atrosinenko
atrosinenko force-pushed the cpd-modelica branch from 33227fd to 20bf4ad Compare December 16, 2019 16:36
@atrosinenko

atrosinenko commented Dec 16, 2019

Copy link
Copy Markdown
Contributor Author

Thanks! I have squashed my commits, rebased them onto fresh master and added two small changes:

  • changed pmd-modelica version from 6.20 to 6.21
  • in Modelica.jjt, in the line
    | <#S_ESCAPE: "\\" [ "’", "\'", "\"", "?", "\\", "a", "b", "f", "n", "r", "t", "v" ] >
    
    changed literal Unicode character ’ to \u2019 (expecting this change will fix Windows build)

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).

JKRT and adangel reacted with hooray emoji
All reactions
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@atrosinenko atrosinenko changed the title [WIP] [modelica] Initial implementation for PMD [modelica] Initial implementation for PMD Dec 16, 2019
@adangel adangel removed the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Dec 16, 2019
@adangel adangel self-assigned this Dec 17, 2019
adangel added a commit that referenced this pull request Dec 17, 2019
@adangel
Update release notes, refs #2041
c27ed3a
@adangel
adangel merged commit 20bf4ad into pmd:master Dec 17, 2019
@atrosinenko atrosinenko mentioned this pull request Dec 17, 2019
[modelica] Follow-up fixes for Modelica language module #2169
Merged
@atrosinenko
atrosinenko deleted the cpd-modelica branch December 17, 2019 15:24
@atrosinenko atrosinenko mentioned this pull request Jan 7, 2020
Code / Formatting guidelines checker modelica/ModelicaStandardLibrary#3060
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@oowekyala oowekyala oowekyala left review comments
@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

a:new-language Proposal to add a new PMD or CPD language to the main distribution

Projects

None yet

Milestone

6.21.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@atrosinenko @adangel @JKRT @oowekyala
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.