Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
languages
EmbeddedMontiArcDL
Commits
6704cd5e
Commit
6704cd5e
authored
Apr 28, 2018
by
Thomas Michael Timmermanns
Committed by
Thomas Michael Timmermanns
Apr 28, 2018
Browse files
Added component instances with config parameters.
Merged CNNTrain branch and extended CNNTrain generation with instances.
parent
607a9705
Changes
32
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
6704cd5e
...
...
@@ -48,7 +48,7 @@
<CNNTrain.version>
0.2.0-SNAPSHOT
</CNNTrain.version>
<Math.version>
0.0.11-SNAPSHOT
</Math.version>
<Embedded-MontiArc-Math.version>
0.0.11-SNAPSHOT
</Embedded-MontiArc-Math.version>
<embedded-montiarc-math-generator>
0.0.
7
-SNAPSHOT
</embedded-montiarc-math-generator>
<embedded-montiarc-math-generator>
0.0.
9
-SNAPSHOT
</embedded-montiarc-math-generator>
<!-- .. Libraries .................................................. -->
<guava.version>
18.0
</guava.version>
...
...
src/main/java/de/monticore/lang/monticar/emadl/_cocos/CheckArchitecture.java
View file @
6704cd5e
...
...
@@ -20,16 +20,15 @@
*/
package
de.monticore.lang.monticar.emadl._cocos
;
import
de.monticore.lang.monticar.cnnarch._ast.ASTArchitecture
;
import
de.monticore.lang.monticar.cnnarch._cocos.CNNArchASTArchitectureCoCo
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol
;
import
de.monticore.lang.monticar.cnnarch._cocos.CNNArchCocos
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol
;
public
class
CheckArchitecture
implements
CNNArchASTArchitectureCoCo
{
public
class
CheckArchitecture
{
@Override
public
void
check
(
ASTArchitecture
node
)
{
ArchitectureSymbol
architecture
=
(
ArchitectureSymbol
)
node
.
getSymbol
(
).
get
();
public
static
void
check
(
ExpandedComponentInstanceSymbol
instance
)
{
ArchitectureSymbol
architecture
=
instance
.
getSpannedScope
().
<
ArchitectureSymbol
>
resolve
(
""
,
ArchitectureSymbol
.
KIND
).
get
();
CNNArchCocos
.
checkAll
(
architecture
);
}
}
src/main/java/de/monticore/lang/monticar/emadl/_cocos/EMADLCocos.java
View file @
6704cd5e
...
...
@@ -21,13 +21,25 @@
package
de.monticore.lang.monticar.emadl._cocos
;
import
de.monticore.lang.embeddedmontiarc.cocos.*
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath.cocos.AtomicComponentCoCo
;
import
de.monticore.lang.math.math._cocos.MatrixAssignmentDeclarationCheck
;
import
de.monticore.lang.monticar.cnnarch._cocos.CNNArchCocos
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol
;
import
java.util.Optional
;
//check all cocos
public
class
EMADLCocos
{
public
static
EMADLCoCoChecker
createChecker
()
{
public
static
void
checkAll
(
ExpandedComponentInstanceSymbol
instance
){
Optional
<
ArchitectureSymbol
>
architecture
=
instance
.
getSpannedScope
().
resolve
(
""
,
ArchitectureSymbol
.
KIND
);
architecture
.
ifPresent
(
CNNArchCocos:
:
checkAll
);
}
private
static
EMADLCoCoChecker
createASTChecker
()
{
CheckBehaviorName
behaviorCoco
=
new
CheckBehaviorName
();
return
new
EMADLCoCoChecker
()
//EMA cocos
...
...
@@ -49,10 +61,7 @@ public class EMADLCocos {
.
addCoCo
((
EMADLASTBehaviorNameCoCo
)
behaviorCoco
)
.
addCoCo
(
new
AtomicComponentCoCo
())
//Math cocos
.
addCoCo
(
new
MatrixAssignmentDeclarationCheck
())
.
addCoCo
(
new
MatrixAssignmentDeclarationCheck
())
;
//.addCoCo(new MatrixAssignmentCheck())
//CNNArch coco (already checked in CNNArchGenerator)
.
addCoCo
(
new
CheckArchitecture
());
}
}
src/main/java/de/monticore/lang/monticar/emadl/_symboltable/EMADLSymbolTableCreator.java
View file @
6704cd5e
...
...
@@ -23,7 +23,6 @@ package de.monticore.lang.monticar.emadl._symboltable;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcSymbolTableCreator
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarcbehavior._symboltable.EmbeddedMontiArcBehaviorSymbolTableCreator
;
import
de.monticore.lang.monticar.cnnarch._symboltable.CNNArchSymbolTableCreator
;
import
de.monticore.lang.monticar.emadl._ast.ASTEMADLCompilationUnit
;
import
de.monticore.lang.monticar.emadl._visitor.CommonEMADLDelegatorVisitor
;
import
de.monticore.lang.monticar.emadl._visitor.EMADLVisitor
;
import
de.monticore.symboltable.MutableScope
;
...
...
@@ -54,7 +53,7 @@ public class EMADLSymbolTableCreator extends de.monticore.symboltable.CommonSymb
}
private
void
initSuperSTC
(
final
ResolvingConfiguration
resolvingConfig
)
{
this
.
emaSTC
=
new
EmbeddedMontiArc
SymbolTableCreator
(
resolvingConfig
,
scopeStack
);
this
.
emaSTC
=
new
ModifiedEMASymbolTableCreator
(
resolvingConfig
,
scopeStack
);
//new ModifiedEMA
SymbolTableCreator(resolvingConfig, scopeStack);
this
.
cnnArchSTC
=
new
CNNArchSymbolTableCreator
(
resolvingConfig
,
scopeStack
);
visitor
.
set_de_monticore_lang_embeddedmontiarc_embeddedmontiarc__visitor_EmbeddedMontiArcVisitor
(
emaSTC
);
...
...
@@ -99,11 +98,11 @@ public class EMADLSymbolTableCreator extends de.monticore.symboltable.CommonSymb
}
}
@Override
/*
@Override
public void visit(ASTEMADLCompilationUnit ast) {
EMADLCompilationUnitSymbol compilationUnit = new EMADLCompilationUnitSymbol("");
addToScopeAndLinkWithNode(compilationUnit, ast);
}
}
*/
}
src/main/java/de/monticore/lang/monticar/emadl/_symboltable/ModifiedEMASymbolTableCreator.java
0 → 100644
View file @
6704cd5e
/**
*
* ******************************************************************************
* 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.emadl._symboltable
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTEMACompilationUnit
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ComponentSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcSymbolTableCreator
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.ResolvingConfiguration
;
import
de.se_rwth.commons.logging.Log
;
import
java.util.Deque
;
public
class
ModifiedEMASymbolTableCreator
extends
EmbeddedMontiArcSymbolTableCreator
{
private
ModifiedExpandedInstanceSymbolCreator
instanceSymbolCreator
=
new
ModifiedExpandedInstanceSymbolCreator
();
public
ModifiedEMASymbolTableCreator
(
ResolvingConfiguration
resolverConfig
,
MutableScope
enclosingScope
)
{
super
(
resolverConfig
,
enclosingScope
);
}
public
ModifiedEMASymbolTableCreator
(
ResolvingConfiguration
resolvingConfig
,
Deque
<
MutableScope
>
scopeStack
)
{
super
(
resolvingConfig
,
scopeStack
);
}
public
ModifiedExpandedInstanceSymbolCreator
getInstanceSymbolCreator
()
{
return
instanceSymbolCreator
;
}
@Override
public
void
endVisit
(
ASTEMACompilationUnit
node
)
{
this
.
removeCurrentScope
();
if
(!
this
.
aboartVisitComponent
)
{
Log
.
debug
(
"endVisit of "
+
node
.
getComponent
().
getSymbol
().
get
().
getFullName
(),
"SymbolTableCreator:"
);
getInstanceSymbolCreator
().
createInstances
((
ComponentSymbol
)(
Log
.
errorIfNull
(
node
.
getComponent
().
getSymbol
().
orElse
(
null
))));
}
}
}
src/main/java/de/monticore/lang/monticar/emadl/_symboltable/ModifiedExpandedComponentInstanceBuilder.java
0 → 100644
View file @
6704cd5e
/**
*
* ******************************************************************************
* 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.emadl._symboltable
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*
;
import
de.monticore.lang.math.math._ast.ASTMathNumberExpression
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchSimpleExpressionSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.VariableSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.VariableType
;
import
de.monticore.lang.monticar.ts.MCFieldSymbol
;
import
de.se_rwth.commons.logging.Log
;
import
java.util.*
;
public
class
ModifiedExpandedComponentInstanceBuilder
extends
ExpandedComponentInstanceBuilder
{
@Override
public
ExpandedComponentInstanceSymbol
build
()
{
ExpandedComponentInstanceSymbol
instance
=
super
.
build
();
ComponentSymbol
component
=
instance
.
getComponentType
().
getReferencedSymbol
();
Optional
<
ArchitectureSymbol
>
architecture
=
component
.
getSpannedScope
()
.
resolve
(
""
,
ArchitectureSymbol
.
KIND
);
if
(
architecture
.
isPresent
()){
addPortArraySymbolsToInstance
(
instance
);
addVariableSymbolsToInstance
(
instance
);
ArchitectureSymbol
architectureInstance
=
architecture
.
get
()
.
preResolveDeepCopy
(
instance
.
getSpannedScope
());
instance
.
getSpannedScope
().
getAsMutableScope
().
add
(
architectureInstance
);
}
return
instance
;
}
public
void
addVariableSymbolsToInstance
(
ExpandedComponentInstanceSymbol
instance
){
for
(
int
i
=
0
;
i
<
instance
.
getArguments
().
size
();
i
++){
if
(!(
instance
.
getArguments
().
get
(
i
)
instanceof
ASTMathNumberExpression
)){
Log
.
error
(
"Argument type error. Arguments of a CNN component "
+
"that are not numbers are not supported."
,
instance
.
getArguments
().
get
(
i
).
get_SourcePositionStart
());
}
ASTMathNumberExpression
exp
=
(
ASTMathNumberExpression
)
instance
.
getArguments
().
get
(
i
);
MCFieldSymbol
emaParam
=
instance
.
getComponentType
().
getConfigParameters
().
get
(
i
);
VariableSymbol
archParam
=
new
VariableSymbol
.
Builder
()
.
name
(
emaParam
.
getName
())
.
type
(
VariableType
.
ARCHITECTURE_PARAMETER
)
.
build
();
archParam
.
setExpression
(
ArchSimpleExpressionSymbol
.
of
(
exp
.
getNumber
().
getUnitNumber
().
get
().
getNumber
().
get
()));
instance
.
getSpannedScope
().
getAsMutableScope
().
add
(
archParam
);
}
}
public
void
addPortArraySymbolsToInstance
(
ExpandedComponentInstanceSymbol
instance
){
Map
<
String
,
List
<
PortSymbol
>>
nameToPortList
=
new
HashMap
<>();
for
(
PortSymbol
port
:
instance
.
getPorts
()){
List
<
PortSymbol
>
list
=
nameToPortList
.
computeIfAbsent
(
port
.
getNameWithoutArrayBracketPart
(),
k
->
new
ArrayList
<>());
list
.
add
(
port
);
}
for
(
String
name
:
nameToPortList
.
keySet
()){
if
(!
instance
.
getSpannedScope
().
resolveLocally
(
name
,
PortArraySymbol
.
KIND
).
isPresent
())
{
List
<
PortSymbol
>
ports
=
nameToPortList
.
get
(
name
);
PortArraySymbol
portArray
=
new
PortArraySymbol
(
name
,
null
);
portArray
.
setDimension
(
ports
.
size
());
portArray
.
setDirection
(
ports
.
get
(
0
).
isIncoming
());
portArray
.
setTypeReference
(
ports
.
get
(
0
).
getTypeReference
());
instance
.
getSpannedScope
().
getAsMutableScope
().
add
(
portArray
);
}
}
}
}
src/main/java/de/monticore/lang/monticar/emadl/_symboltable/ModifiedExpandedInstanceSymbolCreator.java
0 → 100644
View file @
6704cd5e
/**
*
* ******************************************************************************
* 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.emadl._symboltable
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*
;
import
de.monticore.lang.monticar.si._symboltable.ResolutionDeclarationSymbol
;
import
de.monticore.symboltable.Symbol
;
import
de.monticore.symboltable.resolving.ResolvingFilter
;
import
de.se_rwth.commons.logging.Log
;
import
java.util.List
;
import
java.util.Set
;
public
class
ModifiedExpandedInstanceSymbolCreator
extends
EmbeddedMontiArcExpandedComponentInstanceSymbolCreator
{
@Override
protected
ExpandedComponentInstanceBuilder
createInstance
(
ComponentSymbol
cmp
,
Set
<
ResolvingFilter
<?
extends
Symbol
>>
filters
,
List
<
ResolutionDeclarationSymbol
>
resolutionDeclarationSymbols
)
{
ModifiedExpandedComponentInstanceBuilder
builder
=
new
ModifiedExpandedComponentInstanceBuilder
();
//everything below is copied from super class
builder
.
setSymbolReference
(
new
ComponentSymbolReference
(
cmp
.
getName
(),
cmp
.
getEnclosingScope
()))
.
addPorts
(
cmp
.
getPorts
())
.
addConnectors
(
cmp
.
getConnectors
()).
addResolutionDeclarationSymbols
(
cmp
.
getResolutionDeclarationSymbols
()).
addParameters
(
cmp
.
getParameters
()).
addArguments
(
cmp
.
getArguments
());
for
(
ConnectorSymbol
connectorSymbol
:
cmp
.
getConnectors
())
Log
.
info
(
connectorSymbol
.
toString
(),
"Building Connector:"
);
// add sub components
for
(
ComponentInstanceSymbol
inst
:
cmp
.
getSubComponents
())
{
// System.err.println("would create now: " + inst.getName() + "[" + inst.getComponentType().getFullName() + "]");
Log
.
info
(
inst
.
getComponentType
().
getReferencedSymbol
().
howManyResolutionDeclarationSymbol
()
+
""
,
"Important:"
);
Log
.
debug
(
inst
.
toString
(),
"ComponentInstance CreateInstance PreSub"
);
builder
.
addSubComponent
(
createInstance
(
inst
.
getComponentType
(),
filters
,
inst
.
getComponentType
().
getReferencedSymbol
().
getResolutionDeclarationSymbols
())
.
setName
(
inst
.
getName
())
.
addActualTypeArguments
(
inst
.
getComponentType
().
getFormalTypeParameters
(),
inst
.
getComponentType
().
getActualTypeArguments
()).
addResolvingFilters
(
filters
).
addResolutionDeclarationSymbols
(
inst
.
getComponentType
().
getResolutionDeclarationSymbols
()).
addParameters
(
inst
.
getComponentType
().
getReferencedSymbol
().
getParameters
()).
addArguments
(
inst
.
getComponentType
().
getReferencedSymbol
().
getArguments
()).
build
());
Log
.
debug
(
inst
.
getInstanceInformation
().
get
().
getInstanceNumberForArgumentIndex
(
0
)
+
""
,
"InstanceInformation:"
);
Log
.
debug
(
inst
.
toString
(),
"ComponentInstance CreateInstance PostSub"
);
}
// add inherited ports and sub components
for
(
ComponentSymbol
superCmp
=
cmp
;
superCmp
.
getSuperComponent
().
isPresent
();
superCmp
=
superCmp
.
getSuperComponent
().
get
())
{
if
(
superCmp
.
getSuperComponent
().
get
().
getFormalTypeParameters
().
size
()
!=
superCmp
.
getSuperComponent
().
get
().
getActualTypeArguments
().
size
())
{
Log
.
error
(
String
.
format
(
"Super component '%s' definition has %d generic parameters, but its"
+
"instantiation has %d binds generic parameters"
,
superCmp
.
getFullName
(),
superCmp
.
getSuperComponent
().
get
().
getFormalTypeParameters
().
size
(),
superCmp
.
getSuperComponent
().
get
().
getActualTypeArguments
().
size
()));
return
null
;
}
builder
.
addPortsIfNameDoesNotExists
(
superCmp
.
getSuperComponent
().
get
().
getPorts
(),
superCmp
.
getSuperComponent
().
get
().
getFormalTypeParameters
(),
superCmp
.
getSuperComponent
().
get
().
getActualTypeArguments
());
builder
.
addConnectorsIfNameDoesNotExists
(
superCmp
.
getSuperComponent
().
get
().
getConnectors
());
//Log.debug(superCmp.toString(), "superCmp pre lambda");
superCmp
.
getSuperComponent
().
get
().
getSubComponents
().
stream
().
forEachOrdered
(
inst
->
builder
.
addSubComponentIfNameDoesNotExists
(
createInstance
(
inst
.
getComponentType
(),
filters
,
null
).
setName
(
inst
.
getName
())
.
addActualTypeArguments
(
inst
.
getComponentType
().
getFormalTypeParameters
(),
inst
.
getComponentType
().
getActualTypeArguments
())
.
addResolvingFilters
(
filters
).
addResolutionDeclarationSymbols
(
inst
.
getComponentType
().
getReferencedSymbol
().
getResolutionDeclarationSymbols
()).
addParameters
(
inst
.
getComponentType
().
getReferencedSymbol
().
getParameters
()).
build
())
);
//Log.debug(superCmp.toString(), "superCmp post lambda");
}
return
builder
;
}
@Override
public
void
createInstances
(
ComponentSymbol
topComponent
)
{
super
.
createInstances
(
topComponent
);
}
}
src/main/java/de/monticore/lang/monticar/emadl/adapter/PortArraySymbol2IODeclarationSymbol.java
View file @
6704cd5e
...
...
@@ -22,8 +22,11 @@ package de.monticore.lang.monticar.emadl.adapter;
import
de.monticore.ast.ASTNode
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortArraySymbol
;
import
de.monticore.lang.math.math._symboltable.expression.MathNameExpressionSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchSimpleExpressionSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchTypeSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.IODeclarationSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.VariableSymbol
;
import
de.monticore.lang.monticar.common2._ast.ASTCommonDimensionElement
;
import
de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType
;
import
de.monticore.lang.monticar.ts.MCASTTypeSymbol
;
...
...
@@ -48,7 +51,7 @@ public class PortArraySymbol2IODeclarationSymbol extends IODeclarationSymbol
setArrayLength
(
ps
.
getDimension
());
ArchTypeSymbol
type
=
new
ArchTypeSymbol
();
List
<
Integer
>
shape
=
getShape
(
ps
);
List
<
ArchSimpleExpressionSymbol
>
shape
=
getShape
(
ps
);
if
(
shape
.
size
()
>=
1
){
type
.
setChannelIndex
(
0
);
}
...
...
@@ -59,7 +62,7 @@ public class PortArraySymbol2IODeclarationSymbol extends IODeclarationSymbol
type
.
setWidthIndex
(
2
);
}
type
.
setElementType
(
getElementType
(
ps
));
type
.
setDimensions
(
shape
);
type
.
setDimension
Symbol
s
(
shape
);
setType
(
type
);
...
...
@@ -82,15 +85,24 @@ public class PortArraySymbol2IODeclarationSymbol extends IODeclarationSymbol
}
}
private
List
<
Integer
>
getShape
(
PortArraySymbol
port
){
List
<
Integer
>
dimensionList
=
new
ArrayList
<>(
4
);
private
List
<
ArchSimpleExpressionSymbol
>
getShape
(
PortArraySymbol
port
){
List
<
ArchSimpleExpressionSymbol
>
dimensionList
=
new
ArrayList
<>(
4
);
ASTType
astType
=
getASTType
(
port
);
if
(
astType
instanceof
ASTCommonMatrixType
){
ASTCommonMatrixType
matrixType
=
(
ASTCommonMatrixType
)
astType
;
for
(
ASTCommonDimensionElement
element
:
matrixType
.
getCommonDimension
().
getCommonDimensionElements
()){
int
dimension
=
element
.
getUnitNumber
().
get
().
getNumber
().
get
().
getDividend
().
intValue
();
dimensionList
.
add
(
dimension
);
if
(
element
.
getUnitNumber
().
isPresent
()){
int
dimension
=
element
.
getUnitNumber
().
get
().
getNumber
().
get
().
getDividend
().
intValue
();
dimensionList
.
add
(
ArchSimpleExpressionSymbol
.
of
(
dimension
));
}
else
{
ArchSimpleExpressionSymbol
dimension
=
ArchSimpleExpressionSymbol
.
of
(
new
MathNameExpressionSymbol
(
element
.
getName
().
get
()));
VariableSymbol
variable
=
port
.
getEnclosingScope
()
.<
VariableSymbol
>
resolve
(
element
.
getName
().
get
(),
VariableSymbol
.
KIND
).
get
();
dimensionList
.
add
(
variable
.
getExpression
());
}
}
}
...
...
src/main/java/de/monticore/lang/monticar/emadl/generator/Generator.java
View file @
6704cd5e
...
...
@@ -20,6 +20,8 @@
*/
package
de.monticore.lang.monticar.emadl.generator
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Splitter
;
import
de.monticore.io.paths.ModelPath
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTComponent
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ComponentSymbol
;
...
...
@@ -114,13 +116,14 @@ public class Generator {
Scope
symtab
){
allInstances
.
add
(
componentInstanceSymbol
);
ASTComponent
astComponent
=
(
ASTComponent
)
componentInstanceSymbol
.
getComponentType
().
getReferencedSymbol
().
getAstNode
().
get
();
EMADLCocos
.
createChecker
().
checkAll
(
astComponent
);
Optional
<
ArchitectureSymbol
>
architecture
=
astC
omponent
.
getSpannedScope
().
get
().
resolve
(
""
,
ArchitectureSymbol
.
KIND
);
Optional
<
ArchitectureSymbol
>
architecture
=
c
omponent
InstanceSymbol
.
getSpannedScope
().
resolve
(
""
,
ArchitectureSymbol
.
KIND
);
Optional
<
MathStatementsSymbol
>
mathStatements
=
astComponent
.
getSpannedScope
().
get
().
resolve
(
"MathStatements"
,
MathStatementsSymbol
.
KIND
);
EMADLCocos
.
checkAll
(
componentInstanceSymbol
);
if
(
architecture
.
isPresent
()){
generateCNN
(
fileContents
,
taggingResolver
,
componentInstanceSymbol
,
architecture
.
get
()
.
resolve
()
);
generateCNN
(
fileContents
,
taggingResolver
,
componentInstanceSymbol
,
architecture
.
get
());
}
else
if
(
mathStatements
.
isPresent
()){
generateMathComponent
(
fileContents
,
taggingResolver
,
componentInstanceSymbol
,
mathStatements
.
get
());
...
...
@@ -133,7 +136,7 @@ public class Generator {
public
void
generateCNN
(
List
<
FileContent
>
fileContents
,
TaggingResolver
taggingResolver
,
ExpandedComponentInstanceSymbol
instance
,
ArchitectureSymbol
architecture
){
CNNArchGenerator
cnnArchGenerator
=
new
CNNArchGenerator
();
Map
<
String
,
String
>
contentMap
=
cnnArchGenerator
.
generateStrings
(
architecture
);
String
fullName
=
instance
.
getComponentType
().
getReferencedSymbol
().
getFullName
();
String
fullName
=
instance
.
getFullName
();
//get the components execute method
String
executeKey
=
"execute_"
+
fullName
.
replaceAll
(
"\\."
,
"_"
);
...
...
@@ -211,7 +214,7 @@ public class Generator {
if
(
architecture
.
isPresent
()){
String
fileContent
=
getTrainingParamsForComponent
(
mainComponentName
);
String
fileContent
=
getTrainingParamsForComponent
(
mainComponentName
,
component
,
componentInstance
);
if
(!
fileContent
.
isEmpty
())
{
trainParams
.
add
(
fileContent
);
}
...
...
@@ -228,14 +231,36 @@ public class Generator {
return
new
FileContent
(
processTemplate
(
ftlContext
,
CNN_TRAINER
),
CNN_TRAINER
+
"_"
+
mainComponentName
+
".py"
);
}
private
String
getTrainingParamsForComponent
(
String
mainComponentName
)
{
String
configFilename
=
mainComponentName
+
"Config"
;
if
(!
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
configFilename
+
".cnnt"
)))
{
private
String
getTrainingParamsForComponent
(
String
mainComponentName
,
ComponentSymbol
component
,
ExpandedComponentInstanceSymbol
instance
)
{
String
configFilename
;
String
mainComponentConfigFilename
=
mainComponentName
+
"Config"
;
String
componentConfigFilename
=
component
.
getFullName
().
replaceAll
(
"\\."
,
"/"
)
+
"Config"
;
String
instanceConfigFilename
=
component
.
getFullName
().
replaceAll
(
"\\."
,
"/"
)
+
"_"
+
instance
.
getName
()
+
"Config"
;
if
(
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
instanceConfigFilename
+
".cnnt"
)))
{
configFilename
=
instanceConfigFilename
;
}
else
if
(
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
componentConfigFilename
+
".cnnt"
))){
configFilename
=
componentConfigFilename
;
}
else
if
(
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
mainComponentConfigFilename
+
".cnnt"
))){
configFilename
=
mainComponentConfigFilename
;
}
else
{
Log
.
error
(
"Missing configuration file. "
+
"Could not find a file with any of the following names (only one needed): '"
+
instanceConfigFilename
+
".cnnt', '"
+
componentConfigFilename
+
".cnnt', '"
+
mainComponentConfigFilename
+
".cnnt'."
+
" These files denote respectively the configuration for the single instance, the component or the whole system."
);
return
""
;
}
//should be removed when CNNTrain supports packages
List
<
String
>
names
=
Splitter
.
on
(
"/"
).
splitToList
(
configFilename
);
configFilename
=
names
.
get
(
names
.
size
()-
1
);
Path
modelPath
=
Paths
.
get
(
getModelsPath
()
+
"/"
+
Joiner
.
on
(
"/"
).
join
(
names
.
subList
(
0
,
names
.
size
()-
1
)));
//
CNNTrainGenerator
cnnTrainGenerator
=
new
CNNTrainGenerator
();
final
ModelPath
mp
=
new
ModelPath
(
Paths
.
get
(
getM
odel
s
Path
())
);
final
ModelPath
mp
=
new
ModelPath
(
m
odelPath
);
GlobalScope
trainScope
=
new
GlobalScope
(
mp
,
new
CNNTrainLanguage
());
Map
.
Entry
<
String
,
String
>
fileContents
=
cnnTrainGenerator
.
generateFileContent
(
trainScope
,
configFilename
);
return
fileContents
.
getValue
();
...
...
src/main/java/de/monticore/lang/monticar/emadl/generator/GeneratorCli.java
View file @
6704cd5e
...
...
@@ -26,8 +26,6 @@ import freemarker.template.TemplateException;
import
org.apache.commons.cli.*
;
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
public
class
GeneratorCli
{
...
...
src/test/java/de/monticore/lang/monticar/emadl/AbstractSymtabTest.java
View file @
6704cd5e
...
...
@@ -34,8 +34,6 @@ public class AbstractSymtabTest {
protected
static
Scope
createSymTab
(
String
...
modelPath
)
{
ModelingLanguageFamily
fam
=
new
EMADLLanguageFamily
();
Log
.
enableFailQuick
(
false
);
final
ModelPath
mp
=
new
ModelPath
();
for
(
String
m
:
modelPath
)
{
mp
.
addEntry
(
Paths
.
get
(
m
));
...
...
src/test/java/de/monticore/lang/monticar/emadl/GenerationTest.java
View file @
6704cd5e
...
...
@@ -21,15 +21,29 @@
package
de.monticore.lang.monticar.emadl
;
import
de.monticore.lang.monticar.emadl.generator.Generator
;
import
de.se_rwth.commons.logging.Log
;
import
freemarker.template.TemplateException
;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
static
de
.
monticore
.
lang
.
monticar
.
emadl
.
ParserTest
.
ENABLE_FAIL_QUICK
;
import
static
junit
.
framework
.
TestCase
.
assertTrue
;
import
static
de
.
se_rwth
.
commons
.
logging
.
Log
.
getFindings
;
public
class
GenerationTest
{
@Before
public
void
setUp
()
{
// ensure an empty log
Log
.
getFindings
().
clear
();
Log
.
enableFailQuick
(
ENABLE_FAIL_QUICK
);
}
private
void
generate
(
String
qualifiedName
)
throws
IOException
,
TemplateException
{
Generator
gen
=
new
Generator
();