Changeset 528d8ead in OpenModelica


Ignore:
Timestamp:
2020-04-29T11:42:24+02:00 (4 years ago)
Author:
Martin Sjölund <martin.sjolund@…>
Parents:
7ab7997
git-author:
Martin Sjölund <martin.sjolund@…> (04/29/20 09:53:35)
git-committer:
Martin Sjölund <martin.sjolund@…> (04/29/20 11:42:24)
Message:

Make package.order errors into warnings

If for some reason the package.order handling fails, default to the same
order as if there was no package.order file.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/FrontEnd/ClassLoader.mo

    r98d8681d r528d8ead  
    452452
    453453    case (Absyn.CLASS(body=Absyn.PARTS(classParts=cp),info=info),_,_,_)
    454       equation
    455         if (System.regularFileExists(filename)) then
    456           contents = System.readFile(filename);
    457           namesToFind = System.strtok(contents, "\n");
    458           namesToFind = List.removeOnTrue("",stringEqual,List.map(namesToFind,System.trimWhitespace));
    459           duplicates = List.sortedDuplicates(List.sort(namesToFind,Util.strcmpBool),stringEq);
    460           duplicatesStr = stringDelimitList(duplicates, ", ");
     454      algorithm
     455        try
     456          true := System.regularFileExists(filename);
     457          contents := System.readFile(filename);
     458          namesToFind := System.strtok(contents, "\n");
     459          namesToFind := List.removeOnTrue("",stringEqual,List.map(namesToFind,System.trimWhitespace));
     460          duplicates := List.sortedDuplicates(List.sort(namesToFind,Util.strcmpBool),stringEq);
     461          duplicatesStr := stringDelimitList(duplicates, ", ");
    461462          Error.assertionOrAddSourceMessage(listEmpty(duplicates),Error.PACKAGE_ORDER_DUPLICATES,{duplicatesStr},SOURCEINFO(filename,true,0,0,0,0,0.0));
    462463
    463464          if encrypted then
    464465            // get all the .moc files in the directory!
    465             mofiles = List.map(System.mocFiles(mp), Util.removeLast4Char);
     466            mofiles := List.map(System.mocFiles(mp), Util.removeLast4Char);
    466467          else
    467468            // get all the .mo files in the directory!
    468             mofiles = List.map(System.moFiles(mp), Util.removeLast3Char);
     469            mofiles := List.map(System.moFiles(mp), Util.removeLast3Char);
    469470          end if;
    470471          // get all the subdirs
    471           subdirs = System.subDirectories(mp);
    472           subdirs = List.filter2OnTrue(subdirs, existPackage, mp, encrypted);
     472          subdirs := System.subDirectories(mp);
     473          subdirs := List.filter2OnTrue(subdirs, existPackage, mp, encrypted);
    473474          // build a list
    474           intersection = List.intersectionOnTrue(subdirs,mofiles,stringEq);
    475           differencesStr = stringDelimitList(List.map1(intersection, getBothPackageAndFilename, mp), ", ");
     475          intersection := List.intersectionOnTrue(subdirs,mofiles,stringEq);
     476          differencesStr := stringDelimitList(List.map1(intersection, getBothPackageAndFilename, mp), ", ");
    476477          Error.assertionOrAddSourceMessage(listEmpty(intersection),Error.PACKAGE_DUPLICATE_CHILDREN,{differencesStr},SOURCEINFO(filename,true,0,0,0,0,0.0));
    477           mofiles = listAppend(subdirs,mofiles);
     478          mofiles := listAppend(subdirs,mofiles);
    478479          // check if all are present in the package.order
    479           differences = List.setDifference(mofiles, namesToFind);
    480           (po1) = getPackageContentNamesinParts(namesToFind,cp,{});
    481           (po1,differences) = List.map3Fold(po1,checkPackageOrderFilesExist,mp,info,encrypted,differences);
     480          differences := List.setDifference(mofiles, namesToFind);
     481          (po1) := getPackageContentNamesinParts(namesToFind,cp,{});
     482          (po1,differences) := List.map3Fold(po1,checkPackageOrderFilesExist,mp,info,encrypted,differences);
    482483
    483484          // issue a warning if not all are present
    484           differencesStr = stringDelimitList(differences, "\n\t");
     485          differencesStr := stringDelimitList(differences, "\n\t");
    485486          Error.assertionOrAddSourceMessage(listEmpty(differences),Error.PACKAGE_ORDER_FILE_NOT_COMPLETE,{differencesStr},SOURCEINFO(filename,true,0,0,0,0,0.0));
    486487
    487           po2 = List.map(differences, makeClassLoad);
    488 
    489           po = listAppend(po2, po1);
     488          po2 := List.map(differences, makeClassLoad);
     489
     490          po := listAppend(po2, po1);
    490491        else // file not found
    491           mofiles = List.map(System.moFiles(mp), Util.removeLast3Char) "Here .mo files in same directory as package.mo should be loaded as sub-packages";
    492           subdirs = System.subDirectories(mp);
    493           subdirs = List.filter2OnTrue(subdirs, existPackage, mp, encrypted);
    494           mofiles = List.sort(listAppend(subdirs,mofiles), Util.strcmpBool);
     492          mofiles := List.map(System.moFiles(mp), Util.removeLast3Char) "Here .mo files in same directory as package.mo should be loaded as sub-packages";
     493          subdirs := System.subDirectories(mp);
     494          subdirs := List.filter2OnTrue(subdirs, existPackage, mp, encrypted);
     495          mofiles := List.sort(listAppend(subdirs,mofiles), Util.strcmpBool);
    495496          // Look for duplicates
    496           intersection = List.sortedDuplicates(mofiles,stringEq);
    497           differencesStr = stringDelimitList(List.map1(intersection, getBothPackageAndFilename, mp), ", ");
     497          intersection := List.sortedDuplicates(mofiles,stringEq);
     498          differencesStr := stringDelimitList(List.map1(intersection, getBothPackageAndFilename, mp), ", ");
    498499          Error.assertionOrAddSourceMessage(listEmpty(intersection),Error.PACKAGE_DUPLICATE_CHILDREN,{differencesStr},info);
    499500
    500           po = listAppend(List.map(cp, makeClassPart),List.map(mofiles, makeClassLoad));
    501         end if;
     501          po := listAppend(List.map(cp, makeClassPart),List.map(mofiles, makeClassLoad));
     502        end try;
    502503      then
    503504        po;
     
    653654        Error.assertionOrAddSourceMessage(not listMember(load,po), Error.PACKAGE_MO_NOT_IN_ORDER, {name2}, info);
    654655        Error.addSourceMessage(Error.FOUND_ELEMENT_NOT_IN_ORDER_FILE, {name2}, info);
    655       then fail();
     656        (outOrder,names) = getPackageContentNamesinElts(name2 :: inNamesToSort, inElts, po, pub);
     657      then (outOrder,names);
    656658
    657659    case ({},Absyn.ELEMENTITEM(Absyn.ELEMENT(specification=Absyn.COMPONENTS(components=Absyn.COMPONENTITEM(component=Absyn.COMPONENT(name=name2))::_),info=info))::_,_,_)
     
    660662        Error.assertionOrAddSourceMessage(not listMember(load,po), Error.PACKAGE_MO_NOT_IN_ORDER, {name2}, info);
    661663        Error.addSourceMessage(Error.FOUND_ELEMENT_NOT_IN_ORDER_FILE, {name2}, info);
    662       then fail();
     664        (outOrder,names) = getPackageContentNamesinElts(name2 :: inNamesToSort, inElts, po, pub);
     665      then (outOrder,names);
    663666
    664667    case (namesToSort,ei::elts,_,_)
  • OMCompiler/Compiler/Util/Error.mo

    r98d8681d r528d8ead  
    547547public constant ErrorTypes.Message LIBRARY_UNEXPECTED_NAME = ErrorTypes.MESSAGE(236, ErrorTypes.SCRIPTING(), ErrorTypes.ERROR(),
    548548  Gettext.gettext("Expected the package to have name %s, but got %s."));
    549 public constant ErrorTypes.Message PACKAGE_MO_NOT_IN_ORDER = ErrorTypes.MESSAGE(237, ErrorTypes.GRAMMAR(), ErrorTypes.ERROR(),
     549public constant ErrorTypes.Message PACKAGE_MO_NOT_IN_ORDER = ErrorTypes.MESSAGE(237, ErrorTypes.GRAMMAR(), ErrorTypes.WARNING(),
    550550  Gettext.gettext("Elements in the package.mo-file need to be in the same relative order as the package.order file. Got element named %s but it was already added because it was not the next element in the list at that time."));
    551551public constant ErrorTypes.Message LIBRARY_EXPECTED_PARTS = ErrorTypes.MESSAGE(238, ErrorTypes.GRAMMAR(), ErrorTypes.ERROR(),
    552552  Gettext.gettext("%s is a package.mo-file and needs to be based on class parts (i.e. not class extends, derived class, or enumeration)."));
    553 public constant ErrorTypes.Message PACKAGE_ORDER_FILE_NOT_FOUND = ErrorTypes.MESSAGE(239, ErrorTypes.GRAMMAR(), ErrorTypes.ERROR(),
     553public constant ErrorTypes.Message PACKAGE_ORDER_FILE_NOT_FOUND = ErrorTypes.MESSAGE(239, ErrorTypes.GRAMMAR(), ErrorTypes.WARNING(),
    554554  Gettext.gettext("%1 was referenced in the package.order file, but was not found in package.mo, %1/package.mo or %1.mo."));
    555 public constant ErrorTypes.Message FOUND_ELEMENT_NOT_IN_ORDER_FILE = ErrorTypes.MESSAGE(240, ErrorTypes.GRAMMAR(), ErrorTypes.ERROR(),
     555public constant ErrorTypes.Message FOUND_ELEMENT_NOT_IN_ORDER_FILE = ErrorTypes.MESSAGE(240, ErrorTypes.GRAMMAR(), ErrorTypes.WARNING(),
    556556  Gettext.gettext("Got element %1 that was not referenced in the package.order file."));
    557 public constant ErrorTypes.Message ORDER_FILE_COMPONENTS = ErrorTypes.MESSAGE(241, ErrorTypes.GRAMMAR(), ErrorTypes.ERROR(),
     557public constant ErrorTypes.Message ORDER_FILE_COMPONENTS = ErrorTypes.MESSAGE(241, ErrorTypes.GRAMMAR(), ErrorTypes.WARNING(),
    558558  Gettext.gettext("Components referenced in the package.order file must be moved in full chunks. Either split the constants to different lines or make them subsequent in the package.order file."));
    559559public constant ErrorTypes.Message GUARD_EXPRESSION_TYPE_MISMATCH = ErrorTypes.MESSAGE(242, ErrorTypes.GRAMMAR(), ErrorTypes.ERROR(),
     
    567567public constant ErrorTypes.Message EXP_TYPE_MISMATCH = ErrorTypes.MESSAGE(246, ErrorTypes.TRANSLATION(), ErrorTypes.ERROR(),
    568568  Gettext.gettext("Expression '%1' has type %3, expected type %2."));
    569 public constant ErrorTypes.Message PACKAGE_ORDER_DUPLICATES = ErrorTypes.MESSAGE(247, ErrorTypes.TRANSLATION(), ErrorTypes.ERROR(),
     569public constant ErrorTypes.Message PACKAGE_ORDER_DUPLICATES = ErrorTypes.MESSAGE(247, ErrorTypes.TRANSLATION(), ErrorTypes.WARNING(),
    570570  Gettext.gettext("Found duplicate names in package.order file: %s."));
    571571public constant ErrorTypes.Message ERRONEOUS_TYPE_ERROR = ErrorTypes.MESSAGE(248, ErrorTypes.TRANSLATION(), ErrorTypes.ERROR(),
  • testsuite/flattening/modelica/mosfiles/TestLoadModel.mos

    r83ebb9b r528d8ead  
    9595// true
    9696// "3.5 beta1"
    97 // false
    98 // "[TestLibrary//Modelica 3.5 beta1/package.order:0:0-0:0:readonly] Error: Found duplicate names in package.order file: A.
    99 // Error: Failed to load package Modelica (3.5 beta1) using MODELICAPATH TestLibrary/.
     97// true
     98// "[TestLibrary//Modelica 3.5 beta1/package.order:0:0-0:0:readonly] Warning: Found duplicate names in package.order file: A.
    10099// "
    101100// "CustomSort"
Note: See TracChangeset for help on using the changeset viewer.