-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c4b49c
commit 41a1dc9
Showing
13 changed files
with
308 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 29 additions & 12 deletions
41
...java/de/monticore/statements/mccommonstatements/cocos/DoWhileConditionHasBooleanType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,50 @@ | ||
/* (c) https://github.com/MontiCore/monticore */ | ||
package de.monticore.statements.mccommonstatements.cocos; | ||
|
||
import com.google.common.base.Preconditions; | ||
import de.monticore.statements.mccommonstatements._ast.ASTDoWhileStatement; | ||
import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTDoWhileStatementCoCo; | ||
import de.monticore.types.check.SymTypeExpression; | ||
import de.monticore.types.check.TypeCheck; | ||
import de.monticore.types.check.TypeCalculator; | ||
import de.monticore.types3.SymTypeRelations; | ||
import de.monticore.types3.TypeCheck3; | ||
import de.se_rwth.commons.logging.Log; | ||
|
||
public class DoWhileConditionHasBooleanType implements MCCommonStatementsASTDoWhileStatementCoCo { | ||
|
||
|
||
@Deprecated | ||
TypeCalculator typeCheck; | ||
|
||
public static final String ERROR_CODE = "0xA0905"; | ||
|
||
public static final String ERROR_MSG_FORMAT = "Condition in do-statement must be a boolean expression."; | ||
|
||
public DoWhileConditionHasBooleanType(TypeCalculator typeCheck){ | ||
|
||
/** | ||
* @deprecated use default constructor | ||
*/ | ||
@Deprecated | ||
public DoWhileConditionHasBooleanType(TypeCalculator typeCheck) { | ||
this.typeCheck = typeCheck; | ||
} | ||
|
||
|
||
public DoWhileConditionHasBooleanType() { } | ||
|
||
@Override | ||
public void check(ASTDoWhileStatement node) { | ||
|
||
SymTypeExpression result = typeCheck.typeOf(node.getCondition()); | ||
|
||
if(!TypeCheck.isBoolean(result)){ | ||
Preconditions.checkNotNull(node); | ||
|
||
SymTypeExpression result; | ||
|
||
if (typeCheck != null) { | ||
// support deprecated behavior | ||
result = typeCheck.typeOf(node.getCondition()); | ||
} else { | ||
result = TypeCheck3.typeOf(node.getCondition()); | ||
} | ||
|
||
if (!SymTypeRelations.isBoolean(result)) { | ||
Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 28 additions & 12 deletions
40
...ain/java/de/monticore/statements/mccommonstatements/cocos/ForConditionHasBooleanType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,54 @@ | ||
/* (c) https://github.com/MontiCore/monticore */ | ||
package de.monticore.statements.mccommonstatements.cocos; | ||
|
||
import com.google.common.base.Preconditions; | ||
import de.monticore.statements.mccommonstatements._ast.ASTCommonForControl; | ||
import de.monticore.statements.mccommonstatements._ast.ASTForStatement; | ||
import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTForStatementCoCo; | ||
import de.monticore.types.check.SymTypeExpression; | ||
import de.monticore.types.check.TypeCheck; | ||
import de.monticore.types.check.TypeCalculator; | ||
import de.monticore.types3.SymTypeRelations; | ||
import de.monticore.types3.TypeCheck3; | ||
import de.se_rwth.commons.logging.Log; | ||
|
||
public class ForConditionHasBooleanType implements MCCommonStatementsASTForStatementCoCo { | ||
|
||
|
||
@Deprecated | ||
TypeCalculator typeCheck; | ||
|
||
public static final String ERROR_CODE = "0xA0906"; | ||
|
||
public static final String ERROR_MSG_FORMAT = "Condition of for-loop must be a boolean expression."; | ||
|
||
public ForConditionHasBooleanType(TypeCalculator typeCheck){ | ||
|
||
/** | ||
* @deprecated use default constructor | ||
*/ | ||
@Deprecated | ||
public ForConditionHasBooleanType(TypeCalculator typeCheck) { | ||
this.typeCheck = typeCheck; | ||
} | ||
|
||
|
||
public ForConditionHasBooleanType() { } | ||
|
||
@Override | ||
public void check(ASTForStatement node) { | ||
Preconditions.checkNotNull(node); | ||
|
||
// todo replace with typedispatcher as soon as issues are fixed | ||
if(!(node.getForControl() instanceof ASTCommonForControl)) { | ||
if (!(node.getForControl() instanceof ASTCommonForControl)) { | ||
return; | ||
} | ||
SymTypeExpression result = typeCheck.typeOf(((ASTCommonForControl)node.getForControl()).getCondition()); | ||
|
||
if(!TypeCheck.isBoolean(result)){ | ||
SymTypeExpression result; | ||
|
||
if (typeCheck != null) { | ||
// support deprecated behavior | ||
result = typeCheck.typeOf(((ASTCommonForControl) node.getForControl()).getCondition()); | ||
} else { | ||
result = TypeCheck3.typeOf(((ASTCommonForControl) node.getForControl()).getCondition()); | ||
} | ||
|
||
if (!SymTypeRelations.isBoolean(result)) { | ||
Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); | ||
} | ||
|
||
} | ||
} |
26 changes: 22 additions & 4 deletions
26
...rammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForEachIsValid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.