Skip to content

Commit 2751608

Browse files
author
Kristian Stavåker
committed
Made some improvements to the valueblock expression implementation in Codegen and Static. Made some changes in MetaUtil.mo. Added code for for-iterator constructors to Inst (they will be uncommented later on).
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2847 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 157479b commit 2751608

File tree

4 files changed

+559
-60
lines changed

4 files changed

+559
-60
lines changed

Compiler/Codegen.mo

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,11 +3770,15 @@ algorithm
37703770
// Convert back to DAE uniontypes from Exp uniontypes, part of a work-around
37713771
ld2 = Convert.fromExpElemsToDAEElems(ld,{});
37723772
b2 = Convert.fromExpElemToDAEElem(b);
3773-
(cfn,tnr_1) = generateVars(ld2, isVarQ, tnr, funContext);
3773+
3774+
(cfn,tnr_1) = generateVars(ld2, isVarQ, tnr, funContext);
3775+
cfn = cMoveDeclsAndInitsToStatements(cfn);
37743776
(cfn1,tnr2) = generateAlgorithms(Util.listCreate(b2), tnr_1, context);
3777+
37753778
(cfn1_2,var,tnr3) = generateExpression(res, tnr2, context);
37763779
cfn1_2 = cMergeFns({cfn,cfn1,cfn1_2});
3777-
then (cfn1_2,var,tnr2);
3780+
cfn1_2 = cAddBlockAroundStatements(cfn1_2);
3781+
then (cfn1_2,var,tnr2);
37783782

37793783
case (Exp.ASUB(exp = _),_,_)
37803784
equation
@@ -3824,6 +3828,50 @@ algorithm
38243828
end matchcontinue;
38253829
end generateExpression;
38263830

3831+
protected function cAddBlockAroundStatements "function: cAddBlockAroundStatements
3832+
author: KS
3833+
Used by generateExpression - Valueblock
3834+
"
3835+
input CFunction inCFunction;
3836+
output CFunction outCFunction;
3837+
algorithm
3838+
outCFunction:=
3839+
matchcontinue (inCFunction)
3840+
local
3841+
list<Lib> rts,ad,vd,is,st,cl;
3842+
Lib rt,fn;
3843+
case CFUNCTION(returnType = rt,functionName = fn,returnTypeStruct = rts,argumentDeclarationLst = ad,variableDeclarationLst = vd,initStatementLst = is,statementLst = st,cleanupStatementLst = cl)
3844+
equation
3845+
st = listAppend({"{"},st);
3846+
st = listAppend(st,{"}"});
3847+
then
3848+
CFUNCTION(rt,fn,rts,ad,vd,is,st,cl);
3849+
end matchcontinue;
3850+
3851+
end cAddBlockAroundStatements;
3852+
3853+
protected function cMoveDeclsAndInitsToStatements "function: cMoveStatementsToInits
3854+
3855+
Moves all statements of the body to initialization statements.
3856+
"
3857+
input CFunction inCFunction;
3858+
output CFunction outCFunction;
3859+
algorithm
3860+
outCFunction:=
3861+
matchcontinue (inCFunction)
3862+
local
3863+
list<Lib> is_1,rts,ad,vd,is,st,cl;
3864+
Lib rt,fn;
3865+
case CFUNCTION(returnType = rt,functionName = fn,returnTypeStruct = rts,argumentDeclarationLst = ad,variableDeclarationLst = vd,initStatementLst = is,statementLst = st,cleanupStatementLst = cl)
3866+
equation
3867+
st = listAppend(is,st);
3868+
st = listAppend(vd,st);
3869+
then
3870+
CFUNCTION(rt,fn,rts,ad,{},{},st,cl);
3871+
end matchcontinue;
3872+
end cMoveDeclsAndInitsToStatements;
3873+
3874+
38273875
protected function generateBuiltinFunction "function: generateBuiltinFunction
38283876
author: PA
38293877

0 commit comments

Comments
 (0)