Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors committed Aug 25, 2015
2 parents 0500ba2 + 1981ce9 commit e47e061
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 93 deletions.
14 changes: 6 additions & 8 deletions Compiler/BackEnd/StateMachineFeatures.mo
Expand Up @@ -352,7 +352,7 @@ algorithm
bindingKind := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.BINDING_EQUATION(), BackendDAE.NO_LOOP());

R(initialState, refining) := comp;
flatA := List.find(flatAs, function findInitialState(crefCmp=initialState));
flatA := List.find1(flatAs, findInitialState, initialState);
FLAT_AUTOMATON(initialState, states, sms) := flatA;
preRef := ComponentReference.crefPrefixString(SMS_PRE, initialState);
nStates := arrayLength(states);
Expand Down Expand Up @@ -522,7 +522,7 @@ algorithm
outLocalEqns := BackendDAE.EQUATION(exp, rhs, source, attr) :: outLocalEqns;

// Find variable corresponding to componentRef
var := List.selectFirst1(outLocal,cmpVarCref,componentRef);
var := List.find1(outLocal,cmpVarCref,componentRef);

// If lhs "x" is a state variable, i.e., "x" appears somewhere in the global equation system as "previous(x)",
// than substitute all "previous(x)" by a fresh variable "x_previous" which is defined by an equation "x_previous = if resetOfState than initialValueOfX else previous(x)"
Expand Down Expand Up @@ -933,13 +933,11 @@ Succeeds if initialState in flatAIn equals the crefCmp, otherwise fails.
Helper function to find flat automaton within a list of flat automata"
input FlatAutomaton flatAIn;
input DAE.ComponentRef crefCmp;
output FlatAutomaton flatAOut;
output Boolean outFound;
algorithm
flatAOut := match flatAIn
local
DAE.ComponentRef cref;
case FLAT_AUTOMATON(initialState=cref) guard ComponentReference.crefEqual(cref,crefCmp) then flatAIn;
else fail();
outFound := match flatAIn
case FLAT_AUTOMATON() then ComponentReference.crefEqual(flatAIn.initialState, crefCmp);
else false;
end match;
end findInitialState;

Expand Down
14 changes: 8 additions & 6 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -5401,16 +5401,18 @@ protected
list<ClassPart> class_parts;
algorithm
CLASS(body = PARTS(classParts = class_parts)) := inCls;
outExternal := List.find(class_parts, getExternalFromClassPart);
outExternal := List.find(class_parts, isExternalPart);
end getExternalDecl;

protected function getExternalFromClassPart
protected function isExternalPart
input ClassPart inClassPart;
output ClassPart outExternal;
output Boolean outFound;
algorithm
EXTERNAL() := inClassPart;
outExternal := inClassPart;
end getExternalFromClassPart;
outFound := match inClassPart
case EXTERNAL() then true;
else false;
end match;
end isExternalPart;

public function isParts
input ClassDef cl;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -4408,7 +4408,7 @@ algorithm
* Exponentation is very expensive compared to the inner expressions.
*/
((exp_lst as (_ :: _ :: _ :: _))) = Expression.factors(e1);
_ = List.selectFirst(exp_lst,Expression.isConstValue);
_ = List.find(exp_lst,Expression.isConstValue);
exp_lst_1 = simplifyBinaryDistributePow(exp_lst, e2);
then Expression.makeProductLst(exp_lst_1);
// (e1^e2)^e3 => e1^(e2*e3)
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -214,7 +214,7 @@ algorithm
//print(" Ceval res: ("+stringDelimitList(List.map(valList,ValuesUtil.printValStr),",")+")\n");

blist = List.map(valList,ValuesUtil.valueBool);
selectedBranch = List.selectFirstBoolList(blist, tbs, fb);
selectedBranch = List.findBoolList(blist, tbs, fb);
selectedBranch = makeDAEElementInitial(selectedBranch);
then listAppend(selectedBranch,acc);
else elem::acc;
Expand Down Expand Up @@ -2014,14 +2014,14 @@ algorithm
case (exp as Absyn.CREF(componentRef = cref), (all_el, stack, accum_el, b))
equation
id = Absyn.crefFirstIdent(cref);
e = List.selectFirst1(all_el, isElementNamed, id);
e = List.find1(all_el, isElementNamed, id);
then
(exp, (all_el, stack, e :: accum_el, b));

case (exp as Absyn.CALL(function_ = cref), (all_el, stack, accum_el, b))
equation
id = Absyn.crefFirstIdent(cref);
e = List.selectFirst1(all_el, isElementNamed, id);
e = List.find1(all_el, isElementNamed, id);
then
(exp, (all_el, stack, e :: accum_el, b));

Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Mod.mo
Expand Up @@ -2915,7 +2915,7 @@ algorithm

case DAE.MOD(subModLst = submods)
equation
_ = List.selectFirst(submods, isUntypedSubMod);
_ = List.find(submods, isUntypedSubMod);
then
true;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/NFInstUtil.mo
Expand Up @@ -1653,7 +1653,7 @@ public import SCode;
// case NFInstTypes.SINGLE_CONDITION(condition = cond) then cond;
// case NFInstTypes.ARRAY_CONDITION(conditions = condl)
// equation
// _ = List.selectFirst(condl, conditionFalse);
// _ = List.find(condl, conditionFalse);
// then
// false;
//
Expand All @@ -1673,7 +1673,7 @@ public import SCode;
// case NFInstTypes.SINGLE_CONDITION(condition = cond) then not cond;
// case NFInstTypes.ARRAY_CONDITION(conditions = condl)
// equation
// _ = List.selectFirst(condl, conditionTrue);
// _ = List.find(condl, conditionTrue);
// then
// false;
//
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/NFSCodeFlatten.mo
Expand Up @@ -75,7 +75,7 @@ protected
String name;
algorithm
prog := listReverse(inProgram);
SCode.CLASS(name = name) := List.selectFirst(prog, isClass);
SCode.CLASS(name = name) := List.find(prog, isClass);
outClassName := Absyn.IDENT(name);
end getLastClassNameInProgram;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -3798,7 +3798,7 @@ protected
list<SubMod> submods;
algorithm
ANNOTATION(modification = MOD(subModLst = submods)) := inAnnotation;
NAMEMOD(mod = MOD(info = info, binding = SOME(exp))) := List.selectFirst1(submods, hasNamedAnnotation, inName);
NAMEMOD(mod = MOD(info = info, binding = SOME(exp))) := List.find1(submods, hasNamedAnnotation, inName);
end getNamedAnnotation;

protected function hasNamedAnnotation
Expand Down Expand Up @@ -3937,7 +3937,7 @@ algorithm

case ANNOTATION(MOD(fp, ep, submods, _, info))
equation
inline_mod = List.selectFirst(submods, isInlineTypeSubMod);
inline_mod = List.find(submods, isInlineTypeSubMod);
then
SOME(ANNOTATION(MOD(fp, ep, {inline_mod}, NONE(), info)));

Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Static.mo
Expand Up @@ -7925,7 +7925,7 @@ algorithm

case DAE.T_METARECORD(source = {fq_path})
algorithm
DAE.TYPES_VAR(name = str) := List.selectFirst(inType.fields, Types.varHasMetaRecordType);
DAE.TYPES_VAR(name = str) := List.find(inType.fields, Types.varHasMetaRecordType);
fn_str := Absyn.pathString(fq_path);
Error.addSourceMessage(Error.METARECORD_CONTAINS_METARECORD_MEMBER,
{fn_str, str}, inInfo);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -15278,7 +15278,7 @@ protected
list<Absyn.Class> classes;
algorithm
Absyn.PROGRAM(classes=classes) := inProgram;
cl := List.selectFirst1(classes,getClassInProgramWork,inString);
cl := List.find1(classes,getClassInProgramWork,inString);
end getClassInProgram;

protected function getClassInProgramWork
Expand Down
6 changes: 3 additions & 3 deletions Compiler/SimCode/SimCodeFunctionUtil.mo
Expand Up @@ -535,7 +535,7 @@ protected
algorithm
DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path)) := ty;
name := Absyn.pathStringUnquoteReplaceDot(path, "_");
decl := List.selectFirst1(allDecls, isRecordDecl, name);
decl := List.find1(allDecls, isRecordDecl, name);
end getRecordDependenciesFromType;

protected function isRecordDecl
Expand Down Expand Up @@ -1042,11 +1042,11 @@ algorithm
list<SimCode.Variable> inVars;
case (_, SimCode.FUNCTION(functionArguments = inVars))
equation
failure(_ = List.selectFirst(inVars, isFunctionPtr));
failure(_ = List.find(inVars, isFunctionPtr));
then ();
case (_, SimCode.EXTERNAL_FUNCTION(inVars = inVars))
equation
failure(_ = List.selectFirst(inVars, isFunctionPtr));
failure(_ = List.find(inVars, isFunctionPtr));
then ();
else
equation
Expand Down
14 changes: 7 additions & 7 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -1841,7 +1841,7 @@ case var as VARIABLE(__) then
let &preExp = buffer ""
let params = (arr.array |> e hasindex i1 fromindex 1 =>
let prefix = if arr.scalar then '(<%expTypeFromExpModelica(e)%>)' else '&'
'(*((<%rec_name%>*)generic_array_element_addr(&<%varName%>, sizeof(<%rec_name%>), 1, <%i1%>))) = <%prefix%><%daeExp(e, contextFunction, &preExp, &varDecls, &auxFunction)%>;'
'(*((<%rec_name%>*)generic_array_element_addr1(&<%varName%>, sizeof(<%rec_name%>), <%i1%>))) = <%prefix%><%daeExp(e, contextFunction, &preExp, &varDecls, &auxFunction)%>;'
;separator="\n")
<<
<%preExp%>
Expand Down Expand Up @@ -4520,7 +4520,7 @@ template daeExpCrefRhsFunContext(Exp ecr, Context context, Text &preExp,
>>
else
<<
(*<%arrayType%>_element_addr(&<%arrName%>, <%dimsLenStr%>, <%dimsValuesStr%>))
(*<%arrayType%>_element_addr<%match listLength(crefSubs(cr)) case 1 case 2 then dimsLenStr%>(&<%arrName%>, <%dimsLenStr%>, <%dimsValuesStr%>))
>>
case PARALLEL_FUNCTION_CONTEXT(__) then
<<
Expand Down Expand Up @@ -4570,7 +4570,7 @@ template arrayScalarRhs(Type ty, list<Exp> subs, String arrName, Context context
>>
else
<<
(*<%arrayType%>_element_addr(&<%arrName%>, <%dimsLenStr%>, <%dimsValuesStr%>))
(*<%arrayType%>_element_addr<%if intLt(listLength(subs), 3) then listLength(subs)%>(&<%arrName%>, <%dimsLenStr%>, <%dimsValuesStr%>))
>>
end arrayScalarRhs;

Expand Down Expand Up @@ -4658,7 +4658,7 @@ template daeExpCrefLhsFunContext(Exp ecr, Context context, Text &preExp,
>>
case FUNCTION_CONTEXT(__) then
<<
(*<%arrayType%>_element_addr(&<%arrName%>, <%dimsLenStr%>, <%dimsValuesStr%>))
(*<%arrayType%>_element_addr<%if intLt(listLength(crefSubs(cr)),3) then dimsLenStr%>(&<%arrName%>, <%dimsLenStr%>, <%dimsValuesStr%>))
>>
else
error(sourceInfo(),'This should have been handled in the new daeExpCrefLhsSimContext function. <%printExpStr(ecr)%>')
Expand Down Expand Up @@ -5774,7 +5774,7 @@ case ARRAY(array = array, scalar = scalar, ty = T_ARRAY(ty = t as T_COMPLEX(__))
let &preExp += '<%\n%>alloc_generic_array(&<%arrayVar%>, sizeof(<%rec_name%>), 1, <%listLength(array)%>);<%\n%>'
let params = (array |> e hasindex i1 fromindex 1 =>
let prefix = if scalar then '(<%expTypeFromExpModelica(e)%>)' else '&'
'(*((<%rec_name%>*)generic_array_element_addr(&<%arrayVar%>, sizeof(<%rec_name%>), 1, <%i1%>))) = <%prefix%><%daeExp(e, context, &preExp, &varDecls, &auxFunction)%>;'
'(*((<%rec_name%>*)generic_array_element_addr1(&<%arrayVar%>, sizeof(<%rec_name%>), <%i1%>))) = <%prefix%><%daeExp(e, context, &preExp, &varDecls, &auxFunction)%>;'
;separator="\n")
let &preExp += '<%params%><%\n%>'
arrayVar
Expand Down Expand Up @@ -6140,7 +6140,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
match typeof(r.expr)
case T_COMPLEX(complexClassType = record_state) then
let rec_name = '<%underscorePath(ClassInf.getStateName(record_state))%>'
'*((<%rec_name%>*)generic_array_element_addr(&<%res%>, sizeof(<%rec_name%>), 1, <%arrIndex%>++)) = <%reductionBodyExpr%>;'
'*((<%rec_name%>*)generic_array_element_addr1(&<%res%>, sizeof(<%rec_name%>), <%arrIndex%>++)) = <%reductionBodyExpr%>;'
case T_ARRAY(__) then
let tmp = tempDecl("index_spec_t", &varDecls)
let nridx_str = intAdd(1,listLength(dims))
Expand Down Expand Up @@ -6213,7 +6213,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
let addr = match iter.ty
case T_ARRAY(ty=T_COMPLEX(complexClassType = record_state)) then
let rec_name = '<%underscorePath(ClassInf.getStateName(record_state))%>'
'*((<%rec_name%>*)generic_array_element_addr(&<%loopVar%>, sizeof(<%rec_name%>), 1, <%firstIndex%>++))'
'*((<%rec_name%>*)generic_array_element_addr1(&<%loopVar%>, sizeof(<%rec_name%>), <%firstIndex%>++))'
else
'*(<%arrayType%>_element_addr1(&<%loopVar%>, 1, <%firstIndex%>++))'
<<
Expand Down
29 changes: 21 additions & 8 deletions Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -3125,22 +3125,22 @@ template daeExpPartEvalFunction(Exp exp, Context context, Text &preExp, Text &va
let closureName = '_Closure<%System.tmpTickIndex(2/*auxFunction*/)%>_<%funcName%>'
let functionsObject = match context case FUNCTION_CONTEXT(__) then 'this' else '_functions'
let createClosure = (expList |> e => ', <%daeExp(e, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>')
let closureArgsDecl = (setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => ', <%expTypeShort(a.ty)%> <%a.name%>')
let closureArgsDecl = (setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => ', <%partEvalBoxedType(listGet(expList, i1))%> &<%a.name%>')
let callArgsDecl = (t.funcArg |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%expTypeShort(a.ty)%> <%a.name%>, ')
let callArgsOrig = (t_orig.funcArg |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%a.name%>, ')
let &extraFuncsDecl +=
<<

template <typename metatype> // TODO: remove this if actual types known
template <typename metatype> // TODO: remove metatype if actual types known
class <%closureName%>
{
Functions *_functions;
<%setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%expTypeShort(a.ty)%> <%a.name%>;<%\n%>'%>
<%setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%partEvalBoxedType(listGet(expList, i1))%> &<%a.name%>;<%\n%>'%>
public:
<%closureName%>(Functions *functions<%closureArgsDecl%>) {
_functions = functions;
<%setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex intAdd(listLength(t.funcArg), 1) => 'this-><%a.name%> = <%a.name%>;<%\n%>'%>
}
<%closureName%>(Functions *functions<%closureArgsDecl%>)
: _functions(functions)
<%setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => ', <%a.name%>(<%a.name%>)<%\n%>'%>
{}
void operator()(<%callArgsDecl%><%funcName%>RetType &output) {
_functions-><%funcName%>(<%callArgsOrig%>output);
}
Expand All @@ -3151,12 +3151,25 @@ template daeExpPartEvalFunction(Exp exp, Context context, Text &preExp, Text &va
error(sourceInfo(), 'PARTEVALFUNCTION: <%ExpressionDump.printExpStr(exp)%>, ty=<%unparseType(ty)%>, origType=<%unparseType(origType)%>')
end daeExpPartEvalFunction;

template partEvalBoxedType(Exp exp)
"Returns the type of a boxed expression"
::=
match exp
case exp as BOX(__) then
let elty = expTypeFromExpShort(exp.exp)
let ty = if isArrayType(typeof(exp.exp)) then 'BaseArray< <%elty%> >' else '<%elty%>'
'<%ty%>'
else
'<%expTypeFromExpShort(exp)%>'
end partEvalBoxedType;

template daeExpBox(Exp exp, Context context, Text &preExp, Text &varDecls, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
"Not needed; just returns exp"
::=
match exp
case BOX(__) then
let ty = if isArrayType(typeof(exp)) then "modelica_array" else expTypeFromExpShort(exp)
let elty = expTypeFromExpShort(exp)
let ty = if isArrayType(typeof(exp)) then 'BaseArray< <%elty%> >' else '<%elty%>'
let res = daeExp(exp, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
'/*box <%ty%>*/<%res%>'
end daeExpBox;
Expand Down

0 comments on commit e47e061

Please sign in to comment.