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

Checks for uniqueness of members #2085

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/java/org/lflang/LinguaFranca.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ TypeExpr:
TargetDecl:
'target' name=ID (config=KeyValuePairs)? ';'?;


/////////// Statements

/**
Expand Down Expand Up @@ -283,6 +282,9 @@ TypedVariable:
Variable:
TypedVariable | Timer | Mode | Watchdog;

Member:
Variable | Reaction | Method;

VarRef:
(variable=[Variable] | container=[Instantiation] '.' variable=[Variable]
| interleaved?='interleaved' '(' (variable=[Variable] | container=[Instantiation] '.' variable=[Variable]) ')') ('as' (alias=ID))?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.eclipse.emf.ecore.EClass;
import org.eclipse.xtext.validation.NamesAreUniqueValidationHelper;
import org.lflang.lf.LfPackage;
import org.lflang.lf.LfPackage.Literals;

public class LFNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper {

Expand All @@ -12,13 +12,17 @@ public class LFNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHe
*/
@Override
public EClass getAssociatedClusterType(EClass eClass) {
if (LfPackage.Literals.INPUT == eClass
|| LfPackage.Literals.OUTPUT == eClass
|| LfPackage.Literals.TIMER == eClass
|| LfPackage.Literals.ACTION == eClass
|| LfPackage.Literals.PARAMETER == eClass
|| LfPackage.Literals.INSTANTIATION == eClass) {
return LfPackage.Literals.VARIABLE;
if (Literals.ACTION == eClass
|| Literals.INPUT == eClass
|| Literals.INSTANTIATION == eClass
|| Literals.METHOD == eClass
|| Literals.OUTPUT == eClass
|| Literals.PARAMETER == eClass
|| Literals.REACTION == eClass
|| Literals.STATE_VAR == eClass
|| Literals.TIMER == eClass
|| Literals.WATCHDOG == eClass) {
return Literals.MEMBER;
}
return super.getAssociatedClusterType(eClass);
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/org/lflang/validation/LFValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class LFValidator extends BaseLFValidator {

@Check(CheckType.FAST)
public void checkAction(Action action) {
checkName(action.getName(), Literals.VARIABLE__NAME);
checkName(action.getName(), Literals.MEMBER__NAME);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this PR also add checkName calls to other syntactic elements like method, reaction, parameters and state variables? Or am I missing something here about how this code works?

Copy link
Member Author

Choose a reason for hiding this comment

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

I created an interface called Member that is implemented by all of those.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, but I expected to see a new check checkMember added that actually performs the name check. The way it looks now, we only check names for actions and ports. Or does Xtext automatically take care of checking uniqueness here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uniqueness is checked automatically based on the name attribute. This only specifies which nodes should be checked against one another.

if (action.getOrigin() == ActionOrigin.NONE) {
error(
"Action must have modifier {@code logical} or {@code physical}.",
Expand Down Expand Up @@ -472,9 +472,9 @@ public void checkImportedReactor(ImportedReactor reactor) {
public void checkInput(Input input) {
Reactor parent = (Reactor) input.eContainer();
if (parent.isMain() || parent.isFederated()) {
error("Main reactor cannot have inputs.", Literals.VARIABLE__NAME);
error("Main reactor cannot have inputs.", Literals.MEMBER__NAME);
}
checkName(input.getName(), Literals.VARIABLE__NAME);
checkName(input.getName(), Literals.MEMBER__NAME);
if (target.requiresTypes) {
if (input.getType() == null) {
error("Input must have a type.", Literals.TYPED_VARIABLE__TYPE);
Expand Down Expand Up @@ -555,9 +555,9 @@ public void updateModelInfo(Model model) {
public void checkOutput(Output output) {
Reactor parent = (Reactor) output.eContainer();
if (parent.isMain() || parent.isFederated()) {
error("Main reactor cannot have outputs.", Literals.VARIABLE__NAME);
error("Main reactor cannot have outputs.", Literals.MEMBER__NAME);
}
checkName(output.getName(), Literals.VARIABLE__NAME);
checkName(output.getName(), Literals.MEMBER__NAME);
if (this.target.requiresTypes) {
if (output.getType() == null) {
error("Output must have a type.", Literals.TYPED_VARIABLE__TYPE);
Expand Down Expand Up @@ -1082,7 +1082,7 @@ public void checkTargetProperties(KeyValuePairs targetProperties) {

@Check(CheckType.FAST)
public void checkTimer(Timer timer) {
checkName(timer.getName(), Literals.VARIABLE__NAME);
checkName(timer.getName(), Literals.MEMBER__NAME);
checkExpressionIsTime(timer.getOffset(), Literals.TIMER__OFFSET);
checkExpressionIsTime(timer.getPeriod(), Literals.TIMER__PERIOD);
}
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public void checkModeTimerNamespace(Reactor reactor) {
+ " modes)",
timer.getName()),
timer,
Literals.VARIABLE__NAME);
Literals.MEMBER__NAME);
}
names.add(timer.getName());
}
Expand All @@ -1282,7 +1282,7 @@ public void checkModeActionNamespace(Reactor reactor) {
+ " modes)",
action.getName()),
action,
Literals.VARIABLE__NAME);
Literals.MEMBER__NAME);
}
names.add(action.getName());
}
Expand Down
Loading