.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
1.8 KiB

// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace ICSharpCode.NRefactory.Ast
{
public abstract class AbstractNode : INode
{
IList<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 IList<INode> Children {
get {
return children;
}
set {
Debug.Assert(value != null);
children = value;
}
}
public virtual void AddChild(INode childNode)
{
Debug.Assert(childNode != null);
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<T>(IList<T> 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();
}
}
}