@@ -17345,6 +17345,8 @@ protected
1734517345 String dir,filename;
1734617346 Boolean lveStarted;
1734717347 Option<Integer> lveInstance = NONE();
17348+ list<String> features;
17349+ String libraryKey, licenseFile;
1734817350algorithm
1734917351 if not System.regularFileExists(fileName) then
1735017352 topClassNamesQualified := {};
@@ -17359,11 +17361,22 @@ algorithm
1735917361 end if;
1736017362 end if;
1736117363 parsed := Parser.parse(fileName,encoding,dir,lveInstance);
17364+ parsed := MetaUtil.createMetaClassesInProgram(parsed);
17365+ topClassNamesQualified := getTopQualifiedClassnames(parsed);
1736217366 if (lveStarted) then
17367+ for topClassNameQualified in topClassNamesQualified loop
17368+ // check license
17369+ //print("Parser.checkLVEToolLicense returned = " + boolString(Parser.checkLVEToolLicense(lveInstance, AbsynUtil.pathString(topClassNameQualified))) + "\n");
17370+ //(libraryKey, licenseFile) := getLicenseAnnotation(topClassNameQualified, parsed);
17371+ //print("Library Key is : " + libraryKey + "\n");
17372+ //print("License File is : " + licenseFile + "\n");
17373+ features := getFeaturesAnnotation(topClassNameQualified, parsed);
17374+ for feature in features loop
17375+ Parser.checkLVEToolFeature(lveInstance, feature);
17376+ end for;
17377+ end for;
1736317378 Parser.stopLibraryVendorExecutable(lveInstance);
1736417379 end if;
17365- parsed := MetaUtil.createMetaClassesInProgram(parsed);
17366- topClassNamesQualified := getTopQualifiedClassnames(parsed);
1736717380 if updateProgram then
1736817381 SymbolTable.setAbsyn(.Interactive.updateProgram(parsed, SymbolTable.getAbsyn()));
1736917382 end if;
@@ -18291,6 +18304,209 @@ algorithm
1829118304 end match;
1829218305end getAccessAnnotationString2;
1829318306
18307+ public function getLicenseAnnotation
18308+ "Returns the Protection(License=) annotation of a class.
18309+ This is annotated with the annotation:
18310+ annotation(Protection(License(libraryKey=\"15783-A39323-498222-444ckk4ll\", licenseFile=\"MyLibraryAuthorization_Tool.mo_lic\"))); in the class definition"
18311+ input Absyn.Path className;
18312+ input Absyn.Program p;
18313+ output tuple<String, String> license;
18314+ algorithm
18315+ license := match(className,p)
18316+ local
18317+ tuple<String, String> licenseAnn;
18318+ case(_,_)
18319+ equation
18320+ licenseAnn = getNamedAnnotation(className, p, Absyn.IDENT("Protection"), SOME(("","")), getLicenseAnnotationWork1);
18321+ then
18322+ licenseAnn;
18323+ else ("", "");
18324+ end match;
18325+ end getLicenseAnnotation;
18326+
18327+ protected function getLicenseAnnotationWork1
18328+ "Extractor function for getLicenseAnnotation"
18329+ input Option<Absyn.Modification> mod;
18330+ output tuple<String, String> license;
18331+ algorithm
18332+ license := match (mod)
18333+ local
18334+ list<Absyn.ElementArg> arglst;
18335+ String libraryKey, licenseFile;
18336+
18337+ case (SOME(Absyn.CLASSMOD(elementArgLst = arglst)))
18338+ equation
18339+ (libraryKey, licenseFile) = getLicenseAnnotationWork2(arglst);
18340+ then (libraryKey, licenseFile);
18341+ end match;
18342+ end getLicenseAnnotationWork1;
18343+
18344+ protected function getLicenseAnnotationWork2
18345+ "Extractor function for getLicenseAnnotation"
18346+ input list<Absyn.ElementArg> eltArgs;
18347+ output tuple<String, String> license;
18348+ algorithm
18349+ license := match eltArgs
18350+ local
18351+ Option<Absyn.Modification> mod;
18352+ list<Absyn.ElementArg> xs;
18353+ String libraryKey, licenseFile;
18354+
18355+ case ({}) then ("", "");
18356+
18357+ case (Absyn.MODIFICATION(path = Absyn.IDENT(name="License"), modification = mod)::_)
18358+ equation
18359+ (libraryKey, licenseFile) = getLicenseAnnotationTuple(mod);
18360+ then (libraryKey, licenseFile);
18361+
18362+ case (_::xs)
18363+ equation
18364+ (libraryKey, licenseFile) = getLicenseAnnotationWork2(xs);
18365+ then (libraryKey, licenseFile);
18366+
18367+ end match;
18368+ end getLicenseAnnotationWork2;
18369+
18370+ protected function getLicenseAnnotationTuple
18371+ "Extractor function for getLicenseAnnotation"
18372+ input Option<Absyn.Modification> mod;
18373+ output tuple<String, String> license;
18374+ algorithm
18375+ license := match (mod)
18376+ local
18377+ list<Absyn.ElementArg> arglst;
18378+ String libraryKey, licenseFile;
18379+
18380+ case (SOME(Absyn.CLASSMOD(elementArgLst = arglst)))
18381+ equation
18382+ libraryKey = getLicenseAnnotationLibraryKey(arglst);
18383+ licenseFile = getLicenseAnnotationLicenseFile(arglst);
18384+ then (libraryKey, licenseFile);
18385+ end match;
18386+ end getLicenseAnnotationTuple;
18387+
18388+ protected function getLicenseAnnotationLibraryKey
18389+ "Extractor function for getLicenseAnnotation"
18390+ input list<Absyn.ElementArg> eltArgs;
18391+ output String libraryKey;
18392+ algorithm
18393+ libraryKey := match eltArgs
18394+ local
18395+ list<Absyn.ElementArg> xs;
18396+ String s;
18397+
18398+ case ({}) then "";
18399+
18400+ case (Absyn.MODIFICATION(path = Absyn.IDENT(name="libraryKey"),
18401+ modification = SOME(Absyn.CLASSMOD(eqMod=Absyn.EQMOD(exp=Absyn.STRING(s)))))::_)
18402+ then s;
18403+
18404+ case (_::xs)
18405+ equation
18406+ s = getLicenseAnnotationLibraryKey(xs);
18407+ then s;
18408+
18409+ end match;
18410+ end getLicenseAnnotationLibraryKey;
18411+
18412+ protected function getLicenseAnnotationLicenseFile
18413+ "Extractor function for getLicenseAnnotation"
18414+ input list<Absyn.ElementArg> eltArgs;
18415+ output String licenseFile;
18416+ algorithm
18417+ licenseFile := match eltArgs
18418+ local
18419+ list<Absyn.ElementArg> xs;
18420+ String s;
18421+
18422+ case ({}) then "";
18423+
18424+ case (Absyn.MODIFICATION(path = Absyn.IDENT(name="licenseFile"),
18425+ modification = SOME(Absyn.CLASSMOD(eqMod=Absyn.EQMOD(exp=Absyn.STRING(s)))))::_)
18426+ then s;
18427+
18428+ case (_::xs)
18429+ equation
18430+ s = getLicenseAnnotationLicenseFile(xs);
18431+ then s;
18432+
18433+ end match;
18434+ end getLicenseAnnotationLicenseFile;
18435+
18436+ public function getFeaturesAnnotation
18437+ "Returns the Protection(features=) annotation of a class.
18438+ This is annotated with the annotation:
18439+ annotation(Protection(features={\"LicenseOption1 LicenseOption2\", \"LicenseOption3\"})); in the class definition"
18440+ input Absyn.Path className;
18441+ input Absyn.Program p;
18442+ output list<String> features;
18443+ algorithm
18444+ features := match(className,p)
18445+ local
18446+ list<String> featuresList;
18447+ case(_,_)
18448+ equation
18449+ featuresList = getNamedAnnotation(className, p, Absyn.IDENT("Protection"), SOME({}), getFeaturesAnnotationList);
18450+ then
18451+ featuresList;
18452+ else {};
18453+ end match;
18454+ end getFeaturesAnnotation;
18455+
18456+ protected function getFeaturesAnnotationList
18457+ "Extractor function for getFeaturesAnnotation"
18458+ input Option<Absyn.Modification> mod;
18459+ output list<String> features;
18460+ algorithm
18461+ features := match (mod)
18462+ local
18463+ list<Absyn.ElementArg> arglst;
18464+
18465+ case (SOME(Absyn.CLASSMOD(elementArgLst = arglst)))
18466+ then getFeaturesAnnotationList2(arglst);
18467+
18468+ end match;
18469+ end getFeaturesAnnotationList;
18470+
18471+ protected function getFeaturesAnnotationList2
18472+ "Extractor function for getFeaturesAnnotation"
18473+ input list<Absyn.ElementArg> eltArgs;
18474+ output list<String> features;
18475+ algorithm
18476+ features := match eltArgs
18477+ local
18478+ list<Absyn.Exp> expList;
18479+ list<Absyn.ElementArg> xs;
18480+ list<String> featuresList;
18481+
18482+ case ({}) then {};
18483+
18484+ case (Absyn.MODIFICATION(path = Absyn.IDENT(name="features"),
18485+ modification = SOME(Absyn.CLASSMOD(eqMod=Absyn.EQMOD(exp=Absyn.ARRAY(expList)))))::_)
18486+ equation
18487+ featuresList = List.map(expList, expToString);
18488+ then featuresList;
18489+
18490+ case (_::xs)
18491+ equation
18492+ featuresList = getFeaturesAnnotationList2(xs);
18493+ then featuresList;
18494+
18495+ end match;
18496+ end getFeaturesAnnotationList2;
18497+
18498+ protected function expToString
18499+ input Absyn.Exp inExp;
18500+ output String outExp;
18501+ algorithm
18502+ outExp := match (inExp)
18503+ local
18504+ String str;
18505+ case (Absyn.STRING(str)) then str;
18506+ case (_) then "";
18507+ end match;
18508+ end expToString;
18509+
1829418510public function checkAccessAnnotationAndEncryption
1829518511 input Absyn.Path path;
1829618512 input Absyn.Program p;
0 commit comments