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
CNNArchLang
Commits
2eed9ed4
Unverified
Commit
2eed9ed4
authored
Jan 05, 2018
by
Thomas Michael Timmermanns
Committed by
GitHub
Jan 05, 2018
Browse files
Merge pull request #12 from EmbeddedMontiArc/timmermanns
Timmermanns
parents
5034923f
4edc8801
Changes
88
Hide whitespace changes
Inline
Side-by-side
.circleci/config.yml
View file @
2eed9ed4
#
#
# ******************************************************************************
# 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/>.
# *******************************************************************************
#
# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
...
...
README.md
View file @
2eed9ed4
# CNNArch
[

](https://travis-ci.org/EmbeddedMontiArc/CNNArchLang)
[

](https://circleci.com/gh/EmbeddedMontiArc/CNNArchLang/tree/
master
)
[

](https://coveralls.io/github/EmbeddedMontiArc/CNNArchLang?branch=
master
)
[

](https://travis-ci.org/EmbeddedMontiArc/CNNArchLang)
[

](https://circleci.com/gh/EmbeddedMontiArc/CNNArchLang/tree/
timmermanns
)
[

](https://coveralls.io/github/EmbeddedMontiArc/CNNArchLang?branch=
timmermanns
)
pom.xml
View file @
2eed9ed4
...
...
@@ -30,7 +30,7 @@
<groupId>
de.monticore.lang.monticar
</groupId>
<artifactId>
cnn-arch
</artifactId>
<version>
0.
0.2
-SNAPSHOT
</version>
<version>
0.
1.0
-SNAPSHOT
</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
...
...
@@ -42,7 +42,7 @@
<mc.grammars.assembly.version>
0.0.6-SNAPSHOT
</mc.grammars.assembly.version>
<SIUnit.version>
0.0.6-SNAPSHOT
</SIUnit.version>
<Common-MontiCar.version>
0.0.3-SNAPSHOT
</Common-MontiCar.version>
<Math.version>
0.0.
3-SNAPSHOT-REWORK
</Math.version>
<Math.version>
0.0.
7.1
</Math.version>
<!-- .. Libraries .................................................. -->
<guava.version>
18.0
</guava.version>
<junit.version>
4.12
</junit.version>
...
...
settings.xml
View file @
2eed9ed4
...
...
@@ -42,7 +42,7 @@
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
|
values (value
s used when the setting is not specified) are provided.
|
elements (element
s used when the setting is not specified) are provided.
|
|-->
<settings
xmlns=
"http://maven.apache.org/SETTINGS/1.0.0"
...
...
@@ -57,7 +57,7 @@
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default
value
, perhaps based on some other setting, for
| maven will use a sensible default
rhs
, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
...
...
@@ -205,9 +205,9 @@
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular
value
for the property,
| relies on the detection of a system property, either matching a particular
rhs
for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
|
value
of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
|
rhs
of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
...
...
@@ -245,7 +245,7 @@
-->
<!--
| Here is another profile, activated by the system property 'target-env' with a
value
of 'dev',
| Here is another profile, activated by the system property 'target-env' with a
rhs
of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
...
...
@@ -261,14 +261,14 @@
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <
value
/> inside the activation-property.
| anything, you could just leave off the <
rhs
/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<
value
>dev</
value
>
<
rhs
>dev</
rhs
>
</property>
</activation>
<properties>
...
...
src/main/grammars/de/monticore/lang/monticar/CNNArch.mc4
View file @
2eed9ed4
...
...
@@ -2,98 +2,75 @@ package de.monticore.lang.monticar;
grammar
CNNArch
extends
de
.
monticore
.
lang
.
math
.
Math
{
symbol
scope
CNNArchCompilationUnit
=
"Architecture"
Name
&
"{"
Architecture
"}"
;
Architecture
=
(
MainLayer
)+
OutputLayer
;
interface
Layer
;
ast
Layer
=
method
ASTMethod
getMethod
(){};
interface
Method
;
interface
MainLayerMethod
extends
Method
;
interface
OutputLayerMethod
extends
Method
;
interface
ArgumentAssignment
;
ast
ArgumentAssignment
=
method
public
Enum
getLhs
(){}
method
public
ASTArgumentRhs
getRhs
(){};
ArgumentRhs
=
number
:
Number
|
tuple
:
Tuple
|
booleanVal
:
Boolean
|
type
:
ArgumentKeyword
;
Tuple
=
"("
values
:
Number
","
values
:(
Number
||
","
)+
")"
;
enum
Boolean
=
TRUE
:
"true"
|
FALSE
:
"false"
|
TRUE
:
"True"
|
FALSE
:
"False"
;
interface
ArgumentKeyword
;
ast
ArgumentKeyword
=
method
Optional
<
String
>
getName
(){};
MainLayer
implements
Layer
=
method
:
MainLayerMethod
;
OutputLayer
implements
Layer
=
method
:
OutputLayerMethod
;
ConvolutionMethod
implements
MainLayerMethod
=
name
:
"Convolution"
"("
arguments
:(
ConvolutionArgumentAssignment
||
","
)*
")"
;
ConvolutionArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
ConvolutionArgument
"="
rhs
:
ArgumentRhs
;
enum
ConvolutionArgument
=
KERNEL
:
"kernel"
//
required
|
NUMFILTER
:
"num_filter"
//
required
|
STRIDE
:
"stride"
|
PAD
:
"pad"
|
NOBIAS
:
"no_bias"
;
FullyConnectedMethod
implements
MainLayerMethod
=
name
:
"FullyConnected"
"("
arguments
:(
FullyConnectedArgumentAssignment
||
","
)*
")"
;
FullyConnectedArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
FullyConnectedArgument
"="
rhs
:
ArgumentRhs
;
enum
FullyConnectedArgument
=
NUMHIDDEN
:
"units"
//
required
|
NOBIAS
:
"no_bias"
;
ActivationMethod
implements
MainLayerMethod
=
name
:
"Activation"
"("
arguments
:(
ActivationArgumentAssignment
||
","
)*
")"
;
ActivationArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
ActivationArgument
"="
rhs
:
ArgumentRhs
;
enum
ActivationArgument
=
ACTTYPE
:
"type"
;
//
required
ActivationType
implements
ArgumentKeyword
=
name
:
"relu"
|
name
:
"sigmoid"
|
name
:
"tanh"
|
name
:
"softmax"
;
PoolingMethod
implements
MainLayerMethod
=
name
:
"Pooling"
"("
arguments
:(
PoolingArgumentAssignment
||
","
)*
")"
;
PoolingArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
PoolingArgument
"="
rhs
:
ArgumentRhs
;
enum
PoolingArgument
=
KERNEL
:
"kernel"
//
required
|
POOLTYPE
:
"type"
//
required
|
POOLINGCONVENTION
:
"pooling_convention"
|
STRIDE
:
"stride"
|
PAD
:
"pad"
;
PoolingType
implements
ArgumentKeyword
=
name
:
"max"
|
name
:
"avg"
|
name
:
"sum"
;
PoolingConvention
implements
ArgumentKeyword
=
name
:
"full"
|
name
:
"valid"
;
DropoutMethod
implements
MainLayerMethod
=
name
:
"Dropout"
"("
arguments
:(
DropoutArgumentAssignment
||
","
)*
")"
;
DropoutArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
DropoutArgument
"="
rhs
:
ArgumentRhs
;
enum
DropoutArgument
=
P
:
"p"
;
LRNMethod
implements
MainLayerMethod
=
name
:
"LRN"
"("
arguments
:(
LRNArgumentAssignment
||
","
)*
")"
;
LRNArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
LRNArgument
"="
rhs
:
ArgumentRhs
;
enum
LRNArgument
=
ALPHA
:
"alpha"
|
BETA
:
"beta"
|
KNORM
:
"knorm"
|
NSIZE
:
"nsize"
;
//
required
StandardOutputLayerMethod
implements
OutputLayerMethod
=
name
:
"Output"
"("
arguments
:(
StandardOutputArgumentAssignment
||
","
)*
")"
;
StandardOutputArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
StandardOutputArgument
"="
rhs
:
ArgumentRhs
;
enum
StandardOutputArgument
=
GRADSCALE
:
"grad_scale"
|
TYPE
:
"type"
;
OutputType
implements
ArgumentKeyword
=
name
:
"softmax"
|
name
:
"linear"
|
name
:
"logistic"
|
name
:
"mae"
;
//
SVMOutputLayerMethod
implements
OutputLayerMethod
=
name
:
"SVMOutput"
"("
//
arguments
:(
SVMOutputArgumentAssignment
||
","
)*
")"
;
//
SVMOutputArgumentAssignment
implements
ArgumentAssignment
=
lhs
:
SVMOutputArgument
"="
rhs
:
ArgumentRhs
;
//
enum
SVMOutputArgument
=
MARGIN
:
"margin"
//
|
REGULARIZATIONCOEFFICIENT
:
"regularization_coefficient"
//
|
USELINEAR
:
"use_linear"
;
CNNArchCompilationUnit
=
Architecture
;
symbol
scope
Architecture
=
"architecture"
name
:
Name
&
"{"
declarations
:
ArchDeclaration
*
body
:
ArchBody
"}"
;
interface
ArchDeclaration
;
interface
ArchitectureElement
;
interface
Variable
;
ast
Variable
=
method
String
getName
(){};
IODeclaration
implements
ArchDeclaration
=
"def"
(
in
:
"input"
|
out
:
"output"
)
type
:
ArchType
Name
&
(
ArrayDeclaration
)?;
ArchType
implements
Type
=
ElementType
"^"
Shape
;
Shape
=
"{"
(
Dimension
||
","
)+
"}"
;
Dimension
=
IOVariable
|
intLiteral
:
UnitNumberResolution
;
IOVariable
implements
Variable
=
Name
&
(
"="
intRhs
:
UnitNumberResolution
)?;
VariableAssignment
implements
Variable
,
ArchDeclaration
=
Name
&
"="
rhs
:
ArchSimpleExpression
;
MethodDeclaration
implements
ArchDeclaration
=
"def"
Name
&
"("
parameters
:(
Parameter
||
","
)*
")"
"{"
body
:
ArchBody
"}"
;
Parameter
implements
Variable
=
Name
&
(
"="
default
:
ArchSimpleExpression
)?;
scope
ArchBody
=
elements
:(
ArchitectureElement
||
"->"
)*;
IOLayer
implements
ArchitectureElement
=
Name
&
(
"["
index
:
ArchSimpleExpression
"]"
)?;
MethodLayer
implements
ArchitectureElement
=
Name
&
"("
arguments
:(
Argument
||
","
)*
")"
;
Argument
=
Name
"="
rhs
:
ArchExpression
;
PredefinedArgument
extends
Argument
=
(
serial
:
"->"
|
parallel
:
"|"
)
"="
rhs2
:
ArchExpression
;
ParallelLayer
implements
ArchitectureElement
=
"("
groups
:
ArchBody
"|"
groups
:(
ArchBody
||
"|"
)+
")"
;
ArrayAccessLayer
implements
ArchitectureElement
=
"["
index
:
ArchSimpleExpression
"]"
;
ArchExpression
=
(
expression
:
ArchSimpleExpression
|
sequence
:
ArchValueSequence
);
interface
ArchValueSequence
;
ArchParallelSequence
implements
ArchValueSequence
=
"["
parallelValues
:(
ArchSerialSequence
||
"|"
)*
"]"
;
ArchSerialSequence
=
serialValues
:(
ArchSimpleExpression
||
"->"
)+;
ArchValueRange
implements
ArchValueSequence
=
start
:
ArchSimpleExpression
(
serial
:
"->"
|
parallel
:
"|"
)
".."
(
serial2
:
"->"
|
parallel2
:
"|"
)
end
:
ArchSimpleExpression
;
ArchSimpleExpression
=
(
arithmeticExpression
:
MathArithmeticExpression
|
booleanExpression
:
MathBooleanExpression
|
tupleExpression
:
TupleExpression
);
TupleExpression
implements
MathExpression
=
"("
expressions
:
MathArithmeticExpression
","
expressions
:(
MathArithmeticExpression
||
","
)*
")"
;
}
\ No newline at end of file
src/main/java/de/monticore/lang/monticar/cnnarch/_ast/ASTPredefinedArgument.java
0 → 100644
View file @
2eed9ed4
/**
*
* ******************************************************************************
* 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._ast
;
import
de.monticore.lang.monticar.cnnarch.helper.PredefinedVariables
;
public
class
ASTPredefinedArgument
extends
ASTPredefinedArgumentTOP
{
public
ASTPredefinedArgument
()
{
}
public
ASTPredefinedArgument
(
ASTArchExpression
rhs2
,
String
serial
,
String
parallel
,
String
name
,
ASTArchExpression
rhs
)
{
super
(
rhs2
,
serial
,
parallel
,
name
,
rhs
);
}
@Override
public
void
setRhs2
(
ASTArchExpression
rhs2
)
{
super
.
setRhs2
(
rhs2
);
setRhs
(
rhs2
);
}
@Override
public
void
setParallel
(
String
parallel
)
{
super
.
setParallel
(
parallel
);
if
(
parallel
!=
null
&&
!
parallel
.
isEmpty
()){
setName
(
PredefinedVariables
.
CARDINALITY_NAME
);
}
}
@Override
public
void
setSerial
(
String
serial
)
{
super
.
setSerial
(
serial
);
if
(
serial
!=
null
&&
!
serial
.
isEmpty
())
{
setName
(
PredefinedVariables
.
FOR_NAME
);
}
}
}
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CNNArchCocos.java
→
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CNNArch
PostResolve
Cocos.java
View file @
2eed9ed4
...
...
@@ -20,11 +20,11 @@
*/
package
de.monticore.lang.monticar.cnnarch._cocos
;
public
class
CNNArchCocos
{
public
class
CNNArch
PostResolve
Cocos
{
public
static
CNNArchCoCoChecker
createChecker
()
{
return
new
CNNArchCoCoChecker
()
.
addCoCo
(
new
DuplicateArgumentCheck
())
.
addCoCo
(
new
ArchitectureCheck
());
.
addCoCo
(
new
CheckVariableConstraints
());
}
}
\ No newline at end of file
}
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CNNArchPreResolveCocos.java
0 → 100644
View file @
2eed9ed4
/**
*
* ******************************************************************************
* 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
;
public
class
CNNArchPreResolveCocos
{
public
static
CNNArchCoCoChecker
createChecker
()
{
return
new
CNNArchCoCoChecker
()
.
addCoCo
(
new
CheckMethodLayer
())
.
addCoCo
(
new
CheckVariable
())
.
addCoCo
(
new
CheckIOLayer
())
.
addCoCo
(
new
CheckArgument
())
.
addCoCo
(
new
CheckMethodDeclaration
());
}
}
\ No newline at end of file
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/
Duplicate
Argument
Check
.java
→
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/
Check
Argument.java
View file @
2eed9ed4
...
...
@@ -20,26 +20,21 @@
*/
package
de.monticore.lang.monticar.cnnarch._cocos
;
import
de.monticore.lang.monticar.cnnarch._ast.ASTArgumentAssignment
;
import
de.monticore.lang.monticar.cnnarch._ast.ASTMethod
;
import
de.monticore.lang.monticar.cnnarch._ast.ASTArgument
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArgumentSymbol
;
import
de.monticore.lang.monticar.cnnarch.helper.ErrorCodes
;
import
de.se_rwth.commons.logging.Log
;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
DuplicateArgumentCheck
implements
CNNArchASTMethodCoCo
{
public
class
CheckArgument
implements
CNNArchASTArgumentCoCo
{
@Override
public
void
check
(
ASTMethod
node
)
{
Set
<
Enum
>
set
=
new
HashSet
<>();
for
(
ASTArgumentAssignment
assignment
:
node
.
getArguments
())
{
if
(
set
.
contains
(
assignment
.
getLhs
()))
{
Log
.
error
(
"0x03011 Multiple assignments of the same argument are not allowed"
,
assignment
.
get_SourcePositionStart
());
}
else
{
set
.
add
(
assignment
.
getLhs
());
}
public
void
check
(
ASTArgument
node
)
{
ArgumentSymbol
argument
=
(
ArgumentSymbol
)
node
.
getSymbol
().
get
();
if
(
argument
.
getParameter
()
==
null
){
Log
.
error
(
"0"
+
ErrorCodes
.
UNKNOWN_ARGUMENT_CODE
+
" Unknown Argument. "
+
"Parameter with name '"
+
node
.
getName
()
+
"' does not exist."
,
node
.
get_SourcePositionStart
());
}
}
}
\ No newline at end of file
}
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CheckIOLayer.java
0 → 100644
View file @
2eed9ed4
/**
*
* ******************************************************************************
* 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._ast.ASTIOLayer
;
import
de.monticore.lang.monticar.cnnarch._symboltable.CompositeLayerSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.IODeclarationSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.IOLayerSymbol
;
import
de.monticore.lang.monticar.cnnarch.helper.ErrorCodes
;
import
de.monticore.symboltable.Symbol
;
import
de.se_rwth.commons.logging.Log
;
public
class
CheckIOLayer
implements
CNNArchASTIOLayerCoCo
{
@Override
public
void
check
(
ASTIOLayer
node
)
{
Symbol
symbol
=
node
.
getSymbol
().
get
();
IODeclarationSymbol
ioDeclaration
=
null
;
if
(
symbol
instanceof
IOLayerSymbol
){
ioDeclaration
=
((
IOLayerSymbol
)
symbol
).
getDefinition
();
}
else
if
(
symbol
instanceof
CompositeLayerSymbol
){
IOLayerSymbol
layer
=
(
IOLayerSymbol
)
((
CompositeLayerSymbol
)
symbol
).
getLayers
().
get
(
0
);
ioDeclaration
=
layer
.
getDefinition
();
}
if
(
ioDeclaration
==
null
){
Log
.
error
(
"0"
+
ErrorCodes
.
UNKNOWN_IO_CODE
+
" Unknown input or output name. "
+
"The input or output '"
+
node
.
getName
()
+
"' does not exist"
,
node
.
get_SourcePositionStart
());
}
}
}
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CheckMethodDeclaration.java
0 → 100644
View file @
2eed9ed4
/**
*
* ******************************************************************************
* 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._ast.ASTMethodDeclaration
;
import
de.monticore.lang.monticar.cnnarch._symboltable.CompositeLayerSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.LayerSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.MethodDeclarationSymbol
;
import
de.monticore.lang.monticar.cnnarch._symboltable.MethodLayerSymbol
;
import
de.monticore.lang.monticar.cnnarch.helper.ErrorCodes
;
import
de.se_rwth.commons.logging.Log
;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
CheckMethodDeclaration
implements
CNNArchASTMethodDeclarationCoCo
{
//for duplication check
Set
<
String
>
methodNames
=
new
HashSet
<>();
//for recursion check
Set
<
MethodDeclarationSymbol
>
seenMethods
=
new
HashSet
<>();
boolean
done
=
false
;
@Override
public
void
check
(
ASTMethodDeclaration
node
)
{
String
name
=
node
.
getName
();
if
(
name
.
isEmpty
()
||
!
Character
.
isLowerCase
(
name
.
codePointAt
(
0
))){
Log
.
error
(
"0"
+
ErrorCodes
.
ILLEGAL_NAME_CODE
+
" Illegal name: "
+
name
+
". All new variable and method names have to start with a lowercase letter. "
,
node
.
get_SourcePositionStart
());
}
if
(
methodNames
.
contains
(
name
)){
Log
.
error
(
"0"
+
ErrorCodes
.
DUPLICATED_NAME_CODE
+
" Duplicated name. "
+
"The name '"
+
name
+
"' is already defined."
,
node
.
get_SourcePositionStart
());
}
else
{
methodNames
.
add
(
name
);
}
MethodDeclarationSymbol
method
=
(
MethodDeclarationSymbol
)
node
.
getSymbol
().
get
();
checkForRecursion
(
method
,
method
.
getBody
());
}
private
void
checkForRecursion
(
MethodDeclarationSymbol
startingMethod
,
LayerSymbol
current
){
if
(!
done
)
{
if
(
current
instanceof
CompositeLayerSymbol
)
{
for
(
LayerSymbol
layer
:
((
CompositeLayerSymbol
)
current
).
getLayers
())
{
checkForRecursion
(
startingMethod
,
layer
);
}
}
else
if
(
current
instanceof
MethodLayerSymbol
)
{
MethodDeclarationSymbol
method
=
((
MethodLayerSymbol
)
current
).
getMethod
();
if
(
method
!=
null
&&
!
method
.
isPredefined
()
&&
!
seenMethods
.
contains
(
method
))
{
seenMethods
.
add
(
method
);
if
(
startingMethod
==
method
)
{
Log
.
error
(
"0"
+
ErrorCodes
.
RECURSION_ERROR_CODE
+
" Recursion is not allowed. "
+
"The method '"
+
startingMethod
.
getName
()
+
"' creates a recursive cycle."
,
startingMethod
.
getSourcePosition
());
done
=
true
;
}
else
{
checkForRecursion
(
startingMethod
,
method
.
getBody
());
}
}
}
}
}
}
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CheckMethodLayer.java
0 → 100644
View file @
2eed9ed4
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.