From e1de044cc0af6c306d22e8ff3ef51b83ebb9aa10 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 14 Feb 2011 17:40:50 +0100 Subject: [PATCH] Squashed 'NRefactory/' changes from ec42611..8db1fe2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 8db1fe2 Enforce space in output visitor when printing "ptr & &v". b00cf19 Add parentheses test for "a + (b == null ? c : d)" 9b5fdd9 fixed endlocation bug. 914df80 Merge remote branch 'origin/master' into master. 9dc67b8 Fix CecilLoaderTests for Dictionary<,>.ValueCollection::Count (it's a non-virtual property implementing an interface; and isn't considered sealed in C#). 28d8b3a Include Mono.Cecil in solution. 16baa75 Corrected astvisitor interface naming. 41168e3 Fixed tests. e0a6909 added more bugfixes. 31113d2 fixed switch section. daccb3a Fixed parser bug. 59da5a2 Worked on type parsing. 65d688a Added some missing token properties. 83a7d2f Splitted the goto statement cases: GotoStatement, GotoCaseStatement, GotoDefaultStatement. ecc1772 Added YieldBreakStatement. 915a122 Added some comments. b8cf7d3 Splitted while & do while statements. b6c562e Fix some formatting issues with the C# output visitor. 48d8ac5 Fixed detection of 'sealed' method modifier. dc6daa1 Fixed output of enum members and the "const" modifier. 6e47f53 Add missing newline after property declarations. a33009d Add hyperlink support to decompiler. 43625b4 Initial port to new NRefactory. 76d844f Merge commit 'd87c5ea2c89dda7da5eab2dce7a30fe10729481f' 57522bf Enable automatic removal when replacing a node with its own descendant. bad0fdb Merge commit 'e1552755b97863393b543603557590ad90d8ef98' 39ad4c4 Update NRefactory to new Mono.Cecil. git-subtree-dir: NRefactory git-subtree-split: 8db1fe252f6539e9cde8c9fb5f59aa60e4089d8f --- .../CSharp/InsertParenthesesVisitorTests.cs | 21 ++ .../Parser/Statements/GotoStatementTests.cs | 9 +- .../Parser/Statements/WhileStatementTests.cs | 4 +- .../TypeSystem/CecilLoaderTests.cs | 3 +- .../CSharp/Ast/AstComparer.cs | 42 +++ ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs | 8 +- ICSharpCode.NRefactory/CSharp/Ast/AstType.cs | 59 ++++- .../CSharp/Ast/CSharpModifierToken.cs | 1 + .../CSharp/Ast/CSharpTokenNode.cs | 6 +- .../CSharp/Ast/CompilationUnit.cs | 4 +- .../CSharp/Ast/ComposedType.cs | 51 +++- .../CSharp/Ast/DepthFirstAstVisitor.cs | 31 ++- .../Expressions/AnonymousMethodExpression.cs | 4 +- .../Ast/Expressions/ArgListExpression.cs | 4 +- .../Ast/Expressions/ArrayCreateExpression.cs | 4 +- .../Expressions/ArrayInitializerExpression.cs | 6 +- .../CSharp/Ast/Expressions/AsExpression.cs | 4 +- .../Ast/Expressions/AssignmentExpression.cs | 4 +- .../Expressions/BaseReferenceExpression.cs | 4 +- .../Expressions/BinaryOperatorExpression.cs | 4 +- .../CSharp/Ast/Expressions/CastExpression.cs | 4 +- .../Ast/Expressions/CheckedExpression.cs | 4 +- .../Ast/Expressions/ConditionalExpression.cs | 4 +- .../Ast/Expressions/DefaultValueExpression.cs | 4 +- .../Ast/Expressions/DirectionExpression.cs | 4 +- .../CSharp/Ast/Expressions/Expression.cs | 38 ++- .../Ast/Expressions/IdentifierExpression.cs | 9 +- .../Ast/Expressions/IndexerExpression.cs | 4 +- .../Ast/Expressions/InvocationExpression.cs | 4 +- .../CSharp/Ast/Expressions/IsExpression.cs | 4 +- .../Ast/Expressions/LambdaExpression.cs | 4 +- .../Expressions/MemberReferenceExpression.cs | 4 +- .../Expressions/NamedArgumentExpression.cs | 4 +- .../Expressions/NullReferenceExpression.cs | 4 +- .../Ast/Expressions/ObjectCreateExpression.cs | 4 +- .../Expressions/ParenthesizedExpression.cs | 7 +- .../Expressions/PointerReferenceExpression.cs | 4 +- .../Ast/Expressions/PrimitiveExpression.cs | 7 +- .../CSharp/Ast/Expressions/QueryExpression.cs | 24 +- .../Ast/Expressions/SizeOfExpression.cs | 4 +- .../Ast/Expressions/StackAllocExpression.cs | 4 +- .../Expressions/ThisReferenceExpression.cs | 7 +- .../Ast/Expressions/TypeOfExpression.cs | 7 +- .../Expressions/TypeReferenceExpression.cs | 24 ++ .../Expressions/UnaryOperatorExpression.cs | 4 +- .../Ast/Expressions/UncheckedExpression.cs | 4 +- .../CSharp/Ast/GeneralScope/Attribute.cs | 4 +- .../Ast/GeneralScope/AttributeSection.cs | 4 +- .../CSharp/Ast/GeneralScope/Comment.cs | 10 +- .../CSharp/Ast/GeneralScope/Constraint.cs | 4 +- .../Ast/GeneralScope/DelegateDeclaration.cs | 4 +- .../Ast/GeneralScope/NamespaceDeclaration.cs | 4 +- .../Ast/GeneralScope/TypeDeclaration.cs | 4 +- .../GeneralScope/TypeParameterDeclaration.cs | 4 +- .../Ast/GeneralScope/UsingAliasDeclaration.cs | 4 +- .../Ast/GeneralScope/UsingDeclaration.cs | 4 +- .../CSharp/Ast/IAstVisitor.cs | 7 +- .../CSharp/Ast/Identifier.cs | 6 +- .../CSharp/Ast/MemberType.cs | 4 +- .../CSharp/Ast/PrimitiveType.cs | 12 +- .../CSharp/Ast/SimpleType.cs | 9 +- .../CSharp/Ast/Statements/BlockStatement.cs | 12 +- .../CSharp/Ast/Statements/BreakStatement.cs | 4 +- .../CSharp/Ast/Statements/CheckedStatement.cs | 4 +- .../Ast/Statements/ContinueStatement.cs | 4 +- .../CSharp/Ast/Statements/DoWhileStatement.cs | 73 ++++++ .../CSharp/Ast/Statements/EmptyStatement.cs | 4 +- .../Ast/Statements/ExpressionStatement.cs | 4 +- .../CSharp/Ast/Statements/FixedStatement.cs | 4 +- .../CSharp/Ast/Statements/ForStatement.cs | 4 +- .../CSharp/Ast/Statements/ForeachStatement.cs | 4 +- .../CSharp/Ast/Statements/GotoStatement.cs | 86 ++++++- .../CSharp/Ast/Statements/IfElseStatement.cs | 15 +- .../CSharp/Ast/Statements/LabelStatement.cs | 4 +- .../CSharp/Ast/Statements/LockStatement.cs | 4 +- .../CSharp/Ast/Statements/ReturnStatement.cs | 4 +- .../CSharp/Ast/Statements/Statement.cs | 4 +- .../CSharp/Ast/Statements/SwitchStatement.cs | 8 +- .../CSharp/Ast/Statements/ThrowStatement.cs | 4 +- .../Ast/Statements/TryCatchStatement.cs | 28 +- .../Ast/Statements/UncheckedStatement.cs | 4 +- .../CSharp/Ast/Statements/UnsafeStatement.cs | 4 +- .../CSharp/Ast/Statements/UsingStatement.cs | 4 +- .../VariableDeclarationStatement.cs | 4 +- .../CSharp/Ast/Statements/WhileStatement.cs | 25 +- .../Ast/Statements/YieldBreakStatement.cs | 54 ++++ .../CSharp/Ast/Statements/YieldStatement.cs | 12 +- .../CSharp/Ast/TypeMembers/Accessor.cs | 6 +- .../Ast/TypeMembers/ConstructorDeclaration.cs | 8 +- .../Ast/TypeMembers/DestructorDeclaration.cs | 4 +- .../Ast/TypeMembers/EnumMemberDeclaration.cs | 4 +- .../Ast/TypeMembers/EventDeclaration.cs | 14 +- .../Ast/TypeMembers/FieldDeclaration.cs | 4 +- .../Ast/TypeMembers/IndexerDeclaration.cs | 12 +- .../Ast/TypeMembers/MethodDeclaration.cs | 5 +- .../Ast/TypeMembers/OperatorDeclaration.cs | 4 +- .../Ast/TypeMembers/ParameterDeclaration.cs | 4 +- .../Ast/TypeMembers/PropertyDeclaration.cs | 4 +- .../Ast/TypeMembers/VariableInitializer.cs | 15 +- .../CSharp/OutputVisitor/IOutputFormatter.cs | 3 + .../CSharp/OutputVisitor/OutputVisitor.cs | 133 +++++++--- .../TextWriterOutputFormatter.cs | 8 + .../CSharp/Parser/CSharpParser.cs | 242 +++++++++++------- .../ICSharpCode.NRefactory.csproj | 16 +- .../TypeSystem/CecilLoader.cs | 16 +- NRefactory.sln | 12 +- 106 files changed, 1047 insertions(+), 400 deletions(-) create mode 100644 ICSharpCode.NRefactory/CSharp/Ast/AstComparer.cs create mode 100644 ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs create mode 100644 ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs create mode 100644 ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs diff --git a/ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs index 1415ca3f3..fd044068f 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs @@ -108,6 +108,27 @@ namespace ICSharpCode.NRefactory.CSharp Assert.AreEqual("-(-a)", InsertReadable(expr)); } + [Test] + public void AdditionWithConditional() + { + Expression expr = new BinaryOperatorExpression { + Left = new IdentifierExpression("a"), + Operator = BinaryOperatorType.Add, + Right = new ConditionalExpression { + Condition = new BinaryOperatorExpression { + Left = new IdentifierExpression("b"), + Operator = BinaryOperatorType.Equality, + Right = new PrimitiveExpression(null) + }, + TrueExpression = new IdentifierExpression("c"), + FalseExpression = new IdentifierExpression("d") + } + }; + + Assert.AreEqual("a + (b == null ? c : d)", InsertRequired(expr)); + Assert.AreEqual("a + ((b == null) ? c : d)", InsertReadable(expr)); + } + [Test] public void TypeTestInConditional() { diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs index e8db13cb6..ce1df02fc 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs @@ -13,23 +13,20 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements [Test, Ignore("regular goto statement is broken")] public void GotoStatementTest() { - GotoStatement gotoStmt = ParseUtilCSharp.ParseStatement("goto myLabel;"); - Assert.AreEqual(GotoType.Label, gotoStmt.GotoType); + var gotoStmt = ParseUtilCSharp.ParseStatement("goto myLabel;"); Assert.AreEqual("myLabel", gotoStmt.Label); } [Test] public void GotoDefaultStatementTest() { - GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement("goto default;"); - Assert.AreEqual(GotoType.CaseDefault, gotoCaseStmt.GotoType); + var gotoCaseStmt = ParseUtilCSharp.ParseStatement("goto default;"); } [Test] public void GotoCaseStatementTest() { - GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement("goto case 6;"); - Assert.AreEqual(GotoType.Case, gotoCaseStmt.GotoType); + var gotoCaseStmt = ParseUtilCSharp.ParseStatement("goto case 6;"); Assert.IsTrue(gotoCaseStmt.LabelExpression is PrimitiveExpression); } diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs index 6ad09465d..689eb0584 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/WhileStatementTests.cs @@ -13,7 +13,6 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements public void WhileStatementTest() { WhileStatement loopStmt = ParseUtilCSharp.ParseStatement("while (true) { }"); - Assert.AreEqual(WhilePosition.Begin, loopStmt.WhilePosition); Assert.IsTrue(loopStmt.Condition is PrimitiveExpression); Assert.IsTrue(loopStmt.EmbeddedStatement is BlockStatement); } @@ -21,8 +20,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements [Test] public void DoWhileStatementTest() { - WhileStatement loopStmt = ParseUtilCSharp.ParseStatement("do { } while (true);"); - Assert.AreEqual(WhilePosition.End, loopStmt.WhilePosition); + DoWhileStatement loopStmt = ParseUtilCSharp.ParseStatement("do { } while (true);"); Assert.IsTrue(loopStmt.Condition is PrimitiveExpression); Assert.IsTrue(loopStmt.EmbeddedStatement is BlockStatement); } diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs index b380c1cd8..408e2b855 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs @@ -153,7 +153,8 @@ namespace ICSharpCode.NRefactory.TypeSystem IProperty count = valueCollection.Properties.Single(p => p.Name == "Count"); Assert.AreEqual(Accessibility.Public, count.Accessibility); - Assert.IsTrue(count.IsSealed); + // It's sealed on the IL level; but in C# it's just a normal non-virtual method that happens to implement an interface + Assert.IsFalse(count.IsSealed); Assert.IsFalse(count.IsVirtual); Assert.IsFalse(count.IsAbstract); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstComparer.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstComparer.cs new file mode 100644 index 000000000..ab74a4fc5 --- /dev/null +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstComparer.cs @@ -0,0 +1,42 @@ +// 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; + +namespace ICSharpCode.NRefactory.CSharp +{ + /// + /// Compares whether two ASTs are structurally identical. + /// + public static class AstComparer + { + static HashSet nodeTypesWithoutExtraInfo = new HashSet { + typeof(IdentifierExpression) + }; + + public static bool? AreEqual(AstNode node1, AstNode node2) + { + if (node1 == node2) + return true; + if (node1 == null || node1.IsNull || node2 == null || node2.IsNull) + return false; + Type nodeType = node1.GetType(); + if (nodeType != node2.GetType()) + return false; + if (node1.Role != node2.Role) + return false; + AstNode child1 = node1.FirstChild; + AstNode child2 = node2.FirstChild; + bool? result = true; + while (result != false && (child1 != null || child2 != null)) { + result &= AreEqual(child1, child2); + } + if (nodeTypesWithoutExtraInfo.Contains(nodeType)) + return result; + if (nodeType == typeof(Identifier)) + return ((Identifier)node1).Name == ((Identifier)node2).Name; + return null; + } + } +} diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs index f05be52cf..5a81449d2 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs @@ -1,4 +1,4 @@ -// +// // AstNode.cs // // Author: @@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -448,6 +448,8 @@ namespace ICSharpCode.NRefactory.CSharp { 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) { @@ -590,7 +592,7 @@ namespace ICSharpCode.NRefactory.CSharp } #endregion - public abstract S AcceptVisitor (AstVisitor visitor, T data); + public abstract S AcceptVisitor (IAstVisitor visitor, T data); // the Root role must be available when creating the null nodes, so we can't put it in the Roles class static readonly Role RootRole = new Role("Root"); diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs index b4ffdb171..2c4af725a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace ICSharpCode.NRefactory.CSharp { @@ -18,7 +18,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -28,5 +28,60 @@ namespace ICSharpCode.NRefactory.CSharp public override NodeType NodeType { get { return NodeType.TypeReference; } } + + public virtual AstType MakePointerType() + { + return new ComposedType { BaseType = this }.MakePointerType(); + } + + public virtual AstType MakeArrayType(int rank) + { + return new ComposedType { BaseType = this }.MakeArrayType(rank); + } + + /// + /// Builds an expression that can be used to access a static member on this type. + /// + public MemberReferenceExpression Member(string memberName) + { + return new TypeReferenceExpression { Type = this }.Member(memberName); + } + + public static AstType Create(Type type) + { + switch (Type.GetTypeCode(type)) { + case TypeCode.Object: + return new PrimitiveType("object"); + case TypeCode.Boolean: + return new PrimitiveType("bool"); + 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("int"); + case TypeCode.UInt32: + return new PrimitiveType("uint"); + case TypeCode.Int64: + return new PrimitiveType("long"); + case TypeCode.UInt64: + return new PrimitiveType("ulong"); + case TypeCode.Single: + return new PrimitiveType("float"); + case TypeCode.Double: + return new PrimitiveType("double"); + case TypeCode.Decimal: + return new PrimitiveType("decimal"); + case TypeCode.String: + return new PrimitiveType("string"); + } + return new SimpleType(type.FullName); // TODO: implement this correctly + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs b/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs index 54f079917..3b48cdf59 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs @@ -58,6 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp { Modifiers.Volatile, "volatile".Length }, { Modifiers.Extern, "extern".Length }, { Modifiers.Partial, "partial".Length }, + { Modifiers.Const, "const".Length }, }; public static ICollection AllModifiers { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs b/ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs index b4d3e490b..659875dec 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs @@ -1,4 +1,4 @@ -// +// // TokenNode.cs // // Author: @@ -42,7 +42,7 @@ namespace ICSharpCode.NRefactory.CSharp { } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.CSharp this.tokenLength = tokenLength; } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCSharpTokenNode (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs b/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs index 4667b09ae..3756d594b 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs @@ -1,4 +1,4 @@ -// +// // CompilationUnit.cs // // Author: @@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCompilationUnit (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs b/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs index 17b183ead..0a22debe1 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs @@ -55,12 +55,14 @@ namespace ICSharpCode.NRefactory.CSharp return GetChildrenByRole(PointerRole).Count(); } set { - // remove old children - foreach (AstNode node in GetChildrenByRole(PointerRole)) - node.Remove(); - // add new children - for (int i = 0; i < value; i++) { - AddChild(new CSharpTokenNode(AstLocation.Empty, 1), PointerRole); + int d = this.PointerRank; + while (d > value) { + GetChildByRole(PointerRole).Remove(); + d--; + } + while (d < value) { + InsertChildBefore(GetChildByRole(PointerRole), new CSharpTokenNode(AstLocation.Empty, 1), PointerRole); + d++; } } } @@ -70,7 +72,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (ArraySpecifierRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitComposedType (this, data); } @@ -89,6 +91,22 @@ namespace ICSharpCode.NRefactory.CSharp } return b.ToString(); } + + public override AstType MakePointerType() + { + if (ArraySpecifiers.Any()) { + return base.MakePointerType(); + } else { + this.PointerRank++; + return this; + } + } + + public override AstType MakeArrayType(int dimensions) + { + InsertChildBefore(this.ArraySpecifiers.FirstOrDefault(), new ArraySpecifier(dimensions), ArraySpecifierRole); + return this; + } } /// @@ -102,6 +120,19 @@ namespace ICSharpCode.NRefactory.CSharp } } + public ArraySpecifier() + { + } + + public ArraySpecifier(int dimensions) + { + this.Dimensions = dimensions; + } + + public CSharpTokenNode LBracketToken { + get { return GetChildByRole (Roles.LBracket); } + } + public int Dimensions { get { return 1 + GetChildrenByRole(Roles.Comma).Count(); } set { @@ -117,7 +148,11 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public CSharpTokenNode RBracketToken { + get { return GetChildByRole (Roles.RBracket); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitArraySpecifier(this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs b/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs index f862c80ef..e0e9615f3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs @@ -1,5 +1,5 @@ -// -// AstVisitor.cs +// +// IAstVisitor.cs // // Author: // Mike Krüger @@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp /// /// AST visitor with a default implementation that visits all node depth-first. /// - public abstract class DepthFirstAstVisitor : AstVisitor + public abstract class DepthFirstAstVisitor : IAstVisitor { protected virtual S VisitChildren (AstNode node, T data) { @@ -225,6 +225,11 @@ namespace ICSharpCode.NRefactory.CSharp return VisitChildren (continueStatement, data); } + public virtual S VisitDoWhileStatement (DoWhileStatement doWhileStatement, T data) + { + return VisitChildren (doWhileStatement, data); + } + public virtual S VisitEmptyStatement (EmptyStatement emptyStatement, T data) { return VisitChildren (emptyStatement, data); @@ -245,6 +250,16 @@ namespace ICSharpCode.NRefactory.CSharp return VisitChildren (forStatement, data); } + public virtual S VisitGotoCaseStatement (GotoCaseStatement gotoCaseStatement, T data) + { + return VisitChildren (gotoCaseStatement, data); + } + + public virtual S VisitGotoDefaultStatement (GotoDefaultStatement gotoDefaultStatement, T data) + { + return VisitChildren (gotoDefaultStatement, data); + } + public virtual S VisitGotoStatement (GotoStatement gotoStatement, T data) { return VisitChildren (gotoStatement, data); @@ -325,6 +340,11 @@ namespace ICSharpCode.NRefactory.CSharp return VisitChildren (whileStatement, data); } + public virtual S VisitYieldBreakStatement (YieldBreakStatement yieldBreakStatement, T data) + { + return VisitChildren (yieldBreakStatement, data); + } + public virtual S VisitYieldStatement (YieldStatement yieldStatement, T data) { return VisitChildren (yieldStatement, data); @@ -445,6 +465,11 @@ namespace ICSharpCode.NRefactory.CSharp return VisitChildren (typeOfExpression, data); } + public virtual S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data) + { + return VisitChildren (typeReferenceExpression, data); + } + public virtual S VisitUnaryOperatorExpression (UnaryOperatorExpression unaryOperatorExpression, T data) { return VisitChildren (unaryOperatorExpression, data); diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs index 705c87a3f..10d497eda 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs @@ -1,4 +1,4 @@ -// +// // AnonymousMethodExpression.cs // // Author: @@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Body, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitAnonymousMethodExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs index ed0093093..533bf2fb8 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs @@ -1,4 +1,4 @@ -// +// // ArgListExpression.cs // // Author: @@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitArgListExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs index 8a63d03ac..7befd673e 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; namespace ICSharpCode.NRefactory.CSharp @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (InitializerRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitArrayCreateExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs index 6ea133342..8f897048c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs @@ -1,4 +1,4 @@ -// +// // ArrayInitializerExpression.cs // // Author: @@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -64,7 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBrace); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitArrayInitializerExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs index f698b4352..9880a0f28 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs @@ -1,4 +1,4 @@ -// +// // AsExpression.cs // // Author: @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole(Roles.Type, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitAsExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs index 20dda792b..fd0ff5c3c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs @@ -1,4 +1,4 @@ -// +// // AssignmentExpression.cs // // Author: @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole(RightRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitAssignmentExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BaseReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BaseReferenceExpression.cs index d2f088e7b..ca3f5df24 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BaseReferenceExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BaseReferenceExpression.cs @@ -1,4 +1,4 @@ -// +// // BaseReferenceExpression.cs // // Author: @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitBaseReferenceExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs index 98a7a033f..0d3685721 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs @@ -1,4 +1,4 @@ -// +// // BinaryOperatorExpression.cs // // Author: @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole(RightRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitBinaryOperatorExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs index 1cf506bb5..7a737aeaa 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs @@ -1,4 +1,4 @@ -// +// // CastExpression.cs // // Author: @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCastExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs index e1eaf60ed..edb52b3f4 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs @@ -1,4 +1,4 @@ -// +// // CheckedExpression.cs // // Author: @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCheckedExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs index 6cef9c0ae..502a56676 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs @@ -1,4 +1,4 @@ -// +// // ConditionalExpression.cs // // Author: @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole(FalseRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitConditionalExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs index bce82ae2b..7fa19eea3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs @@ -1,4 +1,4 @@ -// +// // DefaultValueExpression.cs // // Author: @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitDefaultValueExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs index 8acc180e5..f815c4579 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs @@ -1,4 +1,4 @@ -// +// // DirectionExpression.cs // // Author: @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitDirectionExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs index 7a7e9790b..6a6e3d9a3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs @@ -1,4 +1,4 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// 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; @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -108,20 +108,54 @@ namespace ICSharpCode.NRefactory.CSharp }; } + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(IEnumerable arguments) + { + return new InvocationExpression { + Target = this, + Arguments = arguments + }; + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(params Expression[] arguments) + { + return Invoke(arguments.AsEnumerable()); + } + public CastExpression CastTo(AstType type) { return new CastExpression { Type = type, Expression = this }; } + public CastExpression CastTo(Type type) + { + return new CastExpression { Type = AstType.Create(type), Expression = this }; + } + public AsExpression CastAs(AstType type) { return new AsExpression { Type = type, Expression = this }; } + public AsExpression CastAs(Type type) + { + return new AsExpression { Type = AstType.Create(type), Expression = this }; + } + public IsExpression IsType(AstType type) { return new IsExpression { Type = type, Expression = this }; } + + public IsExpression IsType(Type type) + { + return new IsExpression { Type = AstType.Create(type), Expression = this }; + } #endregion } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs index cd5be6278..c56b9e564 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; // // IdentifierExpression.cs // @@ -24,6 +23,7 @@ // 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.Collections.Generic; namespace ICSharpCode.NRefactory.CSharp { @@ -38,6 +38,11 @@ namespace ICSharpCode.NRefactory.CSharp this.Identifier = identifier; } + public IdentifierExpression(string identifier, AstLocation location) + { + SetChildByRole(Roles.Identifier, new Identifier(identifier, location)); + } + // public Identifier IdentifierToken { // get { return GetChildByRole (Roles.Identifier); } // } @@ -56,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.TypeArgument, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitIdentifierExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs index 325d7daec..71a8517f3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs @@ -1,4 +1,4 @@ -// +// // IndexerExpression.cs // // Author: @@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBracket); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitIndexerExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs index 2f0a47ee1..9efe86284 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs @@ -1,4 +1,4 @@ -// +// // InvocationExpression.cs // // Author: @@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitInvocationExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IsExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IsExpression.cs index 94fc3ae57..fc325d884 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IsExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IsExpression.cs @@ -1,4 +1,4 @@ -// +// // TypeOfIsExpression.cs // // Author: @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole(Roles.Type, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitIsExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs index 766d9bc4a..06baa857c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs @@ -1,4 +1,4 @@ -// +// // LambdaExpression.cs // // Author: @@ -50,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (BodyRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitLambdaExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs index 4018ed641..c20d2ce07 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs @@ -1,4 +1,4 @@ -// +// // MemberReferenceExpression.cs // // Author: @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RChevron); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitMemberReferenceExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs index d63775e58..60152c533 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// 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; @@ -24,7 +24,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor(AstVisitor visitor, T data) + public override S AcceptVisitor(IAstVisitor visitor, T data) { return visitor.VisitNamedArgumentExpression(this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs index da1789da4..de409e297 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs @@ -1,4 +1,4 @@ -// +// // NullReferenceExpression.cs // // Author: @@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp /// public class NullReferenceExpression : Expression { - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitNullReferenceExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs index 396899f48..efccad91a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs @@ -1,4 +1,4 @@ -// +// // ObjectCreateExpression.cs // // Author: @@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (InitializerRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitObjectCreateExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs index 302ac7b38..88a561327 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs @@ -1,4 +1,4 @@ -// +// // ParenthesizedExpression.cs // // Author: @@ -26,6 +26,9 @@ namespace ICSharpCode.NRefactory.CSharp { + /// + /// ( Expression ) + /// public class ParenthesizedExpression : Expression { public CSharpTokenNode LParToken { @@ -41,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitParenthesizedExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs index 3bae45159..17bd5b72c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs @@ -1,4 +1,4 @@ -// +// // PointerReferenceExpression.cs // // Author: @@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.TypeArgument, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitPointerReferenceExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PrimitiveExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PrimitiveExpression.cs index b0001808f..427906cbd 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PrimitiveExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PrimitiveExpression.cs @@ -1,4 +1,4 @@ -// +// // PrimitiveExpression.cs // // Author: @@ -26,6 +26,9 @@ namespace ICSharpCode.NRefactory.CSharp { + /// + /// Represents a literal value. + /// public class PrimitiveExpression : Expression { AstLocation startLocation; @@ -59,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp this.length = length; } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitPrimitiveExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs index eb4e77fa4..d71be3d8d 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// 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; @@ -21,7 +21,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -33,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole(ClauseRole, value); } } - public override S AcceptVisitor(AstVisitor visitor, T data) + public override S AcceptVisitor(IAstVisitor visitor, T data) { return visitor.VisitQueryExpression (this, data); } @@ -83,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryContinuationClause (this, data); } @@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryFromClause (this, data); } @@ -143,7 +143,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole(Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryLetClause (this, data); } @@ -161,7 +161,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Condition, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryWhereClause (this, data); } @@ -246,7 +246,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryJoinClause (this, data); } @@ -265,7 +265,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (OrderingRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryOrderClause (this, data); } @@ -291,7 +291,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Keyword); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryOrdering (this, data); } @@ -315,7 +315,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQuerySelectClause (this, data); } @@ -346,7 +346,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (KeyRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitQueryGroupClause (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs index 85b1c63f1..5e5062758 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs @@ -1,4 +1,4 @@ -// +// // SizeOfExpression.cs // // Author: @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitSizeOfExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/StackAllocExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/StackAllocExpression.cs index 298b8dbb5..ddb7ede92 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/StackAllocExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/StackAllocExpression.cs @@ -1,4 +1,4 @@ -// +// // StackAllocExpression.cs // // Author: @@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBracket); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitStackAllocExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ThisReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ThisReferenceExpression.cs index a65f57a80..8c6374d29 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ThisReferenceExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ThisReferenceExpression.cs @@ -1,4 +1,4 @@ -// +// // ThisReferenceExpression.cs // // Author: @@ -26,6 +26,9 @@ namespace ICSharpCode.NRefactory.CSharp { + /// + /// this + /// public class ThisReferenceExpression : Expression { public AstLocation Location { @@ -44,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitThisReferenceExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs index 3f9b86137..c18e5f474 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs @@ -1,4 +1,4 @@ -// +// // TypeOfExpression.cs // // Author: @@ -27,6 +27,9 @@ namespace ICSharpCode.NRefactory.CSharp { + /// + /// typeof(Type) + /// public class TypeOfExpression : Expression { public CSharpTokenNode TypeOfToken { @@ -46,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitTypeOfExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs new file mode 100644 index 000000000..910bf69f9 --- /dev/null +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs @@ -0,0 +1,24 @@ +// 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 +{ + /// + /// Represents an AstType as an expression. + /// This is used when calling a method on a primitive type: "int.Parse()" + /// + public class TypeReferenceExpression : Expression + { + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitTypeReferenceExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs index ae5a12338..df36a6ab9 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs @@ -1,4 +1,4 @@ -// +// // UnaryOperatorExpression.cs // // Author: @@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitUnaryOperatorExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs index e207a597a..fd1c162dc 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs @@ -1,4 +1,4 @@ -// +// // UncheckedExpression.cs // // Author: @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitUncheckedExpression (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs index 22e73b4b3..162a4e33b 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs @@ -1,4 +1,4 @@ -// +// // Attribute.cs // // Author: @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.Argument, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitAttribute (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs index f938da10b..35d170dda 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs @@ -1,4 +1,4 @@ -// +// // AttributeSection.cs // // Author: @@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (AttributeRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitAttributeSection (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Comment.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Comment.cs index a8121468b..dc27a875a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Comment.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Comment.cs @@ -1,4 +1,4 @@ -// +// // Comment.cs // // Author: @@ -69,6 +69,12 @@ namespace ICSharpCode.NRefactory.CSharp } } + public Comment (string content, CommentType type = CommentType.SingleLine) + { + this.CommentType = type; + this.Content = content; + } + public Comment (CommentType commentType, AstLocation startLocation, AstLocation endLocation) { this.CommentType = commentType; @@ -76,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp this.endLocation = endLocation; } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitComment (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs index d24f9fa81..dae8d4e19 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs @@ -1,4 +1,4 @@ -// +// // Constraint.cs // // Author: @@ -58,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (BaseTypeRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitConstraint (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs index 4d336e856..1b71cd4c6 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs @@ -1,4 +1,4 @@ -// +// // DelegateDeclaration.cs // // Author: @@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.Constraint, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitDelegateDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs index 91f5ab304..f082150b6 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs @@ -1,4 +1,4 @@ -// +// // NamespaceDeclaration.cs // // Author: @@ -98,7 +98,7 @@ namespace ICSharpCode.NRefactory.CSharp } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitNamespaceDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs index cd3894acc..36381aafd 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs @@ -1,4 +1,4 @@ -// +// // TypeDeclaration.cs // // Author: @@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBrace); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitTypeDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs index 9145aef69..c089f360d 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs @@ -1,4 +1,4 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// 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; @@ -34,7 +34,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor(AstVisitor visitor, T data) + public override S AcceptVisitor(IAstVisitor visitor, T data) { return visitor.VisitTypeParameterDeclaration(this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs index 163e484b9..044537396 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs @@ -1,4 +1,4 @@ -// +// // UsingAliasDeclaration.cs // // Author: @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitUsingAliasDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs index 0a63cc97c..68ff822b3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs @@ -1,4 +1,4 @@ -// +// // UsingDeclaration.cs // // Author: @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitUsingDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs b/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs index e61922a88..f388f856c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs @@ -8,7 +8,7 @@ namespace ICSharpCode.NRefactory.CSharp /// /// AST visitor. /// - public interface AstVisitor + public interface IAstVisitor { S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data); S VisitArgListExpression(ArgListExpression argListExpression, T data); @@ -39,6 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp S VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data); S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data); S VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data); + S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data); S VisitUncheckedExpression(UncheckedExpression uncheckedExpression, T data); @@ -65,11 +66,14 @@ namespace ICSharpCode.NRefactory.CSharp S VisitBreakStatement(BreakStatement breakStatement, T data); S VisitCheckedStatement(CheckedStatement checkedStatement, T data); S VisitContinueStatement(ContinueStatement continueStatement, T data); + S VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data); S VisitEmptyStatement(EmptyStatement emptyStatement, T data); S VisitExpressionStatement(ExpressionStatement expressionStatement, T data); S VisitFixedStatement(FixedStatement fixedStatement, T data); S VisitForeachStatement(ForeachStatement foreachStatement, T data); S VisitForStatement(ForStatement forStatement, T data); + S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data); + S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, T data); S VisitGotoStatement(GotoStatement gotoStatement, T data); S VisitIfElseStatement(IfElseStatement ifElseStatement, T data); S VisitLabelStatement(LabelStatement labelStatement, T data); @@ -86,6 +90,7 @@ namespace ICSharpCode.NRefactory.CSharp S VisitUsingStatement(UsingStatement usingStatement, T data); S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data); S VisitWhileStatement(WhileStatement whileStatement, T data); + S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data); S VisitYieldStatement(YieldStatement yieldStatement, T data); S VisitAccessor(Accessor accessor, T data); diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs b/ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs index d19c3a4dd..94656e5ab 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs @@ -1,4 +1,4 @@ -// +// // Identifier.cs // // Author: @@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp this.startLocation = location; } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitIdentifier (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs b/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs index e188c9db4..8d600b575 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs @@ -1,4 +1,4 @@ -// +// // FullTypeName.cs // // Author: @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.TypeArgument, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitMemberType (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs b/ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs index 19f2e595f..6bc7d0f73 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs @@ -1,4 +1,4 @@ -// +// // FullTypeName.cs // // Author: @@ -43,6 +43,12 @@ namespace ICSharpCode.NRefactory.CSharp this.Keyword = keyword; } + public PrimitiveType(string keyword, AstLocation location) + { + this.Keyword = keyword; + this.Location = location; + } + public override AstLocation StartLocation { get { return Location; @@ -50,11 +56,11 @@ namespace ICSharpCode.NRefactory.CSharp } public override AstLocation EndLocation { get { - return new AstLocation (Location.Line, Location.Column + Keyword != null ? Keyword.Length : 0); + return new AstLocation (Location.Line, Location.Column + (Keyword != null ? Keyword.Length : 0)); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitPrimitiveType (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs b/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs index 2111ea533..ac3eb0210 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs @@ -1,4 +1,4 @@ -// +// // FullTypeName.cs // // Author: @@ -42,6 +42,11 @@ namespace ICSharpCode.NRefactory.CSharp 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; @@ -56,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.TypeArgument, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitSimpleType (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs index 014971253..eb3a6f9a3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs @@ -1,4 +1,4 @@ -// +// // BlockStatement.cs // // Author: @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBrace); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitBlockStatement (this, data); } @@ -81,6 +81,12 @@ namespace ICSharpCode.NRefactory.CSharp AddChild(new ExpressionStatement { Expression = expression }, StatementRole); } + public void AddStatements(IEnumerable statements) + { + foreach (Statement st in statements) + AddChild(st, StatementRole); + } + public void AddAssignment(Expression left, Expression right) { AddStatement(new AssignmentExpression { Left = left, Operator = AssignmentOperatorType.Assign, Right = right }); diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/BreakStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/BreakStatement.cs index 8fe8d5da4..b6ce929b0 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/BreakStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/BreakStatement.cs @@ -1,4 +1,4 @@ -// +// // BreakStatement.cs // // Author: @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitBreakStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs index f274dd051..1461a6407 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs @@ -1,4 +1,4 @@ -// +// // CheckedStatement.cs // // Author: @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Body, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCheckedStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ContinueStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ContinueStatement.cs index 0aaf85386..7dc06c596 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ContinueStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ContinueStatement.cs @@ -1,4 +1,4 @@ -// +// // ContinueStatement.cs // // Author: @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitContinueStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs new file mode 100644 index 000000000..51d5f4708 --- /dev/null +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs @@ -0,0 +1,73 @@ +// +// DoWhileStatement.cs +// +// Author: +// Mike Krüger +// +// Copyright (c) 2011 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.CSharp +{ + /// + /// "do EmbeddedStatement while(Condition);" + /// + public class DoWhileStatement : Statement + { + public static readonly Role DoKeywordRole = new Role("DoKeyword", CSharpTokenNode.Null); + public static readonly Role WhileKeywordRole = new Role("WhileKeyword", CSharpTokenNode.Null); + + public CSharpTokenNode DoToken { + get { return GetChildByRole (DoKeywordRole); } + } + + public Statement EmbeddedStatement { + get { return GetChildByRole (Roles.EmbeddedStatement); } + set { SetChildByRole (Roles.EmbeddedStatement, value); } + } + + public CSharpTokenNode WhileToken { + get { return GetChildByRole (WhileKeywordRole); } + } + + public CSharpTokenNode LParToken { + get { return GetChildByRole (Roles.LPar); } + } + + public Expression Condition { + get { return GetChildByRole (Roles.Condition); } + set { SetChildByRole (Roles.Condition, value); } + } + + public CSharpTokenNode RParToken { + get { return GetChildByRole (Roles.RPar); } + } + + public CSharpTokenNode SemicolonToken { + get { return GetChildByRole (Roles.Semicolon); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitDoWhileStatement (this, data); + } + } +} + diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/EmptyStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/EmptyStatement.cs index 820a940fe..7a9528b86 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/EmptyStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/EmptyStatement.cs @@ -1,4 +1,4 @@ -// +// // EmptyStatement.cs // // Author: @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitEmptyStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ExpressionStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ExpressionStatement.cs index 68e4f36d3..5c6cd41d7 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ExpressionStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ExpressionStatement.cs @@ -1,4 +1,4 @@ -// +// // ExpressionStatement.cs // // Author: @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitExpressionStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs index 685d07a7d..5d44b66e0 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs @@ -1,4 +1,4 @@ -// +// // FixedStatement.cs // // Author: @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.EmbeddedStatement, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitFixedStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs index 8a5ef8403..c667e6086 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs @@ -1,4 +1,4 @@ -// +// // ForStatement.cs // // Author: @@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.EmbeddedStatement, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitForStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForeachStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForeachStatement.cs index d5cad0f32..ca75d6d0d 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForeachStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForeachStatement.cs @@ -1,4 +1,4 @@ -// +// // ForeachStatement.cs // // Author: @@ -71,7 +71,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.EmbeddedStatement, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitForeachStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/GotoStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/GotoStatement.cs index 1cfc9a95b..ee1784ad7 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/GotoStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/GotoStatement.cs @@ -28,17 +28,16 @@ namespace ICSharpCode.NRefactory.CSharp { /// /// "goto Label;" - /// or "goto case LabelExpression;" - /// or "goto default;" /// public class GotoStatement : Statement { - public static readonly Role DefaultKeywordRole = new Role("DefaultKeyword", CSharpTokenNode.Null); - public static readonly Role CaseKeywordRole = new Role("CaseKeyword", CSharpTokenNode.Null); + public GotoStatement () + { + } - public GotoType GotoType { - get; - set; + public GotoStatement (string label) + { + this.Label = label; } public CSharpTokenNode GotoToken { @@ -69,20 +68,79 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitGotoStatement (this, data); } + } + + /// + /// or "goto case LabelExpression;" + /// + public class GotoCaseStatement : Statement + { + public static readonly Role CaseKeywordRole = new Role("CaseKeyword", CSharpTokenNode.Null); + + public CSharpTokenNode GotoToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public CSharpTokenNode CaseToken { + get { return GetChildByRole (CaseKeywordRole); } + } + + public string Label { + get { + return GetChildByRole (Roles.Identifier).Name; + } + set { + if (string.IsNullOrEmpty(value)) + SetChildByRole(Roles.Identifier, null); + else + SetChildByRole(Roles.Identifier, new Identifier(value, AstLocation.Empty)); + } + } + + /// + /// Used for "goto case LabelExpression;" + /// + public Expression LabelExpression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public CSharpTokenNode SemicolonToken { + get { return GetChildByRole (Roles.Semicolon); } + } - public GotoStatement (GotoType gotoType) + public override S AcceptVisitor (IAstVisitor visitor, T data) { - this.GotoType = gotoType; + return visitor.VisitGotoCaseStatement (this, data); } } - public enum GotoType { - Label, - Case, - CaseDefault + /// + /// or "goto default;" + /// + public class GotoDefaultStatement : Statement + { + public static readonly Role DefaultKeywordRole = new Role("DefaultKeyword", CSharpTokenNode.Null); + + public CSharpTokenNode GotoToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public CSharpTokenNode DefaultToken { + get { return GetChildByRole (DefaultKeywordRole); } + } + + public CSharpTokenNode SemicolonToken { + get { return GetChildByRole (Roles.Semicolon); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitGotoDefaultStatement (this, data); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/IfElseStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/IfElseStatement.cs index 62f294f07..85569dfac 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/IfElseStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/IfElseStatement.cs @@ -1,4 +1,4 @@ -// +// // IfElseStatement.cs // // Author: @@ -69,9 +69,20 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (FalseRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitIfElseStatement (this, data); } + + public IfElseStatement() + { + } + + public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement = null) + { + this.Condition = condition; + this.TrueStatement = trueStatement; + this.FalseStatement = falseStatement; + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/LabelStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/LabelStatement.cs index e1b973f09..da9dc5273 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/LabelStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/LabelStatement.cs @@ -1,4 +1,4 @@ -// +// // LabelStatement.cs // // Author: @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitLabelStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/LockStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/LockStatement.cs index ffa17e7f3..3866dbd17 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/LockStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/LockStatement.cs @@ -1,4 +1,4 @@ -// +// // LockStatement.cs // // Author: @@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.EmbeddedStatement, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitLockStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs index d3db45e4e..938fcb679 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs @@ -1,4 +1,4 @@ -// +// // ReturnStatement.cs // // Author: @@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitReturnStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs index ac6bb7c7f..c3341e2c5 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs @@ -1,4 +1,4 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// 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; @@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs index b7f2cf90c..99fb7009b 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs @@ -1,4 +1,4 @@ -// +// // SwitchStatement.cs // // Author: @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBrace); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitSwitchStatement (this, data); } @@ -92,7 +92,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.EmbeddedStatement, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitSwitchSection (this, data); } @@ -111,7 +111,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCaseLabel (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs index 5b6141cd5..545dc6ac3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs @@ -1,4 +1,4 @@ -// +// // ThrowStatement.cs // // Author: @@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitThrowStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs index b9e540c3f..70f48dd29 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs @@ -1,4 +1,4 @@ -// +// // TryCatchStatement.cs // // Author: @@ -30,7 +30,7 @@ using System.Linq; namespace ICSharpCode.NRefactory.CSharp { /// - /// try { TryBlock } CatchClauses finally { FinallyBlock } + /// try TryBlock CatchClauses finally FinallyBlock /// public class TryCatchStatement : Statement { @@ -40,6 +40,10 @@ namespace ICSharpCode.NRefactory.CSharp public static readonly Role FinallyKeywordRole = new Role("FinallyKeyword", CSharpTokenNode.Null); public static readonly Role FinallyBlockRole = new Role("FinallyBlock", BlockStatement.Null); + public CSharpTokenNode TryToken { + get { return GetChildByRole (TryKeywordRole); } + } + public BlockStatement TryBlock { get { return GetChildByRole (TryBlockRole); } set { SetChildByRole (TryBlockRole, value); } @@ -50,12 +54,16 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (CatchClauseRole, value); } } + public CSharpTokenNode FinallyToken { + get { return GetChildByRole (FinallyKeywordRole); } + } + public BlockStatement FinallyBlock { get { return GetChildByRole (FinallyBlockRole); } set { SetChildByRole (FinallyBlockRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitTryCatchStatement (this, data); } @@ -72,6 +80,14 @@ namespace ICSharpCode.NRefactory.CSharp } } + public CSharpTokenNode CatchToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public CSharpTokenNode LParToken { + get { return GetChildByRole (Roles.LPar); } + } + public AstType Type { get { return GetChildByRole (Roles.Type); } set { SetChildByRole (Roles.Type, value); } @@ -87,12 +103,16 @@ namespace ICSharpCode.NRefactory.CSharp } } + public CSharpTokenNode RParToken { + get { return GetChildByRole (Roles.RPar); } + } + public BlockStatement Body { get { return GetChildByRole (Roles.Body); } set { SetChildByRole (Roles.Body, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCatchClause (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs index ddb38cd0b..ec55c0cbc 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs @@ -1,4 +1,4 @@ -// +// // UncheckedStatement.cs // // Author: @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Body, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitUncheckedStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/UnsafeStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/UnsafeStatement.cs index e7898ef57..d9a45a860 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/UnsafeStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/UnsafeStatement.cs @@ -1,4 +1,4 @@ -// +// // UnsafeStatement.cs // // Author: @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Body, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitUnsafeStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/UsingStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/UsingStatement.cs index 0a0623aec..d69487563 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/UsingStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/UsingStatement.cs @@ -1,4 +1,4 @@ -// +// // UsingStatement.cs // // Author: @@ -58,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.EmbeddedStatement, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitUsingStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs index 5aa0ad3ad..7be7b5a33 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs @@ -1,4 +1,4 @@ -// +// // VariableDeclarationStatement.cs // // Author: @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitVariableDeclarationStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs index 2e78196d7..9eec22b2f 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs @@ -1,4 +1,4 @@ -// +// // WhileStatement.cs // // Author: @@ -28,22 +28,11 @@ namespace ICSharpCode.NRefactory.CSharp { /// /// "while (Condition) EmbeddedStatement" - /// or "do EmbeddedStatement while(Condition);" /// public class WhileStatement : Statement { - public static readonly Role DoKeywordRole = new Role("DoKeyword", CSharpTokenNode.Null); public static readonly Role WhileKeywordRole = new Role("WhileKeyword", CSharpTokenNode.Null); - public WhilePosition WhilePosition { - get; - set; - } - - public CSharpTokenNode DoToken { - get { return GetChildByRole (DoKeywordRole); } - } - public CSharpTokenNode WhileToken { get { return GetChildByRole (WhileKeywordRole); } } @@ -66,19 +55,9 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.EmbeddedStatement, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitWhileStatement (this, data); } - - public WhileStatement (WhilePosition whilePosition) - { - this.WhilePosition = whilePosition; - } - } - - public enum WhilePosition { - Begin, - End } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs new file mode 100644 index 000000000..2982dbf41 --- /dev/null +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs @@ -0,0 +1,54 @@ +// +// YieldBreakStatement.cs +// +// Author: +// Mike Krüger +// +// Copyright (c) 2011 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. + +namespace ICSharpCode.NRefactory.CSharp +{ + /// + /// yield break; + /// + public class YieldBreakStatement : Statement + { + public static readonly Role YieldKeywordRole = new Role("YieldKeyword", CSharpTokenNode.Null); + public static readonly Role BreakKeywordRole = new Role("BreakKeyword", CSharpTokenNode.Null); + + public CSharpTokenNode YieldToken { + get { return GetChildByRole (YieldKeywordRole); } + } + + public CSharpTokenNode BreakToken { + get { return GetChildByRole (BreakKeywordRole); } + } + + public CSharpTokenNode SemicolonToken { + get { return GetChildByRole (Roles.Semicolon); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitYieldBreakStatement (this, data); + } + } +} diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs index 9f3403947..531d21ec5 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs @@ -1,4 +1,4 @@ -// +// // YieldStatement.cs // // Author: @@ -26,11 +26,13 @@ namespace ICSharpCode.NRefactory.CSharp { + /// + /// yield return Expression; + /// public class YieldStatement : Statement { public static readonly Role YieldKeywordRole = new Role("YieldKeyword", CSharpTokenNode.Null); public static readonly Role ReturnKeywordRole = new Role("ReturnKeyword", CSharpTokenNode.Null); - public static readonly Role BreakKeywordRole = new Role("BreakKeyword", CSharpTokenNode.Null); public CSharpTokenNode YieldToken { get { return GetChildByRole (YieldKeywordRole); } @@ -40,10 +42,6 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (ReturnKeywordRole); } } - public CSharpTokenNode BreakToken { - get { return GetChildByRole (BreakKeywordRole); } - } - public Expression Expression { get { return GetChildByRole (Roles.Expression); } set { SetChildByRole (Roles.Expression, value); } @@ -53,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Semicolon); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitYieldStatement (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs index 001c4f3b3..05eec5e0f 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs @@ -1,4 +1,4 @@ -// +// // PropertyDeclaration.cs // // Author: @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Body, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitAccessor (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs index addfc9e2f..1097605c3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs @@ -1,4 +1,4 @@ -// +// // ConstructorDeclaration.cs // // Author: @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return NodeType.Member; } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitConstructorDeclaration (this, data); } @@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } @@ -110,7 +110,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.Argument, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitConstructorInitializer (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs index 68a15599a..2336d46d2 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs @@ -1,4 +1,4 @@ -// +// // DestructorDeclaration.cs // // Author: @@ -50,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return NodeType.Member; } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitDestructorDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs index f724f73ea..0715898f0 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs @@ -1,4 +1,4 @@ -// +// // EnumMemberDeclaration.cs // // Author: @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return NodeType.Member; } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitEnumMemberDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs index 7c469e1c7..dde192663 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs @@ -1,4 +1,4 @@ -// +// // EventDeclaration.cs // // Author: @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.Variable, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitEventDeclaration (this, data); } @@ -46,6 +46,10 @@ namespace ICSharpCode.NRefactory.CSharp public static readonly Role AddAccessorRole = new Role("AddAccessor", Accessor.Null); public static readonly Role RemoveAccessorRole = new Role("RemoveAccessor", Accessor.Null); + public CSharpTokenNode LBraceToken { + get { return GetChildByRole (Roles.LBrace); } + } + public Accessor AddAccessor { get { return GetChildByRole (AddAccessorRole); } set { SetChildByRole (AddAccessorRole, value); } @@ -56,7 +60,11 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (RemoveAccessorRole, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public CSharpTokenNode RBraceToken { + get { return GetChildByRole (Roles.RBrace); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitCustomEventDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs index 8604023d0..8969d50b0 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs @@ -1,4 +1,4 @@ -// +// // FieldDeclaration.cs // // Author: @@ -36,7 +36,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildrenByRole (Roles.Variable, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitFieldDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs index da5fa0f75..88d80ce50 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs @@ -1,4 +1,4 @@ -// +// // IndexerDeclaration.cs // // Author: @@ -31,12 +31,20 @@ namespace ICSharpCode.NRefactory.CSharp { public class IndexerDeclaration : PropertyDeclaration { + public CSharpTokenNode LBracketToken { + get { return GetChildByRole (Roles.LBracket); } + } + public IEnumerable Parameters { get { return GetChildrenByRole (Roles.Parameter); } set { SetChildrenByRole (Roles.Parameter, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public CSharpTokenNode RBracketToken { + get { return GetChildByRole (Roles.RBracket); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitIndexerDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs index eefa201c9..84ff90819 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs @@ -1,4 +1,4 @@ -// +// // MethodDeclaration.cs // // Author: @@ -66,8 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitMethodDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs index a7a82269d..4b3a1693b 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs @@ -1,4 +1,4 @@ -// +// // OperatorDeclaration.cs // // Author: @@ -104,7 +104,7 @@ namespace ICSharpCode.NRefactory.CSharp return Mono.CSharp.Operator.GetName((Mono.CSharp.Operator.OpType)type); } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitOperatorDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs index 2b909551c..21c1f644e 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs @@ -1,4 +1,4 @@ -// +// // ParameterDeclarationExpression.cs // // Author: @@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitParameterDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs index 0eb035d9a..d13ce8f5c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs @@ -1,4 +1,4 @@ -// +// // PropertyDeclaration.cs // // Author: @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBrace); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitPropertyDeclaration (this, data); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs index 8bec1f6a6..745a03b7d 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs @@ -1,4 +1,4 @@ -// +// // VariableInitializer.cs // // Author: @@ -33,6 +33,16 @@ namespace ICSharpCode.NRefactory.CSharp return NodeType.Unknown; } } + + public VariableInitializer() + { + } + + public VariableInitializer(string name, Expression initializer = null) + { + this.Name = name; + this.Initializer = initializer; + } public string Name { get { @@ -52,10 +62,9 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Expression, value); } } - public override S AcceptVisitor (AstVisitor visitor, T data) + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitVariableInitializer (this, data); } - } } diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/IOutputFormatter.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/IOutputFormatter.cs index 3aff02b5f..ac1966296 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/IOutputFormatter.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/IOutputFormatter.cs @@ -10,6 +10,9 @@ namespace ICSharpCode.NRefactory.CSharp /// public interface IOutputFormatter { + void StartNode(AstNode node); + void EndNode(AstNode node); + /// /// Writes an identifier. /// If the identifier conflicts with a keyword, the output visitor will diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index c6e6605b2..bcdbd894d 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// 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; @@ -15,7 +15,7 @@ namespace ICSharpCode.NRefactory.CSharp /// /// Outputs the AST. /// - public class OutputVisitor : AstVisitor + public class OutputVisitor : IAstVisitor { readonly IOutputFormatter formatter; readonly CSharpFormattingPolicy policy; @@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp KeywordOrIdentifier, Plus, Minus, + Ampersand, QuestionMark, Division } @@ -67,6 +68,7 @@ namespace ICSharpCode.NRefactory.CSharp WriteSpecialsUpToNode(node); currentContainerNode = node; positionStack.Push(node.FirstChild); + formatter.StartNode(node); } object EndNode(AstNode node) @@ -76,6 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp Debug.Assert(pos == null || pos.Parent == node); WriteSpecials(pos, null); currentContainerNode = node.Parent; + formatter.EndNode(node); return null; } #endregion @@ -203,9 +206,11 @@ namespace ICSharpCode.NRefactory.CSharp { WriteSpecialsUpToRole(identifierRole ?? AstNode.Roles.Identifier); if (IsKeyword(identifier, currentContainerNode)) { + if (lastWritten == LastWritten.KeywordOrIdentifier) + Space(); // this space is not strictly required, so we call Space() formatter.WriteToken("@"); } else if (lastWritten == LastWritten.KeywordOrIdentifier) { - formatter.Space(); + formatter.Space(); // this space is strictly required, so we directly call the formatter } formatter.WriteIdentifier(identifier); lastWritten = LastWritten.KeywordOrIdentifier; @@ -217,10 +222,12 @@ namespace ICSharpCode.NRefactory.CSharp // Avoid that two +, - or ? tokens are combined into a ++, -- or ?? token. // Note that we don't need to handle tokens like = because there's no valid // C# program that contains the single token twice in a row. - // (for + and -, this can happen with unary operators; - // and for ?, this can happen in "a is int? ? b : c" or "a as int? ?? 0") + // (for +, - and &, this can happen with unary operators; + // for ?, this can happen in "a is int? ? b : c" or "a as int? ?? 0"; + // and for /, this can happen with "1/ *ptr" or "1/ //comment".) if (lastWritten == LastWritten.Plus && token[0] == '+' || lastWritten == LastWritten.Minus && token[0] == '-' + || lastWritten == LastWritten.Ampersand && token[0] == '&' || lastWritten == LastWritten.QuestionMark && token[0] == '?' || lastWritten == LastWritten.Division && token[0] == '*') { @@ -231,6 +238,8 @@ namespace ICSharpCode.NRefactory.CSharp lastWritten = LastWritten.Plus; else if (token == "-") lastWritten = LastWritten.Minus; + else if (token == "&") + lastWritten = LastWritten.Ampersand; else if (token == "?") lastWritten = LastWritten.QuestionMark; else if (token == "/") @@ -893,6 +902,13 @@ namespace ICSharpCode.NRefactory.CSharp return EndNode(typeOfExpression); } + public object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) + { + StartNode(typeReferenceExpression); + typeReferenceExpression.Type.AcceptVisitor(this, data); + return EndNode(typeReferenceExpression); + } + public object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { StartNode(unaryOperatorExpression); @@ -1088,6 +1104,7 @@ namespace ICSharpCode.NRefactory.CSharp WriteModifiers(delegateDeclaration.ModifierTokens); WriteKeyword("delegate"); delegateDeclaration.ReturnType.AcceptVisitor(this, data); + Space(); WriteIdentifier(delegateDeclaration.Name); WriteTypeParameters(delegateDeclaration.TypeParameters); Space(policy.BeforeDelegateDeclarationParentheses); @@ -1148,8 +1165,22 @@ namespace ICSharpCode.NRefactory.CSharp constraint.AcceptVisitor(this, data); } OpenBrace(braceStyle); - foreach (var member in typeDeclaration.Members) { - member.AcceptVisitor(this, data); + if (typeDeclaration.ClassType == ClassType.Enum) { + bool first = true; + foreach (var member in typeDeclaration.Members) { + if (first) { + first = false; + } else { + Comma(member); + NewLine(); + } + member.AcceptVisitor(this, data); + } + NewLine(); + } else { + foreach (var member in typeDeclaration.Members) { + member.AcceptVisitor(this, data); + } } CloseBrace(braceStyle); NewLine(); @@ -1239,6 +1270,22 @@ namespace ICSharpCode.NRefactory.CSharp return EndNode(continueStatement); } + public object VisitDoWhileStatement(DoWhileStatement doWhileStatement, object data) + { + StartNode(doWhileStatement); + WriteKeyword("do", DoWhileStatement.DoKeywordRole); + WriteEmbeddedStatement(doWhileStatement.EmbeddedStatement); + WriteKeyword("while", DoWhileStatement.WhileKeywordRole); + Space(policy.WhileParentheses); + LPar(); + Space(policy.WithinWhileParentheses); + doWhileStatement.Condition.AcceptVisitor(this, data); + Space(policy.WithinWhileParentheses); + RPar(); + Semicolon(); + return EndNode(doWhileStatement); + } + public object VisitEmptyStatement(EmptyStatement emptyStatement, object data) { StartNode(emptyStatement); @@ -1274,6 +1321,7 @@ namespace ICSharpCode.NRefactory.CSharp LPar(); Space(policy.WithinForEachParentheses); foreachStatement.VariableType.AcceptVisitor(this, data); + Space(); WriteIdentifier(foreachStatement.VariableName); WriteKeyword("in", ForeachStatement.Roles.InKeyword); Space(); @@ -1306,25 +1354,31 @@ namespace ICSharpCode.NRefactory.CSharp return EndNode(forStatement); } + public object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) + { + StartNode(gotoCaseStatement); + WriteKeyword("goto"); + WriteKeyword("case", GotoCaseStatement.CaseKeywordRole); + Space(); + gotoCaseStatement.LabelExpression.AcceptVisitor(this, data); + Semicolon(); + return EndNode(gotoCaseStatement); + } + + public object VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, object data) + { + StartNode(gotoDefaultStatement); + WriteKeyword("goto"); + WriteKeyword("default", GotoDefaultStatement.DefaultKeywordRole); + Semicolon(); + return EndNode(gotoDefaultStatement); + } + public object VisitGotoStatement(GotoStatement gotoStatement, object data) { StartNode(gotoStatement); WriteKeyword("goto"); - switch (gotoStatement.GotoType) { - case GotoType.Label: - WriteIdentifier(gotoStatement.Label); - break; - case GotoType.Case: - WriteKeyword("case", GotoStatement.CaseKeywordRole); - Space(); - gotoStatement.LabelExpression.AcceptVisitor(this, data); - break; - case GotoType.CaseDefault: - WriteKeyword("default", GotoStatement.DefaultKeywordRole); - break; - default: - throw new NotSupportedException("Invalid value for GotoType"); - } + WriteIdentifier(gotoStatement.Label); Semicolon(); return EndNode(gotoStatement); } @@ -1512,11 +1566,6 @@ namespace ICSharpCode.NRefactory.CSharp public object VisitWhileStatement(WhileStatement whileStatement, object data) { StartNode(whileStatement); - if (whileStatement.WhilePosition == WhilePosition.End) { - // do .. while - WriteKeyword("do", WhileStatement.DoKeywordRole); - WriteEmbeddedStatement(whileStatement.EmbeddedStatement); - } WriteKeyword("while", WhileStatement.WhileKeywordRole); Space(policy.WhileParentheses); LPar(); @@ -1524,25 +1573,26 @@ namespace ICSharpCode.NRefactory.CSharp whileStatement.Condition.AcceptVisitor(this, data); Space(policy.WithinWhileParentheses); RPar(); - if (whileStatement.WhilePosition == WhilePosition.Begin) { - WriteEmbeddedStatement(whileStatement.EmbeddedStatement); - } else { - Semicolon(); - } + WriteEmbeddedStatement(whileStatement.EmbeddedStatement); return EndNode(whileStatement); } + public object VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, object data) + { + StartNode(yieldBreakStatement); + WriteKeyword("yield", YieldBreakStatement.YieldKeywordRole); + WriteKeyword("break", YieldBreakStatement.BreakKeywordRole); + Semicolon(); + return EndNode(yieldBreakStatement); + } + public object VisitYieldStatement(YieldStatement yieldStatement, object data) { StartNode(yieldStatement); WriteKeyword("yield", YieldStatement.YieldKeywordRole); - if (yieldStatement.Expression.IsNull) { - WriteKeyword("break", YieldStatement.BreakKeywordRole); - } else { - WriteKeyword("return", YieldStatement.ReturnKeywordRole); - Space(); - yieldStatement.Expression.AcceptVisitor(this, data); - } + WriteKeyword("return", YieldStatement.ReturnKeywordRole); + Space(); + yieldStatement.Expression.AcceptVisitor(this, data); Semicolon(); return EndNode(yieldStatement); } @@ -1658,6 +1708,7 @@ namespace ICSharpCode.NRefactory.CSharp } } CloseBrace(policy.EventBraceStyle); + NewLine(); return EndNode(customEventDeclaration); } @@ -1690,6 +1741,7 @@ namespace ICSharpCode.NRefactory.CSharp } } CloseBrace(policy.PropertyBraceStyle); + NewLine(); return EndNode(indexerDeclaration); } @@ -1699,6 +1751,7 @@ namespace ICSharpCode.NRefactory.CSharp WriteAttributes(methodDeclaration.Attributes); WriteModifiers(methodDeclaration.ModifierTokens); methodDeclaration.ReturnType.AcceptVisitor(this, data); + Space(); WritePrivateImplementationType(methodDeclaration.PrivateImplementationType); WriteIdentifier(methodDeclaration.Name); WriteTypeParameters(methodDeclaration.TypeParameters); @@ -1776,6 +1829,7 @@ namespace ICSharpCode.NRefactory.CSharp WriteAttributes(propertyDeclaration.Attributes); WriteModifiers(propertyDeclaration.ModifierTokens); propertyDeclaration.ReturnType.AcceptVisitor(this, data); + Space(); WritePrivateImplementationType(propertyDeclaration.PrivateImplementationType); WriteIdentifier(propertyDeclaration.Name); OpenBrace(policy.PropertyBraceStyle); @@ -1786,6 +1840,7 @@ namespace ICSharpCode.NRefactory.CSharp } } CloseBrace(policy.PropertyBraceStyle); + NewLine(); return EndNode(propertyDeclaration); } #endregion diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/TextWriterOutputFormatter.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/TextWriterOutputFormatter.cs index e14d1032c..f8c1340e5 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/TextWriterOutputFormatter.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/TextWriterOutputFormatter.cs @@ -107,5 +107,13 @@ namespace ICSharpCode.NRefactory.CSharp break; } } + + public virtual void StartNode(AstNode node) + { + } + + public virtual void EndNode(AstNode node) + { + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs index ee69f7164..a8cc6acac 100644 --- a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs @@ -67,6 +67,72 @@ namespace ICSharpCode.NRefactory.CSharp #region Global Stack namespaceStack = new Stack (); + void AddTypeArguments (ATypeNameExpression texpr, AstType result) + { + if (!texpr.HasTypeArguments) + return; + foreach (var arg in texpr.TypeArguments.Args) { + result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument); + } + } + + AstType ConvertToType (Mono.CSharp.Expression typeName) + { + if (typeName is TypeExpression) { + var typeExpr = (Mono.CSharp.TypeExpression)typeName; + return new PrimitiveType (typeExpr.GetSignatureForError (), Convert (typeExpr.Location)); + } + + if (typeName is Mono.CSharp.QualifiedAliasMember) { + var qam = (Mono.CSharp.QualifiedAliasMember)typeName; + return new SimpleType (qam.Name, Convert (qam.Location)); + } + + if (typeName is MemberAccess) { + MemberAccess ma = (MemberAccess)typeName; + + var memberType = new MemberType (); + memberType.AddChild (ConvertToType (ma.LeftExpression), MemberType.TargetRole); + memberType.MemberName = ma.Name; + + AddTypeArguments (ma, memberType); + return memberType; + } + + if (typeName is SimpleName) { + var sn = (SimpleName)typeName; + var result = new SimpleType (sn.Name, Convert (sn.Location)); + AddTypeArguments (sn, result); + return result; + } + + if (typeName is ComposedCast) { + var cc = (ComposedCast)typeName; + var baseType = ConvertToType (cc.Left); + var result = new ComposedType () { BaseType = baseType }; + + if (cc.Spec.IsNullable) { + result.HasNullableSpecifier = true; + } else if (cc.Spec.IsPointer) { + result.PointerRank++; + } else { + var location = LocationsBag.GetLocations (cc.Spec); + var spec = new ArraySpecifier () { Dimensions = cc.Spec.Dimension - 1 }; + spec.AddChild (new CSharpTokenNode (Convert (cc.Spec.Location), 1), FieldDeclaration.Roles.LBracket); + if (location != null) + spec.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FieldDeclaration.Roles.RBracket); + + result.ArraySpecifiers = new ArraySpecifier[] { + spec + }; + } + return result; + } + + System.Console.WriteLine ("Error while converting :" + typeName + " - unknown type name"); + return new SimpleType ("unknown"); + } + public override void Visit (UsingsBag.Namespace nspace) { NamespaceDeclaration nDecl = null; @@ -242,7 +308,7 @@ namespace ICSharpCode.NRefactory.CSharp AddModifiers (newDelegate, location); if (location != null) newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword); - newDelegate.AddChild ((AstType)d.ReturnType.Accept (this), AstNode.Roles.Type); + newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type); newDelegate.AddChild (new Identifier (d.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier); if (d.MemberName.TypeArguments != null) { var typeArgLocation = LocationsBag.GetLocations (d.MemberName); @@ -322,22 +388,6 @@ namespace ICSharpCode.NRefactory.CSharp #region Type members - void AddFixedFieldInitializer (VariableInitializer variable, Mono.CSharp.Expression initializer) - { - if (initializer == null) - return; - if (initializer is ConstInitializer) { - variable.AddChild (new CSharpTokenNode (Convert (initializer.Location), 1), FieldDeclaration.Roles.LBracket); - variable.AddChild ((VariableInitializer)initializer.Accept (this), FieldDeclaration.Roles.Variable); - var initializerLoc = LocationsBag.GetLocations (initializer); - if (initializerLoc != null) - variable.AddChild (new CSharpTokenNode (Convert (initializerLoc[0]), 1), FieldDeclaration.Roles.RBracket); - } else { - variable.AddChild (new CSharpTokenNode (Convert (initializer.Location), 1), FieldDeclaration.Roles.Assign); - variable.AddChild ((VariableInitializer)initializer.Accept (this), FieldDeclaration.Roles.Variable); - } - } - public override void Visit (FixedField f) { var location = LocationsBag.GetMemberLocation (f); @@ -347,11 +397,13 @@ namespace ICSharpCode.NRefactory.CSharp AddModifiers (newField, location); if (location != null) newField.AddChild (new CSharpTokenNode (Convert (location[0]), "fixed".Length), FieldDeclaration.Roles.Keyword); - newField.AddChild ((AstType)f.TypeName.Accept (this), FieldDeclaration.Roles.Type); + newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type); VariableInitializer variable = new VariableInitializer (); variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier); - AddFixedFieldInitializer (variable, f.Initializer); + if (!f.Initializer.IsNull) { + variable.AddChild ((Expression)f.Initializer.Accept (this), FieldDeclaration.Roles.Expression); + } newField.AddChild (variable, FieldDeclaration.Roles.Variable); if (f.Declarators != null) { @@ -362,7 +414,9 @@ namespace ICSharpCode.NRefactory.CSharp variable = new VariableInitializer (); variable.AddChild (new Identifier (decl.Name.Value, Convert (decl.Name.Location)), FieldDeclaration.Roles.Identifier); - AddFixedFieldInitializer (variable, decl.Initializer); + if (!decl.Initializer.IsNull) { + variable.AddChild ((Expression)decl.Initializer.Accept (this), FieldDeclaration.Roles.Expression); + } newField.AddChild (variable, FieldDeclaration.Roles.Variable); } } @@ -379,7 +433,7 @@ namespace ICSharpCode.NRefactory.CSharp FieldDeclaration newField = new FieldDeclaration (); AddModifiers (newField, location); - newField.AddChild ((AstType)f.TypeName.Accept (this), FieldDeclaration.Roles.Type); + newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type); VariableInitializer variable = new VariableInitializer (); variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier); @@ -420,7 +474,7 @@ namespace ICSharpCode.NRefactory.CSharp AddModifiers (newField, location); if (location != null) newField.AddChild (new CSharpTokenNode (Convert (location[0]), "const".Length), FieldDeclaration.Roles.Keyword); - newField.AddChild ((AstType)f.TypeName.Accept (this), FieldDeclaration.Roles.Type); + newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type); VariableInitializer variable = new VariableInitializer (); variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), VariableInitializer.Roles.Identifier); @@ -462,7 +516,7 @@ namespace ICSharpCode.NRefactory.CSharp AddModifiers (newOperator, location); - newOperator.AddChild ((AstType)o.TypeName.Accept (this), AstNode.Roles.Type); + newOperator.AddChild (ConvertToType (o.TypeName), AstNode.Roles.Type); if (o.OperatorType == Operator.OpType.Implicit) { if (location != null) { @@ -519,7 +573,7 @@ namespace ICSharpCode.NRefactory.CSharp var location = LocationsBag.GetMemberLocation (indexer); AddModifiers (newIndexer, location); - newIndexer.AddChild ((AstType)indexer.TypeName.Accept (this), AstNode.Roles.Type); + newIndexer.AddChild (ConvertToType (indexer.TypeName), AstNode.Roles.Type); if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IndexerDeclaration.Roles.LBracket); @@ -573,7 +627,7 @@ namespace ICSharpCode.NRefactory.CSharp var location = LocationsBag.GetMemberLocation (m); AddModifiers (newMethod, location); - newMethod.AddChild ((AstType)m.TypeName.Accept (this), AstNode.Roles.Type); + newMethod.AddChild (ConvertToType (m.TypeName), AstNode.Roles.Type); newMethod.AddChild (new Identifier (m.Name, Convert (m.Location)), AstNode.Roles.Identifier); if (m.MemberName.TypeArguments != null) { @@ -641,7 +695,7 @@ namespace ICSharpCode.NRefactory.CSharp var location = LocationsBag.GetMemberLocation (p); AddModifiers (newProperty, location); - newProperty.AddChild ((AstType)p.TypeName.Accept (this), AstNode.Roles.Type); + newProperty.AddChild (ConvertToType (p.TypeName), AstNode.Roles.Type); newProperty.AddChild (new Identifier (p.MemberName.Name, Convert (p.MemberName.Location)), AstNode.Roles.Identifier); if (location != null) newProperty.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LBrace); @@ -729,7 +783,7 @@ namespace ICSharpCode.NRefactory.CSharp if (location != null) newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), EventDeclaration.Roles.Keyword); - newEvent.AddChild ((AstType)e.TypeName.Accept (this), AstNode.Roles.Type); + newEvent.AddChild (ConvertToType (e.TypeName), AstNode.Roles.Type); newEvent.AddChild (new Identifier (e.MemberName.Name, Convert (e.MemberName.Location)), EventDeclaration.Roles.Identifier); if (location != null) newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), EventDeclaration.Roles.Semicolon); @@ -746,7 +800,7 @@ namespace ICSharpCode.NRefactory.CSharp if (location != null) newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), CustomEventDeclaration.Roles.Keyword); - newEvent.AddChild ((AstType)ep.TypeName.Accept (this), CustomEventDeclaration.Roles.Type); + newEvent.AddChild (ConvertToType (ep.TypeName), CustomEventDeclaration.Roles.Type); newEvent.AddChild (new Identifier (ep.MemberName.Name, Convert (ep.MemberName.Location)), CustomEventDeclaration.Roles.Identifier); if (location != null && location.Count >= 2) newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CustomEventDeclaration.Roles.LBrace); @@ -789,7 +843,7 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (BlockVariableDeclaration blockVariableDeclaration) { var result = new VariableDeclarationStatement (); - result.AddChild ((AstType)blockVariableDeclaration.TypeExpression.Accept (this), VariableDeclarationStatement.Roles.Type); + result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), VariableDeclarationStatement.Roles.Type); var varInit = new VariableInitializer (); var location = LocationsBag.GetLocations (blockVariableDeclaration); @@ -828,7 +882,7 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (BlockConstantDeclaration blockVariableDeclaration) { var result = new VariableDeclarationStatement (); - result.AddChild ((AstType)blockVariableDeclaration.TypeExpression.Accept (this), VariableDeclarationStatement.Roles.Type); + result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), VariableDeclarationStatement.Roles.Type); var varInit = new VariableInitializer (); var location = LocationsBag.GetLocations (blockVariableDeclaration); @@ -907,18 +961,18 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (Do doStatement) { - var result = new WhileStatement (WhilePosition.End); + var result = new DoWhileStatement (); var location = LocationsBag.GetLocations (doStatement); - result.AddChild (new CSharpTokenNode (Convert (doStatement.loc), "do".Length), WhileStatement.DoKeywordRole); + result.AddChild (new CSharpTokenNode (Convert (doStatement.loc), "do".Length), DoWhileStatement.DoKeywordRole); result.AddChild ((Statement)doStatement.EmbeddedStatement.Accept (this), WhileStatement.Roles.EmbeddedStatement); if (location != null) - result.AddChild (new CSharpTokenNode (Convert (location[0]), "while".Length), WhileStatement.WhileKeywordRole); + result.AddChild (new CSharpTokenNode (Convert (location[0]), "while".Length), DoWhileStatement.WhileKeywordRole); if (location != null) - result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), WhileStatement.Roles.LPar); - result.AddChild ((Expression)doStatement.expr.Accept (this), WhileStatement.Roles.Condition); + result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DoWhileStatement.Roles.LPar); + result.AddChild ((Expression)doStatement.expr.Accept (this), DoWhileStatement.Roles.Condition); if (location != null) { - result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), WhileStatement.Roles.RPar); - result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), WhileStatement.Roles.Semicolon); + result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DoWhileStatement.Roles.RPar); + result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DoWhileStatement.Roles.Semicolon); } return result; @@ -926,7 +980,7 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (While whileStatement) { - var result = new WhileStatement (WhilePosition.Begin); + var result = new WhileStatement (); var location = LocationsBag.GetLocations (whileStatement); result.AddChild (new CSharpTokenNode (Convert (whileStatement.loc), "while".Length), WhileStatement.WhileKeywordRole); @@ -1009,7 +1063,7 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (Goto gotoStatement) { - var result = new GotoStatement (GotoType.Label); + var result = new GotoStatement (); var location = LocationsBag.GetLocations (gotoStatement); result.AddChild (new CSharpTokenNode (Convert (gotoStatement.loc), "goto".Length), GotoStatement.Roles.Keyword); result.AddChild (new Identifier (gotoStatement.Target, Convert (gotoStatement.loc)), GotoStatement.Roles.Identifier); @@ -1028,12 +1082,12 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (GotoDefault gotoDefault) { - var result = new GotoStatement (GotoType.CaseDefault); - result.AddChild (new CSharpTokenNode (Convert (gotoDefault.loc), "goto".Length), GotoStatement.Roles.Keyword); + var result = new GotoDefaultStatement (); + result.AddChild (new CSharpTokenNode (Convert (gotoDefault.loc), "goto".Length), GotoDefaultStatement.Roles.Keyword); var location = LocationsBag.GetLocations (gotoDefault); if (location != null) { - result.AddChild (new CSharpTokenNode (Convert (location[0]), "default".Length), GotoStatement.DefaultKeywordRole); - result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), GotoStatement.Roles.Semicolon); + result.AddChild (new CSharpTokenNode (Convert (location[0]), "default".Length), GotoDefaultStatement.DefaultKeywordRole); + result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), GotoDefaultStatement.Roles.Semicolon); } return result; @@ -1041,15 +1095,15 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (GotoCase gotoCase) { - var result = new GotoStatement (GotoType.Case); - result.AddChild (new CSharpTokenNode (Convert (gotoCase.loc), "goto".Length), GotoStatement.Roles.Keyword); + var result = new GotoCaseStatement (); + result.AddChild (new CSharpTokenNode (Convert (gotoCase.loc), "goto".Length), GotoCaseStatement.Roles.Keyword); var location = LocationsBag.GetLocations (gotoCase); if (location != null) - result.AddChild (new CSharpTokenNode (Convert (location[0]), "case".Length), GotoStatement.CaseKeywordRole); - result.AddChild ((Expression)gotoCase.Expr.Accept (this), GotoStatement.Roles.Expression); + result.AddChild (new CSharpTokenNode (Convert (location[0]), "case".Length), GotoCaseStatement.CaseKeywordRole); + result.AddChild ((Expression)gotoCase.Expr.Accept (this), GotoCaseStatement.Roles.Expression); if (location != null) - result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), GotoStatement.Roles.Semicolon); + result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), GotoCaseStatement.Roles.Semicolon); return result; } @@ -1101,13 +1155,13 @@ namespace ICSharpCode.NRefactory.CSharp usingResult.AddChild (new CSharpTokenNode (Convert (u.loc), "using".Length), UsingStatement.Roles.Keyword); usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), UsingStatement.Roles.LPar); if (u.Variables != null) { - usingResult.AddChild ((AstType)u.Variables.TypeExpression.Accept (this), UsingStatement.Roles.Type); + usingResult.AddChild (ConvertToType (u.Variables.TypeExpression), UsingStatement.Roles.Type); usingResult.AddChild (new Identifier (u.Variables.Variable.Name, Convert (u.Variables.Variable.Location)), UsingStatement.Roles.Identifier); var loc = LocationsBag.GetLocations (u.Variables); if (loc != null) usingResult.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), ContinueStatement.Roles.Assign); if (u.Variables.Initializer != null) - usingResult.AddChild ((AstType)u.Variables.Initializer.Accept (this), UsingStatement.ResourceAcquisitionRole); + usingResult.AddChild (ConvertToType (u.Variables.Initializer), UsingStatement.ResourceAcquisitionRole); } cur = u.Statement; @@ -1178,8 +1232,11 @@ namespace ICSharpCode.NRefactory.CSharp var bodyBlock = new BlockStatement (); int curLocal = 0; AddBlockChildren (bodyBlock, blockStatement, ref curLocal); - - newSection.AddChild (bodyBlock, SwitchSection.Roles.Body); + foreach (var statement in bodyBlock.Statements) { + statement.Remove (); + newSection.AddChild (statement, SwitchSection.Roles.EmbeddedStatement); + + } result.AddChild (newSection, SwitchStatement.SwitchSectionRole); } @@ -1241,7 +1298,7 @@ namespace ICSharpCode.NRefactory.CSharp /* if (fixedStatement.Variables != null) { - result.AddChild ((AstType)fixedStatement.Variables.TypeExpression.Accept (this), UsingStatement.Roles.Type); + result.AddChild (ConvertToType (fixedStatement.Variables.TypeExpression.Accept (this), UsingStatement.Roles.Type); result.AddChild (new Identifier (fixedStatement.Variables.Variable.Name, Convert (fixedStatement.Variables.Variable.Location)), UsingStatement.Roles.Identifier); var loc = LocationsBag.GetLocations (fixedStatement.Variables); if (loc != null) @@ -1285,7 +1342,7 @@ namespace ICSharpCode.NRefactory.CSharp if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CatchClause.Roles.LPar); - result.AddChild ((AstType)ctch.TypeExpression.Accept (this), CatchClause.Roles.Type); + result.AddChild (ConvertToType (ctch.TypeExpression), CatchClause.Roles.Type); if (ctch.Variable != null && !string.IsNullOrEmpty (ctch.Variable.Name)) result.AddChild (new Identifier (ctch.Variable.Name, Convert (ctch.Variable.Location)), CatchClause.Roles.Identifier); @@ -1341,7 +1398,7 @@ namespace ICSharpCode.NRefactory.CSharp result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ForeachStatement.Roles.LPar); if (foreachStatement.TypeExpr == null) - result.AddChild ((AstType)foreachStatement.TypeExpr.Accept (this), ForeachStatement.Roles.Type); + result.AddChild (ConvertToType (foreachStatement.TypeExpr), ForeachStatement.Roles.Type); if (foreachStatement.Variable != null) result.AddChild (new Identifier (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier); @@ -1376,12 +1433,12 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (YieldBreak yieldBreakStatement) { - var result = new YieldStatement (); + var result = new YieldBreakStatement (); var location = LocationsBag.GetLocations (yieldBreakStatement); - result.AddChild (new CSharpTokenNode (Convert (yieldBreakStatement.loc), "yield".Length), YieldStatement.YieldKeywordRole); + result.AddChild (new CSharpTokenNode (Convert (yieldBreakStatement.loc), "yield".Length), YieldBreakStatement.YieldKeywordRole); if (location != null) { - result.AddChild (new CSharpTokenNode (Convert (location[0]), "break".Length), YieldStatement.BreakKeywordRole); - result.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), YieldStatement.Roles.Semicolon); + result.AddChild (new CSharpTokenNode (Convert (location[0]), "break".Length), YieldBreakStatement.BreakKeywordRole); + result.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), YieldBreakStatement.Roles.Semicolon); } return result; } @@ -1397,40 +1454,39 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (TypeExpression typeExpression) { - var result = new PrimitiveType (); - result.Location = Convert (typeExpression.Location); + string keyword; if (typeExpression.Type == TypeManager.void_type) { - result.Keyword = "void"; + keyword = "void"; } else if (typeExpression.Type == TypeManager.string_type) { - result.Keyword = "string"; + keyword = "string"; } else if (typeExpression.Type == TypeManager.int32_type) { - result.Keyword = "int"; + keyword = "int"; } else if (typeExpression.Type == TypeManager.object_type) { - result.Keyword = "object"; + keyword = "object"; } else if (typeExpression.Type == TypeManager.float_type) { - result.Keyword = "float"; + keyword = "float"; } else if (typeExpression.Type == TypeManager.double_type) { - result.Keyword = "double"; + keyword = "double"; } else if (typeExpression.Type == TypeManager.int64_type) { - result.Keyword = "long"; + keyword = "long"; } else if (typeExpression.Type == TypeManager.byte_type) { - result.Keyword = "byte"; + keyword = "byte"; } else if (typeExpression.Type == TypeManager.uint32_type) { - result.Keyword = "uint"; + keyword = "uint"; } else if (typeExpression.Type == TypeManager.uint64_type) { - result.Keyword = "ulong"; + keyword = "ulong"; } else if (typeExpression.Type == TypeManager.short_type) { - result.Keyword = "short"; + keyword = "short"; } else if (typeExpression.Type == TypeManager.ushort_type) { - result.Keyword = "ushort"; + keyword = "ushort"; } else if (typeExpression.Type == TypeManager.sbyte_type) { - result.Keyword = "sbyte"; + keyword = "sbyte"; } else if (typeExpression.Type == TypeManager.decimal_type) { - result.Keyword = "decimal"; + keyword = "decimal"; } else { - throw new NotImplementedException(); + keyword = "unknown"; } - return result; + return new IdentifierExpression (keyword, Convert (typeExpression.Location)); } public override object Visit (LocalVariableReference localVariableReference) @@ -1567,7 +1623,7 @@ namespace ICSharpCode.NRefactory.CSharp var result = new IsExpression (); result.AddChild ((Expression)isExpression.Expr.Accept (this), IsExpression.Roles.Expression); result.AddChild (new CSharpTokenNode (Convert (isExpression.Location), "is".Length), IsExpression.Roles.Keyword); - result.AddChild ((AstType)isExpression.ProbeType.Accept (this), IsExpression.Roles.Type); + result.AddChild (ConvertToType (isExpression.ProbeType), IsExpression.Roles.Type); return result; } @@ -1576,7 +1632,7 @@ namespace ICSharpCode.NRefactory.CSharp var result = new AsExpression (); result.AddChild ((Expression)asExpression.Expr.Accept (this), AsExpression.Roles.Expression); result.AddChild (new CSharpTokenNode (Convert (asExpression.Location), "as".Length), AsExpression.Roles.Keyword); - result.AddChild ((AstType)asExpression.ProbeType.Accept (this), AsExpression.Roles.Type); + result.AddChild (ConvertToType (asExpression.ProbeType), AsExpression.Roles.Type); return result; } @@ -1587,7 +1643,7 @@ namespace ICSharpCode.NRefactory.CSharp result.AddChild (new CSharpTokenNode (Convert (castExpression.Location), 1), CastExpression.Roles.LPar); if (castExpression.TargetType != null) - result.AddChild ((AstType)castExpression.TargetType.Accept (this), CastExpression.Roles.Type); + result.AddChild (ConvertToType (castExpression.TargetType), CastExpression.Roles.Type); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.RPar); if (castExpression.Expr != null) @@ -1598,7 +1654,7 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (ComposedCast composedCast) { var result = new ComposedType (); - result.AddChild ((AstType)composedCast.Left.Accept (this), ComposedType.Roles.Type); + result.AddChild (ConvertToType (composedCast.Left), ComposedType.Roles.Type); var spec = composedCast.Spec; while (spec != null) { @@ -1627,7 +1683,7 @@ namespace ICSharpCode.NRefactory.CSharp var location = LocationsBag.GetLocations (defaultValueExpression); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.LPar); - result.AddChild ((AstType)defaultValueExpression.Expr.Accept (this), CastExpression.Roles.Type); + result.AddChild (ConvertToType (defaultValueExpression.Expr), CastExpression.Roles.Type); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CastExpression.Roles.RPar); return result; @@ -1770,7 +1826,7 @@ namespace ICSharpCode.NRefactory.CSharp break; } if (p.TypeExpression != null) // lambdas may have no types (a, b) => ... - parameterDeclarationExpression.AddChild ((AstType)p.TypeExpression.Accept (this), ParameterDeclaration.Roles.Type); + parameterDeclarationExpression.AddChild (ConvertToType (p.TypeExpression), ParameterDeclaration.Roles.Type); parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclaration.Roles.Identifier); if (p.HasDefaultValue) { if (location != null) @@ -1791,7 +1847,7 @@ namespace ICSharpCode.NRefactory.CSharp var arg = typeArguments.Args[i]; if (arg == null) continue; - parent.AddChild ((AstType)arg.Accept (this), InvocationExpression.Roles.TypeArgument); + parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument); } } @@ -1805,7 +1861,7 @@ namespace ICSharpCode.NRefactory.CSharp var arg = typeArguments.Args[i]; if (arg == null) continue; - parent.AddChild ((AstType)arg.Accept (this), InvocationExpression.Roles.TypeArgument); + parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument); } } @@ -1821,7 +1877,7 @@ namespace ICSharpCode.NRefactory.CSharp parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier); parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole); foreach (var expr in c.ConstraintExpressions) - parent.AddChild ((AstType)expr.Accept (this), Constraint.BaseTypeRole); + parent.AddChild (ConvertToType (expr), Constraint.BaseTypeRole); } } @@ -1878,7 +1934,7 @@ namespace ICSharpCode.NRefactory.CSharp result.AddChild (new CSharpTokenNode (Convert (newExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword); if (newExpression.TypeRequested != null) - result.AddChild ((AstType)newExpression.TypeRequested.Accept (this), ObjectCreateExpression.Roles.Type); + result.AddChild (ConvertToType (newExpression.TypeRequested), ObjectCreateExpression.Roles.Type); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ObjectCreateExpression.Roles.LPar); AddArguments (result, location, newExpression.Arguments); @@ -1898,7 +1954,7 @@ namespace ICSharpCode.NRefactory.CSharp result.AddChild (new CSharpTokenNode (Convert (newInitializeExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword); if (newInitializeExpression.TypeRequested != null) - result.AddChild ((AstType)newInitializeExpression.TypeRequested.Accept (this), ObjectCreateExpression.Roles.Type); + result.AddChild (ConvertToType (newInitializeExpression.TypeRequested), ObjectCreateExpression.Roles.Type); var location = LocationsBag.GetLocations (newInitializeExpression); if (location != null) @@ -1919,7 +1975,7 @@ namespace ICSharpCode.NRefactory.CSharp result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Location), "new".Length), ArrayCreateExpression.Roles.Keyword); if (arrayCreationExpression.NewType != null) - result.AddChild ((AstType)arrayCreationExpression.NewType.Accept (this), ArrayCreateExpression.Roles.Type); + result.AddChild (ConvertToType (arrayCreationExpression.NewType), ArrayCreateExpression.Roles.Type); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ArrayCreateExpression.Roles.LBracket); if (arrayCreationExpression.Arguments != null) { @@ -1989,7 +2045,7 @@ namespace ICSharpCode.NRefactory.CSharp var location = LocationsBag.GetLocations (typeOfExpression); result.AddChild (new CSharpTokenNode (Convert (typeOfExpression.Location), "typeof".Length), TypeOfExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar); - result.AddChild ((AstType)typeOfExpression.TypeExpression.Accept (this), TypeOfExpression.Roles.Type); + result.AddChild (ConvertToType (typeOfExpression.TypeExpression), TypeOfExpression.Roles.Type); result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar); return result; } @@ -2001,7 +2057,7 @@ namespace ICSharpCode.NRefactory.CSharp result.AddChild (new CSharpTokenNode (Convert (sizeOfExpression.Location), "sizeof".Length), TypeOfExpression.Roles.Keyword); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar); - result.AddChild ((AstType)sizeOfExpression.QueriedType.Accept (this), TypeOfExpression.Roles.Type); + result.AddChild (ConvertToType (sizeOfExpression.QueriedType), TypeOfExpression.Roles.Type); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar); return result; @@ -2060,7 +2116,7 @@ namespace ICSharpCode.NRefactory.CSharp var location = LocationsBag.GetLocations (stackAllocExpression); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), "stackalloc".Length), StackAllocExpression.Roles.Keyword); - result.AddChild ((AstType)stackAllocExpression.TypeExpression.Accept (this), StackAllocExpression.Roles.Type); + result.AddChild (ConvertToType (stackAllocExpression.TypeExpression), StackAllocExpression.Roles.Type); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), StackAllocExpression.Roles.LBracket); result.AddChild ((Expression)stackAllocExpression.CountExpression.Accept (this), StackAllocExpression.Roles.Expression); @@ -2177,7 +2233,7 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (ConstInitializer constInitializer) { - return new Identifier (constInitializer.Name, Convert (constInitializer.Location)); + return constInitializer.Expr.Accept (this); } public override object Visit (ArrayInitializer arrayInitializer) diff --git a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj index 1ff587cd2..dbc34bcba 100644 --- a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj +++ b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj @@ -1,4 +1,4 @@ - + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} @@ -47,9 +47,6 @@ 4 - - ..\lib\Mono.Cecil.dll - @@ -58,6 +55,8 @@ + + @@ -329,10 +328,17 @@ + + - + + + + {D68133BD-1E63-496E-9EDE-4FBDBF77B486} + Mono.Cecil + \ No newline at end of file diff --git a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs index 48424ca19..65bcae4b9 100644 --- a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs +++ b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs @@ -179,6 +179,16 @@ namespace ICSharpCode.NRefactory.TypeSystem { return null; } + + public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) + { + return null; + } + + public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) + { + return null; + } } #endregion @@ -749,8 +759,10 @@ namespace ICSharpCode.NRefactory.TypeSystem m.IsAbstract = true; m.IsOverride = !method.IsNewSlot; } else if (method.IsFinal) { - m.IsSealed = true; - m.IsOverride = !method.IsNewSlot; + if (!method.IsNewSlot) { + m.IsSealed = true; + m.IsOverride = true; + } } else if (method.IsVirtual) { if (method.IsNewSlot) m.IsVirtual = true; diff --git a/NRefactory.sln b/NRefactory.sln index b1c0ae610..575ae336b 100644 --- a/NRefactory.sln +++ b/NRefactory.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -# SharpDevelop 4.0.1.7088 +# SharpDevelop 4.0.1.7096 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DC98210E-1646-483B-819A-2BB8272461E4}" ProjectSection(SolutionItems) = postProject README = README @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.VB", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.VB.Tests", "ICSharpCode.NRefactory.VB.Tests\ICSharpCode.NRefactory.VB.Tests.csproj", "{870115DD-960A-4406-A6B9-600BCDC36A03}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "..\Mono.Cecil\Mono.Cecil.csproj", "{D68133BD-1E63-496E-9EDE-4FBDBF77B486}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -68,6 +70,14 @@ Global {870115DD-960A-4406-A6B9-600BCDC36A03}.Release|Any CPU.ActiveCfg = Release|Any CPU {870115DD-960A-4406-A6B9-600BCDC36A03}.Release|x86.Build.0 = Release|Any CPU {870115DD-960A-4406-A6B9-600BCDC36A03}.Release|x86.ActiveCfg = Release|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.Build.0 = net_4_0_Debug|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.ActiveCfg = net_4_0_Debug|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.Build.0 = net_4_0_Debug|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.Build.0 = net_4_0_Debug|Any CPU + {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.ActiveCfg = net_4_0_Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj