The Meta-Environment API

asf-utils.tb

Go to the documentation of this file.
00001 #ifndef __ASF_UTILS__
00002 #define __ASF_UTILS__
00003 
00004 #include <sdf-namespace.h>
00005 #include <error-support.idef>
00006 #include <sdf-renaming.idef>
00007 #include <asfoperations.idef>
00008 #include <asfe.idef>
00009 #include <asfc.idef>
00010 #include <asfchecker.idef>
00011 #include <term-utils.tb>
00012 #include <sdf-utils.tb>
00013 #include <asfsdfchecker.idef>
00014 
00015 #define ASF_TREE_CACHE "asf-annotated-tree"
00016 #define ASF_NORMALIZED_TREE_CACHE "asf-normalized-tree"
00017 
00018 /* RegisterASFModule forges the link between an ASF and an SDF module.
00019  * It reuses the same module Id, and constructs an ASF path from
00020  * a SDF path.
00021  */
00022 process RegisterASFModule(ModuleId: module-id) is
00023 let
00024   AsfPath: str,
00025   Modulename: str,
00026   SdfPath: str
00027 in
00028   MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", Modulename?)
00029   . MM-SetAttribute(ModuleId, ASF_NAMESPACE, "name", Modulename)
00030   . GetModulePath(ModuleId, SDF_NAMESPACE, SdfPath?)
00031   . ReplaceExtension(SdfPath, ASF_EXTENSION, AsfPath?)
00032   . SetModulePath(ModuleId, ASF_NAMESPACE, AsfPath)
00033   . MM-SetAttribute(ModuleId, ASF_NAMESPACE, "status", unknown)
00034 endlet
00035 
00036 process OpenASFModule(ModuleId: module-id) is
00037 let
00038   AsfPath: str,
00039   Editable: bool,
00040   LibraryModule: bool
00041 in
00042   GetModulePath(ModuleId, ASF_NAMESPACE, AsfPath?)
00043   . snd-msg(io-exists-file(AsfPath))
00044   .
00045   (
00046     rec-msg(io-file-exists)
00047     . IsLibraryModule(ModuleId, LibraryModule?)
00048     . Editable := not(LibraryModule)
00049     . MM-SetAttribute(ModuleId, ASF_NAMESPACE, "editable", Editable)
00050     . MM-SetAttribute(ModuleId, ASF_NAMESPACE, "status", available)
00051   +
00052     rec-msg(io-file-not-exists)
00053     . MM-SetAttribute(ModuleId, ASF_NAMESPACE, "status", unavailable)
00054   )
00055 endlet
00056 
00057 process CheckASFSDFSyntax(ModuleId : module-id) is
00058 let
00059   Syntax: term,
00060   Feedback: term,
00061   Modulename: str,
00062   Summary: summary,
00063   Errors: list
00064 in
00065   AddJob("Checking syntax definition") 
00066   . snd-msg(tm-request-transaction(syntax-definition))
00067   . GetSyntaxDefinition(ModuleId, Syntax?)
00068   . snd-msg(tm-end-transaction(syntax-definition))
00069   .
00070   if not-equal(Syntax, UNDEFINED) then
00071     MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", Modulename?)
00072     . snd-msg(check-asfsdf(Syntax, Modulename)) 
00073     . rec-msg(checked-asfsdf(Feedback?)) 
00074     . snd-msg(convert-feedback(Feedback)) 
00075     . rec-msg(converted-feedback(Summary?)) 
00076     . ReplaceSummaryInfo(Summary?, "asfsdf-checker", Modulename)
00077     . RemoveSummary("asfsdf-checker", Modulename)
00078     . DisplaySummary(Summary)
00079     . Syntax := UNDEFINED
00080   else
00081     tau
00082   fi
00083   . JobDone("Checking syntax definition") 
00084 endlet
00085 
00086 process CheckASFModule(ModuleId: module-id) is
00087 let
00088   Summary : summary,
00089   Errors: list,
00090   Modulename: str,
00091   Tree: term
00092 in
00093   GetASFParseTree(ModuleId, Tree?)
00094   .
00095   if not-equal(Tree, UNDEFINED) then
00096     snd-msg(check-asf(Tree))
00097     . rec-msg(messages(Errors?))
00098     . MM-GetAttribute(ModuleId, ASF_NAMESPACE, "name", Modulename?) 
00099     . RemoveSummary("asf-checker", Modulename)
00100     . snd-msg(es-make-summary("asf-checker", Modulename, Errors))
00101     . rec-msg(es-summary(Summary?))
00102     . DisplaySummary(Summary)
00103   else
00104     tau
00105   fi
00106 endlet
00107 
00108 /* TODO: ensure cache is initialized before first call */
00109 toolbus(InitCache(ASF_TREE_CACHE))
00110 toolbus(ClearCacheHandler(ASF_TREE_CACHE, ASF_NAMESPACE, "status", <term>,edited))
00111 toolbus(ClearCacheHandler(ASF_TREE_CACHE, SDF_NAMESPACE, "status", <term>,complete))
00112 
00113 process GetASFParseTree(ModuleId: module-id, Result: term?) is
00114 let
00115   AmbPid: int,
00116   ParseTable: term,
00117   Path: str,
00118   Pid: int,
00119   Text: str,
00120   Type: term,
00121   Tree: term
00122 in
00123   snd-msg(tm-request-transaction(asf-parsing))
00124   . GetCachedValue(ASF_TREE_CACHE, ModuleId, Tree?)
00125   .
00126   if equal(Tree, UNDEFINED) then
00127     Type := eqs
00128     . GetModulePath(ModuleId, ASF_NAMESPACE, Path?)
00129     . ReadText(Path, Text?)
00130     .
00131     if not-equal(Text, "") then
00132       GetParseTable(ModuleId, Type, ParseTable?)
00133       .
00134       if not-equal(ParseTable, UNDEFINED) then
00135         create(ParseTreeHandler(ModuleId, Path), Pid?)
00136     . RemoveAmbiguitySummary(Path)
00137         . ParseText(Pid, Text, ParseTable, ASF_TOPSORT, on)
00138         .
00139         (
00140           rec-msg(parse-handler-done(Pid, ModuleId, Tree?))
00141       . create(AmbiguityHandler(Tree, Path), AmbPid?)
00142           . AnnotateTree(Tree, Path, Result?) 
00143           . PutCachedValue(ASF_TREE_CACHE, ModuleId, Result)
00144         +
00145           rec-msg(parse-handler-done(Pid))
00146           . Result := UNDEFINED
00147         )
00148       else 
00149         Result := UNDEFINED
00150       fi
00151     else
00152       Result := UNDEFINED
00153     fi
00154   else
00155     Result := Tree
00156   fi 
00157   . snd-msg(tm-end-transaction(asf-parsing))
00158 endlet
00159 
00160 process RunCompiler(Modulename: str, Table: term, Equations: term, OutputFile: str ) is
00161 let
00162   Progress : str,
00163   Id : int
00164 in
00165   Id := process-id
00166   . subscribe(asfc-progress(<term>))
00167   . snd-msg(compile-module(Modulename, OutputFile, Equations, Table)) .
00168   (
00169     rec-note(asfc-progress(Progress?)).
00170     snd-note(ui-status(endstat(Id))).
00171     snd-note(ui-status(statf(Id,"Compiling %s - %s", [Modulename, Progress])))
00172   )
00173   *
00174   rec-msg(compilation-done(Modulename))
00175 endlet
00176 
00177 process CompileModule(ModuleId : module-id, OutputFile: str) is
00178 let
00179   Equations: term,
00180   Error: str,
00181   Id: term,
00182   Pid: int,
00183   Specification: term,
00184   Table: term,
00185   Modulename: str
00186 in
00187    AddJob("Compiling")
00188    . GetSpecification(ModuleId, Specification?)
00189    .
00190    if not-equal(Specification, UNDEFINED) then
00191      GetSpecificationEquations(Specification, Equations?)
00192      . GetParseTable(ModuleId, trm, Table?)
00193      .
00194      if not-equal(Table, UNDEFINED) then
00195        MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", Modulename?)
00196        . RunCompiler(Modulename, Table, Equations, OutputFile)   
00197      else
00198        snd-note(ui-status(statf(Id, "Specification could not be compiled")))
00199      fi
00200    else
00201      snd-note(ui-status(statf(Id, "Specification could not be compiled")))
00202      . snd-note(ui-status(stop(Id)))
00203    fi
00204    . JobDone("Compiling")
00205 endlet
00206 
00207 process DumpEquations(ModuleId: module-id) is
00208 let
00209   SdfPath: str,
00210   Path : str
00211 in
00212   GetModulePath(ModuleId, SDF_NAMESPACE, SdfPath?)
00213   . ReplaceExtension(SdfPath, ".eqs", Path?)
00214   . DumpEquationsGivenFile(ModuleId, Path)
00215 endlet
00216 
00217 process DumpTestEquationsGivenFile(ModuleId : module-id, Path: str) is
00218 let
00219   Equations: term,
00220   Error: term,
00221   Filename: str,
00222   Id: int,
00223   Pid: int,
00224   Specification: term
00225 in
00226   AddJob("Dumping tests...")
00227   . GetSpecification(ModuleId, Specification?)
00228   .
00229   if not-equal(Specification, UNDEFINED) then
00230     GetSpecificationTests(Specification, Equations?)
00231     . snd-msg(io-unpack-and-write-term-in-baf(Path, Equations))
00232     .
00233     (
00234       rec-msg(io-file-written)
00235     +
00236       rec-msg(io-file-not-written(Error?))
00237       . snd-note(ui-status(errorf("%s: %t", [Path, Error])))
00238     )
00239   else   
00240      snd-note(ui-status(statf(Id, "Specification could not be dumped")))
00241   fi
00242   . snd-note(ui-status(stop(Id)))
00243   . JobDone("Dumping tests...")
00244 endlet
00245 
00246 
00247 process DumpEquationsGivenFile(ModuleId : module-id, Path: str) is
00248 let
00249   Equations: term,
00250   Error: term,
00251   Filename: str,
00252   Id: int,
00253   Pid: int,
00254   Specification: term
00255 in
00256   AddJob("Dumping equations...")
00257   . GetSpecification(ModuleId, Specification?)
00258   .
00259   if not-equal(Specification, UNDEFINED) then
00260     GetSpecificationEquations(Specification, Equations?)
00261     . snd-msg(io-unpack-and-write-term-in-baf(Path, Equations))
00262     .
00263     (
00264       rec-msg(io-file-written)
00265     +
00266       rec-msg(io-file-not-written(Error?))
00267       . snd-note(ui-status(errorf("%s: %t", [Path, Error])))
00268     )
00269   else   
00270      snd-note(ui-status(statf(Id, "Specification could not be dumped")))
00271   fi
00272   . snd-note(ui-status(stop(Id)))
00273   . JobDone("Dumping equations...")
00274 endlet
00275 
00276 toolbus(InitCache(ASF_NORMALIZED_TREE_CACHE))
00277 toolbus(ClearCacheHandler(ASF_NORMALIZED_TREE_CACHE, ASF_NAMESPACE, "status", <term>,edited))
00278 toolbus(ClearCacheHandler(ASF_NORMALIZED_TREE_CACHE, SDF_NAMESPACE, "status", <term>,complete))
00279 
00280 process NormalizeEquations(ModuleId : term, Equations: term, Result : term?) is
00281 let
00282   Tree : term
00283 in
00284   Tree := UNDEFINED
00285   . GetCachedValue(ASF_NORMALIZED_TREE_CACHE, ModuleId, Tree?)
00286   .
00287   if not-equal(Tree, UNDEFINED) then
00288     Result := Tree
00289   else
00290     AddJob("Normalizing ...")
00291     . snd-msg(ao-normalize-module(Equations)) 
00292     . rec-msg(ao-normalize-module-result(Tree?))
00293     . PutCachedValue(ASF_NORMALIZED_TREE_CACHE, ModuleId, Tree)
00294     . Result := Tree
00295     . JobDone("Normalizing ...")
00296   fi 
00297 endlet
00298 
00299 process RenameEquations(Modulename: str, Imports : list, Equations : term,
00300                         Result : term?)
00301 is
00302   AddJob("Renaming ...")
00303   . snd-msg(sr-rename-module(Imports, Modulename, Equations))
00304   . rec-msg(sr-renamed-module(Result?))
00305   . JobDone("Renaming ...")
00306 
00307 process GetSpecification(ModuleId: module-id, Result: term?) is
00308 let
00309   Error: term,
00310   CurModule: module-id,
00311   Equations: term,
00312   NormalizedEquations: term,
00313   RenamedEquations: term,
00314   Imports: list,
00315   Modulename: str,
00316   Modules: list,
00317   Opened: bool,
00318   Pid: int,
00319   Specification: term,
00320   Id : int,
00321   Count : int,
00322   Done : int
00323 in
00324   Id := process-id
00325   . snd-note(ui-status(start(Id, "Get Specification")))
00326   . AddJob("Collecting and normalizing specification")
00327   . MM-GetAllModuleDependencies(ModuleId, Modules?)
00328   . Modules := join([ModuleId], Modules)
00329   . GetImportsForRenaming(ModuleId, Modules, Imports?)
00330   . Count := size(Modules)
00331   . Specification := []
00332   . 
00333   if and(not-equal(Modules, []), equal(Error, undefined)) then
00334     CurModule := first(Modules)
00335     . GetASFParseTree(CurModule, Equations?)
00336     .
00337     if equal(Equations, UNDEFINED) then
00338       tau
00339     else
00340     /* normalization should occur BEFORE renaming 
00341      * proposal: merge the renaming and normalization tools,
00342      * possibly including the get-imports tool. 
00343      */
00344       MM-GetAttribute(CurModule, ASF_NAMESPACE, "name", Modulename?)
00345       . NormalizeEquations(CurModule, Equations, NormalizedEquations?)
00346       . RenameEquations(Modulename, Imports, NormalizedEquations, RenamedEquations?)
00347       . Specification := join(Specification, RenamedEquations)
00348       . MM-SetAttribute(CurModule, ASF_NAMESPACE, "status", complete)
00349     fi
00350     . Modules := next(Modules)
00351     . Done := sub(Count, size(Modules))
00352   fi
00353   *
00354   (
00355     if not-equal(Error, undefined) then
00356       Result := UNDEFINED
00357     fi
00358   +
00359     if equal(Modules, []) then
00360       Result := Specification
00361     fi
00362   )
00363   . snd-msg(ao-restart)
00364   . JobDone("Collecting and normalizing specification")
00365 endlet
00366 
00367 process GetSpecificationEquations(Specification: term, Equations: term?) is
00368   snd-msg(ao-extract-equations(Specification))
00369   . rec-msg(ao-extract-equations-result(Equations?))
00370 
00371 process GetSpecificationTests(Specification: term, Tests: term?) is
00372   snd-msg(ao-extract-tests(Specification))
00373   . rec-msg(ao-extract-tests-result(Tests?))
00374 
00375 process TestAsfSpecification(ModuleId: module-id, Debugging: term) is
00376 let
00377   Specification : term,
00378   Equations : term,
00379   ParseTable : term,
00380   Tests : term,
00381   Id : int,
00382   Pid : int,
00383   Errors : list,
00384   Summary: summary,
00385   Modulename: str
00386 in
00387   AddJob("Testing ASF Specification")
00388   . snd-note(ui-status(stat(Id, "Retrieving equations and tests"))) 
00389   . GetSpecification(ModuleId, Specification?)
00390   .
00391   if not-equal(Specification, UNDEFINED) then
00392     GetSpecificationEquations(Specification, Equations?) 
00393     . GetSpecificationTests(Specification, Tests?) 
00394     . GetTermParseTable(ModuleId, ParseTable?)
00395     . snd-note(ui-status(endstat(Id))) 
00396     . snd-note(ui-status(stat(Id, "Running tests"))) 
00397     . snd-msg(asfe-run-tests(Equations, Tests, ParseTable, Debugging)) 
00398     .
00399     (
00400       rec-msg(asfe-test-results(Errors?)) 
00401       . MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", Modulename?)
00402       . RemoveSummary("asf-tests",Modulename)
00403       .
00404       if equal(Errors, []) then
00405         snd-msg(show-message-dialog("All tests succeeded"))
00406       else
00407         snd-msg(es-make-summary("asf-tests", Modulename, Errors))
00408         . rec-msg(es-summary(Summary?))
00409         . DisplaySummary(Summary)
00410       fi
00411     +
00412       rec-msg(asfe-rewrite-errors(Errors?))
00413       . RemoveSummary("asfe", "all")
00414       . snd-msg(es-make-summary("asfe", "all", Errors)) 
00415       . rec-msg(es-summary(Summary?)) 
00416       . DisplaySummary(Summary)
00417     ) 
00418     . snd-note(ui-status(endstat(Id))) 
00419   else
00420     TODO("Summary is undefined here!\n")
00421     . DisplaySummary(Summary)
00422     . snd-note(ui-status(endstat(Id))) 
00423     . snd-note(ui-status(errorf("Equations incomplete for %s", [Modulename])))
00424   fi
00425   . JobDone("Testing ASF Specification")
00426 endlet
00427 
00428 process ReduceTerm(Tree: term, ModuleId: module-id, Debugging: term, NormalForm: term?) is
00429 let
00430   Summary: summary,
00431   Equations: term,
00432   Id: int,
00433   Modulename: str,
00434   Pid: int,
00435   Specification: term,
00436   Text: str,
00437   Errors: list,
00438   ParseTable: term,
00439   NormalFormWithoutBrackets: term
00440 in
00441   Id := process-id
00442   . GetSpecification(ModuleId, Specification?)
00443   .
00444   if not-equal(Specification, UNDEFINED) then
00445     GetSpecificationEquations(Specification, Equations?)
00446     . GetTermParseTable(ModuleId, ParseTable?)
00447     . AddJob("Rewriting...")
00448     . MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", Modulename?)
00449     . snd-msg(asfe-rewrite(Modulename, Equations, ParseTable, Tree, Debugging))
00450     .
00451     (
00452       rec-msg(asfe-rewrite-result(NormalFormWithoutBrackets?))
00453       . RestoreTermBrackets(ModuleId, NormalFormWithoutBrackets, NormalForm?)
00454       . RemoveSummary("asfe", "all")
00455     +
00456       rec-msg(asfe-rewrite-result-with-errors(NormalFormWithoutBrackets?,Errors?))
00457       . RemoveSummary("asfe", "all")
00458       . snd-msg(es-make-summary("asfe", "all", Errors)) 
00459       . rec-msg(es-summary(Summary?)) 
00460       . DisplaySummary(Summary)
00461       . RestoreTermBrackets(ModuleId, NormalFormWithoutBrackets, NormalForm?)
00462     +
00463       rec-msg(asfe-rewrite-errors(Errors?))
00464       . RemoveSummary("asfe", "all")
00465       . snd-msg(es-make-summary("asfe", "all", Errors)) 
00466       . rec-msg(es-summary(Summary?)) 
00467       . DisplaySummary(Summary)
00468     )
00469     . JobDone("Rewriting...")
00470   else
00471     NormalForm := UNDEFINED
00472   fi
00473 endlet
00474 
00475 process Reduce(ModuleId : module-id, Path : str, Debugging: term, Tree: term?) is
00476 let
00477   Parsetree: term,
00478   ResultTree: term
00479 in
00480   GetTermParsetree(ModuleId, Path, Parsetree?)
00481   . Tree := UNDEFINED
00482   .
00483   if not-equal(Parsetree, UNDEFINED) then
00484     ReduceTerm(Parsetree, ModuleId, Debugging, ResultTree?)
00485     .
00486     if not-equal(ResultTree, UNDEFINED) then
00487       snd-msg(promote-posinfo-to-origin(ResultTree))
00488       . rec-msg(promoted-posinfo-to-origin(ResultTree?))
00489       . AnnotateTree(ResultTree, "reduct.out", Tree?)
00490     else
00491       tau
00492     fi
00493   else
00494     tau
00495   fi
00496 endlet
00497 
00498 /*****
00499  BELOW HERE IS ALL DOUBTFUL
00500  TODO fix!
00501  */
00502 
00503 process GenerateASFSDFApi(ModuleId: module-id, Path: str) is
00504 let
00505   /* TODO: split up this process into smaller pieces if possible */
00506   Directory : str,
00507   ErrorMessage : str,
00508   Feedback : term,
00509   Filename : str,
00510   FullPath : str,
00511   NewEquationsText : str ,
00512   NewEquationsTree : term,
00513   NewModuleId: module-id,
00514   NewSyntaxText : str,
00515   NewSyntaxTree : term,
00516   Rewriter : str,
00517   SearchPaths : list,
00518   SyntaxTree : term,
00519   WarningBanner : str
00520 in
00521   TODO("This is broken!\n")
00522 /*
00523   WarningBanner := "%% WARNING: DO NOT EDIT, THIS MODULE IS GENERATED\n\n" .
00524   Rewriter := "ASFSDFApigen" .
00525   snd-msg(io-get-path-filename(Path)) .
00526   rec-msg(io-filename(Path, Filename?)) .
00527   snd-msg(io-get-path-directory(Path)) .
00528   rec-msg(io-directory(Path, Directory?)) .
00529   snd-msg(get-module-paths) .
00530   rec-msg(module-paths(SearchPaths?)) .
00531   snd-msg(sm-get-new-module-name(SearchPaths, Directory, Filename)) .
00532   (
00533     rec-msg(sm-new-module-name(Directory?, Filename?)) .
00534     snd-msg(get-syntax-tree(ModuleId)) .
00535     (
00536         rec-msg(syntax(SyntaxTree?)) .
00537     snd-msg(apply-rewrite(Rewriter, "generate-syntax", "Module", 
00538                   [SyntaxTree, Filename])) .
00539     rec-msg(normalform(Rewriter, NewSyntaxTree?)) .
00540     snd-msg(pretty-print(NewSyntaxTree)) .
00541     (
00542       rec-msg(pretty-print-result(NewSyntaxTree?)) 
00543         +
00544       rec-msg(pretty-print-error(Feedback?))
00545         ) .
00546     snd-msg(unparse(NewSyntaxTree)) .
00547     rec-msg(unparsed-text(NewSyntaxText?)) .
00548     snd-msg(io-get-filename(Directory, Filename, SDF_EXTENSION)) .
00549     rec-msg(io-filename(FullPath?)) .
00550     snd-msg(io-write-text-list(FullPath, [WarningBanner,NewSyntaxText])) .
00551     (
00552       rec-msg(io-file-written) .
00553       snd-msg(apply-rewrite(Rewriter, "generate-equations", "Skeleton", 
00554                 [SyntaxTree])) .
00555       rec-msg(normalform(Rewriter, NewEquationsTree?)) .
00556       snd-msg(pretty-print(NewEquationsTree)) .
00557       (
00558         rec-msg(pretty-print-result(NewEquationsTree?)) 
00559       +
00560         rec-msg(pretty-print-error(Feedback?))
00561       ) .
00562       snd-msg(unparse(NewEquationsTree)) .
00563       rec-msg(unparsed-text(NewEquationsText?)) .
00564       snd-msg(io-get-filename(Directory, Filename, ASF_EXTENSION)) .
00565       rec-msg(io-filename(FullPath?)) .
00566       snd-msg(io-write-text-list(FullPath, [NewEquationsText])) .
00567       (
00568         rec-msg(io-file-written)  .
00569         OpenModule(Filename, NewModuleId?)
00570       +
00571         rec-msg(io-file-not-written(ErrorMessage?)) .
00572         snd-note(ui-status(errorf("Generating module failed: %s",[ErrorMessage])))
00573       )
00574     +
00575       rec-msg(io-file-not-written(ErrorMessage?)) .
00576       snd-note(ui-status(errorf("Generating module failed: %s",[ErrorMessage])))
00577     )
00578       +
00579     rec-msg(unavailable) .
00580     snd-note(ui-status(error("Generating module failed.")))
00581       ) 
00582     +
00583       rec-msg(sm-new-module-name-inconsistent) .
00584         snd-note(ui-status(errorf(
00585             "Module %s in %s is inconsistent with search paths",
00586                 [Filename, Directory])))
00587     ) .
00588     snd-msg(asfsdfapigen-done)
00589   ) * delta */
00590 endlet
00591 
00592 #ifdef DEAD 
00593 process DeleteModule(Modulename: str) is
00594 let
00595   Changed: list,
00596   Id: int,
00597   Path: str,
00598   Status: term
00599 in
00600   TODO("split into ASF and SDF responsabilities")
00601   . Id := process-id
00602   . snd-note(ui-status(statf(Id, "Deleting %s", [Modulename])))
00603   . snd-msg(get-path-from-db(Modulename))
00604   .
00605   (
00606     rec-msg(path(Path?))
00607     . RemoveModuleFromDisk(Path, Modulename)
00608   +
00609     rec-msg(no-path)
00610   )
00611   . DeleteSessions(Modulename)
00612   . snd-msg(delete-module-from-db(Modulename))
00613   . rec-msg(changed-modules(Changed?))
00614   . SaveSdfModules(Changed, Status?)
00615   . snd-note(ui-status(endstat(Id)))
00616 endlet
00617 
00618 process RenameModule(Modulename: str, Directory: str, Filename: str) is
00619 let
00620   Id: int,
00621   NewModule: str,
00622   Path: str
00623 in
00624   TODO("split into ASF and SDF responsabilities")
00625   . Id := process-id
00626   . snd-note(ui-status(statf(Id, "Renaming %s", [Modulename])))
00627   . CopySdfModule(Modulename, Directory, Filename)
00628   . CopyAsfModule(Modulename, Directory, Filename)
00629   . BuildPath(Directory, Filename, SDF_EXTENSION, Path?)
00630   /*. GetModuleForPath(Path, NewModule?)*/
00631   . RenameImports(Modulename, NewModule)
00632   . DeleteModule(Modulename)
00633   . snd-note(ui-status(endstat(Id)))
00634 endlet
00635 
00636 process CopyAsfModule(SrcModulename: str, Directory: str, Filename: str) is
00637 let
00638   DestPath: str,
00639   Error: str,
00640   SrcPath: str
00641 in
00642   LocateFile(SrcModulename, ASF_EXTENSION, SrcPath?)
00643   . snd-msg(io-exists-file(SrcPath))
00644   .
00645   (
00646     rec-msg(io-file-exists)
00647     . BuildPath(Directory, Filename, ASF_EXTENSION, DestPath?)
00648     . snd-msg(io-exists-file(DestPath))
00649     .
00650     (
00651       rec-msg(io-file-exists)
00652       . printf("warning: refusing to overwrite existing file: %s", DestPath)
00653     +
00654       rec-msg(io-file-not-exists)
00655       . snd-msg(io-copy-file(SrcPath, DestPath))
00656       .
00657       (
00658         rec-msg(io-file-copied(SrcPath, DestPath))
00659       +
00660         rec-msg(io-file-not-copied(SrcPath, DestPath, Error?))
00661         . printf("error: Unable to copy %s to %s: %s", SrcPath, DestPath, Error)
00662       )
00663     )
00664   +
00665     rec-msg(io-file-not-exists)
00666   )
00667 endlet
00668 
00669 process AddImport(Modulename: str, Import: str) is
00670 let
00671   Depending: list,
00672   Status: term
00673 in
00674   TODO("split asf and sdf")
00675   . DeleteSessions(Modulename)
00676   . GetDependingModules(Modulename, Depending?)
00677   . MDB-InvalidateModules(Depending, sdf)
00678   . AddImportInDB(Modulename, Import)
00679   . SaveAsfSdfModule(Modulename, Status?)
00680 endlet
00681 
00682 process RemoveImport(Modulename: str, Import: str) is
00683 let
00684   Depending: list,
00685   Status: term
00686 in
00687   TODO("split asf and sdf")
00688   .DeleteSessions(Modulename)
00689   . GetDependingModules(Modulename, Depending?)
00690   . MDB-InvalidateModules(Depending, sdf)
00691   . RemoveImportInDB(Modulename, Import)
00692   . SaveAsfSdfModule(Modulename, Status?)
00693 endlet
00694 #endif
00695 
00696 process SaveAsfSdfModule(Modulename: str, Status: term?) is
00697   snd-msg(save-module(Modulename, asfsdf))
00698   . rec-msg(saved-module(Modulename, Status?))
00699 
00700 process RemoveModuleFromDisk(Directory: str, Modulename: str) is
00701 let
00702   Path: str
00703 in
00704   BuildPath(Directory, Modulename, SDF_EXTENSION, Path?)
00705   . RemoveFile(Path)
00706   . BuildPath(Directory, Modulename, ASF_EXTENSION, Path?)
00707   . snd-msg(io-exists-file(Path))
00708   .
00709   (
00710     rec-msg(io-file-exists)
00711     . RemoveFile(Path)
00712   +
00713     rec-msg(io-file-not-exists)
00714   )
00715 endlet
00716 
00717 process WriteTreeToFile(Tree : term, Filename : str) is
00718 let
00719   Text : str,
00720   Error : term
00721 in
00722     snd-msg(unparse(Tree))
00723     . rec-msg(unparsed-text(Text?))
00724     . snd-msg(io-write-text-list(Filename, [Text]))
00725     .
00726     (
00727       rec-msg(io-file-written)
00728     +
00729       rec-msg(io-file-not-written(Error?))
00730       . printf("error: %s not written, %t\n", Filename, Error)
00731     )
00732 endlet
00733 
00734 process CheckEquationConsistency(Modulename: str, Path: str) is
00735 let
00736   Filename: str,
00737   FileText: str,
00738   RepositoryText: str,
00739   Error : term
00740 in
00741   snd-msg(io-get-filename(Path, Modulename, ASF_EXTENSION))
00742   . rec-msg(io-filename(Filename?))
00743   . snd-msg(io-exists-file(Filename))
00744   .
00745   (
00746     rec-msg(io-file-exists)
00747     . snd-msg(io-read-file(Filename))
00748     .
00749     (
00750       rec-msg(io-file-contents(FileText?))
00751       . snd-msg(update-eqs-text-in-db(Modulename, FileText))
00752       . rec-msg(eqs-text-updated(Modulename))
00753     +
00754       rec-msg(io-error-reading(Error?))
00755       . printf("TODO: fix this error %t\n", Error)
00756     )
00757   +
00758     rec-msg(io-file-not-exists)
00759     . snd-msg(get-eqs-text(Modulename))
00760     .
00761     (
00762       rec-msg(eqs-text(Modulename, RepositoryText?))
00763       . snd-msg(remove-eqs-from-db(Modulename))
00764       . rec-msg(eqs-removed-from-db)
00765     +
00766       rec-msg(no-eqs-text(Modulename))
00767     )
00768   )
00769 endlet
00770 
00771 process PrintModule is
00772 let
00773   Id: term,
00774   SdfText: str,
00775   AsfText: str,
00776   AsfTree: term,
00777   ModuleId: module-id,
00778   Modulename: str,
00779   Path: str,
00780   Filename: str,
00781   ErrMsg: str
00782 in
00783   TODO("reimplement")
00784 /*
00785     rec-msg(print-module(ModuleId?, Filename?))
00786         . snd-msg(io-write-text-list(Filename, [SdfText, "\n", AsfText])) */
00787 endlet
00788 
00789 
00790 #endif /* __ASF_UTILS__ */
00791 

Generated on Fri Sep 12 13:16:07 2008 for asfsdf-meta by  doxygen 1.4.6