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
generators
EMAM2Cpp
Commits
8803420c
Commit
8803420c
authored
Jul 04, 2018
by
Evgeny Kusmenko
Browse files
Merge branch 'richter-dev' into 'master'
Richter dev See merge request
!8
parents
209850b3
560cebbd
Pipeline
#60379
passed with stage
in 2 minutes and 27 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
8803420c
...
...
@@ -8,7 +8,7 @@
<groupId>
de.monticore.lang.monticar
</groupId>
<artifactId>
embedded-montiarc-math-generator
</artifactId>
<version>
0.0.1
6
-SNAPSHOT
</version>
<version>
0.0.1
7
-SNAPSHOT
</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
...
...
src/main/java/de/monticore/lang/monticar/generator/cpp/converter/StringIndexHelper.java
View file @
8803420c
...
...
@@ -2,28 +2,36 @@ package de.monticore.lang.monticar.generator.cpp.converter;
/**
* @author Sascha Schneiders
* @author Christoph Richter
*/
public
class
StringIndexHelper
{
public
static
String
modifyContentBetweenBracketsByAdding
(
String
input
,
String
modifier
)
{
return
modifyContentBetweenBracketsByAdding
(
input
,
modifier
,
"("
,
","
,
")"
);
}
/**
* Only adds modifier in the first occurring bracket
*/
public
static
String
modifyContentBetweenBracketsByAdding
(
String
input
,
String
modifier
,
String
bracketStart
,
String
bracketSep
,
String
bracketEnd
)
{
String
result
=
""
;
boolean
done
=
false
;
int
indexFirst
=
input
.
indexOf
(
"("
,
0
);
int
indexFirst
=
input
.
indexOf
(
bracketStart
,
0
);
if
(
indexFirst
==
-
1
)
return
input
;
result
+=
input
.
substring
(
0
,
indexFirst
);
int
indexSecond
=
input
.
indexOf
(
","
,
indexFirst
+
1
);
int
indexSecond
=
input
.
indexOf
(
bracketSep
,
indexFirst
+
bracketSep
.
length
()
);
if
(
indexSecond
==
-
1
)
{
indexSecond
=
input
.
indexOf
(
")"
,
indexFirst
+
1
);
indexSecond
=
input
.
indexOf
(
bracketEnd
,
indexFirst
+
bracketEnd
.
length
()
);
done
=
true
;
}
while
(!
done
)
{
result
+=
input
.
substring
(
indexFirst
,
indexSecond
)
+
modifier
;
indexFirst
=
indexSecond
;
indexSecond
=
input
.
indexOf
(
","
,
indexSecond
+
1
);
indexSecond
=
input
.
indexOf
(
bracketSep
,
indexSecond
+
bracketSep
.
length
()
);
if
(
indexSecond
==
-
1
)
{
indexSecond
=
input
.
indexOf
(
")"
,
indexFirst
+
1
);
indexSecond
=
input
.
indexOf
(
bracketEnd
,
indexFirst
+
bracketEnd
.
length
()
);
done
=
true
;
}
}
...
...
@@ -37,9 +45,22 @@ public class StringIndexHelper {
if
(
input
.
endsWith
(
endPart
))
{
int
indexFirst
=
input
.
lastIndexOf
(
endPart
);
result
=
input
.
substring
(
0
,
indexFirst
);
result
+=
newEndPart
;
result
+=
newEndPart
;
}
return
result
;
}
public
static
String
modifyContentBetweenBracketsByAddingForAllBrackets
(
String
input
,
String
modifier
,
String
bracketStart
,
String
bracketSep
,
String
bracketEnd
)
{
String
[]
parts
=
input
.
split
(
"(?<=\\))"
);
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
s
:
parts
)
{
sb
.
append
(
modifyContentBetweenBracketsByAdding
(
s
,
modifier
,
bracketStart
,
bracketSep
,
bracketEnd
));
}
return
sb
.
toString
();
}
public
static
String
modifyContentBetweenBracketsByAddingForAllBrackets
(
String
input
,
String
modifier
)
{
return
modifyContentBetweenBracketsByAddingForAllBrackets
(
input
,
modifier
,
"("
,
","
,
")"
);
}
}
src/main/java/de/monticore/lang/monticar/generator/optimization/MathInformationRegister.java
View file @
8803420c
package
de.monticore.lang.monticar.generator.optimization
;
import
de.monticore.lang.math._symboltable.expression.MathExpressionSymbol
;
import
de.monticore.lang.math._symboltable.expression.MathNumberExpressionSymbol
;
import
de.monticore.lang.math._symboltable.expression.MathValueExpressionSymbol
;
import
de.monticore.lang.math._symboltable.expression.MathValueSymbol
;
import
de.monticore.lang.math._symboltable.expression.*
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixAccessOperatorSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol
;
import
de.monticore.lang.monticar.generator.BluePrint
;
import
de.monticore.lang.monticar.generator.Variable
;
import
de.monticore.lang.monticar.generator.cpp.BluePrintCPP
;
...
...
@@ -19,6 +17,7 @@ import java.util.Optional;
* This class stores information of already encountered math information
*
* @author Sascha Schneiders
* @author Christoph Richter
*/
public
class
MathInformationRegister
{
protected
List
<
Variable
>
variables
=
new
ArrayList
<>();
//contains in implementation Math section declared Variables
...
...
@@ -164,6 +163,7 @@ public class MathInformationRegister {
var
.
addDimensionalInformation
(
dimension
.
getTextualRepresentation
());
this
.
variables
.
add
(
var
);
var
.
addProperties
(
mathValueSymbol
.
getType
().
getProperties
());
this
.
mathValueSymbols
.
add
(
mathValueSymbol
);
}
public
Variable
getVariable
(
String
name
)
{
...
...
@@ -200,4 +200,74 @@ public class MathInformationRegister {
}
return
result
;
}
/**
* Searches MathValueSymbol in list and returns first matching symbol which contains the type declaration information
*
* @param symbol Symbol for which type information should be collected
* @return returns the first type declaration as symbol
*/
public
MathValueSymbol
getFullTypeInformation
(
MathValueSymbol
symbol
)
{
MathValueSymbol
result
=
getMathValueSymbol
(
symbol
.
getName
());
if
(
result
==
null
)
result
=
symbol
;
return
result
;
}
/**
* Variables are replaced by their definition.
*
* @param nonAtomarExpression Expression in which the variables will be substituted
* @param atomarValueName Defines the name of the atomar variable after which no more substitution will be made
* @return MathExpressionSymbol containing the replaces variables
*/
public
MathExpressionSymbol
resolveMathExpressionToAtomarExpression
(
MathExpressionSymbol
nonAtomarExpression
,
String
atomarValueName
)
{
MathExpressionSymbol
result
;
if
(
nonAtomarExpression
.
isArithmeticExpression
())
{
// recursively substitute expressions
MathArithmeticExpressionSymbol
arithmeticSubstituted
=
(
MathArithmeticExpressionSymbol
)
nonAtomarExpression
;
MathArithmeticExpressionSymbol
arithmeticResult
=
new
MathArithmeticExpressionSymbol
();
arithmeticResult
.
setMathOperator
(
arithmeticSubstituted
.
getOperator
());
arithmeticResult
.
setLeftExpression
(
resolveMathExpressionToAtomarExpression
(
arithmeticSubstituted
.
getLeftExpression
(),
atomarValueName
));
arithmeticResult
.
setRightExpression
(
resolveMathExpressionToAtomarExpression
(
arithmeticSubstituted
.
getRightExpression
(),
atomarValueName
));
result
=
arithmeticResult
;
}
else
if
(
nonAtomarExpression
instanceof
MathValueSymbol
)
{
// substitute value expr by assigned expr
MathValueSymbol
valueExpr
=
(
MathValueSymbol
)
nonAtomarExpression
;
result
=
getSubstituteByName
(
valueExpr
.
getName
(),
nonAtomarExpression
,
atomarValueName
);
}
else
if
(
nonAtomarExpression
instanceof
MathMatrixNameExpressionSymbol
)
{
MathMatrixNameExpressionSymbol
sourceExpr
=
(
MathMatrixNameExpressionSymbol
)
nonAtomarExpression
;
MathMatrixNameExpressionSymbol
targetExpr
;
// modifiy access name
String
accessName
=
getSubstituteByName
(
sourceExpr
.
getNameToAccess
(),
nonAtomarExpression
,
atomarValueName
).
getTextualRepresentation
();
if
(
sourceExpr
.
isMathMatrixAccessOperatorSymbolPresent
()
&&
!(
accessName
.
contains
(
"("
)))
{
targetExpr
=
new
MathMatrixNameExpressionSymbol
(
String
.
format
(
"(%s)"
,
accessName
));
// modify access operator
MathMatrixAccessOperatorSymbol
sourceAccessOperator
=
sourceExpr
.
getMathMatrixAccessOperatorSymbol
();
MathMatrixAccessOperatorSymbol
targetAccessOperator
=
new
MathMatrixAccessOperatorSymbol
();
targetAccessOperator
.
setMathMatrixAccessSymbols
(
sourceAccessOperator
.
getMathMatrixAccessSymbols
());
targetAccessOperator
.
setAccessStartSymbol
(
".at("
);
targetExpr
.
setMathMatrixAccessOperatorSymbol
(
targetAccessOperator
);
result
=
targetExpr
;
}
else
{
result
=
nonAtomarExpression
;
}
}
else
if
(
nonAtomarExpression
instanceof
IMathNamedExpression
)
{
// substitute value expr by assigned expr
result
=
getSubstituteByName
(((
IMathNamedExpression
)
nonAtomarExpression
).
getNameToAccess
(),
nonAtomarExpression
,
atomarValueName
);
}
else
{
result
=
nonAtomarExpression
;
}
return
result
;
}
private
MathExpressionSymbol
getSubstituteByName
(
String
name
,
MathExpressionSymbol
expr
,
String
atomarValueName
)
{
MathExpressionSymbol
result
;
MathValueSymbol
declaration
=
getMathValueSymbol
(
name
);
if
((
declaration
!=
null
)
&&
(
declaration
.
getValue
()
!=
null
)
&&
(!
name
.
contentEquals
(
atomarValueName
)))
result
=
declaration
.
getValue
();
else
result
=
expr
;
return
result
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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