Skip to content

Commit

Permalink
This addresses #1973 but breaks some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Nov 5, 2023
1 parent 63a3d9c commit 54ca16b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
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);
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

0 comments on commit 54ca16b

Please sign in to comment.