Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
8e2325eb
Commit
8e2325eb
authored
Oct 26, 2017
by
Sascha Niklas Schneiders
Browse files
fixed array start indexing bug when multiple expressions are used
parent
9ddb295e
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/cpp/MathFunctionFixer.java
View file @
8e2325eb
...
...
@@ -78,7 +78,7 @@ public class MathFunctionFixer {
if
(
mathMatrixExpressionSymbol
.
isMatrixAccessExpression
())
{
if
(
mathChainedExpression
.
getSecondExpressionSymbol
().
getExpressionID
()
==
MathStringExpression
.
ID
)
{
MathStringExpression
mathStringExpression
=
(
MathStringExpression
)
mathChainedExpression
.
getSecondExpressionSymbol
();
if
(
mathStringExpression
.
getText
().
equal
s
(
"-1"
))
if
(
mathStringExpression
.
getText
().
contain
s
(
"-1"
))
return
;
}
}
...
...
@@ -194,7 +194,9 @@ public class MathFunctionFixer {
if
(
mathExpressionSymbol
.
getMathExpressionSymbol
().
isPresent
())
{
fixMathFunctions
(
mathExpressionSymbol
.
getMathExpressionSymbol
().
get
(),
bluePrintCPP
);
MathExpressionSymbol
mathExp
=
mathExpressionSymbol
.
getMathExpressionSymbol
().
get
();
mathExpressionSymbol
.
setMathExpressionSymbol
(
new
MathChainedExpression
(
mathExp
,
new
MathStringExpression
(
"-1"
)));
//mathExpressionSymbol.setMathExpressionSymbol(mathExp);
if
(!(
mathExp
instanceof
MathChainedExpression
))
mathExpressionSymbol
.
setMathExpressionSymbol
(
new
MathChainedExpression
(
mathExp
,
new
MathStringExpression
(
"-1"
)));
/*if (mathExp.getExpressionID() != MathChainedExpression.ID && mathExp.getExpressionID() != MathStringExpression.ID) {
mathExpressionSymbol.setMathExpressionSymbol(new MathChainedExpression(mathExp, new MathStringExpression("-1")));
...
...
src/test/java/de/monticore/lang/monticar/generator/cpp/GenerationTest.java
View file @
8e2325eb
...
...
@@ -442,5 +442,17 @@ public class GenerationTest extends AbstractSymtabTest {
testFilesAreEqual
(
files
,
restPath
);
}
@Test
public
void
testForLoopIf
()
throws
IOException
{
ConstantPortSymbol
.
resetLastID
();
Scope
symtab
=
createSymTab
(
"src/test/resources"
);
ExpandedComponentInstanceSymbol
componentSymbol
=
symtab
.<
ExpandedComponentInstanceSymbol
>
resolve
(
"testing.forLoopIfInstance"
,
ExpandedComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentSymbol
);
GeneratorCPP
generatorCPP
=
new
GeneratorCPP
();
generatorCPP
.
setGenerationTargetPath
(
"./target/generated-sources-cpp/testing"
);
List
<
File
>
files
=
generatorCPP
.
generateFiles
(
componentSymbol
,
symtab
);
String
restPath
=
"test/"
;
testFilesAreEqual
(
files
,
restPath
);
}
}
src/test/resources/results/testBasicGenericArrayInstance/test_basicGenericArrayInstance_basicGenericArraySize1.h
View file @
8e2325eb
...
...
@@ -17,6 +17,9 @@ void execute()
for
(
auto
i
=
1
/
1
;
i
<=
n
;
++
i
){
valOut
(
i
)
=
val1
[
i
-
1
]
*
2
/
1
;
}
for
(
auto
i
=
1
/
1
;
i
<=
n
;
++
i
){
valOut
(
i
)
=
val1
[
i
-
1
]
*
3
/
1
;
}
}
};
...
...
src/test/resources/results/testBasicGenericArrayInstance/test_basicGenericArrayInstance_basicGenericArraySize2.h
View file @
8e2325eb
...
...
@@ -15,7 +15,10 @@ void init()
void
execute
()
{
for
(
auto
i
=
1
/
1
;
i
<=
n
;
++
i
){
valOut
(
i
)
=
val1
[
i
-
1
-
1
]
*
2
/
1
;
valOut
(
i
)
=
val1
[
i
-
1
]
*
2
/
1
;
}
for
(
auto
i
=
1
/
1
;
i
<=
n
;
++
i
){
valOut
(
i
)
=
val1
[
i
-
1
]
*
3
/
1
;
}
}
...
...
src/test/resources/test/BasicGenericArrayInstance.emam
View file @
8e2325eb
...
...
@@ -4,7 +4,8 @@ component BasicGenericArrayInstance{
ports
in
Q
(-
oo
:
oo
)
val1
[
6
],
out
Q
(-
oo
:
oo
)
valOut
[
6
];
instance
BasicGenericArraySize
<
3
>
basicGenericArraySize1
,
basicGenericArraySize2
;
instance
BasicGenericArraySize
<
3
>
basicGenericArraySize1
;
instance
BasicGenericArraySize
<
3
>
basicGenericArraySize2
;
connect
val1
[
1
:
3
]
->
basicGenericArraySize1
.
val1
[:];
connect
val1
[
4
:
6
]
->
basicGenericArraySize2
.
val1
[:];
...
...
src/test/resources/test/BasicGenericArraySize.emam
View file @
8e2325eb
...
...
@@ -6,7 +6,11 @@ component BasicGenericArraySize<N1 n=1>{
implementation
Math
{
for
i
=
1
:
n
valOut
(
i
)
=
val1
(
i
)
*
2
;
valOut
(
i
)
=
val1
(
i
)
*
2
;
end
for
i
=
1
:
n
valOut
(
i
)
=
val1
(
i
)
*
3
;
end
}
}
\ No newline at end of file
src/test/resources/testing/ForLoopIf.emam
0 → 100644
View file @
8e2325eb
package
testing
;
component
ForLoopIf
<
N1
counter
>{
ports
out
Q
(-
oo
:
oo
)
result
;
implementation
Math
{
for
i
=
1
:
1
:
8
result
=
result
+
counter
;
end
if
counter
<
0
{
result
=
0
;
}
elseif
counter
<
100
{
result
=
counter
;
}
else
{
result
=
100
;
}
end
}
}
\ No newline at end of file
src/test/resources/testing/ForLoopIfInstance.emam
0 → 100644
View file @
8e2325eb
package
testing
;
component
ForLoopIfInstance
{
ports
out
Q
(-
oo
:
oo
)
result
;
instance
ForLoopIf
forLoopIf
;
connect
forLoopIf
.
result
->
result
;
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment