Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Look for duplicate elements in the package.order file


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13079 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 28, 2012
1 parent 791bc88 commit 860b040
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Compiler/FrontEnd/ClassLoader.mo
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ protected function getPackageContentNames
algorithm
(po) := matchcontinue (cl,filename,mp,numError)
local
String contents;
list<String> namesToFind, mofiles, subdirs;
String contents, duplicatesStr;
list<String> duplicates, namesToFind, mofiles, subdirs;
list<Absyn.ClassPart> cp;
Absyn.Info info;
case (Absyn.CLASS(body=Absyn.PARTS(classParts=cp),info=info),_,_,_)
Expand All @@ -410,6 +410,9 @@ algorithm
contents = System.readFile(filename);
namesToFind = System.strtok(contents, "\n");
namesToFind = List.removeOnTrue("",stringEqual,List.map(namesToFind,System.trimWhitespace));
duplicates = List.sortedFilterDuplicates(List.sort(namesToFind,Util.strcmpBool),stringEq);
duplicatesStr = stringDelimitList(duplicates, ", ");
Error.assertionOrAddSourceMessage(List.isEmpty(duplicates),Error.PACKAGE_ORDER_DUPLICATES,{duplicatesStr},Absyn.INFO(filename,true,0,0,0,0,Absyn.dummyTimeStamp));
po = getPackageContentNamesinParts(namesToFind,cp,{});
List.map2_0(po,checkPackageOrderFilesExist,mp,info);
then po;
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Util/Error.mo
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ public constant Message WARNING_DEF_USE = MESSAGE(244, TRANSLATION(), WARNING(),
Util.gettext("%s was used before it was defined (given a value). Additional such uses may exist for the variable, but some messages were suppressed."));
public constant Message EXP_TYPE_MISMATCH = MESSAGE(245, TRANSLATION(), ERROR(),
Util.gettext("Expression %1 has type %3, expected type %2."));

public constant Message PACKAGE_ORDER_DUPLICATES = MESSAGE(246, TRANSLATION(), ERROR(),
Util.gettext("Found duplicate names in package.order file: %s."));
public constant Message UNBOUND_PARAMETER_WARNING = MESSAGE(500, TRANSLATION(), WARNING(),
Util.gettext("Parameter %s has neither value nor start value, and is fixed during initialization (fixed=true)"));
public constant Message BUILTIN_FUNCTION_PRODUCT_HAS_SCALAR_PARAMETER = MESSAGE(502, TRANSLATION(), WARNING(),
Expand Down
43 changes: 43 additions & 0 deletions Compiler/Util/List.mo
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,49 @@ algorithm
end match;
end sort;

public function sortedFilterDuplicates
"Checks if the list has any duplicates in it"
input list<ElementType> inList;
input CompareFunc inCompFunc "Equality comparator";
output list<ElementType> duplicates;

partial function CompareFunc
input ElementType inElement1;
input ElementType inElement2;
output Boolean outRes;
end CompareFunc;
algorithm
duplicates := sortedFilterDuplicatesWork(inList,inCompFunc,{});
end sortedFilterDuplicates;

protected function sortedFilterDuplicatesWork
"Checks if the list has any duplicates in it"
input list<ElementType> inList;
input CompareFunc inCompFunc "Equality comparator";
input list<ElementType> inAcc;
output list<ElementType> duplicates;

partial function CompareFunc
input ElementType inElement1;
input ElementType inElement2;
output Boolean outRes;
end CompareFunc;
algorithm
duplicates := match(inList, inCompFunc, inAcc)
local
ElementType e1,e2;
list<ElementType> rest;
Boolean b;

case ({}, _, _) then listReverse(inAcc);
case (_::{}, _, _) then listReverse(inAcc);
case (e1::(rest as e2::_), _, _)
equation
b = inCompFunc(e1,e2);
then sortedFilterDuplicatesWork(rest, inCompFunc, consOnTrue(b, e1, inAcc));
end match;
end sortedFilterDuplicatesWork;

protected function merge
"Helper function to sort, merges two sorted lists."
input list<ElementType> inLeft;
Expand Down

0 comments on commit 860b040

Please sign in to comment.