Commits

Jesse McGrew committed 0e09ce6

Added local routine scope display

  • Participants
  • Parent commits 0f6c8c9

Comments (0)

Files changed (5)

File Rellor.Core/CompileTimeType.cs

         public static readonly CompileTimeType Number = new NumberType();
         public static readonly CompileTimeType String = new StringType();
         public static readonly CompileTimeType Object = new ObjectType();
+        public static readonly CompileTimeType Routine = new RoutineType();
 
         private class UnknownType : CompileTimeType
         {
                 get { return "object"; }
             }
         }
+
+        private class RoutineType : CompileTimeType
+        {
+            public override string Name
+            {
+                get { return "routine"; }
+            }
+        }
     }
 }

File Rellor.Core/Inform6.g3

 		{if ($nested) {
 			logger.Log(CoreMessages.RoutinesNotNestable, $routine_directive.start);
 			omit = true;
-		 } else
-			DefineSymbol($Symbols::scope, SymbolType.Routine, $routine_directive.identifier, $routine_directive.tree);}
+		 } else {
+			var rsym = DefineSymbol($Symbols::scope, SymbolType.Routine, $routine_directive.identifier, $routine_directive.tree);
+			//XXX should probably be some kind of RoutineDef structure instead of just a scope
+			rsym.Value = new CompileTimeValue<IRoutineScope>(BackpatchType.Routine, (IRoutineScope)$routine_directive.routineScope, CompileTimeType.Routine);
+		 }}
     |	array_directive
 		{DefineSymbol($Symbols::scope, SymbolType.Array, $array_directive.identifier, $array_directive.tree);}
     |	global_directive

File Rellor.Core/Scope.cs

         public string Serial { get; set; }
     }
 
-    class RoutineScope : ScopeBase
+    [ContractClass(typeof(IRoutineScopeContract))]
+    public interface IRoutineScope : IScope
+    {
+        string RoutineName { get; set; }
+    }
+
+    [ContractClassFor(typeof(IRoutineScope))]
+    internal abstract class IRoutineScopeContract : IRoutineScope
+    {
+        public string RoutineName { get; set; }
+
+        [ContractInvariantMethod]
+        private void ObjectInvariant()
+        {
+            Contract.Invariant(RoutineName != null);
+        }
+
+        #region IScope Members
+        public abstract string Name { get; }
+        public abstract Symbol Resolve(string name);
+        public abstract void Define(string name, Symbol symbol);
+        public abstract IEnumerable<KeyValuePair<string, Symbol>> AllSymbols();
+        #endregion
+    }
+
+    class RoutineScope : ScopeBase, IRoutineScope
     {
         public RoutineScope(IScope enclosingScope, string routineName)
             : base(enclosingScope)

File RellorPad/MainForm.Designer.cs

         private void InitializeComponent()
         {
             this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+            this.splitContainer2 = new System.Windows.Forms.SplitContainer();
+            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+            this.txtSourceCode = new System.Windows.Forms.TextBox();
+            this.btnAnalyze = new System.Windows.Forms.Button();
+            this.lvMessages = new System.Windows.Forms.ListView();
+            this.colFile = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+            this.colLine = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+            this.colPos = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+            this.colLevel = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+            this.colCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+            this.colMessage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.tabControl1 = new System.Windows.Forms.TabControl();
             this.astPage = new System.Windows.Forms.TabPage();
             this.tvAST = new System.Windows.Forms.TreeView();
             this.menuStrip1 = new System.Windows.Forms.MenuStrip();
             this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.samplesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
-            this.splitContainer2 = new System.Windows.Forms.SplitContainer();
-            this.lvMessages = new System.Windows.Forms.ListView();
-            this.colFile = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-            this.colLine = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-            this.colPos = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-            this.colLevel = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-            this.colCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-            this.colMessage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
-            this.txtSourceCode = new System.Windows.Forms.TextBox();
-            this.btnAnalyze = new System.Windows.Forms.Button();
             ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
             this.splitContainer1.Panel1.SuspendLayout();
             this.splitContainer1.Panel2.SuspendLayout();
             this.splitContainer1.SuspendLayout();
-            this.tabControl1.SuspendLayout();
-            this.astPage.SuspendLayout();
-            this.tabPage1.SuspendLayout();
-            this.menuStrip1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
             this.splitContainer2.Panel1.SuspendLayout();
             this.splitContainer2.Panel2.SuspendLayout();
             this.splitContainer2.SuspendLayout();
             this.tableLayoutPanel1.SuspendLayout();
+            this.tabControl1.SuspendLayout();
+            this.astPage.SuspendLayout();
+            this.tabPage1.SuspendLayout();
+            this.menuStrip1.SuspendLayout();
             this.SuspendLayout();
             // 
             // splitContainer1
             this.splitContainer1.SplitterDistance = 422;
             this.splitContainer1.TabIndex = 0;
             // 
-            // tabControl1
-            // 
-            this.tabControl1.Controls.Add(this.astPage);
-            this.tabControl1.Controls.Add(this.tabPage1);
-            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.tabControl1.Location = new System.Drawing.Point(0, 0);
-            this.tabControl1.Name = "tabControl1";
-            this.tabControl1.SelectedIndex = 0;
-            this.tabControl1.Size = new System.Drawing.Size(297, 400);
-            this.tabControl1.TabIndex = 0;
-            // 
-            // astPage
-            // 
-            this.astPage.Controls.Add(this.tvAST);
-            this.astPage.Location = new System.Drawing.Point(4, 22);
-            this.astPage.Name = "astPage";
-            this.astPage.Padding = new System.Windows.Forms.Padding(3);
-            this.astPage.Size = new System.Drawing.Size(289, 374);
-            this.astPage.TabIndex = 0;
-            this.astPage.Text = "AST";
-            this.astPage.UseVisualStyleBackColor = true;
-            // 
-            // tvAST
-            // 
-            this.tvAST.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.tvAST.Location = new System.Drawing.Point(3, 3);
-            this.tvAST.Name = "tvAST";
-            this.tvAST.Size = new System.Drawing.Size(283, 368);
-            this.tvAST.TabIndex = 0;
-            // 
-            // tabPage1
-            // 
-            this.tabPage1.Controls.Add(this.tvGlobalScope);
-            this.tabPage1.Location = new System.Drawing.Point(4, 22);
-            this.tabPage1.Name = "tabPage1";
-            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
-            this.tabPage1.Size = new System.Drawing.Size(287, 329);
-            this.tabPage1.TabIndex = 1;
-            this.tabPage1.Text = "Global Scope";
-            this.tabPage1.UseVisualStyleBackColor = true;
-            // 
-            // tvGlobalScope
-            // 
-            this.tvGlobalScope.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.tvGlobalScope.Location = new System.Drawing.Point(3, 3);
-            this.tvGlobalScope.Name = "tvGlobalScope";
-            this.tvGlobalScope.Size = new System.Drawing.Size(281, 323);
-            this.tvGlobalScope.TabIndex = 0;
-            // 
-            // menuStrip1
-            // 
-            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
-            this.fileToolStripMenuItem,
-            this.samplesToolStripMenuItem});
-            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
-            this.menuStrip1.Name = "menuStrip1";
-            this.menuStrip1.Size = new System.Drawing.Size(723, 24);
-            this.menuStrip1.TabIndex = 1;
-            this.menuStrip1.Text = "menuStrip1";
-            // 
-            // fileToolStripMenuItem
-            // 
-            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
-            this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
-            this.fileToolStripMenuItem.Text = "&File";
-            // 
-            // samplesToolStripMenuItem
-            // 
-            this.samplesToolStripMenuItem.Name = "samplesToolStripMenuItem";
-            this.samplesToolStripMenuItem.Size = new System.Drawing.Size(63, 20);
-            this.samplesToolStripMenuItem.Text = "&Samples";
-            // 
             // splitContainer2
             // 
             this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
             this.splitContainer2.SplitterDistance = 271;
             this.splitContainer2.TabIndex = 4;
             // 
+            // tableLayoutPanel1
+            // 
+            this.tableLayoutPanel1.ColumnCount = 1;
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+            this.tableLayoutPanel1.Controls.Add(this.txtSourceCode, 0, 0);
+            this.tableLayoutPanel1.Controls.Add(this.btnAnalyze, 0, 1);
+            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
+            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+            this.tableLayoutPanel1.RowCount = 2;
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
+            this.tableLayoutPanel1.Size = new System.Drawing.Size(422, 271);
+            this.tableLayoutPanel1.TabIndex = 1;
+            // 
+            // txtSourceCode
+            // 
+            this.txtSourceCode.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.txtSourceCode.Location = new System.Drawing.Point(3, 3);
+            this.txtSourceCode.Multiline = true;
+            this.txtSourceCode.Name = "txtSourceCode";
+            this.txtSourceCode.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
+            this.txtSourceCode.Size = new System.Drawing.Size(416, 236);
+            this.txtSourceCode.TabIndex = 0;
+            // 
+            // btnAnalyze
+            // 
+            this.btnAnalyze.Anchor = System.Windows.Forms.AnchorStyles.None;
+            this.btnAnalyze.Location = new System.Drawing.Point(173, 245);
+            this.btnAnalyze.Name = "btnAnalyze";
+            this.btnAnalyze.Size = new System.Drawing.Size(75, 23);
+            this.btnAnalyze.TabIndex = 1;
+            this.btnAnalyze.Text = "Analyze";
+            this.btnAnalyze.UseVisualStyleBackColor = true;
+            this.btnAnalyze.Click += new System.EventHandler(this.btnAnalyze_Click);
+            // 
             // lvMessages
             // 
             this.lvMessages.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
             this.colMessage.Text = "Message";
             this.colMessage.Width = 300;
             // 
-            // tableLayoutPanel1
+            // tabControl1
             // 
-            this.tableLayoutPanel1.ColumnCount = 1;
-            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
-            this.tableLayoutPanel1.Controls.Add(this.txtSourceCode, 0, 0);
-            this.tableLayoutPanel1.Controls.Add(this.btnAnalyze, 0, 1);
-            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
-            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
-            this.tableLayoutPanel1.RowCount = 2;
-            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
-            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
-            this.tableLayoutPanel1.Size = new System.Drawing.Size(422, 271);
-            this.tableLayoutPanel1.TabIndex = 1;
+            this.tabControl1.Controls.Add(this.astPage);
+            this.tabControl1.Controls.Add(this.tabPage1);
+            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.tabControl1.Location = new System.Drawing.Point(0, 0);
+            this.tabControl1.Name = "tabControl1";
+            this.tabControl1.SelectedIndex = 0;
+            this.tabControl1.Size = new System.Drawing.Size(297, 400);
+            this.tabControl1.TabIndex = 0;
             // 
-            // txtSourceCode
+            // astPage
             // 
-            this.txtSourceCode.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.txtSourceCode.Location = new System.Drawing.Point(3, 3);
-            this.txtSourceCode.Multiline = true;
-            this.txtSourceCode.Name = "txtSourceCode";
-            this.txtSourceCode.Size = new System.Drawing.Size(416, 236);
-            this.txtSourceCode.TabIndex = 0;
+            this.astPage.Controls.Add(this.tvAST);
+            this.astPage.Location = new System.Drawing.Point(4, 22);
+            this.astPage.Name = "astPage";
+            this.astPage.Padding = new System.Windows.Forms.Padding(3);
+            this.astPage.Size = new System.Drawing.Size(289, 374);
+            this.astPage.TabIndex = 0;
+            this.astPage.Text = "AST";
+            this.astPage.UseVisualStyleBackColor = true;
             // 
-            // btnAnalyze
+            // tvAST
             // 
-            this.btnAnalyze.Anchor = System.Windows.Forms.AnchorStyles.None;
-            this.btnAnalyze.Location = new System.Drawing.Point(173, 245);
-            this.btnAnalyze.Name = "btnAnalyze";
-            this.btnAnalyze.Size = new System.Drawing.Size(75, 23);
-            this.btnAnalyze.TabIndex = 1;
-            this.btnAnalyze.Text = "Analyze";
-            this.btnAnalyze.UseVisualStyleBackColor = true;
-            this.btnAnalyze.Click += new System.EventHandler(this.btnAnalyze_Click);
+            this.tvAST.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.tvAST.Location = new System.Drawing.Point(3, 3);
+            this.tvAST.Name = "tvAST";
+            this.tvAST.Size = new System.Drawing.Size(283, 368);
+            this.tvAST.TabIndex = 0;
+            // 
+            // tabPage1
+            // 
+            this.tabPage1.Controls.Add(this.tvGlobalScope);
+            this.tabPage1.Location = new System.Drawing.Point(4, 22);
+            this.tabPage1.Name = "tabPage1";
+            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
+            this.tabPage1.Size = new System.Drawing.Size(289, 374);
+            this.tabPage1.TabIndex = 1;
+            this.tabPage1.Text = "Global Scope";
+            this.tabPage1.UseVisualStyleBackColor = true;
+            // 
+            // tvGlobalScope
+            // 
+            this.tvGlobalScope.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.tvGlobalScope.Location = new System.Drawing.Point(3, 3);
+            this.tvGlobalScope.Name = "tvGlobalScope";
+            this.tvGlobalScope.Size = new System.Drawing.Size(283, 368);
+            this.tvGlobalScope.TabIndex = 0;
+            // 
+            // menuStrip1
+            // 
+            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.fileToolStripMenuItem,
+            this.samplesToolStripMenuItem});
+            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+            this.menuStrip1.Name = "menuStrip1";
+            this.menuStrip1.Size = new System.Drawing.Size(723, 24);
+            this.menuStrip1.TabIndex = 1;
+            this.menuStrip1.Text = "menuStrip1";
+            // 
+            // fileToolStripMenuItem
+            // 
+            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
+            this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
+            this.fileToolStripMenuItem.Text = "&File";
+            // 
+            // samplesToolStripMenuItem
+            // 
+            this.samplesToolStripMenuItem.Name = "samplesToolStripMenuItem";
+            this.samplesToolStripMenuItem.Size = new System.Drawing.Size(63, 20);
+            this.samplesToolStripMenuItem.Text = "&Samples";
             // 
             // MainForm
             // 
             this.splitContainer1.Panel2.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
             this.splitContainer1.ResumeLayout(false);
-            this.tabControl1.ResumeLayout(false);
-            this.astPage.ResumeLayout(false);
-            this.tabPage1.ResumeLayout(false);
-            this.menuStrip1.ResumeLayout(false);
-            this.menuStrip1.PerformLayout();
             this.splitContainer2.Panel1.ResumeLayout(false);
             this.splitContainer2.Panel2.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
             this.splitContainer2.ResumeLayout(false);
             this.tableLayoutPanel1.ResumeLayout(false);
             this.tableLayoutPanel1.PerformLayout();
+            this.tabControl1.ResumeLayout(false);
+            this.astPage.ResumeLayout(false);
+            this.tabPage1.ResumeLayout(false);
+            this.menuStrip1.ResumeLayout(false);
+            this.menuStrip1.PerformLayout();
             this.ResumeLayout(false);
             this.PerformLayout();
 

File RellorPad/MainForm.cs

             analyzer.LogSink = this;
             analyzer.Load(MakeCharStream());
             DumpTree(analyzer);
-            DumpScope(analyzer);
+            DumpGlobalScope(analyzer);
         }
 
         private void DumpTree(Analyzer analyzer)
             return new ANTLRStringStream(txtSourceCode.Text, "<input>");
         }
 
-        private void DumpScope(Analyzer analyzer)
+        private void DumpGlobalScope(Analyzer analyzer)
         {
-            var scope = analyzer.GlobalScope;
+            var globalScope = analyzer.GlobalScope;
 
             tvGlobalScope.BeginUpdate();
             try
                 tvGlobalScope.Nodes.Clear();
 
                 var headerNode = tvGlobalScope.Nodes.Add("Header");
-                headerNode.Nodes.Add("Release " + scope.Release.ToString());
-                headerNode.Nodes.Add("Serial " + scope.Serial.ToString());
+                headerNode.Nodes.Add("Release " + globalScope.Release.ToString());
+                headerNode.Nodes.Add("Serial " + globalScope.Serial.ToString());
 
                 var symbolsNode = tvGlobalScope.Nodes.Add("Symbols");
-                foreach (var pair in scope.AllSymbols())
-                {
-                    var symbol = pair.Value;
-                    string text = DescribeSymbol(symbol);
-                    var thisNode = symbolsNode.Nodes.Add(text);
-
-                    switch (symbol.Type)
-                    {
-                        case SymbolType.Constant:
-                            thisNode.Nodes.Add(DescribeCTV(symbol.Value));
-                            break;
-                    }
-                }
+                DumpScope(globalScope, symbolsNode);
 
                 tvGlobalScope.ExpandAll();
             }
             }
         }
 
+        private void DumpScope(IScope scope, TreeNode parentNode)
+        {
+            foreach (var pair in scope.AllSymbols())
+            {
+                var symbol = pair.Value;
+                string text = DescribeSymbol(symbol);
+                var thisNode = parentNode.Nodes.Add(text);
+
+                switch (symbol.Type)
+                {
+                    case SymbolType.Constant:
+                        thisNode.Nodes.Add(DescribeCTV(symbol.Value));
+                        break;
+
+                    case SymbolType.Routine:
+                        var rs = (IRoutineScope)symbol.Value.GenericValue;
+                        DumpScope(rs, thisNode);
+                        break;
+                }
+            }
+        }
+
         private string DescribeCTV(CompileTimeValue ctv)
         {
             if (ctv == null)
         }
 
         #endregion
+
     }
 }