Skip to content

Commit

Permalink
Fix for issue #2043:
Browse files Browse the repository at this point in the history
- Handle extends when checking external objects in NFSCodeDependency.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15038 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Feb 1, 2013
1 parent f8646aa commit 3fb9764
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
26 changes: 25 additions & 1 deletion Compiler/FrontEnd/NFSCodeDependency.mo
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,34 @@ algorithm
// actually found and removed any 'extends ExternalObject'.
false := (listLength(el) == listLength(inElements));
// Ok, we have an external object, check that it's valid.
el_names := List.map(el, SCode.elementName);
el_names := List.filterMap(el, elementName);
checkExternalObject(el_names, inEnv, inInfo);
end isExternalObject;

protected function elementName
input SCode.Element inElement;
output String outString;
algorithm
outString := match(inElement)
local
String name;
Absyn.Path bc;
Absyn.Import imp;

case SCode.COMPONENT(name = name) then name;
case SCode.CLASS(name = name) then name;
case SCode.DEFINEUNIT(name = name) then name;

case SCode.EXTENDS(baseClassPath = bc)
equation
name = Absyn.pathString(bc);
name = "extends " +& name;
then
name;

end match;
end elementName;

protected function isNotExternalObject
"Fails on 'extends ExternalObject', otherwise succeeds."
input SCode.Element inElement;
Expand Down
48 changes: 47 additions & 1 deletion Compiler/Util/List.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5281,7 +5281,6 @@ algorithm
end match;
end foldcallN;


public function reduce
"Takes a list and a function operating on two elements of the list.
The function performs a reduction of the list to a single value using the
Expand Down Expand Up @@ -6980,6 +6979,53 @@ algorithm
end matchcontinue;
end filter_tail;

public function filterMap
"Applies a function to each element in the given list, but also filters out
all elements for which the function fails."
input list<ElementInType> inList;
input FilterMapFunc inFilterMapFunc;
output list<ElementOutType> outList;

partial function FilterMapFunc
input ElementInType inElement;
output ElementOutType outElement;
end FilterMapFunc;
algorithm
outList := listReverse(filterMap_tail(inList, inFilterMapFunc, {}));
end filterMap;

protected function filterMap_tail
"Tail recursive implementation of filterMap."
input list<ElementInType> inList;
input FilterMapFunc inFilterMapFunc;
input list<ElementOutType> inAccumList;
output list<ElementOutType> outList;

partial function FilterMapFunc
input ElementInType inElement;
output ElementOutType outElement;
end FilterMapFunc;
algorithm
outList := matchcontinue(inList, inFilterMapFunc, inAccumList)
local
ElementInType ie;
list<ElementInType> rest;
ElementOutType oe;

case (ie :: rest, _, _)
equation
oe = inFilterMapFunc(ie);
then
filterMap_tail(rest, inFilterMapFunc, oe :: inAccumList);

case (_ :: rest, _, _)
then filterMap_tail(rest, inFilterMapFunc, inAccumList);

case ({}, _, _) then inAccumList;

end matchcontinue;
end filterMap_tail;

public function filterOnTrue
"Takes a list of values and a filter function over the values and returns a
sub list of values for which the matching function returns true.
Expand Down

0 comments on commit 3fb9764

Please sign in to comment.