diff --git a/Compiler/FrontEnd/ModelicaBuiltin.mo b/Compiler/FrontEnd/ModelicaBuiltin.mo index 0b0bbcf5037..9b6661602f5 100644 --- a/Compiler/FrontEnd/ModelicaBuiltin.mo +++ b/Compiler/FrontEnd/ModelicaBuiltin.mo @@ -753,7 +753,7 @@ function spatialDistribution "Not yet implemented" input Real x; input Boolean positiveVelocity; parameter input Real initialPoints[:](each min = 0, each max = 1) = {0.0, 1.0}; - parameter input Real initialValues[size(initialPoints)] = {0.0, 0.0}; + parameter input Real initialValues[size(initialPoints, 1)] = {0.0, 0.0}; output Real out0; output Real out1; external "builtin"; diff --git a/Compiler/NFFrontEnd/NFBinding.mo b/Compiler/NFFrontEnd/NFBinding.mo index 5d7906da542..c2ff3abaf3f 100644 --- a/Compiler/NFFrontEnd/NFBinding.mo +++ b/Compiler/NFFrontEnd/NFBinding.mo @@ -62,7 +62,7 @@ public record TYPED_BINDING Expression bindingExp; Type bindingType; - DAE.Const variability; + DAE.VarKind variability; Integer propagatedLevels; SourceInfo info; end TYPED_BINDING; @@ -142,12 +142,9 @@ public function variability input Binding binding; - output DAE.Const var; + output DAE.VarKind var; algorithm - var := match binding - case TYPED_BINDING() then binding.variability; - else DAE.Const.C_UNKNOWN(); - end match; + TYPED_BINDING(variability = var) := binding; end variability; function getInfo diff --git a/Compiler/NFFrontEnd/NFBuiltin.mo b/Compiler/NFFrontEnd/NFBuiltin.mo index 62a1b3e051a..800e257ee9e 100644 --- a/Compiler/NFFrontEnd/NFBuiltin.mo +++ b/Compiler/NFFrontEnd/NFBuiltin.mo @@ -152,7 +152,7 @@ constant Binding STATESELECT_NEVER_BINDING = Binding.TYPED_BINDING( Expression.ENUM_LITERAL(STATESELECT_TYPE_TYPE, "never", 1), STATESELECT_TYPE_TYPE, - DAE.C_CONST(), + DAE.VarKind.CONST(), -1, Absyn.dummyInfo); @@ -160,7 +160,7 @@ constant Binding STATESELECT_AVOID_BINDING = Binding.TYPED_BINDING( Expression.ENUM_LITERAL(STATESELECT_TYPE_TYPE, "avoid", 2), STATESELECT_TYPE_TYPE, - DAE.C_CONST(), + DAE.VarKind.CONST(), -1, Absyn.dummyInfo); @@ -168,7 +168,7 @@ constant Binding STATESELECT_DEFAULT_BINDING = Binding.TYPED_BINDING( Expression.ENUM_LITERAL(STATESELECT_TYPE_TYPE, "default", 3), STATESELECT_TYPE_TYPE, - DAE.C_CONST(), + DAE.VarKind.CONST(), -1, Absyn.dummyInfo); @@ -176,7 +176,7 @@ constant Binding STATESELECT_PREFER_BINDING = Binding.TYPED_BINDING( Expression.ENUM_LITERAL(STATESELECT_TYPE_TYPE, "prefer", 4), STATESELECT_TYPE_TYPE, - DAE.C_CONST(), + DAE.VarKind.CONST(), -1, Absyn.dummyInfo); @@ -184,7 +184,7 @@ constant Binding STATESELECT_ALWAYS_BINDING = Binding.TYPED_BINDING( Expression.ENUM_LITERAL(STATESELECT_TYPE_TYPE, "always", 5), STATESELECT_TYPE_TYPE, - DAE.C_CONST(), + DAE.VarKind.CONST(), -1, Absyn.dummyInfo); diff --git a/Compiler/NFFrontEnd/NFCall.mo b/Compiler/NFFrontEnd/NFCall.mo index aaedbd0a728..c8408a0ebcf 100644 --- a/Compiler/NFFrontEnd/NFCall.mo +++ b/Compiler/NFFrontEnd/NFCall.mo @@ -50,6 +50,7 @@ import List; import NFClass.Class; import ErrorExt; import Util; +import InstUtil = NFInstUtil; protected import NFFunction.NamedArg; @@ -171,7 +172,7 @@ uniontype Call input output Expression callExp; input SourceInfo info; output Type ty; - output DAE.Const variability; + output DAE.VarKind variability; protected Call call, argtycall; InstNode fn_node; @@ -180,7 +181,7 @@ uniontype Call Function fn; list args; list arg_ty; - list arg_var; + list arg_var; CallAttributes ca; list tyArgs; algorithm @@ -203,9 +204,9 @@ uniontype Call args := list(Util.tuple31(a) for a in tyArgs); - variability := DAE.C_CONST(); + variability := DAE.VarKind.CONST(); for a in tyArgs loop - variability := Types.constAnd(variability,Util.tuple33(a)); + variability := InstUtil.variabilityAnd(variability,Util.tuple33(a)); end for; // Construct the call expression. @@ -240,7 +241,7 @@ uniontype Call local Expression arg; Type arg_ty; - DAE.Const arg_const; + DAE.VarKind arg_var; list typedArgs; list typedNamedArgs; String name; @@ -248,8 +249,8 @@ uniontype Call case UNTYPED_CALL() algorithm typedArgs := {}; for arg in call.arguments loop - (arg, arg_ty, arg_const) := Typing.typeExp(arg,info); - typedArgs := (arg, arg_ty, arg_const)::typedArgs; + (arg, arg_ty, arg_var) := Typing.typeExp(arg,info); + typedArgs := (arg, arg_ty, arg_var)::typedArgs; end for; typedArgs := listReverse(typedArgs); @@ -257,8 +258,8 @@ uniontype Call typedNamedArgs := {}; for narg in call.named_args loop (name,arg) := narg; - (arg, arg_ty, arg_const) := Typing.typeExp(arg,info); - typedNamedArgs := (name, arg, arg_ty, arg_const)::typedNamedArgs; + (arg, arg_ty, arg_var) := Typing.typeExp(arg,info); + typedNamedArgs := (name, arg, arg_ty, arg_var)::typedNamedArgs; end for; listReverse(typedNamedArgs); diff --git a/Compiler/NFFrontEnd/NFCeval.mo b/Compiler/NFFrontEnd/NFCeval.mo index cf433536d36..e53752c1eda 100644 --- a/Compiler/NFFrontEnd/NFCeval.mo +++ b/Compiler/NFFrontEnd/NFCeval.mo @@ -45,7 +45,7 @@ import Type = NFType; uniontype EvalTarget record DIMENSION - String name; + InstNode component; Integer index; Expression exp; SourceInfo info; @@ -235,7 +235,7 @@ algorithm case EvalTarget.DIMENSION() algorithm Error.addSourceMessage(Error.STRUCTURAL_PARAMETER_OR_CONSTANT_WITH_NO_BINDING, - {Expression.toString(exp), target.name}, target.info); + {Expression.toString(exp), InstNode.name(target.component)}, target.info); then fail(); diff --git a/Compiler/NFFrontEnd/NFClass.mo b/Compiler/NFFrontEnd/NFClass.mo index 45981202838..8844c33e294 100644 --- a/Compiler/NFFrontEnd/NFClass.mo +++ b/Compiler/NFFrontEnd/NFClass.mo @@ -163,17 +163,6 @@ uniontype Class end match; end isBuiltin; - function getType - input Class cls; - output Type ty; - algorithm - ty := match cls - case PARTIAL_BUILTIN() then cls.ty; - case INSTANCED_BUILTIN() then cls.ty; - else Type.UNKNOWN(); - end match; - end getType; - function classTree input Class cls; output ClassTree tree; diff --git a/Compiler/NFFrontEnd/NFComponent.mo b/Compiler/NFFrontEnd/NFComponent.mo index 2ac29a16e27..ce3e82983f9 100644 --- a/Compiler/NFFrontEnd/NFComponent.mo +++ b/Compiler/NFFrontEnd/NFComponent.mo @@ -228,7 +228,7 @@ uniontype Component algorithm ty := match component case TYPED_COMPONENT() then component.ty; - case UNTYPED_COMPONENT() then Class.getType(InstNode.getClass(component.classInst)); + case UNTYPED_COMPONENT() then InstNode.getType(component.classInst); case ITERATOR() then component.ty; else Type.UNKNOWN(); end match; @@ -467,6 +467,18 @@ uniontype Component else false; end match; end isRedeclare; + + function dimensionCount + input Component component; + output Integer count; + algorithm + count := match component + case UNTYPED_COMPONENT() then arrayLength(component.dimensions); + case TYPED_COMPONENT() then listLength(Type.arrayDims(component.ty)); + else 0; + end match; + end dimensionCount; + end Component; annotation(__OpenModelica_Interface="frontend"); diff --git a/Compiler/NFFrontEnd/NFComponentRef.mo b/Compiler/NFFrontEnd/NFComponentRef.mo index 07321d7c12b..47a17eec2a6 100644 --- a/Compiler/NFFrontEnd/NFComponentRef.mo +++ b/Compiler/NFFrontEnd/NFComponentRef.mo @@ -101,20 +101,11 @@ public function getVariability input ComponentRef cref; - output DAE.Const var; + output DAE.VarKind var; algorithm var := match cref - case CREF() - then - match Component.variability(InstNode.component(cref.node)) - case DAE.VarKind.VARIABLE() then DAE.Const.C_VAR(); - case DAE.VarKind.DISCRETE() then DAE.Const.C_VAR(); - case DAE.VarKind.PARAM() then DAE.Const.C_PARAM(); - case DAE.VarKind.CONST() then DAE.Const.C_CONST(); - else DAE.Const.C_UNKNOWN(); - end match; - - else DAE.Const.C_UNKNOWN(); + case CREF() then Component.variability(InstNode.component(cref.node)); + else DAE.VarKind.VARIABLE(); end match; end getVariability; diff --git a/Compiler/NFFrontEnd/NFExpression.mo b/Compiler/NFFrontEnd/NFExpression.mo index 829d5cde2d8..40eaf0e9446 100644 --- a/Compiler/NFFrontEnd/NFExpression.mo +++ b/Compiler/NFFrontEnd/NFExpression.mo @@ -905,7 +905,7 @@ public String s; Expression e; Type t; - DAE.Const c; + DAE.VarKind v; case Call.UNTYPED_CALL() algorithm @@ -926,15 +926,15 @@ public tnargs := {}; for arg in call.arguments loop - (e, t, c) := arg; + (e, t, v) := arg; e := traverse(e, func); - targs := (e, t, c) :: targs; + targs := (e, t, v) :: targs; end for; for arg in call.named_args loop - (s, e, t, c) := arg; + (s, e, t, v) := arg; e := traverse(e, func); - tnargs := (s, e, t, c) :: tnargs; + tnargs := (s, e, t, v) :: tnargs; end for; then Call.ARG_TYPED_CALL(call.ref, listReverse(targs), listReverse(tnargs)); @@ -1089,5 +1089,42 @@ public end match; end expandCref4; + function arrayFirstScalar + "Returns the first scalar element of an array. Fails if the array is empty." + input Expression arrayExp; + output Expression exp; + algorithm + exp := match arrayExp + case ARRAY() then arrayFirstScalar(listHead(arrayExp.elements)); + else arrayExp; + end match; + end arrayFirstScalar; + + function arrayAllEqual + "Checks if all scalar elements in an array are equal to each other." + input Expression arrayExp; + output Boolean allEqual; + algorithm + allEqual := matchcontinue arrayExp + case ARRAY() + then arrayAllEqual2(arrayExp, arrayFirstScalar(arrayExp)); + else true; + end matchcontinue; + end arrayAllEqual; + + function arrayAllEqual2 + input Expression arrayExp; + input Expression element; + output Boolean allEqual; + algorithm + allEqual := match arrayExp + case ARRAY(elements = ARRAY() :: _) + then List.map1BoolAnd(arrayExp.elements, arrayAllEqual2, element); + case ARRAY() + then List.map1BoolAnd(arrayExp.elements, isEqual, element); + else true; + end match; + end arrayAllEqual2; + annotation(__OpenModelica_Interface="frontend"); end NFExpression; diff --git a/Compiler/NFFrontEnd/NFFunc.mo b/Compiler/NFFrontEnd/NFFunc.mo deleted file mode 100644 index 87a1e8136f2..00000000000 --- a/Compiler/NFFrontEnd/NFFunc.mo +++ /dev/null @@ -1,1306 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ - -encapsulated package NFFunc -" file: NFFunc.mo - package: NFFunc - description: package for handling functions. - - - Functions used by NFInst for handling functions. -" - -//public -//function typeFunctionCall -// input Absyn.ComponentRef functionName; -// input Absyn.FunctionArgs functionArgs; -// input InstNode scope; -// input SourceInfo info; -// output Expression typedExp; -// output Type ty; -// output DAE.Const variability; -//protected -// String fn_name; -// Absyn.Path fn, fn_1; -// InstNode fakeComponent; -// InstNode classNode, foundScope; -// list arguments; -// DAE.CallAttributes ca; -// Type classType, resultType; -// list funcArg; -// DAE.FunctionAttributes functionAttributes; -// Prefix prefix; -// SCode.Element cls; -// list vars; -// list args; -// DAE.Const argVariability; -// DAE.FunctionBuiltin isBuiltin; -// Boolean builtin; -// DAE.InlineType inlineType; -// Lookup.LookupState state; -//algorithm -// try -// // make sure the component is a path (no subscripts) -// fn := Absyn.crefToPath(functionName); -// else -// fn_name := Dump.printComponentRefStr(functionName); -// Error.addSourceMessageAndFail(Error.SUBSCRIPTED_FUNCTION_CALL, {fn_name}, info); -// fail(); -// end try; -// -// // TODO: Revise this -// try -// (classNode, _, foundScope, state) := Lookup.lookupCref(functionName, scope, info); -// prefix := InstNode.prefix(foundScope); -// cls := InstNode.definition(classNode); -// -// if SCode.isRecord(cls) then -// classNode := Inst.instantiate(classNode, Modifier.NOMOD(), scope); -// (classNode, classType) := Typing.typeClass(classNode); -// (typedExp, ty, variability) := Record.typeRecordCall(functionName, functionArgs, prefix, classNode, classType, scope, info); -// elseif isBuiltinFunctionName(functionName) then -// classNode := Inst.instantiate(classNode, Modifier.NOMOD(), scope); -// (classNode, classType) := Typing.typeClass(classNode); -// (typedExp, ty, variability) := typeBuiltinFunctionCall(functionName, functionArgs, prefix, classNode, classType, cls, scope, info); -// else -// // assertfunction here. -// // (classNode, foundScope) := Lookup.lookupFunctionName(functionName, scope, info); -// classNode := Inst.instantiate(classNode, Modifier.NOMOD(), scope); -// (classNode, classType) := Typing.typeClass(classNode); -// (typedExp, ty, variability) := typeNormalFunction(functionName, functionArgs, prefix, classNode, classType, scope, info); -// end if; -// else -// // we could not lookup the class, see if is a special builtin such as String(), etc -// if isSpecialBuiltinFunctionName(functionName) then -// (typedExp, ty, variability) := typeSpecialBuiltinFunctionCall(functionName, functionArgs, prefix, classNode, scope, info); -// return; -// end if; -// // fail otherwise -// fail(); -// end try; -// -//end typeFunctionCall; -// -//function typeNormalFunction -// input Absyn.ComponentRef funcName; -// input Absyn.FunctionArgs callArgs; -// input Prefix prefix; -// input InstNode classNode; -// input Type classType; -// input InstNode scope; -// input SourceInfo info; -// output Expression typedExp; -// output Type ty; -// output DAE.Const variability; -//protected -// Absyn.Path fn; -// InstNode ty_node; -// NFExpression.CallAttributes ca; -// Type resultType; -// DAE.FunctionAttributes functionAttributes; -// list posargs; -// list namedargs; -// DAE.FunctionBuiltin isBuiltin; -// Boolean builtin; -// DAE.InlineType inlineType; -// list inputs; -// list dargs, callExps; -// Expression argExp; -// Type argTy; -// DAE.Const argConst; -// list slots; -// FunctionSlot sl; -// list vectDims; -// SCode.Element cls; -// -//algorithm -// -// fn := Absyn.crefToPath(funcName); -// inputs := getFunctionInputs(classNode); -// -// slots := createAndFillSlots(funcName, prefix, inputs, callArgs, scope, info); -// -// // check that there are no unfilled slots and the types of actual arguments agree with the type of function arguments -// (slots,vectDims) := typeCheckFunctionSlots(slots, fn, prefix, info); -// -// (dargs, variability) := argsFromSlots(slots); -// -// Type.COMPLEX(cls = ty_node) := classType; -// functionAttributes := getFunctionAttributes(ty_node); -// ty := makeFunctionType(ty_node, functionAttributes); -// -// Type.FUNCTION(resultType = resultType) := ty; -// -// (isBuiltin, builtin, fn) := isBuiltinFunc(fn, functionAttributes); -// inlineType := Static.inlineBuiltin(isBuiltin,functionAttributes.inline); -// -// ca := CallAttributes.CALL_ATTR( -// resultType, -// Type.isTuple(resultType), -// builtin, -// functionAttributes.isImpure or (not functionAttributes.isOpenModelicaPure), -// functionAttributes.isFunctionPointer, -// inlineType,DAE.NO_TAIL()); -// -// if listLength(vectDims) == 0 then -// typedExp := Expression.CALL(fn, Expression.CREF(classNode, prefix), dargs, ca); -// else -// // ty := Type.liftArrayLeftList(ty, vectDims); -// callExps := vectorizeCall(fn, classNode, prefix, dargs, ca, vectDims); -// typedExp := Expression.arrayFromList(callExps, ty, vectDims); -// end if; -//end typeNormalFunction; -// -//function createAndFillSlots -// input Absyn.ComponentRef funcName; -// input Prefix prefix; -// input list funcInputs; -// input Absyn.FunctionArgs callArgs; -// input InstNode callScope; -// input SourceInfo info; -// output list filledSlots; -//protected -// Component comp; -// DAE.VarKind vari; -// DAE.Const consts; -// list posargs; -// list namedargs; -// FunctionSlot sl; -// list slots, posfilled; -// Expression argExp; -// Type argTy; -// DAE.Const argConst; -//algorithm -// -// slots := {}; -// for compnode in funcInputs loop -// comp := InstNode.component(compnode); -// vari := Component.variability(comp); -// consts := Typing.variabilityToConst(NFInstUtil.daeToSCodeVariability(vari)); -// slots := SLOT(InstNode.name(compnode), -// NONE(), -// Component.getBinding(comp), -// SOME((Component.getType(comp), consts)), -// false)::slots; -// end for; -// slots := listReverse(slots); -// -// Absyn.FUNCTIONARGS(args = posargs, argNames = namedargs) := callArgs; -// -// posfilled := {}; -// // handle positional args -// for arg in posargs loop -// (argExp, argTy, argConst) := Typing.typeExp(arg, callScope, info); -// sl::slots := slots; -// sl := fillPosSlotWithArg(sl,(argExp, argTy, argConst)); -// posfilled := sl::posfilled; -// end for; -// slots := listAppend(listReverse(posfilled), slots); -// -// // handle named args -// for narg in namedargs loop -// Absyn.NAMEDARG() := narg; -// (argExp, argTy, argConst) := Typing.typeExp(narg.argValue, callScope, info); -// slots := fillNamedSlot(slots, narg.argName, (argExp, argTy, argConst), Absyn.crefToPath(funcName), prefix, info); -// end for; -// -// filledSlots := slots; -//end createAndFillSlots; -// -//function typeCheckFunctionSlots -// input list slots; -// input Absyn.Path fn; -// input Prefix prefix; -// input SourceInfo info; -// output list outslots; -// output list vectDims; -//algorithm -//protected -// String str1, str2, s1, s2, s3, s4, s5; -// Boolean b, found = false; -// String sname "the name of the slot"; -// Option> sarg "the argument given by the function call"; -// Binding sdefault "the default value from binding of the input component in the function"; -// Option> sexpected "the actual type of the input component, what we expect to get"; -// Boolean sisFilled, compatible; -// Expression expActual, expMatched; -// DAE.Const vrActual, vrExpected; -// Type tyActual, tyExpected, tyMatched, ty1,ty2; -// list dims1,dims2; -// Integer position = 0; -// -//algorithm -// outslots := {}; -// vectDims := {}; -// -// for s in slots loop -// position := position + 1; -// SLOT(sname, sarg, sdefault, sexpected, sisFilled) := s; -// -// // slot is filled, i.e, an argument has been specified. -// if sisFilled then -// SOME((expActual, tyActual, vrActual)) := sarg; -// SOME((tyExpected, vrExpected)) := sexpected; -// -// // fail if the variability is wrong -// if not Types.constEqualOrHigher(vrActual, vrExpected) then -// str1 := Expression.toString(expActual); -// str2 := DAEUtil.constStrFriendly(vrExpected); -// Error.addSourceMessageAndFail(Error.FUNCTION_SLOT_VARIABILITY, {sname, str1, str2}, info); -// end if; -// -// // check the types match -// (expMatched, tyMatched, compatible) := TypeCheck.matchTypes(tyActual, tyExpected, expActual, false); -// -// // If types don't match check the element types to see if it is a dimension issue. If so we try vectorization -// if not compatible then -// ty1 := Type.elementType(tyActual); -// ty2 := Type.elementType(tyExpected); -// (expMatched, tyMatched, compatible) := TypeCheck.matchTypes(ty1, ty2, expActual, false); -// -// // if even the element types are different then fail. -// if not compatible then -// s1 := intString(position); -// s2 := Absyn.pathStringNoQual(fn); -// s3 := Expression.toString(expActual); -// s4 := Type.toString(tyActual); -// s5 := Type.toString(tyExpected); -// Error.addSourceMessage(Error.ARG_TYPE_MISMATCH, {s1,s2,sname,s3,s4,s5}, info); -// fail(); -// // If the element types are the same then try to find a vectorization dim. -// // Matching RESTARTS from the first argument again in vectorize mode. -// else -// dims1 := Type.getTypeDims(tyActual); -// dims2 := Type.getTypeDims(tyExpected); -// vectDims := findVectorizationDim(dims1,dims2); -// outslots := vectorizeTypeCheckFunctionSlots(slots, fn, prefix, info, vectDims); -// return; -// end if; -// end if; -// -// // Argument has not been given but there is a default value. -// // Right now bindings are not typechecked with the declaration when they reach here. -// // That will change soon so this is just enough. -// elseif Binding.isBound(sdefault) then -// Binding.TYPED_BINDING(expMatched, tyMatched, vrActual) := sdefault; -// // No argument. No default value. -// else -// Error.addSourceMessage(Error.UNFILLED_SLOT, {sname}, info); -// fail(); -// end if; -// -// outslots := SLOT(sname, SOME((expMatched, tyMatched, vrActual)), sdefault, sexpected, sisFilled)::outslots; -// -// end for; -// -// outslots := listReverse(outslots); -//end typeCheckFunctionSlots; -// -//function vectorizeTypeCheckFunctionSlots -// input list slots; -// input Absyn.Path fn; -// input Prefix prefix; -// input SourceInfo info; -// input list vectDims; -// output list outslots; -//algorithm -//protected -// String str1, str2, s1, s2, s3, s4, s5; -// Boolean b, found = false; -// String sname "the name of the slot"; -// Option> sarg "the argument given by the function call"; -// Binding sdefault "the default value from binding of the input component in the function"; -// Option> sexpected "the actual type of the input component, what we expect to get"; -// Boolean sisFilled, compatible; -// Expression expActual, expMatched; -// DAE.Const vrActual, vrExpected; -// Type tyActual, tyExpected, tyMatched, ty1,ty2; -// Dimension dim; -// list dims1,dims2; -// Integer position = 0; -// -//algorithm -// outslots := {}; -// -// for s in slots loop -// position := position + 1; -// SLOT(sname, sarg, sdefault, sexpected, sisFilled) := s; -// -// // slot is filled -// if sisFilled then -// SOME((expActual, tyActual, vrActual)) := sarg; -// SOME((tyExpected, vrExpected)) := sexpected; -// -// // fail if the variability is wrong -// if not Types.constEqualOrHigher(vrActual, vrExpected) then -// str1 := Expression.toString(expActual); -// str2 := DAEUtil.constStrFriendly(vrExpected); -// Error.addSourceMessageAndFail(Error.FUNCTION_SLOT_VARIABILITY, {sname, str1, str2}, info); -// end if; -// -// // check the typing -// (expMatched, tyMatched, compatible) := TypeCheck.matchTypes(tyActual, tyExpected, expActual, false); -// // If the original argument is type compatible then it needs to be repeated -// // for each call. Create an array of it. -// if compatible then -// dims1 := listReverse(vectDims); -// for vdim in dims1 loop -// tyMatched := Type.liftArrayLeft(tyMatched,vdim); -// expMatched := Expression.ARRAY(tyMatched,List.fill(expMatched, Dimension.size(vdim))); -// end for; -// // If it is not compatible see if it is a dimension issue. -// // We can still have actual type mismathc here because we try vectorization -// // immidiately when we have dim mistmatch in normal mode. There might be unchecked -// // args. -// else -// ty1 := Type.elementType(tyActual); -// ty2 := Type.elementType(tyExpected); -// (expMatched, tyMatched, compatible) := TypeCheck.matchTypes(ty1, ty2, expActual, false); -// // if even the element types are different then fail. -// if not compatible then -// s1 := intString(position); -// s2 := Absyn.pathStringNoQual(fn); -// s3 := Expression.toString(expActual); -// s4 := Type.toString(tyActual); -// s5 := Type.toString(tyExpected); -// Error.addSourceMessage(Error.ARG_TYPE_MISMATCH, {s1,s2,sname,s3,s4,s5}, info); -// fail(); -// // if the element types are the same then lift the expected argument with the -// // vectorization dim and mathc it again. If this passes then vectorization is possible -// // for this argument. -// else -// ty2 := Type.liftArrayLeftList(tyExpected,vectDims); -// dims2 := Type.getTypeDims(ty2); -// dims1 := Type.getTypeDims(tyActual); -// if Dimension.allEqual(dims1,dims2) then -// (expMatched, tyMatched, compatible) := TypeCheck.matchTypes(tyActual, ty2, expActual, false); -// else -// fail(); -// end if; -// end if; -// end if; -// -// // Argument is not given but there is a default value. -// // Create an array of the default value for each call. -// elseif Binding.isBound(sdefault) then -// Binding.TYPED_BINDING(expMatched, tyMatched, vrActual) := sdefault; -// dims1 := listReverse(vectDims); -// for vdim in dims1 loop -// tyMatched := Type.liftArrayLeft(tyMatched,vdim); -// expMatched := Expression.ARRAY(tyMatched,List.fill(expMatched, Dimension.size(vdim))); -// end for; -// // No argument give and no default value. -// else -// Error.addSourceMessage(Error.UNFILLED_SLOT, {sname}, info); -// fail(); -// end if; -// -// outslots := SLOT(sname, SOME((expMatched, tyMatched, vrActual)), sdefault, sexpected, sisFilled)::outslots; -// -// end for; -// -// outslots := listReverse(outslots); -//end vectorizeTypeCheckFunctionSlots; -// -//function vectorizeCall -// input Absyn.Path inFnName; -// input InstNode classNode; -// input Prefix prefix; -// input list inArgs; -// input CallAttributes inAttrs; -// input list vecDims; -// output list outCalls; -//protected -// list> vectsubs; -// list> vecargslst; -//algorithm -// -// // Create combinations of each dims subs, i.e., expand an array[dims] -// vectsubs := vectorizeDims(vecDims); -// -// // Apply the set of subs to each argument, i.e., expand each arg. -// vecargslst := {}; -// for currsubs in vectsubs loop -// vecargslst := list(Expression.subscript(arg, currsubs) for arg in inArgs)::vecargslst; -// end for; -// -// -// outCalls := {}; -// for args in vecargslst loop -// outCalls := Expression.CALL(inFnName, Expression.CREF(classNode, prefix), args, inAttrs)::outCalls; -// end for; -// -// /* -// for dim in vecDims loop -// for idx in 1:dimSize -// vargs := {}; -// for arg in args loop -// vargs := Expression.subscriptExp(arg,{DAE.INDEX(idx)})::vargs -// end for; -// vargs := listReverse(vargs); -// vargslist := vargslist::vargs; -// vcalls := Expression.CALL(fn, vargs, ca)::vcalls; -// end for; -// vcalls := listReverse(vcalls); -// end for; -// */ -//end vectorizeCall; -// -//function vectorizeDims -// "This should go either in NFDimension or NFSubscript." -// input list vecDims; -// output list> vectsubs; -//protected -// list dimsizes; -// list subs; -// list> subslstlst; -//algorithm -// -// // Get the size of each vectorization dim -// dimsizes := list(Dimension.size(d) for d in vecDims); -// -// // Expand each dim to subscripts -// subslstlst := {}; -// for dimsize in dimsizes loop -// subslstlst := list(Subscript.INDEX(Expression.INTEGER(i)) for i in 1:dimsize)::subslstlst; -// end for; -// subslstlst := listReverse(subslstlst); -// -// // Create combinations of each dims subs, i.e., expand an array[dims] -// vectsubs := List.combination(subslstlst); -//end vectorizeDims; -// -//public function findVectorizationDim -//"@mahge: -//TODO: rewirite me -//This function basically finds the diff between two dims. The resulting dimension -//is used for vectorizing calls. -// -//e.g. dim1=[2,3,4,2] dim2=[4,2], findVectorizationDim(dim1,dim2) => [2,3] -// dim1=[2,3,4,2] dim2=[3,4,2], findVectorizationDim(dim1,dim2) => [2] -// dim1=[2,3,4,2] dim2=[4,3], fail -//" -// input list inGivenDims; -// input list inExpectedDims; -// output list outVectDims; -//algorithm -// outVectDims := matchcontinue(inGivenDims, inExpectedDims) -// local -// list dims1; -// Dimension dim1; -// -// case(_, {}) then inGivenDims; -// -// case(_, _) -// equation -// true = Dimension.allEqual(inGivenDims, inExpectedDims); -// then -// {}; -// -// case(dim1::dims1, _) -// equation -// true = listLength(inGivenDims) > listLength(inExpectedDims); -// dims1 = findVectorizationDim(dims1,inExpectedDims); -// then -// dim1::dims1; -// -// case(_::_, _) -// equation -// assert(false, getInstanceName() + " failed."); -// /* with dimensions: [" + -// ExpressionDump.printListStr(inGivenDims,ExpressionDump.dimensionString,",") + "] vs [" + -// ExpressionDump.printListStr(inExpectedDims,ExpressionDump.dimensionString,",") + "]."); -// */ -// then -// fail(); -// -// end matchcontinue; -// -//end findVectorizationDim; -// -//protected function isSpecialBuiltinFunctionName -//"@author: adrpo -// check if the name is special builtin function or -// operator which does not have a definition in ModelicaBuiltin.mo -// TODO FIXME, add all of them" -// input Absyn.ComponentRef functionName; -// output Boolean isBuiltinFname; -//algorithm -// isBuiltinFname := matchcontinue(functionName) -// local -// String name; -// Boolean b, b1, b2; -// Absyn.ComponentRef fname; -// -// case (Absyn.CREF_FULLYQUALIFIED(fname)) -// then -// isSpecialBuiltinFunctionName(fname); -// -// case (Absyn.CREF_IDENT(name, {})) -// equation -// b1 = listMember(name, {"String", "Integer"}); -// // these are the new Modelica 3.3 synch operators -// b2 = if intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// then -// listMember(name, {"Clock", "previous", "hold", "subSample", "superSample", "shiftSample", -// "backSample", "noClock", "transition", "initialState", "activeState", -// "ticksInState", "timeInState"}) -// else false; -// b = boolOr(b1, b2); -// then -// b; -// -// case (_) then false; -// end matchcontinue; -//end isSpecialBuiltinFunctionName; -// -//protected function isBuiltinFunctionName -//"@author: adrpo -// check if the name is a builtin function or operator -// TODO FIXME, add all of them" -// input Absyn.ComponentRef functionName; -// output Boolean isBuiltinFname; -//algorithm -// isBuiltinFname := matchcontinue(functionName) -// local -// String name; -// Boolean b; -// Absyn.ComponentRef fname; -// -// case (Absyn.CREF_FULLYQUALIFIED(fname)) -// then -// isBuiltinFunctionName(fname); -// -// case (Absyn.CREF_IDENT(name, {})) -// equation -// b = listMember(name, -// { -// "noEvent", -// "smooth", -// "sample", -// "pre", -// "edge", -// "change", -// "reinit", -// "size", -// "rooted", -// "transpose", -// "skew", -// "identity", -// "min", -// "max", -// "cross", -// "diagonal", -// "abs", -// "sum", -// "product", -// "assert", -// "array", -// "cat", -// "rem", -// "actualStream", -// "inStream", -// // TODO Clock -// "previous", -// "hold", -// "subSample", -// "superSample", -// // TODO sample, shiftSample, backSample, noClock -// "initialState", -// "transition", -// "activeState", -// "ticksInState", -// "timeInState" -// }); -// then -// b; -// -// case (_) then false; -// end matchcontinue; -//end isBuiltinFunctionName; -// -//// adrpo: -//// - see Static.mo for how to check the input arguments or any other checks we need that should be ported -//// - try to use Expression.makePureBuiltinCall everywhere instead of creating the typedExp via DAE.CALL -//// - this function should handle special builtin operators which are not defined in ModelicaBuiltin.mo -//protected function typeSpecialBuiltinFunctionCall -//"@author: adrpo -// handle all builtin calls that are not defined at all in ModelicaBuiltin.mo -// TODO FIXME, add all" -// input Absyn.ComponentRef functionName; -// input Absyn.FunctionArgs functionArgs; -// input Prefix prefix; -// input InstNode classNode; -// input InstNode scope; -// input SourceInfo info; -// output Expression typedExp; -// output Type ty; -// output DAE.Const variability; -//protected -// String fnName; -// DAE.Const vr, vr1, vr2; -//algorithm -// (typedExp, ty, variability) := match(functionName, functionArgs) -// local -// Absyn.ComponentRef acref; -// Absyn.Exp aexp1, aexp2; -// Expression dexp1, dexp2; -// list afargs; -// list anamed_args; -// Absyn.Path call_path; -// list pos_args, args; -// list> named_args; -// list inputs, outputs; -// Absyn.ForIterators iters; -// DAE.Dimensions d1, d2; -// Type el_ty; -// list tys; -// list vrs; -// -// // TODO FIXME: String might be overloaded, we need to handle this better! See Static.mo -// case (Absyn.CREF_IDENT(name = "String"), Absyn.FUNCTIONARGS(args = afargs)) -// algorithm -// call_path := Absyn.crefToPath(functionName); -// (args,_, vrs) := Typing.typeExps(afargs, scope, info); -// vr := List.fold(vrs, Types.constAnd, DAE.C_CONST()); -// ty := Type.STRING(); -// then -// (Expression.CALL(call_path, Expression.CREF(classNode, prefix), args, NFExpression.callAttrBuiltinOther), ty, vr); -// -// // TODO FIXME: check that the input is an enumeration -// case (Absyn.CREF_IDENT(name = "Integer"), Absyn.FUNCTIONARGS(args = afargs)) -// algorithm -// call_path := Absyn.crefToPath(functionName); -// (args,_, vrs) := Typing.typeExps(afargs, scope, info); -// vr := List.fold(vrs, Types.constAnd, DAE.C_CONST()); -// ty := Type.INTEGER(); -// then -// (Expression.CALL(call_path, Expression.CREF(classNode, prefix), args, NFExpression.callAttrBuiltinOther), ty, vr); -// -// // TODO FIXME! handle all the Modelica 3.3 operators here, see isSpecialBuiltinFunctionName -// -// end match; -//end typeSpecialBuiltinFunctionCall; -// -// -//// adrpo: -//// - see Static.mo for how to check the input arguments or any other checks we need that should be ported -//// - try to use Expression.makePureBuiltinCall everywhere instead of creating the typedExp via DAE.CALL -//// - all the functions that are defined *with no input/output type* in ModelicaBuiltin.mo such as: -//// function NAME "Transpose a matrix" -//// external "builtin"; -//// end NAME; -//// need to be handled here! -//// - the functions which have a type in the ModelicaBuiltin.mo should be handled by the last case in this function -//protected function typeBuiltinFunctionCall -//"@author: adrpo -// handle all builtin calls that are not in ModelicaBuiltin.mo -// TODO FIXME, add all" -// input Absyn.ComponentRef functionName; -// input Absyn.FunctionArgs functionArgs; -// input Prefix prefix; -// input InstNode classNode; -// input Type classType; -// input SCode.Element cls; -// input InstNode scope; -// input SourceInfo info; -// output Expression typedExp; -// output Type ty; -// output DAE.Const variability; -//protected -// String fnName; -// DAE.Const vr, vr1, vr2; -//algorithm -// (typedExp, ty, variability) := matchcontinue(functionName, functionArgs) -// local -// Absyn.ComponentRef acref; -// Absyn.Exp aexp1, aexp2; -// Expression dexp1, dexp2; -// list afargs; -// list anamed_args; -// Absyn.Path call_path; -// list pos_args, args; -// list> named_args; -// list inputs, outputs; -// Absyn.ForIterators iters; -// Dimension d1, d2; -// Type el_ty, ty1, ty2; -// -// // size(arr, dim) -// case (Absyn.CREF_IDENT(name = "size"), Absyn.FUNCTIONARGS(args = {aexp1, aexp2})) -// algorithm -// (dexp1,_, vr1) := Typing.typeExp(aexp1, scope, info); -// (dexp2,_, vr2) := Typing.typeExp(aexp2, scope, info); -// -// // TODO FIXME: calculate the correct type and the correct variability, see Static.elabBuiltinSize in Static.mo -// ty := Type.INTEGER(); -// // the variability does not actually depend on the variability of "arr" but on the variability of the dimensions of "arr" -// vr := Types.constAnd(vr1, vr2); -// then -// (Expression.SIZE(dexp1, SOME(dexp2)), ty, vr); -// -// // size(arr) -// case (Absyn.CREF_IDENT(name = "size"), Absyn.FUNCTIONARGS(args = {aexp1})) -// algorithm -// (dexp1,_, vr1) := Typing.typeExp(aexp1, scope, info); -// // TODO FIXME: calculate the correct type and the correct variability, see Static.elabBuiltinSize in Static.mo -// ty := Type.INTEGER(); -// // the variability does not actually depend on the variability of "arr" but on the variability of the dimensions of "arr" -// vr := vr1; -// then -// (Expression.SIZE(dexp1, NONE()), ty, vr); -// -// case (Absyn.CREF_IDENT(name = "smooth"), Absyn.FUNCTIONARGS(args = {aexp1, aexp2})) -// algorithm -// call_path := Absyn.crefToPath(functionName); -// (dexp1,_, vr1) := Typing.typeExp(aexp1, scope, info); -// (dexp2,_, vr2) := Typing.typeExp(aexp2, scope, info); -// -// // TODO FIXME: calculate the correct type and the correct variability, see Static.mo -// ty := Type.REAL(); -// vr := vr1; -// then -// (Expression.CALL(call_path, Expression.CREF(classNode, prefix), {dexp1,dexp2}, NFExpression.callAttrBuiltinOther), ty, vr); -// -// case (Absyn.CREF_IDENT(name = "rooted"), Absyn.FUNCTIONARGS(args = {aexp1})) -// algorithm -// call_path := Absyn.crefToPath(functionName); -// (dexp1,_, vr1) := Typing.typeExp(aexp1, scope, info); -// -// // TODO FIXME: calculate the correct type and the correct variability, see Static.mo -// ty := Type.BOOLEAN(); -// vr := vr1; -// then -// (Expression.CALL(call_path, Expression.CREF(classNode, prefix), {dexp1}, NFExpression.callAttrBuiltinOther), ty, vr); -// -// case (Absyn.CREF_IDENT(name = "transpose"), Absyn.FUNCTIONARGS(args = {aexp1})) -// algorithm -// (dexp1, ty1, vr1) := Typing.typeExp(aexp1, scope, info); -// -// // transpose the type. -// Type.ARRAY(elementType = el_ty, dimensions = {d1, d2}) := ty1; -// ty := Type.ARRAY(el_ty, {d2, d1}); -// -// // create the typed transpose expression -// typedExp := Expression.makePureBuiltinCall("transpose", Expression.CREF(classNode, prefix), {dexp1}, ty); -// vr := vr1; -// then -// (typedExp, ty, vr); -// -// // min|max(arr) -// case (Absyn.CREF_IDENT(name = fnName), Absyn.FUNCTIONARGS(args = {aexp1})) -// algorithm -// true := listMember(fnName, {"min", "max"}); -// (dexp1, ty1, vr1) := Typing.typeExp(aexp1, scope, info); -// -// true := Type.isArray(ty1); -// //dexp1 := Expression.matrixToArray(dexp1); -// el_ty := Type.arrayElementType(ty1); -// false := Type.isString(el_ty); -// -// ty := el_ty; -// vr := vr1; -// typedExp := Expression.makePureBuiltinCall(fnName, Expression.CREF(classNode, prefix), {dexp1}, ty); -// then -// (typedExp, ty, vr); -// -// // min|max(x,y) where x & y are scalars. -// case (Absyn.CREF_IDENT(name = fnName), Absyn.FUNCTIONARGS(args = {aexp1, aexp2})) -// algorithm -// true := listMember(fnName, {"min", "max"}); -// (dexp1, ty1, vr1) := Typing.typeExp(aexp1, scope, info); -// (dexp2, ty2, vr2) := Typing.typeExp(aexp2, scope, info); -// -// ty := Type.scalarSuperType(ty1, ty2); -// //(dexp1, _) := Types.matchType(dexp1, ty1, ty, true); -// //(dexp2, _) := Types.matchType(dexp2, ty2, ty, true); -// vr := Types.constAnd(vr1, vr2); -// false := Type.isString(ty); -// typedExp := Expression.makePureBuiltinCall(fnName, Expression.CREF(classNode, prefix), {dexp1, dexp2}, ty); -// then -// (typedExp, ty, vr); -// -// case (Absyn.CREF_IDENT(name = "diagonal"), Absyn.FUNCTIONARGS(args = aexp1::_)) -// algorithm -// (dexp1, ty1, vr1) := Typing.typeExp(aexp1, scope, info); -// Type.ARRAY(elementType = el_ty, dimensions = {d1}) := ty1; -// ty := Type.ARRAY(el_ty, {d1, d1}); -// typedExp := Expression.makePureBuiltinCall("diagonal", Expression.CREF(classNode, prefix), {dexp1}, ty); -// vr := vr1; -// then -// (typedExp, ty, vr); -// -// case (Absyn.CREF_IDENT(name = "pre"), Absyn.FUNCTIONARGS(args = {aexp1})) -// algorithm -// (dexp1, ty, vr) := Typing.typeExp(aexp1, scope, info); -// -// // create the typed call -// typedExp := Expression.makePureBuiltinCall("pre", Expression.CREF(classNode, prefix), {dexp1}, ty); -// then -// (typedExp, ty, vr); -// -// case (Absyn.CREF_IDENT(name = "previous"), Absyn.FUNCTIONARGS(args = {aexp1})) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// algorithm -// // TODO? Check that aexp1 is a Component Expression (MLS 3.3, Section 16.2.3) or parameter expression -// (dexp1, ty, vr) := Typing.typeExp(aexp1, scope, info); -// // create the typed call -// typedExp := Expression.makeBuiltinCall("previous", Expression.CREF(classNode, prefix), {dexp1}, ty, true); -// then -// (typedExp, ty, vr); -// -// case (Absyn.CREF_IDENT(name = "hold"), Absyn.FUNCTIONARGS(args = {aexp1})) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// algorithm -// // TODO? Check that aexp1 is a Component Expression (MLS 3.3, Section 16.2.3) or parameter expression -// (dexp1, ty, vr) := Typing.typeExp(aexp1, scope, info); -// // create the typed call -// typedExp := Expression.makeBuiltinCall("hold", Expression.CREF(classNode, prefix), {dexp1}, ty, true); -// then -// (typedExp, ty, vr); -// -// // subSample(u)/superSample(u), subSample(u, factor)/superSample(u, factor) -// case (Absyn.CREF_IDENT(name = fnName), Absyn.FUNCTIONARGS(args = afargs)) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) and -// listMember(fnName, {"subSample", "superSample"}) and -// (listLength(afargs) == 1 or listLength(afargs) == 2) -// algorithm -// if listLength(afargs) == 1 then -// aexp1 := listHead(afargs); -// // Create default argument factor=0 -// dexp2 := Expression.INTEGER(0); -// else -// {aexp1, aexp2} := afargs; -// (dexp2, ty2, vr2) := Typing.typeExp(aexp2, scope, info); -// Type.INTEGER() := ty2; -// // TODO FIXME check if vr2 is a parameter expressions -// // TODO FIXME (evaluate) and check if factor >= 0 -// end if; -// (dexp1, ty, vr) := Typing.typeExp(aexp1, scope, info); -// -// // create the typed call -// typedExp := Expression.makeBuiltinCall(fnName, Expression.CREF(classNode, prefix), {dexp1, dexp2}, ty, true); -// then -// (typedExp, ty, vr); -// -// // initialState(state) -// case (Absyn.CREF_IDENT(name = "initialState"), Absyn.FUNCTIONARGS(args = {aexp1})) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// algorithm -// (dexp1, ty1, vr) := Typing.typeExp(aexp1, scope, info); -// -// // MLS 3.3 requires a 'block' instance as argument aexp1. -// // Checking here for 'complex' types is too broad, but convenient -// Error.assertionOrAddSourceMessage(Type.isComplex(ty1),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"initialState(" + Expression.toString(dexp1) + "), Argument needs to be a block instance.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// ty := Type.NORETCALL(); -// -// // create the typed call -// typedExp := Expression.makeBuiltinCall("initialState", Expression.CREF(classNode, prefix), {dexp1}, ty, true); -// then -// (typedExp, ty, vr); -// -// // transition(from, to, condition, immediate=true, reset=true, synchronize=false, priority=1) -// case (Absyn.CREF_IDENT(name = "transition"), _) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// then -// elabBuiltinTransition(functionName, functionArgs, prefix, classNode, classType, cls, scope, info); -// -// // activeState(state) -// case (Absyn.CREF_IDENT(name = "activeState"), Absyn.FUNCTIONARGS(args = {aexp1})) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// algorithm -// (dexp1, ty1, vr) := Typing.typeExp(aexp1, scope, info); -// -// // MLS 3.3 requires a 'block' instance as argument aexp1. -// // Checking here for 'complex' types is too broad, but convenient -// Error.assertionOrAddSourceMessage(Type.isComplex(ty1),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"activeState(" + Expression.toString(dexp1) + "), Argument needs to be a block instance.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// ty := Type.BOOLEAN(); -// -// // create the typed call -// typedExp := Expression.makeBuiltinCall("activeState", Expression.CREF(classNode, prefix), {dexp1}, ty, true); -// then -// (typedExp, ty, vr); -// -// // ticksInState() -// case (Absyn.CREF_IDENT(name = "ticksInState"), Absyn.FUNCTIONARGS(args = {})) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// algorithm -// ty := Type.INTEGER(); -// vr := DAE.C_VAR(); -// // create the typed call -// typedExp := Expression.makeBuiltinCall("ticksInState", Expression.CREF(classNode, prefix), {}, ty, true); -// then -// (typedExp, ty, vr); -// -// // timeInState() -// case (Absyn.CREF_IDENT(name = "timeInState"), Absyn.FUNCTIONARGS(args = {})) -// guard intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) -// algorithm -// ty := Type.REAL(); -// vr := DAE.C_VAR(); -// // create the typed call -// typedExp := Expression.makeBuiltinCall("timeInState", Expression.CREF(classNode, prefix), {}, ty, true); -// then -// (typedExp, ty, vr); -// -// -// -// /* adrpo: adapt these to the new structures, see above -// case (Absyn.CREF_IDENT(name = "product"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "pre"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "noEvent"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "sum"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "assert"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "change"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "array"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "array"), Absyn.FOR_ITER_FARG(exp=aexp1, iterators=iters)) -// equation -// call_path = Absyn.crefToPath(functionName); -// env = NFSCodeEnv.extendEnvWithIterators(iters, System.tmpTickIndex(NFSCodeEnv.tmpTickIndex), inEnv); -// (dexp1, globals) = Typing.typeExp(aexp1, env, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, {dexp1}, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "sum"), Absyn.FOR_ITER_FARG(exp=aexp1, iterators=iters)) -// equation -// call_path = Absyn.crefToPath(functionName); -// env = NFSCodeEnv.extendEnvWithIterators(iters, System.tmpTickIndex(NFSCodeEnv.tmpTickIndex), inEnv); -// (dexp1, globals) = Typing.typeExp(aexp1, env, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, {dexp1}, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "min"), Absyn.FOR_ITER_FARG(exp=aexp1, iterators=iters)) -// equation -// call_path = Absyn.crefToPath(functionName); -// env = NFSCodeEnv.extendEnvWithIterators(iters, System.tmpTickIndex(NFSCodeEnv.tmpTickIndex), inEnv); -// (dexp1, globals) = Typing.typeExp(aexp1, env, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, {dexp1}, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "max"), Absyn.FOR_ITER_FARG(exp=aexp1, iterators=iters)) -// equation -// call_path = Absyn.crefToPath(functionName); -// env = NFSCodeEnv.extendEnvWithIterators(iters, System.tmpTickIndex(NFSCodeEnv.tmpTickIndex), inEnv); -// (dexp1, globals) = Typing.typeExp(aexp1, env, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, {dexp1}, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "product"), Absyn.FOR_ITER_FARG(exp=aexp1, iterators=iters)) -// equation -// call_path = Absyn.crefToPath(functionName); -// env = NFSCodeEnv.extendEnvWithIterators(iters, System.tmpTickIndex(NFSCodeEnv.tmpTickIndex), inEnv); -// (dexp1, globals) = Typing.typeExp(aexp1, env, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, {dexp1}, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "cat"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "actualStream"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "inStream"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "String"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "Integer"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "Real"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// */ -// -// // TODO! FIXME! -// // check if more functions need to be handled here -// // we also need to handle Absyn.FOR_ITER_FARG reductions instead of Absyn.FUNCTIONARGS -// -// /* -// // adrpo: no support for $overload functions yet: div, mod, rem, abs, i.e. ModelicaBuiltin.mo: -// // function mod = $overload(OpenModelica.Internal.intMod,OpenModelica.Internal.realMod) -// case (Absyn.CREF_IDENT(name = "rem"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// -// case (Absyn.CREF_IDENT(name = "abs"), Absyn.FUNCTIONARGS(args = afargs)) -// equation -// call_path = Absyn.crefToPath(functionName); -// (pos_args, globals) = Typing.typeExps(afargs, inEnv, inPrefix, inInfo, globals); -// then -// DAE.CALL(call_path, pos_args, NFExpression.callAttrBuiltinOther); -// */ -// -// // hopefully all the other ones have a complete entry in ModelicaBuiltin.mo -// case (_, _) -// algorithm -// (typedExp, ty, vr) := typeNormalFunction(functionName, functionArgs, prefix, classNode, classType, scope, info); -// then -// (typedExp, ty, vr); -// -// end matchcontinue; -//end typeBuiltinFunctionCall; -// -// -//protected function elabBuiltinTransition -//"elaborate the builtin operator -// transition(from, to, condition, immediate=true, reset=true, synchronize=false, priority=1)" -// input Absyn.ComponentRef functionName; -// input Absyn.FunctionArgs functionArgs; -// input Prefix prefix; -// input InstNode classNode; -// input Type classType; -// input SCode.Element cls; -// input InstNode scope; -// input SourceInfo info; -// output Expression typedExp; -// output Type ty; -// output DAE.Const variability; -//protected -// list afargs; -// list anamed_args; -// Absyn.Ident argName; -// Absyn.Exp argValue; -// array argExps = listArray({Absyn.STRING("from_NoDefault"), Absyn.STRING("to_NoDefault"), Absyn.STRING("condition_NoDefault"), Absyn.BOOL(true), Absyn.BOOL(true), Absyn.BOOL(false), Absyn.INTEGER(1)}); -// array afargsArray; -// Expression dexp1, dexp2, dexp3, dexp4, dexp5, dexp6, dexp7; -// Type ty1, ty2, ty3, ty4, ty5, ty6, ty7; -// DAE.Const vr1, vr2, vr3, vr4, vr5, vr6, vr7; -// String str; -// Integer afargsLen; -//algorithm -// Absyn.FUNCTIONARGS(args=afargs, argNames=anamed_args) := functionArgs; -// afargsArray := listArray(afargs); -// afargsLen := listLength(afargs); -// -// for i in 1:afargsLen loop -// argExps := arrayUpdate(argExps, i, arrayGet(afargsArray,i)); -// end for; -// -// for anamed in anamed_args loop -// Absyn.NAMEDARG(argName, argValue) := anamed; -// if argName == "from" and afargsLen < 1 then arrayUpdate(argExps, 1, argValue); -// elseif argName == "to" and afargsLen < 2 then arrayUpdate(argExps, 2, argValue); -// elseif argName == "condition" and afargsLen < 3 then arrayUpdate(argExps, 3, argValue); -// elseif argName == "immediate" and afargsLen < 4 then arrayUpdate(argExps, 4, argValue); -// elseif argName == "reset" and afargsLen < 5 then arrayUpdate(argExps, 5, argValue); -// elseif argName == "synchronize" and afargsLen < 6 then arrayUpdate(argExps, 6, argValue); -// elseif argName == "priority" and afargsLen < 7 then arrayUpdate(argExps, 7, argValue); -// else -// Error.addSourceMessageAndFail(Error.NO_SUCH_ARGUMENT, -// {"transition(" + argName + "=" + Dump.dumpExpStr(argValue) + "), no such argument or conflict with unnamed arguments", -// Absyn.pathString(InstNode.path(scope))}, info); -// end if; -// end for; -// -// // check if first 3 mandatory arguments have been provided -// for i in 1:3 loop -// () := match arrayGet(argExps, i) -// case Absyn.STRING(str) -// algorithm -// Error.addSourceMessageAndFail(Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(from, to, condition, immediate=true, reset=true, synchronize=false, priority=1), missing " + intString(i) + ". argument", -// Absyn.pathString(InstNode.path(scope))}, info); -// then fail(); -// else then (); -// end match; -// end for; -// -// (dexp1, ty1, vr1) := Typing.typeExp(arrayGet(argExps,1), scope, info); -// (dexp2, ty2, vr2) := Typing.typeExp(arrayGet(argExps,2), scope, info); -// // MLS 3.3 requires a 'block' instances as argument 1 and 2. -// // Checking here for 'complex' types is too broad, but convenient -// Error.assertionOrAddSourceMessage(Type.isComplex(ty1),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(" + Expression.toString(dexp1) + ", ...), Argument needs to be a block instance.", -// Absyn.pathString(InstNode.path(scope))}, info); -// Error.assertionOrAddSourceMessage(Type.isComplex(ty2),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(..., " + Expression.toString(dexp2) + ", ...), Argument needs to be a block instance.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// // TODO check that variability of arguments below are parameter or constant -// -// (dexp3, ty3, vr3) := Typing.typeExp(arrayGet(argExps,3), scope, info); -// Error.assertionOrAddSourceMessage(Type.isBoolean(ty3),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(..., " + Expression.toString(dexp3) + ", ...), Argument needs to be of type Boolean.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// (dexp4, ty4, vr4) := Typing.typeExp(arrayGet(argExps,4), scope, info); -// Error.assertionOrAddSourceMessage(Type.isBoolean(ty4),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(..., " + Expression.toString(dexp4) + ", ...), Argument needs to be of type Boolean.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// // Error.assertionOrAddSourceMessage(Types.isParameterOrConstant(vr4),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// // {"transition(..., " + Expression.toString(dexp4) + ", ...), Argument needs to be of type Boolean.", -// // Absyn.pathString(InstNode.path(scope))}, info); -// -// (dexp5, ty5, vr5) := Typing.typeExp(arrayGet(argExps,5), scope, info); -// Error.assertionOrAddSourceMessage(Type.isBoolean(ty5),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(..., " + Expression.toString(dexp5) + ", ...), Argument needs to be of type Boolean.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// (dexp6, ty6, vr6) := Typing.typeExp(arrayGet(argExps,6), scope, info); -// Error.assertionOrAddSourceMessage(Type.isBoolean(ty6),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(..., " + Expression.toString(dexp6) + ", ...), Argument needs to be of type Boolean.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// (dexp7, ty7, vr7) := Typing.typeExp(arrayGet(argExps,7), scope, info); -// // TODO check that "priority" argument is >= 1 -// Error.assertionOrAddSourceMessage(Type.isInteger(ty7),Error.WRONG_TYPE_OR_NO_OF_ARGS, -// {"transition(..., " + Expression.toString(dexp7) + ", ...), Argument needs to be of type Integer.", -// Absyn.pathString(InstNode.path(scope))}, info); -// -// -// ty := Type.NORETCALL(); -// // create the typed call -// typedExp := Expression.makeBuiltinCall("transition", Expression.CREF(classNode, prefix), {dexp1, dexp2, dexp3, dexp4, dexp5, dexp6, dexp7}, ty, true); -// variability := DAE.C_UNKNOWN(); -//end elabBuiltinTransition; -// -// -//function isBuiltinFunc -// input Absyn.Path funcName; -// input DAE.FunctionAttributes funcAttr; -// output DAE.FunctionBuiltin builtin; -// output Boolean isBuiltin; -// output Absyn.Path newName; -//algorithm -// (builtin, isBuiltin, newName) := matchcontinue (funcName, funcAttr) -// local -// String id; -// -// case (_, DAE.FUNCTION_ATTRIBUTES(isBuiltin = builtin as DAE.FUNCTION_BUILTIN())) -// then (builtin, true, Absyn.makeNotFullyQualified(funcName)); -// -// case (_, DAE.FUNCTION_ATTRIBUTES(isBuiltin = builtin as DAE.FUNCTION_BUILTIN_PTR())) -// then (builtin, true, Absyn.makeNotFullyQualified(funcName)); -// -// case (Absyn.IDENT(name = id), _) -// algorithm -// Static.elabBuiltinHandler(id); -// then -// (DAE.FUNCTION_BUILTIN(SOME(id), false), true, funcName); -// -// case (Absyn.QUALIFIED("OpenModelicaInternal", Absyn.IDENT(name = id)), _) -// algorithm -// Static.elabBuiltinHandlerInternal(id); -// then -// (DAE.FUNCTION_BUILTIN(SOME(id), false), true, funcName); -// -// case (Absyn.FULLYQUALIFIED(), _) -// algorithm -// (builtin, isBuiltin, _) := isBuiltinFunc(funcName.path, funcAttr); -// then -// (builtin, isBuiltin, funcName.path); -// -// case (Absyn.QUALIFIED("Connection", Absyn.IDENT("isRoot")), _) -// then (DAE.FUNCTION_BUILTIN(NONE(), false), true, funcName); -// -// else (DAE.FUNCTION_NOT_BUILTIN(), false, funcName); -// end matchcontinue; -//end isBuiltinFunc; - -annotation(__OpenModelica_Interface="frontend"); -end NFFunc; diff --git a/Compiler/NFFrontEnd/NFFunction.mo b/Compiler/NFFrontEnd/NFFunction.mo index 00a16204246..6ffd658c887 100644 --- a/Compiler/NFFrontEnd/NFFunction.mo +++ b/Compiler/NFFrontEnd/NFFunction.mo @@ -60,8 +60,8 @@ import MatchKind = NFTypeCheck.MatchKind; public type NamedArg = tuple; -type TypedArg = tuple; -type TypedNamedArg = tuple; +type TypedArg = tuple; +type TypedNamedArg = tuple; public type SlotType = enumeration( @@ -484,7 +484,7 @@ uniontype Function String argName; Type ty; Expression argExp; - DAE.Const var; + DAE.VarKind var; algorithm // Try to find a slot and fill it with the argument expression. for i in 1:arrayLength(slots) loop @@ -552,7 +552,7 @@ uniontype Function args := match (default, arg) case (_, SOME(a)) then a :: args; // Use the argument from the call if one was given. // TODO: save this info in the defaults in slots (the type we can get from the exp manually but the variability is lost.). - case (SOME(e), _) then (e,Expression.typeOf(e),DAE.C_CONST()) ::args; // Otherwise, check that a default value exists. + case (SOME(e), _) then (e,Expression.typeOf(e),DAE.VarKind.CONST()) ::args; // Otherwise, check that a default value exists. else // Give an error if no argument was given and there's no default value. algorithm if isSome(info) then @@ -580,7 +580,7 @@ uniontype Function list inputs; Expression argexp, margexp; Type ty, mty; - DAE.Const var; + DAE.VarKind var; list checked_args; Integer idx; TypeCheck.MatchKind matchKind; @@ -613,7 +613,7 @@ uniontype Function return; end if; - correct := TypeCheck.checkConstVariability(var, Component.variability(comp)); + correct := TypeCheck.matchVariability(var, Component.variability(comp)); // Variability mismatch, print an error. if not correct then diff --git a/Compiler/NFFrontEnd/NFInst.mo b/Compiler/NFFrontEnd/NFInst.mo index 7832ce4a41a..6ce8e1aa3e9 100644 --- a/Compiler/NFFrontEnd/NFInst.mo +++ b/Compiler/NFFrontEnd/NFInst.mo @@ -604,8 +604,8 @@ algorithm case CachedData.NO_CACHE() algorithm inst := instantiate(node); - instExpressions(inst); InstNode.setCachedData(CachedData.PACKAGE(inst), node); + instExpressions(inst); then inst; diff --git a/Compiler/NFFrontEnd/NFInstNode.mo b/Compiler/NFFrontEnd/NFInstNode.mo index f221b4c67f1..806451e1637 100644 --- a/Compiler/NFFrontEnd/NFInstNode.mo +++ b/Compiler/NFFrontEnd/NFInstNode.mo @@ -521,11 +521,20 @@ uniontype InstNode output Type ty; algorithm ty := match node - case CLASS_NODE() then - if Class.isBuiltin(Pointer.access(node.cls)) then - Class.getType(Pointer.access(node.cls)) - else - Type.COMPLEX(node); + local + Class cls; + + case CLASS_NODE() + algorithm + cls := Pointer.access(node.cls); + then + match cls + case Class.DERIVED_CLASS() then getType(cls.baseClass); + case Class.INSTANCED_CLASS() then Type.COMPLEX(node); + case Class.PARTIAL_BUILTIN() then cls.ty; + case Class.INSTANCED_BUILTIN() then cls.ty; + else Type.UNKNOWN(); + end match; case COMPONENT_NODE() then Component.getType(Pointer.access(node.component)); end match; @@ -793,6 +802,24 @@ uniontype InstNode end match; end isRedeclare; + function countDimensions + input InstNode node; + input Integer levels; + input Integer accumCount = 0; + output Integer dimCount; + algorithm + if levels <= 0 then + dimCount := accumCount; + else + dimCount := match node + case COMPONENT_NODE() + then countDimensions(node.parent, levels - 1, + Component.dimensionCount(Pointer.access(node.component))); + else accumCount; + end match; + end if; + end countDimensions; + end InstNode; annotation(__OpenModelica_Interface="frontend"); diff --git a/Compiler/NFFrontEnd/NFInstUtil.mo b/Compiler/NFFrontEnd/NFInstUtil.mo index 9fb52555ca7..3e6e6bdd6aa 100644 --- a/Compiler/NFFrontEnd/NFInstUtil.mo +++ b/Compiler/NFFrontEnd/NFInstUtil.mo @@ -38,207 +38,10 @@ encapsulated package NFInstUtil Utility functions for operating on the types in NFInstTypes. " -//public import Absyn; -//public import ClassInf; public import DAE; -//public import NFInstSymbolTable; -//public import NFInstPrefix; -//public import NFInstTypes; public import SCode; -//public import NFEnv; -//protected import ComponentReference; -//protected import Debug; -//protected import Error; -//protected import Expression; -//protected import Flags; -//protected import NFInstDump; -//protected import List; -//protected import SCodeDump; -//protected import Types; -//protected import Util; -// -//public type Binding = NFInstTypes.Binding; -//public type Class = NFInstTypes.Class; -//public type Component = NFInstTypes.Component; -//public type Condition = NFInstTypes.Condition; -//public type DaePrefixes = NFInstTypes.DaePrefixes; -//public type Dimension = NFInstTypes.Dimension; -//public type Element = NFInstTypes.Element; -//public type Env = NFEnv.Env; -//public type Equation = NFInstTypes.Equation; -//public type Function = NFInstTypes.Function; -//public type Modifier = NFInstTypes.Modifier; -//public type ParamType = NFInstTypes.ParamType; -//public type Prefixes = NFInstTypes.Prefixes; -//public type Prefix = NFInstPrefix.Prefix; -//public type Statement = NFInstTypes.Statement; -//public type SymbolTable = NFInstSymbolTable.SymbolTable; -// -//public function makeClassType -// input Class inClass; -// input ClassInf.State inState; -// input Boolean inContainsSpecialExtends; -// output Class outClass; -// output DAE.Type outClassType; -//algorithm -// (outClass, outClassType) := match(inClass, inState, inContainsSpecialExtends) -// local -// list elems; -// Class cls; -// DAE.Type ty; -// list vars; -// -// case (NFInstTypes.COMPLEX_CLASS(components = elems), _, false) -// equation -// vars = List.accumulateMapReverse(elems, makeDaeVarsFromElement); -// ty = DAE.T_COMPLEX(inState, vars, NONE(), DAE.emptyTypeSource); -// then -// (inClass, ty); -// -// case (NFInstTypes.COMPLEX_CLASS(_, elems, {}, {}, {}, {}), _, true) -// equation -// (NFInstTypes.EXTENDED_ELEMENTS(cls = cls, ty = ty), elems) = -// getSpecialExtends(elems); -// then -// (cls, ty); -// -// end match; -//end makeClassType; -// -//public function makeDaeVarsFromElement -// input Element inElement; -// input list inAccumVars; -// output list outVars; -//algorithm -// outVars := match(inElement, inAccumVars) -// local -// Component comp; -// Class cls; -// list vars; -// DAE.Var var; -// -// case (NFInstTypes.ELEMENT(component = comp), vars) -// equation -// var = componentToDaeVar(comp); -// then -// var :: vars; -// -// case (NFInstTypes.CONDITIONAL_ELEMENT(component = comp), vars) -// equation -// var = componentToDaeVar(comp); -// then -// var :: vars; -// -// end match; -//end makeDaeVarsFromElement; -// -//protected function componentToDaeVar -// input Component inComponent; -// output DAE.Var outVar; -//algorithm -// outVar := match(inComponent) -// local -// Absyn.Path path; -// DAE.Type ty; -// String name; -// DAE.Attributes attr; -// Prefixes prefs; -// DaePrefixes dprefs; -// -// case NFInstTypes.UNTYPED_COMPONENT(name = path, prefixes = prefs) -// equation -// name = Absyn.pathLastIdent(path); -// attr = prefixesToDaeAttr(prefs); -// then -// DAE.TYPES_VAR(name, attr, DAE.T_UNKNOWN_DEFAULT, DAE.UNBOUND(), NONE()); -// -// case NFInstTypes.TYPED_COMPONENT(name = path, ty = ty, prefixes = dprefs) -// equation -// name = Absyn.pathLastIdent(path); -// attr = daePrefixesToDaeAttr(dprefs); -// then -// DAE.TYPES_VAR(name, attr, ty, DAE.UNBOUND(), NONE()); -// -// case NFInstTypes.CONDITIONAL_COMPONENT(name = path) -// equation -// name = Absyn.pathLastIdent(path); -// then -// DAE.TYPES_VAR(name, DAE.dummyAttrVar, DAE.T_UNKNOWN_DEFAULT, -// DAE.UNBOUND(), NONE()); -// -// case NFInstTypes.OUTER_COMPONENT(name = path) -// equation -// name = Absyn.pathLastIdent(path); -// then -// DAE.TYPES_VAR(name, DAE.dummyAttrVar, DAE.T_UNKNOWN_DEFAULT, -// DAE.UNBOUND(), NONE()); -// -// case NFInstTypes.COMPONENT_ALIAS() -// equation -// print("Got component alias in componentToDaeVar\n"); -// then -// fail(); -// -// case NFInstTypes.DELETED_COMPONENT() -// equation -// print("Got deleted component\n"); -// then -// fail(); -// -// end match; -//end componentToDaeVar; -// -//protected function prefixesToDaeAttr -// input Prefixes inPrefixes; -// output DAE.Attributes outAttr; -//algorithm -// outAttr := match(inPrefixes) -// local -// SCode.ConnectorType cty; -// SCode.Variability var; -// Absyn.Direction dir; -// Absyn.InnerOuter io; -// SCode.Visibility vis; -// -// case NFInstTypes.NO_PREFIXES() then DAE.dummyAttrVar; -// case NFInstTypes.PREFIXES(vis, var, _, io, (dir, _), (cty, _), _) -// then DAE.ATTR(cty, SCode.NON_PARALLEL(), var, dir, io, vis); -// -// end match; -//end prefixesToDaeAttr; -// -//protected function daePrefixesToDaeAttr -// input DaePrefixes inPrefixes; -// output DAE.Attributes outAttr; -//algorithm -// outAttr := match(inPrefixes) -// local -// DAE.VarVisibility dvis; -// DAE.VarKind dvar; -// DAE.VarDirection ddir; -// DAE.ConnectorType dcty; -// SCode.ConnectorType cty; -// SCode.Variability var; -// Absyn.Direction dir; -// Absyn.InnerOuter io; -// SCode.Visibility vis; -// -// case NFInstTypes.NO_DAE_PREFIXES() then DAE.dummyAttrVar; -// case NFInstTypes.DAE_PREFIXES(dvis, dvar, _, io, ddir, dcty) -// equation -// vis = daeToSCodeVisibility(dvis); -// var = daeToSCodeVariability(dvar); -// dir = daeToAbsynDirection(ddir); -// cty = daeToSCodeConnectorType(dcty); -// then -// DAE.ATTR(cty, SCode.NON_PARALLEL(), var, dir, io, vis); -// -// end match; -//end daePrefixesToDaeAttr; -// - -public function daeToSCodeConnectorType +function daeToSCodeConnectorType input DAE.ConnectorType inConnectorType; output SCode.ConnectorType outConnectorType; algorithm @@ -250,7 +53,7 @@ algorithm end match; end daeToSCodeConnectorType; -public function daeToSCodeParallelism +function daeToSCodeParallelism input DAE.VarParallelism inParallelism; output SCode.Parallelism outParallelism; algorithm @@ -261,7 +64,7 @@ algorithm end match; end daeToSCodeParallelism; -public function daeToSCodeVariability +function daeToSCodeVariability input DAE.VarKind inVariability; output SCode.Variability outVariability; algorithm @@ -273,7 +76,7 @@ algorithm end match; end daeToSCodeVariability; -public function daeToAbsynDirection +function daeToAbsynDirection input DAE.VarDirection inDirection; output Absyn.Direction outDirection; algorithm @@ -284,7 +87,7 @@ algorithm end match; end daeToAbsynDirection; -public function daeToAbsynInnerOuter +function daeToAbsynInnerOuter input DAE.VarInnerOuter inInnerOuter; output Absyn.InnerOuter outInnerOuter; algorithm @@ -296,7 +99,7 @@ algorithm end match; end daeToAbsynInnerOuter; -public function daeToSCodeVisibility +function daeToSCodeVisibility input DAE.VarVisibility inVisibility; output SCode.Visibility outVisibility; algorithm @@ -306,1321 +109,7 @@ algorithm end match; end daeToSCodeVisibility; -//public function makeDerivedClassType -// input DAE.Type inType; -// input ClassInf.State inState; -// output DAE.Type outType; -//algorithm -// outType := match(inType, inState) -// local -// list vars; -// DAE.EqualityConstraint ec; -// DAE.TypeSource src; -// -// // TODO: Check type restrictions. -// case (DAE.T_COMPLEX(_, vars, ec, src), _) -// then DAE.T_COMPLEX(inState, vars, ec, src); -// -// else DAE.T_SUBTYPE_BASIC(inState, {}, inType, NONE(), DAE.emptyTypeSource); -// -// end match; -//end makeDerivedClassType; -// -//public function arrayElementType -// input DAE.Type inType; -// output DAE.Type outType; -//algorithm -// outType := match(inType) -// local -// DAE.Type ty; -// ClassInf.State state; -// DAE.EqualityConstraint ec; -// DAE.TypeSource src; -// -// case DAE.T_ARRAY(ty = ty) then arrayElementType(ty); -// case DAE.T_SUBTYPE_BASIC(state, _, ty, ec, src) -// equation -// ty = arrayElementType(ty); -// then -// DAE.T_SUBTYPE_BASIC(state, {}, ty, ec, src); -// -// else inType; -// end match; -//end arrayElementType; -// -//public function addElementsToClass -// input list inElements; -// input Class inClass; -// output Class outClass; -//algorithm -// outClass := match(inElements, inClass) -// local -// list el; -// list eq, ieq; -// list> al, ial; -// Absyn.Path name; -// -// case ({}, _) then inClass; -// -// case (_, NFInstTypes.COMPLEX_CLASS(name, el, eq, ieq, al, ial)) -// equation -// el = listAppend(inElements, el); -// then -// NFInstTypes.COMPLEX_CLASS(name, el, eq, ieq, al, ial); -// -// case (_, NFInstTypes.BASIC_TYPE(_)) -// equation -// Error.addMessage(Error.INTERNAL_ERROR, -// {"NFSCodeInst.addElementsToClass: Can't add elements to basic type.\n"}); -// then -// fail(); -// -// end match; -//end addElementsToClass; -// -//public function getElementComponent -// input Element inElement; -// output Component outComponent; -//algorithm -// outComponent := match(inElement) -// local -// Component comp; -// -// case NFInstTypes.ELEMENT(component = comp) then comp; -// case NFInstTypes.CONDITIONAL_ELEMENT(component = comp) then comp; -// -// end match; -//end getElementComponent; -// -//public function getComponentName -// input Component inComponent; -// output Absyn.Path outName; -//algorithm -// outName := match(inComponent) -// local -// Absyn.Path name; -// -// case NFInstTypes.UNTYPED_COMPONENT(name = name) then name; -// case NFInstTypes.TYPED_COMPONENT(name = name) then name; -// case NFInstTypes.CONDITIONAL_COMPONENT(name = name) then name; -// case NFInstTypes.DELETED_COMPONENT(name = name) then name; -// case NFInstTypes.OUTER_COMPONENT(name = name) then name; -// -// end match; -//end getComponentName; -// -//public function setComponentName -// input Component inComponent; -// input Absyn.Path inName; -// output Component outComponent; -//algorithm -// outComponent := match(inComponent, inName) -// local -// DAE.Type ty; -// array dims; -// Prefixes prefs; -// DaePrefixes dprefs; -// ParamType pty; -// Binding binding; -// SourceInfo info; -// SCode.Element elem; -// Modifier mod; -// Env env; -// Prefix prefix; -// Option inner_name; -// DAE.Exp cond; -// Option p; -// -// case (NFInstTypes.UNTYPED_COMPONENT(_, ty, dims, prefs, pty, binding, info), _) -// then NFInstTypes.UNTYPED_COMPONENT(inName, ty, dims, prefs, pty, binding, info); -// -// case (NFInstTypes.TYPED_COMPONENT(_, ty, p, dprefs, binding, info), _) -// then NFInstTypes.TYPED_COMPONENT(inName, ty, p, dprefs, binding, info); -// -// case (NFInstTypes.CONDITIONAL_COMPONENT(_, cond, elem, mod, prefs, env, prefix, info), _) -// then NFInstTypes.CONDITIONAL_COMPONENT(inName, cond, elem, mod, prefs, env, prefix, info); -// -// case (NFInstTypes.DELETED_COMPONENT(_), _) -// then NFInstTypes.DELETED_COMPONENT(inName); -// -// case (NFInstTypes.OUTER_COMPONENT(_, inner_name), _) -// then NFInstTypes.OUTER_COMPONENT(inName, inner_name); -// -// end match; -//end setComponentName; -// -//public function setTypedComponentType -// input Component inComponent; -// input DAE.Type inType; -// output Component outComponent; -//algorithm -// outComponent := match(inComponent, inType) -// local -// Absyn.Path name; -// DaePrefixes dprefs; -// Binding binding; -// SourceInfo info; -// Option p; -// -// case (NFInstTypes.TYPED_COMPONENT(name, _, p, dprefs, binding, info), _) -// then NFInstTypes.TYPED_COMPONENT(name, inType, p, dprefs, binding, info); -// -// else inComponent; -// -// end match; -//end setTypedComponentType; -// -//public function setComponentParamType -// input Component inComponent; -// input ParamType inParamType; -// output Component outComponent; -//algorithm -// outComponent := match(inComponent, inParamType) -// local -// Absyn.Path name; -// DAE.Type ty; -// array dims; -// Prefixes prefs; -// Binding binding; -// SourceInfo info; -// -// case (NFInstTypes.UNTYPED_COMPONENT(name, ty, dims, prefs, _, binding, info), _) -// then NFInstTypes.UNTYPED_COMPONENT(name, ty, dims, prefs, inParamType, binding, info); -// -// else inComponent; -// -// end match; -//end setComponentParamType; -// -//public function getComponentType -// input Component inComponent; -// output DAE.Type outType; -//algorithm -// outType := match(inComponent) -// local -// DAE.Type ty; -// -// case NFInstTypes.UNTYPED_COMPONENT(baseType = ty) then ty; -// case NFInstTypes.TYPED_COMPONENT(ty = ty) then ty; -// -// end match; -//end getComponentType; -// -//public function getElementComponentType -// input Element inElement; -// output DAE.Type outType; -//algorithm -// outType := match(inElement) -// local -// DAE.Type ty; -// -// case NFInstTypes.ELEMENT(NFInstTypes.TYPED_COMPONENT(ty = ty),_) then ty; -// case NFInstTypes.ELEMENT(_, _) -// equation -// Error.addMessage(Error.INTERNAL_ERROR, -// {"NFInstUtil.getElementComponentType: Expected element with TYPED_COMPONENT \n"}); -// then -// fail(); -// else -// equation -// Error.addMessage(Error.INTERNAL_ERROR, -// {"NFInstUtil.getElementComponentType: Expected ELEMENT. found either conditional or extended element \n"}); -// then -// fail(); -// -// end match; -//end getElementComponentType; -// -//public function getComponentTypeDimensions -// input Component inComponent; -// output DAE.Dimensions outDims; -//algorithm -// outDims := match(inComponent) -// local -// DAE.Type ty; -// DAE.Dimensions dims; -// -// case NFInstTypes.TYPED_COMPONENT(ty = ty) -// equation -// dims = Types.getDimensions(ty); -// then dims; -// end match; -//end getComponentTypeDimensions; -// -//public function getComponentBinding -// input Component inComponent; -// output Binding outBinding; -//algorithm -// outBinding := match(inComponent) -// local -// Binding binding; -// -// case NFInstTypes.UNTYPED_COMPONENT(binding = binding) then binding; -// case NFInstTypes.TYPED_COMPONENT(binding = binding) then binding; -// -// end match; -//end getComponentBinding; -// -//public function getComponentBindingExp -// input Component inComponent; -// output DAE.Exp outExp; -//algorithm -// NFInstTypes.TYPED_COMPONENT(binding = -// NFInstTypes.TYPED_BINDING(bindingExp = outExp)) := inComponent; -//end getComponentBindingExp; -// -//public function getComponentVariability -// input Component inComponent; -// output SCode.Variability outVariability; -//algorithm -// outVariability := match(inComponent) -// local -// SCode.Variability var; -// -// case NFInstTypes.UNTYPED_COMPONENT(prefixes = -// NFInstTypes.PREFIXES(variability = var)) then var; -// -// case NFInstTypes.TYPED_COMPONENT(prefixes = -// NFInstTypes.DAE_PREFIXES(variability = DAE.CONST())) then SCode.CONST(); -// -// case NFInstTypes.TYPED_COMPONENT(prefixes = -// NFInstTypes.DAE_PREFIXES(variability = DAE.PARAM())) then SCode.PARAM(); -// -// else SCode.VAR(); -// -// end match; -//end getComponentVariability; -// -//public function getEffectiveComponentVariability -// input Component inComponent; -// output SCode.Variability outVariability; -//algorithm -// outVariability := match(inComponent) -// case NFInstTypes.UNTYPED_COMPONENT(paramType = NFInstTypes.STRUCT_PARAM()) -// then SCode.CONST(); -// -// else getComponentVariability(inComponent); -// -// end match; -//end getEffectiveComponentVariability; -// -//public function getComponentConnectorType -// input Component inComponent; -// output DAE.ConnectorType outConnectorType; -//algorithm -// outConnectorType := match(inComponent) -// local -// DAE.ConnectorType cty; -// -// case NFInstTypes.TYPED_COMPONENT(prefixes = -// NFInstTypes.DAE_PREFIXES(connectorType = cty)) then cty; -// -// else DAE.POTENTIAL(); -// -// end match; -//end getComponentConnectorType; -// -//protected function getSpecialExtends -// input list inElements; -// output Element outSpecialExtends; -// output list outRestElements; -//algorithm -// (outSpecialExtends, outRestElements) := getSpecialExtends2(inElements, {}); -//end getSpecialExtends; -// -//protected function getSpecialExtends2 -// input list inElements; -// input list inAccumEl; -// output Element outSpecialExtends; -// output list outRestElements; -//algorithm -// (outSpecialExtends, outRestElements) := matchcontinue(inElements, inAccumEl) -// local -// Element el; -// list rest_el; -// DAE.Type ty; -// -// case ((el as NFInstTypes.EXTENDED_ELEMENTS(ty = ty)) :: rest_el, _) -// equation -// true = isSpecialExtends(ty); -// rest_el = listAppend(listReverse(inAccumEl), rest_el); -// then -// (el, rest_el); -// -// // TODO: Check for illegal elements here (components, etc.). -// -// case (el :: rest_el, _) -// equation -// (el, rest_el) = getSpecialExtends2(rest_el, el :: inAccumEl); -// then -// (el, rest_el); -// -// else -// equation -// true = Flags.isSet(Flags.FAILTRACE); -// Debug.traceln("- NFSCodeInst.getSpecialExtends2 failed!"); -// then -// fail(); -// -// end matchcontinue; -//end getSpecialExtends2; -// -//public function isSpecialExtends -// input DAE.Type inType; -// output Boolean outResult; -//algorithm -// outResult := match(inType) -// case DAE.T_COMPLEX() then false; -// else true; -// end match; -//end isSpecialExtends; -// -//public function getComponentBindingDimension -// input Component inComponent; -// input Integer inDimension; -// input Integer inCompDimensions; -// output DAE.Dimension outDimension; -//protected -// Binding binding; -//algorithm -// binding := getComponentBinding(inComponent); -// outDimension := getBindingDimension(binding, inDimension, inCompDimensions); -//end getComponentBindingDimension; -// -//public function getBindingDimension -// input Binding inBinding; -// input Integer inDimension; -// input Integer inCompDimensions; -// output DAE.Dimension outDimension; -//algorithm -// outDimension := match(inBinding, inDimension, inCompDimensions) -// local -// DAE.Exp exp; -// Integer pd, index; -// -// case (NFInstTypes.TYPED_BINDING(bindingExp = exp, propagatedDims = pd), _, _) -// equation -// index = if intEq(pd, -1) then inDimension else (inDimension + pd - inCompDimensions); -// then -// getExpDimension(exp, index); -// -// end match; -//end getBindingDimension; -// -//public function getExpDimension -// input DAE.Exp inExp; -// input Integer inDimIndex; -// output DAE.Dimension outDimension; -//algorithm -// outDimension := matchcontinue(inExp, inDimIndex) -// local -// DAE.Type ty; -// list dims; -// DAE.Dimension dim; -// -// case (_, _) -// equation -// ty = Expression.typeof(inExp); -// dims = Types.getDimensions(ty); -// dim = listGet(dims, inDimIndex); -// then -// dim; -// -// // TODO: Error on index out of bounds! -// -// else DAE.DIM_UNKNOWN(); -// -// end matchcontinue; -//end getExpDimension; -// -//public function getBindingExp -// input Binding inBinding; -// output DAE.Exp outExp; -//algorithm -// outExp := match(inBinding) -// local -// DAE.Exp exp; -// -// case NFInstTypes.TYPED_BINDING(bindingExp = exp) then exp; -// else DAE.ICONST(0); -// end match; -//end getBindingExp; -// -//public function getBindingExpOpt -// input Binding inBinding; -// output Option outExp; -//algorithm -// outExp := match(inBinding) -// local -// DAE.Exp exp; -// -// case NFInstTypes.UNTYPED_BINDING(bindingExp = exp) then SOME(exp); -// case NFInstTypes.TYPED_BINDING(bindingExp = exp) then SOME(exp); -// else NONE(); -// -// end match; -//end getBindingExpOpt; -// -//public function getBindingTypeOpt -// input Binding inBinding; -// output Option outTy; -//algorithm -// outTy := match(inBinding) -// local -// DAE.Type ty; -// -// case NFInstTypes.TYPED_BINDING(bindingType = ty) then SOME(ty); -// else NONE(); -// -// end match; -//end getBindingTypeOpt; -// -//public function getBindingPropagatedDimsOpt -// input Binding inBinding; -// output Option outPropagatedDimsOpt; -//algorithm -// outPropagatedDimsOpt := match(inBinding) -// local -// Integer pd; -// -// case NFInstTypes.TYPED_BINDING(propagatedDims = pd) then SOME(pd); -// case NFInstTypes.RAW_BINDING(propagatedDims = pd) then SOME(pd); -// case NFInstTypes.UNTYPED_BINDING(propagatedDims = pd) then SOME(pd); -// else NONE(); -// -// end match; -//end getBindingPropagatedDimsOpt; -// -//public function makeEnumType -// input list inEnumLiterals; -// input Absyn.Path inEnumPath; -// output DAE.Type outType; -//protected -// list names; -//algorithm -// names := List.map(inEnumLiterals, SCode.enumName); -// outType := DAE.T_ENUMERATION(NONE(), inEnumPath, names, {}, {}, DAE.emptyTypeSource); -//end makeEnumType; -// -//public function makeEnumLiteralComp -// input Absyn.Path inName; -// input DAE.Type inType; -// input Integer inIndex; -// output Component outComponent; -//protected -// Binding binding; -//algorithm -// binding := NFInstTypes.TYPED_BINDING(DAE.ENUM_LITERAL(inName, inIndex), inType, -// 0, Absyn.dummyInfo); -// outComponent := NFInstTypes.TYPED_COMPONENT(inName, inType, NONE(), -// NFInstTypes.DEFAULT_CONST_DAE_PREFIXES, binding, Absyn.dummyInfo); -//end makeEnumLiteralComp; -// -//public function makeDimension -// input DAE.Exp inExp; -// output DAE.Dimension outDimension; -//algorithm -// outDimension := matchcontinue(inExp) -// local -// Integer idim; -// DAE.Type ty; -// Absyn.Path path; -// list enum_lits; -// Integer dim_size; -// -// case DAE.ICONST(idim) then DAE.DIM_INTEGER(idim); -// -// case DAE.ARRAY(ty = DAE.T_ARRAY(ty = -// DAE.T_ENUMERATION(index = NONE(), path = path, names = enum_lits), -// dims = {DAE.DIM_INTEGER(dim_size)})) -// then -// DAE.DIM_ENUM(path, enum_lits, dim_size); -// -// case DAE.CREF(ty = ty) -// equation -// DAE.T_ENUMERATION(path = path, names = enum_lits) = -// Types.derivedBasicType(ty); -// dim_size = listLength(enum_lits); -// then -// DAE.DIM_ENUM(path, enum_lits, dim_size); -// -// else DAE.DIM_EXP(inExp); -// end matchcontinue; -//end makeDimension; -// -//public function makeDimensionArray -// input list inDimensions; -// output array outDimensions; -//protected -// list dims; -//algorithm -// dims := List.map(inDimensions, wrapDimension); -// outDimensions := listArray(dims); -//end makeDimensionArray; -// -//public function wrapDimension -// input DAE.Dimension inDimension; -// output Dimension outDimension; -//algorithm -// outDimension := NFInstTypes.UNTYPED_DIMENSION(inDimension, false); -//end wrapDimension; -// -//public function wrapTypedDimension -// input DAE.Dimension inDimension; -// output Dimension outDimension; -//algorithm -// outDimension := NFInstTypes.TYPED_DIMENSION(inDimension); -//end wrapTypedDimension; -// -//public function unwrapDimension -// input Dimension inDimension; -// output DAE.Dimension outDimension; -//algorithm -// outDimension := match inDimension -// local -// DAE.Dimension dim; -// case NFInstTypes.UNTYPED_DIMENSION(dimension=dim) then dim; -// case NFInstTypes.TYPED_DIMENSION(dimension=dim) then dim; -// end match; -//end unwrapDimension; -// -//public function makeIterator -// input Absyn.Path inName; -// input DAE.Type inType; -// input SourceInfo inInfo; -// output Component outIterator; -//algorithm -// outIterator := NFInstTypes.TYPED_COMPONENT(inName, inType, NONE(), -// NFInstTypes.NO_DAE_PREFIXES(), NFInstTypes.UNBOUND(), inInfo); -//end makeIterator; -// -//public function mergePrefixesFromComponent -// "Merges a component's prefixes with the given prefixes, with the component's -// prefixes having priority." -// input Absyn.Path inComponentName; -// input SCode.Element inComponent; -// input Prefixes inPrefixes; -// output Prefixes outPrefixes; -//algorithm -// outPrefixes := match(inComponentName, inComponent, inPrefixes) -// local -// SCode.Prefixes pf; -// SCode.Attributes attr; -// Prefixes prefs; -// SourceInfo info; -// SCode.Comment comment; -// String err_str; -// -// case (_, SCode.COMPONENT(prefixes = pf, attributes = attr, comment = comment, info = info), _) -// equation -// prefs = makePrefixes(pf, attr, comment, info); -// prefs = mergePrefixes(prefs, inPrefixes, inComponentName, "variable"); -// then -// prefs; -// -// else -// equation -// err_str = Absyn.pathString(inComponentName); -// err_str = "NFInstUtil.mergePrefixesFromComponent got " + err_str + -// " which is not a component!"; -// Error.addMessage(Error.INTERNAL_ERROR, {err_str}); -// then -// fail(); -// -// end match; -//end mergePrefixesFromComponent; -// -//protected function makePrefixes -// "Creates an NFInstTypes.Prefixes record from SCode.Prefixes and SCode.Attributes." -// input SCode.Prefixes inPrefixes; -// input SCode.Attributes inAttributes; -// input SCode.Comment inComment; -// input SourceInfo inInfo; -// output Prefixes outPrefixes; -//algorithm -// outPrefixes := match(inPrefixes, inAttributes, inComment, inInfo) -// local -// SCode.Visibility vis; -// SCode.Variability var; -// SCode.Final fp; -// Absyn.InnerOuter io; -// Absyn.Direction dir; -// SCode.ConnectorType ct; -// SourceInfo info; -// NFInstTypes.VarArgs va; -// -// // All prefixes are the default ones, same as having no prefixes. -// case (SCode.PREFIXES(visibility = SCode.PUBLIC(), finalPrefix = -// SCode.NOT_FINAL(), innerOuter = Absyn.NOT_INNER_OUTER()), SCode.ATTR( -// connectorType = SCode.POTENTIAL(), variability = SCode.VAR(), -// direction = Absyn.BIDIR()), _, _) -// then NFInstTypes.NO_PREFIXES(); -// -// // Otherwise, select the prefixes we are interested in and build a PREFIXES -// // record. -// case (SCode.PREFIXES(visibility = vis, finalPrefix = fp, innerOuter = io), -// SCode.ATTR(connectorType = ct, variability = var, direction = dir), _, info) -// equation -// va = makeVarArg(dir,inComment); -// then NFInstTypes.PREFIXES(vis, var, fp, io, (dir, info), (ct, info), va); -// -// end match; -//end makePrefixes; -// -//protected function makeVarArg "Checks if the component might be a varargs type of component" -// input Absyn.Direction inDir; -// input SCode.Comment inComment; -// output NFInstTypes.VarArgs varArgs; -//algorithm -// varArgs := match (inDir,inComment) -// case (Absyn.INPUT(),_) -// then -// if SCode.optCommentHasBooleanNamedAnnotation(SOME(inComment),"__OpenModelica_varArgs") then NFInstTypes.IS_VARARG() else NFInstTypes.NO_VARARG(); -// else NFInstTypes.NO_VARARG(); -// end match; -//end makeVarArg; -// -//public function mergePrefixesWithDerivedClass -// "Merges the attributes of a derived class with the given prefixes." -// input Absyn.Path inClassName; -// input SCode.Element inClass; -// input Prefixes inPrefixes; -// output Prefixes outPrefixes; -//algorithm -// outPrefixes := match(inClassName, inClass, inPrefixes) -// local -// SCode.Attributes attr; -// SourceInfo info; -// Prefixes prefs; -// -// case (_, SCode.CLASS(classDef = SCode.DERIVED(attributes = attr), info = info), _) -// equation -// prefs = makePrefixesFromAttributes(attr, info); -// prefs = mergePrefixes(prefs, inPrefixes, inClassName, "class"); -// then -// prefs; -// -// end match; -//end mergePrefixesWithDerivedClass; -// -//protected function makePrefixesFromAttributes -// "Creates an NFInstTypes.Prefixes record from an SCode.Attributes." -// input SCode.Attributes inAttributes; -// input SourceInfo inInfo; -// output Prefixes outPrefixes; -//algorithm -// outPrefixes := match(inAttributes, inInfo) -// local -// SCode.ConnectorType ct; -// SCode.Variability var; -// Absyn.Direction dir; -// -// // All attributes are the default ones, same as having no prefixes. -// case (SCode.ATTR(connectorType = SCode.POTENTIAL(), variability = SCode.VAR(), -// direction = Absyn.BIDIR()), _) -// then NFInstTypes.NO_PREFIXES(); -// -// // Otherwise, select the attributes we are interested in and build a -// // PREFIXES record with the parts not covered by SCode.Attributes set to the -// // default values. -// case (SCode.ATTR(connectorType = ct, variability = var, direction = dir), _) -// then NFInstTypes.PREFIXES(SCode.PUBLIC(), var, SCode.NOT_FINAL(), -// Absyn.NOT_INNER_OUTER(), (dir, inInfo), (ct, inInfo), NFInstTypes.NO_VARARG()); -// -// end match; -//end makePrefixesFromAttributes; -// -//public function mergePrefixes -// "Merges two NFInstTypes.Prefixes records, with the outer having priority over -// the inner. inElementName and inElementType are used for error reporting, where -// inElementName is the name of the element that the outer prefixes comes from -// and inElementType the type of that element as a string (variable or class)." -// input Prefixes inOuterPrefixes; -// input Prefixes inInnerPrefixes; -// input Absyn.Path inElementName; -// input String inElementType; -// output Prefixes outPrefixes; -//algorithm -// outPrefixes := -// match(inOuterPrefixes, inInnerPrefixes, inElementName, inElementType) -// local -// SCode.Visibility vis1, vis2; -// SCode.Variability var1, var2; -// SCode.Final fp1, fp2; -// Absyn.InnerOuter io1, io2; -// tuple dir1, dir2; -// tuple ct1, ct2; -// NFInstTypes.VarArgs va2; -// -// // No outer prefixes => no change. -// case (NFInstTypes.NO_PREFIXES(), _, _, _) then inInnerPrefixes; -// // No inner prefixes => overwrite with outer prefixes. -// case (_, NFInstTypes.NO_PREFIXES(), _, _) then inOuterPrefixes; -// -// // Both outer and inner prefixes => merge them. -// case (NFInstTypes.PREFIXES(vis1, var1, fp1, io1, dir1, ct1, _), -// NFInstTypes.PREFIXES(vis2, var2, fp2, _, dir2, ct2, va2), _, _) -// equation -// vis2 = mergeVisibility(vis1, vis2); -// var2 = mergeVariability(var1, var2); -// fp2 = mergeFinal(fp1, fp2); -// dir2 = mergeDirection(dir1, dir2, inElementName, inElementType); -// ct2 = mergeConnectorType(ct1, ct2, inElementName, inElementType); -// then -// NFInstTypes.PREFIXES(vis2, var2, fp2, io1, dir2, ct2, va2); -// -// end match; -//end mergePrefixes; -// -//public function mergePrefixesFromExtends -// input SCode.Element inExtends; -// input Prefixes inPrefixes; -// output Prefixes outPrefixes; -//protected -// SCode.Visibility vis; -//algorithm -// SCode.EXTENDS(visibility = vis) := inExtends; -// outPrefixes := setPrefixVisibility(vis, inPrefixes); -//end mergePrefixesFromExtends; -// -//protected function setPrefixVisibility -// input SCode.Visibility inVisibility; -// input Prefixes inPrefixes; -// output Prefixes outPrefixes; -//algorithm -// outPrefixes := match(inVisibility, inPrefixes) -// local -// SCode.Variability var; -// SCode.Final fp; -// Absyn.InnerOuter io; -// tuple dir; -// tuple ct; -// NFInstTypes.VarArgs va; -// -// case (SCode.PUBLIC(), _) then inPrefixes; -// -// case (_, NFInstTypes.PREFIXES(_, var, fp, io, dir, ct, va)) -// then NFInstTypes.PREFIXES(inVisibility, var, fp, io, dir, ct, va); -// -// else NFInstTypes.DEFAULT_PROTECTED_PREFIXES; -// -// end match; -//end setPrefixVisibility; -// -//protected function mergeVisibility -// "Merges an outer and inner visibility prefix." -// input SCode.Visibility inOuterVisibility; -// input SCode.Visibility inInnerVisibility; -// output SCode.Visibility outVisibility; -//algorithm -// outVisibility := match(inOuterVisibility, inInnerVisibility) -// // If the outer is protected, return protected. -// case (SCode.PROTECTED(), _) then inOuterVisibility; -// // Otherwise, no change. -// else inInnerVisibility; -// end match; -//end mergeVisibility; -// -//protected function mergeVariability -// "Merges an outer and inner variability prefix. The most restrictive -// variability is returned (with constant most restrictive, variable least)." -// input SCode.Variability inOuterVariability; -// input SCode.Variability inInnerVariability; -// output SCode.Variability outVariability; -//algorithm -// outVariability := match(inOuterVariability, inInnerVariability) -// case (SCode.CONST(), _) then inOuterVariability; -// case (_, SCode.CONST()) then inInnerVariability; -// case (SCode.PARAM(), _) then inOuterVariability; -// case (_, SCode.PARAM()) then inInnerVariability; -// case (SCode.DISCRETE(), _) then inOuterVariability; -// case (_, SCode.DISCRETE()) then inInnerVariability; -// else inInnerVariability; -// end match; -//end mergeVariability; -// -//protected function mergeFinal -// "Merges an outer and inner final prefix." -// input SCode.Final inOuterFinal; -// input SCode.Final inInnerFinal; -// output SCode.Final outFinal; -//algorithm -// outFinal := match(inOuterFinal, inInnerFinal) -// // If the outer prefix is final, return final. -// case (SCode.FINAL(), _) then inOuterFinal; -// // Otherwise, no change. -// else inInnerFinal; -// end match; -//end mergeFinal; -// -//protected function mergeDirection -// "Merges an outer and inner direction prefix." -// input tuple inOuterDirection; -// input tuple inInnerDirection; -// input Absyn.Path inElementName; -// input String inElementType; -// output tuple outDirection; -//algorithm -// outDirection := -// match(inOuterDirection, inInnerDirection, inElementName, inElementType) -// local -// Absyn.Direction dir1, dir2; -// SourceInfo info1, info2; -// String dir_str1, dir_str2, el_name; -// -// // If either prefix is unset, return the other. -// case (_, (Absyn.BIDIR(), _), _, _) then inOuterDirection; -// case ((Absyn.BIDIR(), _), _, _, _) then inInnerDirection; -// -// // we need this for now, see i.e. Modelica.Blocks.Math.Add3 -// case ((Absyn.INPUT(), _), (Absyn.INPUT(), _), _, _) then inInnerDirection; -// case ((Absyn.OUTPUT(), _), (Absyn.OUTPUT(), _), _, _) then inInnerDirection; -// -// // Otherwise we have an error, since it's not allowed to overwrite -// // input/output prefixes. -// case ((dir1, info1), (dir2, info2), _, _) -// equation -// dir_str1 = directionString(dir1); -// dir_str2 = directionString(dir2); -// el_name = Absyn.pathString(inElementName); -// Error.addMultiSourceMessage(Error.INVALID_TYPE_PREFIX, -// {dir_str1, inElementType, el_name, dir_str2}, {info2, info1}); -// then -// fail(); -// -// end match; -//end mergeDirection; -// -//protected function directionString -// input Absyn.Direction inDirection; -// output String outString; -//algorithm -// outString := match(inDirection) -// case Absyn.INPUT() then "input"; -// case Absyn.OUTPUT() then "output"; -// else ""; -// end match; -//end directionString; -// -//protected function mergeConnectorType -// "Merges outer and inner connector type prefixes (flow, stream)." -// input tuple inOuterConnectorType; -// input tuple inInnerConnectorType; -// input Absyn.Path inElementName; -// input String inElementType; -// output tuple outConnectorType; -//algorithm -// outConnectorType := matchcontinue(inOuterConnectorType, inInnerConnectorType, -// inElementName, inElementType) -// local -// SCode.ConnectorType ct1, ct2; -// SourceInfo info1, info2; -// String ct1_str, ct2_str, el_name; -// -// // If either of the prefixes are unset, return the others. -// case ((SCode.POTENTIAL(), _), _, _, _) then inInnerConnectorType; -// case (_, (SCode.POTENTIAL(), _), _, _) then inOuterConnectorType; -// -// // Trying to overwrite a flow/stream prefix => show error. -// case ((ct1, info1), (ct2, info2), _, _) -// equation -// ct1_str = SCodeDump.connectorTypeStr(ct1); -// ct2_str = SCodeDump.connectorTypeStr(ct2); -// el_name = Absyn.pathString(inElementName); -// Error.addMultiSourceMessage(Error.INVALID_TYPE_PREFIX, -// {ct2_str, inElementType, el_name, ct1_str}, {info1, info2}); -// then -// fail(); -// -// end matchcontinue; -//end mergeConnectorType; -// -//public function prefixElement -// input Element inElement; -// input Prefix inPrefix; -// output Element outElement; -//algorithm -// outElement := match(inElement, inPrefix) -// local -// Component comp; -// Class cls; -// Absyn.Path bc; -// DAE.Type ty; -// -// case (NFInstTypes.ELEMENT(comp, cls), _) -// equation -// comp = prefixComponent(comp, inPrefix); -// cls = prefixClass(cls, inPrefix); -// then -// NFInstTypes.ELEMENT(comp, cls); -// -// case (NFInstTypes.CONDITIONAL_ELEMENT(comp), _) -// equation -// comp = prefixComponent(comp, inPrefix); -// then -// NFInstTypes.CONDITIONAL_ELEMENT(comp); -// -// end match; -//end prefixElement; -// -//public function prefixComponent -// input Component inComponent; -// input Prefix inPrefix; -// output Component outComponent; -//protected -// Absyn.Path name; -//algorithm -// name := getComponentName(inComponent); -// name := NFInstPrefix.prefixPath(name, inPrefix); -// outComponent := setComponentName(inComponent, name); -//end prefixComponent; -// -//public function prefixClass -// input Class inClass; -// input Prefix inPrefix; -// output Class outClass; -//algorithm -// outClass := match(inClass, inPrefix) -// local -// list comps; -// list eq, ieq; -// list> al, ial; -// Absyn.Path name; -// -// case (NFInstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), _) -// equation -// comps = List.map1(comps, prefixElement, inPrefix); -// then -// NFInstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial); -// -// else inClass; -// -// end match; -//end prefixClass; -// -//public function countElementsInClass -// input Class inClass; -// output Integer outElements; -//algorithm -// outElements := match(inClass) -// local -// list comps; -// Integer count; -// -// case NFInstTypes.BASIC_TYPE(_) then 0; -// -// case NFInstTypes.COMPLEX_CLASS(components = comps) -// equation -// count = List.fold(comps, countElementsInElement, 0); -// then -// count; -// -// end match; -//end countElementsInClass; -// -//public function countElementsInElement -// input Element inElement; -// input Integer inCount; -// output Integer outCount; -//algorithm -// outCount := match(inElement, inCount) -// local -// Class cls; -// -// case (NFInstTypes.ELEMENT(cls = cls), _) -// then 1 + countElementsInClass(cls) + inCount; -// -// case (NFInstTypes.CONDITIONAL_ELEMENT(), _) -// then 1 + inCount; -// -// end match; -//end countElementsInElement; -// -//public function removeCrefOuterPrefix -// input Absyn.Path inInnerPath; -// input DAE.ComponentRef inOuterCref; -// output DAE.ComponentRef outInnerCref; -//algorithm -// outInnerCref := match(inInnerPath, inOuterCref) -// local -// Absyn.Path path; -// DAE.ComponentRef cref; -// String id, err_msg; -// DAE.Type ty; -// list subs; -// -// case (Absyn.IDENT(), _) -// equation -// cref = ComponentReference.crefLastCref(inOuterCref); -// then -// cref; -// -// case (Absyn.QUALIFIED(path = path), DAE.CREF_QUAL(id, ty, subs, cref)) -// equation -// cref = removeCrefOuterPrefix(path, cref); -// then -// DAE.CREF_QUAL(id, ty, subs, cref); -// -// else -// equation -// true = Flags.isSet(Flags.FAILTRACE); -// err_msg = "NFSCodeInst.removeCrefOuterPrefix failed on inner path " + -// Absyn.pathString(inInnerPath) + " and outer cref " + -// ComponentReference.printComponentRefStr(inOuterCref); -// Debug.traceln(err_msg); -// then -// fail(); -// -// end match; -//end removeCrefOuterPrefix; -// -//public function replaceCrefOuterPrefix -// input DAE.ComponentRef inCref; -// input SymbolTable inSymbolTable; -// output DAE.ComponentRef outCref; -// output SymbolTable outSymbolTable; -//algorithm -// (outCref, outSymbolTable) := match(inCref, inSymbolTable) -// local -// DAE.ComponentRef prefix_cref, rest_cref, cref; -// SymbolTable st; -// -// case (_, st) -// equation -// (prefix_cref, rest_cref) = ComponentReference.splitCrefLast(inCref); -// (cref, st) = replaceCrefOuterPrefix2(prefix_cref, rest_cref, st); -// then -// (cref, st); -// -// end match; -//end replaceCrefOuterPrefix; -// -//protected function replaceCrefOuterPrefix2 -// input DAE.ComponentRef inPrefixCref; -// input DAE.ComponentRef inSuffixCref; -// input SymbolTable inSymbolTable; -// output DAE.ComponentRef outNewCref; -// output SymbolTable outSymbolTable; -//algorithm -// (outNewCref, outSymbolTable) := -// matchcontinue(inPrefixCref, inSuffixCref, inSymbolTable) -// local -// Absyn.Path inner_name; -// Component comp; -// SymbolTable st; -// DAE.ComponentRef inner_cref, new_cref, prefix_cref, rest_cref; -// -// case (_, _, st) -// equation -// comp = NFInstSymbolTable.lookupCref(inPrefixCref, st); -// (inner_name, _, st) = NFInstSymbolTable.updateInnerReference(comp, st); -// inner_cref = removeCrefOuterPrefix(inner_name, inPrefixCref); -// new_cref = ComponentReference.joinCrefs(inner_cref, inSuffixCref); -// then -// (new_cref, st); -// -// case (_, _, st) -// equation -// (prefix_cref, rest_cref) = ComponentReference.splitCrefLast(inPrefixCref); -// rest_cref = ComponentReference.joinCrefs(rest_cref, inSuffixCref); -// (new_cref, st) = replaceCrefOuterPrefix2(prefix_cref, rest_cref, st); -// then -// (new_cref, st); -// -// end matchcontinue; -//end replaceCrefOuterPrefix2; -// -//public function isInnerComponent -// input Component inComponent; -// output Boolean outIsInner; -//algorithm -// outIsInner := match(inComponent) -// local -// SCode.Element el; -// Absyn.InnerOuter io; -// -// case NFInstTypes.UNTYPED_COMPONENT(prefixes = NFInstTypes.PREFIXES(innerOuter = io)) -// then Absyn.isInner(io); -// -// case NFInstTypes.TYPED_COMPONENT(prefixes = NFInstTypes.DAE_PREFIXES(innerOuter = io)) -// then Absyn.isInner(io); -// -// case NFInstTypes.CONDITIONAL_COMPONENT(element = el) -// then SCode.isInnerComponent(el); -// -// else false; -// end match; -//end isInnerComponent; -// -//public function isConnectorComponent -// input Component inComponent; -// output Boolean outIsConnector; -//algorithm -// outIsConnector := match(inComponent) -// local -// DAE.Type ty; -// -// case NFInstTypes.TYPED_COMPONENT(ty = ty) -// equation -// ty = arrayElementType(ty); -// then -// Types.isConnector(ty); -// -// case NFInstTypes.UNTYPED_COMPONENT(baseType = ty) -// then Types.isConnector(ty); -// -// else -// equation -// Error.addMessage(Error.INTERNAL_ERROR, -// {"NFInstUtil.isConnectorComponent: Unknown component\n"}); -// then -// fail(); -// -// end match; -//end isConnectorComponent; -// -//replaceable type TraverseArgType subtypeof Any; -// -//partial function TraverseFuncType -// input Component inComponent; -// input TraverseArgType inArg; -// output Component outComponent; -// output TraverseArgType outArg; -//end TraverseFuncType; -// -//public function traverseClassComponents -// input Class inClass; -// input TraverseArgType inArg; -// input TraverseFuncType inFunc; -// output Class outClass; -// output TraverseArgType outArg; -//algorithm -// (outClass, outArg) := match(inClass, inArg, inFunc) -// local -// TraverseArgType arg; -// list comps; -// list eq, ieq; -// list> al, ial; -// Absyn.Path name; -// -// case (NFInstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), arg, _) -// equation -// (comps, arg) = traverseClassComponents2(comps, arg, inFunc, {}); -// then -// (NFInstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), arg); -// -// else (inClass, inArg); -// -// end match; -//end traverseClassComponents; -// -//protected function traverseClassComponents2 -// input list inElements; -// input TraverseArgType inArg; -// input TraverseFuncType inFunc; -// input list inAccumEl; -// output list outElements; -// output TraverseArgType outArg; -//algorithm -// (outElements, outArg) := match(inElements, inArg, inFunc, inAccumEl) -// local -// Element el; -// list rest_el; -// TraverseArgType arg; -// -// case (el :: rest_el, arg, _, _) -// equation -// (el, arg) = traverseClassElement(el, inArg, inFunc); -// (rest_el, arg) = traverseClassComponents2(rest_el, arg, inFunc, el :: inAccumEl); -// then -// (rest_el, arg); -// -// else (listReverse(inAccumEl), inArg); -// -// end match; -//end traverseClassComponents2; -// -//protected function traverseClassElement -// input Element inElement; -// input TraverseArgType inArg; -// input TraverseFuncType inFunc; -// output Element outElement; -// output TraverseArgType outArg; -//algorithm -// (outElement, outArg) := match(inElement, inArg, inFunc) -// local -// Component comp; -// Class cls; -// Absyn.Path bc; -// DAE.Type ty; -// TraverseArgType arg; -// -// case (NFInstTypes.ELEMENT(comp, cls), arg, _) -// equation -// (comp, arg) = inFunc(comp, arg); -// (cls, arg) = traverseClassComponents(cls, arg, inFunc); -// then -// (NFInstTypes.ELEMENT(comp, cls), arg); -// -// case (NFInstTypes.CONDITIONAL_ELEMENT(comp), arg, _) -// equation -// (comp, arg) = inFunc(comp, arg); -// then -// (NFInstTypes.CONDITIONAL_ELEMENT(comp), arg); -// -// case (NFInstTypes.EXTENDED_ELEMENTS(bc, cls, ty), arg, _) -// equation -// (cls, arg) = traverseClassComponents(cls, arg, inFunc); -// then -// (NFInstTypes.EXTENDED_ELEMENTS(bc, cls, ty), arg); -// -// end match; -//end traverseClassElement; -// -//public function paramTypeFromPrefixes -// input Prefixes inPrefixes; -// output ParamType outParamType; -//algorithm -// outParamType := match(inPrefixes) -// case NFInstTypes.PREFIXES(variability = SCode.PARAM()) -// then NFInstTypes.NON_STRUCT_PARAM(); -// -// else NFInstTypes.NON_PARAM(); -// -// end match; -//end paramTypeFromPrefixes; -// -//public function translatePrefixes -// input Prefixes inPrefixes; -// output DaePrefixes outPrefixes; -//algorithm -// outPrefixes := match(inPrefixes) -// local -// SCode.Visibility vis1; -// DAE.VarVisibility vis2; -// SCode.Variability var1; -// DAE.VarKind var2; -// SCode.Final fp; -// Absyn.InnerOuter io; -// Absyn.Direction dir1; -// DAE.VarDirection dir2; -// SCode.ConnectorType ct1; -// DAE.ConnectorType ct2; -// -// case NFInstTypes.NO_PREFIXES() then NFInstTypes.NO_DAE_PREFIXES(); -// case NFInstTypes.PREFIXES(vis1, var1, fp, io, (dir1, _), (ct1, _), _) -// equation -// vis2 = translateVisibility(vis1); -// var2 = translateVariability(var1); -// dir2 = translateDirection(dir1); -// ct2 = translateConnectorType(ct1); -// then -// NFInstTypes.DAE_PREFIXES(vis2, var2, fp, io, dir2, ct2); -// -// end match; -//end translatePrefixes; - -public function translateConnectorType +function translateConnectorType input SCode.ConnectorType inConnectorType; output DAE.ConnectorType outConnectorType; algorithm @@ -1631,7 +120,7 @@ algorithm end match; end translateConnectorType; -public function translateParallelism +function translateParallelism input SCode.Parallelism inParallelism; output DAE.VarParallelism outParallelism; algorithm @@ -1642,7 +131,7 @@ algorithm end match; end translateParallelism; -public function translateVariability +function translateVariability input SCode.Variability inVariability; output DAE.VarKind outVariability; algorithm @@ -1654,7 +143,7 @@ algorithm end match; end translateVariability; -public function translateDirection +function translateDirection input Absyn.Direction inDirection; output DAE.VarDirection outDirection; algorithm @@ -1665,7 +154,7 @@ algorithm end match; end translateDirection; -public function translateInnerOuter +function translateInnerOuter input Absyn.InnerOuter inInnerOuter; output DAE.VarInnerOuter outInnerOuter; algorithm @@ -1677,7 +166,7 @@ algorithm end match; end translateInnerOuter; -public function translateVisibility +function translateVisibility input SCode.Visibility inVisibility; output DAE.VarVisibility outVisibility; algorithm @@ -1687,236 +176,7 @@ algorithm end match; end translateVisibility; -//public function conditionTrue -// input Condition inCondition; -// output Boolean outCondition; -//algorithm -// outCondition := matchcontinue(inCondition) -// local -// Boolean cond; -// list condl; -// -// case NFInstTypes.SINGLE_CONDITION(condition = cond) then cond; -// case NFInstTypes.ARRAY_CONDITION(conditions = condl) -// equation -// _ = List.find(condl, conditionFalse); -// then -// false; -// -// else true; -// end matchcontinue; -//end conditionTrue; -// -//public function conditionFalse -// input Condition inCondition; -// output Boolean outCondition; -//algorithm -// outCondition := matchcontinue(inCondition) -// local -// Boolean cond; -// list condl; -// -// case NFInstTypes.SINGLE_CONDITION(condition = cond) then not cond; -// case NFInstTypes.ARRAY_CONDITION(conditions = condl) -// equation -// _ = List.find(condl, conditionTrue); -// then -// false; -// -// else true; -// end matchcontinue; -//end conditionFalse; -// -//public function isArrayAllocation -// input NFInstTypes.Statement stmt; -// output Boolean b; -//algorithm -// b := match stmt case NFInstTypes.FUNCTION_ARRAY_INIT() then true; else false; end match; -//end isArrayAllocation; -// -//public function isFlowComponent -// input Component inComponent; -// output Boolean outIsFlow; -//algorithm -// outIsFlow := match(inComponent) -// case NFInstTypes.UNTYPED_COMPONENT(prefixes = -// NFInstTypes.PREFIXES(connectorType = (SCode.FLOW(), _))) then true; -// case NFInstTypes.TYPED_COMPONENT(prefixes = -// NFInstTypes.DAE_PREFIXES(connectorType = DAE.FLOW())) then true; -// else false; -// end match; -//end isFlowComponent; -// -//public function getFunctionInputs -// input Function inFunction; -// output list outInputs; -//algorithm -// outInputs := match(inFunction) -// local -// list inputs; -// -// case NFInstTypes.FUNCTION(inputs = inputs) then inputs; -// case NFInstTypes.RECORD_CONSTRUCTOR(inputs = inputs) then inputs; -// -// end match; -//end getFunctionInputs; -// -//public function getComponentParent -// input Component inComponent; -// output Option outParent; -//algorithm -// outParent := match(inComponent) -// local -// Option parent; -// -// case NFInstTypes.TYPED_COMPONENT(parent = parent) then parent; -// else NONE(); -// -// end match; -//end getComponentParent; -// -//public function setComponentParent -// input Component inComponent; -// input Option inParent; -// output Component outComponent; -//algorithm -// outComponent := match(inComponent, inParent) -// local -// Absyn.Path name; -// DAE.Type ty; -// DaePrefixes pref; -// Binding binding; -// SourceInfo info; -// -// case (NFInstTypes.TYPED_COMPONENT(name, ty, _, pref, binding, info), SOME(_)) -// then NFInstTypes.TYPED_COMPONENT(name, ty, inParent, pref, binding, info); -// -// else inComponent; -// -// end match; -//end setComponentParent; -// -//public function makeTypedComponentCref -// input Component inComponent; -// output DAE.ComponentRef outCref; -//algorithm -// outCref := match(inComponent) -// local -// Absyn.Path name; -// DAE.ComponentRef cref; -// -// case NFInstTypes.TYPED_COMPONENT(name = name) -// equation -// (cref, _) = makeTypedComponentCref2(name, inComponent); -// then -// cref; -// -// else -// equation -// true = Flags.isSet(Flags.FAILTRACE); -// Debug.trace("- NFInstUtil.makeTypedComponentCref failed on component "); -// Debug.traceln(NFInstDump.componentStr(inComponent)); -// then -// fail(); -// -// end match; -//end makeTypedComponentCref; -// -//protected function makeTypedComponentCref2 -// input Absyn.Path inPath; -// input Component inComponent; -// output DAE.ComponentRef outCref; -// output Option outParent; -//algorithm -// (outCref, outParent) := match(inPath, inComponent) -// local -// Absyn.Ident id; -// Absyn.Path rest_path; -// DAE.ComponentRef cref; -// DAE.Type ty; -// Option parent; -// -// case (Absyn.QUALIFIED(name = id, path = rest_path), _) -// equation -// (cref, SOME(NFInstTypes.TYPED_COMPONENT(ty = ty, parent = parent))) = -// makeTypedComponentCref2(rest_path, inComponent); -// then -// (DAE.CREF_QUAL(id, ty, {}, cref), parent); -// -// case (Absyn.IDENT(name = id), -// NFInstTypes.TYPED_COMPONENT(ty = ty, parent = parent)) -// then (DAE.CREF_IDENT(id, ty, {}), parent); -// -// else -// equation -// true = Flags.isSet(Flags.FAILTRACE); -// Debug.trace("- NFInstUtil.makeTypedComponentCref2 failed on path "); -// Debug.traceln(Absyn.pathString(inPath)); -// then -// fail(); -// -// end match; -//end makeTypedComponentCref2; -// -//public function typeCrefWithComponent -// input DAE.ComponentRef inCref; -// input Component inComponent; -// output DAE.ComponentRef outCref; -//algorithm -// outCref := match(inCref, inComponent) -// local -// DAE.ComponentRef cref; -// -// case (_, NFInstTypes.TYPED_COMPONENT(parent = NONE())) then inCref; -// -// else -// equation -// (cref, _) = typeCrefWithComponent2(inCref, inComponent); -// then -// cref; -// -// end match; -//end typeCrefWithComponent; -// -//protected function typeCrefWithComponent2 -// input DAE.ComponentRef inCref; -// input Component inComponent; -// output DAE.ComponentRef outCref; -// output Option outParent; -//algorithm -// (outCref, outParent) := matchcontinue(inCref, inComponent) -// local -// Option parent; -// DAE.Ident id; -// DAE.Type ty; -// list subs; -// DAE.ComponentRef rest_cref; -// -// case (DAE.CREF_IDENT(id, _, subs), -// NFInstTypes.TYPED_COMPONENT(ty = ty, parent = parent)) -// then (DAE.CREF_IDENT(id, ty, subs), parent); -// -// case (DAE.CREF_QUAL(id, _, subs, rest_cref), _) -// equation -// (rest_cref, SOME(NFInstTypes.TYPED_COMPONENT(ty = ty, parent = parent))) = -// typeCrefWithComponent2(rest_cref, inComponent); -// then -// (DAE.CREF_QUAL(id, ty, subs, rest_cref), parent); -// -// else -// equation -// true = Flags.isSet(Flags.FAILTRACE); -// Debug.trace("- NFInstUtil.typeCrefWithComponent2 failed on cref "); -// Debug.trace(ComponentReference.printComponentRefStr(inCref)); -// Debug.trace(" and component "); -// Debug.traceln(NFInstDump.componentStr(inComponent)); -// then -// fail(); -// -// end matchcontinue; -//end typeCrefWithComponent2; -// -public function toConst +function toConst "Translates SCode.Variability to DAE.Const" input SCode.Variability inVar; output DAE.Const outConst; @@ -1928,159 +188,52 @@ algorithm end match; end toConst; -//public function setClassName -// input Class inClass; -// input Absyn.Path inClassName; -// output Class outClass; -//algorithm -// outClass := match(inClass, inClassName) -// local -// list el; -// list eq, ieq; -// list> al, ial; -// Absyn.Path name; -// -// case (NFInstTypes.COMPLEX_CLASS(_, el, eq, ieq, al, ial), _) -// then -// NFInstTypes.COMPLEX_CLASS(inClassName, el, eq, ieq, al, ial); -// -// case (NFInstTypes.BASIC_TYPE(_), _) -// then -// NFInstTypes.BASIC_TYPE(inClassName); -// -// end match; -//end setClassName; -// -//public function getClassName -// input Class inClass; -// output Absyn.Path outClassName; -//algorithm -// outClassName := match(inClass) -// local -// Absyn.Path name; -// -// case (NFInstTypes.COMPLEX_CLASS(name = name)) -// then -// name; -// -// case (NFInstTypes.BASIC_TYPE(name)) -// then -// name; -// -// end match; -//end getClassName; -// -//public function isModifiableElement -// input Element inElement; -// output Boolean outBool; -//algorithm -// outBool := match(inElement) -// local -// Component comp; -// -// case(NFInstTypes.ELEMENT(comp, _)) then isModifiableComponent(comp); -// -// end match; -//end isModifiableElement; -// -//public function isModifiableComponent -//"@mahge: -// Returns true if a component is modifiable from outside of scope. -// Protected, final and constants with bidings can not be modifed. -// Everything else can be. -//" -// input Component inComponent; -// output Boolean outBool; -//algorithm -// outBool := matchcontinue(inComponent) -// local -// case(NFInstTypes.UNTYPED_COMPONENT(prefixes = NFInstTypes.PREFIXES(visibility = SCode.PROTECTED()))) then false; -// case(NFInstTypes.UNTYPED_COMPONENT(prefixes = NFInstTypes.PREFIXES(variability = SCode.CONST()), binding = NFInstTypes.UNBOUND())) then true; -// case(NFInstTypes.UNTYPED_COMPONENT(prefixes = NFInstTypes.PREFIXES(variability = SCode.CONST()))) then false; -// case(NFInstTypes.UNTYPED_COMPONENT(prefixes = NFInstTypes.PREFIXES(finalPrefix = SCode.FINAL()))) then false; -// else true; -// end matchcontinue; -//end isModifiableComponent; -// -//public function markElementAsInput -// input Element inElement; -// output Element outElement; -//algorithm -// outElement := match(inElement) -// local -// Component comp; -// Class cls; -// -// case(NFInstTypes.ELEMENT(comp, cls)) -// equation -// comp = markComponentAsInput(comp); -// then NFInstTypes.ELEMENT(comp, cls); -// -// end match; -//end markElementAsInput; -// -//public function markComponentAsInput -// input Component inComponent; -// output Component outComponent; -//algorithm -// outComponent := match(inComponent) -// local -// Absyn.Path name; -// DAE.Type baseType; -// array dimensions; -// ParamType paramType; -// Binding binding; -// SourceInfo info; -// -// case(NFInstTypes.UNTYPED_COMPONENT(name, baseType, dimensions, _, paramType, binding, info)) -// then NFInstTypes.UNTYPED_COMPONENT(name, baseType, dimensions, NFInstTypes.DEFAULT_INPUT_PREFIXES, paramType, binding, info); -// -// else -// equation -// Error.addMessage(Error.INTERNAL_ERROR,{"NFInstUtil.markComponentAsInput failed"}); -// then fail(); -// end match; -//end markComponentAsInput; -// -//public function markElementAsProtected -// input Element inElement; -// output Element outElement; -//algorithm -// outElement := match(inElement) -// local -// Component comp; -// Class cls; -// -// case(NFInstTypes.ELEMENT(comp, cls)) -// equation -// comp = markComponentAsProtected(comp); -// then NFInstTypes.ELEMENT(comp, cls); -// -// end match; -//end markElementAsProtected; -// -//public function markComponentAsProtected -// input Component inComponent; -// output Component outComponent; -//algorithm -// outComponent := match(inComponent) -// local -// Absyn.Path name; -// DAE.Type baseType; -// array dimensions; -// ParamType paramType; -// Binding binding; -// SourceInfo info; -// -// case(NFInstTypes.UNTYPED_COMPONENT(name, baseType, dimensions, _, paramType, binding, info)) -// then NFInstTypes.UNTYPED_COMPONENT(name, baseType, dimensions, NFInstTypes.DEFAULT_PROTECTED_PREFIXES, paramType, binding, info); -// -// else -// equation -// Error.addMessage(Error.INTERNAL_ERROR,{"NFInstUtil.markComponentAsProtected failed"}); -// then fail(); -// end match; -//end markComponentAsProtected; -// +function variabilityAnd + "Returns the most variable of two VarKinds." + input DAE.VarKind var1; + input DAE.VarKind var2; + output DAE.VarKind var; +algorithm + var := match (var1, var2) + case (DAE.VarKind.VARIABLE(), _) then var1; + case (_, DAE.VarKind.VARIABLE()) then var2; + case (DAE.VarKind.DISCRETE(), _) then var1; + case (_, DAE.VarKind.DISCRETE()) then var2; + case (DAE.VarKind.PARAM(), _) then var1; + case (_, DAE.VarKind.PARAM()) then var2; + else var1; + end match; +end variabilityAnd; + +function variabilityOr + "Returns the least variable of two VarKinds." + input DAE.VarKind var1; + input DAE.VarKind var2; + output DAE.VarKind var; +algorithm + var := match (var1, var2) + case (DAE.VarKind.CONST(), _) then var1; + case (_, DAE.VarKind.CONST()) then var2; + case (DAE.VarKind.PARAM(), _) then var1; + case (_, DAE.VarKind.PARAM()) then var2; + case (DAE.VarKind.DISCRETE(), _) then var1; + case (_, DAE.VarKind.DISCRETE()) then var2; + else var1; + end match; +end variabilityOr; + +function variabilityString + input DAE.VarKind var; + output String string; +algorithm + string := match var + case DAE.VarKind.CONST() then "constant"; + case DAE.VarKind.PARAM() then "parameter"; + case DAE.VarKind.DISCRETE() then "discrete"; + case DAE.VarKind.VARIABLE() then "continuous"; + end match; +end variabilityString; + + annotation(__OpenModelica_Interface="frontend"); end NFInstUtil; diff --git a/Compiler/NFFrontEnd/NFLookup.mo b/Compiler/NFFrontEnd/NFLookup.mo index 06c74769dba..7007f43c982 100644 --- a/Compiler/NFFrontEnd/NFLookup.mo +++ b/Compiler/NFFrontEnd/NFLookup.mo @@ -107,7 +107,7 @@ protected Type ty; algorithm if InstNode.isClass(component) then - ty := Class.getType(InstNode.getClass(Inst.expand(component))); + ty := InstNode.getType(Inst.expand(component)); state := match ty case Type.ENUMERATION() then LookupState.STATE_COMP(); diff --git a/Compiler/NFFrontEnd/NFRecord.mo b/Compiler/NFFrontEnd/NFRecord.mo index a7e28236975..3174adf32ec 100644 --- a/Compiler/NFFrontEnd/NFRecord.mo +++ b/Compiler/NFFrontEnd/NFRecord.mo @@ -70,7 +70,7 @@ function typeRecordCall input SourceInfo info; output Expression typedExp; output Type ty; - output DAE.Const variability; + output DAE.VarKind variability; //protected // InstNode instClassNode; // list inputs; @@ -84,7 +84,7 @@ function typeRecordCall algorithm typedExp := Expression.INTEGER(0); ty := Type.UNKNOWN(); - variability := DAE.Const.C_VAR(); + variability := DAE.VarKind.VARIABLE(); // // inputs := getRecordConstructorInputs(classNode); // diff --git a/Compiler/NFFrontEnd/NFTypeCheck.mo b/Compiler/NFFrontEnd/NFTypeCheck.mo index 8da5974070f..4b0a6ea6b60 100644 --- a/Compiler/NFFrontEnd/NFTypeCheck.mo +++ b/Compiler/NFFrontEnd/NFTypeCheck.mo @@ -55,6 +55,8 @@ import Operator = NFOperator; import Type = NFType; import Class = NFClass.Class; import ClassTree = NFClassTree; +import InstUtil = NFInstUtil; +import DAEUtil; public @@ -2284,17 +2286,17 @@ end getRangeTypeEnum; function checkIfExpression input Expression condExp; input Type condType; - input DAE.Const condVar; + input DAE.VarKind condVar; input Expression thenExp; input Type thenType; - input DAE.Const thenVar; + input DAE.VarKind thenVar; input Expression elseExp; input Type elseType; - input DAE.Const elseVar; + input DAE.VarKind elseVar; input SourceInfo info; output Expression outExp; output Type outType; - output DAE.Const outVar; + output DAE.VarKind outVar; protected Expression ec, e1, e2; String s1, s2, s3, s4; @@ -2324,22 +2326,24 @@ algorithm outExp := Expression.IF(ec, e1, e2); outType := thenType; - outVar := Types.constAnd(thenVar, elseVar); + outVar := InstUtil.variabilityAnd(thenVar, elseVar); end checkIfExpression; -function checkConstVariability - input DAE.Const actualVar; +function matchVariability + input DAE.VarKind actualVar; input DAE.VarKind expectedVar; output Boolean matching; algorithm matching := match (actualVar, expectedVar) - case (DAE.Const.C_CONST(), _) then true; + case (DAE.VarKind.CONST(), _) then true; case (_, DAE.VarKind.CONST()) then false; - case (DAE.Const.C_PARAM(), _) then true; + case (DAE.VarKind.PARAM(), _) then true; case (_, DAE.VarKind.PARAM()) then false; + case (DAE.VarKind.DISCRETE(), _) then true; + case (_, DAE.VarKind.DISCRETE()) then false; else true; end match; -end checkConstVariability; +end matchVariability; function matchBinding input output Binding binding; @@ -2362,7 +2366,7 @@ algorithm parent := component; for i in 1:binding.propagatedLevels loop - parent := InstNode.parent(parent); + parent := InstNode.parent(component); dims := Type.arrayDims(InstNode.getType(parent)); comp_ty := Type.liftArrayLeftList(comp_ty, dims); end for; @@ -2391,5 +2395,33 @@ algorithm end match; end matchBinding; +function checkDimension + "Checks that an expression used as a dimension is a parameter expression and + has a valid type for a dimension, otherwise prints an error and fails." + input Expression exp; + input Type ty; + input DAE.VarKind var; + input SourceInfo info; +algorithm + if not Type.isInteger(ty) then + () := match exp + case Expression.TYPENAME(ty = Type.ARRAY(elementType = Type.BOOLEAN())) then (); + case Expression.TYPENAME(ty = Type.ARRAY(elementType = Type.ENUMERATION())) then (); + else + algorithm + Error.addSourceMessage(Error.INVALID_DIMENSION_TYPE, + {Expression.toString(exp), Type.toString(ty)}, info); + then + fail(); + end match; + end if; + + if not DAEUtil.isParamOrConstVarKind(var) then + Error.addSourceMessage(Error.DIMENSION_NOT_KNOWN, + {Expression.toString(exp)}, info); + fail(); + end if; +end checkDimension; + annotation(__OpenModelica_Interface="frontend"); end NFTypeCheck; diff --git a/Compiler/NFFrontEnd/NFTyping.mo b/Compiler/NFFrontEnd/NFTyping.mo index 84bd214468d..3d7c9b87f99 100644 --- a/Compiler/NFFrontEnd/NFTyping.mo +++ b/Compiler/NFFrontEnd/NFTyping.mo @@ -67,6 +67,7 @@ import TypeCheck = NFTypeCheck; import Types; import NFSections.Sections; import List; +import DAEUtil; uniontype TypingError record NO_ERROR end NO_ERROR; @@ -109,25 +110,27 @@ end typeFunction; function typeComponents input InstNode cls; - output Type ty; protected Class c = InstNode.getClass(cls); ClassTree cls_tree; list dims; algorithm - ty := match c + () := match c case Class.INSTANCED_CLASS(elements = cls_tree as ClassTree.FLAT_TREE()) algorithm for c in cls_tree.components loop typeComponent(c); end for; then - Type.COMPLEX(cls); + (); case Class.DERIVED_CLASS() - then typeComponents(c.baseClass); + algorithm + typeComponents(c.baseClass); + then + (); - case Class.INSTANCED_BUILTIN() then c.ty; + case Class.INSTANCED_BUILTIN() then (); else algorithm @@ -150,16 +153,14 @@ algorithm case Component.UNTYPED_COMPONENT() algorithm // Type the component's dimensions. - typeDimensions(c.dimensions, InstNode.name(component), c.binding, c.info); - - // Type the component's children. - ty := typeComponents(c.classInst); - - // Add the dimensions from the component to its type. - ty := Type.liftArrayLeftList(ty, arrayList(c.dimensions)); + typeDimensions(c.dimensions, component, c.binding, c.info); - // Finally, update the component in the instance tree. + // Construct the type of the component and update the node with it. + ty := Type.liftArrayLeftList(InstNode.getType(c.classInst), arrayList(c.dimensions)); InstNode.updateComponent(Component.setType(ty, c), component); + + // Type the component's children. + typeComponents(c.classInst); then ty; @@ -196,7 +197,7 @@ algorithm // If the iteration range is structural, it must be a parameter expression. if structural then - if not Types.isParameterOrConstant(Binding.variability(binding)) then + if not DAEUtil.isParamOrConstVarKind(Binding.variability(binding)) then Error.addSourceMessageAndFail(Error.NON_PARAMETER_ITERATOR_RANGE, {Binding.toString(binding)}, info); else @@ -239,18 +240,18 @@ end typeIterator; function typeDimensions input output array dimensions; - input String elementName; + input InstNode component; input Binding binding; input SourceInfo info; algorithm for i in 1:arrayLength(dimensions) loop - typeDimension(dimensions[i], elementName, binding, i, dimensions, info); + typeDimension(dimensions[i], component, binding, i, dimensions, info); end for; end typeDimensions; function typeDimension input output Dimension dimension; - input String elementName; + input InstNode component; input Binding binding; input Integer index; input array dimensions; @@ -259,10 +260,12 @@ algorithm dimension := match dimension local Expression exp; - DAE.Const var; + DAE.VarKind var; Dimension dim; Binding b; TypingError ty_err; + Type ty; + Integer prop_dims; // Print an error when a dimension that's currently being processed is // found, which indicates a dependency loop. Another way of handling this @@ -276,7 +279,7 @@ algorithm // found with DFS on the dimension expression. Maybe have a limit // on the output in case there's a lot of dimensions involved. Error.addSourceMessage(Error.CYCLIC_DIMENSIONS, - {String(index), elementName, Expression.toString(dimension.dimension)}, info); + {String(index), InstNode.name(component), Expression.toString(dimension.dimension)}, info); then fail(); @@ -285,18 +288,24 @@ algorithm algorithm arrayUpdate(dimensions, index, Dimension.UNTYPED(dimension.dimension, true)); - (exp, _, var) := typeExp(dimension.dimension, info); - - // TODO: Improve this error message: - // "Dimension %s of %s is not a parameter expression." - if not Types.isParameterOrConstant(var) then - Error.addSourceMessageAndFail(Error.DIMENSION_NOT_KNOWN, {Expression.toString(exp)}, info); - end if; + (exp, ty, var) := typeExp(dimension.dimension, info); + TypeCheck.checkDimension(exp, ty, var, info); - exp := Ceval.evalExp(exp, Ceval.EvalTarget.DIMENSION(elementName, index, exp, info)); + exp := Ceval.evalExp(exp, Ceval.EvalTarget.DIMENSION(component, index, exp, info)); exp := SimplifyExp.simplifyExp(exp); - dim := Dimension.fromExp(exp); + // It's possible to get an array expression here, for example if the + // dimension expression is a parameter whose binding comes from a + // modifier on an array component. If all the elements are equal we can + // just take one of them and use that, but we don't yet support the case + // where they are different. Creating a dimension from an array leads to + // weird things happening, so for now we print an error instead. + if not Expression.arrayAllEqual(exp) then + Error.addSourceMessage(Error.RAGGED_DIMENSION, {Expression.toString(exp)}, info); + fail(); + end if; + + dim := Dimension.fromExp(Expression.arrayFirstScalar(exp)); arrayUpdate(dimensions, index, dim); then dim; @@ -309,7 +318,7 @@ algorithm case Binding.UNBOUND() algorithm Error.addSourceMessage(Error.FAILURE_TO_DEDUCE_DIMS_NO_MOD, - {String(index), elementName}, info); + {String(index), InstNode.name(component)}, info); then fail(); @@ -317,14 +326,16 @@ algorithm // to get the dimension we're looking for. case Binding.UNTYPED_BINDING() algorithm - dim := typeExpDim(binding.bindingExp, index + binding.propagatedLevels, info); + prop_dims := InstNode.countDimensions(InstNode.parent(component), binding.propagatedLevels); + dim := typeExpDim(binding.bindingExp, index + prop_dims, info); then dim; // A typed binding, get the dimension from the binding's type. case Binding.TYPED_BINDING() algorithm - dim := nthDimensionBoundsChecked(binding.bindingType, index + binding.propagatedLevels); + prop_dims := InstNode.countDimensions(InstNode.parent(component), binding.propagatedLevels); + dim := nthDimensionBoundsChecked(binding.bindingType, index + prop_dims); then dim; @@ -401,6 +412,15 @@ algorithm // binding which is now typed, and it needs to be type checked. if dirty then binding := TypeCheck.matchBinding(binding, c.ty, component); + + if not TypeCheck.matchVariability(Binding.variability(binding), Component.variability(c)) then + Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING, + {InstNode.name(component), InstUtil.variabilityString(Component.variability(c)), + "'" + Binding.toString(binding) + "'", InstUtil.variabilityString(Binding.variability(binding))}, + Binding.getInfo(binding)); + fail(); + end if; + c.binding := binding; end if; @@ -436,7 +456,7 @@ algorithm local Expression exp; Type ty; - DAE.Const var; + DAE.VarKind var; case Binding.UNTYPED_BINDING(bindingExp = exp) algorithm @@ -556,23 +576,23 @@ function typeExp input output Expression exp; input SourceInfo info; output Type ty; - output DAE.Const variability; + output DAE.VarKind variability; - import DAE.Const; + import DAE.VarKind; algorithm (exp, ty, variability) := match exp local Expression e1, e2, e3; - DAE.Const var1, var2, var3; + DAE.VarKind var1, var2, var3; Type ty1, ty2, ty3; Operator op; ComponentRef cref; - case Expression.INTEGER() then (exp, Type.INTEGER(), Const.C_CONST()); - case Expression.REAL() then (exp, Type.REAL(), Const.C_CONST()); - case Expression.STRING() then (exp, Type.STRING(), Const.C_CONST()); - case Expression.BOOLEAN() then (exp, Type.BOOLEAN(), Const.C_CONST()); - case Expression.ENUM_LITERAL() then (exp, exp.ty, Const.C_CONST()); + case Expression.INTEGER() then (exp, Type.INTEGER(), VarKind.CONST()); + case Expression.REAL() then (exp, Type.REAL(), VarKind.CONST()); + case Expression.STRING() then (exp, Type.STRING(), VarKind.CONST()); + case Expression.BOOLEAN() then (exp, Type.BOOLEAN(), VarKind.CONST()); + case Expression.ENUM_LITERAL() then (exp, exp.ty, VarKind.CONST()); case Expression.CREF() algorithm @@ -580,13 +600,13 @@ algorithm then (Expression.CREF(ty, cref), ty, variability); - case Expression.TYPENAME() then (exp, exp.ty, Const.C_CONST()); + case Expression.TYPENAME() then (exp, exp.ty, VarKind.CONST()); case Expression.ARRAY() then typeArray(exp.elements, info); case Expression.RANGE() then typeRange(exp, info); case Expression.TUPLE() then typeTuple(exp.elements, info); case Expression.SIZE() then typeSize(exp, info); - case Expression.END() then (exp, Type.INTEGER(), Const.C_CONST()); + case Expression.END() then (exp, Type.INTEGER(), VarKind.CONST()); case Expression.BINARY() algorithm @@ -594,7 +614,7 @@ algorithm (e2, ty2, var2) := typeExp(exp.exp2, info); (exp, ty) := TypeCheck.checkBinaryOperation(e1, ty1, exp.operator, e2, ty2); then - (exp, ty, Types.constAnd(var1, var2)); + (exp, ty, InstUtil.variabilityAnd(var1, var2)); case Expression.UNARY() algorithm @@ -609,7 +629,7 @@ algorithm (e2, ty2, var2) := typeExp(exp.exp2, info); (exp, ty) := TypeCheck.checkLogicalBinaryOperation(e1, ty1, exp.operator, e2, ty2); then - (exp, ty, Types.constAnd(var1, var2)); + (exp, ty, InstUtil.variabilityAnd(var1, var2)); case Expression.LUNARY() algorithm @@ -624,7 +644,7 @@ algorithm (e2, ty2, var2) := typeExp(exp.exp2, info); (exp, ty) := TypeCheck.checkRelationOperation(e1, ty1, exp.operator, e2, ty2); then - (exp, ty, Types.constAnd(var1, var2)); + (exp, ty, InstUtil.variabilityAnd(var1, var2)); case Expression.IF() algorithm @@ -651,10 +671,10 @@ function typeExpl input SourceInfo info; output list explTyped = {}; output list tyl = {}; - output list varl = {}; + output list varl = {}; protected Expression exp; - DAE.Const var; + DAE.VarKind var; Type ty; algorithm for e in listReverse(expl) loop @@ -790,7 +810,7 @@ algorithm else error := TypingError.NO_ERROR(); d := arrayGet(c.dimensions, dimIndex); - d := typeDimension(d, InstNode.name(component), c.binding, dimIndex, c.dimensions, info); + d := typeDimension(d, component, c.binding, dimIndex, c.dimensions, c.info); end if; then (d, error); @@ -824,7 +844,7 @@ function typeCref input output ComponentRef cref; input SourceInfo info; output Type ty; - output DAE.Const variability; + output DAE.VarKind variability; import NFComponentRef.Origin; algorithm @@ -835,7 +855,7 @@ algorithm list subs; case ComponentRef.CREF(origin = Origin.SCOPE) - then (cref, Type.UNKNOWN(), DAE.Const.C_VAR()); + then (cref, Type.UNKNOWN(), DAE.VarKind.VARIABLE()); case ComponentRef.CREF(node = InstNode.COMPONENT_NODE()) algorithm @@ -849,13 +869,13 @@ algorithm (ComponentRef.CREF(cref.node, subs, cref_ty, cref.origin, rest_cr), ty, variability); case ComponentRef.CREF(node = InstNode.CLASS_NODE()) - then (cref, Type.UNKNOWN(), DAE.Const.C_VAR()); + then (cref, Type.UNKNOWN(), DAE.VarKind.VARIABLE()); case ComponentRef.EMPTY() - then (cref, Type.UNKNOWN(), DAE.Const.C_VAR()); + then (cref, Type.UNKNOWN(), DAE.VarKind.VARIABLE()); case ComponentRef.WILD() - then (cref, Type.UNKNOWN(), DAE.Const.C_VAR()); + then (cref, Type.UNKNOWN(), DAE.VarKind.VARIABLE()); else algorithm @@ -898,17 +918,17 @@ function typeArray input SourceInfo info; output Expression arrayExp; output Type arrayType = Type.UNKNOWN(); - output DAE.Const variability = DAE.C_CONST(); + output DAE.VarKind variability = DAE.VarKind.CONST(); protected Expression exp; list expl = {}; - DAE.Const var; + DAE.VarKind var; Type ty; algorithm for e in elements loop // TODO: Type checking. (exp, ty, var) := typeExp(e, info); - variability := Types.constAnd(var, variability); + variability := InstUtil.variabilityAnd(var, variability); expl := exp :: expl; end for; @@ -920,13 +940,13 @@ function typeRange input output Expression rangeExp; input SourceInfo info; output Type rangeType; - output DAE.Const variability; + output DAE.VarKind variability; protected Expression start_exp, step_exp, stop_exp; Type start_ty, step_ty, stop_ty; Option ostep_exp; Option ostep_ty; - DAE.Const start_var, step_var, stop_var; + DAE.VarKind start_var, step_var, stop_var; TypeCheck.MatchKind ty_match; algorithm Expression.RANGE(start = start_exp, step = ostep_exp, stop = stop_exp) := rangeExp; @@ -934,7 +954,7 @@ algorithm // Type start and stop. (start_exp, start_ty, start_var) := typeExp(start_exp, info); (stop_exp, stop_ty, stop_var) := typeExp(stop_exp, info); - variability := Types.constAnd(start_var, stop_var); + variability := InstUtil.variabilityAnd(start_var, stop_var); // Type check start and stop. (start_exp, stop_exp, rangeType, ty_match) := @@ -948,7 +968,7 @@ algorithm // Type step. SOME(step_exp) := ostep_exp; (step_exp, step_ty, step_var) := typeExp(step_exp, info); - variability := Types.constAnd(step_var, variability); + variability := InstUtil.variabilityAnd(step_var, variability); // Type check start and step. (start_exp, step_exp, rangeType, ty_match) := @@ -978,16 +998,16 @@ function typeTuple input SourceInfo info; output Expression tupleExp; output Type tupleType; - output DAE.Const variability; + output DAE.VarKind variability; protected list expl; list tyl; - list valr; + list valr; algorithm (expl, tyl, valr) := typeExpl(elements, info); tupleType := Type.TUPLE(tyl, NONE()); tupleExp := Expression.TUPLE(tupleType, expl); - variability := List.fold(valr, Types.constAnd, DAE.C_CONST()); + variability := List.fold(valr, InstUtil.variabilityAnd, DAE.VarKind.CONST()); end typeTuple; protected @@ -1008,7 +1028,7 @@ function typeSize input output Expression sizeExp; input SourceInfo info; output Type sizeType; - output DAE.Const variability; + output DAE.VarKind variability; protected Expression exp, index; Type exp_ty, index_ty; @@ -1063,7 +1083,7 @@ algorithm dim_size := Dimension.size(dim); then - (Expression.INTEGER(dim_size), Type.INTEGER(), DAE.C_CONST()); + (Expression.INTEGER(dim_size), Type.INTEGER(), DAE.VarKind.CONST()); case Expression.SIZE() algorithm @@ -1077,7 +1097,7 @@ algorithm sizeType := Type.ARRAY(Type.INTEGER(), {Dimension.INTEGER(Type.dimensionCount(exp_ty))}); then - (Expression.SIZE(exp, NONE()), sizeType, DAE.C_PARAM()); + (Expression.SIZE(exp, NONE()), sizeType, DAE.VarKind.PARAM()); end match; end typeSize; diff --git a/Compiler/Util/Error.mo b/Compiler/Util/Error.mo index 1d0e7f09afb..320d0764c1f 100644 --- a/Compiler/Util/Error.mo +++ b/Compiler/Util/Error.mo @@ -729,6 +729,10 @@ public constant Message CLASS_EXTENDS_MISSING_REDECLARE = MESSAGE(299, TRANSLATI Util.gettext("Missing redeclare prefix on class extends %s, treating like redeclare anyway.")); public constant Message CYCLIC_DIMENSIONS = MESSAGE(300, TRANSLATION(), ERROR(), Util.gettext("Dimension %s of %s, '%s', could not be evaluated due to a cyclic dependency.")); +public constant Message INVALID_DIMENSION_TYPE = MESSAGE(301, TRANSLATION(), ERROR(), + Util.gettext("Dimension '%s' of type %s is not an integer expression or an enumeration or Boolean type name.")); +public constant Message RAGGED_DIMENSION = MESSAGE(302, TRANSLATION(), ERROR(), + Util.gettext("Ragged dimensions are not yet supported (from dimension '%s')")); public constant Message INITIALIZATION_NOT_FULLY_SPECIFIED = MESSAGE(496, TRANSLATION(), WARNING(), Util.gettext("The initial conditions are not fully specified. %s.")); public constant Message INITIALIZATION_OVER_SPECIFIED = MESSAGE(497, TRANSLATION(), WARNING(), diff --git a/Compiler/Util/List.mo b/Compiler/Util/List.mo index 801053336b4..164e8b06b31 100644 --- a/Compiler/Util/List.mo +++ b/Compiler/Util/List.mo @@ -3286,7 +3286,7 @@ end map1BoolOr; public function map1BoolAnd - "Maps each element of a inList to Boolean type with inFunc. Stops mapping at first occurrence of true return value. + "Maps each element of a inList to Boolean type with inFunc. Stops mapping at first occurrence of false return value. inFunc takes one additional argument." input list inList; input MapFunc inFunc;