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
461ee8ec
Commit
461ee8ec
authored
Apr 26, 2018
by
Thomas Michael Timmermanns
Committed by
Thomas Michael Timmermanns
Apr 28, 2018
Browse files
Implemented parameterization/instances for ArchitectureSymbol and CNNArchCompilationSymbol.
parent
15df474f
Changes
33
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CNNArchCocos.java
View file @
461ee8ec
...
...
@@ -28,36 +28,39 @@ import de.se_rwth.commons.logging.Log;
//check all cocos
public
class
CNNArchCocos
{
public
static
void
checkAll
(
ArchitectureSymbol
architecture
){
public
static
ArchitectureSymbol
checkAll
(
ArchitectureSymbol
architecture
){
ArchitectureSymbol
resolvedArchitecture
=
null
;
ASTCNNArchNode
node
=
(
ASTCNNArchNode
)
architecture
.
getAstNode
().
get
();
int
findings
=
Log
.
getFindings
().
size
();
createPreResolveChecker
().
checkAll
(
node
);
if
(
findings
==
Log
.
getFindings
().
size
()){
architecture
.
resolve
();
resolvedArchitecture
=
architecture
.
resolve
();
if
(
findings
==
Log
.
getFindings
().
size
()){
createPostResolveChecker
().
checkAll
(
nod
e
);
createPostResolveChecker
().
checkAll
(
resolvedArchitectur
e
);
}
}
return
resolvedArchitecture
;
}
public
static
void
checkAll
(
CNNArchCompilationUnitSymbol
compilationUnit
){
public
static
ArchitectureSymbol
checkAll
(
CNNArchCompilationUnitSymbol
compilationUnit
){
ArchitectureSymbol
resolvedArchitecture
=
null
;
ASTCNNArchNode
node
=
(
ASTCNNArchNode
)
compilationUnit
.
getAstNode
().
get
();
int
findings
=
Log
.
getFindings
().
size
();
createPreResolveChecker
().
checkAll
(
node
);
if
(
findings
==
Log
.
getFindings
().
size
()){
compilationUnit
.
getArchitecture
().
resolve
();
resolvedArchitecture
=
compilationUnit
.
getArchitecture
().
resolve
();
if
(
findings
==
Log
.
getFindings
().
size
()){
createPostResolveChecker
().
checkAll
(
nod
e
);
createPostResolveChecker
().
checkAll
(
resolvedArchitectur
e
);
}
}
return
resolvedArchitecture
;
}
public
static
CNNArchCoCoChecker
createPostResolveChecker
()
{
return
new
CNNArchCoCoChecker
()
public
static
CNNArch
Extended
CoCoChecker
createPostResolveChecker
()
{
return
new
CNNArch
Extended
CoCoChecker
()
.
addCoCo
(
new
CheckIOType
())
.
addCoCo
(
new
CheckLayerInputs
())
.
addCoCo
(
new
CheckIOAccessAndIOMissing
())
.
addCoCo
(
new
CheckUnusedASTIODeclaration
())
.
addCoCo
(
new
CheckArchitectureFinished
());
}
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CNNArchExtendedCoCoChecker.java
0 → 100644
View file @
461ee8ec
/**
*
* ******************************************************************************
* 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.ArchitectureSymbol
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
CNNArchExtendedCoCoChecker
{
private
List
<
CNNArchSymbolCoCo
>
cocos
=
new
ArrayList
<>();
public
List
<
CNNArchSymbolCoCo
>
getCocos
()
{
return
cocos
;
}
public
CNNArchExtendedCoCoChecker
addCoCo
(
CNNArchSymbolCoCo
coco
)
{
getCocos
().
add
(
coco
);
return
this
;
}
public
void
checkAll
(
ArchitectureSymbol
resolvedArchitecture
)
{
if
(!
resolvedArchitecture
.
isResolved
()){
throw
new
IllegalStateException
(
"Architecture has to be resolved to check symboltable cocos"
);
}
for
(
CNNArchSymbolCoCo
coco
:
getCocos
()){
coco
.
check
(
resolvedArchitecture
);
}
}
}
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/C
heckUnusedASTIODeclaration
.java
→
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/C
NNArchSymbolCoCo
.java
View file @
461ee8ec
...
...
@@ -20,20 +20,9 @@
*/
package
de.monticore.lang.monticar.cnnarch._cocos
;
import
de.monticore.lang.monticar.cnnarch._ast.ASTIODeclaration
;
import
de.monticore.lang.monticar.cnnarch._symboltable.IODeclarationSymbol
;
import
de.monticore.lang.monticar.cnnarch.helper.ErrorCodes
;
import
de.se_rwth.commons.logging.Log
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol
;
public
class
CheckUnusedASTIODeclaration
implements
CNNArchASTIODeclarationCoCo
{
@Override
public
void
check
(
ASTIODeclaration
node
)
{
IODeclarationSymbol
ioDeclaration
=
(
IODeclarationSymbol
)
node
.
getSymbol
().
get
();
if
(
ioDeclaration
.
getConnectedLayers
().
isEmpty
()){
Log
.
error
(
"0"
+
ErrorCodes
.
MISSING_IO
+
" Input or output with name '"
+
ioDeclaration
.
getName
()
+
"' was declared but not used. "
,
ioDeclaration
.
getSourcePosition
());
}
}
public
interface
CNNArchSymbolCoCo
{
void
check
(
ArchitectureSymbol
architecture
);
}
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CheckArchitectureFinished.java
View file @
461ee8ec
...
...
@@ -25,23 +25,22 @@ import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol;
import
de.monticore.lang.monticar.cnnarch.helper.ErrorCodes
;
import
de.se_rwth.commons.logging.Log
;
public
class
CheckArchitectureFinished
implements
CNNArch
ASTArchitecture
CoCo
{
public
class
CheckArchitectureFinished
implements
CNNArch
Symbol
CoCo
{
@Override
public
void
check
(
ASTArchitecture
node
)
{
ArchitectureSymbol
architecture
=
(
ArchitectureSymbol
)
node
.
getSymbol
().
get
();
public
void
check
(
ArchitectureSymbol
architecture
)
{
if
(!
architecture
.
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. "
,
nod
e
.
get
_
SourcePosition
End
());
,
architectur
e
.
getSourcePosition
());
}
if
(
architecture
.
getInputs
().
isEmpty
()){
Log
.
error
(
"0"
+
ErrorCodes
.
UNFINISHED_ARCHITECTURE
+
" The architecture has no inputs. "
,
nod
e
.
get
_
SourcePosition
Start
());
,
architectur
e
.
getSourcePosition
());
}
if
(
architecture
.
getOutputs
().
isEmpty
()){
Log
.
error
(
"0"
+
ErrorCodes
.
UNFINISHED_ARCHITECTURE
+
" The architecture has no outputs. "
,
nod
e
.
get
_
SourcePosition
Start
());
,
architectur
e
.
getSourcePosition
());
}
}
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CheckIOAccessAndIOMissing.java
View file @
461ee8ec
...
...
@@ -34,12 +34,10 @@ import java.util.Optional;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
public
class
CheckIOAccessAndIOMissing
implements
CNNArch
ASTArchitecture
CoCo
{
public
class
CheckIOAccessAndIOMissing
implements
CNNArch
Symbol
CoCo
{
@Override
public
void
check
(
ASTArchitecture
node
)
{
ArchitectureSymbol
architecture
=
(
ArchitectureSymbol
)
node
.
getSymbol
().
get
();
public
void
check
(
ArchitectureSymbol
architecture
)
{
for
(
IODeclarationSymbol
ioDeclaration
:
architecture
.
getIODeclarations
()){
if
(
ioDeclaration
.
getArrayLength
()
==
1
){
checkSingleIO
(
ioDeclaration
);
...
...
@@ -50,7 +48,6 @@ public class CheckIOAccessAndIOMissing implements CNNArchASTArchitectureCoCo {
}
}
private
void
checkSingleIO
(
IODeclarationSymbol
ioDeclaration
){
if
(
ioDeclaration
.
getConnectedLayers
().
isEmpty
()){
Log
.
error
(
"0"
+
ErrorCodes
.
MISSING_IO
+
" Input or output '"
+
ioDeclaration
.
getName
()
+
"' was declared but never used."
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CheckIOType.java
View file @
461ee8ec
...
...
@@ -30,12 +30,10 @@ import de.se_rwth.commons.logging.Log;
import
java.util.Optional
;
public
class
CheckIOType
implements
CNNArch
ASTArchitecture
CoCo
{
public
class
CheckIOType
implements
CNNArch
Symbol
CoCo
{
@Override
public
void
check
(
ASTArchitecture
node
)
{
ArchitectureSymbol
architecture
=
(
ArchitectureSymbol
)
node
.
getSymbol
().
get
();
public
void
check
(
ArchitectureSymbol
architecture
)
{
for
(
IODeclarationSymbol
ioDeclaration
:
architecture
.
getIODeclarations
()){
check
(
ioDeclaration
);
}
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_cocos/CheckLayerInputs.java
View file @
461ee8ec
...
...
@@ -23,10 +23,10 @@ package de.monticore.lang.monticar.cnnarch._cocos;
import
de.monticore.lang.monticar.cnnarch._ast.ASTArchitecture
;
import
de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol
;
public
class
CheckLayerInputs
implements
CNNArchASTArchitectureCoCo
{
public
class
CheckLayerInputs
implements
CNNArchSymbolCoCo
{
@Override
public
void
check
(
ASTArchitecture
node
)
{
ArchitectureSymbol
architecture
=
(
ArchitectureSymbol
)
node
.
getSymbol
().
get
();
public
void
check
(
ArchitectureSymbol
architecture
)
{
architecture
.
getBody
().
checkInput
();
}
}
src/main/java/de/monticore/lang/monticar/cnnarch/_symboltable/ArchExpressionSymbol.java
View file @
461ee8ec
...
...
@@ -22,6 +22,7 @@ package de.monticore.lang.monticar.cnnarch._symboltable;
import
de.monticore.symboltable.CommonSymbol
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.Scope
;
import
de.monticore.symboltable.Symbol
;
import
java.util.*
;
...
...
@@ -359,13 +360,13 @@ abstract public class ArchExpressionSymbol extends CommonSymbol {
*/
abstract
public
boolean
isResolved
();
abstract
public
ArchExpressionSymbol
copy
();
protected
void
putInScope
(
MutableScope
scope
){
protected
void
putInScope
(
Scope
scope
){
Collection
<
Symbol
>
symbolsInScope
=
scope
.
getLocalSymbols
().
get
(
getName
());
if
(
symbolsInScope
==
null
||
!
symbolsInScope
.
contains
(
this
))
{
scope
.
add
(
this
);
scope
.
getAsMutableScope
().
add
(
this
);
}
}
abstract
protected
ArchExpressionSymbol
preResolveDeepCopy
();
}
src/main/java/de/monticore/lang/monticar/cnnarch/_symboltable/ArchRangeExpressionSymbol.java
View file @
461ee8ec
...
...
@@ -21,6 +21,7 @@
package
de.monticore.lang.monticar.cnnarch._symboltable
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.Scope
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -152,15 +153,6 @@ public class ArchRangeExpressionSymbol extends ArchAbstractSequenceExpression {
unresolvableVariables
.
addAll
(
getEndSymbol
().
getUnresolvableVariables
());
}
public
ArchRangeExpressionSymbol
copy
(){
ArchRangeExpressionSymbol
copy
=
new
ArchRangeExpressionSymbol
();
copy
.
setParallel
(
isParallel
());
copy
.
setStartSymbol
(
getStartSymbol
().
copy
());
copy
.
setEndSymbol
(
getEndSymbol
().
copy
());
copy
.
setUnresolvableVariables
(
getUnresolvableVariables
());
return
copy
;
}
@Override
public
String
getTextualRepresentation
()
{
String
separator
=
isParallel
()
?
"|"
:
"->"
;
...
...
@@ -168,12 +160,25 @@ public class ArchRangeExpressionSymbol extends ArchAbstractSequenceExpression {
}
@Override
protected
void
putInScope
(
Mutable
Scope
scope
)
{
protected
void
putInScope
(
Scope
scope
)
{
super
.
putInScope
(
scope
);
getStartSymbol
().
putInScope
(
scope
);
getEndSymbol
().
putInScope
(
scope
);
}
@Override
public
ArchRangeExpressionSymbol
preResolveDeepCopy
(){
ArchRangeExpressionSymbol
copy
=
new
ArchRangeExpressionSymbol
();
if
(
getAstNode
().
isPresent
()){
copy
.
setAstNode
(
getAstNode
().
get
());
}
copy
.
setParallel
(
isParallel
());
copy
.
setStartSymbol
(
getStartSymbol
().
preResolveDeepCopy
());
copy
.
setEndSymbol
(
getEndSymbol
().
preResolveDeepCopy
());
return
copy
;
}
public
static
ArchRangeExpressionSymbol
of
(
ArchSimpleExpressionSymbol
start
,
ArchSimpleExpressionSymbol
end
,
boolean
parallel
){
ArchRangeExpressionSymbol
sym
=
new
ArchRangeExpressionSymbol
();
sym
.
setStartSymbol
(
start
);
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_symboltable/ArchSequenceExpressionSymbol.java
View file @
461ee8ec
...
...
@@ -22,6 +22,7 @@ package de.monticore.lang.monticar.cnnarch._symboltable;
import
com.google.common.base.Joiner
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.Scope
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -115,21 +116,6 @@ public class ArchSequenceExpressionSymbol extends ArchAbstractSequenceExpression
}
}
public
ArchSequenceExpressionSymbol
copy
(){
ArchSequenceExpressionSymbol
copy
=
new
ArchSequenceExpressionSymbol
();
List
<
List
<
ArchSimpleExpressionSymbol
>>
elementsCopy
=
new
ArrayList
<>(
getElements
().
get
().
size
());
for
(
List
<
ArchSimpleExpressionSymbol
>
serialList
:
getElements
().
get
()){
List
<
ArchSimpleExpressionSymbol
>
serialListCopy
=
new
ArrayList
<>(
serialList
.
size
());
for
(
ArchSimpleExpressionSymbol
element
:
serialList
){
serialListCopy
.
add
(
element
.
copy
());
}
elementsCopy
.
add
(
serialListCopy
);
}
copy
.
setElements
(
getElements
().
get
());
copy
.
setUnresolvableVariables
(
getUnresolvableVariables
());
return
copy
;
}
@Override
public
String
getTextualRepresentation
()
{
List
<
String
>
parallelExpressions
=
new
ArrayList
<>();
...
...
@@ -140,7 +126,7 @@ public class ArchSequenceExpressionSymbol extends ArchAbstractSequenceExpression
}
@Override
protected
void
putInScope
(
Mutable
Scope
scope
)
{
protected
void
putInScope
(
Scope
scope
)
{
super
.
putInScope
(
scope
);
for
(
List
<
ArchSimpleExpressionSymbol
>
serialList
:
_getElements
()){
for
(
ArchSimpleExpressionSymbol
element
:
serialList
){
...
...
@@ -149,6 +135,25 @@ public class ArchSequenceExpressionSymbol extends ArchAbstractSequenceExpression
}
}
@Override
public
ArchSequenceExpressionSymbol
preResolveDeepCopy
(){
ArchSequenceExpressionSymbol
copy
=
new
ArchSequenceExpressionSymbol
();
if
(
getAstNode
().
isPresent
()){
copy
.
setAstNode
(
getAstNode
().
get
());
}
List
<
List
<
ArchSimpleExpressionSymbol
>>
elementsCopy
=
new
ArrayList
<>(
_getElements
().
size
());
for
(
List
<
ArchSimpleExpressionSymbol
>
serialList
:
_getElements
()){
List
<
ArchSimpleExpressionSymbol
>
serialListCopy
=
new
ArrayList
<>(
serialList
.
size
());
for
(
ArchSimpleExpressionSymbol
element
:
serialList
){
serialListCopy
.
add
(
element
.
preResolveDeepCopy
());
}
elementsCopy
.
add
(
serialListCopy
);
}
copy
.
setElements
(
elementsCopy
);
return
copy
;
}
public
static
ArchSequenceExpressionSymbol
of
(
List
<
List
<
ArchSimpleExpressionSymbol
>>
elements
){
ArchSequenceExpressionSymbol
sym
=
new
ArchSequenceExpressionSymbol
();
sym
.
setElements
(
elements
);
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_symboltable/ArchSimpleExpressionSymbol.java
View file @
461ee8ec
...
...
@@ -23,6 +23,9 @@ package de.monticore.lang.monticar.cnnarch._symboltable;
import
de.monticore.lang.math.math._symboltable.expression.*
;
import
de.monticore.lang.monticar.cnnarch.helper.Calculator
;
import
de.monticore.lang.monticar.cnnarch.helper.Utils
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.Scope
;
import
de.monticore.symboltable.Symbol
;
import
java.util.*
;
...
...
@@ -214,11 +217,31 @@ public class ArchSimpleExpressionSymbol extends ArchExpressionSymbol {
return
getValue
().
isPresent
()
||
!
getMathExpression
().
isPresent
();
}
public
ArchSimpleExpressionSymbol
copy
(){
@Override
protected
void
putInScope
(
Scope
scope
)
{
super
.
putInScope
(
scope
);
if
(
getMathExpression
().
isPresent
()){
for
(
MathExpressionSymbol
exp
:
Utils
.
createSubExpressionList
(
getMathExpression
().
get
()))
{
Collection
<
Symbol
>
symbolsInScope
=
scope
.
getLocalSymbols
().
get
(
exp
.
getName
());
if
(
symbolsInScope
==
null
||
!
symbolsInScope
.
contains
(
exp
))
{
scope
.
getAsMutableScope
().
add
(
exp
);
}
}
}
}
@Override
public
ArchSimpleExpressionSymbol
preResolveDeepCopy
(){
ArchSimpleExpressionSymbol
copy
=
new
ArchSimpleExpressionSymbol
();
copy
.
setMathExpression
(
mathExpression
);
copy
.
setValue
(
value
);
copy
.
setUnresolvableVariables
(
getUnresolvableVariables
());
if
(
getAstNode
().
isPresent
()){
copy
.
setAstNode
(
getAstNode
().
get
());
}
if
(
getMathExpression
().
isPresent
()){
copy
.
setMathExpression
(
Utils
.
copy
(
getMathExpression
().
get
()));
}
else
{
copy
.
setValue
(
value
);
}
return
copy
;
}
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_symboltable/ArchTypeSymbol.java
View file @
461ee8ec
...
...
@@ -23,6 +23,8 @@ package de.monticore.lang.monticar.cnnarch._symboltable;
import
de.monticore.lang.monticar.types2._ast.ASTElementType
;
import
de.monticore.symboltable.CommonSymbol
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.Scope
;
import
de.monticore.symboltable.Symbol
;
import
java.util.*
;
...
...
@@ -37,10 +39,9 @@ public class ArchTypeSymbol extends CommonSymbol {
private
int
channelIndex
=
-
1
;
private
int
heightIndex
=
-
1
;
private
int
widthIndex
=
-
1
;
private
List
<
ArchSimpleExpressionSymbol
>
dimensions
=
new
ArrayList
<>();
public
ArchTypeSymbol
()
{
super
(
""
,
KIND
);
ASTElementType
elementType
=
new
ASTElementType
();
...
...
@@ -190,6 +191,35 @@ public class ArchTypeSymbol extends CommonSymbol {
}
}
public
void
putInScope
(
Scope
scope
)
{
Collection
<
Symbol
>
symbolsInScope
=
scope
.
getLocalSymbols
().
get
(
getName
());
if
(
symbolsInScope
==
null
||
!
symbolsInScope
.
contains
(
this
))
{
scope
.
getAsMutableScope
().
add
(
this
);
for
(
ArchSimpleExpressionSymbol
dimension
:
getDimensionSymbols
()){
dimension
.
putInScope
(
scope
);
}
}
}
public
ArchTypeSymbol
preResolveDeepCopy
()
{
ArchTypeSymbol
copy
=
new
ArchTypeSymbol
();
if
(
getAstNode
().
isPresent
()){
copy
.
setAstNode
(
getAstNode
().
get
());
}
copy
.
setElementType
(
getElementType
());
copy
.
setWidthIndex
(
getWidthIndex
());
copy
.
setChannelIndex
(
getChannelIndex
());
copy
.
setHeightIndex
(
getHeightIndex
());
List
<
ArchSimpleExpressionSymbol
>
dimensionCopies
=
new
ArrayList
<>();
for
(
ArchSimpleExpressionSymbol
dimension
:
getDimensionSymbols
()){
dimensionCopies
.
add
(
dimension
.
preResolveDeepCopy
());
}
copy
.
setDimensionSymbols
(
dimensionCopies
);
return
copy
;
}
public
static
class
Builder
{
private
int
height
=
1
;
private
int
width
=
1
;
...
...
src/main/java/de/monticore/lang/monticar/cnnarch/_symboltable/ArchitectureSymbol.java
View file @
461ee8ec
...
...
@@ -23,7 +23,12 @@
package
de.monticore.lang.monticar.cnnarch._symboltable
;
import
de.monticore.lang.monticar.cnnarch.helper.Utils
;
import
de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedMethods
;
import
de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedVariables
;
import
de.monticore.symboltable.CommonScopeSpanningSymbol
;
import
de.monticore.symboltable.Scope
;
import
de.monticore.symboltable.Symbol
;
import
javax.annotation.Nullable
;
import
java.util.*
;
...
...
@@ -36,11 +41,16 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
private
List
<
IOLayerSymbol
>
inputs
=
new
ArrayList
<>();
private
List
<
IOLayerSymbol
>
outputs
=
new
ArrayList
<>();
private
Map
<
String
,
IODeclarationSymbol
>
ioDeclarationMap
=
new
HashMap
<>();
private
boolean
isCopy
=
false
;
public
ArchitectureSymbol
()
{
super
(
""
,
KIND
);
}
public
ArchitectureSymbol
(
String
name
)
{
super
(
name
,
KIND
);
}
public
LayerSymbol
getBody
()
{
return
body
;
}
...
...
@@ -57,6 +67,10 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
return
outputs
;
}
public
boolean
isCopy
()
{
return
isCopy
;
}
//called in IOLayer to get IODeclaration; only null if error; will be checked in coco CheckIOName
@Nullable
protected
IODeclarationSymbol
resolveIODeclaration
(
String
name
){
...
...
@@ -80,16 +94,30 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
return
getSpannedScope
().
resolveLocally
(
MethodDeclarationSymbol
.
KIND
);
}
public
void
resolve
(){
getBody
().
checkIfResolvable
();
try
{
getBody
().
resolveOrError
();
//useful to resolve the architecture in a component instance
public
ArchitectureSymbol
resolveInScope
(
Scope
scope
){
if
(
isCopy
()){
getBody
().
checkIfResolvable
();
try
{
getBody
().
resolveOrError
();
}
catch
(
ArchResolveException
e
){
//do nothing; error is already logged
}
return
this
;
}
catch
(
ArchResolveException
e
){
//do nothing; error is already logged
else
{
ArchitectureSymbol
copy
=
preResolveDeepCopy
();
copy
.
putInScope
(
scope
);
copy
.
resolve
();
return
copy
;
}
}
public
ArchitectureSymbol
resolve
(){
return
resolveInScope
(
getEnclosingScope
());
}
public
List
<
LayerSymbol
>
getFirstLayers
(){
if
(!
getBody
().
isResolved
()){
resolve
();
...
...
@@ -104,4 +132,35 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
public
boolean
isResolvable
(){
return
getBody
().
isResolvable
();
}
public
void
putInScope
(
Scope
scope
){
Collection
<
Symbol
>
symbolsInScope
=
scope
.
getLocalSymbols
().
get
(
getName
());
if
(
symbolsInScope
==
null
||
!
symbolsInScope
.
contains
(
this
)){
scope
.
getAsMutableScope
().
add
(
this
);
getSpannedScope
().
getAsMutableScope
().
setResolvingFilters
(
scope
.
getResolvingFilters
());
Utils
.
recursiveSetResolvingFilters
(
getSpannedScope
(),
scope
.
getResolvingFilters
());
}
}
public
ArchitectureSymbol
preResolveDeepCopy
(){
ArchitectureSymbol
copy
=
new
ArchitectureSymbol
(
"instance"
);
copy
.
setBody
(
getBody
().
preResolveDeepCopy
());
if
(
getAstNode
().
isPresent
()){
copy
.
setAstNode
(
getAstNode
().
get
());
}
copy
.
getSpannedScope
().
getAsMutableScope
().
add
(
AllPredefinedVariables
.
createTrueConstant
());
copy
.
getSpannedScope
().
getAsMutableScope
().
add
(
AllPredefinedVariables
.
createFalseConstant
());
for
(
MethodDeclarationSymbol
methodDeclaration
:
AllPredefinedMethods
.
createList
()){
copy
.
getSpannedScope
().
getAsMutableScope
().
add
(
methodDeclaration
);
}
for
(
MethodDeclarationSymbol
methodDeclaration
:
getSpannedScope
().<
MethodDeclarationSymbol
>
resolveLocally
(
MethodDeclarationSymbol
.
KIND
)){
if
(!
methodDeclaration
.
isPredefined
())
{
copy
.
getSpannedScope
().
getAsMutableScope
().
add
(
methodDeclaration
.
deepCopy
());
}
}
copy
.
getBody
().
putInScope
(
copy
.
getSpannedScope
());
copy
.
isCopy
=
true
;