This commit is contained in:
Jürgen Doser 2007-02-09 17:33:34 +00:00
parent 3bfeea80f1
commit b3e3bed204
5 changed files with 31 additions and 23 deletions

View File

@ -44,12 +44,19 @@ val out = ref TextIO.stdOut
fun closeFile () = if (!curFile = "")
then ()
else (TextIO.closeOut (!out);
info ("closing "^(!curFile));
(* info ("closing "^(!curFile));*)
curFile := "")
(* FIXME: set out to a real NullStream *)
fun openNull file = (closeFile ();
info ("skipping "^file);
out := (TextIO.openOut "/dev/null");
curFile := "/dev/null"
)
fun openFile file = (closeFile ();
info ("opening "^file^"...");
info ("opening "^file);
Gcg_Helper.assureDir file;
out := (TextIO.openOut file);
curFile := file
@ -57,7 +64,7 @@ fun openFile file = (closeFile ();
fun openFileIfNotExists file = (closeFile ();
(if ((OS.FileSys.fileSize file) > 0)
then openFile "/dev/null"
then openNull file
else openFile file
) handle SysErr => ( openFile file ))
@ -128,7 +135,9 @@ fun generate model template
(initOut();
(*printTTree tree;*)
write env tree;
closeFile () )
closeFile ();
info "codegen finished successfully"
)
handle ex => (closeFile(); raise ex)
end

View File

@ -1,13 +1,12 @@
@// base template
@// assumption: all classifiers are classes
@openfile generated/securemova/$classifier_package$.mova
@// generated by su4sml GCG - Generic Code Generator
load /home/doserj/projects/securemova/ocl-tool-v30/ocl-tool.maude @nl
load /home/doserj/projects/securemova/ocl-tool-v30/securemova.maude @nl
@nl@nl
(create-security-diagram $classifier_package$ .) @nl
@foreach role_list
(insert-role $classifier_package$ : $role_name$ .) @nl
@foreach superrole_list
@ -16,7 +15,7 @@
@end
@foreach subject_list
(insert-user $classifier_package$: $subject_name$ .) @nl
(insert-user $classifier_package$ : $subject_name$ .) @nl
@foreach role_list
(insert-user-assignment $classifier_package$ | $subject_name$ <-> $role_name$ .) @nl
@end
@ -53,7 +52,7 @@
(insert-authorization-constraint-assignment $classifier_package$ : $constraint_perm$ : auth$counter$ .) @nl
@end
@//TODO: also support composite actions (not supported in cartridge yet...
@//TODO: also support composite actions (not supported in cartridge yet...)
@foreach entity_list
@foreach createPermission_list
(insert-atomic-create $classifier_package$ : $permission_name$ : $entity_name$ .) @nl

View File

@ -50,13 +50,13 @@ val tplStream = ref (TextIO.openString "@// dummy template\n");
fun opentFile file = (TextIO.closeIn (!tplStream) ;
tplStream := (TextIO.openIn file))
handle ex => error ("in Tpl_Parser.opentFile: \
\couldn't open preprocessed template file: "^
General.exnMessage ex)
handle ex => error ("in Tpl_Parser.opentFile: \
\couldn't open preprocessed template file: "^
General.exnMessage ex)
fun cleanUp tplFile = (TextIO.closeIn (!tplStream);
OS.FileSys.remove tplFile)
fun readNextLine () = TextIO.inputLine (!tplStream)
@ -65,6 +65,7 @@ fun readNextLine () = TextIO.inputLine (!tplStream)
(* This should really be relaxed... *)
(* FIXME: add separate VariableLeaf *)
(* FIXME: merge If and Else Nodes *)
(* FIXME: add InfoLeaf to print informational messages during codegen *)
datatype TemplateTree = RootNode of TemplateTree list
| OpenFileLeaf of string
| OpenFileIfNotExistsLeaf of string
@ -135,7 +136,7 @@ fun tokenize line = let val l = joinEscapeSplitted "@" (fieldSplit #"@" line)
fun getType l = let val sl = tokenize l
in
if (length sl = 1) orelse (length sl = 0)
then "text" (* rather: comment *)
then "text" (* rather: comment? *)
else hd (tokenSplit #" " (String.concat sl))
end
handle ex => error ("in Tpl_Parser.getType: "^General.exnMessage ex)
@ -194,9 +195,7 @@ fun codegen_home _ = getOpt (OS.Process.getEnv "CODEGEN_HOME", su4sml_home()^"sr
*)
fun call_cpp file =
let val targetFile = OS.FileSys.tmpName ()
val _ = info ("tmpfile "^targetFile)
val _ = OS.Process.system ("cpp -P -C "^codegen_home()^"/"^file^" "^targetFile)
val _ = info ("cpp done")
in
targetFile
end
@ -206,7 +205,7 @@ fun call_cpp file =
(** parse template-file
* @return the parsed template tree
*)
fun parse file = let val _ = info ("parsing template "^file)
fun parse file = let val _ = info ("parsing template "^file)
val mergedTpl = call_cpp file;
val _ = opentFile mergedTpl;
val pt = RootNode(buildTree (readNextLine()));

View File

@ -149,11 +149,11 @@ fun filter_subject cs = List.filter (classifier_has_stereotype "secuml.user") cs
fun filter_role cs = List.filter (classifier_has_stereotype "secuml.role") cs
fun mkRole (C as Rep.Class c) = Rep.short_name_of C
fun mkRole (C as Rep.Class c) = Rep.string_of_path (Rep.name_of C)
| mkRole _ = error ("in mkRole: argument is not a class")
(* FIXME: handle groups also *)
fun mkSubject (C as Rep.Class c) = User (Rep.short_name_of C)
fun mkSubject (C as Rep.Class c) = User (Rep.string_of_path (Rep.name_of C))
| mkSubject _ = error ("in mkSubject: argument is not a class")
fun mkPermission cs (c as Rep.Class _) =
@ -199,7 +199,7 @@ fun mkSubjectAssignment cs (c as (Rep.Class _)) =
* removes the classes with SecureUML stereotypes.
*)
fun parse (cs:Rep_Core.Classifier list) =
let val _ = info "parsing security configuration"
let val _ = info "parsing security configuration"
in
(List.filter (classifier_has_no_stereotype ["secuml.permission",
"secuml.role",

View File

@ -979,7 +979,8 @@ fun mkPackage tree =
then let val trees = tree |> get "UML:Namespace.ownedElement"
val atts = attributes tree
val package_name = atts |> name
val _ = info ("parsing package "^package_name)
val _ = if tree is "UML:Model" then info ("parsing model "^package_name)
else info ("parsing package "^package_name)
in
XMI.Package
{ xmiid = atts |> xmiid,