/// <summary> /// Compiles all .akk files in a given folder and puts compiled version in /// a parallel folder structure elsewhere. /// </summary> public static void CompileAll(string sourcePath, string targetPath) { // Start timer DateTime startTime = DateTime.Now; // Delete C# files generated on a prior run (to avoid cruft) Console.WriteLine("Deleting obsolete C# files...\n"); System.IO.DirectoryInfo generatedFileInfo = new DirectoryInfo(targetPath); foreach (FileInfo file in generatedFileInfo.GetFiles()) { file.Delete(); } // Compile all files in .akk directory (in parallel) Console.WriteLine("Compiling .akk source files...\n"); string[] akkFiles = Directory.GetFiles(sourcePath, "*.akk", SearchOption.AllDirectories); Parallel.ForEach(akkFiles, f => { Compile(f, targetPath); }); // Generate metadata files // The next two steps consume 10% of the compilation time... Questions.GenerateMetadataFile(targetPath); Assumptions.GenerateAssumptionFile(targetPath); // Determine elapsed time TimeSpan duration = DateTime.Now - startTime; // Display compilation stats Console.WriteLine("\nStats...\n"); Console.WriteLine(" * Time: " + Math.Round(duration.TotalSeconds, 3) + "s"); Console.WriteLine(" * Files: " + akkFiles.Length); Console.WriteLine(" * Rules: " + (totalRuleCount - totalInputRuleCount)); Console.WriteLine(" * Inputs: " + totalInputRuleCount); Console.WriteLine(" * SLOC: " + SlocCount); }
/// <summary> /// Applies transformation rules to the input line. /// </summary> private static string Convert(string line, string previousLine, string fileName, string tableMatchLine, string currentRuleType, string docNameSpace) { // Perform general syntactic replacements line = line.Replace("|~", "^"); line = line.Replace("&", "&&").Replace("|", "||"); line = line.Replace("...", "("); line = line.Replace("<>", "!="); // Currency values line = Util.RemoveCurrencyStyling(line); // Stub() line = Regex.Replace(line, @"Stub\(\)", "new " + currentRuleType + "(Hstate.Stub)"); // Process question-related metadata and declared assumptions Questions.GatherMetadata(line, previousLine, fileName, docNameSpace); line = Assumptions.Process(line, docNameSpace); // Regex part const string word = @"[-!\+\*/A-Za-z0-9\.;\(\),""'_<>=&| %]+"; // Convert rules and dates line = ConvertRegularRules(line, docNameSpace); line = ConvertRuleTables(line, currentRuleType, tableMatchLine, word); // Facts.QueryTvar<Tvar>() // line = TransformMethod.QueryTvarTransform(line, docNameSpace, previousLine); // can be used to generate c# custom attributes line = TransformMethod.QueryTvarTransform(line, docNameSpace); // IfThen() line = Regex.Replace(line, @"if (?<txt>" + word + @") then (?<txt2>[-!\+\*/A-Za-z0-9\.;\(\),""'_<>= ]+)", "IfThen(${txt}, ${txt2})"); // Higher-order set functions line = Regex.Replace(line, @"\.(?<quant>(Exists|ForAll|Filter|Sum|Min|Max|OptimalSubset))\((?<fcn>[a-zA-Z0-9\(\)\._,\! ]+)\)", ".${quant}( _ => ${fcn})"); return(line); }