Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/14 17:33:22 (11 years ago)
Author:
jkarder
Message:

#2136:

  • refactored HLScriptGeneration to separate outputs from different running HL scripts.
  • added persistence support for HLScripts and fixed cloning
  • added code completion for all types in the currently loaded assemblies
  • merged trunk changes
Location:
branches/HLScript
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HLScript

  • branches/HLScript/HeuristicLab.HLScript/3.3/HLScript.cs

    r10332 r10358  
    1717
    1818namespace HeuristicLab.HLScript {
    19   [Item("HLScript", "A HeuristicLab script.")]
     19  [Item("HL Script", "A HeuristicLab script.")]
    2020  [Creatable("Scripts")]
    2121  [StorableClass]
     
    8484      : base(original, cloner) {
    8585      code = original.code;
    86       //      variableStore = cloner.Clone(original.variableStore);
    87       //      compiledHLScript = cloner.Clone(original.compiledHLScript)
     86      variableStore = new VariableStore();
    8887      compilationUnitCode = original.compilationUnitCode;
    8988      if (original.compileErrors != null)
     
    9291
    9392    public HLScript()
    94       : base("HLS") {
     93      : base("HL Script", "A HeuristicLab script.") {
    9594      code = CodeTemplate;
    96       variableStore = new VariableStore();
    97     }
    98 
    99     [StorableHook(HookType.AfterDeserialization)]
    100     private void AfterDeserialization() {
    101       compiledHLScript = null;
    10295      variableStore = new VariableStore();
    10396    }
     
    172165    }
    173166
     167    public IEnumerable<Assembly> GetAssemblies() {
     168      var assemblies = new List<Assembly>();
     169      foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
     170        try {
     171          if (File.Exists(a.Location)) assemblies.Add(a);
     172        } catch (NotSupportedException) {
     173          // NotSupportedException is thrown while accessing
     174          // the Location property of the anonymously hosted
     175          // dynamic methods assembly, which is related to
     176          // LINQ queries
     177        }
     178      }
     179      assemblies.Add(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly); // for dlr functionality
     180      return assemblies;
     181    }
     182
    174183    private readonly Regex LineSplitter = new Regex(@"\r\n|\r|\n");
    175184    private readonly Regex SafeTypeNameCharRegex = new Regex("[_a-zA-Z0-9]+");
     
    177186    private readonly Regex NamespaceDeclarationRegex = new Regex(@"using\s+(@?[a-z_A-Z]\w+(?:\s*\.\s*@?[a-z_A-Z]\w*)*)\s*;");
    178187    private readonly Regex NamespaceRegex = new Regex(@"(@?[a-z_A-Z]\w+(?:\s*\.\s*@?[a-z_A-Z]\w*)*)");
     188    private readonly Regex CommentRegex = new Regex(@"((/\*)[^/]+(\*/))|(//.*)");
    179189
    180190    private CodeCompileUnit CreateCompilationUnit() {
     
    191201
    192202    private IEnumerable<string> GetNamespaces() {
    193       var strings = NamespaceDeclarationRegex.Matches(code)
     203      var strings = NamespaceDeclarationRegex.Matches(CommentRegex.Replace(code, string.Empty))
    194204                                             .Cast<Match>()
    195205                                             .Select(m => m.Value);
     
    207217          yield return trimmedLine;
    208218      }
    209     }
    210 
    211     private IEnumerable<Assembly> GetAssemblies() {
    212       var assemblies = new List<Assembly>();
    213       foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
    214         try {
    215           if (File.Exists(a.Location)) assemblies.Add(a);
    216         } catch (NotSupportedException) {
    217           // NotSupportedException is thrown while accessing
    218           // the Location property of the anonymously hosted
    219           // dynamic methods assembly, which is related to
    220           // LINQ queries
    221         }
    222       }
    223       assemblies.Add(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly); // for dlr functionality
    224       return assemblies;
    225219    }
    226220
  • branches/HLScript/HeuristicLab.HLScript/3.3/HLScriptGeneration.cs

    r10332 r10358  
    88namespace HeuristicLab.HLScript {
    99  public abstract class HLScriptGeneration {
    10     protected static dynamic vars;
     10    protected dynamic vars;
     11
     12    private readonly EventWriter console;
     13    protected EventWriter Console {
     14      get { return console; }
     15    }
     16
     17    protected HLScriptGeneration() {
     18      console = new EventWriter(this);
     19    }
    1120
    1221    public abstract void Main();
     
    1423    private void Execute(VariableStore variableStore) {
    1524      vars = new Variables(variableStore);
    16       using (new EventWriter(this)) {
    17         try {
    18           Main();
    19         } catch (ThreadAbortException) {
    20         } catch (Exception e) {
    21           Console.WriteLine("---");
    22           Console.WriteLine(e);
    23         }
     25      try {
     26        Main();
     27      } catch (ThreadAbortException) {
     28      } catch (Exception e) {
     29        Console.WriteLine("---");
     30        Console.WriteLine(e);
    2431      }
    2532    }
     
    4855    }
    4956
    50     private class EventWriter : TextWriter {
    51       private readonly TextWriter consoleOut;
     57    protected class EventWriter : TextWriter {
    5258      private readonly HLScriptGeneration hlsg;
    53       private bool disposed;
    5459
    5560      public EventWriter(HLScriptGeneration hlsg) {
    5661        this.hlsg = hlsg;
    57         consoleOut = Console.Out;
    58         Console.SetOut(this);
    59         disposed = false;
    6062      }
    6163
     
    106108      #endregion
    107109      #endregion
    108 
    109       protected override void Dispose(bool disposing) {
    110         if (!disposed && disposing)
    111           Console.SetOut(consoleOut);
    112         disposed = true;
    113       }
    114110    }
    115111  }
Note: See TracChangeset for help on using the changeset viewer.