Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
handle list and listFile if we have encryption
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - #2510
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Jun 17, 2018
1 parent 8c6ff41 commit 7ee060b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -734,6 +734,16 @@ algorithm
SymbolTable.setVars({});
then (cache,Values.BOOL(true));

// handle encryption
case (cache,_,"list",_,_)
equation
// if AST contains encrypted class show nothing
p = SymbolTable.getAbsyn();
true = Interactive.astContainsEncryptedClass(p);
Error.addMessage(Error.ACCESS_ENCRYPTED_PROTECTED_CONTENTS, {});
then
(cache,Values.STRING(""));

case (cache,_,"list",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT("AllLoadedClasses"))),Values.BOOL(false),Values.BOOL(false),Values.ENUM_LITERAL(name=path)},_)
equation
name = Absyn.pathLastIdent(path);
Expand Down Expand Up @@ -776,8 +786,15 @@ algorithm
case Absyn.FULLYQUALIFIED() then className.path;
else className;
end match;
(absynClass as Absyn.CLASS(info=SOURCEINFO(fileName=str))) = Interactive.getPathedClassInProgram(className, SymbolTable.getAbsyn());
str = Dump.unparseStr(Absyn.PROGRAM({absynClass}, match path case Absyn.IDENT() then Absyn.TOP(); else Absyn.WITHIN(Absyn.stripLast(path)); end match), options=Dump.DUMPOPTIONS(str));
// handle encryption
Values.ENUM_LITERAL(index=access) = Interactive.checkAccessAnnotationAndEncryption(path, SymbolTable.getAbsyn());
if (access >= 9) then // i.e., The class is not encrypted.
(absynClass as Absyn.CLASS(info=SOURCEINFO(fileName=str))) = Interactive.getPathedClassInProgram(className, SymbolTable.getAbsyn());
str = Dump.unparseStr(Absyn.PROGRAM({absynClass}, match path case Absyn.IDENT() then Absyn.TOP(); else Absyn.WITHIN(Absyn.stripLast(path)); end match), options=Dump.DUMPOPTIONS(str));
else
Error.addMessage(Error.ACCESS_ENCRYPTED_PROTECTED_CONTENTS, {});
str = "";
end if;
then
(cache,Values.STRING(str));

Expand Down
19 changes: 19 additions & 0 deletions Compiler/Script/Interactive.mo
Expand Up @@ -18219,5 +18219,24 @@ algorithm
end try;
end checkAccessAnnotationAndEncryption;

public function astContainsEncryptedClass
input Absyn.Program inProgram;
output Boolean containsEncryptedClass = false;
protected
list<Absyn.Class> classes;
Absyn.Program p;
String fileName;
algorithm
classes := match(inProgram)
case p as Absyn.PROGRAM()
then p.classes;
end match;
for c in classes loop
Absyn.CLASS(info=SOURCEINFO(fileName=fileName)) := c;
containsEncryptedClass := containsEncryptedClass or Util.endsWith(fileName, ".moc");
if containsEncryptedClass then break; end if;
end for;
end astContainsEncryptedClass;

annotation(__OpenModelica_Interface="backend");
end Interactive;

0 comments on commit 7ee060b

Please sign in to comment.