Browse Source

Implemented OutputVisitor.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
35a8fd1dfa
  1. 3
      ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  2. 11
      ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs
  3. 5
      ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs
  4. 36
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs
  5. 48
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs
  6. 2
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs
  7. 2
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs
  8. 28
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs
  9. 25
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs
  10. 2
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs
  11. 2
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs
  12. 4
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs
  13. 1
      ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs
  14. 4
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs
  15. 5
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs
  16. 25
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputFormatter.cs
  17. 1623
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  18. 1
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

3
ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs

@ -216,7 +216,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
if (role == null) if (role == null)
throw new ArgumentNullException("role"); throw new ArgumentNullException("role");
if (nextSibling == null) { if (nextSibling == null || nextSibling.IsNull) {
AddChild(child, role); AddChild(child, role);
return; return;
} }
@ -563,6 +563,7 @@ namespace ICSharpCode.NRefactory.CSharp
public static readonly Role<CSharpTokenNode> LChevron = new Role<CSharpTokenNode>("LChevron", CSharpTokenNode.Null); public static readonly Role<CSharpTokenNode> LChevron = new Role<CSharpTokenNode>("LChevron", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> RChevron = new Role<CSharpTokenNode>("RChevron", CSharpTokenNode.Null); public static readonly Role<CSharpTokenNode> RChevron = new Role<CSharpTokenNode>("RChevron", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Comma = new Role<CSharpTokenNode>("Comma", CSharpTokenNode.Null); public static readonly Role<CSharpTokenNode> Comma = new Role<CSharpTokenNode>("Comma", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Dot = new Role<CSharpTokenNode>("Dot", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Semicolon = new Role<CSharpTokenNode>("Semicolon", CSharpTokenNode.Null); public static readonly Role<CSharpTokenNode> Semicolon = new Role<CSharpTokenNode>("Semicolon", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Assign = new Role<CSharpTokenNode>("Assign", CSharpTokenNode.Null); public static readonly Role<CSharpTokenNode> Assign = new Role<CSharpTokenNode>("Assign", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Colon = new Role<CSharpTokenNode>("Colon", CSharpTokenNode.Null); public static readonly Role<CSharpTokenNode> Colon = new Role<CSharpTokenNode>("Colon", CSharpTokenNode.Null);

11
ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs

@ -104,6 +104,17 @@ namespace ICSharpCode.NRefactory.CSharp
public int Dimensions { public int Dimensions {
get { return 1 + GetChildrenByRole(Roles.Comma).Count(); } 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 CSharpTokenNode(AstLocation.Empty, 1), Roles.Comma);
d++;
}
}
} }
public override S AcceptVisitor<T, S> (AstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (AstVisitor<T, S> visitor, T data)

5
ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs

@ -522,6 +522,11 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (arrayInitializerExpression, data); return VisitChildren (arrayInitializerExpression, data);
} }
public virtual S VisitArraySpecifier (ArraySpecifier arraySpecifier, T data)
{
return VisitChildren (arraySpecifier, data);
}
public virtual S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data) public virtual S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data)
{ {
return VisitChildren (namedArgumentExpression, data); return VisitChildren (namedArgumentExpression, data);

36
ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs

@ -1,6 +1,6 @@
// //
// AssignmentExpression.cs // AssignmentExpression.cs
// //
// Author: // Author:
// Mike Krüger <mkrueger@novell.com> // Mike Krüger <mkrueger@novell.com>
// //
@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
/// <summary> /// <summary>
@ -59,9 +61,39 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
return visitor.VisitAssignmentExpression (this, data); return visitor.VisitAssignmentExpression (this, data);
} }
public static string GetOperatorSymbol(AssignmentOperatorType op)
{
switch (op) {
case AssignmentOperatorType.Assign:
return "=";
case AssignmentOperatorType.Add:
return "+=";
case AssignmentOperatorType.Subtract:
return "-=";
case AssignmentOperatorType.Multiply:
return "*=";
case AssignmentOperatorType.Divide:
return "/=";
case AssignmentOperatorType.Modulus:
return "%=";
case AssignmentOperatorType.ShiftLeft:
return "<<=";
case AssignmentOperatorType.ShiftRight:
return ">>=";
case AssignmentOperatorType.BitwiseAnd:
return "&=";
case AssignmentOperatorType.BitwiseOr:
return "|=";
case AssignmentOperatorType.ExclusiveOr:
return "^=";
default:
throw new NotSupportedException("Invalid value for AssignmentOperatorType");
}
}
} }
public enum AssignmentOperatorType public enum AssignmentOperatorType
{ {
/// <summary>left = right</summary> /// <summary>left = right</summary>
Assign, Assign,

48
ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs

@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
/// <summary> /// <summary>
@ -58,6 +60,52 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
return visitor.VisitBinaryOperatorExpression (this, data); return visitor.VisitBinaryOperatorExpression (this, data);
} }
public static string GetOperatorSymbol(BinaryOperatorType op)
{
switch (op) {
case BinaryOperatorType.BitwiseAnd:
return "&";
case BinaryOperatorType.BitwiseOr:
return "|";
case BinaryOperatorType.LogicalAnd:
return "&&";
case BinaryOperatorType.LogicalOr:
return "||";
case BinaryOperatorType.ExclusiveOr:
return "^";
case BinaryOperatorType.GreaterThan:
return ">";
case BinaryOperatorType.GreaterThanOrEqual:
return ">=";
case BinaryOperatorType.Equality:
return "==";
case BinaryOperatorType.InEquality:
return "!=";
case BinaryOperatorType.LessThan:
return "<";
case BinaryOperatorType.LessThanOrEqual:
return "<=";
case BinaryOperatorType.Add:
return "+";
case BinaryOperatorType.Subtract:
return "-";
case BinaryOperatorType.Multiply:
return "*";
case BinaryOperatorType.Divide:
return "/";
case BinaryOperatorType.Modulus:
return "%";
case BinaryOperatorType.ShiftLeft:
return "<<";
case BinaryOperatorType.ShiftRight:
return ">>";
case BinaryOperatorType.NullCoalescing:
return "??";
default:
throw new NotSupportedException("Invalid value for BinaryOperatorType");
}
}
} }
public enum BinaryOperatorType public enum BinaryOperatorType

2
ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class LambdaExpression : Expression public class LambdaExpression : Expression
{ {
public readonly static Role<CSharpTokenNode> ArrowRole = new Role<CSharpTokenNode>("Arror", CSharpTokenNode.Null); public readonly static Role<CSharpTokenNode> ArrowRole = new Role<CSharpTokenNode>("Arrow", CSharpTokenNode.Null);
public static readonly Role<AstNode> BodyRole = new Role<AstNode>("Body", AstNode.Null); public static readonly Role<AstNode> BodyRole = new Role<AstNode>("Body", AstNode.Null);
public IEnumerable<ParameterDeclaration> Parameters { public IEnumerable<ParameterDeclaration> Parameters {

2
ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs

@ -33,6 +33,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class PointerReferenceExpression : Expression public class PointerReferenceExpression : Expression
{ {
public readonly static Role<CSharpTokenNode> ArrowRole = new Role<CSharpTokenNode>("Arrow", CSharpTokenNode.Null);
public Expression Target { public Expression Target {
get { return GetChildByRole (Roles.TargetExpression); } get { return GetChildByRole (Roles.TargetExpression); }
set { SetChildByRole(Roles.TargetExpression, value); } set { SetChildByRole(Roles.TargetExpression, value); }

28
ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs

@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
/// <summary> /// <summary>
@ -51,6 +53,32 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
return visitor.VisitUnaryOperatorExpression (this, data); return visitor.VisitUnaryOperatorExpression (this, data);
} }
public static string GetOperatorSymbol(UnaryOperatorType op)
{
switch (op) {
case UnaryOperatorType.Not:
return "!";
case UnaryOperatorType.BitNot:
return "~";
case UnaryOperatorType.Minus:
return "-";
case UnaryOperatorType.Plus:
return "+";
case UnaryOperatorType.Increment:
case UnaryOperatorType.PostIncrement:
return "++";
case UnaryOperatorType.PostDecrement:
case UnaryOperatorType.Decrement:
return "--";
case UnaryOperatorType.Dereference:
return "*";
case UnaryOperatorType.AddressOf:
return "&";
default:
throw new NotSupportedException("Invalid value for UnaryOperatorType");
}
}
} }
public enum UnaryOperatorType public enum UnaryOperatorType

25
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs

@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -57,6 +58,30 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
return visitor.VisitAttributeSection (this, data); return visitor.VisitAttributeSection (this, data);
} }
public static string GetAttributeTargetName(AttributeTarget attributeTarget)
{
switch (attributeTarget) {
case AttributeTarget.None:
return null;
case AttributeTarget.Assembly:
return "assembly";
case AttributeTarget.Module:
return "module";
case AttributeTarget.Type:
return "type";
case AttributeTarget.Param:
return "param";
case AttributeTarget.Field:
return "field";
case AttributeTarget.Return:
return "return";
case AttributeTarget.Method:
return "method";
default:
throw new NotSupportedException("Invalid value for AttributeTarget");
}
}
} }
public enum AttributeTarget { public enum AttributeTarget {

2
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class TypeDeclaration : AttributedNode public class TypeDeclaration : AttributedNode
{ {
public readonly static Role<CSharpTokenNode> ColonRole = new Role<CSharpTokenNode>("Colon", CSharpTokenNode.Null); public readonly static Role<CSharpTokenNode> ColonRole = Roles.Colon;
public readonly static Role<AstType> BaseTypeRole = new Role<AstType>("BaseType", AstType.Null); public readonly static Role<AstType> BaseTypeRole = new Role<AstType>("BaseType", AstType.Null);
public readonly static Role<AttributedNode> MemberRole = new Role<AttributedNode>("Member"); public readonly static Role<AttributedNode> MemberRole = new Role<AttributedNode>("Member");

2
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.CSharp
get; set; get; set;
} }
public string Identifier { public string Name {
get { get {
return GetChildByRole (Roles.Identifier).Name; return GetChildByRole (Roles.Identifier).Name;
} }

4
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs

@ -53,6 +53,10 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public CSharpTokenNode AssignToken {
get { return GetChildByRole (Roles.Assign); }
}
public AstType Import { public AstType Import {
get { return GetChildByRole (ImportRole); } get { return GetChildByRole (ImportRole); }
set { SetChildByRole (ImportRole, value); } set { SetChildByRole (ImportRole, value); }

1
ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs

@ -96,6 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitSimpleType(SimpleType simpleType, T data); S VisitSimpleType(SimpleType simpleType, T data);
S VisitMemberType(MemberType memberType, T data); S VisitMemberType(MemberType memberType, T data);
S VisitComposedType(ComposedType composedType, T data); S VisitComposedType(ComposedType composedType, T data);
S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data);
S VisitPrimitiveType(PrimitiveType primitiveType, T data); S VisitPrimitiveType(PrimitiveType primitiveType, T data);
S VisitComment(Comment comment, T data); S VisitComment(Comment comment, T data);

4
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs

@ -21,6 +21,10 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetModifiers(this, value); } set { SetModifiers(this, value); }
} }
public IEnumerable<CSharpModifierToken> ModifierTokens {
get { return GetChildrenByRole (ModifierRole); }
}
internal static Modifiers GetModifiers(AstNode node) internal static Modifiers GetModifiers(AstNode node)
{ {
Modifiers m = 0; Modifiers m = 0;

5
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs

@ -99,6 +99,11 @@ namespace ICSharpCode.NRefactory.CSharp
return Mono.CSharp.Operator.GetMetadataName((Mono.CSharp.Operator.OpType)type); return Mono.CSharp.Operator.GetMetadataName((Mono.CSharp.Operator.OpType)type);
} }
public static string GetToken(OperatorType type)
{
return Mono.CSharp.Operator.GetName((Mono.CSharp.Operator.OpType)type);
}
public override S AcceptVisitor<T, S> (AstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (AstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitOperatorDeclaration (this, data); return visitor.VisitOperatorDeclaration (this, data);

25
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputFormatter.cs

@ -0,0 +1,25 @@
// 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;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// Output formatter for the output visitor.
/// </summary>
public class OutputFormatter
{
void WriteIdentifier(string ident);
void WriteKeyword(string keyword);
void WriteToken(string token);
void Space();
void OpenBrace();
void CloseBrace();
void NewLine();
void WriteComment(CommentType commentType, string content);
}
}

1623
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

File diff suppressed because it is too large Load Diff

1
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -149,6 +149,7 @@
<Compile Include="CSharp\Formatter\DomIndentationVisitor.cs" /> <Compile Include="CSharp\Formatter\DomIndentationVisitor.cs" />
<Compile Include="CSharp\Formatter\DomSpacingVisitor.cs" /> <Compile Include="CSharp\Formatter\DomSpacingVisitor.cs" />
<Compile Include="CSharp\Formatter\Indent.cs" /> <Compile Include="CSharp\Formatter\Indent.cs" />
<Compile Include="CSharp\OutputVisitor\OutputFormatter.cs" />
<Compile Include="CSharp\OutputVisitor\OutputVisitor.cs" /> <Compile Include="CSharp\OutputVisitor\OutputVisitor.cs" />
<Compile Include="CSharp\Parser\CSharpParser.cs" /> <Compile Include="CSharp\Parser\CSharpParser.cs" />
<Compile Include="CSharp\Parser\mcs\CryptoConvert.cs" /> <Compile Include="CSharp\Parser\mcs\CryptoConvert.cs" />

Loading…
Cancel
Save