1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
19 using System
.Windows
.Forms
;
21 using Castle
.Rook
.Compiler
;
22 using Castle
.Rook
.Compiler
.AST
;
23 using Castle
.Rook
.Compiler
.Services
;
27 /// Summary description for Form1.
29 public class Form1
: System
.Windows
.Forms
.Form
31 private System
.Windows
.Forms
.TabControl tabControl1
;
32 private System
.Windows
.Forms
.TabPage tabPage1
;
33 private System
.Windows
.Forms
.TabPage tabPage2
;
34 private System
.Windows
.Forms
.TabPage tabPage3
;
35 private System
.Windows
.Forms
.RichTextBox sourceCode
;
36 private System
.Windows
.Forms
.TreeView rawAST
;
37 private System
.Windows
.Forms
.ListView listView1
;
38 private System
.Windows
.Forms
.ColumnHeader columnHeader1
;
39 private System
.Windows
.Forms
.ColumnHeader columnHeader2
;
40 private System
.Windows
.Forms
.ColumnHeader columnHeader3
;
41 private System
.Windows
.Forms
.ColumnHeader columnHeader4
;
43 /// Required designer variable.
45 private System
.ComponentModel
.Container components
= null;
47 private UICompilerContainer container
= new UICompilerContainer();
48 private System
.Windows
.Forms
.TreeView resultingAST
;
49 private System
.Windows
.Forms
.Panel panel1
;
50 private System
.Windows
.Forms
.CheckBox checkBox1
;
51 private System
.Windows
.Forms
.Button button2
;
52 private System
.Windows
.Forms
.Button button1
;
53 private System
.Windows
.Forms
.PropertyGrid propertyGrid1
;
55 private UIErrorReport errorReport
;
59 InitializeComponent();
61 errorReport
= container
[ typeof(IErrorReport
) ] as UIErrorReport
;
63 FileInfo info
= new FileInfo( "source.rook.txt" );
65 if (!info
.Exists
) return;
67 using(StreamReader reader
= new StreamReader(info
.FullName
))
69 sourceCode
.Text
= reader
.ReadToEnd();
74 /// Clean up any resources being used.
76 protected override void Dispose( bool disposing
)
80 if (components
!= null)
85 base.Dispose( disposing
);
88 #region Windows Form Designer generated code
90 /// Required method for Designer support - do not modify
91 /// the contents of this method with the code editor.
93 private void InitializeComponent()
95 this.tabControl1
= new System
.Windows
.Forms
.TabControl();
96 this.tabPage1
= new System
.Windows
.Forms
.TabPage();
97 this.sourceCode
= new System
.Windows
.Forms
.RichTextBox();
98 this.tabPage2
= new System
.Windows
.Forms
.TabPage();
99 this.rawAST
= new System
.Windows
.Forms
.TreeView();
100 this.tabPage3
= new System
.Windows
.Forms
.TabPage();
101 this.resultingAST
= new System
.Windows
.Forms
.TreeView();
102 this.listView1
= new System
.Windows
.Forms
.ListView();
103 this.columnHeader1
= new System
.Windows
.Forms
.ColumnHeader();
104 this.columnHeader2
= new System
.Windows
.Forms
.ColumnHeader();
105 this.columnHeader3
= new System
.Windows
.Forms
.ColumnHeader();
106 this.columnHeader4
= new System
.Windows
.Forms
.ColumnHeader();
107 this.panel1
= new System
.Windows
.Forms
.Panel();
108 this.propertyGrid1
= new System
.Windows
.Forms
.PropertyGrid();
109 this.checkBox1
= new System
.Windows
.Forms
.CheckBox();
110 this.button2
= new System
.Windows
.Forms
.Button();
111 this.button1
= new System
.Windows
.Forms
.Button();
112 this.tabControl1
.SuspendLayout();
113 this.tabPage1
.SuspendLayout();
114 this.tabPage2
.SuspendLayout();
115 this.tabPage3
.SuspendLayout();
116 this.panel1
.SuspendLayout();
117 this.SuspendLayout();
121 this.tabControl1
.Controls
.Add(this.tabPage1
);
122 this.tabControl1
.Controls
.Add(this.tabPage2
);
123 this.tabControl1
.Controls
.Add(this.tabPage3
);
124 this.tabControl1
.Dock
= System
.Windows
.Forms
.DockStyle
.Fill
;
125 this.tabControl1
.Location
= new System
.Drawing
.Point(0, 0);
126 this.tabControl1
.Name
= "tabControl1";
127 this.tabControl1
.SelectedIndex
= 0;
128 this.tabControl1
.Size
= new System
.Drawing
.Size(880, 574);
129 this.tabControl1
.TabIndex
= 0;
133 this.tabPage1
.Controls
.Add(this.sourceCode
);
134 this.tabPage1
.Location
= new System
.Drawing
.Point(4, 22);
135 this.tabPage1
.Name
= "tabPage1";
136 this.tabPage1
.Size
= new System
.Drawing
.Size(872, 548);
137 this.tabPage1
.TabIndex
= 0;
138 this.tabPage1
.Text
= "Source";
142 this.sourceCode
.Dock
= System
.Windows
.Forms
.DockStyle
.Fill
;
143 this.sourceCode
.Font
= new System
.Drawing
.Font("Lucida Console", 11.25F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
144 this.sourceCode
.Location
= new System
.Drawing
.Point(0, 0);
145 this.sourceCode
.Name
= "sourceCode";
146 this.sourceCode
.Size
= new System
.Drawing
.Size(872, 548);
147 this.sourceCode
.TabIndex
= 0;
148 this.sourceCode
.Text
= "";
152 this.tabPage2
.Controls
.Add(this.rawAST
);
153 this.tabPage2
.Location
= new System
.Drawing
.Point(4, 22);
154 this.tabPage2
.Name
= "tabPage2";
155 this.tabPage2
.Size
= new System
.Drawing
.Size(872, 548);
156 this.tabPage2
.TabIndex
= 1;
157 this.tabPage2
.Text
= "Raw AST";
161 this.rawAST
.Dock
= System
.Windows
.Forms
.DockStyle
.Fill
;
162 this.rawAST
.Font
= new System
.Drawing
.Font("Microsoft Sans Serif", 9.75F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
163 this.rawAST
.ImageIndex
= -1;
164 this.rawAST
.Location
= new System
.Drawing
.Point(0, 0);
165 this.rawAST
.Name
= "rawAST";
166 this.rawAST
.SelectedImageIndex
= -1;
167 this.rawAST
.Size
= new System
.Drawing
.Size(872, 548);
168 this.rawAST
.TabIndex
= 0;
169 this.rawAST
.AfterSelect
+= new System
.Windows
.Forms
.TreeViewEventHandler(this.rawAST_AfterSelect
);
173 this.tabPage3
.Controls
.Add(this.resultingAST
);
174 this.tabPage3
.Location
= new System
.Drawing
.Point(4, 22);
175 this.tabPage3
.Name
= "tabPage3";
176 this.tabPage3
.Size
= new System
.Drawing
.Size(872, 548);
177 this.tabPage3
.TabIndex
= 2;
178 this.tabPage3
.Text
= "After passes";
182 this.resultingAST
.Dock
= System
.Windows
.Forms
.DockStyle
.Fill
;
183 this.resultingAST
.Font
= new System
.Drawing
.Font("Microsoft Sans Serif", 9.75F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
184 this.resultingAST
.ImageIndex
= -1;
185 this.resultingAST
.Location
= new System
.Drawing
.Point(0, 0);
186 this.resultingAST
.Name
= "resultingAST";
187 this.resultingAST
.SelectedImageIndex
= -1;
188 this.resultingAST
.Size
= new System
.Drawing
.Size(872, 548);
189 this.resultingAST
.TabIndex
= 1;
190 this.resultingAST
.AfterSelect
+= new System
.Windows
.Forms
.TreeViewEventHandler(this.resultingAST_AfterSelect
);
194 this.listView1
.Columns
.AddRange(new System
.Windows
.Forms
.ColumnHeader
[] {
198 this.columnHeader4
});
199 this.listView1
.Dock
= System
.Windows
.Forms
.DockStyle
.Bottom
;
200 this.listView1
.GridLines
= true;
201 this.listView1
.HeaderStyle
= System
.Windows
.Forms
.ColumnHeaderStyle
.None
;
202 this.listView1
.Location
= new System
.Drawing
.Point(0, 486);
203 this.listView1
.Name
= "listView1";
204 this.listView1
.Size
= new System
.Drawing
.Size(880, 88);
205 this.listView1
.TabIndex
= 4;
206 this.listView1
.View
= System
.Windows
.Forms
.View
.Details
;
210 this.columnHeader1
.Text
= "file";
214 this.columnHeader2
.Text
= "position";
218 this.columnHeader3
.Text
= "cat";
222 this.columnHeader4
.Text
= "Message";
223 this.columnHeader4
.Width
= 400;
227 this.panel1
.Controls
.Add(this.propertyGrid1
);
228 this.panel1
.Controls
.Add(this.checkBox1
);
229 this.panel1
.Controls
.Add(this.button2
);
230 this.panel1
.Controls
.Add(this.button1
);
231 this.panel1
.Dock
= System
.Windows
.Forms
.DockStyle
.Right
;
232 this.panel1
.Location
= new System
.Drawing
.Point(640, 0);
233 this.panel1
.Name
= "panel1";
234 this.panel1
.Size
= new System
.Drawing
.Size(240, 486);
235 this.panel1
.TabIndex
= 12;
239 this.propertyGrid1
.CommandsVisibleIfAvailable
= true;
240 this.propertyGrid1
.Dock
= System
.Windows
.Forms
.DockStyle
.Bottom
;
241 this.propertyGrid1
.LargeButtons
= false;
242 this.propertyGrid1
.LineColor
= System
.Drawing
.SystemColors
.ScrollBar
;
243 this.propertyGrid1
.Location
= new System
.Drawing
.Point(0, 142);
244 this.propertyGrid1
.Name
= "propertyGrid1";
245 this.propertyGrid1
.Size
= new System
.Drawing
.Size(240, 344);
246 this.propertyGrid1
.TabIndex
= 15;
247 this.propertyGrid1
.Text
= "propertyGrid1";
248 this.propertyGrid1
.ViewBackColor
= System
.Drawing
.SystemColors
.Window
;
249 this.propertyGrid1
.ViewForeColor
= System
.Drawing
.SystemColors
.WindowText
;
253 this.checkBox1
.Checked
= true;
254 this.checkBox1
.CheckState
= System
.Windows
.Forms
.CheckState
.Checked
;
255 this.checkBox1
.Location
= new System
.Drawing
.Point(12, 16);
256 this.checkBox1
.Name
= "checkBox1";
257 this.checkBox1
.Size
= new System
.Drawing
.Size(112, 24);
258 this.checkBox1
.TabIndex
= 14;
259 this.checkBox1
.Text
= "Declaration Pass";
263 this.button2
.Location
= new System
.Drawing
.Point(28, 88);
264 this.button2
.Name
= "button2";
265 this.button2
.TabIndex
= 13;
266 this.button2
.Text
= "Reset";
270 this.button1
.Location
= new System
.Drawing
.Point(28, 56);
271 this.button1
.Name
= "button1";
272 this.button1
.TabIndex
= 12;
273 this.button1
.Text
= "&Compile";
274 this.button1
.Click
+= new System
.EventHandler(this.button1_Click_1
);
278 this.AutoScaleBaseSize
= new System
.Drawing
.Size(5, 13);
279 this.ClientSize
= new System
.Drawing
.Size(880, 574);
280 this.Controls
.Add(this.panel1
);
281 this.Controls
.Add(this.listView1
);
282 this.Controls
.Add(this.tabControl1
);
285 this.tabControl1
.ResumeLayout(false);
286 this.tabPage1
.ResumeLayout(false);
287 this.tabPage2
.ResumeLayout(false);
288 this.tabPage3
.ResumeLayout(false);
289 this.panel1
.ResumeLayout(false);
290 this.ResumeLayout(false);
296 /// The main entry point for the application.
301 Application
.Run(new Form1());
304 private void button1_Click_1(object sender
, System
.EventArgs e
)
306 listView1
.Items
.Clear();
310 Compiler comp
= new Compiler( container
);
312 comp
.PrePassExecution
+= new PassInfoHandler(PrePassExecution
);
313 comp
.PostPassExecution
+= new PassInfoHandler(PostPassExecution
);
315 comp
.Compile( sourceCode
.Text
);
320 private void SaveSource()
322 FileInfo info
= new FileInfo( "source.rook.txt" );
329 using( StreamWriter writer
= new StreamWriter(info
.FullName
) )
331 writer
.Write( sourceCode
.Text
);
336 private void PrePassExecution(object sender
, ICompilerPass pass
, CompilationUnit unit
, IErrorReport errorService
)
338 CreateAst(unit
, rawAST
.Nodes
);
341 private void PostPassExecution(object sender
, ICompilerPass pass
, CompilationUnit unit
, IErrorReport errorService
)
343 CreateAst(unit
, resultingAST
.Nodes
);
346 private void ShowErrors()
348 listView1
.Items
.Clear();
350 foreach(ErrorEntry entry
in errorReport
.List
)
352 ListViewItem item
= listView1
.Items
.Add( entry
.Filename
);
353 // item.SubItems.Add( entry.Pos );
354 item
.SubItems
.Add( "" );
355 item
.SubItems
.Add( entry
.IsError
? "error" : "warning" );
356 item
.SubItems
.Add( entry
.Contents
);
360 private void CreateAst(CompilationUnit unit
, TreeNodeCollection nodes
)
362 nodes
.Clear(); new TreeWalker(unit
, nodes
);
365 private void rawAST_AfterSelect(object sender
, TreeViewEventArgs e
)
367 propertyGrid1
.SelectedObject
= e
.Node
.Tag
;
370 private void resultingAST_AfterSelect(object sender
, TreeViewEventArgs e
)
372 propertyGrid1
.SelectedObject
= e
.Node
.Tag
;