From 11092c11ff1ec8eb17ab32eda3455604c6b9933c Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 14 Dec 2018 18:48:53 +0100 Subject: [PATCH] Save module dependencies in script, so we can easily read these --- Upsilon/Binder/Binder.cs | 4 +++- Upsilon/Binder/BoundStatements/BoundScript.cs | 6 +++++- Upsilon/Evaluator/Script.cs | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index 19252fe..6b0af2d 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -69,7 +69,7 @@ namespace Upsilon.Binder variable.ResultType = resultType; } _unboundFunctions = new Dictionary(); - return new BoundScript((BoundBlockStatement) bound, e.Span, Scope, fileName); + return new BoundScript((BoundBlockStatement) bound, e.Span, Scope, fileName, _script); } private BoundStatement BindStatement(StatementSyntax s) @@ -256,6 +256,8 @@ namespace Upsilon.Binder { var moduleName = be.Value.ToString(); var module = _script.Options.ModuleHandler.GetModule(_script, moduleName); + if (!_script.ModuleDependencies.Contains(moduleName)) + _script.ModuleDependencies.Add(moduleName); if (module == null) { var fullPath = Path.GetFullPath(_script.Options.ScriptLoader.ModulesPath); diff --git a/Upsilon/Binder/BoundStatements/BoundScript.cs b/Upsilon/Binder/BoundStatements/BoundScript.cs index e13d5ce..0e5fc3e 100644 --- a/Upsilon/Binder/BoundStatements/BoundScript.cs +++ b/Upsilon/Binder/BoundStatements/BoundScript.cs @@ -1,15 +1,19 @@ using System.Collections.Generic; +using Upsilon.Evaluator; using Upsilon.Text; namespace Upsilon.Binder { public class BoundScript : BoundStatement { - public BoundScript(BoundBlockStatement statement, TextSpan span, BoundScope scope, string fileName) : base(span) + public Script Script { get; } + + public BoundScript(BoundBlockStatement statement, TextSpan span, BoundScope scope, string fileName, Script script) : base(span) { Statement = statement; Scope = scope; FileName = fileName; + Script = script; } public string FileName { get; set; } diff --git a/Upsilon/Evaluator/Script.cs b/Upsilon/Evaluator/Script.cs index e4e60fe..7b53dac 100644 --- a/Upsilon/Evaluator/Script.cs +++ b/Upsilon/Evaluator/Script.cs @@ -25,6 +25,7 @@ namespace Upsilon.Evaluator public Diagnostics Diagnostics { get; } private Binder.Binder Binder { get; } private EvaluationScope Scope { get; } + public List ModuleDependencies { get; } = new List(); internal Script(string scriptString, string fileName, ScriptOptions options ) {