Commit ad995430 authored by Thomas Michael Timmermanns's avatar Thomas Michael Timmermanns Committed by Thomas Michael Timmermanns

refactoring

parent 165b3f66
......@@ -61,7 +61,7 @@ grammar CNNArch extends de.monticore.lang.math.Math {
ArchExpression = (expression:ArchSimpleExpression | sequence:ArchValueSequence);
interface ArchValueSequence;
interface ArchValueSequence;
ArchParallelSequence implements ArchValueSequence = "[" parallelValues:(ArchSerialSequence || "|")* "]";
......
......@@ -34,13 +34,13 @@ public class ASTArchSpecialArgument extends ASTArchSpecialArgumentTOP {
@Override
public String getName() {
if (getParallel().isPresent()){
return AllPredefinedVariables.CARDINALITY_NAME;
return AllPredefinedVariables.PARALLEL_ARG_NAME;
}
else if (getSerial().isPresent()) {
return AllPredefinedVariables.FOR_NAME;
return AllPredefinedVariables.SERIAL_ARG_NAME;
}
else if (getConditional().isPresent()){
return AllPredefinedVariables.IF_NAME;
return AllPredefinedVariables.CONDITIONAL_ARG_NAME;
}
else {
throw new IllegalStateException();
......
......@@ -54,7 +54,7 @@ public class CheckVariableName implements CNNArchASTVariableCoCo {
". No variable can be named 'true' or 'false'"
, node.get_SourcePositionStart());
}
else if (name.equals(AllPredefinedVariables.IF_NAME.toLowerCase())){
else if (name.equals(AllPredefinedVariables.CONDITIONAL_ARG_NAME.toLowerCase())){
Log.error("0" + ErrorCodes.ILLEGAL_NAME + " Illegal name: " + name +
". No variable can be named 'if'"
, node.get_SourcePositionStart());
......
......@@ -62,7 +62,7 @@ public class ArgumentSymbol extends CommonSymbol {
}
protected void setRhs(ArchExpressionSymbol rhs) {
if (getName().equals(AllPredefinedVariables.FOR_NAME)
if (getName().equals(AllPredefinedVariables.SERIAL_ARG_NAME)
&& rhs instanceof ArchSimpleExpressionSymbol
&& (!rhs.getValue().isPresent() || !rhs.getValue().get().equals(1))){
this.rhs = ArchRangeExpressionSymbol.of(
......@@ -70,7 +70,7 @@ public class ArgumentSymbol extends CommonSymbol {
(ArchSimpleExpressionSymbol) rhs,
false);
}
else if (getName().equals(AllPredefinedVariables.CARDINALITY_NAME)
else if (getName().equals(AllPredefinedVariables.PARALLEL_ARG_NAME)
&& rhs instanceof ArchSimpleExpressionSymbol
&& (!rhs.getValue().isPresent() || !rhs.getValue().get().equals(1))) {
this.rhs = ArchRangeExpressionSymbol.of(
......@@ -116,7 +116,7 @@ public class ArgumentSymbol extends CommonSymbol {
List<ArgumentSymbol> serialArgumentList = new ArrayList<>(serialElementList.size());
for (ArchSimpleExpressionSymbol element : serialElementList){
ArchSimpleExpressionSymbol value = element;
if (getName().equals(AllPredefinedVariables.FOR_NAME) || getName().equals(AllPredefinedVariables.CARDINALITY_NAME)){
if (getName().equals(AllPredefinedVariables.SERIAL_ARG_NAME) || getName().equals(AllPredefinedVariables.PARALLEL_ARG_NAME)){
value = ArchSimpleExpressionSymbol.of(1);
}
......
......@@ -160,7 +160,6 @@ public enum Constraints {
}
return false;
}
@Override
protected String msgString() {
return AllPredefinedMethods.PADDING_VALID + ", "
......@@ -222,7 +221,7 @@ public enum Constraints {
for (List<ArchSimpleExpressionSymbol> expList : exp.getElements().get()) {
for (ArchSimpleExpressionSymbol singleExp : expList) {
if (!isValid(singleExp)) {
Log.error("0" + ILLEGAL_ASSIGNMENT + " Illegal assignment of '" + printName(name) + "'. " +
Log.error("0" + ILLEGAL_ASSIGNMENT + " Illegal assignment of '" + name + "'. " +
"Expression must be " + msgString() + "."
, sourcePosition);
return false;
......@@ -231,16 +230,4 @@ public enum Constraints {
}
return true;
}
private String printName(String name){
if (name.equals(AllPredefinedVariables.FOR_NAME)){
return "->";
}
else if (name.equals(AllPredefinedVariables.CARDINALITY_NAME)){
return "|";
}
else {
return name;
}
}
}
......@@ -211,7 +211,7 @@ public abstract class LayerSymbol extends CommonScopeSpanningSymbol {
}
/**
* deepCopy for LayerSymbols, ArgumentSymbol and ArchExpressionSymbols but does not copy math expressions or scope and ast information.
* deepCopy for LayerSymbols, ArgumentSymbol and ArchExpressionSymbols but does not copy math expressions.
* @return returns a copy of this object
*/
abstract public LayerSymbol copy();
......
......@@ -26,12 +26,8 @@ package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedVariables;
import de.monticore.symboltable.CommonScopeSpanningSymbol;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
public class MethodDeclarationSymbol extends CommonScopeSpanningSymbol {
......@@ -61,17 +57,17 @@ public class MethodDeclarationSymbol extends CommonScopeSpanningSymbol {
protected void setParameters(List<VariableSymbol> parameters) {
this.parameters = parameters;
if (!getParameter(AllPredefinedVariables.IF_NAME).isPresent()){
if (!getParameter(AllPredefinedVariables.CONDITIONAL_ARG_NAME).isPresent()){
VariableSymbol ifParam = AllPredefinedVariables.createIfParameter();
this.parameters.add(ifParam);
ifParam.putInScope(getSpannedScope());
}
if (!getParameter(AllPredefinedVariables.FOR_NAME).isPresent()){
if (!getParameter(AllPredefinedVariables.SERIAL_ARG_NAME).isPresent()){
VariableSymbol forParam = AllPredefinedVariables.createForParameter();
this.parameters.add(forParam);
forParam.putInScope(getSpannedScope());
}
if (!getParameter(AllPredefinedVariables.CARDINALITY_NAME).isPresent()){
if (!getParameter(AllPredefinedVariables.PARALLEL_ARG_NAME).isPresent()){
VariableSymbol forParam = AllPredefinedVariables.createCardinalityParameter();
this.parameters.add(forParam);
forParam.putInScope(getSpannedScope());
......
......@@ -68,7 +68,7 @@ public class MethodLayerSymbol extends LayerSymbol {
}
public ArchExpressionSymbol getIfExpression(){
Optional<ArgumentSymbol> argument = getArgument(AllPredefinedVariables.IF_NAME);
Optional<ArgumentSymbol> argument = getArgument(AllPredefinedVariables.CONDITIONAL_ARG_NAME);
if (argument.isPresent()){
return argument.get().getRhs();
}
......
......@@ -31,7 +31,6 @@ import de.monticore.symboltable.ResolvingConfiguration;
import java.util.Deque;
public class ModifiedMathSymbolTableCreator extends MathSymbolTableCreator {
//todo: remove this class if MontiMath is fixed
public ModifiedMathSymbolTableCreator(ResolvingConfiguration resolverConfiguration, MutableScope enclosingScope) {
super(resolverConfiguration, enclosingScope);
......
......@@ -96,9 +96,6 @@ public class Utils {
public static boolean equals(ASTElementType firstType, ASTElementType secondType){
ASTRange firstRange = firstType.getRange().get();
ASTRange secondRange = secondType.getRange().get();
if (firstType.isIsBoolean() ^ secondType.isIsBoolean()
|| firstType.isIsNatural() ^ secondType.isIsNatural()
|| firstType.isIsRational() ^ secondType.isIsRational()
......@@ -106,6 +103,19 @@ public class Utils {
|| firstType.isIsComplex() ^ secondType.isIsComplex()){
return false;
}
if (firstType.getRange().isPresent()){
if (!secondType.getRange().isPresent()){
return false;
}
}
else {
return !secondType.getRange().isPresent();
}
return equals(firstType.getRange().get(), secondType.getRange().get());
}
public static boolean equals(ASTRange firstRange, ASTRange secondRange){
if (firstRange.getStartInf().isPresent() ^ secondRange.getStartInf().isPresent()
|| firstRange.getEndInf().isPresent() ^ secondRange.getEndInf().isPresent()){
return false;
......@@ -125,5 +135,4 @@ public class Utils {
return true;
}
}
......@@ -26,15 +26,15 @@ import de.monticore.lang.monticar.cnnarch._symboltable.VariableType;
public class AllPredefinedVariables {
public static final String IF_NAME = "?";
public static final String FOR_NAME = "->";
public static final String CARDINALITY_NAME = "|";
public static final String CONDITIONAL_ARG_NAME = "?";
public static final String SERIAL_ARG_NAME = "->";
public static final String PARALLEL_ARG_NAME = "|";
public static final String TRUE_NAME = "true";
public static final String FALSE_NAME = "false";
public static VariableSymbol createIfParameter(){
return new VariableSymbol.Builder()
.name(IF_NAME)
.name(CONDITIONAL_ARG_NAME)
.type(VariableType.METHOD_PARAMETER)
.constraints(Constraints.BOOLEAN)
.defaultValue(true)
......@@ -43,7 +43,7 @@ public class AllPredefinedVariables {
public static VariableSymbol createForParameter(){
return new VariableSymbol.Builder()
.name(FOR_NAME)
.name(SERIAL_ARG_NAME)
.type(VariableType.METHOD_PARAMETER)
.constraints(Constraints.INTEGER, Constraints.POSITIVE)
.defaultValue(1)
......@@ -52,7 +52,7 @@ public class AllPredefinedVariables {
public static VariableSymbol createCardinalityParameter(){
return new VariableSymbol.Builder()
.name(CARDINALITY_NAME)
.name(PARALLEL_ARG_NAME)
.type(VariableType.METHOD_PARAMETER)
.constraints(Constraints.INTEGER, Constraints.POSITIVE)
.defaultValue(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment