Skip to content

Commit

Permalink
Split MetaUtil into SCode and front-end parts
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Jul 26, 2019
1 parent 0464072 commit f83a024
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 85 deletions.
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/FrontEnd/Inst.mo
Expand Up @@ -137,6 +137,7 @@ import Global;
import HashTable;
import HashTable5;
import InstHashTable;
import InstMeta;
import InstSection;
import InstBinding;
import InstVar;
Expand All @@ -145,7 +146,6 @@ import InstUtil;
import InstExtends;
import List;
import Lookup;
import MetaUtil;
import Mutable;
import OperatorOverloading;
import PrefixUtil;
Expand Down Expand Up @@ -2172,7 +2172,7 @@ algorithm
// Search for equalityConstraint
eqConstraint = InstUtil.equalityConstraint(env5, els, info);
ci_state6 = if isSome(ed) then ClassInf.assertTrans(ci_state6,ClassInf.FOUND_EXT_DECL(),info) else ci_state6;
(cache,oty) = MetaUtil.fixUniontype(cache, env5, ci_state6, inClassDef6);
(cache,oty) = InstMeta.fixUniontype(cache, env5, ci_state6, inClassDef6);
_ = match oty
case SOME(ty as DAE.T_METAUNIONTYPE(typeVars=_::_))
algorithm
Expand Down Expand Up @@ -2464,7 +2464,7 @@ algorithm
(cache,(SCode.CLASS(name=cn2,restriction=SCode.R_UNIONTYPE(typeVars=typeVars),classDef=classDef)),cenv) = Lookup.lookupClass(cache, env, cn, SOME(info));
(cache,fq_class) = makeFullyQualifiedIdent(cache,cenv,cn2);
new_ci_state = ClassInf.META_UNIONTYPE(fq_class, typeVars);
(cache,SOME(ty as DAE.T_METAUNIONTYPE())) = MetaUtil.fixUniontype(cache, env, new_ci_state, classDef);
(cache,SOME(ty as DAE.T_METAUNIONTYPE())) = InstMeta.fixUniontype(cache, env, new_ci_state, classDef);
(cache,_,ih,tys,csets,oDA) = instClassDefHelper(cache,env,ih,tSpecs,pre,inst_dims,impl,{}, inSets,info);
tys = list(Types.boxIfUnboxedType(t) for t in tys);
if not (listLength(tys)==listLength(typeVars)) then
Expand Down
119 changes: 119 additions & 0 deletions OMCompiler/Compiler/FrontEnd/InstMeta.mo
@@ -0,0 +1,119 @@
/*
* 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 InstMeta
" file: InstMeta.mo
package: InstMeta
description: Different MetaModelica extension functions, for instantiation and later parts of the compiler.
"

import ClassInf;
import DAE;
import FCore;
import SCode;

protected

import Flags;
import Lookup;
import SCodeUtil;
import Types;

public function fixUniontype
input FCore.Cache inCache;
input FCore.Graph inEnv;
input ClassInf.State inState;
input SCode.ClassDef inClassDef;
output FCore.Cache cache = inCache;
output Option<DAE.Type> outType;
algorithm
outType := match (inState, inClassDef)
local
Boolean b;
Absyn.Path p,p2;
list<Absyn.Path> paths;
list<DAE.Type> typeVarsTypes;
list<String> names, typeVars;
DAE.EvaluateSingletonType singletonType;
SCode.Element c;
FCore.Graph env_1;

case (ClassInf.META_UNIONTYPE(typeVars=typeVars), SCode.PARTS())
algorithm
p := AbsynUtil.makeFullyQualified(inState.path);
names := SCodeUtil.elementNames(list(e for e guard match e case SCode.CLASS(restriction=SCode.R_METARECORD()) then true; else false; end match in inClassDef.elementLst));
paths := list(AbsynUtil.suffixPath(p, n) for n in names);
b := listLength(paths)==1;
if b then
p2 := listGet(paths, 1);
singletonType := DAE.EVAL_SINGLETON_TYPE_FUNCTION(function fixUniontype2(arr=arrayCreate(1, (cache,inEnv,p2,NONE()))));
else
singletonType := DAE.NOT_SINGLETON();
end if;
typeVarsTypes := list(DAE.T_METAPOLYMORPHIC(tv) for tv in typeVars);
then
SOME(DAE.T_METAUNIONTYPE(paths,typeVarsTypes,b,singletonType,p));

else NONE();
end match;
end fixUniontype;

protected function fixUniontype2
input array<tuple<FCore.Cache, FCore.Graph, Absyn.Path, Option<DAE.Type>>> arr;
output DAE.Type singletonType;
protected
FCore.Cache cache;
FCore.Graph env;
Absyn.Path p;
Option<DAE.Type> ot;
algorithm
(cache,env,p,ot) := arrayGet(arr, 1);
if isNone(ot) then
(_, singletonType) := Lookup.lookupType(cache, env, p, SOME(sourceInfo()));
arrayUpdate(arr, 1, (cache,env,p,SOME(singletonType)));
else
SOME(singletonType) := ot;
end if;
end fixUniontype2;

public function checkArrayType
"Checks that an array type is valid."
input DAE.Type inType;
protected
DAE.Type el_ty;
algorithm
el_ty := Types.arrayElementType(inType);
false := (not Types.isString(el_ty) and Types.isBoxedType(el_ty)) or
Flags.isSet(Flags.RML);
end checkArrayType;

annotation(__OpenModelica_Interface="frontend");
end InstMeta;
75 changes: 0 additions & 75 deletions OMCompiler/Compiler/FrontEnd/MetaUtil.mo
Expand Up @@ -37,21 +37,14 @@ encapsulated package MetaUtil

import Absyn;
import AbsynUtil;
import ClassInf;
import DAE;
import FCore;
import SCode;

protected

import Config;
import Error;
import Flags;
import List;
import MetaModelica.Dangerous;
import Lookup;
import SCodeUtil;
import Types;

public function createMetaClassesInProgram
"This function goes through a program and changes all records inside of
Expand Down Expand Up @@ -285,74 +278,6 @@ algorithm
end match for e in inElementItems);
end fixElementItems;

public function fixUniontype
input FCore.Cache inCache;
input FCore.Graph inEnv;
input ClassInf.State inState;
input SCode.ClassDef inClassDef;
output FCore.Cache cache = inCache;
output Option<DAE.Type> outType;
algorithm
outType := match (inState, inClassDef)
local
Boolean b;
Absyn.Path p,p2;
list<Absyn.Path> paths;
list<DAE.Type> typeVarsTypes;
list<String> names, typeVars;
DAE.EvaluateSingletonType singletonType;
SCode.Element c;
FCore.Graph env_1;

case (ClassInf.META_UNIONTYPE(typeVars=typeVars), SCode.PARTS())
algorithm
p := AbsynUtil.makeFullyQualified(inState.path);
names := SCodeUtil.elementNames(list(e for e guard match e case SCode.CLASS(restriction=SCode.R_METARECORD()) then true; else false; end match in inClassDef.elementLst));
paths := list(AbsynUtil.suffixPath(p, n) for n in names);
b := listLength(paths)==1;
if b then
p2 := listGet(paths, 1);
singletonType := DAE.EVAL_SINGLETON_TYPE_FUNCTION(function fixUniontype2(arr=arrayCreate(1, (cache,inEnv,p2,NONE()))));
else
singletonType := DAE.NOT_SINGLETON();
end if;
typeVarsTypes := list(DAE.T_METAPOLYMORPHIC(tv) for tv in typeVars);
then
SOME(DAE.T_METAUNIONTYPE(paths,typeVarsTypes,b,singletonType,p));

else NONE();
end match;
end fixUniontype;

protected function fixUniontype2
input array<tuple<FCore.Cache, FCore.Graph, Absyn.Path, Option<DAE.Type>>> arr;
output DAE.Type singletonType;
protected
FCore.Cache cache;
FCore.Graph env;
Absyn.Path p;
Option<DAE.Type> ot;
algorithm
(cache,env,p,ot) := arrayGet(arr, 1);
if isNone(ot) then
(_, singletonType) := Lookup.lookupType(cache, env, p, SOME(sourceInfo()));
arrayUpdate(arr, 1, (cache,env,p,SOME(singletonType)));
else
SOME(singletonType) := ot;
end if;
end fixUniontype2;

public function checkArrayType
"Checks that an array type is valid."
input DAE.Type inType;
protected
DAE.Type el_ty;
algorithm
el_ty := Types.arrayElementType(inType);
false := (not Types.isString(el_ty) and Types.isBoxedType(el_ty)) or
Flags.isSet(Flags.RML);
end checkArrayType;

public function transformArrayNodesToListNodes
input list<Absyn.Exp> inList;
output list<Absyn.Exp> outList;
Expand Down
18 changes: 11 additions & 7 deletions OMCompiler/Compiler/FrontEnd/Static.mo
Expand Up @@ -62,19 +62,23 @@ encapsulated package Static
The elaboration also contain function deoverloading which will be added to Modelica in the future."

import Absyn;
import AbsynUtil;
import DAE;
import FCore;
import FGraph;
import FNode;
import MetaUtil;
import Prefix;
import SCode;
import AbsynToSCode;
import Util;
import Values;

protected

import AbsynToSCode;
import AbsynUtil;
import FGraph;
import FNode;
import InstMeta;
import MetaUtil;
import Util;


constant Integer SLOT_NOT_EVALUATED = 0;
constant Integer SLOT_EVALUATING = 1;
constant Integer SLOT_EVALUATED = 2;
Expand Down Expand Up @@ -728,7 +732,7 @@ algorithm
(expl, DAE.PROP(ty, c)) := elabArray(expl, props, inPrefix, inInfo); // type-checking the array
arr_ty := DAE.T_ARRAY(ty, {DAE.DIM_INTEGER(listLength(expl))});
exp := DAE.ARRAY(Types.simplifyType(arr_ty), not Types.isArray(ty), expl);
MetaUtil.checkArrayType(ty);
InstMeta.checkArrayType(ty);
exp := elabMatrixToMatrixExp(exp);
then
(exp, DAE.PROP(arr_ty, c));
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/boot/LoadCompilerSources.mos
Expand Up @@ -39,6 +39,7 @@ if true then /* Suppress output */
"../FrontEnd/InstBinding.mo",
"../FrontEnd/InstFunction.mo",
"../FrontEnd/InstHashTable.mo",
"../FrontEnd/InstMeta.mo",
"../FrontEnd/InstUtil.mo",
"../FrontEnd/InstExtends.mo",
"../FrontEnd/InstSection.mo",
Expand Down

0 comments on commit f83a024

Please sign in to comment.