Commit 75ffe205 authored by Sebastian Nickels's avatar Sebastian Nickels
Browse files

Updated constants

parent 349d487d
Pipeline #200232 passed with stages
in 17 minutes and 5 seconds
......@@ -71,7 +71,8 @@ public class CNNArchCocos {
.addCoCo(new CheckNetworkStreamMissing())
.addCoCo(new CheckVariableMember())
.addCoCo(new CheckLayerVariableDeclarationLayerType())
.addCoCo(new CheckLayerVariableDeclarationIsUsed());
.addCoCo(new CheckLayerVariableDeclarationIsUsed())
.addCoCo(new CheckConstants());
}
//checks cocos based on symbols before the resolve method of the ArchitectureSymbol is called
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch._cocos;
import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureElementSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.ConstantSymbol;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.se_rwth.commons.logging.Log;
import java.util.Optional;
public class CheckConstants extends CNNArchSymbolCoCo {
@Override
public void check(ArchitectureElementSymbol sym) {
if (sym instanceof ConstantSymbol) {
checkConstant((ConstantSymbol) sym);
}
}
public void checkConstant(ConstantSymbol constant) {
Optional<Boolean> isInt = constant.getExpression().isInt();
if (!isInt.isPresent() || !isInt.get()) {
Log.error("0" + ErrorCodes.INVALID_CONSTANT + " Invalid constant, only integers allowed. ",
constant.getSourcePosition());
}
}
}
......@@ -41,6 +41,7 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
private List<NetworkInstructionSymbol> networkInstructions = new ArrayList<>();
private List<VariableSymbol> inputs = new ArrayList<>();
private List<VariableSymbol> outputs = new ArrayList<>();
private List<ConstantSymbol> constants = new ArrayList<>();
private String dataPath;
private String componentName;
......@@ -108,6 +109,10 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
this.outputs = outputs;
}
public List<ConstantSymbol> getConstants() {
return constants;
}
public Collection<IODeclarationSymbol> getIODeclarations(){
return getEnclosingScope().resolveLocally(IODeclarationSymbol.KIND);
}
......
......@@ -41,6 +41,10 @@ public class ConstantSymbol extends ArchitectureElementSymbol {
return expression;
}
public int getIntValue() {
return getExpression().getIntValue().get();
}
protected void setExpression(ArchSimpleExpressionSymbol expression) {
this.expression = expression;
}
......@@ -80,6 +84,9 @@ public class ConstantSymbol extends ArchitectureElementSymbol {
if (!isResolved()) {
if (isResolvable()) {
resolveExpressions();
getArchitecture().getConstants().add(this);
setResolvedThis(this);
}
}
......
......@@ -48,5 +48,6 @@ public class ErrorCodes {
public static final String INVALID_MEMBER = "x04896";
public static final String ILLEGAL_LAYER_USE = "x04845";
public static final String UNUSED_LAYER = "x04847";
public static final String INVALID_CONSTANT = "x04856";
}
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