Commit d4b75de5 authored by Christian Fuß's avatar Christian Fuß
Browse files

changed UnrollSymbol to extend Scope rather than ArchitectureElementSymbol,...

changed UnrollSymbol to extend Scope rather than ArchitectureElementSymbol, thereby resolved error in EMADL
parent 50fc840b
Pipeline #174377 passed with stages
in 18 minutes and 53 seconds
target
nppBackup
.project
.settings
.classpath
.idea
.git
*.iml
#
#
# ******************************************************************************
# 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/>.
# *******************************************************************************
#
stages:
- windows
- linux
masterJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
- mvn package sonar:sonar -s settings.xml
only:
- master
masterJobWindows:
stage: windows
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
tags:
- Windows10
BranchJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
except:
- master
#
#
# ******************************************************************************
# 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/>.
# *******************************************************************************
#
script:
- git checkout ${TRAVIS_BRANCH}
- mvn clean install cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report --settings "settings.xml"
after_success:
- if [ "${TRAVIS_BRANCH}" == "master" ]; then mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B deploy --debug --settings "./settings.xml"; fi
......@@ -36,6 +36,9 @@ public class CNNArchSymbolCoCo {
else if (sym instanceof UnrollDeclarationSymbol){
check((UnrollDeclarationSymbol) sym);
}
else if (sym instanceof UnrollSymbol){
check((UnrollSymbol) sym);
}
else if (sym instanceof ArchitectureElementSymbol){
check((ArchitectureElementSymbol) sym);
}
......@@ -110,4 +113,8 @@ public class CNNArchSymbolCoCo {
public void check(MathExpressionSymbol sym){
//Override if needed
}
public void check(UnrollSymbol sym){
//Override if needed
}
}
......@@ -41,7 +41,7 @@ public class CheckArchitectureFinished extends CNNArchSymbolCoCo {
}
for (UnrollSymbol unroll : architecture.getUnrolls()) {
System.err.println("UnrollSymbol in checkArchFinished");
if (!unroll.getOutputTypes().isEmpty()){
if (!unroll.getBody().getOutputTypes().isEmpty()){
Log.error("0" + ErrorCodes.UNFINISHED_ARCHITECTURE + " The architecture is not finished. " +
"There are still open streams at the end of the architecture. "
, architecture.getSourcePosition());
......
......@@ -34,7 +34,7 @@ public class CheckElementInputs extends CNNArchSymbolCoCo {
for (UnrollSymbol unroll : architecture.getUnrolls()) {
System.err.println("BEFORE check");
unroll.checkInput();
unroll.getBody().checkInput();
System.err.println("AFTER check");
}
}
......
......@@ -103,7 +103,19 @@ public abstract class ArchitectureElementSymbol extends CommonScopeSpanningSymbo
if (sym instanceof ArchitectureSymbol){
return (ArchitectureSymbol) sym;
}
else {
else if (sym instanceof UnrollSymbol) {
sym = sym.getEnclosingScope().getSpanningSymbol().get();
if(sym instanceof UnrollSymbol) {
System.err.println("Scope1");
return ((ArchitectureElementSymbol)sym.getEnclosingScope().getSpanningSymbol().get()).getArchitecture();
}else if(sym instanceof ArchitectureSymbol) {
System.err.println("Scope2");
return (ArchitectureSymbol)sym;
}else{
System.err.println("Scope3");
return ((ArchitectureElementSymbol)sym).getArchitecture();
}
}else {
return ((ArchitectureElementSymbol) sym).getArchitecture();
}
}
......
......@@ -124,11 +124,10 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
}
for (UnrollSymbol unroll : unrolls) {
unroll.checkIfResolvable();
//unroll.checkIfResolvable();
try {
unroll.resolveOrError();
unroll.getBody().resolveOrError();
unroll.resolve();
}
catch (ArchResolveException e) {
// Do nothing; error is already logged
......@@ -143,9 +142,6 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
resolved &= stream.isResolved();
}
for (UnrollSymbol unroll: unrolls) {
resolved &= unroll.isResolved();
}
return resolved;
}
......
......@@ -345,17 +345,9 @@ public class CNNArchSymbolTableCreator extends de.monticore.symboltable.CommonSy
@Override
public void endVisit(ASTUnroll ast) {
UnrollSymbol layer = (UnrollSymbol) ast.getSymbolOpt().get();
SerialCompositeElementSymbol sces = new SerialCompositeElementSymbol();
List<ArchitectureElementSymbol> elements = new ArrayList<>();
for (ASTArchitectureElement astElement : ast.getBody().getElementsList()){
elements.add((ArchitectureElementSymbol) astElement.getSymbolOpt().get());
}
sces.setElements(elements);
layer.setBody(sces);
layer.setBody((SerialCompositeElementSymbol) ast.getBody().getSymbolOpt().get());
//layer.getDeclaration().setBody(sces);
//layer.setElements(elements);
List<ArgumentSymbol> arguments = new ArrayList<>(6);
for (ASTArchArgument astArgument : ast.getArgumentsList()){
Optional<ArgumentSymbol> optArgument = astArgument.getSymbolOpt().map(e -> (ArgumentSymbol)e);
......
......@@ -64,9 +64,6 @@ public abstract class CompositeElementSymbol extends ArchitectureElementSymbol {
}
}
}
else if (element instanceof UnrollSymbol) {
isTrainable |= ((UnrollSymbol) element).isTrainable();
}
}
return isTrainable;
......
......@@ -112,25 +112,12 @@ public class UnrollDeclarationSymbol extends CommonScopeSpanningSymbol {
}
public ArchitectureElementSymbol call(UnrollSymbol layer) throws ArchResolveException{
public UnrollSymbol call(UnrollSymbol layer) throws ArchResolveException{
checkForSequence(layer.getArguments());
if (isPredefined()){
return layer;
}
else {
reset();
set(layer.getArguments());
SerialCompositeElementSymbol copy = getBody().preResolveDeepCopy();
copy.putInScope(getSpannedScope());
copy.resolveOrError();
getSpannedScope().remove(copy);
getSpannedScope().removeSubScope(copy.getSpannedScope());
reset();
return copy;
}
return layer;
}
private void reset(){
......
/**
*
* ******************************************************************************
* 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._symboltable;
import de.monticore.symboltable.SymbolKind;
public class UnrollKind implements SymbolKind {
private static final String NAME = "de.monticore.lang.monticar.cnnarch._symboltable.UnrollKind";
@Override
public String getName() {
return NAME;
}
@Override
public boolean isKindOf(SymbolKind kind) {
return NAME.equals(kind.getName()) || SymbolKind.super.isKindOf(kind);
}
}
......@@ -24,44 +24,23 @@ package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedLayers;
import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedVariables;
import de.monticore.symboltable.CommonScopeSpanningSymbol;
import de.monticore.symboltable.Scope;
import de.monticore.symboltable.Symbol;
import de.monticore.symboltable.SymbolKind;
import de.se_rwth.commons.logging.Log;
import java.util.*;
import java.util.function.Function;
public class UnrollSymbol extends ArchitectureElementSymbol {
protected List<ArchitectureElementSymbol> elements = new ArrayList<>();
protected void setElements(List<ArchitectureElementSymbol> elements) {
ArchitectureElementSymbol previous = null;
for (ArchitectureElementSymbol current : elements){
if (previous != null){
current.setInputElement(previous);
previous.setOutputElement(current);
}
else {
if (getInputElement().isPresent()){
current.setInputElement(getInputElement().get());
}
if (getOutputElement().isPresent()){
current.setOutputElement(getOutputElement().get());
}
}
previous = current;
}
this.elements = elements;
}
public List<ArchitectureElementSymbol> getElements() {
return elements;
}
public class UnrollSymbol extends CommonScopeSpanningSymbol {
public static final UnrollKind KIND = new UnrollKind();
private UnrollDeclarationSymbol declaration = null;
private List<ArgumentSymbol> arguments;
private Set<ParameterSymbol> unresolvableParameters = null;
private UnrollSymbol resolvedThis = null;
private SerialCompositeElementSymbol body;
public SerialCompositeElementSymbol getBody() {
......@@ -77,7 +56,7 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
protected UnrollSymbol(String name) {
super(name);
super(name, KIND);
}
public UnrollDeclarationSymbol getDeclaration() {
......@@ -90,9 +69,9 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
return declaration;
}
@Override
public boolean isResolvable() {
return super.isResolvable() && getDeclaration() != null;
return getBody().isResolvable() && getDeclaration() != null;
}
private void setDeclaration(UnrollDeclarationSymbol declaration) {
......@@ -117,23 +96,6 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
}
@Override
public void setInputElement(ArchitectureElementSymbol inputElement) {
super.setInputElement(inputElement);
if (getResolvedThis().isPresent() && getResolvedThis().get() != this){
getResolvedThis().get().setInputElement(inputElement);
}
}
@Override
public void setOutputElement(ArchitectureElementSymbol outputElement) {
super.setOutputElement(outputElement);
if (getResolvedThis().isPresent() && getResolvedThis().get() != this){
getResolvedThis().get().setOutputElement(outputElement);
}
}
@Override
protected void putInScope(Scope scope){
Collection<Symbol> symbolsInScope = scope.getLocalSymbols().get(getName());
if (symbolsInScope == null || !symbolsInScope.contains(this)){
......@@ -142,56 +104,39 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
getResolvedThis().get().putInScope(getSpannedScope());
}*/
for (ArgumentSymbol argument : getArguments()){
argument.putInScope(getSpannedScope());
argument.putInScope(getSpannedScope().getAsMutableScope());
}
}
}
@Override
public boolean isAtomic(){
return getResolvedThis().isPresent() && getResolvedThis().get() == this;
}
protected void setResolvedThis(UnrollSymbol resolvedThis) {
if (resolvedThis != null){
//resolvedThis.putInScope(getSpannedScope());
@Override
public List<ArchitectureElementSymbol> getFirstAtomicElements() {
return this.getBody().getElements().get(0).getFirstAtomicElements();
}
System.err.println("setResolvedThis() called");
this.resolvedThis = resolvedThis;
}
@Override
public List<ArchitectureElementSymbol> getLastAtomicElements() {
return this.getBody().getElements().get(this.getBody().getElements().size()-1).getLastAtomicElements();
}
@Override
public Set<ParameterSymbol> resolve() throws ArchResolveException {
if (!isResolved()) {
if (true) {
if (isResolvable()) {
getDeclaration();
resolveExpressions();
int parallelLength = getParallelLength().get();
int maxSerialLength = getMaxSerialLength().get();
if (!isActive() || maxSerialLength == 0) {
System.err.println("UnrollSymbol resolveSequences called!1");
//set resolvedThis to empty composite to remove the unroll.
setResolvedThis(new SerialCompositeElementSymbol());
}
else if (parallelLength == 1 && maxSerialLength == 1) {
System.err.println("UnrollSymbol resolveSequences called!2");
//resolve the unroll call
ArchitectureElementSymbol resolvedUnroll = getDeclaration().call(this);
setResolvedThis(resolvedUnroll);
}
else {
System.err.println("UnrollSymbol resolveSequences called!3");
//split the unroll if it contains an argument sequence
ArchitectureElementSymbol splitComposite = resolveSequences(parallelLength, getSerialLengths().get());
setResolvedThis(splitComposite);
splitComposite.resolveOrError();
}
System.err.println("UnrollSymbol resolveSequences called!2");
//resolve the unroll call
getBody().resolveOrError();
System.err.println("BODY1: " +getBody().getElements().toString());
UnrollSymbol resolvedUnroll = getDeclaration().call(this);
setResolvedThis(resolvedUnroll);
System.err.println("HERE1");
}
}
return getUnresolvableParameters();
return new HashSet<ParameterSymbol>() ;
}
private boolean isActive(){
......@@ -209,26 +154,6 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
}
private ArchitectureElementSymbol resolveSequences(int parallelLength, List<Integer> serialLengths){
List<List<ArchitectureElementSymbol>> elements = computeExpandedSplit(parallelLength, serialLengths);
List<ArchitectureElementSymbol> serialComposites = new ArrayList<>();
if (elements.size() == 1){
return createSerialSequencePart(elements.get(0));
}
else {
for (List<ArchitectureElementSymbol> serialElements : elements) {
serialComposites.add(createSerialSequencePart(serialElements));
}
ParallelCompositeElementSymbol parallelElement = new ParallelCompositeElementSymbol();
parallelElement.setElements(serialComposites);
if (getAstNode().isPresent()) {
parallelElement.setAstNode(getAstNode().get());
}
return parallelElement;
}
}
private ArchitectureElementSymbol createSerialSequencePart(List<ArchitectureElementSymbol> elements){
if (elements.size() == 1){
......@@ -245,37 +170,9 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
}
private List<List<ArchitectureElementSymbol>> computeExpandedSplit(int parallelLength, List<Integer> serialLengths){
List<List<ArchitectureElementSymbol>> elements = new ArrayList<>(parallelLength);
List<List<List<ArgumentSymbol>>> allExpandedArguments = new ArrayList<>(getArguments().size());
for (ArgumentSymbol argument : getArguments()){
allExpandedArguments.add(argument.expandedSplit(parallelLength, serialLengths).get());
}
for (int i = 0; i < parallelLength; i++){
List<ArchitectureElementSymbol> serialElementList = new ArrayList<>(serialLengths.get(i));
for (int j = 0; j < serialLengths.get(i); j++){
List<ArgumentSymbol> unrollArguments = new ArrayList<>();
for (List<List<ArgumentSymbol>> args : allExpandedArguments){
unrollArguments.add(args.get(i).get(j));
}
UnrollSymbol unroll = new UnrollSymbol.Builder()
.declaration(getDeclaration())
.arguments(unrollArguments)
.build();
if (getAstNode().isPresent()){
unroll.setAstNode(getAstNode().get());
}
serialElementList.add(unroll);
}
elements.add(serialElementList);
}
return elements;
}
@Override
protected void computeUnresolvableParameters(Set<ParameterSymbol> unresolvableVariables, Set<ParameterSymbol> allVariables) {
for (ArgumentSymbol argument : getArguments()){
argument.getRhs().checkIfResolvable(allVariables);
......@@ -283,36 +180,6 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
}
@Override
public List<ArchTypeSymbol> computeOutputTypes() {
System.err.println("##33333333");
if (getResolvedThis().isPresent()) {
if (getResolvedThis().get() == this) {
List<ArchTypeSymbol> inputTypes = getInputTypes();
return ((PredefinedUnrollDeclaration) getDeclaration()).computeOutputTypes(inputTypes, this, VariableSymbol.Member.NONE);
}
else {
return getResolvedThis().get().getOutputTypes();
}
}
else {
throw new IllegalStateException("Output type cannot be computed before the unroll is resolved");
}
}
@Override
public void checkInput() {
if (getResolvedThis().isPresent()){
if (getResolvedThis().get() == this){
((PredefinedUnrollDeclaration) getDeclaration()).checkInput(getInputTypes(), this, VariableSymbol.Member.NONE);
}
else {
getResolvedThis().get().checkInput();
}
}
}
public Optional<ArgumentSymbol> getArgument(String name){
for (ArgumentSymbol argument : getArguments()){
if (argument.getName().equals(name)) {
......@@ -360,117 +227,9 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
}
@Override
public Optional<Integer> getParallelLength(){
int length = -1;
for (ArgumentSymbol argument : getArguments()) {
if (argument.getRhs() instanceof ArchAbstractSequenceExpression) {
Optional<Integer> optParallelLength = argument.getRhs().getParallelLength();
if (optParallelLength.isPresent()) {
int argLength = optParallelLength.get();
if (length == -1) {
length = argLength;
}
else if (length != argLength) {
Log.error("0" + ErrorCodes.ILLEGAL_SEQUENCE_LENGTH + " Illegal sequence length. " +
"Length is " + argLength + " but it should be " + length + " or not a sequence. " +
"All parallel sequences in the same unroll must be of the same size. "
, argument.getSourcePosition());
}
}
else {
return Optional.empty();
}
}