mirror of https://github.com/icsharpcode/ILSpy.git
230 changed files with 28453 additions and 37799 deletions
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.XmlDoc |
||||
{ |
||||
/// <summary>
|
||||
/// Adds XML documentation for member definitions.
|
||||
/// </summary>
|
||||
static class AddXmlDocTransform |
||||
{ |
||||
public static void Run(AstNode node) |
||||
{ |
||||
if (node is AttributedNode) { |
||||
MemberReference mr = node.Annotation<MemberReference>(); |
||||
if (mr != null && mr.Module != null) { |
||||
var xmldoc = XmlDocLoader.LoadDocumentation(mr.Module); |
||||
if (xmldoc != null) { |
||||
string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(mr)); |
||||
if (doc != null) { |
||||
InsertXmlDocumentation(node, new StringReader(doc)); |
||||
} |
||||
} |
||||
} |
||||
if (!(node is TypeDeclaration)) |
||||
return; // don't recurse into attributed nodes, except for type definitions
|
||||
} |
||||
foreach (AstNode child in node.Children) |
||||
Run(child); |
||||
} |
||||
|
||||
static void InsertXmlDocumentation(AstNode node, StringReader r) |
||||
{ |
||||
// Find the first non-empty line:
|
||||
string firstLine; |
||||
do { |
||||
firstLine = r.ReadLine(); |
||||
if (firstLine == null) |
||||
return; |
||||
} while (string.IsNullOrWhiteSpace(firstLine)); |
||||
string indentation = firstLine.Substring(0, firstLine.Length - firstLine.TrimStart().Length); |
||||
string line = firstLine; |
||||
int skippedWhitespaceLines = 0; |
||||
// Copy all lines from input to output, except for empty lines at the end.
|
||||
while (line != null) { |
||||
if (string.IsNullOrWhiteSpace(line)) { |
||||
skippedWhitespaceLines++; |
||||
} else { |
||||
while (skippedWhitespaceLines > 0) { |
||||
node.Parent.InsertChildBefore(node, new Comment(string.Empty, CommentType.Documentation), AstNode.Roles.Comment); |
||||
skippedWhitespaceLines--; |
||||
} |
||||
if (line.StartsWith(indentation, StringComparison.Ordinal)) |
||||
line = line.Substring(indentation.Length); |
||||
node.Parent.InsertChildBefore(node, new Comment(" " + line, CommentType.Documentation), AstNode.Roles.Comment); |
||||
} |
||||
line = r.ReadLine(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,151 @@
@@ -0,0 +1,151 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
partial class CSDemo |
||||
{ |
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null; |
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the control.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) { |
||||
if (components != null) { |
||||
components.Dispose(); |
||||
} |
||||
} |
||||
base.Dispose(disposing); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent() |
||||
{ |
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); |
||||
this.csharpCodeTextBox = new System.Windows.Forms.TextBox(); |
||||
this.resolveButton = new System.Windows.Forms.Button(); |
||||
this.csharpTreeView = new System.Windows.Forms.TreeView(); |
||||
this.csharpGenerateCodeButton = new System.Windows.Forms.Button(); |
||||
this.csharpParseButton = new System.Windows.Forms.Button(); |
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); |
||||
this.splitContainer1.Panel1.SuspendLayout(); |
||||
this.splitContainer1.Panel2.SuspendLayout(); |
||||
this.splitContainer1.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// splitContainer1
|
||||
//
|
||||
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.splitContainer1.Location = new System.Drawing.Point(0, 0); |
||||
this.splitContainer1.Name = "splitContainer1"; |
||||
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; |
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
this.splitContainer1.Panel1.Controls.Add(this.csharpCodeTextBox); |
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.resolveButton); |
||||
this.splitContainer1.Panel2.Controls.Add(this.csharpTreeView); |
||||
this.splitContainer1.Panel2.Controls.Add(this.csharpGenerateCodeButton); |
||||
this.splitContainer1.Panel2.Controls.Add(this.csharpParseButton); |
||||
this.splitContainer1.Size = new System.Drawing.Size(475, 406); |
||||
this.splitContainer1.SplitterDistance = 178; |
||||
this.splitContainer1.TabIndex = 1; |
||||
//
|
||||
// csharpCodeTextBox
|
||||
//
|
||||
this.csharpCodeTextBox.AcceptsReturn = true; |
||||
this.csharpCodeTextBox.AcceptsTab = true; |
||||
this.csharpCodeTextBox.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.csharpCodeTextBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); |
||||
this.csharpCodeTextBox.HideSelection = false; |
||||
this.csharpCodeTextBox.Location = new System.Drawing.Point(0, 0); |
||||
this.csharpCodeTextBox.Multiline = true; |
||||
this.csharpCodeTextBox.Name = "csharpCodeTextBox"; |
||||
this.csharpCodeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; |
||||
this.csharpCodeTextBox.Size = new System.Drawing.Size(475, 178); |
||||
this.csharpCodeTextBox.TabIndex = 0; |
||||
this.csharpCodeTextBox.Text = "using System;\r\nclass Test\r\n{\r\n public void Main(string[] args)\r\n {\r\n " + |
||||
" Console.WriteLine(\"Hello, World\");\r\n }\r\n}"; |
||||
this.csharpCodeTextBox.WordWrap = false; |
||||
this.csharpCodeTextBox.TextChanged += new System.EventHandler(this.CsharpCodeTextBoxTextChanged); |
||||
//
|
||||
// resolveButton
|
||||
//
|
||||
this.resolveButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.resolveButton.Location = new System.Drawing.Point(187, 3); |
||||
this.resolveButton.Name = "resolveButton"; |
||||
this.resolveButton.Size = new System.Drawing.Size(100, 23); |
||||
this.resolveButton.TabIndex = 3; |
||||
this.resolveButton.Text = "Resolve"; |
||||
this.resolveButton.UseVisualStyleBackColor = true; |
||||
this.resolveButton.Click += new System.EventHandler(this.ResolveButtonClick); |
||||
//
|
||||
// csharpTreeView
|
||||
//
|
||||
this.csharpTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
||||
| System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.csharpTreeView.HideSelection = false; |
||||
this.csharpTreeView.Location = new System.Drawing.Point(3, 32); |
||||
this.csharpTreeView.Name = "csharpTreeView"; |
||||
this.csharpTreeView.Size = new System.Drawing.Size(467, 189); |
||||
this.csharpTreeView.TabIndex = 2; |
||||
this.csharpTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.CSharpTreeViewAfterSelect); |
||||
//
|
||||
// csharpGenerateCodeButton
|
||||
//
|
||||
this.csharpGenerateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.csharpGenerateCodeButton.Location = new System.Drawing.Point(293, 2); |
||||
this.csharpGenerateCodeButton.Name = "csharpGenerateCodeButton"; |
||||
this.csharpGenerateCodeButton.Size = new System.Drawing.Size(100, 23); |
||||
this.csharpGenerateCodeButton.TabIndex = 1; |
||||
this.csharpGenerateCodeButton.Text = "Generate"; |
||||
this.csharpGenerateCodeButton.UseVisualStyleBackColor = true; |
||||
this.csharpGenerateCodeButton.Click += new System.EventHandler(this.CSharpGenerateCodeButtonClick); |
||||
//
|
||||
// csharpParseButton
|
||||
//
|
||||
this.csharpParseButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.csharpParseButton.Location = new System.Drawing.Point(81, 3); |
||||
this.csharpParseButton.Name = "csharpParseButton"; |
||||
this.csharpParseButton.Size = new System.Drawing.Size(100, 23); |
||||
this.csharpParseButton.TabIndex = 0; |
||||
this.csharpParseButton.Text = "Parse"; |
||||
this.csharpParseButton.UseVisualStyleBackColor = true; |
||||
this.csharpParseButton.Click += new System.EventHandler(this.CSharpParseButtonClick); |
||||
//
|
||||
// CSDemo
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||
this.Controls.Add(this.splitContainer1); |
||||
this.Name = "CSDemo"; |
||||
this.Size = new System.Drawing.Size(475, 406); |
||||
this.splitContainer1.Panel1.ResumeLayout(false); |
||||
this.splitContainer1.Panel1.PerformLayout(); |
||||
this.splitContainer1.Panel2.ResumeLayout(false); |
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); |
||||
this.splitContainer1.ResumeLayout(false); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.Button csharpParseButton; |
||||
private System.Windows.Forms.Button csharpGenerateCodeButton; |
||||
private System.Windows.Forms.TreeView csharpTreeView; |
||||
private System.Windows.Forms.Button resolveButton; |
||||
private System.Windows.Forms.TextBox csharpCodeTextBox; |
||||
private System.Windows.Forms.SplitContainer splitContainer1; |
||||
} |
||||
} |
@ -0,0 +1,232 @@
@@ -0,0 +1,232 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.Diagnostics; |
||||
using System.Drawing; |
||||
using System.IO; |
||||
using System.Reflection; |
||||
using System.Text; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
/// <summary>
|
||||
/// Description of CSDemo.
|
||||
/// </summary>
|
||||
public partial class CSDemo : UserControl |
||||
{ |
||||
public CSDemo() |
||||
{ |
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
InitializeComponent(); |
||||
|
||||
if (LicenseManager.UsageMode != LicenseUsageMode.Designtime) { |
||||
csharpCodeTextBox.SelectAll(); |
||||
CSharpParseButtonClick(null, null); |
||||
resolveButton.UseWaitCursor = true; |
||||
ThreadPool.QueueUserWorkItem( |
||||
delegate { |
||||
builtInLibs.Value.ToString(); |
||||
BeginInvoke(new Action(delegate { resolveButton.UseWaitCursor = false; })); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
CompilationUnit compilationUnit; |
||||
|
||||
void CSharpParseButtonClick(object sender, EventArgs e) |
||||
{ |
||||
CSharpParser parser = new CSharpParser(); |
||||
compilationUnit = parser.Parse(new StringReader(csharpCodeTextBox.Text)); |
||||
csharpTreeView.Nodes.Clear(); |
||||
foreach (var element in compilationUnit.Children) { |
||||
csharpTreeView.Nodes.Add(MakeTreeNode(element)); |
||||
} |
||||
SelectCurrentNode(csharpTreeView.Nodes); |
||||
resolveButton.Enabled = true; |
||||
} |
||||
|
||||
TreeNode MakeTreeNode(AstNode node) |
||||
{ |
||||
TreeNode t = new TreeNode(GetNodeTitle(node)); |
||||
t.Tag = node; |
||||
foreach (AstNode child in node.Children) { |
||||
t.Nodes.Add(MakeTreeNode(child)); |
||||
} |
||||
return t; |
||||
} |
||||
|
||||
string GetNodeTitle(AstNode node) |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
b.Append(node.Role.ToString()); |
||||
b.Append(": "); |
||||
b.Append(node.GetType().Name); |
||||
bool hasProperties = false; |
||||
foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { |
||||
if (p.Name == "NodeType" || p.Name == "IsNull") |
||||
continue; |
||||
if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) { |
||||
if (!hasProperties) { |
||||
hasProperties = true; |
||||
b.Append(" ("); |
||||
} else { |
||||
b.Append(", "); |
||||
} |
||||
b.Append(p.Name); |
||||
b.Append(" = "); |
||||
try { |
||||
object val = p.GetValue(node, null); |
||||
b.Append(val != null ? val.ToString() : "**null**"); |
||||
} catch (TargetInvocationException ex) { |
||||
b.Append("**" + ex.InnerException.GetType().Name + "**"); |
||||
} |
||||
} |
||||
} |
||||
if (hasProperties) |
||||
b.Append(")"); |
||||
return b.ToString(); |
||||
} |
||||
|
||||
bool SelectCurrentNode(TreeNodeCollection c) |
||||
{ |
||||
int selectionStart = csharpCodeTextBox.SelectionStart; |
||||
int selectionEnd = selectionStart + csharpCodeTextBox.SelectionLength; |
||||
foreach (TreeNode t in c) { |
||||
AstNode node = t.Tag as AstNode; |
||||
if (node != null |
||||
&& selectionStart >= GetOffset(csharpCodeTextBox, node.StartLocation) |
||||
&& selectionEnd <= GetOffset(csharpCodeTextBox, node.EndLocation)) |
||||
{ |
||||
if (selectionStart == selectionEnd |
||||
&& (selectionStart == GetOffset(csharpCodeTextBox, node.StartLocation) |
||||
|| selectionStart == GetOffset(csharpCodeTextBox, node.EndLocation))) |
||||
{ |
||||
// caret is on border of this node; don't expand
|
||||
csharpTreeView.SelectedNode = t; |
||||
} else { |
||||
t.Expand(); |
||||
if (!SelectCurrentNode(t.Nodes)) |
||||
csharpTreeView.SelectedNode = t; |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
void CSharpGenerateCodeButtonClick(object sender, EventArgs e) |
||||
{ |
||||
StringWriter w = new StringWriter(); |
||||
OutputVisitor output = new OutputVisitor(w, new CSharpFormattingOptions()); |
||||
compilationUnit.AcceptVisitor(output, null); |
||||
csharpCodeTextBox.Text = w.ToString(); |
||||
} |
||||
|
||||
int GetOffset(TextBox textBox, AstLocation location) |
||||
{ |
||||
return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1; |
||||
} |
||||
|
||||
void CSharpTreeViewAfterSelect(object sender, TreeViewEventArgs e) |
||||
{ |
||||
AstNode node = e.Node.Tag as AstNode; |
||||
if (node != null) { |
||||
int startOffset = GetOffset(csharpCodeTextBox, node.StartLocation); |
||||
int endOffset = GetOffset(csharpCodeTextBox, node.EndLocation); |
||||
csharpCodeTextBox.Select(startOffset, endOffset - startOffset); |
||||
} |
||||
} |
||||
|
||||
Lazy<IList<IProjectContent>> builtInLibs = new Lazy<IList<IProjectContent>>( |
||||
delegate { |
||||
Assembly[] assemblies = { |
||||
typeof(object).Assembly, // mscorlib
|
||||
typeof(Uri).Assembly, // System.dll
|
||||
typeof(System.Linq.Enumerable).Assembly, // System.Core.dll
|
||||
// typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll
|
||||
// typeof(System.Drawing.Bitmap).Assembly, // System.Drawing.dll
|
||||
// typeof(Form).Assembly, // System.Windows.Forms.dll
|
||||
typeof(ICSharpCode.NRefactory.TypeSystem.IProjectContent).Assembly, |
||||
}; |
||||
IProjectContent[] projectContents = new IProjectContent[assemblies.Length]; |
||||
Stopwatch total = Stopwatch.StartNew(); |
||||
Parallel.For( |
||||
0, assemblies.Length, |
||||
delegate (int i) { |
||||
Stopwatch w = Stopwatch.StartNew(); |
||||
CecilLoader loader = new CecilLoader(); |
||||
projectContents[i] = loader.LoadAssemblyFile(assemblies[i].Location); |
||||
Debug.WriteLine(Path.GetFileName(assemblies[i].Location) + ": " + w.Elapsed); |
||||
}); |
||||
Debug.WriteLine("Total: " + total.Elapsed); |
||||
return projectContents; |
||||
}); |
||||
|
||||
void ResolveButtonClick(object sender, EventArgs e) |
||||
{ |
||||
SimpleProjectContent project = new SimpleProjectContent(); |
||||
TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(project, "dummy.cs"); |
||||
compilationUnit.AcceptVisitor(convertVisitor, null); |
||||
project.UpdateProjectContent(null, convertVisitor.ParsedFile.TopLevelTypeDefinitions, null, null); |
||||
|
||||
List<ITypeResolveContext> projects = new List<ITypeResolveContext>(); |
||||
projects.Add(project); |
||||
projects.AddRange(builtInLibs.Value); |
||||
|
||||
using (var context = new CompositeTypeResolveContext(projects).Synchronize()) { |
||||
CSharpResolver resolver = new CSharpResolver(context); |
||||
|
||||
IResolveVisitorNavigator navigator = null; |
||||
if (csharpTreeView.SelectedNode != null) { |
||||
navigator = new NodeListResolveVisitorNavigator(new[] { (AstNode)csharpTreeView.SelectedNode.Tag }); |
||||
} |
||||
ResolveVisitor visitor = new ResolveVisitor(resolver, convertVisitor.ParsedFile, navigator); |
||||
visitor.Scan(compilationUnit); |
||||
csharpTreeView.BeginUpdate(); |
||||
ShowResolveResultsInTree(csharpTreeView.Nodes, visitor); |
||||
csharpTreeView.EndUpdate(); |
||||
} |
||||
} |
||||
|
||||
void ShowResolveResultsInTree(TreeNodeCollection c, ResolveVisitor v) |
||||
{ |
||||
foreach (TreeNode t in c) { |
||||
AstNode node = t.Tag as AstNode; |
||||
if (node != null) { |
||||
ResolveResult rr = v.GetResolveResult(node); |
||||
if (rr != null) |
||||
t.Text = GetNodeTitle(node) + " " + rr.ToString(); |
||||
else |
||||
t.Text = GetNodeTitle(node); |
||||
} |
||||
ShowResolveResultsInTree(t.Nodes, v); |
||||
} |
||||
} |
||||
|
||||
void CSharpCodeTextBoxKeyDown(object sender, KeyEventArgs e) |
||||
{ |
||||
if (e.Control && e.KeyCode == Keys.A) { |
||||
e.Handled = true; |
||||
csharpCodeTextBox.SelectAll(); |
||||
} |
||||
} |
||||
|
||||
void CsharpCodeTextBoxTextChanged(object sender, EventArgs e) |
||||
{ |
||||
resolveButton.Enabled = false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<root> |
||||
<!-- |
||||
Microsoft ResX Schema |
||||
|
||||
Version 2.0 |
||||
|
||||
The primary goals of this format is to allow a simple XML format |
||||
that is mostly human readable. The generation and parsing of the |
||||
various data types are done through the TypeConverter classes |
||||
associated with the data types. |
||||
|
||||
Example: |
||||
|
||||
... ado.net/XML headers & schema ... |
||||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
<resheader name="version">2.0</resheader> |
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
</data> |
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
<comment>This is a comment</comment> |
||||
</data> |
||||
|
||||
There are any number of "resheader" rows that contain simple |
||||
name/value pairs. |
||||
|
||||
Each data row contains a name, and value. The row also contains a |
||||
type or mimetype. Type corresponds to a .NET class that support |
||||
text/value conversion through the TypeConverter architecture. |
||||
Classes that don't support this are serialized and stored with the |
||||
mimetype set. |
||||
|
||||
The mimetype is used for serialized objects, and tells the |
||||
ResXResourceReader how to depersist the object. This is currently not |
||||
extensible. For a given mimetype the value must be set accordingly: |
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
that the ResXResourceWriter will generate, however the reader can |
||||
read any of the formats listed below. |
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
value : The object must be serialized into a byte array |
||||
: using a System.ComponentModel.TypeConverter |
||||
: and then encoded with base64 encoding. |
||||
--> |
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
<xsd:complexType> |
||||
<xsd:choice maxOccurs="unbounded"> |
||||
<xsd:element name="metadata"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||
<xsd:attribute name="type" type="xsd:string" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="assembly"> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="alias" type="xsd:string" /> |
||||
<xsd:attribute name="name" type="xsd:string" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="data"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="resheader"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:choice> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:schema> |
||||
<resheader name="resmimetype"> |
||||
<value>text/microsoft-resx</value> |
||||
</resheader> |
||||
<resheader name="version"> |
||||
<value>2.0</value> |
||||
</resheader> |
||||
<resheader name="reader"> |
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<resheader name="writer"> |
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
</root> |
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
// assign short name to the fake reflection type
|
||||
using dynamic = ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.Dynamic; |
||||
|
||||
[TestFixture] |
||||
public class ConditionalOperatorTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void PickMoreGeneralOfTheTypes() |
||||
{ |
||||
AssertType(typeof(object), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeResult(typeof(string)), MakeResult(typeof(object)))); |
||||
AssertType(typeof(long), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeResult(typeof(int)), MakeResult(typeof(long)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Null() |
||||
{ |
||||
AssertType(typeof(string), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeResult(typeof(string)), MakeConstant(null))); |
||||
AssertType(typeof(string), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeConstant(null), MakeResult(typeof(string)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void DynamicInArguments() |
||||
{ |
||||
AssertType(typeof(dynamic), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeResult(typeof(dynamic)), MakeResult(typeof(double)))); |
||||
|
||||
AssertType(typeof(dynamic), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeResult(typeof(double)), MakeResult(typeof(dynamic)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void DynamicInCondition() |
||||
{ |
||||
AssertType(typeof(double), resolver.ResolveConditional( |
||||
MakeResult(typeof(dynamic)), MakeResult(typeof(float)), MakeResult(typeof(double)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllDynamic() |
||||
{ |
||||
AssertType(typeof(dynamic), resolver.ResolveConditional( |
||||
MakeResult(typeof(dynamic)), MakeResult(typeof(dynamic)), MakeResult(typeof(dynamic)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ListOfDynamicAndListOfObject() |
||||
{ |
||||
AssertError(typeof(List<dynamic>), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeResult(typeof(List<object>)), MakeResult(typeof(List<dynamic>)))); |
||||
|
||||
AssertError(typeof(List<object>), resolver.ResolveConditional( |
||||
MakeResult(typeof(bool)), MakeResult(typeof(List<dynamic>)), MakeResult(typeof(List<object>)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Constant() |
||||
{ |
||||
AssertConstant(1L, resolver.ResolveConditional( |
||||
MakeConstant(true), MakeConstant(1), MakeConstant(2L))); |
||||
|
||||
AssertConstant(2L, resolver.ResolveConditional( |
||||
MakeConstant(false), MakeConstant(1), MakeConstant(2L))); |
||||
} |
||||
|
||||
[Test] |
||||
public void NotConstantIfFalsePortionNotConstant() |
||||
{ |
||||
AssertType(typeof(long), resolver.ResolveConditional( |
||||
MakeConstant(true), MakeConstant(1), MakeResult(typeof(long)))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem |
||||
{ |
||||
[TestFixture] |
||||
public class StructureTests |
||||
{ |
||||
[Test] |
||||
public void ClasesThatSupportInterningAreSealed() |
||||
{ |
||||
foreach (Type type in typeof(ISupportsInterning).Assembly.GetTypes()) { |
||||
if (typeof(ISupportsInterning).IsAssignableFrom(type) && !type.IsInterface) { |
||||
Assert.IsTrue(type.IsSealed, type.FullName); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Ensures that all nodes have the Parent property correctly set.
|
||||
/// </summary>
|
||||
public class CheckParentVisitor : NodeTrackingAstVisitor |
||||
{ |
||||
Stack<INode> nodeStack = new Stack<INode>(); |
||||
|
||||
public CheckParentVisitor() |
||||
{ |
||||
nodeStack.Push(null); |
||||
} |
||||
|
||||
protected override void BeginVisit(INode node) |
||||
{ |
||||
nodeStack.Push(node); |
||||
} |
||||
|
||||
protected override void EndVisit(INode node) |
||||
{ |
||||
Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!"); |
||||
Assert.AreSame(nodeStack.Peek(), node.Parent, "node " + node + " is missing parent: " + nodeStack.Peek()); |
||||
} |
||||
} |
||||
} |
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class DelegateDeclarationTests |
||||
{ |
||||
void TestDelegateDeclaration(DelegateDeclaration dd) |
||||
{ |
||||
Assert.AreEqual("System.Void", dd.ReturnType.Type); |
||||
Assert.AreEqual("MyDelegate", dd.Name); |
||||
} |
||||
|
||||
void TestParameters(DelegateDeclaration dd) |
||||
{ |
||||
Assert.AreEqual(3, dd.Parameters.Count); |
||||
|
||||
Assert.AreEqual("a", ((ParameterDeclarationExpression)dd.Parameters[0]).ParameterName); |
||||
Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[0]).TypeReference.Type); |
||||
|
||||
Assert.AreEqual("secondParam", ((ParameterDeclarationExpression)dd.Parameters[1]).ParameterName); |
||||
Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[1]).TypeReference.Type); |
||||
|
||||
Assert.AreEqual("lastParam", ((ParameterDeclarationExpression)dd.Parameters[2]).ParameterName); |
||||
Assert.AreEqual("MyObj", ((ParameterDeclarationExpression)dd.Parameters[2]).TypeReference.Type); |
||||
} |
||||
|
||||
#region VB.NET
|
||||
[Test] |
||||
public void SimpleVBNetDelegateDeclarationTest() |
||||
{ |
||||
string program = "Public Delegate Sub MyDelegate(ByVal a As Integer, ByVal secondParam As Integer, ByVal lastParam As MyObj)\n"; |
||||
TestDelegateDeclaration(ParseUtil.ParseGlobal<DelegateDeclaration>(program)); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,168 @@
@@ -0,0 +1,168 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ImportsStatementTests |
||||
{ |
||||
[Test] |
||||
public void InvalidImportsStatement() |
||||
{ |
||||
string program = "Imports\n"; |
||||
ParseUtil.ParseGlobal<ImportsStatement>(program, true); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidImportsStatement2() |
||||
{ |
||||
string program = "Imports ,\n"; |
||||
ParseUtil.ParseGlobal<ImportsStatement>(program, true); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleImportsStatement() |
||||
{ |
||||
string program = "Imports System\n"; |
||||
|
||||
var clause1 = new MemberImportsClause { |
||||
Member = new SimpleType("System") |
||||
}; |
||||
|
||||
var node = new ImportsStatement(); |
||||
node.AddChild(clause1, ImportsStatement.ImportsClauseRole); |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void QualifiedTypeImportsStatement() |
||||
{ |
||||
string program = "Imports My.Name.Space\n"; |
||||
|
||||
var clause2 = new MemberImportsClause { |
||||
Member = new QualifiedType(new QualifiedType(new SimpleType("My"), new Identifier("Name", AstLocation.Empty)), new Identifier("Space", AstLocation.Empty)) |
||||
}; |
||||
|
||||
var node = new ImportsStatement(); |
||||
node.AddChild(clause2, ImportsStatement.ImportsClauseRole); |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
//
|
||||
// [Test]
|
||||
// public void VBNetUsingAliasDeclarationTest()
|
||||
// {
|
||||
// string program = "Imports TESTME=System\n" +
|
||||
// "Imports myAlias=My.Name.Space\n" +
|
||||
// "Imports StringCollection = System.Collections.Generic.List(Of string)\n";
|
||||
// VBParser parser = ParserFactory.CreateParser(new StringReader(program));
|
||||
// parser.Parse();
|
||||
//
|
||||
// Assert.AreEqual("", parser.Errors.ErrorOutput);
|
||||
// CheckAliases(parser.CompilationUnit);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetComplexUsingAliasDeclarationTest()
|
||||
// {
|
||||
// string program = "Imports NS1, AL=NS2, NS3, AL2=NS4, NS5\n";
|
||||
// VBParser parser = ParserFactory.CreateParser(new StringReader(program));
|
||||
// parser.Parse();
|
||||
//
|
||||
// Assert.AreEqual("", parser.Errors.ErrorOutput);
|
||||
// // TODO : Extend test ...
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetXmlNamespaceUsingTest()
|
||||
// {
|
||||
// string program = "Imports <xmlns=\"http://icsharpcode.net/sharpdevelop/avalonedit\">";
|
||||
// VBParser parser = ParserFactory.CreateParser(new StringReader(program));
|
||||
// parser.Parse();
|
||||
//
|
||||
// Assert.AreEqual("", parser.Errors.ErrorOutput);
|
||||
// CompilationUnit unit = parser.CompilationUnit;
|
||||
//
|
||||
// Assert.AreEqual(1, unit.Children.Count);
|
||||
// Assert.IsTrue(unit.Children[0] is ImportsStatement);
|
||||
// ImportsStatement ud = (ImportsStatement)unit.Children[0];
|
||||
// Assert.AreEqual(1, ud.ImportsClauses.Count);
|
||||
// Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
|
||||
// Assert.IsTrue(ud.ImportsClauses[0].IsXml);
|
||||
//
|
||||
// Assert.AreEqual("xmlns", ud.ImportsClauses[0].XmlPrefix);
|
||||
// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetXmlNamespaceWithPrefixUsingTest()
|
||||
// {
|
||||
// string program = "Imports <xmlns:avalonedit=\"http://icsharpcode.net/sharpdevelop/avalonedit\">";
|
||||
// VBParser parser = ParserFactory.CreateParser(new StringReader(program));
|
||||
// parser.Parse();
|
||||
//
|
||||
// Assert.AreEqual("", parser.Errors.ErrorOutput);
|
||||
// CompilationUnit unit = parser.CompilationUnit;
|
||||
//
|
||||
// Assert.AreEqual(1, unit.Children.Count);
|
||||
// Assert.IsTrue(unit.Children[0] is ImportsStatement);
|
||||
// ImportsStatement ud = (ImportsStatement)unit.Children[0];
|
||||
// Assert.AreEqual(1, ud.ImportsClauses.Count);
|
||||
// Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
|
||||
// Assert.IsTrue(ud.ImportsClauses[0].IsXml);
|
||||
//
|
||||
// Assert.AreEqual("xmlns:avalonedit", ud.ImportsClauses[0].XmlPrefix);
|
||||
// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetXmlNamespaceSingleQuotedUsingTest()
|
||||
// {
|
||||
// string program = "Imports <xmlns='http://icsharpcode.net/sharpdevelop/avalonedit'>";
|
||||
// VBParser parser = ParserFactory.CreateParser(new StringReader(program));
|
||||
// parser.Parse();
|
||||
//
|
||||
// Assert.AreEqual("", parser.Errors.ErrorOutput);
|
||||
// CompilationUnit unit = parser.CompilationUnit;
|
||||
//
|
||||
// Assert.AreEqual(1, unit.Children.Count);
|
||||
// Assert.IsTrue(unit.Children[0] is ImportsStatement);
|
||||
// ImportsStatement ud = (ImportsStatement)unit.Children[0];
|
||||
// Assert.AreEqual(1, ud.ImportsClauses.Count);
|
||||
// Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
|
||||
// Assert.IsTrue(ud.ImportsClauses[0].IsXml);
|
||||
//
|
||||
// Assert.AreEqual("xmlns", ud.ImportsClauses[0].XmlPrefix);
|
||||
// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetXmlNamespaceSingleQuotedWithPrefixUsingTest()
|
||||
// {
|
||||
// string program = "Imports <xmlns:avalonedit='http://icsharpcode.net/sharpdevelop/avalonedit'>";
|
||||
// VBParser parser = ParserFactory.CreateParser(new StringReader(program));
|
||||
// parser.Parse();
|
||||
//
|
||||
// Assert.AreEqual("", parser.Errors.ErrorOutput);
|
||||
// CompilationUnit unit = parser.CompilationUnit;
|
||||
//
|
||||
// Assert.AreEqual(1, unit.Children.Count);
|
||||
// Assert.IsTrue(unit.Children[0] is ImportsStatement);
|
||||
// ImportsStatement ud = (ImportsStatement)unit.Children[0];
|
||||
// Assert.AreEqual(1, ud.ImportsClauses.Count);
|
||||
// Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
|
||||
// Assert.IsTrue(ud.ImportsClauses[0].IsXml);
|
||||
//
|
||||
// Assert.AreEqual("xmlns:avalonedit", ud.ImportsClauses[0].XmlPrefix);
|
||||
// Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
|
||||
// }
|
||||
// #endregion
|
||||
} |
||||
} |
@ -1,87 +0,0 @@
@@ -1,87 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class OptionDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void VBNetStrictOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Strict On\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Strict, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetExplicitOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Explicit Off\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Explicit, opDec.OptionType); |
||||
Assert.IsFalse(opDec.OptionValue, "Off option value excepted!"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetCompareBinaryOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Compare Binary\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.CompareBinary, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetCompareTextOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Compare Text\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.CompareText, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInferOnOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Infer On\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Infer, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInferOffOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Infer\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Infer, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInferOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Infer\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Infer, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInvalidOptionDeclarationTest() |
||||
{ |
||||
string program = "Option\n"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class OptionStatementTests |
||||
{ |
||||
[Test] |
||||
public void InvalidOptionSyntax() |
||||
{ |
||||
string program = "Option\n"; |
||||
ParseUtil.ParseGlobal<OptionStatement>(program, true); |
||||
} |
||||
|
||||
[Test] |
||||
public void StrictOption() |
||||
{ |
||||
string program = "Option Strict On\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Strict, |
||||
OptionValue = OptionValue.On |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExplicitOption() |
||||
{ |
||||
string program = "Option Explicit Off\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Explicit, |
||||
OptionValue = OptionValue.Off |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompareBinaryOption() |
||||
{ |
||||
string program = "Option Compare Binary\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Compare, |
||||
OptionValue = OptionValue.Binary |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompareTextOption() |
||||
{ |
||||
string program = "Option Compare Text\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Compare, |
||||
OptionValue = OptionValue.Text |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void InferOnOption() |
||||
{ |
||||
string program = "Option Infer On\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Infer, |
||||
OptionValue = OptionValue.On |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void InferOffOption() |
||||
{ |
||||
string program = "Option Infer Off\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Infer, |
||||
OptionValue = OptionValue.Off |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void InferOption() |
||||
{ |
||||
string program = "Option Infer\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Infer, |
||||
OptionValue = OptionValue.On |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
} |
||||
} |
@ -1,207 +0,0 @@
@@ -1,207 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class UsingDeclarationTests |
||||
{ |
||||
void CheckTwoSimpleUsings(CompilationUnit u) |
||||
{ |
||||
Assert.AreEqual(2, u.Children.Count); |
||||
Assert.IsTrue(u.Children[0] is UsingDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)u.Children[0]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsTrue(!ud.Usings[0].IsAlias); |
||||
Assert.AreEqual("System", ud.Usings[0].Name); |
||||
|
||||
|
||||
Assert.IsTrue(u.Children[1] is UsingDeclaration); |
||||
ud = (UsingDeclaration)u.Children[1]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsTrue(!ud.Usings[0].IsAlias); |
||||
Assert.AreEqual("My.Name.Space", ud.Usings[0].Name); |
||||
} |
||||
|
||||
void CheckAliases(CompilationUnit u) |
||||
{ |
||||
Assert.AreEqual(3, u.Children.Count); |
||||
|
||||
Assert.IsTrue(u.Children[0] is UsingDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)u.Children[0]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); |
||||
Assert.AreEqual("TESTME", ud.Usings[0].Name); |
||||
Assert.AreEqual("System", ud.Usings[0].Alias.Type); |
||||
|
||||
Assert.IsTrue(u.Children[1] is UsingDeclaration); |
||||
ud = (UsingDeclaration)u.Children[1]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); |
||||
Assert.AreEqual("myAlias", ud.Usings[0].Name); |
||||
Assert.AreEqual("My.Name.Space", ud.Usings[0].Alias.Type); |
||||
|
||||
Assert.IsTrue(u.Children[2] is UsingDeclaration); |
||||
ud = (UsingDeclaration)u.Children[2]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); |
||||
Assert.AreEqual("StringCollection", ud.Usings[0].Name); |
||||
Assert.AreEqual("System.Collections.Generic.List", ud.Usings[0].Alias.Type); |
||||
Assert.AreEqual("System.String", ud.Usings[0].Alias.GenericTypes[0].Type); |
||||
} |
||||
|
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetWrongUsingTest() |
||||
{ |
||||
string program = "Imports\n"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.IsTrue(parser.Errors.Count > 0); |
||||
UsingDeclaration u = (UsingDeclaration)parser.CompilationUnit.Children[0]; |
||||
foreach (Using us in u.Usings) { |
||||
Assert.IsNotNull(us); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetWrongUsing2Test() |
||||
{ |
||||
string program = "Imports ,\n"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.IsTrue(parser.Errors.Count > 0); |
||||
UsingDeclaration u = (UsingDeclaration)parser.CompilationUnit.Children[0]; |
||||
foreach (Using us in u.Usings) { |
||||
Assert.IsNotNull(us); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetDeclarationTest() |
||||
{ |
||||
string program = "Imports System\n" + |
||||
"Imports My.Name.Space\n"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
|
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
CheckTwoSimpleUsings(parser.CompilationUnit); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetUsingAliasDeclarationTest() |
||||
{ |
||||
string program = "Imports TESTME=System\n" + |
||||
"Imports myAlias=My.Name.Space\n" + |
||||
"Imports StringCollection = System.Collections.Generic.List(Of string)\n"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
|
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
CheckAliases(parser.CompilationUnit); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetComplexUsingAliasDeclarationTest() |
||||
{ |
||||
string program = "Imports NS1, AL=NS2, NS3, AL2=NS4, NS5\n"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
|
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
// TODO : Extend test ...
|
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetXmlNamespaceUsingTest() |
||||
{ |
||||
string program = "Imports <xmlns=\"http://icsharpcode.net/sharpdevelop/avalonedit\">"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
|
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
CompilationUnit unit = parser.CompilationUnit; |
||||
|
||||
Assert.AreEqual(1, unit.Children.Count); |
||||
Assert.IsTrue(unit.Children[0] is UsingDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsFalse(ud.Usings[0].IsAlias); |
||||
Assert.IsTrue(ud.Usings[0].IsXml); |
||||
|
||||
Assert.AreEqual("xmlns", ud.Usings[0].XmlPrefix); |
||||
Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetXmlNamespaceWithPrefixUsingTest() |
||||
{ |
||||
string program = "Imports <xmlns:avalonedit=\"http://icsharpcode.net/sharpdevelop/avalonedit\">"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
|
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
CompilationUnit unit = parser.CompilationUnit; |
||||
|
||||
Assert.AreEqual(1, unit.Children.Count); |
||||
Assert.IsTrue(unit.Children[0] is UsingDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsFalse(ud.Usings[0].IsAlias); |
||||
Assert.IsTrue(ud.Usings[0].IsXml); |
||||
|
||||
Assert.AreEqual("xmlns:avalonedit", ud.Usings[0].XmlPrefix); |
||||
Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetXmlNamespaceSingleQuotedUsingTest() |
||||
{ |
||||
string program = "Imports <xmlns='http://icsharpcode.net/sharpdevelop/avalonedit'>"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
|
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
CompilationUnit unit = parser.CompilationUnit; |
||||
|
||||
Assert.AreEqual(1, unit.Children.Count); |
||||
Assert.IsTrue(unit.Children[0] is UsingDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsFalse(ud.Usings[0].IsAlias); |
||||
Assert.IsTrue(ud.Usings[0].IsXml); |
||||
|
||||
Assert.AreEqual("xmlns", ud.Usings[0].XmlPrefix); |
||||
Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetXmlNamespaceSingleQuotedWithPrefixUsingTest() |
||||
{ |
||||
string program = "Imports <xmlns:avalonedit='http://icsharpcode.net/sharpdevelop/avalonedit'>"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
|
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
CompilationUnit unit = parser.CompilationUnit; |
||||
|
||||
Assert.AreEqual(1, unit.Children.Count); |
||||
Assert.IsTrue(unit.Children[0] is UsingDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; |
||||
Assert.AreEqual(1, ud.Usings.Count); |
||||
Assert.IsFalse(ud.Usings[0].IsAlias); |
||||
Assert.IsTrue(ud.Usings[0].IsXml); |
||||
|
||||
Assert.AreEqual("xmlns:avalonedit", ud.Usings[0].XmlPrefix); |
||||
Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
public class LocationAssignmentCheckVisitor : NodeTrackingAstVisitor |
||||
{ |
||||
protected override void BeginVisit(INode node) |
||||
{ |
||||
if (node is CompilationUnit) |
||||
return; |
||||
if (node is INullable && ((INullable)node).IsNull) |
||||
return; |
||||
if (node is TypeReference) |
||||
return; |
||||
|
||||
Assert.IsFalse(node.StartLocation.IsEmpty, "StartLocation of {0}", node); |
||||
Assert.IsFalse(node.EndLocation.IsEmpty, "EndLocation of {0}", node); |
||||
} |
||||
} |
||||
} |
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public abstract class AbstractNode : INode |
||||
{ |
||||
List<INode> children = new List<INode>(); |
||||
|
||||
public INode Parent { get; set; } |
||||
public Location StartLocation { get; set; } |
||||
public Location EndLocation { get; set; } |
||||
public object UserData { get; set; } |
||||
|
||||
public List<INode> Children { |
||||
get { |
||||
return children; |
||||
} |
||||
set { |
||||
Debug.Assert(value != null); |
||||
children = value; |
||||
} |
||||
} |
||||
|
||||
public virtual void AddChild(INode childNode) |
||||
{ |
||||
Debug.Assert(childNode != null); |
||||
childNode.Parent = this; |
||||
children.Add(childNode); |
||||
} |
||||
|
||||
public abstract object AcceptVisitor(IAstVisitor visitor, object data); |
||||
|
||||
public virtual object AcceptChildren(IAstVisitor visitor, object data) |
||||
{ |
||||
foreach (INode child in children) { |
||||
Debug.Assert(child != null); |
||||
child.AcceptVisitor(visitor, data); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
public static string GetCollectionString(ICollection collection) |
||||
{ |
||||
StringBuilder output = new StringBuilder(); |
||||
output.Append('{'); |
||||
|
||||
if (collection != null) { |
||||
IEnumerator en = collection.GetEnumerator(); |
||||
bool isFirst = true; |
||||
while (en.MoveNext()) { |
||||
if (!isFirst) { |
||||
output.Append(", "); |
||||
} else { |
||||
isFirst = false; |
||||
} |
||||
output.Append(en.Current == null ? "<null>" : en.Current.ToString()); |
||||
} |
||||
} else { |
||||
return "null"; |
||||
} |
||||
|
||||
output.Append('}'); |
||||
return output.ToString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,137 @@
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// DomLocation.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
[Serializable] |
||||
public struct AstLocation : IComparable<AstLocation>, IEquatable<AstLocation> |
||||
{ |
||||
public static readonly AstLocation Empty = new AstLocation(0, 0); |
||||
|
||||
readonly int line, column; |
||||
|
||||
public AstLocation (int line, int column) |
||||
{ |
||||
this.line = line; |
||||
this.column = column; |
||||
} |
||||
|
||||
public bool IsEmpty { |
||||
get { |
||||
return line <= 0; |
||||
} |
||||
} |
||||
|
||||
public int Line { |
||||
get { return line; } |
||||
} |
||||
|
||||
public int Column { |
||||
get { return column; } |
||||
} |
||||
|
||||
public override bool Equals (object obj) |
||||
{ |
||||
if (!(obj is AstLocation)) |
||||
return false; |
||||
return (AstLocation)obj == this; |
||||
} |
||||
|
||||
public override int GetHashCode () |
||||
{ |
||||
unchecked { |
||||
return line + column * 5000; |
||||
} |
||||
} |
||||
|
||||
public bool Equals (AstLocation other) |
||||
{ |
||||
return other == this; |
||||
} |
||||
|
||||
public int CompareTo (AstLocation other) |
||||
{ |
||||
if (this == other) |
||||
return 0; |
||||
if (this < other) |
||||
return -1; |
||||
return 1; |
||||
} |
||||
|
||||
public override string ToString () |
||||
{ |
||||
return String.Format ("(Line {0}, Column {1})", Line, Column); |
||||
} |
||||
|
||||
public static AstLocation FromInvariantString (string invariantString) |
||||
{ |
||||
if (string.Equals(invariantString, "EMPTY", StringComparison.OrdinalIgnoreCase)) |
||||
return AstLocation.Empty; |
||||
string[] splits = invariantString.Split (',', '/'); |
||||
if (splits.Length == 2) |
||||
return new AstLocation (Int32.Parse (splits[0]), Int32.Parse (splits[1])); |
||||
return AstLocation.Empty; |
||||
} |
||||
|
||||
public string ToInvariantString () |
||||
{ |
||||
if (IsEmpty) |
||||
return "Empty"; |
||||
return String.Format ("{0}/{1}", line, column); |
||||
} |
||||
|
||||
public static bool operator==(AstLocation left, AstLocation right) |
||||
{ |
||||
return left.line == right.line && left.column == right.column; |
||||
} |
||||
|
||||
public static bool operator!=(AstLocation left, AstLocation right) |
||||
{ |
||||
return left.line != right.line || left.column != right.column; |
||||
} |
||||
|
||||
public static bool operator<(AstLocation left, AstLocation right) |
||||
{ |
||||
return left.line < right.line || left.line == right.line && left.column < right.column; |
||||
} |
||||
public static bool operator>(AstLocation left, AstLocation right) |
||||
{ |
||||
return left.line > right.line || left.line == right.line && left.column > right.column; |
||||
} |
||||
public static bool operator<=(AstLocation left, AstLocation right) |
||||
{ |
||||
return !(left > right); |
||||
} |
||||
public static bool operator>=(AstLocation left, AstLocation right) |
||||
{ |
||||
return !(left < right); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,730 @@
@@ -0,0 +1,730 @@
|
||||
//
|
||||
// AstNode.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public abstract class AstNode : PatternMatching.INode |
||||
{ |
||||
#region Null
|
||||
public static readonly AstNode Null = new NullAstNode (); |
||||
|
||||
sealed class NullAstNode : AstNode |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator AstNode(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : AstNode, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
AstNode parent; |
||||
AstNode prevSibling; |
||||
AstNode nextSibling; |
||||
AstNode firstChild; |
||||
AstNode lastChild; |
||||
Role role = RootRole; |
||||
|
||||
public virtual bool IsNull { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public virtual AstLocation StartLocation { |
||||
get { |
||||
var child = firstChild; |
||||
if (child == null) |
||||
return AstLocation.Empty; |
||||
return child.StartLocation; |
||||
} |
||||
} |
||||
|
||||
public virtual AstLocation EndLocation { |
||||
get { |
||||
var child = lastChild; |
||||
if (child == null) |
||||
return AstLocation.Empty; |
||||
return child.EndLocation; |
||||
} |
||||
} |
||||
|
||||
public AstNode Parent { |
||||
get { return parent; } |
||||
} |
||||
|
||||
public Role Role { |
||||
get { return role; } |
||||
} |
||||
|
||||
public AstNode NextSibling { |
||||
get { return nextSibling; } |
||||
} |
||||
|
||||
public AstNode PrevSibling { |
||||
get { return prevSibling; } |
||||
} |
||||
|
||||
public AstNode FirstChild { |
||||
get { return firstChild; } |
||||
} |
||||
|
||||
public AstNode LastChild { |
||||
get { return lastChild; } |
||||
} |
||||
|
||||
public IEnumerable<AstNode> Children { |
||||
get { |
||||
AstNode next; |
||||
for (AstNode cur = firstChild; cur != null; cur = next) { |
||||
Debug.Assert(cur.parent == this); |
||||
// Remember next before yielding cur.
|
||||
// This allows removing/replacing nodes while iterating through the list.
|
||||
next = cur.nextSibling; |
||||
yield return cur; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the ancestors of this node (excluding this node itself)
|
||||
/// </summary>
|
||||
public IEnumerable<AstNode> Ancestors { |
||||
get { |
||||
for (AstNode cur = parent; cur != null; cur = cur.parent) { |
||||
yield return cur; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets all descendants of this node (excluding this node itself).
|
||||
/// </summary>
|
||||
public IEnumerable<AstNode> Descendants { |
||||
get { |
||||
return Utils.TreeTraversal.PreOrder(this.Children, n => n.Children); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets all descendants of this node (including this node itself).
|
||||
/// </summary>
|
||||
public IEnumerable<AstNode> DescendantsAndSelf { |
||||
get { |
||||
return Utils.TreeTraversal.PreOrder(this, n => n.Children); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the first child with the specified role.
|
||||
/// Returns the role's null object if the child is not found.
|
||||
/// </summary>
|
||||
public T GetChildByRole<T>(Role<T> role) where T : AstNode |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
for (var cur = firstChild; cur != null; cur = cur.nextSibling) { |
||||
if (cur.role == role) |
||||
return (T)cur; |
||||
} |
||||
return role.NullObject; |
||||
} |
||||
|
||||
public AstNodeCollection<T> GetChildrenByRole<T>(Role<T> role) where T : AstNode |
||||
{ |
||||
return new AstNodeCollection<T>(this, role); |
||||
} |
||||
|
||||
protected void SetChildByRole<T>(Role<T> role, T newChild) where T : AstNode |
||||
{ |
||||
AstNode oldChild = GetChildByRole(role); |
||||
if (oldChild.IsNull) |
||||
AddChild(newChild, role); |
||||
else |
||||
oldChild.ReplaceWith(newChild); |
||||
} |
||||
|
||||
public void AddChild<T>(T child, Role<T> role) where T : AstNode |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
if (child == null || child.IsNull) |
||||
return; |
||||
if (this.IsNull) |
||||
throw new InvalidOperationException("Cannot add children to null nodes"); |
||||
if (child.parent != null) |
||||
throw new ArgumentException ("Node is already used in another tree.", "child"); |
||||
AddChildUnsafe(child, role); |
||||
} |
||||
|
||||
internal void AddChildUntyped(AstNode child, Role role) |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
if (child == null || child.IsNull) |
||||
return; |
||||
if (this.IsNull) |
||||
throw new InvalidOperationException("Cannot add children to null nodes"); |
||||
if (child.parent != null) |
||||
throw new ArgumentException ("Node is already used in another tree.", "child"); |
||||
AddChildUnsafe(child, role); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a child without performing any safety checks.
|
||||
/// </summary>
|
||||
void AddChildUnsafe(AstNode child, Role role) |
||||
{ |
||||
child.parent = this; |
||||
child.role = role; |
||||
if (firstChild == null) { |
||||
lastChild = firstChild = child; |
||||
} else { |
||||
lastChild.nextSibling = child; |
||||
child.prevSibling = lastChild; |
||||
lastChild = child; |
||||
} |
||||
} |
||||
|
||||
public void InsertChildBefore<T>(AstNode nextSibling, T child, Role<T> role) where T : AstNode |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
if (nextSibling == null || nextSibling.IsNull) { |
||||
AddChild(child, role); |
||||
return; |
||||
} |
||||
|
||||
if (child == null || child.IsNull) |
||||
return; |
||||
if (child.parent != null) |
||||
throw new ArgumentException ("Node is already used in another tree.", "child"); |
||||
if (nextSibling.parent != this) |
||||
throw new ArgumentException ("NextSibling is not a child of this node.", "nextSibling"); |
||||
// No need to test for "Cannot add children to null nodes",
|
||||
// as there isn't any valid nextSibling in null nodes.
|
||||
InsertChildBeforeUnsafe(nextSibling, child, role); |
||||
} |
||||
|
||||
|
||||
void InsertChildBeforeUnsafe(AstNode nextSibling, AstNode child, Role role) |
||||
{ |
||||
child.parent = this; |
||||
child.role = role; |
||||
child.nextSibling = nextSibling; |
||||
child.prevSibling = nextSibling.prevSibling; |
||||
|
||||
if (nextSibling.prevSibling != null) { |
||||
Debug.Assert(nextSibling.prevSibling.nextSibling == nextSibling); |
||||
nextSibling.prevSibling.nextSibling = child; |
||||
} else { |
||||
Debug.Assert(firstChild == nextSibling); |
||||
firstChild = child; |
||||
} |
||||
nextSibling.prevSibling = child; |
||||
} |
||||
|
||||
public void InsertChildAfter<T>(AstNode prevSibling, T child, Role<T> role) where T : AstNode |
||||
{ |
||||
InsertChildBefore((prevSibling == null || prevSibling.IsNull) ? firstChild : prevSibling.nextSibling, child, role); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes this node from its parent.
|
||||
/// </summary>
|
||||
public void Remove() |
||||
{ |
||||
if (parent != null) { |
||||
if (prevSibling != null) { |
||||
Debug.Assert(prevSibling.nextSibling == this); |
||||
prevSibling.nextSibling = nextSibling; |
||||
} else { |
||||
Debug.Assert(parent.firstChild == this); |
||||
parent.firstChild = nextSibling; |
||||
} |
||||
if (nextSibling != null) { |
||||
Debug.Assert(nextSibling.prevSibling == this); |
||||
nextSibling.prevSibling = prevSibling; |
||||
} else { |
||||
Debug.Assert(parent.lastChild == this); |
||||
parent.lastChild = prevSibling; |
||||
} |
||||
parent = null; |
||||
role = Roles.Root; |
||||
prevSibling = null; |
||||
nextSibling = null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Replaces this node with the new node.
|
||||
/// </summary>
|
||||
public void ReplaceWith(AstNode newNode) |
||||
{ |
||||
if (newNode == null || newNode.IsNull) { |
||||
Remove(); |
||||
return; |
||||
} |
||||
if (newNode == this) |
||||
return; // nothing to do...
|
||||
if (parent == null) { |
||||
throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); |
||||
} |
||||
// Because this method doesn't statically check the new node's type with the role,
|
||||
// we perform a runtime test:
|
||||
if (!role.IsValid(newNode)) { |
||||
throw new ArgumentException (string.Format("The new node '{0}' is not valid in the role {1}", newNode.GetType().Name, role.ToString()), "newNode"); |
||||
} |
||||
if (newNode.parent != null) { |
||||
// newNode is used within this tree?
|
||||
if (newNode.Ancestors.Contains(this)) { |
||||
// e.g. "parenthesizedExpr.ReplaceWith(parenthesizedExpr.Expression);"
|
||||
// enable automatic removal
|
||||
newNode.Remove(); |
||||
} else { |
||||
throw new ArgumentException ("Node is already used in another tree.", "newNode"); |
||||
} |
||||
} |
||||
|
||||
newNode.parent = parent; |
||||
newNode.role = role; |
||||
newNode.prevSibling = prevSibling; |
||||
newNode.nextSibling = nextSibling; |
||||
if (parent != null) { |
||||
if (prevSibling != null) { |
||||
Debug.Assert(prevSibling.nextSibling == this); |
||||
prevSibling.nextSibling = newNode; |
||||
} else { |
||||
Debug.Assert(parent.firstChild == this); |
||||
parent.firstChild = newNode; |
||||
} |
||||
if (nextSibling != null) { |
||||
Debug.Assert(nextSibling.prevSibling == this); |
||||
nextSibling.prevSibling = newNode; |
||||
} else { |
||||
Debug.Assert(parent.lastChild == this); |
||||
parent.lastChild = newNode; |
||||
} |
||||
parent = null; |
||||
prevSibling = null; |
||||
nextSibling = null; |
||||
role = Roles.Root; |
||||
} |
||||
} |
||||
|
||||
public AstNode ReplaceWith(Func<AstNode, AstNode> replaceFunction) |
||||
{ |
||||
if (replaceFunction == null) |
||||
throw new ArgumentNullException("replaceFunction"); |
||||
if (parent == null) { |
||||
throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); |
||||
} |
||||
AstNode oldParent = parent; |
||||
AstNode oldSuccessor = nextSibling; |
||||
Role oldRole = role; |
||||
Remove(); |
||||
AstNode replacement = replaceFunction(this); |
||||
if (oldSuccessor != null && oldSuccessor.parent != oldParent) |
||||
throw new InvalidOperationException("replace function changed nextSibling of node being replaced?"); |
||||
if (!(replacement == null || replacement.IsNull)) { |
||||
if (replacement.parent != null) |
||||
throw new InvalidOperationException("replace function must return the root of a tree"); |
||||
if (!oldRole.IsValid(replacement)) { |
||||
throw new InvalidOperationException (string.Format("The new node '{0}' is not valid in the role {1}", replacement.GetType().Name, oldRole.ToString())); |
||||
} |
||||
|
||||
if (oldSuccessor != null) |
||||
oldParent.InsertChildBeforeUnsafe(oldSuccessor, replacement, oldRole); |
||||
else |
||||
oldParent.AddChildUnsafe(replacement, oldRole); |
||||
} |
||||
return replacement; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Clones the whole subtree starting at this AST node.
|
||||
/// </summary>
|
||||
/// <remarks>Annotations are copied over to the new nodes; and any annotations implementating ICloneable will be cloned.</remarks>
|
||||
public AstNode Clone() |
||||
{ |
||||
AstNode copy = (AstNode)MemberwiseClone(); |
||||
// First, reset the shallow pointer copies
|
||||
copy.parent = null; |
||||
copy.role = Roles.Root; |
||||
copy.firstChild = null; |
||||
copy.lastChild = null; |
||||
copy.prevSibling = null; |
||||
copy.nextSibling = null; |
||||
|
||||
// Then perform a deep copy:
|
||||
for (AstNode cur = firstChild; cur != null; cur = cur.nextSibling) { |
||||
copy.AddChildUnsafe(cur.Clone(), cur.role); |
||||
} |
||||
|
||||
// Finally, clone the annotation, if necessary
|
||||
ICloneable annotations = copy.annotations as ICloneable; // read from copy (for thread-safety)
|
||||
if (annotations != null) |
||||
copy.annotations = annotations.Clone(); |
||||
|
||||
return copy; |
||||
} |
||||
|
||||
#region Annotation support
|
||||
// Annotations: points either null (no annotations), to the single annotation,
|
||||
// or to an AnnotationList.
|
||||
// Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list)
|
||||
object annotations; |
||||
|
||||
sealed class AnnotationList : List<object>, ICloneable |
||||
{ |
||||
// There are two uses for this custom list type:
|
||||
// 1) it's private, and thus (unlike List<object>) cannot be confused with real annotations
|
||||
// 2) It allows us to simplify the cloning logic by making the list behave the same as a clonable annotation.
|
||||
public AnnotationList(int initialCapacity) : base(initialCapacity) |
||||
{ |
||||
} |
||||
|
||||
public object Clone() |
||||
{ |
||||
lock (this) { |
||||
AnnotationList copy = new AnnotationList(this.Count); |
||||
for (int i = 0; i < this.Count; i++) { |
||||
object obj = this[i]; |
||||
ICloneable c = obj as ICloneable; |
||||
copy.Add(c != null ? c.Clone() : obj); |
||||
} |
||||
return copy; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void AddAnnotation(object annotation) |
||||
{ |
||||
if (annotation == null) |
||||
throw new ArgumentNullException("annotation"); |
||||
if (this.IsNull) |
||||
throw new InvalidOperationException("Cannot add annotations to the null node"); |
||||
retry: // Retry until successful
|
||||
object oldAnnotation = Interlocked.CompareExchange(ref this.annotations, annotation, null); |
||||
if (oldAnnotation == null) { |
||||
return; // we successfully added a single annotation
|
||||
} |
||||
AnnotationList list = oldAnnotation as AnnotationList; |
||||
if (list == null) { |
||||
// we need to transform the old annotation into a list
|
||||
list = new AnnotationList(4); |
||||
list.Add(oldAnnotation); |
||||
list.Add(annotation); |
||||
if (Interlocked.CompareExchange(ref this.annotations, list, oldAnnotation) != oldAnnotation) { |
||||
// the transformation failed (some other thread wrote to this.annotations first)
|
||||
goto retry; |
||||
} |
||||
} else { |
||||
// once there's a list, use simple locking
|
||||
lock (list) { |
||||
list.Add(annotation); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void RemoveAnnotations<T>() where T : class |
||||
{ |
||||
retry: // Retry until successful
|
||||
object oldAnnotations = this.annotations; |
||||
AnnotationList list = oldAnnotations as AnnotationList; |
||||
if (list != null) { |
||||
lock (list) |
||||
list.RemoveAll(obj => obj is T); |
||||
} else if (oldAnnotations is T) { |
||||
if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) { |
||||
// Operation failed (some other thread wrote to this.annotations first)
|
||||
goto retry; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void RemoveAnnotations(Type type) |
||||
{ |
||||
if (type == null) |
||||
throw new ArgumentNullException("type"); |
||||
retry: // Retry until successful
|
||||
object oldAnnotations = this.annotations; |
||||
AnnotationList list = oldAnnotations as AnnotationList; |
||||
if (list != null) { |
||||
lock (list) |
||||
list.RemoveAll(obj => type.IsInstanceOfType(obj)); |
||||
} else if (type.IsInstanceOfType(oldAnnotations)) { |
||||
if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) { |
||||
// Operation failed (some other thread wrote to this.annotations first)
|
||||
goto retry; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public T Annotation<T>() where T: class |
||||
{ |
||||
object annotations = this.annotations; |
||||
AnnotationList list = annotations as AnnotationList; |
||||
if (list != null) { |
||||
lock (list) { |
||||
foreach (object obj in list) { |
||||
T t = obj as T; |
||||
if (t != null) |
||||
return t; |
||||
} |
||||
return null; |
||||
} |
||||
} else { |
||||
return annotations as T; |
||||
} |
||||
} |
||||
|
||||
public object Annotation(Type type) |
||||
{ |
||||
if (type == null) |
||||
throw new ArgumentNullException("type"); |
||||
object annotations = this.annotations; |
||||
AnnotationList list = annotations as AnnotationList; |
||||
if (list != null) { |
||||
lock (list) { |
||||
foreach (object obj in list) { |
||||
if (type.IsInstanceOfType(obj)) |
||||
return obj; |
||||
} |
||||
} |
||||
} else { |
||||
if (type.IsInstanceOfType(annotations)) |
||||
return annotations; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets all annotations stored on this AstNode.
|
||||
/// </summary>
|
||||
public IEnumerable<object> Annotations { |
||||
get { |
||||
object annotations = this.annotations; |
||||
AnnotationList list = annotations as AnnotationList; |
||||
if (list != null) { |
||||
lock (list) { |
||||
return list.ToArray(); |
||||
} |
||||
} else { |
||||
if (annotations != null) |
||||
return new object[] { annotations }; |
||||
else |
||||
return Enumerable.Empty<object>(); |
||||
} |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data); |
||||
|
||||
#region Pattern Matching
|
||||
protected static bool MatchString(string name1, string name2) |
||||
{ |
||||
return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase); |
||||
} |
||||
|
||||
protected static bool MatchStringXml(string name1, string name2) |
||||
{ |
||||
return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.Ordinal); |
||||
} |
||||
|
||||
protected internal abstract bool DoMatch(AstNode other, PatternMatching.Match match); |
||||
|
||||
bool PatternMatching.INode.DoMatch(PatternMatching.INode other, PatternMatching.Match match) |
||||
{ |
||||
AstNode o = other as AstNode; |
||||
// try matching if other is null, or if other is an AstNode
|
||||
return (other == null || o != null) && DoMatch(o, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
AstNode o = pos as AstNode; |
||||
return (pos == null || o != null) && DoMatch (o, match); |
||||
} |
||||
|
||||
PatternMatching.INode PatternMatching.INode.NextSibling { |
||||
get { return nextSibling; } |
||||
} |
||||
|
||||
PatternMatching.INode PatternMatching.INode.FirstChild { |
||||
get { return firstChild; } |
||||
} |
||||
#endregion
|
||||
|
||||
public AstNode GetNextNode () |
||||
{ |
||||
if (NextSibling != null) |
||||
return NextSibling; |
||||
if (Parent != null) |
||||
return Parent.GetNextNode (); |
||||
return null; |
||||
} |
||||
|
||||
public AstNode GetPrevNode () |
||||
{ |
||||
if (PrevSibling != null) |
||||
return PrevSibling; |
||||
if (Parent != null) |
||||
return Parent.GetPrevNode (); |
||||
return null; |
||||
} |
||||
|
||||
// filters all non VB nodes (comments, white spaces or pre processor directives)
|
||||
public AstNode GetVBNodeBefore (AstNode node) |
||||
{ |
||||
var n = node.PrevSibling; |
||||
while (n != null) { |
||||
if (n.Role != Roles.Comment) |
||||
return n; |
||||
n = n.GetPrevNode (); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
|
||||
static readonly Role<AstNode> RootRole = new Role<AstNode>("Root"); |
||||
|
||||
public static class Roles |
||||
{ |
||||
/// <summary>
|
||||
/// Root of an abstract syntax tree.
|
||||
/// </summary>
|
||||
public static readonly Role<AstNode> Root = RootRole; |
||||
|
||||
// some pre defined constants for common roles
|
||||
public static readonly Role<Identifier> Identifier = new Role<Identifier>("Identifier", Ast.Identifier.Null); |
||||
public static readonly Role<XmlIdentifier> XmlIdentifier = new Role<XmlIdentifier>("XmlIdentifier", Ast.XmlIdentifier.Null); |
||||
public static readonly Role<XmlLiteralString> XmlLiteralString = new Role<XmlLiteralString>("XmlLiteralString", Ast.XmlLiteralString.Null); |
||||
|
||||
// public static readonly Role<BlockStatement> Body = new Role<BlockStatement>("Body", CSharp.BlockStatement.Null);
|
||||
public static readonly Role<ParameterDeclaration> Parameter = new Role<ParameterDeclaration>("Parameter"); |
||||
public static readonly Role<Expression> Argument = new Role<Expression>("Argument", Ast.Expression.Null); |
||||
public static readonly Role<AstType> Type = new Role<AstType>("Type", AstType.Null); |
||||
public static readonly Role<Expression> Expression = new Role<Expression>("Expression", Ast.Expression.Null); |
||||
// public static readonly Role<Expression> TargetExpression = new Role<Expression>("Target", CSharp.Expression.Null);
|
||||
// public readonly static Role<Expression> Condition = new Role<Expression>("Condition", CSharp.Expression.Null);
|
||||
//
|
||||
public static readonly Role<TypeParameterDeclaration> TypeParameter = new Role<TypeParameterDeclaration>("TypeParameter"); |
||||
public static readonly Role<AstType> TypeArgument = new Role<AstType>("TypeArgument", AstType.Null); |
||||
// public static readonly Role<VariableInitializer> Variable = new Role<VariableInitializer>("Variable");
|
||||
// public static readonly Role<Statement> EmbeddedStatement = new Role<Statement>("EmbeddedStatement", CSharp.Statement.Null);
|
||||
//
|
||||
public static readonly Role<VBTokenNode> Keyword = new Role<VBTokenNode>("Keyword", VBTokenNode.Null); |
||||
// public static readonly Role<VBTokenNode> InKeyword = new Role<VBTokenNode>("InKeyword", VBTokenNode.Null);
|
||||
|
||||
// some pre defined constants for most used punctuation
|
||||
public static readonly Role<VBTokenNode> LPar = new Role<VBTokenNode>("LPar", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RPar = new Role<VBTokenNode>("RPar", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> LBracket = new Role<VBTokenNode>("LBracket", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RBracket = new Role<VBTokenNode>("RBracket", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> LBrace = new Role<VBTokenNode>("LBrace", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RBrace = new Role<VBTokenNode>("RBrace", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> LChevron = new Role<VBTokenNode>("LChevron", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RChevron = new Role<VBTokenNode>("RChevron", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Comma = new Role<VBTokenNode>("Comma", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Dot = new Role<VBTokenNode>("Dot", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Semicolon = new Role<VBTokenNode>("Semicolon", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Assign = new Role<VBTokenNode>("Assign", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Colon = new Role<VBTokenNode>("Colon", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> StatementTerminator = new Role<VBTokenNode>("StatementTerminator", VBTokenNode.Null); |
||||
|
||||
// XML
|
||||
/// <summary>
|
||||
/// Text: <
|
||||
/// </summary>
|
||||
public static readonly Role<VBTokenNode> XmlOpenTag = new Role<VBTokenNode>("XmlOpenTag", VBTokenNode.Null); |
||||
/// <summary>
|
||||
/// Text: >
|
||||
/// </summary>
|
||||
public static readonly Role<VBTokenNode> XmlCloseTag = new Role<VBTokenNode>("XmlOpenTag", VBTokenNode.Null); |
||||
|
||||
public static readonly Role<Comment> Comment = new Role<Comment>("Comment"); |
||||
|
||||
} |
||||
} |
||||
|
||||
public class Comment |
||||
{ |
||||
|
||||
} |
||||
} |
@ -0,0 +1,209 @@
@@ -0,0 +1,209 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the children of an AstNode that have a specific role.
|
||||
/// </summary>
|
||||
public class AstNodeCollection<T> : ICollection<T> where T : AstNode |
||||
{ |
||||
readonly AstNode node; |
||||
readonly Role<T> role; |
||||
|
||||
public AstNodeCollection(AstNode node, Role<T> role) |
||||
{ |
||||
if (node == null) |
||||
throw new ArgumentNullException("node"); |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
this.node = node; |
||||
this.role = role; |
||||
} |
||||
|
||||
public int Count { |
||||
get { |
||||
int count = 0; |
||||
for (AstNode cur = node.FirstChild; cur != null; cur = cur.NextSibling) { |
||||
if (cur.Role == role) |
||||
count++; |
||||
} |
||||
return count; |
||||
} |
||||
} |
||||
|
||||
public void Add(T element) |
||||
{ |
||||
node.AddChild(element, role); |
||||
} |
||||
|
||||
public void AddRange(IEnumerable<T> nodes) |
||||
{ |
||||
// Evaluate 'nodes' first, since it might change when we add the new children
|
||||
// Example: collection.AddRange(collection);
|
||||
if (nodes != null) { |
||||
foreach (T node in nodes.ToList()) |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
public void AddRange(T[] nodes) |
||||
{ |
||||
// Fast overload for arrays - we don't need to create a copy
|
||||
if (nodes != null) { |
||||
foreach (T node in nodes) |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
public void ReplaceWith(IEnumerable<T> nodes) |
||||
{ |
||||
// Evaluate 'nodes' first, since it might change when we call Clear()
|
||||
// Example: collection.ReplaceWith(collection);
|
||||
if (nodes != null) |
||||
nodes = nodes.ToList(); |
||||
Clear(); |
||||
foreach (T node in nodes) |
||||
Add(node); |
||||
} |
||||
|
||||
public void MoveTo(ICollection<T> targetCollection) |
||||
{ |
||||
foreach (T node in this) { |
||||
node.Remove(); |
||||
targetCollection.Add(node); |
||||
} |
||||
} |
||||
|
||||
public bool Contains(T element) |
||||
{ |
||||
return element != null && element.Parent == node && element.Role == role; |
||||
} |
||||
|
||||
public bool Remove(T element) |
||||
{ |
||||
if (Contains(element)) { |
||||
element.Remove(); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public void CopyTo(T[] array, int arrayIndex) |
||||
{ |
||||
foreach (T item in this) |
||||
array[arrayIndex++] = item; |
||||
} |
||||
|
||||
public void Clear() |
||||
{ |
||||
foreach (T item in this) |
||||
item.Remove(); |
||||
} |
||||
|
||||
bool ICollection<T>.IsReadOnly { |
||||
get { return false; } |
||||
} |
||||
|
||||
public IEnumerator<T> GetEnumerator() |
||||
{ |
||||
AstNode next; |
||||
for (AstNode cur = node.FirstChild; cur != null; cur = next) { |
||||
Debug.Assert(cur.Parent == node); |
||||
// Remember next before yielding cur.
|
||||
// This allows removing/replacing nodes while iterating through the list.
|
||||
next = cur.NextSibling; |
||||
if (cur.Role == role) |
||||
yield return (T)cur; |
||||
} |
||||
} |
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() |
||||
{ |
||||
return GetEnumerator(); |
||||
} |
||||
|
||||
#region Equals and GetHashCode implementation
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
if (obj is AstNodeCollection<T>) { |
||||
return ((AstNodeCollection<T>)obj) == this; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return node.GetHashCode() ^ role.GetHashCode(); |
||||
} |
||||
|
||||
public static bool operator ==(AstNodeCollection<T> left, AstNodeCollection<T> right) |
||||
{ |
||||
return left.role == right.role && left.node == right.node; |
||||
} |
||||
|
||||
public static bool operator !=(AstNodeCollection<T> left, AstNodeCollection<T> right) |
||||
{ |
||||
return !(left.role == right.role && left.node == right.node); |
||||
} |
||||
#endregion
|
||||
|
||||
internal bool DoMatch(AstNodeCollection<T> other, Match match) |
||||
{ |
||||
// TODO : does not compile (ask Daniel)!
|
||||
// Stack<AstNode> patternStack = new Stack<AstNode>();
|
||||
// Stack<Pattern.PossibleMatch> stack = new Stack<Pattern.PossibleMatch>();
|
||||
// patternStack.Push(this.node.FirstChild);
|
||||
// stack.Push(new Pattern.PossibleMatch(other.node.FirstChild, match.CheckPoint()));
|
||||
// while (stack.Count > 0) {
|
||||
// AstNode cur1 = patternStack.Pop();
|
||||
// AstNode cur2 = stack.Peek().NextOther;
|
||||
// match.RestoreCheckPoint(stack.Pop().Checkpoint);
|
||||
// bool success = true;
|
||||
// while (cur1 != null && success) {
|
||||
// while (cur1 != null && cur1.Role != role)
|
||||
// cur1 = cur1.NextSibling;
|
||||
// while (cur2 != null && cur2.Role != role)
|
||||
// cur2 = cur2.NextSibling;
|
||||
// if (cur1 == null)
|
||||
// break;
|
||||
//
|
||||
// Debug.Assert(stack.Count == patternStack.Count);
|
||||
// success = cur1.DoMatchCollection(role, cur2, match, stack);
|
||||
// Debug.Assert(stack.Count >= patternStack.Count);
|
||||
// while (stack.Count > patternStack.Count)
|
||||
// patternStack.Push(cur1.NextSibling);
|
||||
//
|
||||
// cur1 = cur1.NextSibling;
|
||||
// if (cur2 != null)
|
||||
// cur2 = cur2.NextSibling;
|
||||
// }
|
||||
// while (cur2 != null && cur2.Role != role)
|
||||
// cur2 = cur2.NextSibling;
|
||||
// if (success && cur2 == null)
|
||||
// return true;
|
||||
// }
|
||||
return false; |
||||
} |
||||
|
||||
public void InsertAfter(T existingItem, T newItem) |
||||
{ |
||||
node.InsertChildAfter(existingItem, newItem, role); |
||||
} |
||||
|
||||
public void InsertBefore(T existingItem, T newItem) |
||||
{ |
||||
node.InsertChildBefore(existingItem, newItem, role); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public abstract class Expression : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly Expression Null = new NullExpression (); |
||||
|
||||
sealed class NullExpression : Expression |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a literal value.
|
||||
/// </summary>
|
||||
public class PrimitiveExpression : Expression |
||||
{ |
||||
public static readonly object AnyValue = new object(); |
||||
|
||||
AstLocation startLocation; |
||||
public override AstLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
int length; |
||||
public override AstLocation EndLocation { |
||||
get { |
||||
return new AstLocation(StartLocation.Line, StartLocation.Column + length); |
||||
} |
||||
} |
||||
|
||||
public object Value { get; private set; } |
||||
|
||||
string stringValue; |
||||
|
||||
public string StringValue { |
||||
get { return stringValue; } // TODO ?? VBNetOutputVisitor.ToVBNetString(this); }
|
||||
} |
||||
|
||||
public PrimitiveExpression(object value) |
||||
{ |
||||
this.Value = value; |
||||
} |
||||
|
||||
public PrimitiveExpression(object value, string stringValue) |
||||
{ |
||||
this.Value = value; |
||||
this.stringValue = stringValue; |
||||
} |
||||
|
||||
public PrimitiveExpression(object value, AstLocation startLocation, int length) |
||||
{ |
||||
this.Value = value; |
||||
this.startLocation = startLocation; |
||||
this.length = length; |
||||
} |
||||
|
||||
public PrimitiveExpression(object value, string stringValue, AstLocation startLocation, int length) |
||||
{ |
||||
this.Value = value; |
||||
this.stringValue = stringValue; |
||||
this.startLocation = startLocation; |
||||
this.length = length; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPrimitiveExpression(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
PrimitiveExpression o = other as PrimitiveExpression; |
||||
return o != null && (this.Value == AnyValue || object.Equals(this.Value, o.Value)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Description of IdentifierExpression.
|
||||
/// </summary>
|
||||
public class SimpleNameExpression : Expression |
||||
{ |
||||
public Identifier Identifier { get; set; } |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var node = other as SimpleNameExpression; |
||||
return node != null |
||||
&& Identifier.DoMatch(node.Identifier, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitSimpleNameExpression(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Description of XmlIdentifier.
|
||||
/// </summary>
|
||||
public class XmlIdentifier : AstNode |
||||
{ |
||||
public static readonly new XmlIdentifier Null = new NullXmlIdentifier(); |
||||
|
||||
class NullXmlIdentifier : XmlIdentifier |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default(S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
|
||||
public string Name { get; set; } |
||||
|
||||
AstLocation startLocation; |
||||
public override AstLocation StartLocation { |
||||
get { return startLocation; } |
||||
} |
||||
|
||||
AstLocation endLocation; |
||||
public override AstLocation EndLocation { |
||||
get { return endLocation; } |
||||
} |
||||
|
||||
private XmlIdentifier() |
||||
{ |
||||
this.Name = string.Empty; |
||||
} |
||||
|
||||
public XmlIdentifier(string name, AstLocation startLocation, AstLocation endLocation) |
||||
{ |
||||
this.Name = name; |
||||
this.startLocation = startLocation; |
||||
this.endLocation = endLocation; |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var ident = other as XmlIdentifier; |
||||
return ident != null |
||||
&& MatchStringXml(Name, ident.Name) |
||||
&& ident.startLocation == startLocation |
||||
&& ident.endLocation == endLocation; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitXmlIdentifier(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class XmlLiteralString : AstNode |
||||
{ |
||||
public static readonly new XmlLiteralString Null = new XmlLiteralString(); |
||||
|
||||
class NullXmlLiteralString : XmlLiteralString |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default(S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
|
||||
public string Value { get; set; } |
||||
|
||||
AstLocation startLocation; |
||||
public override AstLocation StartLocation { |
||||
get { return startLocation; } |
||||
} |
||||
|
||||
AstLocation endLocation; |
||||
public override AstLocation EndLocation { |
||||
get { return endLocation; } |
||||
} |
||||
|
||||
private XmlLiteralString() |
||||
{ |
||||
this.Value = string.Empty; |
||||
} |
||||
|
||||
public XmlLiteralString(string value, AstLocation startLocation, AstLocation endLocation) |
||||
{ |
||||
this.Value = value; |
||||
this.startLocation = startLocation; |
||||
this.endLocation = endLocation; |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var ident = other as XmlLiteralString; |
||||
return ident != null |
||||
&& MatchStringXml(Value, ident.Value) |
||||
&& ident.startLocation == startLocation |
||||
&& ident.endLocation == endLocation; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitXmlLiteralString(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class Attribute : AstNode |
||||
{ |
||||
#region PatternPlaceholder
|
||||
public static implicit operator Attribute(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : Attribute, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute"); |
||||
public static readonly Role<VBTokenNode> TargetRole = new Role<VBTokenNode>("Target", VBTokenNode.Null); |
||||
|
||||
public VBTokenNode Target { |
||||
get { return GetChildByRole(TargetRole); } |
||||
set { SetChildByRole(TargetRole, value); } |
||||
} |
||||
|
||||
public VBTokenNode ColonToken { |
||||
get { return GetChildByRole(Roles.StatementTerminator); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public VBTokenNode LParToken { |
||||
get { return GetChildByRole(Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return GetChildrenByRole(Roles.Argument); } |
||||
} |
||||
|
||||
public VBTokenNode RParToken { |
||||
get { return GetChildByRole(Roles.RPar); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAttribute(this, data); |
||||
} |
||||
|
||||
// public override string ToString()
|
||||
// {
|
||||
// return string.Format("[Attribute Type={0} Arguments={1}]", Type, GetCollectionString(Arguments));
|
||||
// }
|
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var node = other as Attribute; |
||||
return node != null && node.Target.DoMatch(this.Target, match) && node.Type.DoMatch(this.Type, match) && node.Arguments.DoMatch(this.Arguments, match); |
||||
} |
||||
} |
||||
|
||||
public enum AttributeTarget |
||||
{ |
||||
Assembly, |
||||
Module |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class AttributeBlock : AstNode |
||||
{ |
||||
public readonly static Role<AttributeBlock> AttributeBlockRole = new Role<AttributeBlock>("AttributeBlock"); |
||||
public readonly static Role<AttributeBlock> ReturnTypeAttributeBlockRole = new Role<AttributeBlock>("ReturnTypeAttributeBlock"); |
||||
|
||||
public VBTokenNode LChevron { |
||||
get { return GetChildByRole(Roles.LChevron); } |
||||
} |
||||
|
||||
public AstNodeCollection<Attribute> Attributes { |
||||
get { return GetChildrenByRole(Attribute.AttributeRole); } |
||||
} |
||||
|
||||
public VBTokenNode RChevron { |
||||
get { return GetChildByRole(Roles.RChevron); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var node = other as AttributeBlock; |
||||
return node != null && Attributes.DoMatch(node.Attributes, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAttributeBlock(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public abstract class AttributedNode : AstNode |
||||
{ |
||||
public AstNodeCollection<AttributeBlock> Attributes { |
||||
get { return GetChildrenByRole(AttributeBlock.AttributeBlockRole); } |
||||
} |
||||
|
||||
public static readonly Role<VBModifierToken> ModifierRole = new Role<VBModifierToken>("Modifier"); |
||||
|
||||
public Modifiers Modifiers { |
||||
get { return GetModifiers(this); } |
||||
set { SetModifiers(this, value); } |
||||
} |
||||
|
||||
public IEnumerable<VBModifierToken> ModifierTokens { |
||||
get { return GetChildrenByRole (ModifierRole); } |
||||
} |
||||
|
||||
internal static Modifiers GetModifiers(AstNode node) |
||||
{ |
||||
Modifiers m = 0; |
||||
foreach (VBModifierToken t in node.GetChildrenByRole (ModifierRole)) { |
||||
m |= t.Modifier; |
||||
} |
||||
return m; |
||||
} |
||||
|
||||
internal static void SetModifiers(AstNode node, Modifiers newValue) |
||||
{ |
||||
Modifiers oldValue = GetModifiers(node); |
||||
AstNode insertionPos = node.GetChildrenByRole(Attribute.AttributeRole).LastOrDefault(); |
||||
foreach (Modifiers m in VBModifierToken.AllModifiers) { |
||||
if ((m & newValue) != 0) { |
||||
if ((m & oldValue) == 0) { |
||||
// Modifier was added
|
||||
var newToken = new VBModifierToken(AstLocation.Empty, m); |
||||
node.InsertChildAfter(insertionPos, newToken, ModifierRole); |
||||
insertionPos = newToken; |
||||
} else { |
||||
// Modifier already exists
|
||||
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m); |
||||
} |
||||
} else { |
||||
if ((m & oldValue) != 0) { |
||||
// Modifier was removed
|
||||
node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected bool MatchAttributesAndModifiers(AttributedNode o, PatternMatching.Match match) |
||||
{ |
||||
return (this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch(o.Attributes, match); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -1,58 +0,0 @@
@@ -1,58 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class BlockStatement : Statement |
||||
{ |
||||
// Children in VB: LabelStatement, EndStatement, Statement
|
||||
|
||||
public static new BlockStatement Null { |
||||
get { |
||||
return NullBlockStatement.Instance; |
||||
} |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.VisitBlockStatement(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[BlockStatement: Children={0}]", |
||||
GetCollectionString(base.Children)); |
||||
} |
||||
} |
||||
|
||||
internal sealed class NullBlockStatement : BlockStatement |
||||
{ |
||||
public static readonly NullBlockStatement Instance = new NullBlockStatement(); |
||||
|
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return data; |
||||
} |
||||
public override object AcceptChildren(IAstVisitor visitor, object data) |
||||
{ |
||||
return data; |
||||
} |
||||
public override void AddChild(INode childNode) |
||||
{ |
||||
throw new InvalidOperationException(); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullBlockStatement]"); |
||||
} |
||||
} |
||||
} |
@ -1,103 +0,0 @@
@@ -1,103 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public abstract class Expression : AbstractNode, INullable |
||||
{ |
||||
public static Expression Null { |
||||
get { |
||||
return NullExpression.Instance; |
||||
} |
||||
} |
||||
|
||||
public virtual bool IsNull { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static Expression CheckNull(Expression expression) |
||||
{ |
||||
return expression == null ? NullExpression.Instance : expression; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the existing expression plus the specified integer value.
|
||||
/// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression
|
||||
/// (and thus its parent property is modified).
|
||||
/// </summary>
|
||||
public static Expression AddInteger(Expression expr, int value) |
||||
{ |
||||
PrimitiveExpression pe = expr as PrimitiveExpression; |
||||
if (pe != null && pe.Value is int) { |
||||
int newVal = (int)pe.Value + value; |
||||
return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); |
||||
} |
||||
BinaryOperatorExpression boe = expr as BinaryOperatorExpression; |
||||
if (boe != null && boe.Op == BinaryOperatorType.Add) { |
||||
// clone boe:
|
||||
boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); |
||||
|
||||
boe.Right = AddInteger(boe.Right, value); |
||||
if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) { |
||||
int newVal = (int)((PrimitiveExpression)boe.Right).Value; |
||||
if (newVal == 0) { |
||||
return boe.Left; |
||||
} else if (newVal < 0) { |
||||
((PrimitiveExpression)boe.Right).Value = -newVal; |
||||
boe.Op = BinaryOperatorType.Subtract; |
||||
} |
||||
} |
||||
return boe; |
||||
} |
||||
if (boe != null && boe.Op == BinaryOperatorType.Subtract) { |
||||
pe = boe.Right as PrimitiveExpression; |
||||
if (pe != null && pe.Value is int) { |
||||
int newVal = (int)pe.Value - value; |
||||
if (newVal == 0) |
||||
return boe.Left; |
||||
|
||||
// clone boe:
|
||||
boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); |
||||
|
||||
if (newVal < 0) { |
||||
newVal = -newVal; |
||||
boe.Op = BinaryOperatorType.Add; |
||||
} |
||||
boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); |
||||
return boe; |
||||
} |
||||
} |
||||
BinaryOperatorType opType = BinaryOperatorType.Add; |
||||
if (value < 0) { |
||||
value = -value; |
||||
opType = BinaryOperatorType.Subtract; |
||||
} |
||||
return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); |
||||
} |
||||
} |
||||
|
||||
internal sealed class NullExpression : Expression |
||||
{ |
||||
internal static readonly NullExpression Instance = new NullExpression(); |
||||
|
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullExpression]"); |
||||
} |
||||
} |
||||
} |
@ -1,99 +0,0 @@
@@ -1,99 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class LocalVariableDeclaration : Statement |
||||
{ |
||||
TypeReference typeReference; |
||||
Modifiers modifier = Modifiers.None; |
||||
List<VariableDeclaration> variables = new List<VariableDeclaration>(); |
||||
|
||||
public TypeReference TypeReference { |
||||
get { |
||||
return typeReference; |
||||
} |
||||
set { |
||||
typeReference = TypeReference.CheckNull(value); |
||||
if (!typeReference.IsNull) typeReference.Parent = this; |
||||
} |
||||
} |
||||
|
||||
public Modifiers Modifier { |
||||
get { |
||||
return modifier; |
||||
} |
||||
set { |
||||
modifier = value; |
||||
} |
||||
} |
||||
|
||||
public List<VariableDeclaration> Variables { |
||||
get { |
||||
return variables; |
||||
} |
||||
} |
||||
|
||||
public TypeReference GetTypeForVariable(int variableIndex) |
||||
{ |
||||
if (!typeReference.IsNull) { |
||||
return typeReference; |
||||
} |
||||
|
||||
for (int i = variableIndex; i < Variables.Count;++i) { |
||||
if (!((VariableDeclaration)Variables[i]).TypeReference.IsNull) { |
||||
return ((VariableDeclaration)Variables[i]).TypeReference; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public LocalVariableDeclaration(VariableDeclaration declaration) : this(TypeReference.Null) |
||||
{ |
||||
Variables.Add(declaration); |
||||
} |
||||
|
||||
public LocalVariableDeclaration(TypeReference typeReference) |
||||
{ |
||||
this.TypeReference = typeReference; |
||||
} |
||||
|
||||
public LocalVariableDeclaration(TypeReference typeReference, Modifiers modifier) |
||||
{ |
||||
this.TypeReference = typeReference; |
||||
this.modifier = modifier; |
||||
} |
||||
|
||||
public LocalVariableDeclaration(Modifiers modifier) |
||||
{ |
||||
this.typeReference = TypeReference.Null; |
||||
this.modifier = modifier; |
||||
} |
||||
|
||||
public VariableDeclaration GetVariableDeclaration(string variableName) |
||||
{ |
||||
foreach (VariableDeclaration variableDeclaration in variables) { |
||||
if (variableDeclaration.Name == variableName) { |
||||
return variableDeclaration; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.VisitLocalVariableDeclaration(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[LocalVariableDeclaration: Type={0}, Modifier ={1} Variables={2}]", |
||||
typeReference, |
||||
modifier, |
||||
GetCollectionString(variables)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class ParameterDeclaration : AttributedNode |
||||
{ |
||||
public Identifier Name { |
||||
get { return GetChildByRole(Roles.Identifier); } |
||||
set { SetChildByRole(Roles.Identifier, value); } |
||||
} |
||||
|
||||
public Expression OptionalValue { |
||||
get { return GetChildByRole(Roles.Expression); } |
||||
set { SetChildByRole(Roles.Expression, value); } |
||||
} |
||||
|
||||
public AstType ReturnType { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var param = other as ParameterDeclaration; |
||||
return param != null && |
||||
MatchAttributesAndModifiers(param, match) && |
||||
Name.DoMatch(param.Name, match) && |
||||
OptionalValue.DoMatch(param.OptionalValue, match) && |
||||
ReturnType.DoMatch(param.ReturnType, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitParameterDeclaration(this, data); |
||||
} |
||||
} |
||||
} |
@ -1,53 +0,0 @@
@@ -1,53 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class PrimitiveExpression : Expression |
||||
{ |
||||
string stringValue; |
||||
|
||||
public Parser.LiteralFormat LiteralFormat { get; set; } |
||||
public object Value { get; set; } |
||||
|
||||
public string StringValue { |
||||
get { |
||||
if (stringValue == null) |
||||
return VBNetOutputVisitor.ToVBNetString(this); |
||||
else |
||||
return stringValue; |
||||
} |
||||
set { |
||||
stringValue = value == null ? String.Empty : value; |
||||
} |
||||
} |
||||
|
||||
public PrimitiveExpression(object val) |
||||
{ |
||||
this.Value = val; |
||||
} |
||||
|
||||
public PrimitiveExpression(object val, string stringValue) |
||||
{ |
||||
this.Value = val; |
||||
this.StringValue = stringValue; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.VisitPrimitiveExpression(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[PrimitiveExpression: Value={1}, ValueType={2}, StringValue={0}]", |
||||
this.StringValue, |
||||
this.Value, |
||||
this.Value == null ? "null" : this.Value.GetType().FullName |
||||
); |
||||
} |
||||
} |
||||
} |
@ -1,62 +0,0 @@
@@ -1,62 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public abstract class Statement : AbstractNode, INullable |
||||
{ |
||||
public static Statement Null { |
||||
get { |
||||
return NullStatement.Instance; |
||||
} |
||||
} |
||||
|
||||
public virtual bool IsNull { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static Statement CheckNull(Statement statement) |
||||
{ |
||||
return statement ?? NullStatement.Instance; |
||||
} |
||||
} |
||||
|
||||
public abstract class StatementWithEmbeddedStatement : Statement |
||||
{ |
||||
Statement embeddedStatement; |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { |
||||
return embeddedStatement; |
||||
} |
||||
set { |
||||
embeddedStatement = Statement.CheckNull(value); |
||||
if (value != null) |
||||
value.Parent = this; |
||||
} |
||||
} |
||||
} |
||||
|
||||
internal sealed class NullStatement : Statement |
||||
{ |
||||
public static readonly NullStatement Instance = new NullStatement(); |
||||
|
||||
public override bool IsNull { |
||||
get { return true; } |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return data; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullStatement]"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// [In|Out] Name [As Contraints]
|
||||
///
|
||||
/// Represents a type parameter.
|
||||
/// </summary>
|
||||
public class TypeParameterDeclaration : AstNode |
||||
{ |
||||
public static readonly Role<AstType> TypeConstraintRole = TypeDeclaration.InheritsTypeRole; |
||||
public static readonly Role<VBTokenNode> VarianceRole = new Role<VBTokenNode>("Variance"); |
||||
|
||||
public VarianceModifier Variance { get; set; } |
||||
|
||||
public string Name { |
||||
get { return GetChildByRole (Roles.Identifier).Name; } |
||||
set { SetChildByRole(Roles.Identifier, new Identifier(value, AstLocation.Empty)); } |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> Constraints { |
||||
get { return GetChildrenByRole(TypeConstraintRole); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitTypeParameterDeclaration(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
TypeParameterDeclaration o = other as TypeParameterDeclaration; |
||||
return o != null && this.Variance == o.Variance |
||||
&& MatchString(this.Name, o.Name) |
||||
&& this.Constraints.DoMatch(o.Constraints, match); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class DelegateDeclaration : AttributedNode |
||||
{ |
||||
public bool IsSub { get; set; } |
||||
|
||||
public AstNodeCollection<TypeParameterDeclaration> TypeParameters { |
||||
get { return GetChildrenByRole(Roles.TypeParameter); } |
||||
} |
||||
|
||||
public Identifier Name { |
||||
get { return GetChildByRole(Roles.Identifier); } |
||||
set { SetChildByRole(Roles.Identifier, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<ParameterDeclaration> Parameters { |
||||
get { return GetChildrenByRole(Roles.Parameter); } |
||||
} |
||||
|
||||
public AstNodeCollection<AttributeBlock> ReturnTypeAttributes { |
||||
get { return GetChildrenByRole(AttributeBlock.ReturnTypeAttributeBlockRole); } |
||||
} |
||||
|
||||
public AstType ReturnType { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var o = other as DelegateDeclaration; |
||||
return o != null && |
||||
MatchAttributesAndModifiers(o, match) && |
||||
IsSub == o.IsSub && |
||||
TypeParameters.DoMatch(o.TypeParameters, match) && |
||||
Name.DoMatch(o.Name, match) && |
||||
Parameters.DoMatch(o.Parameters, match) && |
||||
ReturnTypeAttributes.DoMatch(o.ReturnTypeAttributes, match) && |
||||
ReturnType.DoMatch(o.ReturnType, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitDelegateDeclaration(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class EnumDeclaration : AttributedNode |
||||
{ |
||||
public readonly static Role<EnumMemberDeclaration> MemberRole = new Role<EnumMemberDeclaration>("Member"); |
||||
public readonly static Role<AstType> UnderlyingTypeRole = new Role<AstType>("UnderlyingType", AstType.Null); |
||||
|
||||
public Identifier Name { |
||||
get { return GetChildByRole(Roles.Identifier); } |
||||
set { SetChildByRole(Roles.Identifier, value); } |
||||
} |
||||
|
||||
public AstType UnderlyingType { |
||||
get { return GetChildByRole(UnderlyingTypeRole); } |
||||
set { SetChildByRole(UnderlyingTypeRole, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<EnumMemberDeclaration> Member { |
||||
get { return GetChildrenByRole(MemberRole); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var decl = other as EnumDeclaration; |
||||
return decl != null && |
||||
MatchAttributesAndModifiers(decl, match) && |
||||
Name.DoMatch(decl.Name, match) && |
||||
UnderlyingType.DoMatch(decl.UnderlyingType, match) && |
||||
Member.DoMatch(decl.Member, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitEnumDeclaration(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class EnumMemberDeclaration : AstNode |
||||
{ |
||||
public AstNodeCollection<AttributeBlock> Attributes { |
||||
get { return GetChildrenByRole(AttributeBlock.AttributeBlockRole); } |
||||
} |
||||
|
||||
public Identifier Name { |
||||
get { return GetChildByRole(Roles.Identifier); } |
||||
set { SetChildByRole(Roles.Identifier, value); } |
||||
} |
||||
|
||||
public Expression Value { |
||||
get { return GetChildByRole(Roles.Expression); } |
||||
set { SetChildByRole(Roles.Expression, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var member = other as EnumMemberDeclaration; |
||||
return Attributes.DoMatch(member.Attributes, match) && |
||||
Name.DoMatch(member.Name, match) && |
||||
Value.DoMatch(member.Value, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitEnumMemberDeclaration(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public abstract class ImportsClause : AstNode |
||||
{ |
||||
public new static readonly ImportsClause Null = new NullImportsClause(); |
||||
|
||||
class NullImportsClause : ImportsClause |
||||
{ |
||||
public override bool IsNull { |
||||
get { return true; } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
return other != null && other.IsNull; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default(S); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class AliasImportsClause : ImportsClause |
||||
{ |
||||
public Identifier Name { |
||||
get { return GetChildByRole(Roles.Identifier); } |
||||
set { SetChildByRole(Roles.Identifier, value); } |
||||
} |
||||
|
||||
public AstType Alias { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var clause = other as AliasImportsClause; |
||||
return clause != null |
||||
&& Name.DoMatch(clause.Name, match) |
||||
&& Alias.DoMatch(clause.Alias, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAliasImportsClause(this, data); |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return string.Format("[AliasImportsClause Name={0} Alias={1}]", Name, Alias); |
||||
} |
||||
} |
||||
|
||||
public class MemberImportsClause : ImportsClause |
||||
{ |
||||
public AstType Member { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var node = other as MemberImportsClause; |
||||
return node != null |
||||
&& Member.DoMatch(node.Member, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitMembersImportsClause(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[MemberImportsClause Member={0}]", Member); |
||||
} |
||||
} |
||||
|
||||
public class XmlNamespaceImportsClause : ImportsClause |
||||
{ |
||||
public XmlIdentifier Prefix { |
||||
get { return GetChildByRole(Roles.XmlIdentifier); } |
||||
set { SetChildByRole(Roles.XmlIdentifier, value); } |
||||
} |
||||
|
||||
public XmlLiteralString Namespace { |
||||
get { return GetChildByRole(Roles.XmlLiteralString); } |
||||
set { SetChildByRole(Roles.XmlLiteralString, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var clause = other as XmlNamespaceImportsClause; |
||||
return clause != null && Namespace.DoMatch(clause.Namespace, match) && Prefix.DoMatch(clause.Prefix, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitXmlNamespaceImportsClause(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[XmlNamespaceImportsClause Prefix={0}, Namespace={1}]", Prefix, Namespace); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class ImportsStatement : AstNode |
||||
{ |
||||
public static readonly Role<ImportsClause> ImportsClauseRole = new Role<ImportsClause>("ImportsClause", ImportsClause.Null); |
||||
|
||||
public VBTokenNode Imports { |
||||
get { return GetChildByRole(Roles.Keyword); } |
||||
} |
||||
|
||||
public AstNodeCollection<ImportsClause> ImportsClauses { |
||||
get { return GetChildrenByRole(ImportsClauseRole); } |
||||
} |
||||
|
||||
// public override string ToString() {
|
||||
// return string.Format("[ImportsStatement ImportsClauses={0}]", GetCollectionString(ImportsClauses));
|
||||
// }
|
||||
|
||||
protected internal override bool DoMatch(AstNode other, Match match) |
||||
{ |
||||
ImportsStatement stmt = other as ImportsStatement; |
||||
return stmt != null && stmt.ImportsClauses.DoMatch(ImportsClauses, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitImportsStatement(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Namespace Name
|
||||
/// Members
|
||||
/// End Namespace
|
||||
/// </summary>
|
||||
public class NamespaceDeclaration : AstNode |
||||
{ |
||||
public static readonly Role<AstNode> MemberRole = CompilationUnit.MemberRole; |
||||
|
||||
public string Name { |
||||
get { |
||||
StringBuilder builder = new StringBuilder(); |
||||
foreach (Identifier identifier in GetChildrenByRole (Roles.Identifier)) { |
||||
if (builder.Length > 0) |
||||
builder.Append ('.'); |
||||
builder.Append (identifier.Name); |
||||
} |
||||
return builder.ToString (); |
||||
} |
||||
set { |
||||
GetChildrenByRole(Roles.Identifier).ReplaceWith(value.Split('.').Select(ident => new Identifier(ident, AstLocation.Empty))); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<Identifier> Identifiers { |
||||
get { return GetChildrenByRole (Roles.Identifier); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the full namespace name (including any parent namespaces)
|
||||
/// </summary>
|
||||
public string FullName { |
||||
get { |
||||
NamespaceDeclaration parentNamespace = Parent as NamespaceDeclaration; |
||||
if (parentNamespace != null) |
||||
return BuildQualifiedName (parentNamespace.FullName, Name); |
||||
return Name; |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<AstNode> Members { |
||||
get { return GetChildrenByRole(MemberRole); } |
||||
} |
||||
|
||||
public static string BuildQualifiedName (string name1, string name2) |
||||
{ |
||||
if (string.IsNullOrEmpty (name1)) |
||||
return name2; |
||||
if (string.IsNullOrEmpty (name2)) |
||||
return name1; |
||||
return name1 + "." + name2; |
||||
} |
||||
|
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNamespaceDeclaration(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
NamespaceDeclaration o = other as NamespaceDeclaration; |
||||
return o != null && MatchString(this.Name, o.Name) && this.Members.DoMatch(o.Members, match); |
||||
} |
||||
} |
||||
}; |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class OptionStatement : AstNode |
||||
{ |
||||
public static readonly Role<VBTokenNode> OptionTypeRole = new Role<VBTokenNode>("OptionType"); |
||||
public static readonly Role<VBTokenNode> OptionValueRole = new Role<VBTokenNode>("OptionValue"); |
||||
|
||||
public VBTokenNode OptionKeyword { |
||||
get { return GetChildByRole(Roles.Keyword); } |
||||
} |
||||
|
||||
public VBTokenNode OptionTypeKeyword { |
||||
get { return GetChildByRole(OptionTypeRole); } |
||||
} |
||||
|
||||
public VBTokenNode OptionValueKeyword { |
||||
get { return GetChildByRole(OptionValueRole); } |
||||
} |
||||
|
||||
public OptionType OptionType { get; set; } |
||||
|
||||
public OptionValue OptionValue { get; set; } |
||||
|
||||
protected internal override bool DoMatch(AstNode other, Match match) |
||||
{ |
||||
var stmt = other as OptionStatement; |
||||
return stmt != null && stmt.OptionType == this.OptionType |
||||
&& stmt.OptionValue == this.OptionValue; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitOptionStatement(this, data); |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return string.Format("[OptionStatement OptionType={0} OptionValue={1}]", OptionType, OptionValue); |
||||
} |
||||
} |
||||
|
||||
public enum OptionType |
||||
{ |
||||
Explicit, |
||||
Strict, |
||||
Compare, |
||||
Infer |
||||
} |
||||
|
||||
public enum OptionValue |
||||
{ |
||||
On, Off, |
||||
Text, Binary |
||||
} |
||||
} |
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class TypeDeclaration : AttributedNode |
||||
{ |
||||
public readonly static Role<AttributedNode> MemberRole = new Role<AttributedNode>("Member"); |
||||
public readonly static Role<AstType> InheritsTypeRole = new Role<AstType>("InheritsType", AstType.Null); |
||||
public readonly static Role<AstType> ImplementsTypesRole = new Role<AstType>("ImplementsTypes", AstType.Null); |
||||
|
||||
public AstNodeCollection<AttributedNode> Members { |
||||
get { return base.GetChildrenByRole(MemberRole); } |
||||
} |
||||
|
||||
public ClassType ClassType { get; set; } |
||||
|
||||
public Identifier Name { |
||||
get { return GetChildByRole(Roles.Identifier); } |
||||
set { SetChildByRole(Roles.Identifier, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<TypeParameterDeclaration> TypeParameters { |
||||
get { return GetChildrenByRole(Roles.TypeParameter); } |
||||
} |
||||
|
||||
public AstType InheritsType { |
||||
get { return GetChildByRole(InheritsTypeRole); } |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> ImplementsTypes { |
||||
get { return GetChildrenByRole(ImplementsTypesRole); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
TypeDeclaration t = other as TypeDeclaration; |
||||
return t != null && |
||||
MatchAttributesAndModifiers(t, match) && |
||||
Members.DoMatch(t.Members, match) && |
||||
ClassType == t.ClassType && |
||||
Name.DoMatch(t.Name, match) && |
||||
TypeParameters.DoMatch(t.TypeParameters, match) && |
||||
InheritsType.DoMatch(t.InheritsType, match) && |
||||
ImplementsTypes.DoMatch(t.ImplementsTypes, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitTypeDeclaration(this, data); |
||||
} |
||||
} |
||||
} |
@ -1,51 +0,0 @@
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public interface INode |
||||
{ |
||||
INode Parent { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
List<INode> Children { |
||||
get; |
||||
} |
||||
|
||||
Location StartLocation { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
Location EndLocation { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
object UserData { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Visits all children
|
||||
/// </summary>
|
||||
/// <param name="visitor">The visitor to accept</param>
|
||||
/// <param name="data">Additional data for the visitor</param>
|
||||
/// <returns>The paremeter <paramref name="data"/></returns>
|
||||
object AcceptChildren(IAstVisitor visitor, object data); |
||||
|
||||
/// <summary>
|
||||
/// Accept the visitor
|
||||
/// </summary>
|
||||
/// <param name="visitor">The visitor to accept</param>
|
||||
/// <param name="data">Additional data for the visitor</param>
|
||||
/// <returns>The value the visitor returns after the visit</returns>
|
||||
object AcceptVisitor(IAstVisitor visitor, object data); |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an identifier in VB.
|
||||
/// </summary>
|
||||
public class Identifier : AstNode |
||||
{ |
||||
public static readonly new Identifier Null = new NullIdentifier (); |
||||
class NullIdentifier : Identifier |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
|
||||
string name; |
||||
|
||||
public string Name { |
||||
get { return name; } |
||||
set { |
||||
if (value == null) |
||||
throw new ArgumentNullException("value"); |
||||
name = value; |
||||
} |
||||
} |
||||
|
||||
public TypeCode TypeCharacter { get; set; } |
||||
|
||||
AstLocation startLocation; |
||||
public override AstLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
public override AstLocation EndLocation { |
||||
get { |
||||
return new AstLocation (StartLocation.Line, StartLocation.Column + Name.Length); |
||||
} |
||||
} |
||||
|
||||
private Identifier() |
||||
{ |
||||
this.name = string.Empty; |
||||
} |
||||
|
||||
public Identifier (string name, AstLocation location) |
||||
{ |
||||
if (name == null) |
||||
throw new ArgumentNullException("name"); |
||||
this.Name = name; |
||||
this.startLocation = location; |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var node = other as Identifier; |
||||
return node != null |
||||
&& MatchString(node.name, name) |
||||
&& node.TypeCharacter == TypeCharacter; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitIdentifier(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[Identifier Name={0}, StartLocation={1}, TypeCharacter{4}]", |
||||
name, startLocation, TypeCharacter); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,125 @@
@@ -0,0 +1,125 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// { Statements }
|
||||
/// </summary>
|
||||
public class BlockStatement : Statement, IEnumerable<Statement> |
||||
{ |
||||
public static readonly Role<Statement> StatementRole = new Role<Statement>("Statement", Statement.Null); |
||||
|
||||
#region Null
|
||||
public static readonly new BlockStatement Null = new NullBlockStatement(); |
||||
sealed class NullBlockStatement : BlockStatement |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default(S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator BlockStatement(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public AstNodeCollection<Statement> Statements { |
||||
get { return GetChildrenByRole (StatementRole); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitBlockStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
BlockStatement o = other as BlockStatement; |
||||
return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match); |
||||
} |
||||
|
||||
#region Builder methods
|
||||
public void Add(Statement statement) |
||||
{ |
||||
AddChild(statement, StatementRole); |
||||
} |
||||
|
||||
// TODO : uncomment
|
||||
|
||||
// public void Add(Expression expression)
|
||||
// {
|
||||
// AddChild(new ExpressionStatement { Expression = expression }, StatementRole);
|
||||
// }
|
||||
//
|
||||
public void AddRange(IEnumerable<Statement> statements) |
||||
{ |
||||
foreach (Statement st in statements) |
||||
AddChild(st, StatementRole); |
||||
} |
||||
|
||||
// public void AddAssignment(Expression left, Expression right)
|
||||
// {
|
||||
// Add(new AssignmentExpression { Left = left, Operator = AssignmentOperatorType.Assign, Right = right });
|
||||
// }
|
||||
//
|
||||
// public void AddReturnStatement(Expression expression)
|
||||
// {
|
||||
// Add(new ReturnStatement { Expression = expression });
|
||||
// }
|
||||
#endregion
|
||||
|
||||
IEnumerator<Statement> IEnumerable<Statement>.GetEnumerator() |
||||
{ |
||||
return this.Statements.GetEnumerator(); |
||||
} |
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
||||
{ |
||||
return this.Statements.GetEnumerator(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,132 @@
@@ -0,0 +1,132 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for statements.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class is useful even though it doesn't provide any additional functionality:
|
||||
/// It can be used to communicate more information in APIs, e.g. "this subnode will always be a statement"
|
||||
/// </remarks>
|
||||
public abstract class Statement : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly Statement Null = new NullStatement (); |
||||
|
||||
sealed class NullStatement : Statement |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator Statement(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : Statement, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the previous statement within the current block.
|
||||
/// This is usually equivalent to <see cref="PrevSibling"/>, but will skip any non-statements (e.g. comments)
|
||||
/// </summary>
|
||||
public Statement PreviousStatement { |
||||
get { |
||||
AstNode node = this; |
||||
while ((node = node.PrevSibling) != null) { |
||||
Statement stmt = node as Statement; |
||||
if (stmt != null) |
||||
return stmt; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the next statement within the current block.
|
||||
/// This is usually equivalent to <see cref="NextSibling"/>, but will skip any non-statements (e.g. comments)
|
||||
/// </summary>
|
||||
public Statement NextStatement { |
||||
get { |
||||
AstNode node = this; |
||||
while ((node = node.NextSibling) != null) { |
||||
Statement stmt = node as Statement; |
||||
if (stmt != null) |
||||
return stmt; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public new Statement Clone() |
||||
{ |
||||
return (Statement)base.Clone(); |
||||
} |
||||
|
||||
public Statement ReplaceWith(Func<Statement, Statement> replaceFunction) |
||||
{ |
||||
if (replaceFunction == null) |
||||
throw new ArgumentNullException("replaceFunction"); |
||||
return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node)); |
||||
} |
||||
|
||||
// Make debugging easier by giving Statements a ToString() implementation
|
||||
public override string ToString() |
||||
{ |
||||
// if (IsNull)
|
||||
// return "Null";
|
||||
// StringWriter w = new StringWriter();
|
||||
// AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null);
|
||||
// string text = w.ToString().TrimEnd().Replace("\t", "").Replace(w.NewLine, " ");
|
||||
// if (text.Length > 100)
|
||||
// return text.Substring(0, 97) + "...";
|
||||
// else
|
||||
// return text;
|
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,145 @@
@@ -0,0 +1,145 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// A type reference in the VB AST.
|
||||
/// </summary>
|
||||
public abstract class AstType : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly AstType Null = new NullAstType(); |
||||
|
||||
sealed class NullAstType : AstType |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator AstType(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : AstType, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public virtual AstType MakeArrayType(int rank = 1) |
||||
{ |
||||
return new ComposedType { BaseType = this }.MakeArrayType(rank); |
||||
} |
||||
|
||||
// TODO : reimplement this
|
||||
// /// <summary>
|
||||
// /// Builds an expression that can be used to access a static member on this type.
|
||||
// /// </summary>
|
||||
// public MemberReferenceExpression Member(string memberName)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Member(memberName);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Builds an invocation expression using this type as target.
|
||||
// /// </summary>
|
||||
// public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Builds an invocation expression using this type as target.
|
||||
// /// </summary>
|
||||
// public InvocationExpression Invoke(string methodName, params Expression[] arguments)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Builds an invocation expression using this type as target.
|
||||
// /// </summary>
|
||||
// public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments);
|
||||
// }
|
||||
|
||||
public static AstType Create(Type type) |
||||
{ |
||||
switch (Type.GetTypeCode(type)) { |
||||
case TypeCode.Object: |
||||
return new PrimitiveType("Object"); |
||||
case TypeCode.Boolean: |
||||
return new PrimitiveType("Boolean"); |
||||
case TypeCode.Char: |
||||
return new PrimitiveType("Char"); |
||||
case TypeCode.SByte: |
||||
return new PrimitiveType("SByte"); |
||||
case TypeCode.Byte: |
||||
return new PrimitiveType("Byte"); |
||||
case TypeCode.Int16: |
||||
return new PrimitiveType("Short"); |
||||
case TypeCode.UInt16: |
||||
return new PrimitiveType("UShort"); |
||||
case TypeCode.Int32: |
||||
return new PrimitiveType("Integer"); |
||||
case TypeCode.UInt32: |
||||
return new PrimitiveType("UInteger"); |
||||
case TypeCode.Int64: |
||||
return new PrimitiveType("Long"); |
||||
case TypeCode.UInt64: |
||||
return new PrimitiveType("ULong"); |
||||
case TypeCode.Single: |
||||
return new PrimitiveType("Single"); |
||||
case TypeCode.Double: |
||||
return new PrimitiveType("Double"); |
||||
case TypeCode.Decimal: |
||||
return new PrimitiveType("Decimal"); |
||||
case TypeCode.String: |
||||
return new PrimitiveType("String"); |
||||
case TypeCode.DateTime: |
||||
return new PrimitiveType("Date"); |
||||
} |
||||
return new SimpleType(type.FullName); // TODO: implement this correctly
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class ComposedType : AstType |
||||
{ |
||||
public static readonly Role<VBTokenNode> NullableRole = new Role<VBTokenNode>("Nullable", VBTokenNode.Null); |
||||
public static readonly Role<ArraySpecifier> ArraySpecifierRole = new Role<ArraySpecifier>("ArraySpecifier"); |
||||
|
||||
public AstType BaseType { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public bool HasNullableSpecifier { |
||||
get { |
||||
return !GetChildByRole(NullableRole).IsNull; |
||||
} |
||||
set { |
||||
SetChildByRole(NullableRole, value ? new VBTokenNode(AstLocation.Empty, 1) : null); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<ArraySpecifier> ArraySpecifiers { |
||||
get { return GetChildrenByRole (ArraySpecifierRole); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitComposedType (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ComposedType o = other as ComposedType; |
||||
return o != null && this.HasNullableSpecifier == o.HasNullableSpecifier && this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
b.Append(this.BaseType.ToString()); |
||||
if (this.HasNullableSpecifier) |
||||
b.Append('?'); |
||||
foreach (var arraySpecifier in this.ArraySpecifiers) { |
||||
b.Append('('); |
||||
b.Append(',', arraySpecifier.Dimensions - 1); |
||||
b.Append(')'); |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
|
||||
public override AstType MakeArrayType(int dimensions) |
||||
{ |
||||
InsertChildBefore(this.ArraySpecifiers.FirstOrDefault(), new ArraySpecifier(dimensions), ArraySpecifierRole); |
||||
return this; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// [,,,]
|
||||
/// </summary>
|
||||
public class ArraySpecifier : AstNode |
||||
{ |
||||
public ArraySpecifier() |
||||
{ |
||||
} |
||||
|
||||
public ArraySpecifier(int dimensions) |
||||
{ |
||||
this.Dimensions = dimensions; |
||||
} |
||||
|
||||
public VBTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public int Dimensions { |
||||
get { return 1 + GetChildrenByRole(Roles.Comma).Count(); } |
||||
set { |
||||
int d = this.Dimensions; |
||||
while (d > value) { |
||||
GetChildByRole(Roles.Comma).Remove(); |
||||
d--; |
||||
} |
||||
while (d < value) { |
||||
InsertChildBefore(GetChildByRole(Roles.Comma), new VBTokenNode(AstLocation.Empty, 1), Roles.Comma); |
||||
d++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public VBTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitArraySpecifier(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ArraySpecifier o = other as ArraySpecifier; |
||||
return o != null && this.Dimensions == o.Dimensions; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return "(" + new string(',', this.Dimensions - 1) + ")"; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class PrimitiveType : AstType |
||||
{ |
||||
public string Keyword { get; set; } |
||||
public AstLocation Location { get; set; } |
||||
|
||||
public PrimitiveType() |
||||
{ |
||||
} |
||||
|
||||
public PrimitiveType(string keyword) |
||||
{ |
||||
this.Keyword = keyword; |
||||
} |
||||
|
||||
public PrimitiveType(string keyword, AstLocation location) |
||||
{ |
||||
this.Keyword = keyword; |
||||
this.Location = location; |
||||
} |
||||
|
||||
public override AstLocation StartLocation { |
||||
get { |
||||
return Location; |
||||
} |
||||
} |
||||
public override AstLocation EndLocation { |
||||
get { |
||||
return new AstLocation (Location.Line, Location.Column + (Keyword != null ? Keyword.Length : 0)); |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPrimitiveType(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
PrimitiveType o = other as PrimitiveType; |
||||
return o != null && MatchString(this.Keyword, o.Keyword); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return Keyword ?? base.ToString(); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Description of QualifiedType.
|
||||
/// </summary>
|
||||
public class QualifiedType : AstType |
||||
{ |
||||
public static readonly Role<AstType> TargetRole = new Role<AstType>("Target", AstType.Null); |
||||
|
||||
public AstType Target { |
||||
get { return GetChildByRole(TargetRole); } |
||||
set { SetChildByRole(TargetRole, value); } |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole (Roles.Identifier, new Identifier(value, AstLocation.Empty)); |
||||
} |
||||
} |
||||
|
||||
public QualifiedType(AstType target, Identifier name) |
||||
{ |
||||
Target = target; |
||||
SetChildByRole(Roles.Identifier, name); |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> TypeArguments { |
||||
get { return GetChildrenByRole (Roles.TypeArgument); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitQualifiedType(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as QualifiedType; |
||||
return o != null && MatchString(this.Name, o.Name) && this.Target.DoMatch(o.Target, match); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
b.Append(this.Target); |
||||
b.Append('.'); |
||||
b.Append(this.Name); |
||||
if (this.TypeArguments.Any()) { |
||||
b.Append('('); |
||||
b.Append(string.Join(", ", this.TypeArguments)); |
||||
b.Append(')'); |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// FullTypeName.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class SimpleType : AstType |
||||
{ |
||||
public SimpleType() |
||||
{ |
||||
} |
||||
|
||||
public SimpleType(string identifier) |
||||
{ |
||||
this.Identifier = identifier; |
||||
} |
||||
|
||||
public SimpleType(string identifier, AstLocation location) |
||||
{ |
||||
SetChildByRole (Roles.Identifier, new Identifier(identifier, location)); |
||||
} |
||||
|
||||
public string Identifier { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole (Roles.Identifier, new Identifier(value, AstLocation.Empty)); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> TypeArguments { |
||||
get { return GetChildrenByRole (Roles.TypeArgument); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitSimpleType(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
SimpleType o = other as SimpleType; |
||||
return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
StringBuilder b = new StringBuilder(this.Identifier); |
||||
if (this.TypeArguments.Any()) { |
||||
b.Append('('); |
||||
b.Append("Of "); |
||||
b.Append(string.Join(", ", this.TypeArguments)); |
||||
b.Append(')'); |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,427 +0,0 @@
@@ -1,427 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Globalization; |
||||
using System.Runtime.InteropServices; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class TypeReference : AbstractNode, INullable, ICloneable |
||||
{ |
||||
public static readonly TypeReference StructConstraint = new TypeReference("constraint: struct"); |
||||
public static readonly TypeReference ClassConstraint = new TypeReference("constraint: class"); |
||||
public static readonly TypeReference NewConstraint = new TypeReference("constraint: new"); |
||||
|
||||
string type = ""; |
||||
int pointerNestingLevel; |
||||
int[] rankSpecifier; |
||||
List<TypeReference> genericTypes = new List<TypeReference>(); |
||||
|
||||
#region Static primitive type list
|
||||
static Dictionary<string, string> types = new Dictionary<string, string>(); |
||||
static Dictionary<string, string> vbtypes = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); |
||||
static Dictionary<string, string> typesReverse = new Dictionary<string, string>(); |
||||
static Dictionary<string, string> vbtypesReverse = new Dictionary<string, string>(); |
||||
|
||||
static TypeReference() |
||||
{ |
||||
// C# types
|
||||
types.Add("bool", "System.Boolean"); |
||||
types.Add("byte", "System.Byte"); |
||||
types.Add("char", "System.Char"); |
||||
types.Add("decimal", "System.Decimal"); |
||||
types.Add("double", "System.Double"); |
||||
types.Add("float", "System.Single"); |
||||
types.Add("int", "System.Int32"); |
||||
types.Add("long", "System.Int64"); |
||||
types.Add("object", "System.Object"); |
||||
types.Add("sbyte", "System.SByte"); |
||||
types.Add("short", "System.Int16"); |
||||
types.Add("string", "System.String"); |
||||
types.Add("uint", "System.UInt32"); |
||||
types.Add("ulong", "System.UInt64"); |
||||
types.Add("ushort", "System.UInt16"); |
||||
types.Add("void", "System.Void"); |
||||
|
||||
// VB.NET types
|
||||
vbtypes.Add("Boolean", "System.Boolean"); |
||||
vbtypes.Add("Byte", "System.Byte"); |
||||
vbtypes.Add("SByte", "System.SByte"); |
||||
vbtypes.Add("Date", "System.DateTime"); |
||||
vbtypes.Add("Char", "System.Char"); |
||||
vbtypes.Add("Decimal", "System.Decimal"); |
||||
vbtypes.Add("Double", "System.Double"); |
||||
vbtypes.Add("Single", "System.Single"); |
||||
vbtypes.Add("Integer", "System.Int32"); |
||||
vbtypes.Add("Long", "System.Int64"); |
||||
vbtypes.Add("UInteger","System.UInt32"); |
||||
vbtypes.Add("ULong", "System.UInt64"); |
||||
vbtypes.Add("Object", "System.Object"); |
||||
vbtypes.Add("Short", "System.Int16"); |
||||
vbtypes.Add("UShort", "System.UInt16"); |
||||
vbtypes.Add("String", "System.String"); |
||||
|
||||
foreach (KeyValuePair<string, string> pair in types) { |
||||
typesReverse.Add(pair.Value, pair.Key); |
||||
} |
||||
foreach (KeyValuePair<string, string> pair in vbtypes) { |
||||
vbtypesReverse.Add(pair.Value, pair.Key); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a shortname=>full name dictionary of C# types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> PrimitiveTypesCSharp { |
||||
get { return types; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a shortname=>full name dictionary of VB types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> PrimitiveTypesVB { |
||||
get { return vbtypes; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a full name=>shortname dictionary of C# types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> PrimitiveTypesCSharpReverse { |
||||
get { return typesReverse; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a full name=>shortname dictionary of VB types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> PrimitiveTypesVBReverse { |
||||
get { return vbtypesReverse; } |
||||
} |
||||
|
||||
|
||||
static string GetSystemType(string type) |
||||
{ |
||||
if (types == null) return type; |
||||
|
||||
string systemType; |
||||
if (types.TryGetValue(type, out systemType)) { |
||||
return systemType; |
||||
} |
||||
if (vbtypes.TryGetValue(type, out systemType)) { |
||||
return systemType; |
||||
} |
||||
return type; |
||||
} |
||||
#endregion
|
||||
|
||||
object ICloneable.Clone() |
||||
{ |
||||
return this.Clone(); |
||||
} |
||||
|
||||
public virtual TypeReference Clone() |
||||
{ |
||||
TypeReference c = new TypeReference(type); |
||||
CopyFields(this, c); |
||||
return c; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the pointerNestingLevel, RankSpecifier, GenericTypes and IsGlobal flag
|
||||
/// from <paramref name="from"/> to <paramref name="to"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If <paramref name="to"/> already contains generics, the new generics are appended to the list.
|
||||
/// </remarks>
|
||||
protected static void CopyFields(TypeReference from, TypeReference to) |
||||
{ |
||||
to.pointerNestingLevel = from.pointerNestingLevel; |
||||
if (from.rankSpecifier != null) { |
||||
to.rankSpecifier = (int[])from.rankSpecifier.Clone(); |
||||
} |
||||
foreach (TypeReference r in from.genericTypes) { |
||||
to.genericTypes.Add(r.Clone()); |
||||
} |
||||
to.IsGlobal = from.IsGlobal; |
||||
to.IsKeyword = from.IsKeyword; |
||||
} |
||||
|
||||
public string Type { |
||||
get { |
||||
return type; |
||||
} |
||||
set { |
||||
Debug.Assert(value != null); |
||||
type = value ?? "?"; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the last identifier from the type.
|
||||
/// e.g. "System.String.Length" becomes "System.String" or
|
||||
/// "System.Collections.IEnumerable(of string).Current" becomes "System.Collections.IEnumerable(of string)"
|
||||
/// This is used for explicit interface implementation in VB.
|
||||
/// </summary>
|
||||
public static string StripLastIdentifierFromType(ref TypeReference tr) |
||||
{ |
||||
if (tr is InnerClassTypeReference && ((InnerClassTypeReference)tr).Type.IndexOf('.') < 0) { |
||||
string ident = ((InnerClassTypeReference)tr).Type; |
||||
tr = ((InnerClassTypeReference)tr).BaseType; |
||||
return ident; |
||||
} else { |
||||
int pos = tr.Type.LastIndexOf('.'); |
||||
if (pos < 0) |
||||
return tr.Type; |
||||
string ident = tr.Type.Substring(pos + 1); |
||||
tr.Type = tr.Type.Substring(0, pos); |
||||
return ident; |
||||
} |
||||
} |
||||
|
||||
public int PointerNestingLevel { |
||||
get { |
||||
return pointerNestingLevel; |
||||
} |
||||
set { |
||||
Debug.Assert(this.IsNull == false); |
||||
pointerNestingLevel = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The rank of the array type.
|
||||
/// For "object[]", this is { 0 }; for "object[,]", it is {1}.
|
||||
/// For "object[,][,,][]", it is {1, 2, 0}.
|
||||
/// For non-array types, this property is null or {}.
|
||||
/// </summary>
|
||||
public int[] RankSpecifier { |
||||
get { |
||||
return rankSpecifier; |
||||
} |
||||
set { |
||||
Debug.Assert(this.IsNull == false); |
||||
rankSpecifier = value; |
||||
} |
||||
} |
||||
|
||||
public List<TypeReference> GenericTypes { |
||||
get { |
||||
return genericTypes; |
||||
} |
||||
} |
||||
|
||||
public bool IsArrayType { |
||||
get { |
||||
return rankSpecifier != null && rankSpecifier.Length > 0; |
||||
} |
||||
} |
||||
|
||||
public static TypeReference CheckNull(TypeReference typeReference) |
||||
{ |
||||
return typeReference ?? NullTypeReference.Instance; |
||||
} |
||||
|
||||
public static TypeReference Null { |
||||
get { |
||||
return NullTypeReference.Instance; |
||||
} |
||||
} |
||||
|
||||
public virtual bool IsNull { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets if the type reference had a "global::" prefix.
|
||||
/// </summary>
|
||||
public bool IsGlobal { |
||||
get; set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets if the type reference was using a language keyword.
|
||||
/// </summary>
|
||||
public bool IsKeyword { |
||||
get; set; |
||||
} |
||||
|
||||
public TypeReference(string type) |
||||
{ |
||||
this.Type = type; |
||||
} |
||||
|
||||
public TypeReference(string type, bool isKeyword) |
||||
{ |
||||
this.Type = type; |
||||
this.IsKeyword = isKeyword; |
||||
} |
||||
|
||||
public TypeReference(string type, List<TypeReference> genericTypes) : this(type) |
||||
{ |
||||
if (genericTypes != null) { |
||||
this.genericTypes = genericTypes; |
||||
} |
||||
} |
||||
|
||||
public TypeReference(string type, int[] rankSpecifier) : this(type, 0, rankSpecifier) |
||||
{ |
||||
} |
||||
|
||||
public TypeReference(string type, int pointerNestingLevel, int[] rankSpecifier) : this(type, pointerNestingLevel, rankSpecifier, null) |
||||
{ |
||||
} |
||||
|
||||
public TypeReference(string type, int pointerNestingLevel, int[] rankSpecifier, List<TypeReference> genericTypes) |
||||
{ |
||||
Debug.Assert(type != null); |
||||
this.type = type; |
||||
this.pointerNestingLevel = pointerNestingLevel; |
||||
this.rankSpecifier = rankSpecifier; |
||||
if (genericTypes != null) { |
||||
this.genericTypes = genericTypes; |
||||
} |
||||
} |
||||
|
||||
protected TypeReference() |
||||
{} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.VisitTypeReference(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
StringBuilder b = new StringBuilder(type); |
||||
if (genericTypes != null && genericTypes.Count > 0) { |
||||
b.Append('<'); |
||||
for (int i = 0; i < genericTypes.Count; i++) { |
||||
if (i > 0) b.Append(','); |
||||
b.Append(genericTypes[i].ToString()); |
||||
} |
||||
b.Append('>'); |
||||
} |
||||
if (pointerNestingLevel > 0) { |
||||
b.Append('*', pointerNestingLevel); |
||||
} |
||||
if (IsArrayType) { |
||||
foreach (int rank in rankSpecifier) { |
||||
b.Append('['); |
||||
if (rank < 0) |
||||
b.Append('`', -rank); |
||||
else |
||||
b.Append(',', rank); |
||||
b.Append(']'); |
||||
} |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
|
||||
public static bool AreEqualReferences(TypeReference a, TypeReference b) |
||||
{ |
||||
if (a == b) return true; |
||||
if (a == null || b == null) return false; |
||||
if (a is InnerClassTypeReference) a = ((InnerClassTypeReference)a).CombineToNormalTypeReference(); |
||||
if (b is InnerClassTypeReference) b = ((InnerClassTypeReference)b).CombineToNormalTypeReference(); |
||||
if (a.type != b.type) return false; |
||||
if (a.IsKeyword != b.IsKeyword) return false; |
||||
if (a.IsGlobal != b.IsGlobal) return false; |
||||
if (a.pointerNestingLevel != b.pointerNestingLevel) return false; |
||||
if (a.IsArrayType != b.IsArrayType) return false; |
||||
if (a.IsArrayType) { |
||||
if (a.rankSpecifier.Length != b.rankSpecifier.Length) return false; |
||||
for (int i = 0; i < a.rankSpecifier.Length; i++) { |
||||
if (a.rankSpecifier[i] != b.rankSpecifier[i]) return false; |
||||
} |
||||
} |
||||
if (a.genericTypes.Count != b.genericTypes.Count) return false; |
||||
for (int i = 0; i < a.genericTypes.Count; i++) { |
||||
if (!AreEqualReferences(a.genericTypes[i], b.genericTypes[i])) |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
internal sealed class NullTypeReference : TypeReference |
||||
{ |
||||
public static readonly NullTypeReference Instance = new NullTypeReference(); |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
public override TypeReference Clone() |
||||
{ |
||||
return this; |
||||
} |
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullTypeReference]"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// We need this special type reference for cases like
|
||||
/// OuterClass(Of T1).InnerClass(Of T2) (in expression or type context)
|
||||
/// or Dictionary(Of String, NamespaceStruct).KeyCollection (in type context, otherwise it's a
|
||||
/// MemberReferenceExpression)
|
||||
/// </summary>
|
||||
public class InnerClassTypeReference: TypeReference |
||||
{ |
||||
TypeReference baseType; |
||||
|
||||
public TypeReference BaseType { |
||||
get { return baseType; } |
||||
set { baseType = value; } |
||||
} |
||||
|
||||
public override TypeReference Clone() |
||||
{ |
||||
InnerClassTypeReference c = new InnerClassTypeReference(baseType.Clone(), Type, new List<TypeReference>()); |
||||
CopyFields(this, c); |
||||
return c; |
||||
} |
||||
|
||||
public InnerClassTypeReference(TypeReference outerClass, string innerType, List<TypeReference> innerGenericTypes) |
||||
: base(innerType, innerGenericTypes) |
||||
{ |
||||
this.baseType = outerClass; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.VisitInnerClassTypeReference(this, data); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a type reference where all type parameters are specified for the innermost class.
|
||||
/// Namespace.OuterClass(of string).InnerClass(of integer).InnerInnerClass
|
||||
/// becomes Namespace.OuterClass.InnerClass.InnerInnerClass(of string, integer)
|
||||
/// </summary>
|
||||
public TypeReference CombineToNormalTypeReference() |
||||
{ |
||||
TypeReference tr = (baseType is InnerClassTypeReference) |
||||
? ((InnerClassTypeReference)baseType).CombineToNormalTypeReference() |
||||
: baseType.Clone(); |
||||
CopyFields(this, tr); |
||||
tr.Type += "." + Type; |
||||
return tr; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return baseType.ToString() + "+" + base.ToString(); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue