private bool MustGenerate(String grgFilename, String statisticsPath, ProcessSpecFlags flags, out String actionsFilename, out String modelFilename) { String actionsName = GetPathBaseName(grgFilename); String actionsDir = GetDir(grgFilename); // Parse grg file and collect information about the used files and the main graph model List <String> neededFilenames = new List <String>(); neededFilenames.Add(grgFilename); if (statisticsPath != null) { neededFilenames.Add(statisticsPath); } Dictionary <String, object> processedActionFiles = new Dictionary <String, object>(); Dictionary <String, object> processedModelFiles = new Dictionary <String, object>(); GetNeededFiles(actionsDir, grgFilename, neededFilenames, processedActionFiles, processedModelFiles); String mainModelName; if (processedModelFiles.Count == 0) { mainModelName = "Std"; } else if (processedModelFiles.Count == 1) { Dictionary <string, object> .Enumerator enu = processedModelFiles.GetEnumerator(); enu.MoveNext(); mainModelName = enu.Current.Key; } else { mainModelName = actionsName; } actionsFilename = actionsDir + "lgsp-" + actionsName + "Actions.dll"; modelFilename = actionsDir + "lgsp-" + GetPathBaseName(mainModelName) + "Model.dll"; // Do the libraries exist at all? if (!File.Exists(actionsFilename) || !File.Exists(modelFilename)) { return(true); } if (File.Exists(actionsDir + actionsName + "ActionsExternalFunctionsImpl.cs")) { neededFilenames.Add(actionsDir + actionsName + "ActionsExternalFunctionsImpl.cs"); } if (File.Exists(actionsDir + mainModelName + "ModelExternalFunctionsImpl.cs")) { neededFilenames.Add(actionsDir + mainModelName + "ModelExternalFunctionsImpl.cs"); } DateTime actionsTime = File.GetLastWriteTime(actionsFilename); DateTime modelTime = File.GetLastWriteTime(modelFilename); DateTime oldestOutputTime = actionsTime < modelTime ? actionsTime : modelTime; return(DepsOlder(oldestOutputTime, neededFilenames) || (flags & ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange) == ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange); }
private bool MustGenerate(String gmFilename, String statisticsPath, ProcessSpecFlags flags, out String modelFilename) { String modelName = GetPathBaseName(gmFilename); String modelDir = GetDir(gmFilename); // Parse grg file and collect information about the used files and the main graph model List <String> neededFilenames = new List <String>(); neededFilenames.Add(gmFilename); if (statisticsPath != null) { neededFilenames.Add(statisticsPath); } Dictionary <String, object> processedModelFiles = new Dictionary <String, object>(); GetNeededFiles(modelDir, gmFilename, neededFilenames, processedModelFiles); modelFilename = modelDir + "lgsp-" + modelName + "Model.dll"; // Does the model library exist at all? if (!File.Exists(modelFilename)) { return(true); } if (File.Exists(modelDir + modelName + "ModelExternalFunctionsImpl.cs")) { neededFilenames.Add(modelDir + modelName + "ModelExternalFunctionsImpl.cs"); } DateTime modelTime = File.GetLastWriteTime(modelFilename); return(DepsOlder(modelTime, neededFilenames) || (flags & ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange) == ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange); }
public void CreateNamedFromSpec(string grgFilename, string graphName, String statisticsPath, ProcessSpecFlags flags, List <String> externalAssemblies, int capacity, out INamedGraph newGraph, out IActions newActions) { LGSPGraph graph; LGSPActions actions; CreateFromSpec(grgFilename, graphName, statisticsPath, flags, externalAssemblies, true, capacity, out graph, out actions); newGraph = (LGSPNamedGraph)graph; newActions = actions; }
/// <summary> /// Creates a new LGSPGraph or LGSPNamedGraph instance from the specified specification file. /// If the according dll does not exist or is out of date, the needed processing steps are performed automatically. /// </summary> /// <param name="gmFilename">Filename of the model specification file (.gm).</param> /// <param name="graphName">Name of the new graph.</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed; only KeepGeneratedFiles and CompileWithDebug are taken care of!</param> /// <param name="externalAssemblies">List of external assemblies to reference.</param> /// <param name="named">Returns a named graph if true otherwise a non-named graph. You must cast the LGSPGraph returned to the inherited LGSPNamedGraph if named=true.</param> /// <param name="capacity">The initial capacity for the name maps (performance optimization, use 0 if unsure).</param> /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception> /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception> /// <returns>The new LGSPGraph or LGSPNamedGraph instance.</returns> public LGSPGraph CreateFromSpec(String gmFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List <String> externalAssemblies, bool named, int capacity) { if (!File.Exists(gmFilename)) { throw new FileNotFoundException("The model specification file \"" + gmFilename + "\" does not exist!", gmFilename); } String modelFilename; if (MustGenerate(gmFilename, statisticsPath, flags, out modelFilename)) { LGSPGrGen.ProcessSpecification(gmFilename, statisticsPath, flags, externalAssemblies.ToArray()); } return(CreateGraph(modelFilename, graphName, named, "capacity=" + capacity.ToString())); }
/// <summary> /// Creates a new LGSPGraph or LGSPNamedGraph and LGSPActions instance from the specified specification file. /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically. /// </summary> /// <param name="grgFilename">Filename of the rule specification file (.grg).</param> /// <param name="graphName">Name of the new graph.</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed; only KeepGeneratedFiles and CompileWithDebug are taken care of!</param> /// <param name="externalAssemblies">List of external assemblies to reference.</param> /// <param name="named">Returns a named graph if true otherwise a non-named graph. You must cast the LGSPGraph returned to the inherited LGSPNamedGraph if named=true.</param> /// <param name="capacity">The initial capacity for the name maps, only used if named (performance optimization, use 0 if unsure).</param> /// <param name="newGraph">Returns the new graph.</param> /// <param name="newActions">Returns the new BaseActions object.</param> /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception> /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception> public void CreateFromSpec(String grgFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List <String> externalAssemblies, bool named, int capacity, out LGSPGraph newGraph, out LGSPActions newActions) { if (!File.Exists(grgFilename)) { throw new FileNotFoundException("The rule specification file \"" + grgFilename + "\" does not exist!", grgFilename); } String actionsFilename; String modelFilename; if (MustGenerate(grgFilename, statisticsPath, flags, out actionsFilename, out modelFilename)) { LGSPGrGen.ProcessSpecification(grgFilename, statisticsPath, flags, externalAssemblies.ToArray()); } newGraph = named ? (LGSPNamedGraph)CreateNamedGraph(modelFilename, graphName, "capacity=" + capacity.ToString()) : (LGSPGraph)CreateGraph(modelFilename, graphName); newActions = LGSPActions.LoadActions(actionsFilename, newGraph); }
public IGraph CreateFromSpec(String gmFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List<String> externalAssemblies) { return CreateFromSpec(gmFilename, graphName, statisticsPath, flags, externalAssemblies, false, 0); }
public static bool ExecuteGrGenJava(String tmpDir, ProcessSpecFlags flags, out List<String> genModelFiles, out List<String> genModelStubFiles, out List<String> genActionsFiles, params String[] sourceFiles) { genModelFiles = new List<string>(); genModelStubFiles = new List<string>(); genActionsFiles = new List<string>(); if(sourceFiles.Length == 0) { Console.Error.WriteLine("No GrGen.NET source files specified!"); return false; } String binPath = FixDirectorySeparators(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) + Path.DirectorySeparatorChar; Process grGenJava = null; // The code handling CTRL+C makes sure, the Java process is killed even if CTRL+C was pressed at the very // begining of Process.Start without making the program hang in an indeterminate state. bool ctrlCPressed = false; bool delayCtrlC = true; // between registering the handler and the end of Process.Start, delay actually handling of CTRL+C ConsoleCancelEventHandler ctrlCHandler = delegate(object sender, ConsoleCancelEventArgs e) { if(!delayCtrlC) { if(grGenJava == null || grGenJava.HasExited) return; Console.Error.WriteLine("Aborting..."); System.Threading.Thread.Sleep(100); // a short delay to make sure the process is correctly started if(!grGenJava.HasExited) grGenJava.Kill(); } ctrlCPressed = true; if(e != null) // compare to null, as we also call this by ourself when handling has been delayed e.Cancel = true; // we handled the cancel event }; ProcessStartInfo startInfo = null; String javaString = null; try { if(Environment.OSVersion.Platform == PlatformID.Unix) javaString = "java"; else javaString = "javaw"; String execStr = "-Xss1M -Xmx1024M -jar \"" + binPath + "grgen.jar\" " + "-b de.unika.ipd.grgen.be.Csharp.SearchPlanBackend2 " + "-c \"" + tmpDir + Path.DirectorySeparatorChar + "printOutput.txt\" " + "-o \"" + tmpDir + "\"" + ((flags & ProcessSpecFlags.NoEvents) != 0 ? " --noevents" : "") + ((flags & ProcessSpecFlags.NoDebugEvents) != 0 ? " --nodebugevents" : "") + ((flags & ProcessSpecFlags.Profile) != 0 ? " --profile" : "") + " \"" + String.Join("\" \"", sourceFiles) + "\""; startInfo = new ProcessStartInfo(javaString, execStr); startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; try { Console.CancelKeyPress += ctrlCHandler; grGenJava = Process.Start(startInfo); delayCtrlC = false; if(ctrlCPressed) ctrlCHandler(null, null); grGenJava.WaitForExit(); } finally { Console.CancelKeyPress -= ctrlCHandler; } } catch(System.ComponentModel.Win32Exception e) { Console.Error.WriteLine("Unable to process specification: " + e.Message); Console.Error.WriteLine("Is Java installed and the executable " + javaString + " available in one of the folders of the search path? Search path: " + startInfo.EnvironmentVariables["path"]); return false; } catch(Exception e) { Console.Error.WriteLine("Unable to process specification: " + e.Message); return false; } if(ctrlCPressed) return false; bool noError = true, doneFound = false; using(StreamReader sr = new StreamReader(tmpDir + Path.DirectorySeparatorChar + "printOutput.txt")) { String frontStr = " generating the "; String backStr = " file..."; String frontStubStr = " writing the "; String backStubStr = " stub file..."; String line; while((line = sr.ReadLine()) != null) { if(line.Contains("ERROR")) { Console.Error.WriteLine(line); noError = false; continue; } if(line.Contains("WARNING")) { Console.Error.WriteLine(line); continue; } if(line.StartsWith(frontStr) && line.EndsWith(backStr)) { String filename = line.Substring(frontStr.Length, line.Length - frontStr.Length - backStr.Length); if(filename.EndsWith("Model.cs")) genModelFiles.Add(tmpDir + Path.DirectorySeparatorChar + filename); else if(filename.EndsWith("Actions_intermediate.cs")) genActionsFiles.Add(tmpDir + Path.DirectorySeparatorChar + filename); } else if(line.StartsWith(frontStubStr) && line.EndsWith(backStubStr)) { String filename = line.Substring(frontStubStr.Length, line.Length - frontStubStr.Length - backStubStr.Length); if(filename.EndsWith("ModelStub.cs")) genModelStubFiles.Add(tmpDir + Path.DirectorySeparatorChar + filename); } else if(line.StartsWith("done!")) doneFound = true; } } return noError && doneFound; }
/// <summary> /// Constructs an LGSPGrGen object. /// </summary> /// <param name="flags">Flags specifying how the specification should be processed.</param> public LGSPGrGen(ProcessSpecFlags flags) { this.flags = flags; }
public INamedGraph CreateNamedFromSpec(String gmFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List <String> externalAssemblies, int capacity) { return((LGSPNamedGraph)CreateFromSpec(gmFilename, graphName, statisticsPath, flags, externalAssemblies, true, capacity)); }
/// <summary> /// Processes the given rule specification file and generates a model and actions library. /// </summary> /// <param name="specPath">The path to the rule specification file (.grg).</param> /// <param name="destDir">The directory, where the generated libraries are to be placed.</param> /// <param name="intermediateDir">A directory, where intermediate files can be placed.</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed.</param> /// <param name="externalAssemblies">External assemblies to reference</param> /// <exception cref="System.Exception">Thrown, when an error occurred.</exception> public void ProcessSpecification(string specPath, string destDir, string intermediateDir, String statisticsPath, ProcessSpecFlags flags, params String[] externalAssemblies) { LGSPGrGen.ProcessSpecification(specPath, destDir, intermediateDir, statisticsPath, flags, externalAssemblies); }
private bool MustGenerate(String grgFilename, String statisticsPath, ProcessSpecFlags flags, out String actionsFilename, out String modelFilename) { String actionsName = GetPathBaseName(grgFilename); String actionsDir = GetDir(grgFilename); // Parse grg file and collect information about the used files and the main graph model List<String> neededFilenames = new List<String>(); neededFilenames.Add(grgFilename); if(statisticsPath != null) neededFilenames.Add(statisticsPath); Dictionary<String, object> processedActionFiles = new Dictionary<String, object>(); Dictionary<String, object> processedModelFiles = new Dictionary<String, object>(); GetNeededFiles(actionsDir, grgFilename, neededFilenames, processedActionFiles, processedModelFiles); String mainModelName; if(processedModelFiles.Count == 0) mainModelName = "Std"; else if(processedModelFiles.Count == 1) { Dictionary<string, object>.Enumerator enu = processedModelFiles.GetEnumerator(); enu.MoveNext(); mainModelName = enu.Current.Key; } else mainModelName = actionsName; actionsFilename = actionsDir + "lgsp-" + actionsName + "Actions.dll"; modelFilename = actionsDir + "lgsp-" + GetPathBaseName(mainModelName) + "Model.dll"; // Do the libraries exist at all? if(!File.Exists(actionsFilename) || !File.Exists(modelFilename)) return true; if(File.Exists(actionsDir + actionsName + "ActionsExternalFunctionsImpl.cs")) neededFilenames.Add(actionsDir + actionsName + "ActionsExternalFunctionsImpl.cs"); if(File.Exists(actionsDir + mainModelName + "ModelExternalFunctionsImpl.cs")) neededFilenames.Add(actionsDir + mainModelName + "ModelExternalFunctionsImpl.cs"); DateTime actionsTime = File.GetLastWriteTime(actionsFilename); DateTime modelTime = File.GetLastWriteTime(modelFilename); DateTime oldestOutputTime = actionsTime < modelTime ? actionsTime : modelTime; return DepsOlder(oldestOutputTime, neededFilenames) || (flags & ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange) == ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange; }
public IGraph CreateFromSpec(String gmFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List <String> externalAssemblies) { return(CreateFromSpec(gmFilename, graphName, statisticsPath, flags, externalAssemblies, false, 0)); }
/// <summary> /// Processes the given rule specification file and generates a model and actions library. /// </summary> /// <param name="specPath">The path to the rule specification file (.grg).</param> /// <param name="destDir">The directory, where the generated libraries are to be placed.</param> /// <param name="intermediateDir">A directory, where intermediate files can be placed.</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed.</param> /// <param name="externalAssemblies">External assemblies to reference</param> /// <exception cref="System.Exception">Thrown, when an error occurred.</exception> public void ProcessSpecification(string specPath, string destDir, string intermediateDir, String statisticsPath, ProcessSpecFlags flags, params String[] externalAssemblies) { LGSPGrGen.ProcessSpecification(specPath, destDir, intermediateDir, statisticsPath, flags, externalAssemblies); }
static int Main(string[] args) { String specFile = null; String dirname = null; String destDir = null; ProcessSpecFlags flags = ProcessSpecFlags.UseNoExistingFiles; IBackend backend = null; List <String> externalAssemblies = new List <String>(); String statisticsPath = null; for (int i = 0; i < args.Length; i++) { if (args[i][0] == '-') { switch (args[i]) { case "-o": if (i + 1 >= args.Length) { Console.Error.WriteLine("Missing parameter for -o option!"); specFile = null; // show usage break; } destDir = args[++i]; if (!Directory.Exists(destDir)) { Console.Error.WriteLine("Specified output directory does not exist!"); return(1); } if (destDir[destDir.Length - 1] != Path.DirectorySeparatorChar) { destDir += Path.DirectorySeparatorChar; } break; case "-b": if (i + 1 >= args.Length) { Console.Error.WriteLine("Missing parameter for -b option!"); specFile = null; // show usage break; } backend = LoadBackend(args[++i]); if (backend == null) { return(1); } Console.WriteLine("Using backend \"" + backend.Name + "\"."); break; case "-r": if (i + 1 >= args.Length) { Console.Error.WriteLine("Missing parameter for -r option!"); specFile = null; // show usage break; } externalAssemblies.Add(args[++i]); break; case "-keep": flags |= ProcessSpecFlags.KeepGeneratedFiles; if (specFile != null) // specFile already specified? { if (i + 1 >= args.Length) // yes. is there another parameter? { break; } } else if (i + 2 >= args.Length) // no. are there two more parameters? { break; } if (args[i + 1][0] == '-') // is the next parameter an option? { break; } dirname = args[++i]; // no, use it as a gen-dir break; case "-use": if (i + 1 >= args.Length) { Console.Error.WriteLine("Missing parameter for -use option!"); specFile = null; // show usage break; } if (dirname != null) { Console.Error.WriteLine("The -d option may not specify a directory if -use is used!"); specFile = null; break; } dirname = args[++i]; flags |= ProcessSpecFlags.UseJavaGeneratedFiles; if (!Directory.Exists(dirname)) { Console.Error.WriteLine("Illegal directory specified! It does not exist!"); return(1); } break; case "-usefull": if (i + 1 >= args.Length) { Console.Error.WriteLine("Missing parameter for -usefull option!"); specFile = null; // show usage break; } if (dirname != null) { Console.Error.WriteLine("The -d option may not specify a directory if -usefull is used!"); specFile = null; break; } dirname = args[++i]; flags |= ProcessSpecFlags.UseAllGeneratedFiles; if (!Directory.Exists(dirname)) { Console.Error.WriteLine("Illegal directory specified! It does not exist!"); return(1); } break; case "-debug": flags |= ProcessSpecFlags.CompileWithDebug; break; case "-noevents": flags |= ProcessSpecFlags.NoEvents; flags |= ProcessSpecFlags.NoDebugEvents; break; case "-nodebugevents": flags |= ProcessSpecFlags.NoDebugEvents; break; case "-lazynic": flags |= ProcessSpecFlags.LazyNIC; break; case "-noinline": flags |= ProcessSpecFlags.Noinline; break; case "-statistics": if (i + 1 >= args.Length) { Console.Error.WriteLine("Missing parameter for -statistics option!"); specFile = null; // show usage break; } statisticsPath = args[++i]; if (!File.Exists(statisticsPath)) { Console.Error.WriteLine("Specified statistics file \"" + statisticsPath + "\" does not exist!"); return(1); } break; case "-profile": flags |= ProcessSpecFlags.Profile; break; default: Console.Error.WriteLine("Illegal option: " + args[i]); specFile = null; i = args.Length; // leave for loop break; } } else if (specFile != null) { Console.Error.WriteLine("Two rule specification files specified: \"" + specFile + "\" and \"" + args[i] + "\""); specFile = null; break; } else { specFile = args[i]; } } // flags |= ProcessSpecFlags.Profile; // uncomment to test profiling if (specFile == null) { Console.WriteLine( "Usage: GrGen [OPTIONS] <grg-file>[.grg]\n" + "Options:\n" + " -o <output-dir> Output directory for the generated assemblies\n" + " -keep [<gen-dir>] Don't delete generated files making it possible\n" + " to use the files in a C# project directly.\n" + " This way you can also debug non-matching rules.\n" + " Optionally you can specify a destination directory.\n" + " -debug Compiles the assemblies with debug information\n" + " -r <assembly-path> Assembly path to reference, i.e. link into\n" + " the generated assembly\n" + " -statistics <path> Build matchers based on the graph statistics\n" + " contained in the specified file\n" + " -use <existing-dir> Use old C# files generated by the Java frontend\n" + " using the -keep option in the specified directory\n" + " -usefull <exist-dir> Use all old C# files generated using the -keep option\n" + " in the specified directory\n" + " -b <backend-dll> Use the specified backend library\n" + " (default: LGSPBackend)\n" + " -lazynic Negatives, Independents, and Conditions are only\n" + " executed at the end of matching (normally asap)\n" + " -noinline disables subpattern and independent inlining\n" + "Optimizing options:\n" + " -nodebugevents Do not fire debug events in the generated code.\n" + " Mostly action events, impacts debugging.\n" + " -noevents Do not fire events in the generated code.\n" + " Mostly attribute change events.\n" + " Impacts transactions, recording, debugging.\n" + " -noperfinfo Do not try to update the performance info object\n" + " counting number of matches and rewrites."); return(1); } if (!File.Exists(specFile)) { if (File.Exists(specFile + ".grg")) { specFile += ".grg"; } else { Console.Error.WriteLine("The GRG-file \"" + specFile + "\" does not exist!"); return(1); } } specFile = FixDirectorySeparators(specFile); String specDir; int index = specFile.LastIndexOf(Path.DirectorySeparatorChar); if (index == -1) { specDir = ""; } else { specDir = specFile.Substring(0, index + 1); if (!Directory.Exists(specDir)) { Console.Error.WriteLine("Something is wrong with the directory of the specification file:\n\"" + specDir + "\" does not exist!"); return(1); } } if (destDir == null) { destDir = specDir; } if (dirname == null) { int id = 0; do { dirname = specDir + "tmpgrgen" + id + ""; id++; }while(Directory.Exists(dirname)); } if (!Directory.Exists(dirname)) { try { Directory.CreateDirectory(dirname); } catch (Exception) { Console.Error.WriteLine("Unable to create temporary directory \"" + dirname + "\"!"); return(1); } } if ((flags & ProcessSpecFlags.KeepGeneratedFiles) != 0) { Console.WriteLine("The generated files will be kept in: " + dirname); } if (backend == null) { backend = LGSPBackend.Instance; } int ret = 0; try { backend.ProcessSpecification(specFile, destDir, dirname, statisticsPath, flags, externalAssemblies.ToArray()); } catch (Exception ex) { Console.Error.WriteLine((flags & ProcessSpecFlags.CompileWithDebug) != 0 ? ex.ToString() : ex.Message); ret = 1; } if ((flags & ProcessSpecFlags.KeepGeneratedFiles) == 0 && (flags & ProcessSpecFlags.UseExistingMask) == ProcessSpecFlags.UseNoExistingFiles) { Directory.Delete(dirname, true); } return(ret); }
public void CreateFromSpec(string grgFilename, string graphName, String statisticsPath, ProcessSpecFlags flags, List <String> externalAssemblies, out IGraph newGraph, out IActions newActions) { LGSPGraph graph; LGSPActions actions; CreateFromSpec(grgFilename, graphName, statisticsPath, flags, externalAssemblies, false, 0, out graph, out actions); newGraph = graph; newActions = actions; }
/// <summary> /// Processes the given rule specification file and generates a model and actions library in the same directory as the specification file. /// </summary> /// <param name="specPath">The path to the rule specification file (.grg).</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed.</param> /// <param name="externalAssemblies">External assemblies to reference</param> public static void ProcessSpecification(String specPath, String statisticsPath, ProcessSpecFlags flags, params String[] externalAssemblies) { specPath = FixDirectorySeparators(specPath); String specDir; int index = specPath.LastIndexOf(Path.DirectorySeparatorChar); if(index == -1) specDir = ""; else { specDir = specPath.Substring(0, index + 1); if(!Directory.Exists(specDir)) throw new Exception("Something is wrong with the directory of the specification file:\n\"" + specDir + "\" does not exist!"); } String dirname; int id = 0; do { dirname = specDir + "tmpgrgen" + id + ""; id++; } while(Directory.Exists(dirname)); try { Directory.CreateDirectory(dirname); } catch(Exception ex) { throw new Exception("Unable to create temporary directory \"" + dirname + "\"!", ex); } try { ProcessSpecification(specPath, specDir, dirname, statisticsPath, flags, externalAssemblies); } finally { Directory.Delete(dirname, true); } }
/// <summary> /// Creates a new LGSPGraph or LGSPNamedGraph instance from the specified specification file. /// If the according dll does not exist or is out of date, the needed processing steps are performed automatically. /// </summary> /// <param name="gmFilename">Filename of the model specification file (.gm).</param> /// <param name="graphName">Name of the new graph.</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed; only KeepGeneratedFiles and CompileWithDebug are taken care of!</param> /// <param name="externalAssemblies">List of external assemblies to reference.</param> /// <param name="named">Returns a named graph if true otherwise a non-named graph. You must cast the LGSPGraph returned to the inherited LGSPNamedGraph if named=true.</param> /// <param name="capacity">The initial capacity for the name maps (performance optimization, use 0 if unsure).</param> /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception> /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception> /// <returns>The new LGSPGraph or LGSPNamedGraph instance.</returns> public LGSPGraph CreateFromSpec(String gmFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List<String> externalAssemblies, bool named, int capacity) { if(!File.Exists(gmFilename)) throw new FileNotFoundException("The model specification file \"" + gmFilename + "\" does not exist!", gmFilename); String modelFilename; if(MustGenerate(gmFilename, statisticsPath, flags, out modelFilename)) LGSPGrGen.ProcessSpecification(gmFilename, statisticsPath, flags, externalAssemblies.ToArray()); return CreateGraph(modelFilename, graphName, named, "capacity=" + capacity.ToString()); }
public void CreateNamedFromSpec(string grgFilename, string graphName, String statisticsPath, ProcessSpecFlags flags, List<String> externalAssemblies, int capacity, out INamedGraph newGraph, out IActions newActions) { LGSPGraph graph; LGSPActions actions; CreateFromSpec(grgFilename, graphName, statisticsPath, flags, externalAssemblies, true, capacity, out graph, out actions); newGraph = (LGSPNamedGraph)graph; newActions = actions; }
public void CreateFromSpec(string grgFilename, string graphName, String statisticsPath, ProcessSpecFlags flags, List<String> externalAssemblies, out IGraph newGraph, out IActions newActions) { LGSPGraph graph; LGSPActions actions; CreateFromSpec(grgFilename, graphName, statisticsPath, flags, externalAssemblies, false, 0, out graph, out actions); newGraph = graph; newActions = actions; }
/// <summary> /// Creates a new LGSPGraph or LGSPNamedGraph and LGSPActions instance from the specified specification file. /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically. /// </summary> /// <param name="grgFilename">Filename of the rule specification file (.grg).</param> /// <param name="graphName">Name of the new graph.</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed; only KeepGeneratedFiles and CompileWithDebug are taken care of!</param> /// <param name="externalAssemblies">List of external assemblies to reference.</param> /// <param name="named">Returns a named graph if true otherwise a non-named graph. You must cast the LGSPGraph returned to the inherited LGSPNamedGraph if named=true.</param> /// <param name="capacity">The initial capacity for the name maps, only used if named (performance optimization, use 0 if unsure).</param> /// <param name="newGraph">Returns the new graph.</param> /// <param name="newActions">Returns the new BaseActions object.</param> /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception> /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception> public void CreateFromSpec(String grgFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List<String> externalAssemblies, bool named, int capacity, out LGSPGraph newGraph, out LGSPActions newActions) { if(!File.Exists(grgFilename)) throw new FileNotFoundException("The rule specification file \"" + grgFilename + "\" does not exist!", grgFilename); String actionsFilename; String modelFilename; if(MustGenerate(grgFilename, statisticsPath, flags, out actionsFilename, out modelFilename)) LGSPGrGen.ProcessSpecification(grgFilename, statisticsPath, flags, externalAssemblies.ToArray()); newGraph = named ? (LGSPNamedGraph)CreateNamedGraph(modelFilename, graphName, "capacity=" + capacity.ToString()) : (LGSPGraph)CreateGraph(modelFilename, graphName); newActions = LGSPActions.LoadActions(actionsFilename, newGraph); }
private bool MustGenerate(String gmFilename, String statisticsPath, ProcessSpecFlags flags, out String modelFilename) { String modelName = GetPathBaseName(gmFilename); String modelDir = GetDir(gmFilename); // Parse grg file and collect information about the used files and the main graph model List<String> neededFilenames = new List<String>(); neededFilenames.Add(gmFilename); if(statisticsPath != null) neededFilenames.Add(statisticsPath); Dictionary<String, object> processedModelFiles = new Dictionary<String, object>(); GetNeededFiles(modelDir, gmFilename, neededFilenames, processedModelFiles); modelFilename = modelDir + "lgsp-" + modelName + "Model.dll"; // Does the model library exist at all? if(!File.Exists(modelFilename)) return true; if(File.Exists(modelDir + modelName + "ModelExternalFunctionsImpl.cs")) neededFilenames.Add(modelDir + modelName + "ModelExternalFunctionsImpl.cs"); DateTime modelTime = File.GetLastWriteTime(modelFilename); return DepsOlder(modelTime, neededFilenames) || (flags & ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange) == ProcessSpecFlags.GenerateEvenIfSourcesDidNotChange; }
public INamedGraph CreateNamedFromSpec(String gmFilename, String graphName, String statisticsPath, ProcessSpecFlags flags, List<String> externalAssemblies, int capacity) { return (LGSPNamedGraph)CreateFromSpec(gmFilename, graphName, statisticsPath, flags, externalAssemblies, true, capacity); }
/// <summary> /// Processes the given rule specification file and generates a model and actions library. /// </summary> /// <param name="specPath">The path to the rule specification file (.grg).</param> /// <param name="destDir">The directory, where the generated libraries are to be placed.</param> /// <param name="intermediateDir">A directory, where intermediate files can be placed.</param> /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param> /// <param name="flags">Specifies how the specification is to be processed.</param> /// <param name="externalAssemblies">External assemblies to reference</param> /// <exception cref="System.Exception">Thrown, when an error occurred.</exception> public static void ProcessSpecification(String specPath, String destDir, String intermediateDir, String statisticsPath, ProcessSpecFlags flags, params String[] externalAssemblies) { ErrorType ret; try { ret = new LGSPGrGen(flags).ProcessSpecificationImpl(specPath, destDir, intermediateDir, statisticsPath, externalAssemblies); } catch(Exception ex) { Console.WriteLine(ex); throw ex; } if(ret != ErrorType.NoError) { if(ret == ErrorType.GrGenJavaError && File.Exists(intermediateDir + Path.DirectorySeparatorChar + "printOutput.txt")) { using(StreamReader sr = new StreamReader(intermediateDir + Path.DirectorySeparatorChar + "printOutput.txt")) { String output = sr.ReadToEnd(); if(output.Length != 0) throw new Exception("\nError while processing specification:\n" + output); } } throw new Exception("Error while processing specification!"); } }