Skip to content

Commit

Permalink
[NF] ExternalObject fixes.
Browse files Browse the repository at this point in the history
- Added missing calls to typeFunctionBody when typing ExternalObject
  structors, so the whole function is typed and not only the inputs.
- Collect ExternalObject structors in functions too.

Belonging to [master]:
  - OpenModelica/OMCompiler#2373
  • Loading branch information
perost authored and OpenModelica-Hudson committed Apr 17, 2018
1 parent a473365 commit 9216359
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -843,16 +843,7 @@ algorithm
algorithm
// TODO: Collect functions from the component's type attributes.

// Collect external object structors.
() := match ty
case Type.COMPLEX(complexTy = ComplexType.EXTERNAL_OBJECT())
algorithm
funcs := collectExternalObjectStructors(ty.complexTy, funcs);
then
();

else ();
end match;
funcs := collectTypeFuncs(ty, funcs);

// Collect functions used in the component's binding, if it has one.
if Binding.isBound(binding) then
Expand All @@ -864,6 +855,22 @@ algorithm
end match;
end collectComponentFuncs;

function collectTypeFuncs
input Type ty;
input output FunctionTree funcs;
algorithm
() := match ty
// Collect external object structors.
case Type.COMPLEX(complexTy = ComplexType.EXTERNAL_OBJECT())
algorithm
funcs := collectExternalObjectStructors(ty.complexTy, funcs);
then
();

else ();
end match;
end collectTypeFuncs;

function collectExternalObjectStructors
input ComplexType ty;
input output FunctionTree funcs;
Expand Down Expand Up @@ -1079,6 +1086,7 @@ algorithm
algorithm
for c in cls_tree.components loop
comp := InstNode.component(c);
funcs := collectTypeFuncs(Component.getType(comp), funcs);
binding := Component.getBinding(comp);

if Binding.isBound(binding) then
Expand Down
10 changes: 10 additions & 0 deletions Compiler/NFFrontEnd/NFRestriction.mo
Expand Up @@ -118,6 +118,16 @@ public
end match;
end isFunction;

function isRecord
input Restriction res;
output Boolean isFunction;
algorithm
isFunction := match res
case RECORD() then true;
else false;
end match;
end isRecord;

function isType
input Restriction res;
output Boolean isType;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -215,12 +215,14 @@ algorithm
CachedData.FUNCTION({fn}, typed, special) := InstNode.getFuncCache(constructor);
if not typed then
fn := Function.typeFunction(fn);
fn := Function.typeFunctionBody(fn);
InstNode.setFuncCache(constructor, CachedData.FUNCTION({fn}, true, special));
end if;

CachedData.FUNCTION({fn}, typed, special) := InstNode.getFuncCache(destructor);
if not typed then
fn := Function.typeFunction(fn);
fn := Function.typeFunctionBody(fn);
InstNode.setFuncCache(destructor, CachedData.FUNCTION({fn}, true, special));
end if;
end typeExternalObjectStructors;
Expand Down

0 comments on commit 9216359

Please sign in to comment.