From 5f5a38c0f6f2ff052585c9d9b426b33d4540592c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 8 May 2011 11:50:18 +0200 Subject: [PATCH 01/57] add support for Imports and Namespaces --- .../Ast/GlobalScope/ImportsClause.cs | 2 +- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 +- .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 498 +++++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 624 ++++++++++++++++++ 5 files changed, 1117 insertions(+), 10 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs index 15730eab03..a7c8dfa17d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public override S AcceptVisitor(IAstVisitor visitor, T data) { - return visitor.VisitMembersImportsClause(this, data); + return visitor.VisitMemberImportsClause(this, data); } public override string ToString() diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index a2f8ac6c75..eb96f229d4 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitAttribute(Attribute attribute, T data); S VisitAttributeBlock(AttributeBlock attributeBlock, T data); S VisitImportsStatement(ImportsStatement importsStatement, T data); - S VisitMembersImportsClause(MemberImportsClause membersImportsClause, T data); + S VisitMemberImportsClause(MemberImportsClause memberImportsClause, T data); S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data); S VisitOptionStatement(OptionStatement optionStatement, T data); S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 1dac9e1d98..a14f015508 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -122,6 +122,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index f4085b6bc7..907e1a6178 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; +using System.Linq; using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.VB.Ast; @@ -21,6 +23,18 @@ namespace ICSharpCode.NRefactory.VB readonly Stack containerStack = new Stack(); readonly Stack positionStack = new Stack(); + /// + /// Used to insert the minimal amount of spaces so that the lexer recognizes the tokens that were written. + /// + LastWritten lastWritten; + + enum LastWritten + { + Whitespace, + Other, + KeywordOrIdentifier + } + public OutputVisitor(TextWriter textWriter, VBFormattingOptions formattingPolicy) { if (textWriter == null) @@ -41,7 +55,7 @@ namespace ICSharpCode.NRefactory.VB this.policy = formattingPolicy; } - public object VisitCompilationUnit(ICSharpCode.NRefactory.VB.Ast.CompilationUnit compilationUnit, object data) + public object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { // don't do node tracking as we visit all children directly foreach (AstNode node in compilationUnit.Children) @@ -91,17 +105,41 @@ namespace ICSharpCode.NRefactory.VB public object VisitImportsStatement(ImportsStatement importsStatement, object data) { - throw new NotImplementedException(); + StartNode(importsStatement); + + WriteKeyword("Imports", AstNode.Roles.Keyword); + Space(); + WriteCommaSeparatedList(importsStatement.ImportsClauses); + NewLine(); + + return EndNode(importsStatement); } - public object VisitMembersImportsClause(MemberImportsClause membersImportsClause, object data) + public object VisitMemberImportsClause(MemberImportsClause memberImportsClause, object data) { - throw new NotImplementedException(); + StartNode(memberImportsClause); + memberImportsClause.Member.AcceptVisitor(this, data); + return EndNode(memberImportsClause); } public object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { - throw new NotImplementedException(); + StartNode(namespaceDeclaration); + WriteKeyword("Namespace"); + bool isFirst = true; + foreach (Identifier node in namespaceDeclaration.Identifiers) { + if (isFirst) { + isFirst = false; + } else { + WriteToken(".", NamespaceDeclaration.Roles.Dot); + } + node.AcceptVisitor(this, null); + } + NewLine(); + WriteKeyword("End"); + WriteKeyword("Namespace"); + NewLine(); + return EndNode(namespaceDeclaration); } public object VisitOptionStatement(OptionStatement optionStatement, object data) @@ -136,7 +174,10 @@ namespace ICSharpCode.NRefactory.VB public object VisitIdentifier(Identifier identifier, object data) { - throw new NotImplementedException(); + StartNode(identifier); + WriteIdentifier(identifier.Name); + WriteTypeCharacter(identifier.TypeCharacter); + return EndNode(identifier); } public object VisitXmlIdentifier(XmlIdentifier xmlIdentifier, object data) @@ -166,7 +207,14 @@ namespace ICSharpCode.NRefactory.VB public object VisitQualifiedType(QualifiedType qualifiedType, object data) { - throw new NotImplementedException(); + StartNode(qualifiedType); + + qualifiedType.Target.AcceptVisitor(this, data); + WriteToken(".", AstNode.Roles.Dot); + WriteIdentifier(qualifiedType.Name); + WriteTypeArguments(qualifiedType.TypeArguments); + + return EndNode(qualifiedType); } public object VisitComposedType(ComposedType composedType, object data) @@ -181,7 +229,12 @@ namespace ICSharpCode.NRefactory.VB public object VisitSimpleType(SimpleType simpleType, object data) { - throw new NotImplementedException(); + StartNode(simpleType); + + WriteIdentifier(simpleType.Identifier); + WriteTypeArguments(simpleType.TypeArguments); + + return EndNode(simpleType); } public object VisitAnyNode(AnyNode anyNode, object data) @@ -218,5 +271,434 @@ namespace ICSharpCode.NRefactory.VB { throw new NotImplementedException(); } + + #region StartNode/EndNode + void StartNode(AstNode node) + { + // Ensure that nodes are visited in the proper nested order. + // Jumps to different subtrees are allowed only for the child of a placeholder node. + Debug.Assert(containerStack.Count == 0 || node.Parent == containerStack.Peek()); + if (positionStack.Count > 0) + WriteSpecialsUpToNode(node); + containerStack.Push(node); + positionStack.Push(node.FirstChild); + formatter.StartNode(node); + } + + object EndNode(AstNode node) + { + Debug.Assert(node == containerStack.Peek()); + AstNode pos = positionStack.Pop(); + Debug.Assert(pos == null || pos.Parent == node); + WriteSpecials(pos, null); + containerStack.Pop(); + formatter.EndNode(node); + return null; + } + #endregion + + #region WriteSpecials + /// + /// Writes all specials from start to end (exclusive). Does not touch the positionStack. + /// + void WriteSpecials(AstNode start, AstNode end) + { + for (AstNode pos = start; pos != end; pos = pos.NextSibling) { + if (pos.Role == AstNode.Roles.Comment) { + pos.AcceptVisitor(this, null); + } + } + } + + /// + /// Writes all specials between the current position (in the positionStack) and the next + /// node with the specified role. Advances the current position. + /// + void WriteSpecialsUpToRole(Role role) + { + for (AstNode pos = positionStack.Peek(); pos != null; pos = pos.NextSibling) { + if (pos.Role == role) { + WriteSpecials(positionStack.Pop(), pos); + positionStack.Push(pos); + break; + } + } + } + + /// + /// Writes all specials between the current position (in the positionStack) and the specified node. + /// Advances the current position. + /// + void WriteSpecialsUpToNode(AstNode node) + { + for (AstNode pos = positionStack.Peek(); pos != null; pos = pos.NextSibling) { + if (pos == node) { + WriteSpecials(positionStack.Pop(), pos); + positionStack.Push(pos); + break; + } + } + } + + void WriteSpecialsUpToRole(Role role, AstNode nextNode) + { + // Look for the role between the current position and the nextNode. + for (AstNode pos = positionStack.Peek(); pos != null && pos != nextNode; pos = pos.NextSibling) { + if (pos.Role == AstNode.Roles.Comma) { + WriteSpecials(positionStack.Pop(), pos); + positionStack.Push(pos); + break; + } + } + } + #endregion + + #region Comma + /// + /// Writes a comma. + /// + /// The next node after the comma. + /// When set prevents printing a space after comma. + void Comma(AstNode nextNode, bool noSpaceAfterComma = false) + { + WriteSpecialsUpToRole(AstNode.Roles.Comma, nextNode); + Space(); // TODO: Comma policy has changed. + formatter.WriteToken(","); + lastWritten = LastWritten.Other; + Space(!noSpaceAfterComma); // TODO: Comma policy has changed. + } + + void WriteCommaSeparatedList(IEnumerable list) + { + bool isFirst = true; + foreach (AstNode node in list) { + if (isFirst) { + isFirst = false; + } else { + Comma(node); + } + node.AcceptVisitor(this, null); + } + } + + void WriteCommaSeparatedListInParenthesis(IEnumerable list, bool spaceWithin) + { + LPar(); + if (list.Any()) { + Space(spaceWithin); + WriteCommaSeparatedList(list); + Space(spaceWithin); + } + RPar(); + } + + #if DOTNET35 + void WriteCommaSeparatedList(IEnumerable list) + { + WriteCommaSeparatedList(list); + } + + void WriteCommaSeparatedList(IEnumerable list) + { + WriteCommaSeparatedList(list); + } + + void WriteCommaSeparatedListInParenthesis(IEnumerable list, bool spaceWithin) + { + WriteCommaSeparatedListInParenthesis(list.SafeCast(), spaceWithin); + } + + void WriteCommaSeparatedListInParenthesis(IEnumerable list, bool spaceWithin) + { + WriteCommaSeparatedListInParenthesis(list.SafeCast(), spaceWithin); + } + + #endif + + void WriteCommaSeparatedListInBrackets(IEnumerable list, bool spaceWithin) + { + WriteToken("[", AstNode.Roles.LBracket); + if (list.Any()) { + Space(spaceWithin); + WriteCommaSeparatedList(list); + Space(spaceWithin); + } + WriteToken("]", AstNode.Roles.RBracket); + } + + void WriteCommaSeparatedListInBrackets(IEnumerable list) + { + WriteToken ("[", AstNode.Roles.LBracket); + if (list.Any ()) { + Space(); + WriteCommaSeparatedList(list); + Space(); + } + WriteToken ("]", AstNode.Roles.RBracket); + } + #endregion + + #region Write tokens + /// + /// Writes a keyword, and all specials up to + /// + void WriteKeyword(string keyword, Role tokenRole = null) + { + WriteSpecialsUpToRole(tokenRole ?? AstNode.Roles.Keyword); + if (lastWritten == LastWritten.KeywordOrIdentifier) + formatter.Space(); + formatter.WriteKeyword(keyword); + lastWritten = LastWritten.KeywordOrIdentifier; + } + + void WriteIdentifier(string identifier, Role identifierRole = null) + { + WriteSpecialsUpToRole(identifierRole ?? AstNode.Roles.Identifier); + if (IsKeyword(identifier, containerStack.Peek())) { + if (lastWritten == LastWritten.KeywordOrIdentifier) + Space(); // this space is not strictly required, so we call Space() + formatter.WriteToken("@"); + } else if (lastWritten == LastWritten.KeywordOrIdentifier) { + formatter.Space(); // this space is strictly required, so we directly call the formatter + } + formatter.WriteIdentifier(identifier); + lastWritten = LastWritten.KeywordOrIdentifier; + } + + void WriteToken(string token, Role tokenRole) + { + WriteSpecialsUpToRole(tokenRole); + // 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; + // 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] == '*') +// { +// formatter.Space(); +// } + formatter.WriteToken(token); +// if (token == "+") +// lastWritten = LastWritten.Plus; +// else if (token == "-") +// lastWritten = LastWritten.Minus; +// else if (token == "&") +// lastWritten = LastWritten.Ampersand; +// else if (token == "?") +// lastWritten = LastWritten.QuestionMark; +// else if (token == "/") +// lastWritten = LastWritten.Division; +// else + lastWritten = LastWritten.Other; + } + + void WriteTypeCharacter(TypeCode typeCharacter) + { + switch (typeCharacter) { + case TypeCode.Empty: + case TypeCode.Object: + case TypeCode.DBNull: + case TypeCode.Boolean: + case TypeCode.Char: + + break; + case TypeCode.SByte: + + break; + case TypeCode.Byte: + + break; + case TypeCode.Int16: + + break; + case TypeCode.UInt16: + + break; + case TypeCode.Int32: + WriteToken("%", null); + break; + case TypeCode.UInt32: + + break; + case TypeCode.Int64: + WriteToken("&", null); + break; + case TypeCode.UInt64: + + break; + case TypeCode.Single: + WriteToken("!", null); + break; + case TypeCode.Double: + WriteToken("#", null); + break; + case TypeCode.Decimal: + WriteToken("@", null); + break; + case TypeCode.DateTime: + + break; + case TypeCode.String: + WriteToken("$", null); + break; + default: + throw new Exception("Invalid value for TypeCode"); + } + } + + void LPar() + { + WriteToken("(", AstNode.Roles.LPar); + } + + void RPar() + { + WriteToken(")", AstNode.Roles.LPar); + } + + /// + /// Writes a space depending on policy. + /// + void Space(bool addSpace = true) + { + if (addSpace) { + formatter.Space(); + lastWritten = LastWritten.Whitespace; + } + } + + void NewLine() + { + formatter.NewLine(); + lastWritten = LastWritten.Whitespace; + } + #endregion + + #region IsKeyword Test + static readonly HashSet unconditionalKeywords = new HashSet { + "AddHandler", "AddressOf", "Alias", "And", "AndAlso", "As", "Boolean", "ByRef", "Byte", + "ByVal", "Call", "Case", "Catch", "CBool", "CByte", "CChar", "CInt", "Class", "CLng", + "CObj", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", "CType", "CUInt", + "CULng", "CUShort", "Date", "Decimal", "Declare", "Default", "Delegate", "Dim", + "DirectCast", "Do", "Double", "Each", "Else", "ElseIf", "End", "EndIf", "Enum", "Erase", + "Error", "Event", "Exit", "False", "Finally", "For", "Friend", "Function", "Get", + "GetType", "GetXmlNamespace", "Global", "GoSub", "GoTo", "Handles", "If", "Implements", + "Imports", "In", "Inherits", "Integer", "Interface", "Is", "IsNot", "Let", "Lib", "Like", + "Long", "Loop", "Me", "Mod", "Module", "MustInherit", "MustOverride", "MyBase", "MyClass", + "Namespace", "Narrowing", "New", "Next", "Not", "Nothing", "NotInheritable", "NotOverridable", + "Object", "Of", "On", "Operator", "Option", "Optional", "Or", "OrElse", "Overloads", + "Overridable", "Overrides", "ParamArray", "Partial", "Private", "Property", "Protected", + "Public", "RaiseEvent", "ReadOnly", "ReDim", "REM", "RemoveHandler", "Resume", "Return", + "SByte", "Select", "Set", "Shadows", "Shared", "Short", "Single", "Static", "Step", "Stop", + "String", "Structure", "Sub", "SyncLock", "Then", "Throw", "To", "True", "Try", "TryCast", + "TypeOf", "UInteger", "ULong", "UShort", "Using", "Variant", "Wend", "When", "While", + "Widening", "With", "WithEvents", "WriteOnly", "Xor" + }; + + static readonly HashSet queryKeywords = new HashSet { + + }; + + /// + /// Determines whether the specified identifier is a keyword in the given context. + /// + public static bool IsKeyword(string identifier, AstNode context) + { + if (unconditionalKeywords.Contains(identifier)) + return true; +// if (context.Ancestors.Any(a => a is QueryExpression)) { +// if (queryKeywords.Contains(identifier)) +// return true; +// } + return false; + } + #endregion + + #region Write constructs + void WriteTypeArguments(IEnumerable typeArguments) + { + if (typeArguments.Any()) { + LPar(); + WriteKeyword("Of"); + WriteCommaSeparatedList(typeArguments); + RPar(); + } + } + + void WriteTypeParameters(IEnumerable typeParameters) + { + if (typeParameters.Any()) { + LPar(); + WriteKeyword("Of"); + WriteCommaSeparatedList(typeParameters); + RPar(); + } + } + + void WriteModifiers(IEnumerable modifierTokens) + { + foreach (VBModifierToken modifier in modifierTokens) { + modifier.AcceptVisitor(this, null); + } + } + + void WriteQualifiedIdentifier(IEnumerable identifiers) + { + bool first = true; + foreach (Identifier ident in identifiers) { + if (first) { + first = false; + if (lastWritten == LastWritten.KeywordOrIdentifier) + formatter.Space(); + } else { + WriteSpecialsUpToRole(AstNode.Roles.Dot, ident); + formatter.WriteToken("."); + lastWritten = LastWritten.Other; + } + WriteSpecialsUpToNode(ident); + formatter.WriteIdentifier(ident.Name); + lastWritten = LastWritten.KeywordOrIdentifier; + } + } + + void WriteEmbeddedStatement(Statement embeddedStatement) + { + if (embeddedStatement.IsNull) + return; + BlockStatement block = embeddedStatement as BlockStatement; + if (block != null) + VisitBlockStatement(block, null); + else + embeddedStatement.AcceptVisitor(this, null); + } + + void WriteMethodBody(BlockStatement body) + { + if (body.IsNull) + NewLine(); + else + VisitBlockStatement(body, null); + } + + void WriteAttributes(IEnumerable attributes) + { + foreach (AttributeBlock attr in attributes) { + attr.AcceptVisitor(this, null); + } + } + + void WritePrivateImplementationType(AstType privateImplementationType) + { + if (!privateImplementationType.IsNull) { + privateImplementationType.AcceptVisitor(this, null); + WriteToken(".", AstNode.Roles.Dot); + } + } + #endregion } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs new file mode 100644 index 0000000000..0077ab687a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -0,0 +1,624 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using ICSharpCode.NRefactory.VB.Ast; + +namespace ICSharpCode.NRefactory.VB.Visitors +{ + /// + /// Description of CSharpToVBConverterVisitor. + /// + public class CSharpToVBConverterVisitor : CSharp.IAstVisitor + { + public AstNode VisitAnonymousMethodExpression(CSharp.AnonymousMethodExpression anonymousMethodExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitUndocumentedExpression(CSharp.UndocumentedExpression undocumentedExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitArrayCreateExpression(CSharp.ArrayCreateExpression arrayCreateExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitArrayInitializerExpression(CSharp.ArrayInitializerExpression arrayInitializerExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitAsExpression(CSharp.AsExpression asExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitAssignmentExpression(CSharp.AssignmentExpression assignmentExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitBaseReferenceExpression(CSharp.BaseReferenceExpression baseReferenceExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitBinaryOperatorExpression(CSharp.BinaryOperatorExpression binaryOperatorExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCastExpression(CSharp.CastExpression castExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCheckedExpression(CSharp.CheckedExpression checkedExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitConditionalExpression(CSharp.ConditionalExpression conditionalExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitDefaultValueExpression(CSharp.DefaultValueExpression defaultValueExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitDirectionExpression(CSharp.DirectionExpression directionExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitIdentifierExpression(CSharp.IdentifierExpression identifierExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitIndexerExpression(CSharp.IndexerExpression indexerExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitInvocationExpression(CSharp.InvocationExpression invocationExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitIsExpression(CSharp.IsExpression isExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitLambdaExpression(CSharp.LambdaExpression lambdaExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitMemberReferenceExpression(CSharp.MemberReferenceExpression memberReferenceExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitNamedArgumentExpression(CSharp.NamedArgumentExpression namedArgumentExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitNullReferenceExpression(CSharp.NullReferenceExpression nullReferenceExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitObjectCreateExpression(CSharp.ObjectCreateExpression objectCreateExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitAnonymousTypeCreateExpression(CSharp.AnonymousTypeCreateExpression anonymousTypeCreateExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitParenthesizedExpression(CSharp.ParenthesizedExpression parenthesizedExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitPointerReferenceExpression(CSharp.PointerReferenceExpression pointerReferenceExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitPrimitiveExpression(CSharp.PrimitiveExpression primitiveExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitSizeOfExpression(CSharp.SizeOfExpression sizeOfExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitStackAllocExpression(CSharp.StackAllocExpression stackAllocExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitThisReferenceExpression(CSharp.ThisReferenceExpression thisReferenceExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitTypeOfExpression(CSharp.TypeOfExpression typeOfExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitTypeReferenceExpression(CSharp.TypeReferenceExpression typeReferenceExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitUnaryOperatorExpression(CSharp.UnaryOperatorExpression unaryOperatorExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitUncheckedExpression(CSharp.UncheckedExpression uncheckedExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitEmptyExpression(CSharp.EmptyExpression emptyExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryExpression(CSharp.QueryExpression queryExpression, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryContinuationClause(CSharp.QueryContinuationClause queryContinuationClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryFromClause(CSharp.QueryFromClause queryFromClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryLetClause(CSharp.QueryLetClause queryLetClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryWhereClause(CSharp.QueryWhereClause queryWhereClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryJoinClause(CSharp.QueryJoinClause queryJoinClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryOrderClause(CSharp.QueryOrderClause queryOrderClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryOrdering(CSharp.QueryOrdering queryOrdering, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQuerySelectClause(CSharp.QuerySelectClause querySelectClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitQueryGroupClause(CSharp.QueryGroupClause queryGroupClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitAttribute(CSharp.Attribute attribute, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitAttributeSection(CSharp.AttributeSection attributeSection, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitDelegateDeclaration(CSharp.DelegateDeclaration delegateDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitNamespaceDeclaration(CSharp.NamespaceDeclaration namespaceDeclaration, object data) + { + var newNamespace = new NamespaceDeclaration(); + + ConvertNodes(namespaceDeclaration.Identifiers, newNamespace.Identifiers); + ConvertNodes(namespaceDeclaration.Members, newNamespace.Members); + + return EndNode(namespaceDeclaration, newNamespace); + } + + public AstNode VisitTypeDeclaration(CSharp.TypeDeclaration typeDeclaration, object data) + { + var type = new TypeDeclaration(); + + return EndNode(typeDeclaration, type); + } + + public AstNode VisitUsingAliasDeclaration(CSharp.UsingAliasDeclaration usingAliasDeclaration, object data) + { + var imports = new ImportsStatement(); + + var clause = new AliasImportsClause() { + Name = new Identifier(usingAliasDeclaration.Alias, AstLocation.Empty), + Alias = (AstType)usingAliasDeclaration.Import.AcceptVisitor(this, data) + }; + + imports.AddChild(clause, ImportsStatement.ImportsClauseRole); + + return EndNode(usingAliasDeclaration, imports); + } + + public AstNode VisitUsingDeclaration(CSharp.UsingDeclaration usingDeclaration, object data) + { + var imports = new ImportsStatement(); + + var clause = new MemberImportsClause() { + Member = (AstType)usingDeclaration.Import.AcceptVisitor(this, data) + }; + + imports.AddChild(clause, ImportsStatement.ImportsClauseRole); + + return EndNode(usingDeclaration, imports); + } + + public AstNode VisitExternAliasDeclaration(CSharp.ExternAliasDeclaration externAliasDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitBlockStatement(CSharp.BlockStatement blockStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitBreakStatement(CSharp.BreakStatement breakStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCheckedStatement(CSharp.CheckedStatement checkedStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitContinueStatement(CSharp.ContinueStatement continueStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitDoWhileStatement(CSharp.DoWhileStatement doWhileStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitEmptyStatement(CSharp.EmptyStatement emptyStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitExpressionStatement(CSharp.ExpressionStatement expressionStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitFixedStatement(CSharp.FixedStatement fixedStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitForeachStatement(CSharp.ForeachStatement foreachStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitForStatement(CSharp.ForStatement forStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitGotoCaseStatement(CSharp.GotoCaseStatement gotoCaseStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitGotoDefaultStatement(CSharp.GotoDefaultStatement gotoDefaultStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitGotoStatement(CSharp.GotoStatement gotoStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitIfElseStatement(CSharp.IfElseStatement ifElseStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitLabelStatement(CSharp.LabelStatement labelStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitLockStatement(CSharp.LockStatement lockStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitReturnStatement(CSharp.ReturnStatement returnStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitSwitchStatement(CSharp.SwitchStatement switchStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitSwitchSection(CSharp.SwitchSection switchSection, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCaseLabel(CSharp.CaseLabel caseLabel, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitThrowStatement(CSharp.ThrowStatement throwStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitTryCatchStatement(CSharp.TryCatchStatement tryCatchStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCatchClause(CSharp.CatchClause catchClause, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitUncheckedStatement(CSharp.UncheckedStatement uncheckedStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitUnsafeStatement(CSharp.UnsafeStatement unsafeStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitUsingStatement(CSharp.UsingStatement usingStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitVariableDeclarationStatement(CSharp.VariableDeclarationStatement variableDeclarationStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitWhileStatement(CSharp.WhileStatement whileStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitYieldBreakStatement(CSharp.YieldBreakStatement yieldBreakStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitYieldStatement(CSharp.YieldStatement yieldStatement, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitAccessor(CSharp.Accessor accessor, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitConstructorDeclaration(CSharp.ConstructorDeclaration constructorDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitConstructorInitializer(CSharp.ConstructorInitializer constructorInitializer, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitDestructorDeclaration(CSharp.DestructorDeclaration destructorDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitEnumMemberDeclaration(CSharp.EnumMemberDeclaration enumMemberDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitEventDeclaration(CSharp.EventDeclaration eventDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCustomEventDeclaration(CSharp.CustomEventDeclaration customEventDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitFieldDeclaration(CSharp.FieldDeclaration fieldDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitIndexerDeclaration(CSharp.IndexerDeclaration indexerDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitMethodDeclaration(CSharp.MethodDeclaration methodDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitOperatorDeclaration(CSharp.OperatorDeclaration operatorDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitParameterDeclaration(CSharp.ParameterDeclaration parameterDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitPropertyDeclaration(CSharp.PropertyDeclaration propertyDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitVariableInitializer(CSharp.VariableInitializer variableInitializer, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitFixedFieldDeclaration(CSharp.FixedFieldDeclaration fixedFieldDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitFixedVariableInitializer(CSharp.FixedVariableInitializer fixedVariableInitializer, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCompilationUnit(CSharp.CompilationUnit compilationUnit, object data) + { + var unit = new CompilationUnit(); + + foreach (var node in compilationUnit.Children) + unit.AddChild(node.AcceptVisitor(this, null), CompilationUnit.MemberRole); + + return EndNode(compilationUnit, unit); + } + + public AstNode VisitSimpleType(CSharp.SimpleType simpleType, object data) + { + var type = new SimpleType(simpleType.Identifier); + ConvertNodes(simpleType.TypeArguments, type.TypeArguments); + + return EndNode(simpleType, type); + } + + public AstNode VisitMemberType(CSharp.MemberType memberType, object data) + { + AstType target = null; + + if (memberType.Target is CSharp.SimpleType && ((CSharp.SimpleType)(memberType.Target)).Identifier.Equals("global", StringComparison.Ordinal)) + target = new PrimitiveType("Global"); + else + target = (AstType)memberType.Target.AcceptVisitor(this, data); + + var type = new QualifiedType(target, new Identifier(memberType.MemberName, AstLocation.Empty)); + + return EndNode(memberType, type); + } + + public AstNode VisitComposedType(CSharp.ComposedType composedType, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitArraySpecifier(CSharp.ArraySpecifier arraySpecifier, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitPrimitiveType(CSharp.PrimitiveType primitiveType, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitComment(CSharp.Comment comment, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitTypeParameterDeclaration(CSharp.TypeParameterDeclaration typeParameterDeclaration, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitConstraint(CSharp.Constraint constraint, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitCSharpTokenNode(CSharp.CSharpTokenNode cSharpTokenNode, object data) + { + throw new NotImplementedException(); + } + + public AstNode VisitIdentifier(CSharp.Identifier identifier, object data) + { + var ident = new Identifier(identifier.Name, ConvertLocation(identifier.StartLocation)); + + return EndNode(identifier, ident); + } + + public AstNode VisitPatternPlaceholder(CSharp.AstNode placeholder, ICSharpCode.NRefactory.PatternMatching.Pattern pattern, object data) + { + throw new NotImplementedException(); + } + + void ConvertNodes(IEnumerable nodes, VB.AstNodeCollection result) where T : VB.AstNode + { + foreach (var node in nodes) + result.Add((T)node.AcceptVisitor(this, null)); + } + + AstLocation ConvertLocation(CSharp.AstLocation location) + { + return new AstLocation(location.Line, location.Column); + } + + T EndNode(CSharp.AstNode node, T result) where T : VB.AstNode + { + return result; + } + } +} From b9dc346330f981e2e542de24e276fec21bcfd77a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 8 May 2011 21:32:56 +0200 Subject: [PATCH 02/57] implement Attribute conversion --- .../OutputVisitor/OutputVisitor.cs | 78 +++++++++++++++++-- .../Visitors/CSharpToVBConverterVisitor.cs | 58 +++++++++++++- 2 files changed, 129 insertions(+), 7 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 907e1a6178..e16957fe8a 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; - using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.VB.Ast; @@ -95,12 +94,28 @@ namespace ICSharpCode.NRefactory.VB public object VisitAttribute(ICSharpCode.NRefactory.VB.Ast.Attribute attribute, object data) { - throw new NotImplementedException(); + StartNode(attribute); + + if (!attribute.Target.IsNull) { + attribute.Target.AcceptVisitor(this, data); + WriteToken(":", VB.Ast.Attribute.TargetRole); + } + attribute.Type.AcceptVisitor(this, data); + WriteCommaSeparatedListInParenthesis(attribute.Arguments, false); + + return EndNode(attribute); } public object VisitAttributeBlock(AttributeBlock attributeBlock, object data) { - throw new NotImplementedException(); + StartNode(attributeBlock); + + WriteToken("<", AttributeBlock.Roles.LChevron); + WriteCommaSeparatedList(attributeBlock.Attributes); + WriteToken(">", AttributeBlock.Roles.RChevron); + NewLine(); + + return EndNode(attributeBlock); } public object VisitImportsStatement(ImportsStatement importsStatement, object data) @@ -136,6 +151,17 @@ namespace ICSharpCode.NRefactory.VB node.AcceptVisitor(this, null); } NewLine(); + Indent(); + isFirst = true; + foreach (var member in namespaceDeclaration.Members) { + if (isFirst) { + isFirst = false; + } else { + NewLine(); + } + member.AcceptVisitor(this, data); + } + Unindent(); WriteKeyword("End"); WriteKeyword("Namespace"); NewLine(); @@ -149,7 +175,40 @@ namespace ICSharpCode.NRefactory.VB public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { - throw new NotImplementedException(); + StartNode(typeDeclaration); + WriteAttributes(typeDeclaration.Attributes); + WriteModifiers(typeDeclaration.ModifierTokens); + WriteClassTypeKeyword(typeDeclaration); + WriteIdentifier(typeDeclaration.Name.Name); + NewLine(); + + WriteKeyword("End"); + WriteClassTypeKeyword(typeDeclaration); + NewLine(); + return EndNode(typeDeclaration); + } + + void WriteClassTypeKeyword(TypeDeclaration typeDeclaration) + { + switch (typeDeclaration.ClassType) { + case ICSharpCode.NRefactory.TypeSystem.ClassType.Class: + WriteKeyword("Class"); + break; + case ICSharpCode.NRefactory.TypeSystem.ClassType.Enum: + break; + case ICSharpCode.NRefactory.TypeSystem.ClassType.Interface: + break; + case ICSharpCode.NRefactory.TypeSystem.ClassType.Struct: + WriteKeyword("Structure"); + break; + case ICSharpCode.NRefactory.TypeSystem.ClassType.Delegate: + break; + case ICSharpCode.NRefactory.TypeSystem.ClassType.Module: + WriteKeyword("Module"); + break; + default: + throw new Exception("Invalid value for ClassType"); + } } public object VisitXmlNamespaceImportsClause(XmlNamespaceImportsClause xmlNamespaceImportsClause, object data) @@ -362,7 +421,6 @@ namespace ICSharpCode.NRefactory.VB void Comma(AstNode nextNode, bool noSpaceAfterComma = false) { WriteSpecialsUpToRole(AstNode.Roles.Comma, nextNode); - Space(); // TODO: Comma policy has changed. formatter.WriteToken(","); lastWritten = LastWritten.Other; Space(!noSpaceAfterComma); // TODO: Comma policy has changed. @@ -577,6 +635,16 @@ namespace ICSharpCode.NRefactory.VB formatter.NewLine(); lastWritten = LastWritten.Whitespace; } + + void Indent() + { + formatter.Indent(); + } + + void Unindent() + { + formatter.Unindent(); + } #endregion #region IsKeyword Test diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 0077ab687a..4a3cc0609b 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -3,15 +3,31 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.VB.Ast; namespace ICSharpCode.NRefactory.VB.Visitors { + public interface IEnvironmentProvider + { + string RootNamespace { get; } + string GetTypeNameForAttribute(CSharp.Attribute attribute); + } + /// /// Description of CSharpToVBConverterVisitor. /// public class CSharpToVBConverterVisitor : CSharp.IAstVisitor { + IEnvironmentProvider provider; + + public CSharpToVBConverterVisitor(IEnvironmentProvider provider) + { + this.provider = provider; + } + public AstNode VisitAnonymousMethodExpression(CSharp.AnonymousMethodExpression anonymousMethodExpression, object data) { throw new NotImplementedException(); @@ -234,12 +250,21 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAttribute(CSharp.Attribute attribute, object data) { - throw new NotImplementedException(); + var attr = new VB.Ast.Attribute(); + + // TODO : attribute targets + + attr.Type = (AstType)attribute.Type.AcceptVisitor(this, data); +// ConvertNodes(attribute.Arguments, attr.Arguments); + + return EndNode(attribute, attr); } public AstNode VisitAttributeSection(CSharp.AttributeSection attributeSection, object data) { - throw new NotImplementedException(); + AttributeBlock block = new AttributeBlock(); + ConvertNodes(attributeSection.Attributes, block.Attributes); + return EndNode(attributeSection, block); } public AstNode VisitDelegateDeclaration(CSharp.DelegateDeclaration delegateDeclaration, object data) @@ -261,6 +286,23 @@ namespace ICSharpCode.NRefactory.VB.Visitors { var type = new TypeDeclaration(); + CSharp.Attribute stdModAttr; + + if (typeDeclaration.ClassType == ClassType.Class && HasAttribute(typeDeclaration.Attributes, "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute", out stdModAttr)) { + type.ClassType = ClassType.Module; + // remove AttributeSection if only one attribute is present + var attrSec = (CSharp.AttributeSection)stdModAttr.Parent; + if (attrSec.Attributes.Count == 1) + attrSec.Remove(); + else + stdModAttr.Remove(); + } else + type.ClassType = typeDeclaration.ClassType; + + ConvertNodes(typeDeclaration.Attributes, type.Attributes); + + type.Name = new Identifier(typeDeclaration.Name, AstLocation.Empty); + return EndNode(typeDeclaration, type); } @@ -620,5 +662,17 @@ namespace ICSharpCode.NRefactory.VB.Visitors { return result; } + + bool HasAttribute(CSharp.AstNodeCollection attributes, string name, out CSharp.Attribute foundAttribute) + { + foreach (var attr in attributes.SelectMany(a => a.Attributes)) { + if (provider.GetTypeNameForAttribute(attr) == name) { + foundAttribute = attr; + return true; + } + } + foundAttribute = null; + return false; + } } } From b3ec92a6edfa9f84f5e5d9760ce8366e21b8586c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 May 2011 06:17:09 +0200 Subject: [PATCH 03/57] implement AddressOfExpression, InstanceExpression, ParenthesizedExpression and SimpleNameExpression --- .../Ast/Expressions/AddressOfExpression.cs | 31 ++++++++++ .../Ast/Expressions/InstanceExpression.cs | 61 +++++++++++++++++++ .../Expressions/ParenthesizedExpression.cs | 34 +++++++++++ .../Ast/Expressions/SimpleNameExpression.cs | 9 ++- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 3 + .../ICSharpCode.NRefactory.VB.csproj | 3 + .../OutputVisitor/OutputVisitor.cs | 55 ++++++++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 14 ++++- 8 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs new file mode 100644 index 0000000000..81eaca8126 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs @@ -0,0 +1,31 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class AddressOfExpression : Expression + { + public AddressOfExpression() + { + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as AddressOfExpression; + return expr != null && + Expression.DoMatch(expr.Expression, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAddressOfExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs new file mode 100644 index 0000000000..80e376524b --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs @@ -0,0 +1,61 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of InstanceExpression. + /// + public class InstanceExpression : Expression + { + AstLocation location; + + public InstanceExpression(InstanceExpressionType type, AstLocation location) + { + this.Type = type; + this.location = location; + } + + public override AstLocation StartLocation { + get { return location; } + } + + public override AstLocation EndLocation { + get { + switch (Type) { + case InstanceExpressionType.Me: + return new AstLocation(location.Line, location.Column + "Me".Length); + case InstanceExpressionType.MyBase: + return new AstLocation(location.Line, location.Column + "MyBase".Length); + case InstanceExpressionType.MyClass: + return new AstLocation(location.Line, location.Column + "MyClass".Length); + default: + throw new Exception("Invalid value for InstanceExpressionType"); + } + } + } + + public InstanceExpressionType Type { get; set; } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as InstanceExpression; + return expr != null && + Type == expr.Type; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitInstanceExpression(this, data); + } + } + + public enum InstanceExpressionType + { + Me, + MyBase, + MyClass + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs new file mode 100644 index 0000000000..492426b668 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs @@ -0,0 +1,34 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of ParenthesizedExpression. + /// + public class ParenthesizedExpression : Expression + { + public ParenthesizedExpression() + { + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as ParenthesizedExpression; + return expr != null && + Expression.DoMatch(expr.Expression, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitParenthesizedExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs index 257b8e744a..e3493784a2 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs @@ -6,17 +6,22 @@ using System; namespace ICSharpCode.NRefactory.VB.Ast { /// - /// Description of IdentifierExpression. + /// Description of SimpleNameExpression. /// public class SimpleNameExpression : Expression { public Identifier Identifier { get; set; } + public AstNodeCollection TypeArguments { + get { return GetChildrenByRole (Roles.TypeArgument); } + } + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { var node = other as SimpleNameExpression; return node != null - && Identifier.DoMatch(node.Identifier, match); + && Identifier.DoMatch(node.Identifier, match) + && TypeArguments.DoMatch(node.TypeArguments, match); } public override S AcceptVisitor(IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index eb96f229d4..5c482efa53 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -35,6 +35,9 @@ namespace ICSharpCode.NRefactory.VB { S VisitXmlLiteralString(XmlLiteralString xmlLiteralString, T data); S VisitSimpleNameExpression(SimpleNameExpression identifierExpression, T data); S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); + S VisitInstanceExpression(InstanceExpression instanceExpression, T data); + S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data); + S VisitAddressOfExpression(AddressOfExpression addressOfExpression, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index a14f015508..f6deb3479d 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -47,7 +47,10 @@ + + + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index e16957fe8a..d498e54292 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -249,9 +249,14 @@ namespace ICSharpCode.NRefactory.VB throw new NotImplementedException(); } - public object VisitSimpleNameExpression(SimpleNameExpression identifierExpression, object data) + public object VisitSimpleNameExpression(SimpleNameExpression simpleNameExpression, object data) { - throw new NotImplementedException(); + StartNode(simpleNameExpression); + + simpleNameExpression.Identifier.AcceptVisitor(this, data); + WriteTypeArguments(simpleNameExpression.TypeArguments); + + return EndNode(simpleNameExpression); } public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) @@ -259,6 +264,49 @@ namespace ICSharpCode.NRefactory.VB throw new NotImplementedException(); } + public object VisitInstanceExpression(InstanceExpression instanceExpression, object data) + { + StartNode(instanceExpression); + + switch (instanceExpression.Type) { + case InstanceExpressionType.Me: + WriteKeyword("Me"); + break; + case InstanceExpressionType.MyBase: + WriteKeyword("MyBase"); + break; + case InstanceExpressionType.MyClass: + WriteKeyword("MyClass"); + break; + default: + throw new Exception("Invalid value for InstanceExpressionType"); + } + + return EndNode(instanceExpression); + } + + public object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) + { + StartNode(parenthesizedExpression); + + LPar(); + parenthesizedExpression.Expression.AcceptVisitor(this, data); + RPar(); + + return EndNode(parenthesizedExpression); + } + + public object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) + { + StartNode(addressOfExpression); + + WriteKeyword("AddressOf"); + addressOfExpression.Expression.AcceptVisitor(this, data); + + return EndNode(addressOfExpression); + } + + #region TypeName public object VisitPrimitiveType(PrimitiveType primitiveType, object data) { throw new NotImplementedException(); @@ -295,7 +343,9 @@ namespace ICSharpCode.NRefactory.VB return EndNode(simpleType); } + #endregion + #region Pattern Matching public object VisitAnyNode(AnyNode anyNode, object data) { throw new NotImplementedException(); @@ -330,6 +380,7 @@ namespace ICSharpCode.NRefactory.VB { throw new NotImplementedException(); } + #endregion #region StartNode/EndNode void StartNode(AstNode node) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 4a3cc0609b..401bc51634 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -60,7 +60,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitBaseReferenceExpression(CSharp.BaseReferenceExpression baseReferenceExpression, object data) { - throw new NotImplementedException(); + InstanceExpression result = new InstanceExpression(InstanceExpressionType.MyBase, ConvertLocation(baseReferenceExpression.StartLocation)); + + return EndNode(baseReferenceExpression, result); } public AstNode VisitBinaryOperatorExpression(CSharp.BinaryOperatorExpression binaryOperatorExpression, object data) @@ -145,7 +147,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitParenthesizedExpression(CSharp.ParenthesizedExpression parenthesizedExpression, object data) { - throw new NotImplementedException(); + var result = new ParenthesizedExpression(); + + result.Expression = (Expression)parenthesizedExpression.Expression.AcceptVisitor(this, data); + + return EndNode(parenthesizedExpression, result); } public AstNode VisitPointerReferenceExpression(CSharp.PointerReferenceExpression pointerReferenceExpression, object data) @@ -170,7 +176,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitThisReferenceExpression(CSharp.ThisReferenceExpression thisReferenceExpression, object data) { - throw new NotImplementedException(); + InstanceExpression result = new InstanceExpression(InstanceExpressionType.Me, ConvertLocation(thisReferenceExpression.StartLocation)); + + return EndNode(thisReferenceExpression, result); } public AstNode VisitTypeOfExpression(CSharp.TypeOfExpression typeOfExpression, object data) From 3a26819995c78ee3fccf7f3b029c8362d0a5d8b1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 May 2011 20:23:09 +0200 Subject: [PATCH 04/57] add GetTypeExpression, GetXmlNamespaceExpression, MemberAccessExpression, TypeOfIsExpression and TypeReferenceExpression --- .../Ast/Expressions/GetTypeExpression.cs | 31 ++++ .../Expressions/GetXmlNamespaceExpression.cs | 32 ++++ .../Ast/Expressions/MemberAccessExpression.cs | 42 +++++ .../Ast/Expressions/SimpleNameExpression.cs | 2 +- .../Ast/Expressions/TypeOfIsExpression.cs | 37 +++++ .../Expressions/TypeReferenceExpression.cs | 39 +++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 5 + .../ICSharpCode.NRefactory.VB.csproj | 5 + .../OutputVisitor/OutputVisitor.cs | 149 +++++++++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 17 +- 10 files changed, 353 insertions(+), 6 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs new file mode 100644 index 0000000000..ce118eb638 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs @@ -0,0 +1,31 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class GetTypeExpression : Expression + { + public GetTypeExpression() + { + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as GetTypeExpression; + return expr != null && + Type.DoMatch(expr.Type, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitGetTypeExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs new file mode 100644 index 0000000000..07a5237384 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs @@ -0,0 +1,32 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class GetXmlNamespaceExpression : Expression + { + public GetXmlNamespaceExpression(XmlIdentifier namespaceName) + { + SetChildByRole(Roles.XmlIdentifier, namespaceName); + } + + public XmlIdentifier NamespaceName { + get { return GetChildByRole(Roles.XmlIdentifier); } + set { SetChildByRole(Roles.XmlIdentifier, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as GetXmlNamespaceExpression; + return expr != null && + NamespaceName.DoMatch(expr.NamespaceName, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitGetXmlNamespaceExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs new file mode 100644 index 0000000000..f9da04bcf8 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs @@ -0,0 +1,42 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class MemberAccessExpression : Expression + { + public MemberAccessExpression() + { + } + + public Expression Target { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public Identifier Member { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstNodeCollection TypeArguments { + get { return GetChildrenByRole(Roles.TypeArgument); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as MemberAccessExpression; + return expr != null && + Target.DoMatch(expr.Target, match) && + Member.DoMatch(expr.Member, match) && + TypeArguments.DoMatch(expr.TypeArguments, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitMemberAccessExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs index e3493784a2..82250a8fa3 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public Identifier Identifier { get; set; } public AstNodeCollection TypeArguments { - get { return GetChildrenByRole (Roles.TypeArgument); } + get { return GetChildrenByRole(Roles.TypeArgument); } } protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs new file mode 100644 index 0000000000..a1dfa6ea5f --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs @@ -0,0 +1,37 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class TypeOfIsExpression : Expression + { + public TypeOfIsExpression() + { + } + + public Expression TypeOfExpression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as TypeOfIsExpression; + return expr != null && + TypeOfExpression.DoMatch(expr.TypeOfExpression, match) && + Type.DoMatch(expr.Type, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitTypeOfIsExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs new file mode 100644 index 0000000000..cfe920d1eb --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs @@ -0,0 +1,39 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Represents an AstType as an expression. + /// This is used when calling a method on a primitive type: "Integer.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); + } + + public TypeReferenceExpression () + { + } + + public TypeReferenceExpression (AstType type) + { + SetChildByRole(Roles.Type, type); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + TypeReferenceExpression o = other as TypeReferenceExpression; + return o != null && this.Type.DoMatch(o.Type, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 5c482efa53..eba3749035 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -38,6 +38,11 @@ namespace ICSharpCode.NRefactory.VB { S VisitInstanceExpression(InstanceExpression instanceExpression, T data); S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data); S VisitAddressOfExpression(AddressOfExpression addressOfExpression, T data); + S VisitGetTypeExpression(GetTypeExpression getTypeExpression, T data); + S VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, T data); + S VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, T data); + S VisitMemberAccessExpression(MemberAccessExpression memberAccessExpression, T data); + S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index f6deb3479d..c2c6c1dbff 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -49,10 +49,15 @@ + + + + + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index d498e54292..4bba92a926 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -4,8 +4,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; +using System.Text; + using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.VB.Ast; @@ -261,7 +264,11 @@ namespace ICSharpCode.NRefactory.VB public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) { - throw new NotImplementedException(); + StartNode(primitiveExpression); + + WritePrimitiveValue(primitiveExpression.Value); + + return EndNode(primitiveExpression); } public object VisitInstanceExpression(InstanceExpression instanceExpression, object data) @@ -306,6 +313,43 @@ namespace ICSharpCode.NRefactory.VB return EndNode(addressOfExpression); } + + public object VisitGetTypeExpression(GetTypeExpression getTypeExpression, object data) + { + throw new NotImplementedException(); + } + + public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) + { + throw new NotImplementedException(); + } + + public object VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, object data) + { + throw new NotImplementedException(); + } + + public object VisitMemberAccessExpression(MemberAccessExpression memberAccessExpression, object data) + { + StartNode(memberAccessExpression); + + memberAccessExpression.Target.AcceptVisitor(this, data); + WriteToken(".", MemberAccessExpression.Roles.Dot); + memberAccessExpression.Member.AcceptVisitor(this, data); + WriteTypeArguments(memberAccessExpression.TypeArguments); + + return EndNode(memberAccessExpression); + } + + public object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) + { + StartNode(typeReferenceExpression); + + typeReferenceExpression.Type.AcceptVisitor(this, data); + + return EndNode(typeReferenceExpression); + } + #region TypeName public object VisitPrimitiveType(PrimitiveType primitiveType, object data) { @@ -818,6 +862,109 @@ namespace ICSharpCode.NRefactory.VB WriteToken(".", AstNode.Roles.Dot); } } + + void WritePrimitiveValue(object val) + { + if (val == null) { + WriteKeyword("Nothing"); + return; + } + + if (val is bool) { + if ((bool)val) { + WriteKeyword("True"); + } else { + WriteKeyword("False"); + } + return; + } + + if (val is string) { + formatter.WriteToken("\"" + ConvertString(val.ToString()) + "\""); + lastWritten = LastWritten.Other; + } else if (val is char) { + formatter.WriteToken("\"" + ConvertCharLiteral((char)val) + "\"c"); + lastWritten = LastWritten.Other; + } else if (val is decimal) { + formatter.WriteToken(((decimal)val).ToString(NumberFormatInfo.InvariantInfo) + "D"); + lastWritten = LastWritten.Other; + } else if (val is float) { + float f = (float)val; + if (float.IsInfinity(f) || float.IsNaN(f)) { + // Strictly speaking, these aren't PrimitiveExpressions; + // but we still support writing these to make life easier for code generators. + WriteKeyword("Single"); + WriteToken(".", AstNode.Roles.Dot); + if (float.IsPositiveInfinity(f)) + WriteIdentifier("PositiveInfinity"); + else if (float.IsNegativeInfinity(f)) + WriteIdentifier("NegativeInfinity"); + else + WriteIdentifier("NaN"); + return; + } + formatter.WriteToken(f.ToString("R", NumberFormatInfo.InvariantInfo) + "F"); + lastWritten = LastWritten.Other; + } else if (val is double) { + double f = (double)val; + if (double.IsInfinity(f) || double.IsNaN(f)) { + // Strictly speaking, these aren't PrimitiveExpressions; + // but we still support writing these to make life easier for code generators. + WriteKeyword("Double"); + WriteToken(".", AstNode.Roles.Dot); + if (double.IsPositiveInfinity(f)) + WriteIdentifier("PositiveInfinity"); + else if (double.IsNegativeInfinity(f)) + WriteIdentifier("NegativeInfinity"); + else + WriteIdentifier("NaN"); + return; + } + string number = f.ToString("R", NumberFormatInfo.InvariantInfo); + if (number.IndexOf('.') < 0 && number.IndexOf('E') < 0) + number += ".0"; + formatter.WriteToken(number); + // needs space if identifier follows number; this avoids mistaking the following identifier as type suffix + lastWritten = LastWritten.KeywordOrIdentifier; + } else if (val is IFormattable) { + StringBuilder b = new StringBuilder(); +// if (primitiveExpression.LiteralFormat == LiteralFormat.HexadecimalNumber) { +// b.Append("0x"); +// b.Append(((IFormattable)val).ToString("x", NumberFormatInfo.InvariantInfo)); +// } else { + b.Append(((IFormattable)val).ToString(null, NumberFormatInfo.InvariantInfo)); +// } + if (val is uint || val is ulong) { + b.Append("U"); + } + if (val is long || val is ulong) { + b.Append("L"); + } + formatter.WriteToken(b.ToString()); + // needs space if identifier follows number; this avoids mistaking the following identifier as type suffix + lastWritten = LastWritten.KeywordOrIdentifier; + } else { + formatter.WriteToken(val.ToString()); + lastWritten = LastWritten.Other; + } + } + #endregion + + #region ConvertLiteral + static string ConvertCharLiteral(char ch) + { + if (ch == '"') return "\"\""; + return ch.ToString(); + } + + static string ConvertString(string str) + { + StringBuilder sb = new StringBuilder(); + foreach (char ch in str) { + sb.Append(ConvertCharLiteral(ch)); + } + return sb.ToString(); + } #endregion } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 401bc51634..160f30ab2f 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -122,7 +122,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitMemberReferenceExpression(CSharp.MemberReferenceExpression memberReferenceExpression, object data) { - throw new NotImplementedException(); + var memberAccessExpression = new MemberAccessExpression(); + + memberAccessExpression.Target = (Expression)memberReferenceExpression.Target.AcceptVisitor(this, data); + memberAccessExpression.Member = new Identifier(memberReferenceExpression.MemberName, AstLocation.Empty); + ConvertNodes(memberReferenceExpression.TypeArguments, memberAccessExpression.TypeArguments); + + return EndNode(memberReferenceExpression, memberAccessExpression); } public AstNode VisitNamedArgumentExpression(CSharp.NamedArgumentExpression namedArgumentExpression, object data) @@ -161,7 +167,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitPrimitiveExpression(CSharp.PrimitiveExpression primitiveExpression, object data) { - throw new NotImplementedException(); + var expr = new PrimitiveExpression(primitiveExpression.Value); + + return EndNode(primitiveExpression, expr); } public AstNode VisitSizeOfExpression(CSharp.SizeOfExpression sizeOfExpression, object data) @@ -188,7 +196,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitTypeReferenceExpression(CSharp.TypeReferenceExpression typeReferenceExpression, object data) { - throw new NotImplementedException(); + var expr = new TypeReferenceExpression((AstType)typeReferenceExpression.Type.AcceptVisitor(this, data)); + return EndNode(typeReferenceExpression, expr); } public AstNode VisitUnaryOperatorExpression(CSharp.UnaryOperatorExpression unaryOperatorExpression, object data) @@ -263,7 +272,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors // TODO : attribute targets attr.Type = (AstType)attribute.Type.AcceptVisitor(this, data); -// ConvertNodes(attribute.Arguments, attr.Arguments); + ConvertNodes(attribute.Arguments, attr.Arguments); return EndNode(attribute, attr); } From 43cf583e81d5ef9227e456ef6e3403b54455263f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 May 2011 05:53:48 +0200 Subject: [PATCH 05/57] add MethodDeclaration, ConstructorDeclaration; EventMemberSpecifier, InterfaceMemberSpecifier for Handles and Implements clauses --- ICSharpCode.NRefactory.VB/Ast/AstNode.cs | 2 +- .../Ast/General/AttributedNode.cs | 2 +- .../Ast/General/EventMemberSpecifier.cs | 39 +++++ .../Ast/General/InterfaceMemberSpecifier.cs | 47 ++++++ .../Ast/TypeMembers/ConstructorDeclaration.cs | 40 ++++++ .../Ast/TypeMembers/MethodDeclaration.cs | 72 ++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 6 + .../ICSharpCode.NRefactory.VB.csproj | 5 + .../OutputVisitor/OutputVisitor.cs | 134 ++++++++++++++++-- .../Visitors/CSharpToVBConverterVisitor.cs | 76 +++++++++- 10 files changed, 403 insertions(+), 20 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs index d66abad926..2d69dc3ec8 100644 --- a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -676,7 +676,7 @@ namespace ICSharpCode.NRefactory.VB public static readonly Role XmlIdentifier = new Role("XmlIdentifier", Ast.XmlIdentifier.Null); public static readonly Role XmlLiteralString = new Role("XmlLiteralString", Ast.XmlLiteralString.Null); -// public static readonly Role Body = new Role("Body", CSharp.BlockStatement.Null); + public static readonly Role Body = new Role("Body", Ast.BlockStatement.Null); public static readonly Role Parameter = new Role("Parameter"); public static readonly Role Argument = new Role("Argument", Ast.Expression.Null); public static readonly Role Type = new Role("Type", AstType.Null); diff --git a/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs b/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs index 37e364ee6b..160ab9145b 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs @@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.VB.Ast set { SetModifiers(this, value); } } - public IEnumerable ModifierTokens { + public AstNodeCollection ModifierTokens { get { return GetChildrenByRole (ModifierRole); } } diff --git a/ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs b/ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs new file mode 100644 index 0000000000..5550ed53ae --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs @@ -0,0 +1,39 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class EventMemberSpecifier : AstNode + { + public static readonly Role EventMemberSpecifierRole = new Role("EventMemberSpecifier"); + + public EventMemberSpecifier() + { + } + + public Expression Target { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public Identifier Member { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as EventMemberSpecifier; + return expr != null && + Target.DoMatch(expr.Target, match) && + Member.DoMatch(expr.Member, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitEventMemberSpecifier(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs b/ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs new file mode 100644 index 0000000000..1cf0610188 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs @@ -0,0 +1,47 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class InterfaceMemberSpecifier : AstNode + { + public static readonly Role InterfaceMemberSpecifierRole = new Role("InterfaceMemberSpecifier"); + + public InterfaceMemberSpecifier(Expression target, Identifier member) + { + Target = target; + Member = member; + } + + public InterfaceMemberSpecifier(AstType target, string member) + { + Target = new TypeReferenceExpression(target); + Member = new Identifier(member, AstLocation.Empty); + } + + public Expression Target { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public Identifier Member { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var expr = other as InterfaceMemberSpecifier; + return expr != null && + Target.DoMatch(expr.Target, match) && + Member.DoMatch(expr.Member, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitInterfaceMemberSpecifier(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs new file mode 100644 index 0000000000..e5a0b8a9fa --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs @@ -0,0 +1,40 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Description of ConstructorDeclaration. + /// + public class ConstructorDeclaration : AttributedNode + { + public ConstructorDeclaration() + { + } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var ctor = other as ConstructorDeclaration; + return ctor != null && + MatchAttributesAndModifiers(ctor, match) && + Parameters.DoMatch(ctor.Parameters, match) && + Body.DoMatch(ctor.Body, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitConstructorDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs new file mode 100644 index 0000000000..4cbe73da28 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs @@ -0,0 +1,72 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class MethodDeclaration : AttributedNode + { + public MethodDeclaration() + { + } + + public bool IsSub { get; set; } + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstNodeCollection TypeParameters { + get { return GetChildrenByRole(Roles.TypeParameter); } + } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public AstNodeCollection ReturnTypeAttributes { + get { return GetChildrenByRole(AttributeBlock.ReturnTypeAttributeBlockRole); } + } + + public AstType ReturnType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public AstNodeCollection HandlesClause { + get { return GetChildrenByRole(EventMemberSpecifier.EventMemberSpecifierRole); } + } + + public AstNodeCollection ImplementsClause { + get { return GetChildrenByRole(InterfaceMemberSpecifier.InterfaceMemberSpecifierRole); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var method = other as MethodDeclaration; + return method != null && + MatchAttributesAndModifiers(method, match) && + IsSub == method.IsSub && + Name.DoMatch(method.Name, match) && + TypeParameters.DoMatch(method.TypeParameters, match) && + Parameters.DoMatch(method.Parameters, match) && + ReturnTypeAttributes.DoMatch(method.ReturnTypeAttributes, match) && + ReturnType.DoMatch(method.ReturnType, match) && + HandlesClause.DoMatch(method.HandlesClause, match) && + ImplementsClause.DoMatch(method.ImplementsClause, match) && + Body.DoMatch(method.Body, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitMethodDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index eba3749035..1b702c15af 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -14,6 +14,8 @@ namespace ICSharpCode.NRefactory.VB { S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data); S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data); S VisitVBTokenNode(VBTokenNode vBTokenNode, T data); + S VisitEventMemberSpecifier(EventMemberSpecifier eventMemberSpecifier, T data); + S VisitInterfaceMemberSpecifier(InterfaceMemberSpecifier interfaceMemberSpecifier, T data); // Global scope S VisitAliasImportsClause(AliasImportsClause aliasImportsClause, T data); @@ -29,6 +31,10 @@ namespace ICSharpCode.NRefactory.VB { S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data); S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data); + // TypeMember scope + S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data); + S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data); + // Expression scope S VisitIdentifier(Identifier identifier, T data); S VisitXmlIdentifier(XmlIdentifier xmlIdentifier, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index c2c6c1dbff..d826ea8b5f 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -64,6 +64,8 @@ + + @@ -79,6 +81,8 @@ + + @@ -139,6 +143,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 4bba92a926..7e26773403 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -87,7 +87,14 @@ namespace ICSharpCode.NRefactory.VB public object VisitVBTokenNode(VBTokenNode vBTokenNode, object data) { - throw new NotImplementedException(); + var mod = vBTokenNode as VBModifierToken; + if (mod != null) { + StartNode(vBTokenNode); + WriteKeyword(VBModifierToken.GetModifierName(mod.Modifier)); + return EndNode(vBTokenNode); + } else { + throw new NotSupportedException("Should never visit individual tokens"); + } } public object VisitAliasImportsClause(AliasImportsClause aliasImportsClause, object data) @@ -154,17 +161,7 @@ namespace ICSharpCode.NRefactory.VB node.AcceptVisitor(this, null); } NewLine(); - Indent(); - isFirst = true; - foreach (var member in namespaceDeclaration.Members) { - if (isFirst) { - isFirst = false; - } else { - NewLine(); - } - member.AcceptVisitor(this, data); - } - Unindent(); + WriteMembers(namespaceDeclaration.Members); WriteKeyword("End"); WriteKeyword("Namespace"); NewLine(); @@ -185,6 +182,8 @@ namespace ICSharpCode.NRefactory.VB WriteIdentifier(typeDeclaration.Name.Name); NewLine(); + WriteMembers(typeDeclaration.Members); + WriteKeyword("End"); WriteClassTypeKeyword(typeDeclaration); NewLine(); @@ -350,6 +349,84 @@ namespace ICSharpCode.NRefactory.VB return EndNode(typeReferenceExpression); } + public object VisitEventMemberSpecifier(EventMemberSpecifier eventMemberSpecifier, object data) + { + StartNode(eventMemberSpecifier); + + eventMemberSpecifier.Target.AcceptVisitor(this, data); + WriteToken(".", EventMemberSpecifier.Roles.Dot); + eventMemberSpecifier.Member.AcceptVisitor(this, data); + + return EndNode(eventMemberSpecifier); + } + + public object VisitInterfaceMemberSpecifier(InterfaceMemberSpecifier interfaceMemberSpecifier, object data) + { + StartNode(interfaceMemberSpecifier); + + interfaceMemberSpecifier.Target.AcceptVisitor(this, data); + WriteToken(".", EventMemberSpecifier.Roles.Dot); + interfaceMemberSpecifier.Member.AcceptVisitor(this, data); + + return EndNode(interfaceMemberSpecifier); + } + + #region TypeMembers + public object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) + { + StartNode(constructorDeclaration); + + WriteAttributes(constructorDeclaration.Attributes); + WriteModifiers(constructorDeclaration.ModifierTokens); + WriteKeyword("Sub"); + WriteKeyword("New"); + WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, false); + NewLine(); + + // TODO Body + + WriteKeyword("End"); + WriteKeyword("Sub"); + NewLine(); + + return EndNode(constructorDeclaration); + } + + public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) + { + StartNode(methodDeclaration); + + WriteAttributes(methodDeclaration.Attributes); + WriteModifiers(methodDeclaration.ModifierTokens); + if (methodDeclaration.IsSub) + WriteKeyword("Sub"); + else + WriteKeyword("Function"); + methodDeclaration.Name.AcceptVisitor(this, data); + WriteTypeParameters(methodDeclaration.TypeParameters); + WriteCommaSeparatedListInParenthesis(methodDeclaration.Parameters, false); + if (!methodDeclaration.IsSub) { + WriteKeyword("As"); + WriteAttributes(methodDeclaration.ReturnTypeAttributes); + methodDeclaration.ReturnType.AcceptVisitor(this, data); + } + WriteHandlesClause(methodDeclaration.HandlesClause); + WriteImplementsClause(methodDeclaration.ImplementsClause); + NewLine(); + + // TODO Body + + WriteKeyword("End"); + if (methodDeclaration.IsSub) + WriteKeyword("Sub"); + else + WriteKeyword("Function"); + NewLine(); + + return EndNode(methodDeclaration); + } + #endregion + #region TypeName public object VisitPrimitiveType(PrimitiveType primitiveType, object data) { @@ -840,7 +917,7 @@ namespace ICSharpCode.NRefactory.VB embeddedStatement.AcceptVisitor(this, null); } - void WriteMethodBody(BlockStatement body) + void WriteBlock(BlockStatement body) { if (body.IsNull) NewLine(); @@ -848,6 +925,21 @@ namespace ICSharpCode.NRefactory.VB VisitBlockStatement(body, null); } + void WriteMembers(IEnumerable members) + { + Indent(); + bool isFirst = true; + foreach (var member in members) { + if (isFirst) { + isFirst = false; + } else { + NewLine(); + } + member.AcceptVisitor(this, null); + } + Unindent(); + } + void WriteAttributes(IEnumerable attributes) { foreach (AttributeBlock attr in attributes) { @@ -863,6 +955,22 @@ namespace ICSharpCode.NRefactory.VB } } + void WriteImplementsClause(AstNodeCollection implementsClause) + { + if (implementsClause.Any()) { + WriteKeyword("Implements"); + WriteCommaSeparatedList(implementsClause); + } + } + + void WriteHandlesClause(AstNodeCollection handlesClause) + { + if (handlesClause.Any()) { + WriteKeyword("Handles"); + WriteCommaSeparatedList(handlesClause); + } + } + void WritePrimitiveValue(object val) { if (val == null) { diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 160f30ab2f..8c38d7ce8c 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -301,6 +301,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitTypeDeclaration(CSharp.TypeDeclaration typeDeclaration, object data) { + // TODO add missing features! var type = new TypeDeclaration(); CSharp.Attribute stdModAttr; @@ -317,9 +318,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors type.ClassType = typeDeclaration.ClassType; ConvertNodes(typeDeclaration.Attributes, type.Attributes); + ConvertNodes(typeDeclaration.ModifierTokens, type.ModifierTokens); type.Name = new Identifier(typeDeclaration.Name, AstLocation.Empty); + ConvertNodes(typeDeclaration.Members, type.Members); + return EndNode(typeDeclaration, type); } @@ -512,7 +516,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitConstructorDeclaration(CSharp.ConstructorDeclaration constructorDeclaration, object data) { - throw new NotImplementedException(); + var result = new ConstructorDeclaration(); + + ConvertNodes(constructorDeclaration.Attributes, result.Attributes); + ConvertNodes(constructorDeclaration.ModifierTokens, result.ModifierTokens); + ConvertNodes(constructorDeclaration.Parameters, result.Parameters); + + return EndNode(constructorDeclaration, result); } public AstNode VisitConstructorInitializer(CSharp.ConstructorInitializer constructorInitializer, object data) @@ -552,7 +562,28 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitMethodDeclaration(CSharp.MethodDeclaration methodDeclaration, object data) { - throw new NotImplementedException(); + var result = new MethodDeclaration(); + + ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); + ConvertNodes(methodDeclaration.ModifierTokens, result.ModifierTokens); + result.Name = new Identifier(methodDeclaration.Name, AstLocation.Empty); + result.IsSub = IsSub(methodDeclaration.ReturnType); + ConvertNodes(methodDeclaration.Parameters, result.Parameters); + ConvertNodes(methodDeclaration.TypeParameters, result.TypeParameters); + ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); + result.ImplementsClause.Add( + new InterfaceMemberSpecifier((AstType)methodDeclaration.PrivateImplementationType.AcceptVisitor(this, data), + methodDeclaration.Name)); + if (!result.IsSub) + result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); + + return EndNode(methodDeclaration, result); + } + + bool IsSub(CSharp.AstType returnType) + { + var t = returnType as CSharp.PrimitiveType; + return t != null && t.Keyword == "void"; } public AstNode VisitOperatorDeclaration(CSharp.OperatorDeclaration operatorDeclaration, object data) @@ -649,7 +680,39 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitCSharpTokenNode(CSharp.CSharpTokenNode cSharpTokenNode, object data) { - throw new NotImplementedException(); + var mod = cSharpTokenNode as CSharp.CSharpModifierToken; + if (mod != null) { + var convertedModifiers = ConvertModifiers(mod.Modifier, mod.Parent); + VBModifierToken token = null; + if (convertedModifiers != Modifiers.None) { + token = new VBModifierToken(AstLocation.Empty, convertedModifiers); + return EndNode(cSharpTokenNode, token); + } + return EndNode(cSharpTokenNode, token); + } else { + throw new NotSupportedException("Should never visit individual tokens"); + } + } + + Modifiers ConvertModifiers(CSharp.Modifiers modifier, CSharp.AstNode container) + { + if ((modifier & CSharp.Modifiers.Any) == CSharp.Modifiers.Any) + return Modifiers.Any; + + var mod = Modifiers.None; + + if ((modifier & CSharp.Modifiers.Const) == CSharp.Modifiers.Const) + mod |= Modifiers.Const; + if ((modifier & CSharp.Modifiers.Abstract) == CSharp.Modifiers.Abstract) { + if (container is CSharp.TypeDeclaration) + mod |= Modifiers.MustInherit; + else + mod |= Modifiers.MustOverride; + } + if ((modifier & CSharp.Modifiers.Static) == CSharp.Modifiers.Static) + mod |= Modifiers.Shared; + + return mod; } public AstNode VisitIdentifier(CSharp.Identifier identifier, object data) @@ -666,8 +729,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors void ConvertNodes(IEnumerable nodes, VB.AstNodeCollection result) where T : VB.AstNode { - foreach (var node in nodes) - result.Add((T)node.AcceptVisitor(this, null)); + foreach (var node in nodes) { + T n = (T)node.AcceptVisitor(this, null); + if (n != null) + result.Add(n); + } } AstLocation ConvertLocation(CSharp.AstLocation location) From e0bfac9bd3bbe501c03268f7914adcde000f4d2d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 May 2011 07:26:36 +0200 Subject: [PATCH 06/57] implement proper conversion of FieldDeclaration --- ICSharpCode.NRefactory.VB/Ast/AstNode.cs | 1 + ICSharpCode.NRefactory.VB/Ast/Enums.cs | 7 - .../Expressions/ObjectCreationExpression.cs | 20 +++ .../Ast/General/ParameterDeclaration.cs | 4 +- .../Ast/General/TypeParameterDeclaration.cs | 2 + .../Ast/TypeMembers/ConstructorDeclaration.cs | 7 +- .../Ast/TypeMembers/MethodDeclaration.cs | 84 ++++++++++- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 3 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 84 ++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 137 +++++++++++++++++- 11 files changed, 327 insertions(+), 23 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs index 2d69dc3ec8..6be2284466 100644 --- a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -702,6 +702,7 @@ namespace ICSharpCode.NRefactory.VB public static readonly Role LChevron = new Role("LChevron", VBTokenNode.Null); public static readonly Role RChevron = new Role("RChevron", VBTokenNode.Null); public static readonly Role Comma = new Role("Comma", VBTokenNode.Null); + public static readonly Role QuestionMark = new Role("QuestionMark", VBTokenNode.Null); public static readonly Role Dot = new Role("Dot", VBTokenNode.Null); public static readonly Role Semicolon = new Role("Semicolon", VBTokenNode.Null); public static readonly Role Assign = new Role("Assign", VBTokenNode.Null); diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index d0fc139296..0746032c2c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -67,13 +67,6 @@ namespace ICSharpCode.NRefactory.VB.Ast Ref } - public enum VarianceModifier - { - Invariant, - Covariant, - Contravariant - }; - public enum AssignmentOperatorType { None, diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs new file mode 100644 index 0000000000..f940c71b06 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs @@ -0,0 +1,20 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ObjectCreationExpression : Expression + { + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs index 87b4162b4f..f382cfeb5c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.VB.Ast set { SetChildByRole(Roles.Expression, value); } } - public AstType ReturnType { + public AstType Type { get { return GetChildByRole(Roles.Type); } set { SetChildByRole(Roles.Type, value); } } @@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.VB.Ast MatchAttributesAndModifiers(param, match) && Name.DoMatch(param.Name, match) && OptionalValue.DoMatch(param.OptionalValue, match) && - ReturnType.DoMatch(param.ReturnType, match); + Type.DoMatch(param.Type, match); } public override S AcceptVisitor(IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs index 794615fc2a..bd3c541efa 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.Linq; +using ICSharpCode.NRefactory.TypeSystem; + namespace ICSharpCode.NRefactory.VB.Ast { /// diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs index e5a0b8a9fa..7076d2215a 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs @@ -5,10 +5,15 @@ using System; namespace ICSharpCode.NRefactory.VB.Ast { + public abstract class MemberDeclaration : AttributedNode + { + + } + /// /// Description of ConstructorDeclaration. /// - public class ConstructorDeclaration : AttributedNode + public class ConstructorDeclaration : MemberDeclaration { public ConstructorDeclaration() { diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs index 4cbe73da28..e3614e2f5f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs @@ -5,7 +5,7 @@ using System; namespace ICSharpCode.NRefactory.VB.Ast { - public class MethodDeclaration : AttributedNode + public class MethodDeclaration : MemberDeclaration { public MethodDeclaration() { @@ -69,4 +69,86 @@ namespace ICSharpCode.NRefactory.VB.Ast return visitor.VisitMethodDeclaration(this, data); } } + + /// + /// Attributes? VariableModifier+ VariableDeclarators StatementTerminator + /// + public class FieldDeclaration : MemberDeclaration + { + public AstNodeCollection Variables { + get { return GetChildrenByRole(VariableDeclarator.VariableDeclaratorRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitFieldDeclaration(this, data); + } + } + + /// + /// VariableIdentifiers As ObjectCreationExpression
+ /// VariableIdentifiers ( As TypeName )? ( Equals Expression )? + ///
+ public class VariableDeclarator : AstNode + { + public static readonly Role VariableDeclaratorRole = new Role("VariableDeclarator"); + + public AstNodeCollection Identifiers { + get { return GetChildrenByRole(VariableIdentifier.VariableIdentifierRole); } + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public Expression Initializer { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableDeclarator(this, data); + } + } + + /// + /// Identifier IdentifierModifiers + /// + public class VariableIdentifier : AstNode + { + public static readonly Role VariableIdentifierRole = new Role("VariableIdentifier"); + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public bool HasNullableSpecifier { get; set; } + + public AstNodeCollection ArraySpecifiers { + get { return GetChildrenByRole(ComposedType.ArraySpecifierRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableIdentifier(this, data); + } + } } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 1b702c15af..4f2342273a 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -34,6 +34,9 @@ namespace ICSharpCode.NRefactory.VB { // TypeMember scope S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data); S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data); + S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data); + S VisitVariableDeclarator(VariableDeclarator variableDeclarator, T data); + S VisitVariableIdentifier(VariableIdentifier variableIdentifier, T data); // Expression scope S VisitIdentifier(Identifier identifier, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index d826ea8b5f..4b176c48ad 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -53,6 +53,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 7e26773403..c6f67ebd0c 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -82,7 +82,18 @@ namespace ICSharpCode.NRefactory.VB public object VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, object data) { - throw new NotImplementedException(); + StartNode(parameterDeclaration); + WriteModifiers(parameterDeclaration.ModifierTokens); + WriteIdentifier(parameterDeclaration.Name.Name); + if (!parameterDeclaration.Type.IsNull) { + WriteKeyword("As"); + parameterDeclaration.Type.AcceptVisitor(this, data); + } + if (!parameterDeclaration.OptionalValue.IsNull) { + WriteToken("=", ParameterDeclaration.Roles.Assign); + parameterDeclaration.OptionalValue.AcceptVisitor(this, data); + } + return EndNode(parameterDeclaration); } public object VisitVBTokenNode(VBTokenNode vBTokenNode, object data) @@ -430,7 +441,11 @@ namespace ICSharpCode.NRefactory.VB #region TypeName public object VisitPrimitiveType(PrimitiveType primitiveType, object data) { - throw new NotImplementedException(); + StartNode(primitiveType); + + WriteKeyword(primitiveType.Keyword); + + return EndNode(primitiveType); } public object VisitQualifiedType(QualifiedType qualifiedType, object data) @@ -452,7 +467,15 @@ namespace ICSharpCode.NRefactory.VB public object VisitArraySpecifier(ArraySpecifier arraySpecifier, object data) { - throw new NotImplementedException(); + StartNode(arraySpecifier); + + LPar(); + for (int i = 0; i < arraySpecifier.Dimensions; i++) { + WriteToken(",", ArraySpecifier.Roles.Comma); + } + RPar(); + + return EndNode(arraySpecifier); } public object VisitSimpleType(SimpleType simpleType, object data) @@ -687,11 +710,14 @@ namespace ICSharpCode.NRefactory.VB if (IsKeyword(identifier, containerStack.Peek())) { if (lastWritten == LastWritten.KeywordOrIdentifier) Space(); // this space is not strictly required, so we call Space() - formatter.WriteToken("@"); + formatter.WriteToken("["); } else if (lastWritten == LastWritten.KeywordOrIdentifier) { formatter.Space(); // this space is strictly required, so we directly call the formatter } formatter.WriteIdentifier(identifier); + if (IsKeyword(identifier, containerStack.Peek())) { + formatter.WriteToken("]"); + } lastWritten = LastWritten.KeywordOrIdentifier; } @@ -887,6 +913,13 @@ namespace ICSharpCode.NRefactory.VB } } + void WriteArraySpecifiers(IEnumerable arraySpecifiers) + { + foreach (ArraySpecifier specifier in arraySpecifiers) { + specifier.AcceptVisitor(this, null); + } + } + void WriteQualifiedIdentifier(IEnumerable identifiers) { bool first = true; @@ -1074,5 +1107,48 @@ namespace ICSharpCode.NRefactory.VB return sb.ToString(); } #endregion + + public object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) + { + StartNode(fieldDeclaration); + + WriteAttributes(fieldDeclaration.Attributes); + WriteModifiers(fieldDeclaration.ModifierTokens); + WriteCommaSeparatedList(fieldDeclaration.Variables); + NewLine(); + + return EndNode(fieldDeclaration); + } + + public object VisitVariableDeclarator(VariableDeclarator variableDeclarator, object data) + { + StartNode(variableDeclarator); + + WriteCommaSeparatedList(variableDeclarator.Identifiers); + WriteKeyword("As"); + if (variableDeclarator.Initializer is ObjectCreationExpression) + variableDeclarator.Initializer.AcceptVisitor(this, data); + else { + variableDeclarator.Type.AcceptVisitor(this, data); + if (!variableDeclarator.Initializer.IsNull) { + WriteToken("=", VariableDeclarator.Roles.Assign); + variableDeclarator.Initializer.AcceptVisitor(this, data); + } + } + + return EndNode(variableDeclarator); + } + + public object VisitVariableIdentifier(VariableIdentifier variableIdentifier, object data) + { + StartNode(variableIdentifier); + + WriteIdentifier(variableIdentifier.Name.Name); + if (variableIdentifier.HasNullableSpecifier) + WriteToken("?", VariableIdentifier.Roles.QuestionMark); + WriteArraySpecifiers(variableIdentifier.ArraySpecifiers); + + return EndNode(variableIdentifier); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 8c38d7ce8c..89f22afbf5 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -552,7 +552,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitFieldDeclaration(CSharp.FieldDeclaration fieldDeclaration, object data) { - throw new NotImplementedException(); + var decl = new FieldDeclaration(); + + ConvertNodes(fieldDeclaration.Attributes, decl.Attributes); + decl.Modifiers = ConvertModifiers(fieldDeclaration.Modifiers, fieldDeclaration); + ConvertNodes(fieldDeclaration.Variables, decl.Variables); + + return EndNode(fieldDeclaration, decl); } public AstNode VisitIndexerDeclaration(CSharp.IndexerDeclaration indexerDeclaration, object data) @@ -593,17 +599,53 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitParameterDeclaration(CSharp.ParameterDeclaration parameterDeclaration, object data) { - throw new NotImplementedException(); + var param = new ParameterDeclaration(); + + ConvertNodes(parameterDeclaration.Attributes, param.Attributes); + param.Modifiers = ConvertParamModifiers(parameterDeclaration.ParameterModifier); + param.Name = new Identifier(parameterDeclaration.Name, AstLocation.Empty); + param.Type = (AstType)parameterDeclaration.Type.AcceptVisitor(this, data); + param.OptionalValue = (Expression)parameterDeclaration.DefaultExpression.AcceptVisitor(this, data); + if (!param.OptionalValue.IsNull) + param.Modifiers |= Modifiers.Optional; + + return EndNode(parameterDeclaration, param); + } + + Modifiers ConvertParamModifiers(CSharp.ParameterModifier mods) + { + switch (mods) { + case ICSharpCode.NRefactory.CSharp.ParameterModifier.None: + case ICSharpCode.NRefactory.CSharp.ParameterModifier.This: + return Modifiers.None; + case ICSharpCode.NRefactory.CSharp.ParameterModifier.Ref: + return Modifiers.ByRef; + case ICSharpCode.NRefactory.CSharp.ParameterModifier.Out: + return Modifiers.ByRef; // TODO verify this! + case ICSharpCode.NRefactory.CSharp.ParameterModifier.Params: + return Modifiers.ParamArray; + default: + throw new Exception("Invalid value for ParameterModifier"); + } } public AstNode VisitPropertyDeclaration(CSharp.PropertyDeclaration propertyDeclaration, object data) { - throw new NotImplementedException(); + return null; } public AstNode VisitVariableInitializer(CSharp.VariableInitializer variableInitializer, object data) { - throw new NotImplementedException(); + var decl = new VariableDeclarator(); + + // look for type in parent + decl.Type = (AstType)variableInitializer.Parent + .GetChildByRole(CSharp.VariableInitializer.Roles.Type) + .AcceptVisitor(this, data); + decl.Identifiers.Add(new VariableIdentifier() { Name = new Identifier(variableInitializer.Name, AstLocation.Empty) }); + decl.Initializer = (Expression)variableInitializer.Initializer.AcceptVisitor(this, data); + + return EndNode(variableInitializer, decl); } public AstNode VisitFixedFieldDeclaration(CSharp.FixedFieldDeclaration fixedFieldDeclaration, object data) @@ -644,23 +686,83 @@ namespace ICSharpCode.NRefactory.VB.Visitors target = (AstType)memberType.Target.AcceptVisitor(this, data); var type = new QualifiedType(target, new Identifier(memberType.MemberName, AstLocation.Empty)); + ConvertNodes(memberType.TypeArguments, type.TypeArguments); return EndNode(memberType, type); } public AstNode VisitComposedType(CSharp.ComposedType composedType, object data) { - throw new NotImplementedException(); + var type = new ComposedType(); + + ConvertNodes(composedType.ArraySpecifiers, type.ArraySpecifiers); + type.BaseType = (AstType)composedType.BaseType.AcceptVisitor(this, data); + type.HasNullableSpecifier = composedType.HasNullableSpecifier; + + return EndNode(composedType, type); } public AstNode VisitArraySpecifier(CSharp.ArraySpecifier arraySpecifier, object data) { - throw new NotImplementedException(); + return EndNode(arraySpecifier, new ArraySpecifier(arraySpecifier.Dimensions)); } public AstNode VisitPrimitiveType(CSharp.PrimitiveType primitiveType, object data) { - throw new NotImplementedException(); + string typeName; + + switch (primitiveType.Keyword) { + case "object": + typeName = "Object"; + break; + case "bool": + typeName = "Boolean"; + break; + case "char": + typeName = "Char"; + break; + case "sbyte": + typeName = "SByte"; + break; + case "byte": + typeName = "Byte"; + break; + case "short": + typeName = "Short"; + break; + case "ushort": + typeName = "UShort"; + break; + case "int": + typeName = "Integer"; + break; + case "uint": + typeName = "UInteger"; + break; + case "long": + typeName = "Long"; + break; + case "ulong": + typeName = "ULong"; + break; + case "float": + typeName = "Single"; + break; + case "double": + typeName = "Double"; + break; + case "decimal": + typeName = "Decimal"; + break; + case "string": + typeName = "String"; + break; + default: + typeName = "unknown"; + break; + } + + return EndNode(primitiveType, new PrimitiveType(typeName)); } public AstNode VisitComment(CSharp.Comment comment, object data) @@ -670,7 +772,17 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitTypeParameterDeclaration(CSharp.TypeParameterDeclaration typeParameterDeclaration, object data) { - throw new NotImplementedException(); + var param = new TypeParameterDeclaration() { + Variance = typeParameterDeclaration.Variance, + Name = typeParameterDeclaration.Name + }; + + // TODO : fetch constraints from parent node + + // TODO : typeParameterDeclaration.Attributes get lost? + //ConvertNodes(typeParameterDeclaration.Attributes + + return EndNode(typeParameterDeclaration, param); } public AstNode VisitConstraint(CSharp.Constraint constraint, object data) @@ -712,6 +824,15 @@ namespace ICSharpCode.NRefactory.VB.Visitors if ((modifier & CSharp.Modifiers.Static) == CSharp.Modifiers.Static) mod |= Modifiers.Shared; + if ((modifier & CSharp.Modifiers.Public) == CSharp.Modifiers.Public) + mod |= Modifiers.Public; + if ((modifier & CSharp.Modifiers.Protected) == CSharp.Modifiers.Protected) + mod |= Modifiers.Protected; + if ((modifier & CSharp.Modifiers.Internal) == CSharp.Modifiers.Internal) + mod |= Modifiers.Friend; + if ((modifier & CSharp.Modifiers.Private) == CSharp.Modifiers.Private) + mod |= Modifiers.Private; + return mod; } From d2174182bceaa960e82b9820a6577483e07a2fd1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 15 May 2011 13:48:51 +0200 Subject: [PATCH 07/57] implement PropertyDeclaration; add Inherits/Implements to TypeDeclaration; implement output for DelegateDeclaration --- .../Ast/GlobalScope/TypeDeclaration.cs | 1 + .../Ast/TypeMembers/Accessor.cs | 49 ++++++ .../Ast/TypeMembers/FieldDeclaration.cs | 89 +++++++++++ .../Ast/TypeMembers/MethodDeclaration.cs | 82 +--------- .../Ast/TypeMembers/PropertyDeclaration.cs | 57 +++++++ .../Ast/VBModifierToken.cs | 16 +- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 + .../ICSharpCode.NRefactory.VB.csproj | 3 + .../OutputVisitor/OutputVisitor.cs | 140 +++++++++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 106 +++++++++++-- 10 files changed, 450 insertions(+), 95 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs index 28b669d9c5..1c7af29660 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs @@ -31,6 +31,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public AstType InheritsType { get { return GetChildByRole(InheritsTypeRole); } + set { SetChildByRole(InheritsTypeRole, value); } } public AstNodeCollection ImplementsTypes { diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs new file mode 100644 index 0000000000..87a2f53e22 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs @@ -0,0 +1,49 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Get/Set/AddHandler/RemoveHandler/RaiseEvent + /// + public class Accessor : AttributedNode + { + public static readonly new Accessor Null = new NullAccessor (); + sealed class NullAccessor : Accessor + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + } + + public BlockStatement Body { + get { return GetChildByRole (Roles.Body); } + set { SetChildByRole (Roles.Body, value); } + } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAccessor(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + Accessor o = other as Accessor; + return o != null && !o.IsNull && this.MatchAttributesAndModifiers(o, match) && + this.Body.DoMatch(o.Body, match) && Parameters.DoMatch(o.Parameters, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs new file mode 100644 index 0000000000..fa093e0457 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs @@ -0,0 +1,89 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Attributes? VariableModifier+ VariableDeclarators StatementTerminator + /// + public class FieldDeclaration : MemberDeclaration + { + public AstNodeCollection Variables { + get { return GetChildrenByRole(VariableDeclarator.VariableDeclaratorRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitFieldDeclaration(this, data); + } + } + + /// + /// VariableIdentifiers As ObjectCreationExpression
+ /// VariableIdentifiers ( As TypeName )? ( Equals Expression )? + ///
+ public class VariableDeclarator : AstNode + { + public static readonly Role VariableDeclaratorRole = new Role("VariableDeclarator"); + + public AstNodeCollection Identifiers { + get { return GetChildrenByRole(VariableIdentifier.VariableIdentifierRole); } + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public Expression Initializer { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableDeclarator(this, data); + } + } + + /// + /// Identifier IdentifierModifiers + /// + public class VariableIdentifier : AstNode + { + public static readonly Role VariableIdentifierRole = new Role("VariableIdentifier"); + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public bool HasNullableSpecifier { get; set; } + + public AstNodeCollection ArraySpecifiers { + get { return GetChildrenByRole(ComposedType.ArraySpecifierRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableIdentifier(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs index e3614e2f5f..dd699c601f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs @@ -70,85 +70,7 @@ namespace ICSharpCode.NRefactory.VB.Ast } } - /// - /// Attributes? VariableModifier+ VariableDeclarators StatementTerminator - /// - public class FieldDeclaration : MemberDeclaration - { - public AstNodeCollection Variables { - get { return GetChildrenByRole(VariableDeclarator.VariableDeclaratorRole); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - throw new NotImplementedException(); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitFieldDeclaration(this, data); - } - } - - /// - /// VariableIdentifiers As ObjectCreationExpression
- /// VariableIdentifiers ( As TypeName )? ( Equals Expression )? - ///
- public class VariableDeclarator : AstNode - { - public static readonly Role VariableDeclaratorRole = new Role("VariableDeclarator"); - - public AstNodeCollection Identifiers { - get { return GetChildrenByRole(VariableIdentifier.VariableIdentifierRole); } - } - - public AstType Type { - get { return GetChildByRole(Roles.Type); } - set { SetChildByRole(Roles.Type, value); } - } - - public Expression Initializer { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - throw new NotImplementedException(); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitVariableDeclarator(this, data); - } - } + - /// - /// Identifier IdentifierModifiers - /// - public class VariableIdentifier : AstNode - { - public static readonly Role VariableIdentifierRole = new Role("VariableIdentifier"); - - public Identifier Name { - get { return GetChildByRole(Roles.Identifier); } - set { SetChildByRole(Roles.Identifier, value); } - } - - public bool HasNullableSpecifier { get; set; } - - public AstNodeCollection ArraySpecifiers { - get { return GetChildrenByRole(ComposedType.ArraySpecifierRole); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - throw new NotImplementedException(); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitVariableIdentifier(this, data); - } - } + } diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs new file mode 100644 index 0000000000..1b0a7d7d22 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs @@ -0,0 +1,57 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class PropertyDeclaration : MemberDeclaration + { + // TODO : support automatic properties + + public static readonly Role GetterRole = new Role("Getter", Accessor.Null); + public static readonly Role SetterRole = new Role("Setter", Accessor.Null); + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public AstNodeCollection ReturnTypeAttributes { + get { return GetChildrenByRole(AttributeBlock.ReturnTypeAttributeBlockRole); } + } + + public AstType ReturnType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public AstNodeCollection ImplementsClause { + get { return GetChildrenByRole(InterfaceMemberSpecifier.InterfaceMemberSpecifierRole); } + } + + public Accessor Getter { + get { return GetChildByRole(GetterRole); } + set { SetChildByRole(GetterRole, value); } + } + + public Accessor Setter { + get { return GetChildByRole(SetterRole); } + set { SetChildByRole(SetterRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPropertyDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs index 05a22acc44..427d3e53d6 100644 --- a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs +++ b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -57,7 +57,11 @@ namespace ICSharpCode.NRefactory.VB.Ast new KeyValuePair(Modifiers.Overloads, "Overloads".Length), new KeyValuePair(Modifiers.WithEvents, "WithEvents".Length), new KeyValuePair(Modifiers.Default, "Default".Length), - new KeyValuePair(Modifiers.Dim, "Dim".Length), + // parameter modifiers + new KeyValuePair(Modifiers.Optional, "Optional".Length), + new KeyValuePair(Modifiers.ByVal, "ByVal".Length), + new KeyValuePair(Modifiers.ByRef, "ByRef".Length), + new KeyValuePair(Modifiers.ParamArray, "ParamArray".Length), // even though it's used for patterns only, it needs to be in this table to be usable in the AST new KeyValuePair(Modifiers.Any, "Any".Length) @@ -117,8 +121,16 @@ namespace ICSharpCode.NRefactory.VB.Ast return "Dim"; case Modifiers.WriteOnly: return "WriteOnly"; + case Modifiers.Optional: + return "Optional"; + case Modifiers.ByVal: + return "ByVal"; + case Modifiers.ByRef: + return "ByRef"; + case Modifiers.ParamArray: + return "ParamArray"; default: - throw new NotSupportedException("Invalid value for Modifiers"); + throw new NotSupportedException("Invalid value for Modifiers: " + modifier); } } } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 4f2342273a..394b3ae2ac 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -37,6 +37,8 @@ namespace ICSharpCode.NRefactory.VB { S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data); S VisitVariableDeclarator(VariableDeclarator variableDeclarator, T data); S VisitVariableIdentifier(VariableIdentifier variableIdentifier, T data); + S VisitAccessor(Accessor accessor, T data); + S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data); // Expression scope S VisitIdentifier(Identifier identifier, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 4b176c48ad..5034fbfd79 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -82,8 +82,11 @@ + + + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index c6f67ebd0c..94efbb6850 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -77,7 +77,32 @@ namespace ICSharpCode.NRefactory.VB public object VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, object data) { - throw new NotImplementedException(); + StartNode(typeParameterDeclaration); + + switch (typeParameterDeclaration.Variance) { + case ICSharpCode.NRefactory.TypeSystem.VarianceModifier.Invariant: + break; + case ICSharpCode.NRefactory.TypeSystem.VarianceModifier.Covariant: + WriteKeyword("Out"); + break; + case ICSharpCode.NRefactory.TypeSystem.VarianceModifier.Contravariant: + WriteKeyword("In"); + break; + default: + throw new Exception("Invalid value for VarianceModifier"); + } + + WriteIdentifier(typeParameterDeclaration.Name); + if (typeParameterDeclaration.Constraints.Any()) { + WriteKeyword("As"); + if (typeParameterDeclaration.Constraints.Count > 1) + WriteToken("{", TypeParameterDeclaration.Roles.LBrace); + WriteCommaSeparatedList(typeParameterDeclaration.Constraints); + if (typeParameterDeclaration.Constraints.Count > 1) + WriteToken("}", TypeParameterDeclaration.Roles.RBrace); + } + + return EndNode(typeParameterDeclaration); } public object VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, object data) @@ -191,6 +216,12 @@ namespace ICSharpCode.NRefactory.VB WriteModifiers(typeDeclaration.ModifierTokens); WriteClassTypeKeyword(typeDeclaration); WriteIdentifier(typeDeclaration.Name.Name); + if (!typeDeclaration.InheritsType.IsNull) { + Space(); + WriteKeyword("Inherits"); + typeDeclaration.InheritsType.AcceptVisitor(this, data); + } + WriteImplementsClause(typeDeclaration.ImplementsTypes); NewLine(); WriteMembers(typeDeclaration.Members); @@ -241,7 +272,27 @@ namespace ICSharpCode.NRefactory.VB public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) { - throw new NotImplementedException(); + StartNode(delegateDeclaration); + + WriteAttributes(delegateDeclaration.Attributes); + WriteModifiers(delegateDeclaration.ModifierTokens); + WriteKeyword("Delegate"); + if (delegateDeclaration.IsSub) + WriteKeyword("Sub"); + else + WriteKeyword("Function"); + WriteIdentifier(delegateDeclaration.Name.Name); + WriteTypeParameters(delegateDeclaration.TypeParameters); + WriteCommaSeparatedListInParenthesis(delegateDeclaration.Parameters, false); + if (!delegateDeclaration.IsSub) { + Space(); + WriteKeyword("As"); + WriteAttributes(delegateDeclaration.ReturnTypeAttributes); + delegateDeclaration.ReturnType.AcceptVisitor(this, data); + } + NewLine(); + + return EndNode(delegateDeclaration); } public object VisitIdentifier(Identifier identifier, object data) @@ -416,7 +467,8 @@ namespace ICSharpCode.NRefactory.VB methodDeclaration.Name.AcceptVisitor(this, data); WriteTypeParameters(methodDeclaration.TypeParameters); WriteCommaSeparatedListInParenthesis(methodDeclaration.Parameters, false); - if (!methodDeclaration.IsSub) { + if (!methodDeclaration.IsSub && !methodDeclaration.ReturnType.IsNull) { + Space(); WriteKeyword("As"); WriteAttributes(methodDeclaration.ReturnTypeAttributes); methodDeclaration.ReturnType.AcceptVisitor(this, data); @@ -462,7 +514,14 @@ namespace ICSharpCode.NRefactory.VB public object VisitComposedType(ComposedType composedType, object data) { - throw new NotImplementedException(); + StartNode(composedType); + + composedType.BaseType.AcceptVisitor(this, data); + if (composedType.HasNullableSpecifier) + WriteToken("?", ComposedType.Roles.QuestionMark); + WriteArraySpecifiers(composedType.ArraySpecifiers); + + return EndNode(composedType); } public object VisitArraySpecifier(ArraySpecifier arraySpecifier, object data) @@ -991,6 +1050,16 @@ namespace ICSharpCode.NRefactory.VB void WriteImplementsClause(AstNodeCollection implementsClause) { if (implementsClause.Any()) { + Space(); + WriteKeyword("Implements"); + WriteCommaSeparatedList(implementsClause); + } + } + + void WriteImplementsClause(AstNodeCollection implementsClause) + { + if (implementsClause.Any()) { + Space(); WriteKeyword("Implements"); WriteCommaSeparatedList(implementsClause); } @@ -999,6 +1068,7 @@ namespace ICSharpCode.NRefactory.VB void WriteHandlesClause(AstNodeCollection handlesClause) { if (handlesClause.Any()) { + Space(); WriteKeyword("Handles"); WriteCommaSeparatedList(handlesClause); } @@ -1150,5 +1220,67 @@ namespace ICSharpCode.NRefactory.VB return EndNode(variableIdentifier); } + + public object VisitAccessor(Accessor accessor, object data) + { + StartNode(accessor); + WriteAttributes(accessor.Attributes); + WriteModifiers(accessor.ModifierTokens); + if (accessor.Role == PropertyDeclaration.GetterRole) { + WriteKeyword("Get"); + } else if (accessor.Role == PropertyDeclaration.SetterRole) { + WriteKeyword("Set"); + } + if (accessor.Parameters.Any()) + WriteCommaSeparatedListInParenthesis(accessor.Parameters, false); + NewLine(); + + WriteBlock(accessor.Body); + + WriteKeyword("End"); + + if (accessor.Role == PropertyDeclaration.GetterRole) { + WriteKeyword("Get"); + } else if (accessor.Role == PropertyDeclaration.SetterRole) { + WriteKeyword("Set"); + } + NewLine(); + + return EndNode(accessor); + } + + public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) + { + StartNode(propertyDeclaration); + + WriteAttributes(propertyDeclaration.Attributes); + WriteModifiers(propertyDeclaration.ModifierTokens); + WriteKeyword("Property"); + WriteIdentifier(propertyDeclaration.Name.Name); + WriteCommaSeparatedListInParenthesis(propertyDeclaration.Parameters, false); + if (!propertyDeclaration.ReturnType.IsNull) { + Space(); + WriteKeyword("As"); + WriteAttributes(propertyDeclaration.ReturnTypeAttributes); + propertyDeclaration.ReturnType.AcceptVisitor(this, data); + } + NewLine(); + Indent(); + + if (!propertyDeclaration.Getter.IsNull) { + propertyDeclaration.Getter.AcceptVisitor(this, data); + } + + if (!propertyDeclaration.Setter.IsNull) { + propertyDeclaration.Setter.AcceptVisitor(this, data); + } + Unindent(); + + WriteKeyword("End"); + WriteKeyword("Property"); + NewLine(); + + return EndNode(propertyDeclaration); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 89f22afbf5..43eb59c1a5 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -14,6 +14,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors { string RootNamespace { get; } string GetTypeNameForAttribute(CSharp.Attribute attribute); + ClassType GetClassTypeForAstType(CSharp.AstType type); } /// @@ -286,7 +287,18 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitDelegateDeclaration(CSharp.DelegateDeclaration delegateDeclaration, object data) { - throw new NotImplementedException(); + var result = new DelegateDeclaration(); + + ConvertNodes(delegateDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); + ConvertNodes(delegateDeclaration.ModifierTokens, result.ModifierTokens); + result.Name = new Identifier(delegateDeclaration.Name, AstLocation.Empty); + result.IsSub = IsSub(delegateDeclaration.ReturnType); + ConvertNodes(delegateDeclaration.Parameters, result.Parameters); + ConvertNodes(delegateDeclaration.TypeParameters, result.TypeParameters); + ConvertNodes(delegateDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); + if (!result.IsSub) + result.ReturnType = (AstType)delegateDeclaration.ReturnType.AcceptVisitor(this, data); + return EndNode(delegateDeclaration, result); } public AstNode VisitNamespaceDeclaration(CSharp.NamespaceDeclaration namespaceDeclaration, object data) @@ -320,6 +332,16 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(typeDeclaration.Attributes, type.Attributes); ConvertNodes(typeDeclaration.ModifierTokens, type.ModifierTokens); + if (typeDeclaration.BaseTypes.Any()) { + var first = typeDeclaration.BaseTypes.First(); + + if (provider.GetClassTypeForAstType(first) != ClassType.Interface) { + ConvertNodes(typeDeclaration.BaseTypes.Skip(1), type.ImplementsTypes); + type.InheritsType = (AstType)first.AcceptVisitor(this, data); + } else + ConvertNodes(typeDeclaration.BaseTypes, type.ImplementsTypes); + } + type.Name = new Identifier(typeDeclaration.Name, AstLocation.Empty); ConvertNodes(typeDeclaration.Members, type.Members); @@ -361,7 +383,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitBlockStatement(CSharp.BlockStatement blockStatement, object data) { - throw new NotImplementedException(); + return null; } public AstNode VisitBreakStatement(CSharp.BreakStatement breakStatement, object data) @@ -511,7 +533,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAccessor(CSharp.Accessor accessor, object data) { - throw new NotImplementedException(); + var result = new Accessor(); + + ConvertNodes(accessor.Attributes, result.Attributes); + ConvertNodes(accessor.ModifierTokens, result.ModifierTokens); + result.Body = (BlockStatement)accessor.Body.AcceptVisitor(this, data); + + return EndNode(accessor, result); } public AstNode VisitConstructorDeclaration(CSharp.ConstructorDeclaration constructorDeclaration, object data) @@ -563,7 +591,29 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitIndexerDeclaration(CSharp.IndexerDeclaration indexerDeclaration, object data) { - throw new NotImplementedException(); + var decl = new PropertyDeclaration(); + + ConvertNodes(indexerDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), decl.Attributes); + decl.Getter = (Accessor)indexerDeclaration.Getter.AcceptVisitor(this, data); + decl.Modifiers = ConvertModifiers(indexerDeclaration.Modifiers, indexerDeclaration); + decl.Name = new Identifier(indexerDeclaration.Name, AstLocation.Empty); + ConvertNodes(indexerDeclaration.Parameters, decl.Parameters); + ConvertNodes(indexerDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), decl.ReturnTypeAttributes); + if (!indexerDeclaration.PrivateImplementationType.IsNull) + decl.ImplementsClause.Add( + new InterfaceMemberSpecifier((AstType)indexerDeclaration.PrivateImplementationType.AcceptVisitor(this, data), + indexerDeclaration.Name)); + decl.ReturnType = (AstType)indexerDeclaration.ReturnType.AcceptVisitor(this, data); + decl.Setter = (Accessor)indexerDeclaration.Setter.AcceptVisitor(this, data); + + if (!decl.Setter.IsNull) { +// decl.Setter.Parameters.Add(new ParameterDeclaration() { +// Name = new Identifier("value", AstLocation.Empty), +// Type = (AstType)indexerDeclaration.ReturnType.AcceptVisitor(this, data), +// }); + } + + return EndNode(indexerDeclaration, decl); } public AstNode VisitMethodDeclaration(CSharp.MethodDeclaration methodDeclaration, object data) @@ -577,9 +627,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(methodDeclaration.Parameters, result.Parameters); ConvertNodes(methodDeclaration.TypeParameters, result.TypeParameters); ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); - result.ImplementsClause.Add( - new InterfaceMemberSpecifier((AstType)methodDeclaration.PrivateImplementationType.AcceptVisitor(this, data), - methodDeclaration.Name)); + if (!methodDeclaration.PrivateImplementationType.IsNull) + result.ImplementsClause.Add( + new InterfaceMemberSpecifier((AstType)methodDeclaration.PrivateImplementationType.AcceptVisitor(this, data), + methodDeclaration.Name)); if (!result.IsSub) result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); @@ -603,6 +654,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(parameterDeclaration.Attributes, param.Attributes); param.Modifiers = ConvertParamModifiers(parameterDeclaration.ParameterModifier); + if ((param.Modifiers & Modifiers.None) == Modifiers.None) + param.Modifiers = Modifiers.ByVal; param.Name = new Identifier(parameterDeclaration.Name, AstLocation.Empty); param.Type = (AstType)parameterDeclaration.Type.AcceptVisitor(this, data); param.OptionalValue = (Expression)parameterDeclaration.DefaultExpression.AcceptVisitor(this, data); @@ -631,7 +684,28 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitPropertyDeclaration(CSharp.PropertyDeclaration propertyDeclaration, object data) { - return null; + var decl = new PropertyDeclaration(); + + ConvertNodes(propertyDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), decl.Attributes); + decl.Getter = (Accessor)propertyDeclaration.Getter.AcceptVisitor(this, data); + decl.Modifiers = ConvertModifiers(propertyDeclaration.Modifiers, propertyDeclaration); + decl.Name = new Identifier(propertyDeclaration.Name, AstLocation.Empty); + ConvertNodes(propertyDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), decl.ReturnTypeAttributes); + if (!propertyDeclaration.PrivateImplementationType.IsNull) + decl.ImplementsClause.Add( + new InterfaceMemberSpecifier((AstType)propertyDeclaration.PrivateImplementationType.AcceptVisitor(this, data), + propertyDeclaration.Name)); + decl.ReturnType = (AstType)propertyDeclaration.ReturnType.AcceptVisitor(this, data); + decl.Setter = (Accessor)propertyDeclaration.Setter.AcceptVisitor(this, data); + + if (!decl.Setter.IsNull) { + decl.Setter.Parameters.Add(new ParameterDeclaration() { + Name = new Identifier("value", AstLocation.Empty), + Type = (AstType)propertyDeclaration.ReturnType.AcceptVisitor(this, data), + }); + } + + return EndNode(propertyDeclaration, decl); } public AstNode VisitVariableInitializer(CSharp.VariableInitializer variableInitializer, object data) @@ -757,6 +831,16 @@ namespace ICSharpCode.NRefactory.VB.Visitors case "string": typeName = "String"; break; + // generic constraints + case "new": + typeName = "New"; + break; + case "struct": + typeName = "Structure"; + break; + case "class": + typeName = "Class"; + break; default: typeName = "unknown"; break; @@ -777,7 +861,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors Name = typeParameterDeclaration.Name }; - // TODO : fetch constraints from parent node + var constraint = typeParameterDeclaration.Parent + .GetChildrenByRole(CSharp.AstNode.Roles.Constraint) + .SingleOrDefault(c => c.TypeParameter == typeParameterDeclaration.Name); + + ConvertNodes(constraint == null ? Enumerable.Empty() : constraint.BaseTypes, param.Constraints); // TODO : typeParameterDeclaration.Attributes get lost? //ConvertNodes(typeParameterDeclaration.Attributes From 82c6419e7d5a5ed3e6a72862e009a4bf3a1bb75a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 15 May 2011 16:42:15 +0200 Subject: [PATCH 08/57] implement translation of EnumDeclaration --- .../Ast/GlobalScope/EnumDeclaration.cs | 4 +- .../OutputVisitor/OutputVisitor.cs | 41 ++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 86 ++++++++++++------- 3 files changed, 97 insertions(+), 34 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs index 49fe3f239c..b24fc4b23c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.VB.Ast set { SetChildByRole(UnderlyingTypeRole, value); } } - public AstNodeCollection Member { + public AstNodeCollection Members { get { return GetChildrenByRole(MemberRole); } } @@ -33,7 +33,7 @@ namespace ICSharpCode.NRefactory.VB.Ast MatchAttributesAndModifiers(decl, match) && Name.DoMatch(decl.Name, match) && UnderlyingType.DoMatch(decl.UnderlyingType, match) && - Member.DoMatch(decl.Member, match); + Members.DoMatch(decl.Members, match); } public override S AcceptVisitor(IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 94efbb6850..7d069f9fde 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -241,6 +241,7 @@ namespace ICSharpCode.NRefactory.VB case ICSharpCode.NRefactory.TypeSystem.ClassType.Enum: break; case ICSharpCode.NRefactory.TypeSystem.ClassType.Interface: + WriteKeyword("Interface"); break; case ICSharpCode.NRefactory.TypeSystem.ClassType.Struct: WriteKeyword("Structure"); @@ -262,12 +263,48 @@ namespace ICSharpCode.NRefactory.VB public object VisitEnumDeclaration(EnumDeclaration enumDeclaration, object data) { - throw new NotImplementedException(); + StartNode(enumDeclaration); + + WriteAttributes(enumDeclaration.Attributes); + WriteModifiers(enumDeclaration.ModifierTokens); + WriteKeyword("Enum"); + WriteIdentifier(enumDeclaration.Name.Name); + if (!enumDeclaration.UnderlyingType.IsNull) { + Space(); + WriteKeyword("As"); + enumDeclaration.UnderlyingType.AcceptVisitor(this, data); + } + NewLine(); + + Indent(); + foreach (var member in enumDeclaration.Members) { + member.AcceptVisitor(this, null); + } + Unindent(); + + WriteKeyword("End"); + WriteKeyword("Enum"); + NewLine(); + + return EndNode(enumDeclaration); } public object VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, object data) { - throw new NotImplementedException(); + StartNode(enumMemberDeclaration); + + WriteAttributes(enumMemberDeclaration.Attributes); + WriteIdentifier(enumMemberDeclaration.Name.Name); + + if (!enumMemberDeclaration.Value.IsNull) { + Space(); + WriteToken("=", EnumMemberDeclaration.Roles.Assign); + Space(); + enumMemberDeclaration.Value.AcceptVisitor(this, data); + } + NewLine(); + + return EndNode(enumMemberDeclaration); } public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 43eb59c1a5..8a0e33d782 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -314,39 +314,59 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitTypeDeclaration(CSharp.TypeDeclaration typeDeclaration, object data) { // TODO add missing features! - var type = new TypeDeclaration(); - CSharp.Attribute stdModAttr; - - if (typeDeclaration.ClassType == ClassType.Class && HasAttribute(typeDeclaration.Attributes, "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute", out stdModAttr)) { - type.ClassType = ClassType.Module; - // remove AttributeSection if only one attribute is present - var attrSec = (CSharp.AttributeSection)stdModAttr.Parent; - if (attrSec.Attributes.Count == 1) - attrSec.Remove(); - else - stdModAttr.Remove(); - } else - type.ClassType = typeDeclaration.ClassType; - - ConvertNodes(typeDeclaration.Attributes, type.Attributes); - ConvertNodes(typeDeclaration.ModifierTokens, type.ModifierTokens); - - if (typeDeclaration.BaseTypes.Any()) { - var first = typeDeclaration.BaseTypes.First(); + if (typeDeclaration.ClassType == ClassType.Enum) { + var type = new EnumDeclaration(); + + ConvertNodes(typeDeclaration.Attributes, type.Attributes); + ConvertNodes(typeDeclaration.ModifierTokens, type.ModifierTokens); + + if (typeDeclaration.BaseTypes.Any()) { + var first = typeDeclaration.BaseTypes.First(); + + type.UnderlyingType = (AstType)first.AcceptVisitor(this, data); + } + + type.Name = new Identifier(typeDeclaration.Name, AstLocation.Empty); + + ConvertNodes(typeDeclaration.Members, type.Members); + + return EndNode(typeDeclaration, type); + } else { + var type = new TypeDeclaration(); + + CSharp.Attribute stdModAttr; - if (provider.GetClassTypeForAstType(first) != ClassType.Interface) { - ConvertNodes(typeDeclaration.BaseTypes.Skip(1), type.ImplementsTypes); - type.InheritsType = (AstType)first.AcceptVisitor(this, data); + if (typeDeclaration.ClassType == ClassType.Class && HasAttribute(typeDeclaration.Attributes, "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute", out stdModAttr)) { + type.ClassType = ClassType.Module; + // remove AttributeSection if only one attribute is present + var attrSec = (CSharp.AttributeSection)stdModAttr.Parent; + if (attrSec.Attributes.Count == 1) + attrSec.Remove(); + else + stdModAttr.Remove(); } else - ConvertNodes(typeDeclaration.BaseTypes, type.ImplementsTypes); + type.ClassType = typeDeclaration.ClassType; + + ConvertNodes(typeDeclaration.Attributes, type.Attributes); + ConvertNodes(typeDeclaration.ModifierTokens, type.ModifierTokens); + + if (typeDeclaration.BaseTypes.Any()) { + var first = typeDeclaration.BaseTypes.First(); + + if (provider.GetClassTypeForAstType(first) != ClassType.Interface) { + ConvertNodes(typeDeclaration.BaseTypes.Skip(1), type.ImplementsTypes); + type.InheritsType = (AstType)first.AcceptVisitor(this, data); + } else + ConvertNodes(typeDeclaration.BaseTypes, type.ImplementsTypes); + } + + type.Name = new Identifier(typeDeclaration.Name, AstLocation.Empty); + + ConvertNodes(typeDeclaration.Members, type.Members); + + return EndNode(typeDeclaration, type); } - - type.Name = new Identifier(typeDeclaration.Name, AstLocation.Empty); - - ConvertNodes(typeDeclaration.Members, type.Members); - - return EndNode(typeDeclaration, type); } public AstNode VisitUsingAliasDeclaration(CSharp.UsingAliasDeclaration usingAliasDeclaration, object data) @@ -565,7 +585,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitEnumMemberDeclaration(CSharp.EnumMemberDeclaration enumMemberDeclaration, object data) { - throw new NotImplementedException(); + var result = new EnumMemberDeclaration(); + + ConvertNodes(enumMemberDeclaration.Attributes, result.Attributes); + result.Name = new Identifier(enumMemberDeclaration.Name, AstLocation.Empty); + result.Value = (Expression)enumMemberDeclaration.Initializer.AcceptVisitor(this, data); + + return EndNode(enumMemberDeclaration, result); } public AstNode VisitEventDeclaration(CSharp.EventDeclaration eventDeclaration, object data) From 032f217237d7619f68272643c4b96d33cab78961 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 May 2011 05:45:54 +0200 Subject: [PATCH 09/57] implemented IfElseStatement and some more expressions --- ICSharpCode.NRefactory.VB/Ast/AstNode.cs | 4 +- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 66 ---- .../Ast/Expressions/Expression.cs | 181 ++++++++++ .../Ast/Expressions/IdentifierExpression.cs | 29 ++ .../Ast/Statements/BlockStatement.cs | 4 +- .../Ast/Statements/Statement.cs | 308 ++++++++++++++++++ .../Ast/TypeMembers/Accessor.cs | 4 +- .../Ast/VBModifierToken.cs | 2 +- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 16 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 260 ++++++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 170 +++++++++- 12 files changed, 955 insertions(+), 90 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs index 6be2284466..2fd9aa9248 100644 --- a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -681,8 +681,8 @@ namespace ICSharpCode.NRefactory.VB public static readonly Role Argument = new Role("Argument", Ast.Expression.Null); public static readonly Role Type = new Role("Type", AstType.Null); public static readonly Role Expression = new Role("Expression", Ast.Expression.Null); -// public static readonly Role TargetExpression = new Role("Target", CSharp.Expression.Null); -// public readonly static Role Condition = new Role("Condition", CSharp.Expression.Null); + public static readonly Role TargetExpression = new Role("Target", Ast.Expression.Null); + public readonly static Role Condition = new Role("Condition", Ast.Expression.Null); // public static readonly Role TypeParameter = new Role("TypeParameter"); public static readonly Role TypeArgument = new Role("TypeArgument", AstType.Null); diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index 0746032c2c..154fb58c2b 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -90,72 +90,6 @@ namespace ICSharpCode.NRefactory.VB.Ast ExclusiveOr, } - public enum BinaryOperatorType - { - None, - - /// '&' in C#, 'And' in VB. - BitwiseAnd, - /// '|' in C#, 'Or' in VB. - BitwiseOr, - /// '&&' in C#, 'AndAlso' in VB. - LogicalAnd, - /// '||' in C#, 'OrElse' in VB. - LogicalOr, - /// '^' in C#, 'Xor' in VB. - ExclusiveOr, - - /// > - GreaterThan, - /// >= - GreaterThanOrEqual, - /// '==' in C#, '=' in VB. - Equality, - /// '!=' in C#, '<>' in VB. - InEquality, - /// < - LessThan, - /// <= - LessThanOrEqual, - - /// + - Add, - /// - - Subtract, - /// * - Multiply, - /// / - Divide, - /// '%' in C#, 'Mod' in VB. - Modulus, - /// VB-only: \ - DivideInteger, - /// VB-only: ^ - Power, - /// VB-only: & - Concat, - - /// C#: << - ShiftLeft, - /// C#: >> - ShiftRight, - /// VB-only: Is - ReferenceEquality, - /// VB-only: IsNot - ReferenceInequality, - - /// VB-only: Like - Like, - /// - /// C#: ?? - /// VB: IF(x, y) - /// - NullCoalescing, - - /// VB-only: ! - DictionaryAccess - } - public enum CastType { /// diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index d15756e3ee..0764501c17 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Collections.Generic; namespace ICSharpCode.NRefactory.VB.Ast { @@ -30,4 +31,184 @@ namespace ICSharpCode.NRefactory.VB.Ast } #endregion } + + public class BinaryOperatorExpression : Expression + { + public readonly static Role LeftExpressionRole = new Role("Left"); + public readonly static Role RightExpressionRole = new Role("Right"); + + public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right) + { + AddChild(left, LeftExpressionRole); + AddChild(right, RightExpressionRole); + Operator = type; + } + + public Expression Left { + get { return GetChildByRole(LeftExpressionRole); } + set { SetChildByRole(LeftExpressionRole, value); } + } + + public BinaryOperatorType Operator { get; set; } + + public Expression Right { + get { return GetChildByRole(RightExpressionRole); } + set { SetChildByRole(RightExpressionRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitBinaryOperatorExpression(this, data); + } + } + + public enum BinaryOperatorType + { + None, + + /// '&' in C#, 'And' in VB. + BitwiseAnd, + /// '|' in C#, 'Or' in VB. + BitwiseOr, + /// '&&' in C#, 'AndAlso' in VB. + LogicalAnd, + /// '||' in C#, 'OrElse' in VB. + LogicalOr, + /// '^' in C#, 'Xor' in VB. + ExclusiveOr, + + /// > + GreaterThan, + /// >= + GreaterThanOrEqual, + /// '==' in C#, '=' in VB. + Equality, + /// '!=' in C#, '<>' in VB. + InEquality, + /// < + LessThan, + /// <= + LessThanOrEqual, + + /// + + Add, + /// - + Subtract, + /// * + Multiply, + /// / + Divide, + /// '%' in C#, 'Mod' in VB. + Modulus, + /// VB-only: \ + DivideInteger, + /// VB-only: ^ + Power, + /// VB-only: & + Concat, + + /// C#: << + ShiftLeft, + /// C#: >> + ShiftRight, + /// VB-only: Is + ReferenceEquality, + /// VB-only: IsNot + ReferenceInequality, + + /// VB-only: Like + Like, + /// + /// C#: ?? + /// VB: IF(x, y) + /// + NullCoalescing, + + /// VB-only: ! + DictionaryAccess + } + + public class AssignmentExpression : Expression + { + public readonly static Role LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; + public readonly static Role RightExpressionRole = BinaryOperatorExpression.RightExpressionRole; + + public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right) + { + AddChild(left, LeftExpressionRole); + AddChild(right, RightExpressionRole); + Operator = type; + } + + public Expression Left { + get { return GetChildByRole(LeftExpressionRole); } + set { SetChildByRole(LeftExpressionRole, value); } + } + + public AssignmentOperatorType Operator { get; set; } + + public Expression Right { + get { return GetChildByRole(RightExpressionRole); } + set { SetChildByRole(RightExpressionRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAssignmentExpression(this, data); + } + } + + /// + /// Target(Arguments) + /// + public class InvocationExpression : Expression + { + public Expression Target { + get { return GetChildByRole (Roles.TargetExpression); } + set { SetChildByRole(Roles.TargetExpression, value); } + } + + public AstNodeCollection Arguments { + get { return GetChildrenByRole(Roles.Argument); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitInvocationExpression(this, data); + } + + public InvocationExpression () + { + } + + public InvocationExpression (Expression target, IEnumerable arguments) + { + AddChild (target, Roles.TargetExpression); + if (arguments != null) { + foreach (var arg in arguments) { + AddChild (arg, Roles.Argument); + } + } + } + + public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable)arguments) + { + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + InvocationExpression o = other as InvocationExpression; + return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match); + } + } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs new file mode 100644 index 0000000000..89e6d4ec14 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs @@ -0,0 +1,29 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class IdentifierExpression : Expression + { + public Identifier Identifier { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstNodeCollection TypeArguments { + get { return GetChildrenByRole(Roles.TypeArgument); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitIdentifierExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs index 73610fe707..b01ac98435 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs @@ -79,7 +79,7 @@ namespace ICSharpCode.NRefactory.VB.Ast protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { BlockStatement o = other as BlockStatement; - return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match); + return o != null && !(o is CatchBlock) && !o.IsNull && this.Statements.DoMatch(o.Statements, match); } #region Builder methods @@ -122,4 +122,6 @@ namespace ICSharpCode.NRefactory.VB.Ast return this.Statements.GetEnumerator(); } } + + } diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs index c20407051c..07bb02ede7 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs @@ -129,4 +129,312 @@ namespace ICSharpCode.NRefactory.VB.Ast throw new NotImplementedException(); } } + + /// + /// Label: + /// + public class LabelDeclarationStatement : Statement + { + public Identifier Label { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public VBTokenNode Colon { + get { return GetChildByRole(Roles.Colon); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitLabelDeclarationStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + LabelDeclarationStatement o = other as LabelDeclarationStatement; + return o != null && MatchString(this.Label.Name, o.Label.Name); + } + } + + /// + /// ( Dim | Static | Const ) VariableDeclarator { , VariableDeclarator } + /// + public class LocalDeclarationStatement : Statement + { + public AstNodeCollection Variables { + get { return GetChildrenByRole(VariableDeclarator.VariableDeclaratorRole); } + } + + public Modifiers Modifiers { + get { return AttributedNode.GetModifiers(this); } + set { AttributedNode.SetModifiers(this, value); } + } + + public VBModifierToken ModifierToken { + get { return GetChildByRole(AttributedNode.ModifierRole); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitLocalDeclarationStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// With Expression
+ /// Block
+ /// End With + ///
+ public class WithStatement : Statement + { + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitWithStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// SyncLock Expression
+ /// Block
+ /// End SyncLock + ///
+ public class SyncLockStatement : Statement + { + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitSyncLockStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// SyncLock Expression
+ /// Block
+ /// End SyncLock + ///
+ public class TryStatement : Statement + { + public static readonly Role FinallyBlockRole = new Role("FinallyBlock", Ast.BlockStatement.Null); + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public AstNodeCollection CatchBlocks { + get { return GetChildrenByRole(CatchBlock.CatchBlockRole); } + } + + public BlockStatement FinallyBlock { + get { return GetChildByRole(FinallyBlockRole); } + set { SetChildByRole(FinallyBlockRole, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitTryStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + public class CatchBlock : BlockStatement + { + public static readonly Role CatchBlockRole = new Role("CatchBlockRole"); + + public Identifier ExceptionVariable { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstType ExceptionType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public Expression WhenExpression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitCatchBlock(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + public class IfElseStatement : Statement + { + public static readonly Role FalseStatementRole = new Role("False", Ast.Statement.Null); + public static readonly Role TrueStatementRole = new Role("True", Ast.Statement.Null); + + public Expression Condition { + get { return GetChildByRole(Roles.Condition); } + set { SetChildByRole(Roles.Condition, value); } + } + + public Statement Body { + get { return GetChildByRole(TrueStatementRole); } + set { SetChildByRole(TrueStatementRole, value); } + } + + public Statement ElseBlock { + get { return GetChildByRole(FalseStatementRole); } + set { SetChildByRole(FalseStatementRole, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitIfElseStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// Expression + /// + public class ExpressionStatement : Statement + { + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitExpressionStatement(this, data); + } + + public ExpressionStatement() + { + } + + public ExpressionStatement(Expression expression) + { + this.Expression = expression; + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ExpressionStatement o = other as ExpressionStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } + + /// + /// Throw Expression + /// + public class ThrowStatement : Statement + { + public VBTokenNode ThrowToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public ThrowStatement() + { + } + + public ThrowStatement(Expression expression) + { + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitThrowStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ThrowStatement o = other as ThrowStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } + + /// + /// Return Expression + /// + public class ReturnStatement : Statement + { + public VBTokenNode ReturnToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public ReturnStatement() + { + } + + public ReturnStatement(Expression expression) + { + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitReturnStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ReturnStatement o = other as ReturnStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } + } diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs index 87a2f53e22..be9751b6a2 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs @@ -26,8 +26,8 @@ namespace ICSharpCode.NRefactory.VB.Ast } public BlockStatement Body { - get { return GetChildByRole (Roles.Body); } - set { SetChildByRole (Roles.Body, value); } + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } } public AstNodeCollection Parameters { diff --git a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs index 427d3e53d6..2050582617 100644 --- a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs +++ b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -46,6 +46,7 @@ namespace ICSharpCode.NRefactory.VB.Ast new KeyValuePair(Modifiers.Overridable, "Overridable".Length), new KeyValuePair(Modifiers.NotInheritable, "NotInheritable".Length), new KeyValuePair(Modifiers.NotOverridable, "NotOverridable".Length), + new KeyValuePair(Modifiers.Dim, "Dim".Length), new KeyValuePair(Modifiers.Const, "Const".Length), new KeyValuePair(Modifiers.Shared, "Shared".Length), new KeyValuePair(Modifiers.Static, "Static".Length), @@ -62,7 +63,6 @@ namespace ICSharpCode.NRefactory.VB.Ast new KeyValuePair(Modifiers.ByVal, "ByVal".Length), new KeyValuePair(Modifiers.ByRef, "ByRef".Length), new KeyValuePair(Modifiers.ParamArray, "ParamArray".Length), - // even though it's used for patterns only, it needs to be in this table to be usable in the AST new KeyValuePair(Modifiers.Any, "Any".Length) }; diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 394b3ae2ac..e96f9c1172 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -54,6 +54,22 @@ namespace ICSharpCode.NRefactory.VB { S VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, T data); S VisitMemberAccessExpression(MemberAccessExpression memberAccessExpression, T data); S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); + S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data); + S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data); + S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); + S VisitInvocationExpression(InvocationExpression invocationExpression, T data); + + // Statement scope + S VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, T data); + S VisitLocalDeclarationStatement(LocalDeclarationStatement localDeclarationStatement, T data); + S VisitExpressionStatement(ExpressionStatement expressionStatement, T data); + S VisitWithStatement(WithStatement withStatement, T data); + S VisitSyncLockStatement(SyncLockStatement syncLockStatement, T data); + S VisitIfElseStatement(IfElseStatement ifElseStatement, T data); + S VisitTryStatement(TryStatement tryStatement, T data); + S VisitThrowStatement(ThrowStatement throwStatement, T data); + S VisitCatchBlock(CatchBlock catchBlock, T data); + S VisitReturnStatement(ReturnStatement returnStatement, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 5034fbfd79..427cd102de 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -51,6 +51,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 7d069f9fde..6a183a7ff6 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -67,7 +67,12 @@ namespace ICSharpCode.NRefactory.VB public object VisitBlockStatement(BlockStatement blockStatement, object data) { - throw new NotImplementedException(); + StartNode(blockStatement); + foreach (var stmt in blockStatement) { + stmt.AcceptVisitor(this, data); + NewLine(); + } + return EndNode(blockStatement); } public object VisitPatternPlaceholder(AstNode placeholder, Pattern pattern, object data) @@ -513,9 +518,9 @@ namespace ICSharpCode.NRefactory.VB WriteHandlesClause(methodDeclaration.HandlesClause); WriteImplementsClause(methodDeclaration.ImplementsClause); NewLine(); - - // TODO Body - + Indent(); + WriteBlock(methodDeclaration.Body); + Unindent(); WriteKeyword("End"); if (methodDeclaration.IsSub) WriteKeyword("Sub"); @@ -1319,5 +1324,252 @@ namespace ICSharpCode.NRefactory.VB return EndNode(propertyDeclaration); } + + public object VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitLocalDeclarationStatement(LocalDeclarationStatement localDeclarationStatement, object data) + { + StartNode(localDeclarationStatement); + + WriteModifiers(new [] { localDeclarationStatement.ModifierToken }); + WriteCommaSeparatedList(localDeclarationStatement.Variables); + + return EndNode(localDeclarationStatement); + } + + public object VisitWithStatement(WithStatement withStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitSyncLockStatement(SyncLockStatement syncLockStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitTryStatement(TryStatement tryStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitCatchBlock(CatchBlock catchBlock, object data) + { + throw new NotImplementedException(); + } + + public object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) + { + StartNode(expressionStatement); + expressionStatement.Expression.AcceptVisitor(this, data); + return EndNode(expressionStatement); + } + + public object VisitThrowStatement(ThrowStatement throwStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) + { + StartNode(ifElseStatement); + WriteKeyword("If"); + ifElseStatement.Condition.AcceptVisitor(this, data); + WriteKeyword("Then"); + NewLine(); + Indent(); + ifElseStatement.Body.AcceptVisitor(this, data); + Unindent(); + if (!ifElseStatement.ElseBlock.IsNull) { + WriteKeyword("Else"); + NewLine(); + Indent(); + ifElseStatement.ElseBlock.AcceptVisitor(this, data); + Unindent(); + } + WriteKeyword("End"); + WriteKeyword("If"); + return EndNode(ifElseStatement); + } + + public object VisitReturnStatement(ReturnStatement returnStatement, object data) + { + StartNode(returnStatement); + WriteKeyword("Return"); + returnStatement.Expression.AcceptVisitor(this, data); + return EndNode(returnStatement); + } + + public object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) + { + StartNode(binaryOperatorExpression); + binaryOperatorExpression.Left.AcceptVisitor(this, data); + Space(); + switch (binaryOperatorExpression.Operator) { + case BinaryOperatorType.None: + + break; + case BinaryOperatorType.BitwiseAnd: + + break; + case BinaryOperatorType.BitwiseOr: + + break; + case BinaryOperatorType.LogicalAnd: + + break; + case BinaryOperatorType.LogicalOr: + + break; + case BinaryOperatorType.ExclusiveOr: + + break; + case BinaryOperatorType.GreaterThan: + + break; + case BinaryOperatorType.GreaterThanOrEqual: + + break; + case BinaryOperatorType.Equality: + WriteToken("=", BinaryOperatorExpression.Roles.Assign); + break; + case BinaryOperatorType.InEquality: + + break; + case BinaryOperatorType.LessThan: + + break; + case BinaryOperatorType.LessThanOrEqual: + + break; + case BinaryOperatorType.Add: + + break; + case BinaryOperatorType.Subtract: + + break; + case BinaryOperatorType.Multiply: + + break; + case BinaryOperatorType.Divide: + + break; + case BinaryOperatorType.Modulus: + + break; + case BinaryOperatorType.DivideInteger: + + break; + case BinaryOperatorType.Power: + + break; + case BinaryOperatorType.Concat: + + break; + case BinaryOperatorType.ShiftLeft: + + break; + case BinaryOperatorType.ShiftRight: + + break; + case BinaryOperatorType.ReferenceEquality: + + break; + case BinaryOperatorType.ReferenceInequality: + + break; + case BinaryOperatorType.Like: + + break; + case BinaryOperatorType.NullCoalescing: + + break; + case BinaryOperatorType.DictionaryAccess: + + break; + default: + throw new Exception("Invalid value for BinaryOperatorType"); + } + Space(); + binaryOperatorExpression.Right.AcceptVisitor(this, data); + return EndNode(binaryOperatorExpression); + } + + public object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) + { + StartNode(identifierExpression); + identifierExpression.Identifier.AcceptVisitor(this, data); + WriteTypeArguments(identifierExpression.TypeArguments); + return EndNode(identifierExpression); + } + + public object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) + { + StartNode(assignmentExpression); + assignmentExpression.Left.AcceptVisitor(this, data); + Space(); + switch (assignmentExpression.Operator) { + case AssignmentOperatorType.None: + + break; + case AssignmentOperatorType.Assign: + WriteToken("=", AssignmentExpression.Roles.Assign); + break; + case AssignmentOperatorType.Add: + + break; + case AssignmentOperatorType.Subtract: + + break; + case AssignmentOperatorType.Multiply: + + break; + case AssignmentOperatorType.Divide: + + break; + case AssignmentOperatorType.Modulus: + + break; + case AssignmentOperatorType.Power: + + break; + case AssignmentOperatorType.DivideInteger: + + break; + case AssignmentOperatorType.ConcatString: + + break; + case AssignmentOperatorType.ShiftLeft: + + break; + case AssignmentOperatorType.ShiftRight: + + break; + case AssignmentOperatorType.BitwiseAnd: + + break; + case AssignmentOperatorType.BitwiseOr: + + break; + case AssignmentOperatorType.ExclusiveOr: + + break; + default: + throw new Exception("Invalid value for AssignmentOperatorType"); + } + Space(); + assignmentExpression.Right.AcceptVisitor(this, data); + return EndNode(assignmentExpression); + } + + public object VisitInvocationExpression(InvocationExpression invocationExpression, object data) + { + StartNode(invocationExpression); + invocationExpression.Target.AcceptVisitor(this, data); + WriteCommaSeparatedListInParenthesis(invocationExpression.Arguments, false); + return EndNode(invocationExpression); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 8a0e33d782..ebeddbabf1 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -56,7 +56,54 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAssignmentExpression(CSharp.AssignmentExpression assignmentExpression, object data) { - throw new NotImplementedException(); + var left = (Expression)assignmentExpression.Left.AcceptVisitor(this, data); + var op = AssignmentOperatorType.None; + + switch (assignmentExpression.Operator) { + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Assign: + op = AssignmentOperatorType.Assign; + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Add: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Subtract: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Divide: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Modulus: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftLeft: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftRight: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseAnd: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseOr: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ExclusiveOr: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Any: + + break; + default: + throw new Exception("Invalid value for AssignmentOperatorType"); + } + + var right = (Expression)assignmentExpression.Right.AcceptVisitor(this, data); + + var expr = new AssignmentExpression(left, op, right); + return EndNode(assignmentExpression, expr); } public AstNode VisitBaseReferenceExpression(CSharp.BaseReferenceExpression baseReferenceExpression, object data) @@ -68,7 +115,76 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitBinaryOperatorExpression(CSharp.BinaryOperatorExpression binaryOperatorExpression, object data) { - throw new NotImplementedException(); + var left = (Expression)binaryOperatorExpression.Left.AcceptVisitor(this, data); + var op = BinaryOperatorType.None; + var right = (Expression)binaryOperatorExpression.Right.AcceptVisitor(this, data); + + switch (binaryOperatorExpression.Operator) { + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseAnd: + op = BinaryOperatorType.BitwiseAnd; + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseOr: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalAnd: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalOr: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ExclusiveOr: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThan: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThanOrEqual: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Equality: + op = BinaryOperatorType.Equality; + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.InEquality: + op = BinaryOperatorType.InEquality; + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThan: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThanOrEqual: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Add: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Subtract: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Multiply: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Divide: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Modulus: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftLeft: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftRight: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.NullCoalescing: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Any: + + break; + default: + throw new Exception("Invalid value for BinaryOperatorType"); + } + + return EndNode(binaryOperatorExpression, new BinaryOperatorExpression(left, op, right)); } public AstNode VisitCastExpression(CSharp.CastExpression castExpression, object data) @@ -98,7 +214,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitIdentifierExpression(CSharp.IdentifierExpression identifierExpression, object data) { - throw new NotImplementedException(); + var expr = new IdentifierExpression(); + expr.Identifier = new Identifier(identifierExpression.Identifier, AstLocation.Empty); + ConvertNodes(identifierExpression.TypeArguments, expr.TypeArguments); + + return EndNode(identifierExpression, expr); } public AstNode VisitIndexerExpression(CSharp.IndexerExpression indexerExpression, object data) @@ -108,7 +228,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitInvocationExpression(CSharp.InvocationExpression invocationExpression, object data) { - throw new NotImplementedException(); + var expr = new InvocationExpression( + (Expression)invocationExpression.Target.AcceptVisitor(this, data)); + ConvertNodes(invocationExpression.Arguments, expr.Arguments); + + return EndNode(invocationExpression, expr); } public AstNode VisitIsExpression(CSharp.IsExpression isExpression, object data) @@ -139,7 +263,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitNullReferenceExpression(CSharp.NullReferenceExpression nullReferenceExpression, object data) { - throw new NotImplementedException(); + return EndNode(nullReferenceExpression, new PrimitiveExpression(null)); } public AstNode VisitObjectCreateExpression(CSharp.ObjectCreateExpression objectCreateExpression, object data) @@ -403,7 +527,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitBlockStatement(CSharp.BlockStatement blockStatement, object data) { - return null; + var block = new BlockStatement(); + ConvertNodes(blockStatement, block.Statements); + + return EndNode(blockStatement, block); } public AstNode VisitBreakStatement(CSharp.BreakStatement breakStatement, object data) @@ -433,7 +560,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitExpressionStatement(CSharp.ExpressionStatement expressionStatement, object data) { - throw new NotImplementedException(); + var expr = new ExpressionStatement((Expression)expressionStatement.Expression.AcceptVisitor(this, data)); + return EndNode(expressionStatement, expr); } public AstNode VisitFixedStatement(CSharp.FixedStatement fixedStatement, object data) @@ -468,7 +596,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitIfElseStatement(CSharp.IfElseStatement ifElseStatement, object data) { - throw new NotImplementedException(); + var stmt = new IfElseStatement(); + + stmt.Condition = (Expression)ifElseStatement.Condition.AcceptVisitor(this, data); + stmt.Body = (Statement)ifElseStatement.TrueStatement.AcceptVisitor(this, data); + stmt.ElseBlock = (Statement)ifElseStatement.FalseStatement.AcceptVisitor(this, data); + + return EndNode(ifElseStatement, stmt); } public AstNode VisitLabelStatement(CSharp.LabelStatement labelStatement, object data) @@ -483,7 +617,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitReturnStatement(CSharp.ReturnStatement returnStatement, object data) { - throw new NotImplementedException(); + var stmt = new ReturnStatement((Expression)returnStatement.Expression.AcceptVisitor(this, data)); + + return EndNode(returnStatement, stmt); } public AstNode VisitSwitchStatement(CSharp.SwitchStatement switchStatement, object data) @@ -533,7 +669,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitVariableDeclarationStatement(CSharp.VariableDeclarationStatement variableDeclarationStatement, object data) { - throw new NotImplementedException(); + var decl = new LocalDeclarationStatement(); + decl.Modifiers = Modifiers.Dim; + ConvertNodes(variableDeclarationStatement.Variables, decl.Variables); + + return EndNode(variableDeclarationStatement, decl); } public AstNode VisitWhileStatement(CSharp.WhileStatement whileStatement, object data) @@ -569,6 +709,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(constructorDeclaration.Attributes, result.Attributes); ConvertNodes(constructorDeclaration.ModifierTokens, result.ModifierTokens); ConvertNodes(constructorDeclaration.Parameters, result.Parameters); + result.Body = (BlockStatement)constructorDeclaration.Body.AcceptVisitor(this, data); return EndNode(constructorDeclaration, result); } @@ -633,10 +774,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors decl.Setter = (Accessor)indexerDeclaration.Setter.AcceptVisitor(this, data); if (!decl.Setter.IsNull) { -// decl.Setter.Parameters.Add(new ParameterDeclaration() { -// Name = new Identifier("value", AstLocation.Empty), -// Type = (AstType)indexerDeclaration.ReturnType.AcceptVisitor(this, data), -// }); + decl.Setter.Parameters.Add(new ParameterDeclaration() { + Name = new Identifier("value", AstLocation.Empty), + Type = (AstType)indexerDeclaration.ReturnType.AcceptVisitor(this, data), + }); } return EndNode(indexerDeclaration, decl); @@ -659,6 +800,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors methodDeclaration.Name)); if (!result.IsSub) result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); + result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); return EndNode(methodDeclaration, result); } From 7ed36c09e8fe511c38d92c1d3dce7feeaf5f3411 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 May 2011 06:04:57 +0200 Subject: [PATCH 10/57] convert default(T) to Nothing and typeof() to GetType() --- ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs | 9 ++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 6a183a7ff6..75d3ddcd33 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -419,7 +419,14 @@ namespace ICSharpCode.NRefactory.VB public object VisitGetTypeExpression(GetTypeExpression getTypeExpression, object data) { - throw new NotImplementedException(); + StartNode(getTypeExpression); + + WriteKeyword("GetType"); + LPar(); + getTypeExpression.Type.AcceptVisitor(this, data); + RPar(); + + return EndNode(getTypeExpression); } public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index ebeddbabf1..e4555bc375 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -204,7 +204,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitDefaultValueExpression(CSharp.DefaultValueExpression defaultValueExpression, object data) { - throw new NotImplementedException(); + // Nothing is equivalent to default(T) for reference and value types. + return EndNode(defaultValueExpression, new PrimitiveExpression(null)); } public AstNode VisitDirectionExpression(CSharp.DirectionExpression directionExpression, object data) @@ -316,7 +317,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitTypeOfExpression(CSharp.TypeOfExpression typeOfExpression, object data) { - throw new NotImplementedException(); + var expr = new GetTypeExpression(); + expr.Type = (AstType)typeOfExpression.Type.AcceptVisitor(this, data); + return EndNode(typeOfExpression, expr); } public AstNode VisitTypeReferenceExpression(CSharp.TypeReferenceExpression typeReferenceExpression, object data) From d523549f6d003993120e50f6c14df195d3ff1472 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 May 2011 06:08:10 +0200 Subject: [PATCH 11/57] fix indentation in Accessor blocks --- ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 75d3ddcd33..44ef830aaf 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1283,9 +1283,9 @@ namespace ICSharpCode.NRefactory.VB if (accessor.Parameters.Any()) WriteCommaSeparatedListInParenthesis(accessor.Parameters, false); NewLine(); - + Indent(); WriteBlock(accessor.Body); - + Unindent(); WriteKeyword("End"); if (accessor.Role == PropertyDeclaration.GetterRole) { From 8cb9d38d400272ad6d444c89ff5597fbd52e0c0b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 May 2011 12:25:50 +0200 Subject: [PATCH 12/57] add ArrayInitializerExpression and ObjectCreationExpression --- .../Expressions/ArrayInitializerExpression.cs | 53 +++++++++++++++++++ .../Expressions/ObjectCreationExpression.cs | 47 ++++++++++++++-- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 27 +++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 7 ++- 6 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs new file mode 100644 index 0000000000..772602de9d --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs @@ -0,0 +1,53 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// { Elements } + /// + public class ArrayInitializerExpression : Expression + { + #region Null + public new static readonly ArrayInitializerExpression Null = new NullArrayInitializerExpression (); + + sealed class NullArrayInitializerExpression : ArrayInitializerExpression + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + public readonly static Role InitializerRole = new Role("Initializer", ArrayInitializerExpression.Null); + + public AstNodeCollection Elements { + get { return GetChildrenByRole(Roles.Expression); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitArrayInitializerExpression (this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ArrayInitializerExpression o = other as ArrayInitializerExpression; + return o != null && this.Elements.DoMatch(o.Elements, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs index f940c71b06..093efb737d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs @@ -2,19 +2,58 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Collections.Generic; namespace ICSharpCode.NRefactory.VB.Ast { + /// + /// New Type(Arguments) { Initializer } + /// public class ObjectCreationExpression : Expression { - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + public readonly static Role InitializerRole = ArrayInitializerExpression.InitializerRole; + + public AstType Type { + get { return GetChildByRole (Roles.Type); } + set { SetChildByRole (Roles.Type, value); } + } + + public AstNodeCollection Arguments { + get { return GetChildrenByRole (Roles.Argument); } + } + + public ArrayInitializerExpression Initializer { + get { return GetChildByRole (InitializerRole); } + set { SetChildByRole (InitializerRole, value); } + } + + public ObjectCreationExpression() + { + } + + public ObjectCreationExpression (AstType type, IEnumerable arguments = null) + { + AddChild (type, Roles.Type); + if (arguments != null) { + foreach (var arg in arguments) { + AddChild (arg, Roles.Argument); + } + } + } + + public ObjectCreationExpression (AstType type, params Expression[] arguments) : this (type, (IEnumerable)arguments) + { + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) { - throw new NotImplementedException(); + return visitor.VisitObjectCreationExpression(this, data); } - public override S AcceptVisitor(IAstVisitor visitor, T data) + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { - throw new NotImplementedException(); + ObjectCreationExpression o = other as ObjectCreationExpression; + return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.Initializer.DoMatch(o.Initializer, match); } } } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index e96f9c1172..f6b5a23367 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -58,6 +58,8 @@ namespace ICSharpCode.NRefactory.VB { S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data); S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); S VisitInvocationExpression(InvocationExpression invocationExpression, T data); + S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data); + S VisitObjectCreationExpression(ObjectCreationExpression objectCreationExpression, T data); // Statement scope S VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 427cd102de..a257a082bb 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -48,6 +48,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 44ef830aaf..08b4c374f9 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -494,7 +494,9 @@ namespace ICSharpCode.NRefactory.VB WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, false); NewLine(); - // TODO Body + Indent(); + WriteBlock(constructorDeclaration.Body); + Unindent(); WriteKeyword("End"); WriteKeyword("Sub"); @@ -1578,5 +1580,28 @@ namespace ICSharpCode.NRefactory.VB WriteCommaSeparatedListInParenthesis(invocationExpression.Arguments, false); return EndNode(invocationExpression); } + + public object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data) + { + StartNode(arrayInitializerExpression); + WriteToken("{", ArrayInitializerExpression.Roles.LBrace); + Space(); + WriteCommaSeparatedList(arrayInitializerExpression.Elements); + Space(); + WriteToken("}", ArrayInitializerExpression.Roles.RBrace); + return EndNode(arrayInitializerExpression); + } + + public object VisitObjectCreationExpression(ObjectCreationExpression objectCreationExpression, object data) + { + StartNode(objectCreationExpression); + + WriteKeyword("New"); + objectCreationExpression.Type.AcceptVisitor(this, data); + WriteCommaSeparatedListInParenthesis(objectCreationExpression.Arguments, false); + objectCreationExpression.Initializer.AcceptVisitor(this, data); + + return EndNode(objectCreationExpression); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index e4555bc375..054d5a470c 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -269,7 +269,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitObjectCreateExpression(CSharp.ObjectCreateExpression objectCreateExpression, object data) { - throw new NotImplementedException(); + var expr = new ObjectCreationExpression((AstType)objectCreateExpression.Type.AcceptVisitor(this, data)); + ConvertNodes(objectCreateExpression.Arguments, expr.Arguments); + if (!objectCreateExpression.Initializer.IsNull) + expr.Initializer = (ArrayInitializerExpression)objectCreateExpression.Initializer.AcceptVisitor(this, data); + + return EndNode(objectCreateExpression, expr); } public AstNode VisitAnonymousTypeCreateExpression(CSharp.AnonymousTypeCreateExpression anonymousTypeCreateExpression, object data) From 0f3377452672bda1da29690d7e82ea43f81051f1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 May 2011 12:44:28 +0200 Subject: [PATCH 13/57] output ThrowStatement --- ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs | 9 ++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 08b4c374f9..430093ba4e 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1252,7 +1252,9 @@ namespace ICSharpCode.NRefactory.VB else { variableDeclarator.Type.AcceptVisitor(this, data); if (!variableDeclarator.Initializer.IsNull) { + Space(); WriteToken("=", VariableDeclarator.Roles.Assign); + Space(); variableDeclarator.Initializer.AcceptVisitor(this, data); } } @@ -1378,7 +1380,12 @@ namespace ICSharpCode.NRefactory.VB public object VisitThrowStatement(ThrowStatement throwStatement, object data) { - throw new NotImplementedException(); + StartNode(throwStatement); + + WriteKeyword("Throw"); + throwStatement.Expression.AcceptVisitor(this, data); + + return EndNode(throwStatement); } public object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 054d5a470c..1f4fa1b246 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -647,7 +647,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitThrowStatement(CSharp.ThrowStatement throwStatement, object data) { - throw new NotImplementedException(); + return EndNode(throwStatement, new ThrowStatement((Expression)throwStatement.Expression.AcceptVisitor(this, data))); } public AstNode VisitTryCatchStatement(CSharp.TryCatchStatement tryCatchStatement, object data) From d83c0e6d371c33623d6e45f37ce2a23be4269ced Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 May 2011 16:49:33 +0200 Subject: [PATCH 14/57] add support for comments --- ICSharpCode.NRefactory.VB/Ast/AstNode.cs | 32 +-------- ICSharpCode.NRefactory.VB/Ast/Comment.cs | 67 +++++++++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 1 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/IOutputFormatter.cs | 4 +- .../OutputVisitor/OutputVisitor.cs | 6 ++ .../TextWriterOutputFormatter.cs | 10 +++ .../Visitors/CSharpToVBConverterVisitor.cs | 7 +- 8 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Comment.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs index 2fd9aa9248..70ede3eaed 100644 --- a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -1,28 +1,5 @@ -// -// AstNode.cs -// -// Author: -// Mike Krüger -// -// Copyright (c) 2009 Novell, Inc (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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; @@ -724,8 +701,5 @@ namespace ICSharpCode.NRefactory.VB } } - public class Comment - { - - } + } diff --git a/ICSharpCode.NRefactory.VB/Ast/Comment.cs b/ICSharpCode.NRefactory.VB/Ast/Comment.cs new file mode 100644 index 0000000000..ee8f6b3853 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Comment.cs @@ -0,0 +1,67 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using ICSharpCode.NRefactory.PatternMatching; +using ICSharpCode.NRefactory.VB.Ast; + +namespace ICSharpCode.NRefactory.VB +{ + public class Comment : AstNode + { + public bool IsDocumentationComment { get; set; } + + public bool StartsLine { + get; + set; + } + + public string Content { + get; + set; + } + + AstLocation startLocation; + public override AstLocation StartLocation { + get { + return startLocation; + } + } + + AstLocation endLocation; + public override AstLocation EndLocation { + get { + return endLocation; + } + } + + public Comment (string content, bool isDocumentation = false) + { + this.IsDocumentationComment = isDocumentation; + this.Content = content; + } + + public Comment (bool isDocumentation, AstLocation startLocation, AstLocation endLocation) + { + this.IsDocumentationComment = isDocumentation; + this.startLocation = startLocation; + this.endLocation = endLocation; + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitComment(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + Comment o = other as Comment; + return o != null && this.IsDocumentationComment == o.IsDocumentationComment && MatchString(this.Content, o.Content); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index f6b5a23367..a9f6d64b54 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -9,6 +9,7 @@ namespace ICSharpCode.NRefactory.VB { public interface IAstVisitor { S VisitBlockStatement(BlockStatement blockStatement, T data); + S VisitComment(Comment comment, T data); S VisitCompilationUnit(CompilationUnit compilationUnit, T data); S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data); S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index a257a082bb..cbb8483124 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -46,6 +46,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs index a544eb0d00..2d8d991a85 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.VB /// /// Writes an identifier. /// If the identifier conflicts with a keyword, the output visitor will - /// call WriteToken("@") before calling WriteIdentifier(). + /// call WriteToken("[") before and WriteToken("]") after calling WriteIdentifier(). /// void WriteIdentifier(string identifier); @@ -35,5 +35,7 @@ namespace ICSharpCode.NRefactory.VB void Unindent(); void NewLine(); + + void WriteComment(bool isDocumentation, string content); } } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 430093ba4e..ff378b376b 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1610,5 +1610,11 @@ namespace ICSharpCode.NRefactory.VB return EndNode(objectCreationExpression); } + + public object VisitComment(Comment comment, object data) + { + formatter.WriteComment(comment.IsDocumentationComment, comment.Content); + return null; + } } } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs index cc2df64ed0..933e966959 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs @@ -79,5 +79,15 @@ namespace ICSharpCode.NRefactory.VB public virtual void EndNode(AstNode node) { } + + public void WriteComment(bool isDocumentation, string content) + { + WriteIndentation(); + if (isDocumentation) + textWriter.Write("'''"); + else + textWriter.Write("'"); + textWriter.WriteLine(content); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 1f4fa1b246..680b88ce74 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -1027,7 +1027,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitComment(CSharp.Comment comment, object data) { - throw new NotImplementedException(); + var c = new Comment(comment.Content, comment.CommentType == CSharp.CommentType.Documentation); + + if (comment.CommentType == CSharp.CommentType.MultiLine) + throw new NotImplementedException(); + + return EndNode(comment, c); } public AstNode VisitTypeParameterDeclaration(CSharp.TypeParameterDeclaration typeParameterDeclaration, object data) From 1e2bce63a4ea109f772a04145da1e4f1e62f595d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 May 2011 17:17:05 +0200 Subject: [PATCH 15/57] do not print method bodies in Interfaces --- .../OutputVisitor/OutputVisitor.cs | 47 +++++++++++-------- .../Visitors/CSharpToVBConverterVisitor.cs | 41 +++++++++++++++- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index ff378b376b..c76643c53e 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -526,15 +526,17 @@ namespace ICSharpCode.NRefactory.VB } WriteHandlesClause(methodDeclaration.HandlesClause); WriteImplementsClause(methodDeclaration.ImplementsClause); - NewLine(); - Indent(); - WriteBlock(methodDeclaration.Body); - Unindent(); - WriteKeyword("End"); - if (methodDeclaration.IsSub) - WriteKeyword("Sub"); - else - WriteKeyword("Function"); + if (!methodDeclaration.Body.IsNull) { + NewLine(); + Indent(); + WriteBlock(methodDeclaration.Body); + Unindent(); + WriteKeyword("End"); + if (methodDeclaration.IsSub) + WriteKeyword("Sub"); + else + WriteKeyword("Function"); + } NewLine(); return EndNode(methodDeclaration); @@ -1317,20 +1319,25 @@ namespace ICSharpCode.NRefactory.VB WriteAttributes(propertyDeclaration.ReturnTypeAttributes); propertyDeclaration.ReturnType.AcceptVisitor(this, data); } - NewLine(); - Indent(); - if (!propertyDeclaration.Getter.IsNull) { - propertyDeclaration.Getter.AcceptVisitor(this, data); - } + bool needsBody = !propertyDeclaration.Getter.Body.IsNull || !propertyDeclaration.Setter.Body.IsNull; - if (!propertyDeclaration.Setter.IsNull) { - propertyDeclaration.Setter.AcceptVisitor(this, data); + if (needsBody) { + NewLine(); + Indent(); + + if (!propertyDeclaration.Getter.Body.IsNull) { + propertyDeclaration.Getter.AcceptVisitor(this, data); + } + + if (!propertyDeclaration.Setter.Body.IsNull) { + propertyDeclaration.Setter.AcceptVisitor(this, data); + } + Unindent(); + + WriteKeyword("End"); + WriteKeyword("Property"); } - Unindent(); - - WriteKeyword("End"); - WriteKeyword("Property"); NewLine(); return EndNode(propertyDeclaration); diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 680b88ce74..4f5c37203a 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -272,7 +272,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors var expr = new ObjectCreationExpression((AstType)objectCreateExpression.Type.AcceptVisitor(this, data)); ConvertNodes(objectCreateExpression.Arguments, expr.Arguments); if (!objectCreateExpression.Initializer.IsNull) - expr.Initializer = (ArrayInitializerExpression)objectCreateExpression.Initializer.AcceptVisitor(this, data); + expr.Initializer = (ArrayInitializerExpression)objectCreateExpression.Initializer.AcceptVisitor(this, data); return EndNode(objectCreateExpression, expr); } @@ -1101,10 +1101,49 @@ namespace ICSharpCode.NRefactory.VB.Visitors mod |= Modifiers.Friend; if ((modifier & CSharp.Modifiers.Private) == CSharp.Modifiers.Private) mod |= Modifiers.Private; + if (container is CSharp.IndexerDeclaration) + mod |= Modifiers.Default; + bool writeable = IsWriteableProperty(container); + bool readable = IsReadableProperty(container); + if (writeable && !readable) + mod |= Modifiers.WriteOnly; + if (readable && !writeable) + mod |= Modifiers.ReadOnly; + return mod; } + bool IsReadableProperty(ICSharpCode.NRefactory.CSharp.AstNode container) + { + if (container is CSharp.IndexerDeclaration) { + var i = container as CSharp.IndexerDeclaration; + return !i.Getter.IsNull; + } + + if (container is CSharp.PropertyDeclaration) { + var p = container as CSharp.PropertyDeclaration; + return !p.Getter.IsNull; + } + + return false; + } + + bool IsWriteableProperty(ICSharpCode.NRefactory.CSharp.AstNode container) + { + if (container is CSharp.IndexerDeclaration) { + var i = container as CSharp.IndexerDeclaration; + return !i.Setter.IsNull; + } + + if (container is CSharp.PropertyDeclaration) { + var p = container as CSharp.PropertyDeclaration; + return !p.Setter.IsNull; + } + + return false; + } + public AstNode VisitIdentifier(CSharp.Identifier identifier, object data) { var ident = new Identifier(identifier.Name, ConvertLocation(identifier.StartLocation)); From 48774e40e480dbd6b89594c903c9d622997445dc Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 May 2011 15:19:48 +0200 Subject: [PATCH 16/57] add support for EventDeclaration and some more binary operators --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 5 - .../Ast/Expressions/Expression.cs | 2 + .../Ast/TypeMembers/EventDeclaration.cs | 59 +++++++ .../Ast/TypeMembers/MethodDeclaration.cs | 4 - ICSharpCode.NRefactory.VB/IAstVisitor.cs | 1 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 144 +++++++++++------- .../Visitors/CSharpToVBConverterVisitor.cs | 68 +++++---- 8 files changed, 190 insertions(+), 94 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index 154fb58c2b..bfe8af953a 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -76,7 +76,6 @@ namespace ICSharpCode.NRefactory.VB.Ast Subtract, Multiply, Divide, - Modulus, Power, // (VB only) DivideInteger, // (VB only) @@ -84,10 +83,6 @@ namespace ICSharpCode.NRefactory.VB.Ast ShiftLeft, ShiftRight, - - BitwiseAnd, - BitwiseOr, - ExclusiveOr, } public enum CastType diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index 0764501c17..c656b485cf 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public class BinaryOperatorExpression : Expression { public readonly static Role LeftExpressionRole = new Role("Left"); + public readonly static Role OperatorRole = new Role("Operator"); public readonly static Role RightExpressionRole = new Role("Right"); public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right) @@ -136,6 +137,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public class AssignmentExpression : Expression { public readonly static Role LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; + public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; public readonly static Role RightExpressionRole = BinaryOperatorExpression.RightExpressionRole; public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right) diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs new file mode 100644 index 0000000000..5357ef47d9 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs @@ -0,0 +1,59 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class EventDeclaration : MemberDeclaration + { + public bool IsCustom { get; set; } + + public static readonly Role AddHandlerRole = new Role("AddHandler", Accessor.Null); + public static readonly Role RemoveHandlerRole = new Role("RemoveHandler", Accessor.Null); + public static readonly Role RaiseEventRole = new Role("RaiseEvent", Accessor.Null); + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstType ReturnType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public AstNodeCollection ImplementsClause { + get { return GetChildrenByRole(InterfaceMemberSpecifier.InterfaceMemberSpecifierRole); } + } + + public Accessor AddHandlerBlock { + get { return GetChildByRole(AddHandlerRole); } + set { SetChildByRole(AddHandlerRole, value); } + } + + public Accessor RemoveHandlerBlock { + get { return GetChildByRole(RemoveHandlerRole); } + set { SetChildByRole(RemoveHandlerRole, value); } + } + + public Accessor RaiseEventBlock { + get { return GetChildByRole(RaiseEventRole); } + set { SetChildByRole(RaiseEventRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitEventDeclaration(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs index dd699c601f..7da71936a1 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs @@ -69,8 +69,4 @@ namespace ICSharpCode.NRefactory.VB.Ast return visitor.VisitMethodDeclaration(this, data); } } - - - - } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index a9f6d64b54..b403ba709e 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -40,6 +40,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitVariableIdentifier(VariableIdentifier variableIdentifier, T data); S VisitAccessor(Accessor accessor, T data); S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data); + S VisitEventDeclaration(EventDeclaration eventDeclaration, T data); // Expression scope S VisitIdentifier(Identifier identifier, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index cbb8483124..f686043a4e 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -87,6 +87,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index c76643c53e..fefd872eb8 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1285,6 +1285,12 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("Get"); } else if (accessor.Role == PropertyDeclaration.SetterRole) { WriteKeyword("Set"); + } else if (accessor.Role == EventDeclaration.AddHandlerRole) { + WriteKeyword("AddHandler"); + } else if (accessor.Role == EventDeclaration.RemoveHandlerRole) { + WriteKeyword("RemoveHandler"); + } else if (accessor.Role == EventDeclaration.RaiseEventRole) { + WriteKeyword("RaiseEvent"); } if (accessor.Parameters.Any()) WriteCommaSeparatedListInParenthesis(accessor.Parameters, false); @@ -1298,6 +1304,12 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("Get"); } else if (accessor.Role == PropertyDeclaration.SetterRole) { WriteKeyword("Set"); + } else if (accessor.Role == EventDeclaration.AddHandlerRole) { + WriteKeyword("AddHandler"); + } else if (accessor.Role == EventDeclaration.RemoveHandlerRole) { + WriteKeyword("RemoveHandler"); + } else if (accessor.Role == EventDeclaration.RaiseEventRole) { + WriteKeyword("RaiseEvent"); } NewLine(); @@ -1431,89 +1443,83 @@ namespace ICSharpCode.NRefactory.VB binaryOperatorExpression.Left.AcceptVisitor(this, data); Space(); switch (binaryOperatorExpression.Operator) { - case BinaryOperatorType.None: - - break; case BinaryOperatorType.BitwiseAnd: - + WriteKeyword("And"); break; case BinaryOperatorType.BitwiseOr: - + WriteKeyword("Or"); break; case BinaryOperatorType.LogicalAnd: - + WriteKeyword("AndAlso"); break; case BinaryOperatorType.LogicalOr: - + WriteKeyword("OrElse"); break; case BinaryOperatorType.ExclusiveOr: - + WriteKeyword("Xor"); break; case BinaryOperatorType.GreaterThan: - + WriteToken(">", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.GreaterThanOrEqual: - + WriteToken(">=", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Equality: - WriteToken("=", BinaryOperatorExpression.Roles.Assign); + WriteToken("=", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.InEquality: - + WriteToken("<>", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.LessThan: - + WriteToken("<", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.LessThanOrEqual: - + WriteToken("<=", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Add: - + WriteToken("+", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Subtract: - + WriteToken("-", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Multiply: - + WriteToken("*", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Divide: - + WriteToken("/", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Modulus: - + WriteKeyword("Mod"); break; case BinaryOperatorType.DivideInteger: - + WriteToken("\\", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Power: - + WriteToken("*", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.Concat: - + WriteToken("&", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.ShiftLeft: - + WriteToken("<<", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.ShiftRight: - + WriteToken(">>", BinaryOperatorExpression.OperatorRole); break; case BinaryOperatorType.ReferenceEquality: - + WriteKeyword("Is"); break; case BinaryOperatorType.ReferenceInequality: - + WriteKeyword("IsNot"); break; case BinaryOperatorType.Like: - - break; - case BinaryOperatorType.NullCoalescing: - + WriteKeyword("Like"); break; case BinaryOperatorType.DictionaryAccess: - + WriteToken("!", BinaryOperatorExpression.OperatorRole); break; default: - throw new Exception("Invalid value for BinaryOperatorType"); + throw new Exception("Invalid value for BinaryOperatorType: " + binaryOperatorExpression.Operator); } Space(); binaryOperatorExpression.Right.AcceptVisitor(this, data); @@ -1534,53 +1540,39 @@ namespace ICSharpCode.NRefactory.VB assignmentExpression.Left.AcceptVisitor(this, data); Space(); switch (assignmentExpression.Operator) { - case AssignmentOperatorType.None: - - break; case AssignmentOperatorType.Assign: - WriteToken("=", AssignmentExpression.Roles.Assign); + WriteToken("=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.Add: - + WriteToken("+=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.Subtract: - + WriteToken("-=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.Multiply: - + WriteToken("*=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.Divide: - - break; - case AssignmentOperatorType.Modulus: - + WriteToken("/=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.Power: - + WriteToken("^=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.DivideInteger: - + WriteToken("\\=", AssignmentExpression.OperatorRole); + break; break; case AssignmentOperatorType.ConcatString: - + WriteToken("&=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.ShiftLeft: - + WriteToken("<<=", AssignmentExpression.OperatorRole); break; case AssignmentOperatorType.ShiftRight: - - break; - case AssignmentOperatorType.BitwiseAnd: - - break; - case AssignmentOperatorType.BitwiseOr: - - break; - case AssignmentOperatorType.ExclusiveOr: - + WriteToken(">>=", AssignmentExpression.OperatorRole); break; default: - throw new Exception("Invalid value for AssignmentOperatorType"); + throw new Exception("Invalid value for AssignmentOperatorType: " + assignmentExpression.Operator); } Space(); assignmentExpression.Right.AcceptVisitor(this, data); @@ -1623,5 +1615,41 @@ namespace ICSharpCode.NRefactory.VB formatter.WriteComment(comment.IsDocumentationComment, comment.Content); return null; } + + public object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) + { + StartNode(eventDeclaration); + + WriteAttributes(eventDeclaration.Attributes); + WriteModifiers(eventDeclaration.ModifierTokens); + if (eventDeclaration.IsCustom) + WriteKeyword("Custom"); + WriteKeyword("Event"); + WriteIdentifier(eventDeclaration.Name.Name); + if (!eventDeclaration.IsCustom && eventDeclaration.ReturnType.IsNull) + WriteCommaSeparatedListInParenthesis(eventDeclaration.Parameters, false); + if (!eventDeclaration.ReturnType.IsNull) { + Space(); + WriteKeyword("As"); + eventDeclaration.ReturnType.AcceptVisitor(this, data); + } + WriteImplementsClause(eventDeclaration.ImplementsClause); + + if (eventDeclaration.IsCustom) { + NewLine(); + Indent(); + + eventDeclaration.AddHandlerBlock.AcceptVisitor(this, data); + eventDeclaration.RemoveHandlerBlock.AcceptVisitor(this, data); + eventDeclaration.RaiseEventBlock.AcceptVisitor(this, data); + + Unindent(); + WriteKeyword("End"); + WriteKeyword("Event"); + } + NewLine(); + + return EndNode(eventDeclaration); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 4f5c37203a..69e5b7dace 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -64,10 +64,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors op = AssignmentOperatorType.Assign; break; case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Add: - + op = AssignmentOperatorType.Add; break; case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Subtract: - + op = AssignmentOperatorType.Subtract; break; case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply: @@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors break; default: - throw new Exception("Invalid value for AssignmentOperatorType"); + throw new Exception("Invalid value for AssignmentOperatorType: " + assignmentExpression.Operator); } var right = (Expression)assignmentExpression.Right.AcceptVisitor(this, data); @@ -124,22 +124,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors op = BinaryOperatorType.BitwiseAnd; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseOr: - + op = BinaryOperatorType.BitwiseOr; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalAnd: - + op = BinaryOperatorType.LogicalAnd; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalOr: - + op = BinaryOperatorType.LogicalOr; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ExclusiveOr: - + op = BinaryOperatorType.ExclusiveOr; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThan: - + op = BinaryOperatorType.GreaterThan; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThanOrEqual: - + op = BinaryOperatorType.GreaterThanOrEqual; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Equality: op = BinaryOperatorType.Equality; @@ -148,40 +148,34 @@ namespace ICSharpCode.NRefactory.VB.Visitors op = BinaryOperatorType.InEquality; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThan: - + op = BinaryOperatorType.LessThan; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThanOrEqual: - + op = BinaryOperatorType.LessThanOrEqual; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Add: - + op = BinaryOperatorType.Add; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Subtract: - + op = BinaryOperatorType.Subtract; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Multiply: - + op = BinaryOperatorType.Multiply; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Divide: - + op = BinaryOperatorType.Divide; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Modulus: - + op = BinaryOperatorType.Modulus; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftLeft: - + op = BinaryOperatorType.ShiftLeft; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftRight: - - break; - case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.NullCoalescing: - - break; - case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Any: - + op = BinaryOperatorType.ShiftRight; break; default: - throw new Exception("Invalid value for BinaryOperatorType"); + throw new Exception("Invalid value for BinaryOperatorType: " + binaryOperatorExpression.Operator); } return EndNode(binaryOperatorExpression, new BinaryOperatorExpression(left, op, right)); @@ -745,12 +739,32 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitEventDeclaration(CSharp.EventDeclaration eventDeclaration, object data) { - throw new NotImplementedException(); + var result = new EventDeclaration(); + // TODO event declaration + +// ConvertNodes(eventDeclaration.Attributes, result.Attributes); +// result.Modifiers = ConvertModifiers(eventDeclaration.Modifiers, eventDeclaration); +// result.Name = new Identifier(eventDeclaration., AstLocation.Empty); + + return EndNode(eventDeclaration, result); } public AstNode VisitCustomEventDeclaration(CSharp.CustomEventDeclaration customEventDeclaration, object data) { - throw new NotImplementedException(); + var result = new EventDeclaration(); + ConvertNodes(customEventDeclaration.Attributes, result.Attributes); + result.Modifiers = ConvertModifiers(customEventDeclaration.Modifiers, customEventDeclaration); + result.IsCustom = true; + result.Name = new Identifier(customEventDeclaration.Name, AstLocation.Empty); + result.ReturnType = (AstType)customEventDeclaration.ReturnType.AcceptVisitor(this, data); + if (!customEventDeclaration.PrivateImplementationType.IsNull) + result.ImplementsClause.Add( + new InterfaceMemberSpecifier((AstType)customEventDeclaration.PrivateImplementationType.AcceptVisitor(this, data), customEventDeclaration.Name)); + + result.AddHandlerBlock = (Accessor)customEventDeclaration.AddAccessor.AcceptVisitor(this, data); + result.RemoveHandlerBlock = (Accessor)customEventDeclaration.RemoveAccessor.AcceptVisitor(this, data); + + return EndNode(customEventDeclaration, result); } public AstNode VisitFieldDeclaration(CSharp.FieldDeclaration fieldDeclaration, object data) From 3381b04961094df6ef7d9cde7f03fd5f10a30284 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 28 Jun 2011 21:51:23 +0200 Subject: [PATCH 17/57] implement ArrayCreateExpression and CastExpression --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 20 ---- .../Ast/Expressions/ArrayCreateExpression.cs | 66 +++++++++++++ .../Ast/Expressions/CastExpression.cs | 95 ++++++++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 + .../ICSharpCode.NRefactory.VB.csproj | 2 + .../OutputVisitor/OutputVisitor.cs | 99 +++++++++++++++++++ .../Visitors/CSharpToVBConverterVisitor.cs | 56 ++++++++++- 7 files changed, 316 insertions(+), 24 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/CastExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index bfe8af953a..de56e432aa 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -85,26 +85,6 @@ namespace ICSharpCode.NRefactory.VB.Ast ShiftRight, } - public enum CastType - { - /// - /// direct cast (C#, VB "DirectCast") - /// - Cast, - /// - /// try cast (C# "as", VB "TryCast") - /// - TryCast, - /// - /// converting cast (VB "CType") - /// - Conversion, - /// - /// primitive converting cast (VB "CString" etc.) - /// - PrimitiveConversion - } - public enum UnaryOperatorType { None, diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs new file mode 100644 index 0000000000..544213829b --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs @@ -0,0 +1,66 @@ +// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// New Type[Dimensions] + /// + public class ArrayCreateExpression : Expression + { + public readonly static Role AdditionalArraySpecifierRole = new Role("AdditionalArraySpecifier"); + public readonly static Role InitializerRole = new Role("Initializer", ArrayInitializerExpression.Null); + + public AstType Type { + get { return GetChildByRole (Roles.Type); } + set { SetChildByRole (Roles.Type, value); } + } + + public AstNodeCollection Arguments { + get { return GetChildrenByRole (Roles.Argument); } + } + + /// + /// Gets additional array ranks (those without size info). + /// Empty for "New Integer(5,1)"; will contain a single element for "New Integer(5)()". + /// + public AstNodeCollection AdditionalArraySpecifiers { + get { return GetChildrenByRole(AdditionalArraySpecifierRole); } + } + + public ArrayInitializerExpression Initializer { + get { return GetChildByRole (InitializerRole); } + set { SetChildByRole (InitializerRole, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitArrayCreateExpression (this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ArrayCreateExpression o = other as ArrayCreateExpression; + return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) && this.Initializer.DoMatch(o.Initializer, match); + } + } + + +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/CastExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/CastExpression.cs new file mode 100644 index 0000000000..5cdbd3fa63 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/CastExpression.cs @@ -0,0 +1,95 @@ +// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// CastType(Expression, AstType) + /// + public class CastExpression : Expression + { + public CastType CastType { get; set; } + + public VBTokenNode CastTypeToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public AstType Type { + get { return GetChildByRole (Roles.Type); } + set { SetChildByRole (Roles.Type, value); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public CastExpression () + { + } + + public CastExpression (CastType castType, AstType castToType, Expression expression) + { + CastType = castType; + AddChild (castToType, Roles.Type); + AddChild (expression, Roles.Expression); + } + + public CastExpression (CastType castType, Expression expression) + { + CastType = castType; + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitCastExpression (this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + CastExpression o = other as CastExpression; + return o != null && this.CastType == o.CastType && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match); + } + } + + public enum CastType + { + DirectCast, + TryCast, + CType, + CBool, + CByte, + CChar, + CDate, + CDec, + CDbl, + CInt, + CLng, + CObj, + CSByte, + CShort, + CSng, + CStr, + CUInt, + CULng, + CUShort + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index b403ba709e..4215de42b3 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -61,7 +61,9 @@ namespace ICSharpCode.NRefactory.VB { S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); S VisitInvocationExpression(InvocationExpression invocationExpression, T data); S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data); + S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data); S VisitObjectCreationExpression(ObjectCreationExpression objectCreationExpression, T data); + S VisitCastExpression(CastExpression castExpression, T data); // Statement scope S VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index f686043a4e..bf288e0841 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -49,7 +49,9 @@ + + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index fefd872eb8..48d00c13aa 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1598,6 +1598,23 @@ namespace ICSharpCode.NRefactory.VB return EndNode(arrayInitializerExpression); } + public object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) + { + StartNode(arrayCreateExpression); + WriteKeyword("New"); + Space(); + arrayCreateExpression.Type.AcceptVisitor(this, data); + WriteCommaSeparatedListInParenthesis(arrayCreateExpression.Arguments, false); + foreach (var specifier in arrayCreateExpression.AdditionalArraySpecifiers) { + specifier.AcceptVisitor(this, data); + } + Space(); + WriteToken("=", ArrayCreateExpression.Roles.Assign); + Space(); + arrayCreateExpression.Initializer.AcceptVisitor(this, data); + return EndNode(arrayCreateExpression); + } + public object VisitObjectCreationExpression(ObjectCreationExpression objectCreationExpression, object data) { StartNode(objectCreationExpression); @@ -1610,6 +1627,88 @@ namespace ICSharpCode.NRefactory.VB return EndNode(objectCreationExpression); } + public object VisitCastExpression(CastExpression castExpression, object data) + { + StartNode(castExpression); + + switch (castExpression.CastType) { + case CastType.DirectCast: + WriteKeyword("DirectCast"); + break; + case CastType.TryCast: + WriteKeyword("TryCast"); + break; + case CastType.CType: + WriteKeyword("CType"); + break; + case CastType.CBool: + WriteKeyword("CBool"); + break; + case CastType.CByte: + WriteKeyword("CByte"); + break; + case CastType.CChar: + WriteKeyword("CChar"); + break; + case CastType.CDate: + WriteKeyword("CDate"); + break; + case CastType.CDec: + WriteKeyword("CType"); + break; + case CastType.CDbl: + WriteKeyword("CDec"); + break; + case CastType.CInt: + WriteKeyword("CInt"); + break; + case CastType.CLng: + WriteKeyword("CLng"); + break; + case CastType.CObj: + WriteKeyword("CObj"); + break; + case CastType.CSByte: + WriteKeyword("CSByte"); + break; + case CastType.CShort: + WriteKeyword("CShort"); + break; + case CastType.CSng: + WriteKeyword("CSng"); + break; + case CastType.CStr: + WriteKeyword("CStr"); + break; + case CastType.CUInt: + WriteKeyword("CUInt"); + break; + case CastType.CULng: + WriteKeyword("CULng"); + break; + case CastType.CUShort: + WriteKeyword("CUShort"); + break; + default: + throw new Exception("Invalid value for CastType"); + } + + WriteToken("(", CastExpression.Roles.LPar); + castExpression.Expression.AcceptVisitor(this, data); + + if (castExpression.CastType == CastType.CType || + castExpression.CastType == CastType.DirectCast || + castExpression.CastType == CastType.TryCast) { + WriteToken(",", CastExpression.Roles.Comma); + Space(); + castExpression.Type.AcceptVisitor(this, data); + } + + WriteToken(")", CastExpression.Roles.RPar); + + return EndNode(castExpression); + } + public object VisitComment(Comment comment, object data) { formatter.WriteComment(comment.IsDocumentationComment, comment.Content); diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 69e5b7dace..7931ee5342 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -15,6 +15,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors string RootNamespace { get; } string GetTypeNameForAttribute(CSharp.Attribute attribute); ClassType GetClassTypeForAstType(CSharp.AstType type); + IType ResolveExpression(CSharp.Expression expression); } /// @@ -41,12 +42,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitArrayCreateExpression(CSharp.ArrayCreateExpression arrayCreateExpression, object data) { - throw new NotImplementedException(); + var expr = new ArrayCreateExpression() { + Type = (AstType)arrayCreateExpression.Type.AcceptVisitor(this, data), + Initializer = (ArrayInitializerExpression)arrayCreateExpression.Initializer.AcceptVisitor(this, data) + }; + ConvertNodes(arrayCreateExpression.Arguments, expr.Arguments); + ConvertNodes(arrayCreateExpression.AdditionalArraySpecifiers, expr.AdditionalArraySpecifiers); + + return EndNode(arrayCreateExpression, expr); } public AstNode VisitArrayInitializerExpression(CSharp.ArrayInitializerExpression arrayInitializerExpression, object data) { - throw new NotImplementedException(); + var expr = new ArrayInitializerExpression(); + ConvertNodes(arrayInitializerExpression.Elements, expr.Elements); + + return EndNode(arrayInitializerExpression, expr); } public AstNode VisitAsExpression(CSharp.AsExpression asExpression, object data) @@ -183,7 +194,34 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitCastExpression(CSharp.CastExpression castExpression, object data) { - throw new NotImplementedException(); + var expr = new CastExpression(); + + expr.Type = (AstType)castExpression.Type.AcceptVisitor(this, data); + // TODO read additional type information from annotation + // (int)x is equivalent to CInt(Math.Truncate(x)) + expr.CastType = GetCastType(expr.Type, null); + expr.Expression = (Expression)castExpression.Expression.AcceptVisitor(this, data); + + if (expr.CastType != CastType.CType) + expr.Type = null; + + return EndNode(castExpression, expr); + } + + CastType GetCastType(AstType type, object typeInformation) + { + var primType = type as PrimitiveType; + if (primType == null) + return CastType.CType; + + switch (primType.Keyword) { + case "Integer": + return CastType.CInt; + case "String": + return CastType.CStr; + } + + return CastType.CType; } public AstNode VisitCheckedExpression(CSharp.CheckedExpression checkedExpression, object data) @@ -712,13 +750,23 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(constructorDeclaration.ModifierTokens, result.ModifierTokens); ConvertNodes(constructorDeclaration.Parameters, result.Parameters); result.Body = (BlockStatement)constructorDeclaration.Body.AcceptVisitor(this, data); + if (!constructorDeclaration.Initializer.IsNull) + result.Body.Statements.InsertBefore(result.Body.FirstOrDefault(), (Statement)constructorDeclaration.Initializer.AcceptVisitor(this, data)); return EndNode(constructorDeclaration, result); } public AstNode VisitConstructorInitializer(CSharp.ConstructorInitializer constructorInitializer, object data) { - throw new NotImplementedException(); + var result = new InvocationExpression( + new MemberAccessExpression() { + Target = new InstanceExpression(constructorInitializer.ConstructorInitializerType == CSharp.ConstructorInitializerType.This ? InstanceExpressionType.Me : InstanceExpressionType.MyBase, AstLocation.Empty), + Member = new Identifier("New", AstLocation.Empty) + } + ); + ConvertNodes(constructorInitializer.Arguments, result.Arguments); + + return EndNode(constructorInitializer, new ExpressionStatement(result)); } public AstNode VisitDestructorDeclaration(CSharp.DestructorDeclaration destructorDeclaration, object data) From 1bb5b83fd57b5c482152914524ea516b4ade192e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 29 Jun 2011 21:46:57 +0200 Subject: [PATCH 18/57] implement conversion of AsExpression to TryCast, improve conversion of string literals, add UnaryOperatorExpression --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 21 --- .../Ast/Expressions/Expression.cs | 67 +++++++ ICSharpCode.NRefactory.VB/Ast/Identifier.cs | 5 + ICSharpCode.NRefactory.VB/IAstVisitor.cs | 1 + .../OutputVisitor/OutputVisitor.cs | 23 +++ .../Visitors/CSharpToVBConverterVisitor.cs | 166 ++++++++++++++---- 6 files changed, 229 insertions(+), 54 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index de56e432aa..b54c49b65a 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -85,27 +85,6 @@ namespace ICSharpCode.NRefactory.VB.Ast ShiftRight, } - public enum UnaryOperatorType - { - None, - Not, - BitNot, - - Minus, - Plus, - - Increment, - Decrement, - - PostIncrement, - PostDecrement, - - /// Dereferencing pointer - Dereference, - /// Get address of - AddressOf - } - public enum ContinueType { None, diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index c656b485cf..212db02c34 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -213,4 +213,71 @@ namespace ICSharpCode.NRefactory.VB.Ast return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match); } } + + /// + /// Operator Expression + /// + public class UnaryOperatorExpression : Expression + { + public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; + + public UnaryOperatorExpression() + { + } + + public UnaryOperatorExpression(UnaryOperatorType op, Expression expression) + { + this.Operator = op; + this.Expression = expression; + } + + public UnaryOperatorType Operator { + get; + set; + } + + public VBTokenNode OperatorToken { + get { return GetChildByRole (OperatorRole); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitUnaryOperatorExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + UnaryOperatorExpression o = other as UnaryOperatorExpression; + return o != null && this.Operator == o.Operator && this.Expression.DoMatch(o.Expression, match); + } + + public static string GetOperatorSymbol(UnaryOperatorType op) + { + switch (op) { + case UnaryOperatorType.Not: + return "Not"; + case UnaryOperatorType.Minus: + return "-"; + case UnaryOperatorType.Plus: + return "+"; + default: + throw new NotSupportedException("Invalid value for UnaryOperatorType"); + } + } + } + + public enum UnaryOperatorType + { + /// Logical/Bitwise not (Not a) + Not, + /// Unary minus (-a) + Minus, + /// Unary plus (+a) + Plus + } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Identifier.cs b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs index ea308b7f9f..72f3cbdd20 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Identifier.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs @@ -69,6 +69,11 @@ namespace ICSharpCode.NRefactory.VB.Ast this.startLocation = location; } + public static implicit operator Identifier(string name) + { + return new Identifier(name, AstLocation.Empty); + } + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { var node = other as Identifier; diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 4215de42b3..bbe2331b67 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -56,6 +56,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, T data); S VisitMemberAccessExpression(MemberAccessExpression memberAccessExpression, T data); S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); + S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data); S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data); S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data); S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 48d00c13aa..2632900946 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1750,5 +1750,28 @@ namespace ICSharpCode.NRefactory.VB return EndNode(eventDeclaration); } + + public object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) + { + StartNode(unaryOperatorExpression); + + switch (unaryOperatorExpression.Operator) { + case UnaryOperatorType.Not: + WriteKeyword("Not"); + break; + case UnaryOperatorType.Minus: + WriteToken("-", UnaryOperatorExpression.OperatorRole); + break; + case UnaryOperatorType.Plus: + WriteToken("+", UnaryOperatorExpression.OperatorRole); + break; + default: + throw new Exception("Invalid value for UnaryOperatorType"); + } + + unaryOperatorExpression.Expression.AcceptVisitor(this, data); + + return EndNode(unaryOperatorExpression); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 7931ee5342..b8fce019ef 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -37,6 +37,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitUndocumentedExpression(CSharp.UndocumentedExpression undocumentedExpression, object data) { + // 29.06.2011 20:28:36 Siegfried Pammer: wie soll ich die behandeln? + // 29.06.2011 20:28:58 Siegfried Pammer: throw new NotSupportedException(); ? + // 29.06.2011 20:35:50 Daniel Grunwald: da würde ich wieder Pseudo-Funktionen einführen throw new NotImplementedException(); } @@ -62,7 +65,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAsExpression(CSharp.AsExpression asExpression, object data) { - throw new NotImplementedException(); + return EndNode(asExpression, new CastExpression(CastType.TryCast, (AstType)asExpression.Type.AcceptVisitor(this, data), (Expression)asExpression.Expression.AcceptVisitor(this, data))); } public AstNode VisitAssignmentExpression(CSharp.AssignmentExpression assignmentExpression, object data) @@ -80,33 +83,30 @@ namespace ICSharpCode.NRefactory.VB.Visitors case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Subtract: op = AssignmentOperatorType.Subtract; break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Divide: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Modulus: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftLeft: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftRight: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseAnd: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseOr: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ExclusiveOr: - - break; - case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Any: - - break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply: +// +// break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Divide: +// +// break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Modulus: +// +// break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftLeft: +// +// break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftRight: +// +// break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseAnd: +// +// break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseOr: +// +// break; +// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ExclusiveOr: +// +// break; default: throw new Exception("Invalid value for AssignmentOperatorType: " + assignmentExpression.Operator); } @@ -242,7 +242,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitDirectionExpression(CSharp.DirectionExpression directionExpression, object data) { - throw new NotImplementedException(); + return EndNode(directionExpression, (Expression)directionExpression.Expression.AcceptVisitor(this, data)); } public AstNode VisitIdentifierExpression(CSharp.IdentifierExpression identifierExpression, object data) @@ -256,7 +256,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitIndexerExpression(CSharp.IndexerExpression indexerExpression, object data) { - throw new NotImplementedException(); + var expr = new InvocationExpression((Expression)indexerExpression.Target.AcceptVisitor(this, data)); + ConvertNodes(indexerExpression.Arguments, expr.Arguments); + return EndNode(indexerExpression, expr); } public AstNode VisitInvocationExpression(CSharp.InvocationExpression invocationExpression, object data) @@ -330,11 +332,52 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitPrimitiveExpression(CSharp.PrimitiveExpression primitiveExpression, object data) { - var expr = new PrimitiveExpression(primitiveExpression.Value); + Expression expr; + + if (primitiveExpression.Value is string && ((string)primitiveExpression.Value).IndexOfAny(new[] {'\r', '\n'}) > -1) + expr = ConvertToConcat((string)primitiveExpression.Value); + else + expr = new PrimitiveExpression(primitiveExpression.Value); return EndNode(primitiveExpression, expr); } + Expression ConvertToConcat(string literal) + { + Stack parts = new Stack(); + int start = 0; + + for (int i = 0; i < literal.Length; i++) { + if (literal[i] == '\r') { + string part = literal.Substring(start, i - start); + parts.Push(new PrimitiveExpression(part)); + if (i + 1 < literal.Length && literal[i + 1] == '\n') { + i++; + parts.Push(new IdentifierExpression() { Identifier = "vbCrLf" }); + } else + parts.Push(new IdentifierExpression() { Identifier = "vbCr" }); + start = i + 1; + } else if (literal[i] == '\n') { + string part = literal.Substring(start, i - start); + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression() { Identifier = "vbLf" }); + start = i + 1; + } + } + + if (start < literal.Length) { + string part = literal.Substring(start); + parts.Push(new PrimitiveExpression(part)); + } + + Expression current = parts.Pop(); + + while (parts.Any()) + current = new BinaryOperatorExpression(parts.Pop(), BinaryOperatorType.Concat, current); + + return current; + } + public AstNode VisitSizeOfExpression(CSharp.SizeOfExpression sizeOfExpression, object data) { throw new NotImplementedException(); @@ -367,7 +410,59 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitUnaryOperatorExpression(CSharp.UnaryOperatorExpression unaryOperatorExpression, object data) { - throw new NotImplementedException(); + Expression expr; + + switch (unaryOperatorExpression.Operator) { + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Not: + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.BitNot: + expr = new UnaryOperatorExpression() { + Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data), + Operator = UnaryOperatorType.Not + }; + break; + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Minus: + expr = new UnaryOperatorExpression() { + Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data), + Operator = UnaryOperatorType.Minus + }; + break; + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Plus: + expr = new UnaryOperatorExpression() { + Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data), + Operator = UnaryOperatorType.Plus + }; + break; + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Increment: + expr = new InvocationExpression(); + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "Increment" }; + ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); + break; + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.PostIncrement: + expr = new InvocationExpression(); + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "PostIncrement" }; + ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); + break; + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Decrement: + expr = new InvocationExpression(); + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "Decrement" }; + ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); + break; + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.PostDecrement: + expr = new InvocationExpression(); + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "PostDecrement" }; + ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); + break; + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.AddressOf: + expr = new AddressOfExpression() { + Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data) + }; + break; +// case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Dereference: + default: + throw new Exception("Invalid value for UnaryOperatorType"); + } + + return EndNode(unaryOperatorExpression, expr); } public AstNode VisitUncheckedExpression(CSharp.UncheckedExpression uncheckedExpression, object data) @@ -894,6 +989,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors param.Modifiers = ConvertParamModifiers(parameterDeclaration.ParameterModifier); if ((param.Modifiers & Modifiers.None) == Modifiers.None) param.Modifiers = Modifiers.ByVal; + if ((parameterDeclaration.ParameterModifier & ICSharpCode.NRefactory.CSharp.ParameterModifier.Out) == ICSharpCode.NRefactory.CSharp.ParameterModifier.Out) { + AttributeBlock block = new AttributeBlock(); + block.Attributes.Add(new Ast.Attribute() { Type = new SimpleType("System.Runtime.InteropServices.OutAttribute") }); + param.Attributes.Add(block); + } param.Name = new Identifier(parameterDeclaration.Name, AstLocation.Empty); param.Type = (AstType)parameterDeclaration.Type.AcceptVisitor(this, data); param.OptionalValue = (Expression)parameterDeclaration.DefaultExpression.AcceptVisitor(this, data); @@ -912,7 +1012,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors case ICSharpCode.NRefactory.CSharp.ParameterModifier.Ref: return Modifiers.ByRef; case ICSharpCode.NRefactory.CSharp.ParameterModifier.Out: - return Modifiers.ByRef; // TODO verify this! + return Modifiers.ByRef; case ICSharpCode.NRefactory.CSharp.ParameterModifier.Params: return Modifiers.ParamArray; default: From 024348d187ec88f6ae4a8646fe5e00011a0e15df Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 30 Jun 2011 10:30:43 +0200 Subject: [PATCH 19/57] implement NamedArgumentExpression and FieldInitializerExpression --- .../Ast/Expressions/Expression.cs | 78 ++++++++++++++++++- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 + .../OutputVisitor/OutputVisitor.cs | 75 +++++++++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 42 +++++++++- 4 files changed, 186 insertions(+), 11 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index 212db02c34..a98a632aea 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -170,7 +170,7 @@ namespace ICSharpCode.NRefactory.VB.Ast } } - /// + /// /// Target(Arguments) /// public class InvocationExpression : Expression @@ -205,7 +205,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable)arguments) { - } + } protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { @@ -214,7 +214,7 @@ namespace ICSharpCode.NRefactory.VB.Ast } } - /// + /// /// Operator Expression /// public class UnaryOperatorExpression : Expression @@ -280,4 +280,76 @@ namespace ICSharpCode.NRefactory.VB.Ast /// Unary plus (+a) Plus } + + /// + /// Represents a named argument passed to a method or attribute. + /// + public class NamedArgumentExpression : Expression + { + public Identifier Identifier { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public VBTokenNode AssignToken { + get { return GetChildByRole (Roles.Assign); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitNamedArgumentExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + NamedArgumentExpression o = other as NamedArgumentExpression; + return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); + } + } + + /// + /// [ Key ] .Identifier = Expression + /// + public class FieldInitializerExpression : Expression + { + public bool IsKey { get; set; } + + public VBTokenNode KeyToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public VBTokenNode DotToken { + get { return GetChildByRole (Roles.Dot); } + } + + public Identifier Identifier { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public VBTokenNode AssignToken { + get { return GetChildByRole (Roles.Assign); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitFieldInitializerExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + FieldInitializerExpression o = other as FieldInitializerExpression; + return o != null && this.IsKey == o.IsKey && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); + } + } } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index bbe2331b67..fb54df1e79 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -65,6 +65,8 @@ namespace ICSharpCode.NRefactory.VB { S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data); S VisitObjectCreationExpression(ObjectCreationExpression objectCreationExpression, T data); S VisitCastExpression(CastExpression castExpression, T data); + S VisitFieldInitializerExpression(FieldInitializerExpression fieldInitializerExpression, T data); + S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data); // Statement scope S VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, T data); diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 2632900946..8a19ea6f98 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -431,7 +431,14 @@ namespace ICSharpCode.NRefactory.VB public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { - throw new NotImplementedException(); + StartNode(typeOfIsExpression); + + WriteKeyword("TypeOf"); + typeOfIsExpression.TypeOfExpression.AcceptVisitor(this, data); + WriteKeyword("Is"); + typeOfIsExpression.Type.AcceptVisitor(this, data); + + return EndNode(typeOfIsExpression); } public object VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, object data) @@ -1382,12 +1389,44 @@ namespace ICSharpCode.NRefactory.VB public object VisitTryStatement(TryStatement tryStatement, object data) { - throw new NotImplementedException(); + StartNode(tryStatement); + WriteKeyword("Try"); + NewLine(); + Indent(); + tryStatement.Body.AcceptVisitor(this, data); + Unindent(); + foreach (var clause in tryStatement.CatchBlocks) { + clause.AcceptVisitor(this, data); + } + if (!tryStatement.FinallyBlock.IsNull) { + WriteKeyword("Finally"); + NewLine(); + Indent(); + tryStatement.FinallyBlock.AcceptVisitor(this, data); + Unindent(); + } + WriteKeyword("End"); + WriteKeyword("Try"); + return EndNode(tryStatement); } public object VisitCatchBlock(CatchBlock catchBlock, object data) { - throw new NotImplementedException(); + StartNode(catchBlock); + WriteKeyword("Catch"); + catchBlock.ExceptionVariable.AcceptVisitor(this, data); + if (!catchBlock.ExceptionType.IsNull) { + WriteKeyword("As"); + catchBlock.ExceptionType.AcceptVisitor(this, data); + } + NewLine(); + Indent(); + foreach (var stmt in catchBlock) { + stmt.AcceptVisitor(this, data); + NewLine(); + } + Unindent(); + return EndNode(catchBlock); } public object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) @@ -1622,7 +1661,10 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("New"); objectCreationExpression.Type.AcceptVisitor(this, data); WriteCommaSeparatedListInParenthesis(objectCreationExpression.Arguments, false); - objectCreationExpression.Initializer.AcceptVisitor(this, data); + if (!objectCreationExpression.Initializer.IsNull) { + Space(); + objectCreationExpression.Initializer.AcceptVisitor(this, data); + } return EndNode(objectCreationExpression); } @@ -1773,5 +1815,30 @@ namespace ICSharpCode.NRefactory.VB return EndNode(unaryOperatorExpression); } + + public object VisitFieldInitializerExpression(FieldInitializerExpression fieldInitializerExpression, object data) + { + StartNode(fieldInitializerExpression); + + if (fieldInitializerExpression.IsKey) { + WriteKeyword("Key"); + Space(); + } + + WriteToken(".", FieldInitializerExpression.Roles.Dot); + fieldInitializerExpression.Identifier.AcceptVisitor(this, data); + + Space(); + WriteToken("=", FieldInitializerExpression.Roles.Assign); + Space(); + fieldInitializerExpression.Expression.AcceptVisitor(this, data); + + return EndNode(fieldInitializerExpression); + } + + public object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) + { + throw new NotImplementedException(); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index b8fce019ef..598f1e5065 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -130,6 +130,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors var op = BinaryOperatorType.None; var right = (Expression)binaryOperatorExpression.Right.AcceptVisitor(this, data); + // TODO obj <> Nothing is wrong; correct would be obj IsNot Nothing + switch (binaryOperatorExpression.Operator) { case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseAnd: op = BinaryOperatorType.BitwiseAnd; @@ -272,7 +274,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitIsExpression(CSharp.IsExpression isExpression, object data) { - throw new NotImplementedException(); + var expr = new TypeOfIsExpression() { + Type = (AstType)isExpression.Type.AcceptVisitor(this, data), + TypeOfExpression = (Expression)isExpression.Expression.AcceptVisitor(this, data) + }; + + return EndNode(isExpression, expr); } public AstNode VisitLambdaExpression(CSharp.LambdaExpression lambdaExpression, object data) @@ -293,7 +300,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitNamedArgumentExpression(CSharp.NamedArgumentExpression namedArgumentExpression, object data) { - throw new NotImplementedException(); + Expression expr; + + if (namedArgumentExpression.Parent is CSharp.ArrayInitializerExpression) { + expr = new FieldInitializerExpression { + IsKey = true, + Identifier = namedArgumentExpression.Identifier, + Expression = (Expression)namedArgumentExpression.Expression.AcceptVisitor(this, data) + }; + } else { + expr = new NamedArgumentExpression { + Identifier = namedArgumentExpression.Identifier, + Expression = (Expression)namedArgumentExpression.Expression.AcceptVisitor(this, data) + }; + } + + return EndNode(namedArgumentExpression, expr); } public AstNode VisitNullReferenceExpression(CSharp.NullReferenceExpression nullReferenceExpression, object data) @@ -779,12 +801,24 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitTryCatchStatement(CSharp.TryCatchStatement tryCatchStatement, object data) { - throw new NotImplementedException(); + var stmt = new TryStatement(); + + stmt.Body = (BlockStatement)tryCatchStatement.TryBlock.AcceptVisitor(this, data); + stmt.FinallyBlock = (BlockStatement)tryCatchStatement.FinallyBlock.AcceptVisitor(this, data); + ConvertNodes(tryCatchStatement.CatchClauses, stmt.CatchBlocks); + + return EndNode(tryCatchStatement, stmt); } public AstNode VisitCatchClause(CSharp.CatchClause catchClause, object data) { - throw new NotImplementedException(); + var clause = new CatchBlock(); + + clause.ExceptionType = (AstType)catchClause.Type.AcceptVisitor(this, data); + clause.ExceptionVariable = catchClause.VariableName; + ConvertNodes(catchClause.Body.Statements, clause.Statements); + + return EndNode(catchClause, clause); } public AstNode VisitUncheckedStatement(CSharp.UncheckedStatement uncheckedStatement, object data) From 9ff6e733fa09e38217d428569f3e54a035c00566 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 30 Jun 2011 10:33:52 +0200 Subject: [PATCH 20/57] reimplement some helper methods --- .../Ast/Statements/BlockStatement.cs | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs index b01ac98435..2e03e0ab91 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs @@ -88,28 +88,26 @@ namespace ICSharpCode.NRefactory.VB.Ast AddChild(statement, StatementRole); } - // TODO : uncomment + public void Add(Expression expression) + { + AddChild(new ExpressionStatement { Expression = expression }, StatementRole); + } -// public void Add(Expression expression) -// { -// AddChild(new ExpressionStatement { Expression = expression }, StatementRole); -// } -// public void AddRange(IEnumerable statements) { foreach (Statement st in statements) AddChild(st, StatementRole); } -// public void AddAssignment(Expression left, Expression right) -// { -// Add(new AssignmentExpression { Left = left, Operator = AssignmentOperatorType.Assign, Right = right }); -// } -// -// public void AddReturnStatement(Expression expression) -// { -// Add(new ReturnStatement { Expression = expression }); -// } + public void AddAssignment(Expression left, Expression right) + { + Add(new AssignmentExpression(left, AssignmentOperatorType.Assign, right)); + } + + public void AddReturnStatement(Expression expression) + { + Add(new ReturnStatement { Expression = expression }); + } #endregion IEnumerator IEnumerable.GetEnumerator() @@ -122,6 +120,4 @@ namespace ICSharpCode.NRefactory.VB.Ast return this.Statements.GetEnumerator(); } } - - } From 1c8d2aa4e210784dd5417544551375fdf15bbaf5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 30 Jun 2011 11:13:29 +0200 Subject: [PATCH 21/57] split Statements into single files --- .../Ast/Statements/ExpressionStatement.cs | 40 +++ .../Ast/Statements/IfElseStatement.cs | 39 +++ .../Statements/LabelDeclarationStatement.cs | 34 ++ .../Statements/LocalDeclarationStatement.cs | 37 +++ .../Ast/Statements/ReturnStatement.cs | 43 +++ .../Ast/Statements/Statement.cs | 308 ------------------ .../Ast/Statements/SyncLockStatement.cs | 36 ++ .../Ast/Statements/ThrowStatement.cs | 43 +++ .../Ast/Statements/TryStatement.cs | 67 ++++ .../Ast/Statements/WithStatement.cs | 36 ++ .../ICSharpCode.NRefactory.VB.csproj | 9 + 11 files changed, 384 insertions(+), 308 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/ExpressionStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/IfElseStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/LocalDeclarationStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/ReturnStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/SyncLockStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/ThrowStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/TryStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/WithStatement.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ExpressionStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ExpressionStatement.cs new file mode 100644 index 0000000000..67e8952d65 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ExpressionStatement.cs @@ -0,0 +1,40 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Expression + /// + // TODO this does not directly reflect the VB grammar! + public class ExpressionStatement : Statement + { + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitExpressionStatement(this, data); + } + + public ExpressionStatement() + { + } + + public ExpressionStatement(Expression expression) + { + this.Expression = expression; + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ExpressionStatement o = other as ExpressionStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/IfElseStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/IfElseStatement.cs new file mode 100644 index 0000000000..08738789aa --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/IfElseStatement.cs @@ -0,0 +1,39 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class IfElseStatement : Statement + { + public static readonly Role FalseStatementRole = new Role("False", Ast.Statement.Null); + public static readonly Role TrueStatementRole = new Role("True", Ast.Statement.Null); + + public Expression Condition { + get { return GetChildByRole(Roles.Condition); } + set { SetChildByRole(Roles.Condition, value); } + } + + public Statement Body { + get { return GetChildByRole(TrueStatementRole); } + set { SetChildByRole(TrueStatementRole, value); } + } + + public Statement ElseBlock { + get { return GetChildByRole(FalseStatementRole); } + set { SetChildByRole(FalseStatementRole, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitIfElseStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs new file mode 100644 index 0000000000..f613a76788 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs @@ -0,0 +1,34 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Label: + /// + public class LabelDeclarationStatement : Statement + { + public Identifier Label { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public VBTokenNode Colon { + get { return GetChildByRole(Roles.Colon); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitLabelDeclarationStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + LabelDeclarationStatement o = other as LabelDeclarationStatement; + return o != null && MatchString(this.Label.Name, o.Label.Name); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/LocalDeclarationStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/LocalDeclarationStatement.cs new file mode 100644 index 0000000000..40c19b2abb --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/LocalDeclarationStatement.cs @@ -0,0 +1,37 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// ( Dim | Static | Const ) VariableDeclarator { , VariableDeclarator } + /// + public class LocalDeclarationStatement : Statement + { + public AstNodeCollection Variables { + get { return GetChildrenByRole(VariableDeclarator.VariableDeclaratorRole); } + } + + public Modifiers Modifiers { + get { return AttributedNode.GetModifiers(this); } + set { AttributedNode.SetModifiers(this, value); } + } + + public VBModifierToken ModifierToken { + get { return GetChildByRole(AttributedNode.ModifierRole); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitLocalDeclarationStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ReturnStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ReturnStatement.cs new file mode 100644 index 0000000000..26deb1ab29 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ReturnStatement.cs @@ -0,0 +1,43 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Return Expression + /// + public class ReturnStatement : Statement + { + public VBTokenNode ReturnToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public ReturnStatement() + { + } + + public ReturnStatement(Expression expression) + { + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitReturnStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ReturnStatement o = other as ReturnStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs index 07bb02ede7..c20407051c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs @@ -129,312 +129,4 @@ namespace ICSharpCode.NRefactory.VB.Ast throw new NotImplementedException(); } } - - /// - /// Label: - /// - public class LabelDeclarationStatement : Statement - { - public Identifier Label { - get { return GetChildByRole(Roles.Identifier); } - set { SetChildByRole(Roles.Identifier, value); } - } - - public VBTokenNode Colon { - get { return GetChildByRole(Roles.Colon); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitLabelDeclarationStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - LabelDeclarationStatement o = other as LabelDeclarationStatement; - return o != null && MatchString(this.Label.Name, o.Label.Name); - } - } - - /// - /// ( Dim | Static | Const ) VariableDeclarator { , VariableDeclarator } - /// - public class LocalDeclarationStatement : Statement - { - public AstNodeCollection Variables { - get { return GetChildrenByRole(VariableDeclarator.VariableDeclaratorRole); } - } - - public Modifiers Modifiers { - get { return AttributedNode.GetModifiers(this); } - set { AttributedNode.SetModifiers(this, value); } - } - - public VBModifierToken ModifierToken { - get { return GetChildByRole(AttributedNode.ModifierRole); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitLocalDeclarationStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - throw new NotImplementedException(); - } - } - - /// - /// With Expression
- /// Block
- /// End With - ///
- public class WithStatement : Statement - { - public Expression Expression { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - public BlockStatement Body { - get { return GetChildByRole(Roles.Body); } - set { SetChildByRole(Roles.Body, value); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitWithStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - throw new NotImplementedException(); - } - } - - /// - /// SyncLock Expression
- /// Block
- /// End SyncLock - ///
- public class SyncLockStatement : Statement - { - public Expression Expression { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - public BlockStatement Body { - get { return GetChildByRole(Roles.Body); } - set { SetChildByRole(Roles.Body, value); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitSyncLockStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - throw new NotImplementedException(); - } - } - - /// - /// SyncLock Expression
- /// Block
- /// End SyncLock - ///
- public class TryStatement : Statement - { - public static readonly Role FinallyBlockRole = new Role("FinallyBlock", Ast.BlockStatement.Null); - - public BlockStatement Body { - get { return GetChildByRole(Roles.Body); } - set { SetChildByRole(Roles.Body, value); } - } - - public AstNodeCollection CatchBlocks { - get { return GetChildrenByRole(CatchBlock.CatchBlockRole); } - } - - public BlockStatement FinallyBlock { - get { return GetChildByRole(FinallyBlockRole); } - set { SetChildByRole(FinallyBlockRole, value); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitTryStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - throw new NotImplementedException(); - } - } - - public class CatchBlock : BlockStatement - { - public static readonly Role CatchBlockRole = new Role("CatchBlockRole"); - - public Identifier ExceptionVariable { - get { return GetChildByRole(Roles.Identifier); } - set { SetChildByRole(Roles.Identifier, value); } - } - - public AstType ExceptionType { - get { return GetChildByRole(Roles.Type); } - set { SetChildByRole(Roles.Type, value); } - } - - public Expression WhenExpression { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitCatchBlock(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - throw new NotImplementedException(); - } - } - - public class IfElseStatement : Statement - { - public static readonly Role FalseStatementRole = new Role("False", Ast.Statement.Null); - public static readonly Role TrueStatementRole = new Role("True", Ast.Statement.Null); - - public Expression Condition { - get { return GetChildByRole(Roles.Condition); } - set { SetChildByRole(Roles.Condition, value); } - } - - public Statement Body { - get { return GetChildByRole(TrueStatementRole); } - set { SetChildByRole(TrueStatementRole, value); } - } - - public Statement ElseBlock { - get { return GetChildByRole(FalseStatementRole); } - set { SetChildByRole(FalseStatementRole, value); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitIfElseStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - throw new NotImplementedException(); - } - } - - /// - /// Expression - /// - public class ExpressionStatement : Statement - { - public Expression Expression { - get { return GetChildByRole (Roles.Expression); } - set { SetChildByRole (Roles.Expression, value); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitExpressionStatement(this, data); - } - - public ExpressionStatement() - { - } - - public ExpressionStatement(Expression expression) - { - this.Expression = expression; - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - ExpressionStatement o = other as ExpressionStatement; - return o != null && this.Expression.DoMatch(o.Expression, match); - } - } - - /// - /// Throw Expression - /// - public class ThrowStatement : Statement - { - public VBTokenNode ThrowToken { - get { return GetChildByRole (Roles.Keyword); } - } - - public Expression Expression { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - public ThrowStatement() - { - } - - public ThrowStatement(Expression expression) - { - AddChild (expression, Roles.Expression); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitThrowStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - ThrowStatement o = other as ThrowStatement; - return o != null && this.Expression.DoMatch(o.Expression, match); - } - } - - /// - /// Return Expression - /// - public class ReturnStatement : Statement - { - public VBTokenNode ReturnToken { - get { return GetChildByRole (Roles.Keyword); } - } - - public Expression Expression { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - public ReturnStatement() - { - } - - public ReturnStatement(Expression expression) - { - AddChild (expression, Roles.Expression); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitReturnStatement(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - ReturnStatement o = other as ReturnStatement; - return o != null && this.Expression.DoMatch(o.Expression, match); - } - } - } diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/SyncLockStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/SyncLockStatement.cs new file mode 100644 index 0000000000..7fd317eb09 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/SyncLockStatement.cs @@ -0,0 +1,36 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// SyncLock Expression
+ /// Block
+ /// End SyncLock + ///
+ public class SyncLockStatement : Statement + { + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitSyncLockStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ThrowStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ThrowStatement.cs new file mode 100644 index 0000000000..c4c1634b5c --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ThrowStatement.cs @@ -0,0 +1,43 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Throw Expression + /// + public class ThrowStatement : Statement + { + public VBTokenNode ThrowToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public ThrowStatement() + { + } + + public ThrowStatement(Expression expression) + { + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitThrowStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ThrowStatement o = other as ThrowStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/TryStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/TryStatement.cs new file mode 100644 index 0000000000..7e5eb94da9 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/TryStatement.cs @@ -0,0 +1,67 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class TryStatement : Statement + { + public static readonly Role FinallyBlockRole = new Role("FinallyBlock", Ast.BlockStatement.Null); + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public AstNodeCollection CatchBlocks { + get { return GetChildrenByRole(CatchBlock.CatchBlockRole); } + } + + public BlockStatement FinallyBlock { + get { return GetChildByRole(FinallyBlockRole); } + set { SetChildByRole(FinallyBlockRole, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitTryStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + public class CatchBlock : BlockStatement + { + public static readonly Role CatchBlockRole = new Role("CatchBlockRole"); + + public Identifier ExceptionVariable { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstType ExceptionType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public Expression WhenExpression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitCatchBlock(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/WithStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/WithStatement.cs new file mode 100644 index 0000000000..b915a90815 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/WithStatement.cs @@ -0,0 +1,36 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// With Expression
+ /// Block
+ /// End With + ///
+ public class WithStatement : Statement + { + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitWithStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index bf288e0841..2b06a9be7a 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -86,7 +86,16 @@ + + + + + + + + + From 84b283be62ae98e973901ef1706d29f53ac13de4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 30 Jun 2011 12:13:58 +0200 Subject: [PATCH 22/57] add ConditionalExpression and WhileStatement --- .../Ast/Expressions/Expression.cs | 36 ++++++++++++++++ .../Ast/Statements/WhileStatement.cs | 31 ++++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 42 +++++++++++++++++++ .../Visitors/CSharpToVBConverterVisitor.cs | 15 ++++++- 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/WhileStatement.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index a98a632aea..5a6dbb3d5f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -352,4 +352,40 @@ namespace ICSharpCode.NRefactory.VB.Ast return o != null && this.IsKey == o.IsKey && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); } } + + public class ConditionalExpression : Expression + { + public readonly static Role ConditionExpressionRole = new Role("ConditionExpressionRole", Expression.Null); + public readonly static Role TrueExpressionRole = new Role("TrueExpressionRole", Expression.Null); + public readonly static Role FalseExpressionRole = new Role("FalseExpressionRole", Expression.Null); + + public VBTokenNode IfToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression ConditionExpression { + get { return GetChildByRole (ConditionExpressionRole); } + set { SetChildByRole (ConditionExpressionRole, value); } + } + + public Expression TrueExpression { + get { return GetChildByRole (TrueExpressionRole); } + set { SetChildByRole (TrueExpressionRole, value); } + } + + public Expression FalseExpression { + get { return GetChildByRole (FalseExpressionRole); } + set { SetChildByRole (FalseExpressionRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitConditionalExpression(this, data); + } + } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/WhileStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/WhileStatement.cs new file mode 100644 index 0000000000..e5c9ec24c5 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/WhileStatement.cs @@ -0,0 +1,31 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class WhileStatement : Statement + { + public Expression Condition { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitWhileStatement(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index fb54df1e79..3f8fb034c5 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -67,6 +67,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitCastExpression(CastExpression castExpression, T data); S VisitFieldInitializerExpression(FieldInitializerExpression fieldInitializerExpression, T data); S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data); + S VisitConditionalExpression(ConditionalExpression conditionalExpression, T data); // Statement scope S VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, T data); @@ -79,6 +80,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitThrowStatement(ThrowStatement throwStatement, T data); S VisitCatchBlock(CatchBlock catchBlock, T data); S VisitReturnStatement(ReturnStatement returnStatement, T data); + S VisitWhileStatement(WhileStatement whileStatement, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 2b06a9be7a..7f289bca8a 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -95,6 +95,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 8a19ea6f98..d04c03ba0f 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -191,6 +191,7 @@ namespace ICSharpCode.NRefactory.VB public object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { StartNode(namespaceDeclaration); + NewLine(); WriteKeyword("Namespace"); bool isFirst = true; foreach (Identifier node in namespaceDeclaration.Identifiers) { @@ -1840,5 +1841,46 @@ namespace ICSharpCode.NRefactory.VB { throw new NotImplementedException(); } + + public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) + { + StartNode(conditionalExpression); + + WriteKeyword("If"); + WriteToken("(", ConditionalExpression.Roles.LPar); + + conditionalExpression.ConditionExpression.AcceptVisitor(this, data); + WriteToken(",", ConditionalExpression.Roles.Comma); + Space(); + + if (!conditionalExpression.TrueExpression.IsNull) { + conditionalExpression.TrueExpression.AcceptVisitor(this, data); + WriteToken(",", ConditionalExpression.Roles.Comma); + Space(); + } + + conditionalExpression.FalseExpression.AcceptVisitor(this, data); + + WriteToken(")", ConditionalExpression.Roles.RPar); + + return EndNode(conditionalExpression); + } + + public object VisitWhileStatement(WhileStatement whileStatement, object data) + { + StartNode(whileStatement); + + WriteKeyword("While"); + Space(); + whileStatement.Condition.AcceptVisitor(this, data); + NewLine(); + Indent(); + whileStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("End"); + WriteKeyword("While"); + + return EndNode(whileStatement); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 598f1e5065..97abcb4b59 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -233,7 +233,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitConditionalExpression(CSharp.ConditionalExpression conditionalExpression, object data) { - throw new NotImplementedException(); + var cond = new ConditionalExpression() { + ConditionExpression = (Expression)conditionalExpression.Condition.AcceptVisitor(this, data), + TrueExpression = (Expression)conditionalExpression.TrueExpression.AcceptVisitor(this, data), + FalseExpression = (Expression)conditionalExpression.FalseExpression.AcceptVisitor(this, data) + }; + + return EndNode(conditionalExpression, cond); } public AstNode VisitDefaultValueExpression(CSharp.DefaultValueExpression defaultValueExpression, object data) @@ -847,7 +853,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitWhileStatement(CSharp.WhileStatement whileStatement, object data) { - throw new NotImplementedException(); + var stmt = new WhileStatement() { + Condition = (Expression)whileStatement.Condition.AcceptVisitor(this, data), + Body = (BlockStatement)whileStatement.EmbeddedStatement.AcceptVisitor(this, data) + }; + + return EndNode(whileStatement, stmt); } public AstNode VisitYieldBreakStatement(CSharp.YieldBreakStatement yieldBreakStatement, object data) From 57d92d186df8ffefe7ec364f0335b6bca13f956a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 6 Jul 2011 14:29:40 +0200 Subject: [PATCH 23/57] add support for OperatorDeclaration and some more statements --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 60 +----- .../Ast/Statements/DoLoopStatement.cs | 21 ++ .../Ast/Statements/ExitStatement.cs | 55 +++++ .../Ast/Statements/ForEachStatement.cs | 38 ++++ .../Ast/Statements/ForStatement.cs | 21 ++ .../Ast/Statements/SelectStatement.cs | 41 ++++ .../Ast/TypeMembers/OperatorDeclaration.cs | 83 ++++++++ .../Ast/VBModifierToken.cs | 7 + ICSharpCode.NRefactory.VB/IAstVisitor.cs | 5 + .../ICSharpCode.NRefactory.VB.csproj | 6 + .../OutputVisitor/OutputVisitor.cs | 201 +++++++++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 161 +++++++++++++- .../Ast/TypeMembers/OperatorDeclaration.cs | 2 +- 13 files changed, 633 insertions(+), 68 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index b54c49b65a..b69ae9aa38 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -45,6 +45,9 @@ namespace ICSharpCode.NRefactory.VB.Ast ParamArray = 0x800000, Optional = 0x1000000, + Narrowing = 0x2000000, + Widening = 0x4000000, + /// /// Special value used to match any modifiers during pattern matching. /// @@ -108,19 +111,6 @@ namespace ICSharpCode.NRefactory.VB.Ast End } - public enum ExitType - { - None, - Sub, - Function, - Property, - Do, - For, - While, - Select, - Try - } - public enum ConstructorInitializerType { None, @@ -135,50 +125,6 @@ namespace ICSharpCode.NRefactory.VB.Ast Explicit } - public enum OverloadableOperatorType - { - None, - - Add, - Subtract, - Multiply, - Divide, - Modulus, - Concat, - - UnaryPlus, - UnaryMinus, - - Not, - BitNot, - - BitwiseAnd, - BitwiseOr, - ExclusiveOr, - - ShiftLeft, - ShiftRight, - - GreaterThan, - GreaterThanOrEqual, - Equality, - InEquality, - LessThan, - LessThanOrEqual, - - Increment, - Decrement, - - IsTrue, - IsFalse, - - // VB specific - Like, - Power, - CType, - DivideInteger - } - /// /// Charset types, used in external methods /// declarations (VB only). diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs new file mode 100644 index 0000000000..0b2101c176 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs @@ -0,0 +1,21 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class DoLoopStatement : Statement + { + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs new file mode 100644 index 0000000000..5868523259 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs @@ -0,0 +1,55 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Exit ( Do | For | While | Select | Sub | Function | Property | Try ) + /// + public class ExitStatement : Statement + { + public static readonly Role ExitKindTokenRole = new Role("ExitKindTokenRole"); + + public ExitKind ExitKind { get; set; } + + public VBTokenNode ExitToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public VBTokenNode ExitKindToken { + get { return GetChildByRole (ExitKindTokenRole); } + } + + public ExitStatement(ExitKind kind) + { + this.ExitKind = kind; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitExitStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ExitStatement o = other as ExitStatement; + return o != null && this.ExitKind == o.ExitKind; + } + } + + public enum ExitKind + { + None, + Sub, + Function, + Property, + Do, + For, + While, + Select, + Try + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs new file mode 100644 index 0000000000..5f9532d146 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs @@ -0,0 +1,38 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ForEachStatement : Statement + { + public static readonly Role InitializerRole = new Role("InitializerRole", Statement.Null); + + public Statement Initializer { + get { return GetChildByRole(InitializerRole); } + set { SetChildByRole(InitializerRole, value); } + } + + public Expression InExpression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitForEachStatement(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs new file mode 100644 index 0000000000..f4abbebff9 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs @@ -0,0 +1,21 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ForStatement : Statement + { + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitForStatement(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs new file mode 100644 index 0000000000..95b576fd7e --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs @@ -0,0 +1,41 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class SelectStatement : Statement + { + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitSelectStatement(this, data); + } + } + + public class CaseStatement : Statement + { + + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs new file mode 100644 index 0000000000..8e3574e530 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs @@ -0,0 +1,83 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class OperatorDeclaration : MemberDeclaration + { + public OperatorDeclaration() + { + } + + public OverloadableOperatorType Operator { get; set; } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public AstNodeCollection ReturnTypeAttributes { + get { return GetChildrenByRole(AttributeBlock.ReturnTypeAttributeBlockRole); } + } + + public AstType ReturnType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitOperatorDeclaration(this, data); + } + } + + public enum OverloadableOperatorType + { + None, + + Add, + Subtract, + Multiply, + Divide, + Modulus, + Concat, + + UnaryPlus, + UnaryMinus, + + Not, + + BitwiseAnd, + BitwiseOr, + ExclusiveOr, + + ShiftLeft, + ShiftRight, + + GreaterThan, + GreaterThanOrEqual, + Equality, + InEquality, + LessThan, + LessThanOrEqual, + + IsTrue, + IsFalse, + + Like, + Power, + CType, + DivideInteger + }// +} diff --git a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs index 2050582617..45b8997860 100644 --- a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs +++ b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -63,6 +63,9 @@ namespace ICSharpCode.NRefactory.VB.Ast new KeyValuePair(Modifiers.ByVal, "ByVal".Length), new KeyValuePair(Modifiers.ByRef, "ByRef".Length), new KeyValuePair(Modifiers.ParamArray, "ParamArray".Length), + // operator modifiers + new KeyValuePair(Modifiers.Narrowing, "Narrowing".Length), + new KeyValuePair(Modifiers.Widening, "Widening".Length), // even though it's used for patterns only, it needs to be in this table to be usable in the AST new KeyValuePair(Modifiers.Any, "Any".Length) }; @@ -129,6 +132,10 @@ namespace ICSharpCode.NRefactory.VB.Ast return "ByRef"; case Modifiers.ParamArray: return "ParamArray"; + case Modifiers.Widening: + return "Widening"; + case Modifiers.Narrowing: + return "Narrowing"; default: throw new NotSupportedException("Invalid value for Modifiers: " + modifier); } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 3f8fb034c5..c9bad327ce 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -41,6 +41,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitAccessor(Accessor accessor, T data); S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data); S VisitEventDeclaration(EventDeclaration eventDeclaration, T data); + S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data); // Expression scope S VisitIdentifier(Identifier identifier, T data); @@ -81,6 +82,10 @@ namespace ICSharpCode.NRefactory.VB { S VisitCatchBlock(CatchBlock catchBlock, T data); S VisitReturnStatement(ReturnStatement returnStatement, T data); S VisitWhileStatement(WhileStatement whileStatement, T data); + S VisitForStatement(ForStatement forStatement, T data); + S VisitForEachStatement(ForEachStatement forEachStatement, T data); + S VisitExitStatement(ExitStatement exitStatement, T data); + S VisitSelectStatement(SelectStatement selectStatement, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 7f289bca8a..8955b43d14 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -86,11 +86,16 @@ + + + + + @@ -102,6 +107,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index d04c03ba0f..71d60b3c7a 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1372,7 +1372,8 @@ namespace ICSharpCode.NRefactory.VB { StartNode(localDeclarationStatement); - WriteModifiers(new [] { localDeclarationStatement.ModifierToken }); + if (localDeclarationStatement.ModifierToken != null && !localDeclarationStatement.ModifierToken.IsNull) + WriteModifiers(new [] { localDeclarationStatement.ModifierToken }); WriteCommaSeparatedList(localDeclarationStatement.Variables); return EndNode(localDeclarationStatement); @@ -1380,12 +1381,30 @@ namespace ICSharpCode.NRefactory.VB public object VisitWithStatement(WithStatement withStatement, object data) { - throw new NotImplementedException(); + StartNode(withStatement); + WriteKeyword("With"); + withStatement.Expression.AcceptVisitor(this, data); + NewLine(); + Indent(); + withStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("End"); + WriteKeyword("With"); + return EndNode(withStatement); } public object VisitSyncLockStatement(SyncLockStatement syncLockStatement, object data) { - throw new NotImplementedException(); + StartNode(syncLockStatement); + WriteKeyword("SyncLock"); + syncLockStatement.Expression.AcceptVisitor(this, data); + NewLine(); + Indent(); + syncLockStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("End"); + WriteKeyword("SyncLock"); + return EndNode(syncLockStatement); } public object VisitTryStatement(TryStatement tryStatement, object data) @@ -1601,7 +1620,6 @@ namespace ICSharpCode.NRefactory.VB case AssignmentOperatorType.DivideInteger: WriteToken("\\=", AssignmentExpression.OperatorRole); break; - break; case AssignmentOperatorType.ConcatString: WriteToken("&=", AssignmentExpression.OperatorRole); break; @@ -1882,5 +1900,180 @@ namespace ICSharpCode.NRefactory.VB return EndNode(whileStatement); } + + public object VisitExitStatement(ExitStatement exitStatement, object data) + { + StartNode(exitStatement); + + WriteKeyword("Exit"); + + switch (exitStatement.ExitKind) { + case ExitKind.Sub: + WriteKeyword("Sub"); + break; + case ExitKind.Function: + WriteKeyword("Function"); + break; + case ExitKind.Property: + WriteKeyword("Property"); + break; + case ExitKind.Do: + WriteKeyword("Do"); + break; + case ExitKind.For: + WriteKeyword("For"); + break; + case ExitKind.While: + WriteKeyword("While"); + break; + case ExitKind.Select: + WriteKeyword("Select"); + break; + case ExitKind.Try: + WriteKeyword("Try"); + break; + default: + throw new Exception("Invalid value for ExitKind"); + } + + return EndNode(exitStatement); + } + + public object VisitForStatement(ForStatement forStatement, object data) + { + StartNode(forStatement); + + throw new NotImplementedException(); + + return EndNode(forStatement); + } + + public object VisitForEachStatement(ForEachStatement forEachStatement, object data) + { + StartNode(forEachStatement); + + WriteKeyword("For"); + WriteKeyword("Each"); + forEachStatement.Initializer.AcceptVisitor(this, data); + WriteKeyword("In"); + forEachStatement.InExpression.AcceptVisitor(this, data); + NewLine(); + Indent(); + forEachStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("Next"); + + return EndNode(forEachStatement); + } + + public object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) + { + StartNode(operatorDeclaration); + + WriteAttributes(operatorDeclaration.Attributes); + WriteModifiers(operatorDeclaration.ModifierTokens); + WriteKeyword("Operator"); + switch (operatorDeclaration.Operator) { + case OverloadableOperatorType.Add: + case OverloadableOperatorType.UnaryPlus: + WriteToken("+", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.Subtract: + case OverloadableOperatorType.UnaryMinus: + WriteToken("-", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.Multiply: + WriteToken("*", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.Divide: + WriteToken("/", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.Modulus: + WriteKeyword("Mod"); + break; + case OverloadableOperatorType.Concat: + WriteToken("&", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.Not: + WriteKeyword("Not"); + break; + case OverloadableOperatorType.BitwiseAnd: + WriteKeyword("And"); + break; + case OverloadableOperatorType.BitwiseOr: + WriteKeyword("Or"); + break; + case OverloadableOperatorType.ExclusiveOr: + WriteKeyword("Xor"); + break; + case OverloadableOperatorType.ShiftLeft: + WriteToken("<<", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.ShiftRight: + WriteToken(">>", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.GreaterThan: + WriteToken(">", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.GreaterThanOrEqual: + WriteToken(">=", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.Equality: + WriteToken("=", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.InEquality: + WriteToken("<>", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.LessThan: + WriteToken("<", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.LessThanOrEqual: + WriteToken("<=", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.IsTrue: + WriteKeyword("IsTrue"); + break; + case OverloadableOperatorType.IsFalse: + WriteKeyword("IsFalse"); + break; + case OverloadableOperatorType.Like: + WriteKeyword("Like"); + break; + case OverloadableOperatorType.Power: + WriteToken("^", OperatorDeclaration.Roles.Keyword); + break; + case OverloadableOperatorType.CType: + WriteKeyword("CType"); + break; + case OverloadableOperatorType.DivideInteger: + WriteToken("\\", OperatorDeclaration.Roles.Keyword); + break; + default: + throw new Exception("Invalid value for OverloadableOperatorType"); + } + WriteCommaSeparatedListInParenthesis(operatorDeclaration.Parameters, false); + if (!operatorDeclaration.ReturnType.IsNull) { + Space(); + WriteKeyword("As"); + WriteAttributes(operatorDeclaration.ReturnTypeAttributes); + operatorDeclaration.ReturnType.AcceptVisitor(this, data); + } + if (!operatorDeclaration.Body.IsNull) { + NewLine(); + Indent(); + WriteBlock(operatorDeclaration.Body); + Unindent(); + WriteKeyword("End"); + WriteKeyword("Operator"); + } + NewLine(); + + return EndNode(operatorDeclaration); + } + + public object VisitSelectStatement(SelectStatement selectStatement, object data) + { + throw new NotImplementedException(); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 97abcb4b59..b5d81087ae 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Security.Cryptography.X509Certificates; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.VB.Ast; @@ -24,10 +25,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public class CSharpToVBConverterVisitor : CSharp.IAstVisitor { IEnvironmentProvider provider; + Stack blocks; public CSharpToVBConverterVisitor(IEnvironmentProvider provider) { this.provider = provider; + this.blocks = new Stack(); } public AstNode VisitAnonymousMethodExpression(CSharp.AnonymousMethodExpression anonymousMethodExpression, object data) @@ -691,14 +694,48 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitBlockStatement(CSharp.BlockStatement blockStatement, object data) { var block = new BlockStatement(); + blocks.Push(block); ConvertNodes(blockStatement, block.Statements); - + blocks.Pop(); return EndNode(blockStatement, block); } public AstNode VisitBreakStatement(CSharp.BreakStatement breakStatement, object data) { - throw new NotImplementedException(); + var exit = new ExitStatement(ExitKind.None); + + foreach (var stmt in breakStatement.Ancestors) { + if (stmt is CSharp.MethodDeclaration) { + exit.ExitKind = IsSub(((CSharp.MethodDeclaration)stmt).ReturnType) ? ExitKind.Sub : ExitKind.Function; + break; + } + if (stmt is CSharp.PropertyDeclaration) { + exit.ExitKind = ExitKind.Property; + break; + } + if (stmt is CSharp.DoWhileStatement) { + exit.ExitKind = ExitKind.Do; + break; + } + if (stmt is CSharp.ForStatement || stmt is CSharp.ForeachStatement) { + exit.ExitKind = ExitKind.For; + break; + } + if (stmt is CSharp.WhileStatement) { + exit.ExitKind = ExitKind.While; + break; + } + if (stmt is CSharp.SwitchStatement) { + exit.ExitKind = ExitKind.Select; + break; + } + if (stmt is CSharp.TryCatchStatement) { + exit.ExitKind = ExitKind.Try; + break; + } + } + + return EndNode(breakStatement, exit); } public AstNode VisitCheckedStatement(CSharp.CheckedStatement checkedStatement, object data) @@ -729,17 +766,41 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitFixedStatement(CSharp.FixedStatement fixedStatement, object data) { + // see http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.gchandle%28v=VS.100%29.aspx throw new NotImplementedException(); } public AstNode VisitForeachStatement(CSharp.ForeachStatement foreachStatement, object data) { - throw new NotImplementedException(); + var var = new LocalDeclarationStatement(); + + var.Variables.Add(new VariableDeclarator() { Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) }); + var.Variables.Last().Identifiers.Add(new VariableIdentifier() { Name = foreachStatement.VariableName }); + + var stmt = new ForEachStatement() { + Body = (BlockStatement)foreachStatement.EmbeddedStatement.AcceptVisitor(this, data), + InExpression = (Expression)foreachStatement.InExpression.AcceptVisitor(this, data), + Initializer = var + }; + + return EndNode(foreachStatement, stmt); } public AstNode VisitForStatement(CSharp.ForStatement forStatement, object data) { - throw new NotImplementedException(); + // for (;;) ; + if (!forStatement.Initializers.Any() && forStatement.Condition.IsNull && !forStatement.Iterators.Any()) + return EndNode(forStatement, new WhileStatement() { Condition = new PrimitiveExpression(true), Body = (BlockStatement)forStatement.EmbeddedStatement.AcceptVisitor(this, data) }); + + var stmt = new WhileStatement() { + Condition = (Expression)forStatement.Condition.AcceptVisitor(this, data), + Body = (BlockStatement)forStatement.EmbeddedStatement.AcceptVisitor(this, data) + }; + ConvertNodes(forStatement.Iterators, stmt.Body.Statements); + foreach (var initializer in forStatement.Initializers) + blocks.Peek().Statements.Add((Statement)initializer.AcceptVisitor(this, data)); + + return EndNode(forStatement, stmt); } public AstNode VisitGotoCaseStatement(CSharp.GotoCaseStatement gotoCaseStatement, object data) @@ -775,7 +836,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitLockStatement(CSharp.LockStatement lockStatement, object data) { - throw new NotImplementedException(); + var stmt = new SyncLockStatement(); + + stmt.Expression = (Expression)lockStatement.Expression.AcceptVisitor(this, data); + stmt.Body = (BlockStatement)lockStatement.EmbeddedStatement.AcceptVisitor(this, data); + + return EndNode(lockStatement, stmt); } public AstNode VisitReturnStatement(CSharp.ReturnStatement returnStatement, object data) @@ -1023,7 +1089,90 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitOperatorDeclaration(CSharp.OperatorDeclaration operatorDeclaration, object data) { - throw new NotImplementedException(); + var result = new OperatorDeclaration(); + ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); + ConvertNodes(operatorDeclaration.ModifierTokens, result.ModifierTokens); + switch (operatorDeclaration.OperatorType) { + case ICSharpCode.NRefactory.CSharp.OperatorType.LogicalNot: + case ICSharpCode.NRefactory.CSharp.OperatorType.OnesComplement: + result.Operator = OverloadableOperatorType.Not; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Increment: + case ICSharpCode.NRefactory.CSharp.OperatorType.Decrement: + case ICSharpCode.NRefactory.CSharp.OperatorType.True: + case ICSharpCode.NRefactory.CSharp.OperatorType.False: + throw new NotSupportedException(); + case ICSharpCode.NRefactory.CSharp.OperatorType.Implicit: + result.Modifiers |= Modifiers.Widening; + result.Operator = OverloadableOperatorType.CType; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Explicit: + result.Modifiers |= Modifiers.Narrowing; + result.Operator = OverloadableOperatorType.CType; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Addition: + result.Operator = OverloadableOperatorType.Add; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Subtraction: + result.Operator = OverloadableOperatorType.Subtract; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.UnaryPlus: + result.Operator = OverloadableOperatorType.UnaryPlus; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.UnaryNegation: + result.Operator = OverloadableOperatorType.UnaryMinus; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Multiply: + result.Operator = OverloadableOperatorType.Multiply; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Division: + result.Operator = OverloadableOperatorType.Divide; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Modulus: + result.Operator = OverloadableOperatorType.Modulus; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.BitwiseAnd: + result.Operator = OverloadableOperatorType.BitwiseAnd; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.BitwiseOr: + result.Operator = OverloadableOperatorType.BitwiseOr; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.ExclusiveOr: + result.Operator = OverloadableOperatorType.ExclusiveOr; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.LeftShift: + result.Operator = OverloadableOperatorType.ShiftLeft; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.RightShift: + result.Operator = OverloadableOperatorType.ShiftRight; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Equality: + result.Operator = OverloadableOperatorType.Equality; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Inequality: + result.Operator = OverloadableOperatorType.InEquality; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.GreaterThan: + result.Operator = OverloadableOperatorType.GreaterThan; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.LessThan: + result.Operator = OverloadableOperatorType.LessThan; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.GreaterThanOrEqual: + result.Operator = OverloadableOperatorType.GreaterThanOrEqual; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.LessThanOrEqual: + result.Operator = OverloadableOperatorType.LessThanOrEqual; + break; + default: + throw new Exception("Invalid value for OperatorType"); + } + ConvertNodes(operatorDeclaration.Parameters, result.Parameters); + ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); + result.ReturnType = (AstType)operatorDeclaration.ReturnType.AcceptVisitor(this, data); + result.Body = (BlockStatement)operatorDeclaration.Body.AcceptVisitor(this, data); + + return EndNode(operatorDeclaration, result); } public AstNode VisitParameterDeclaration(CSharp.ParameterDeclaration parameterDeclaration, object data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs index c7e68ab029..80cff91ddc 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs @@ -29,7 +29,7 @@ using System.Linq; namespace ICSharpCode.NRefactory.CSharp { - public enum OperatorType + public enum OperatorType { // Values must correspond to Mono.CSharp.Operator.OpType // due to the casts used in OperatorDeclaration. From fa4694e3e09f1190c4dd322fd79f0a39967812ab Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 6 Jul 2011 15:08:31 +0200 Subject: [PATCH 24/57] implement VB 11 Iterators --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 3 ++ .../Ast/Statements/YieldStatement.cs | 44 +++++++++++++++++++ .../Ast/VBModifierToken.cs | 7 +++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 1 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 8 ++++ .../Visitors/CSharpToVBConverterVisitor.cs | 18 +++++++- 7 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/YieldStatement.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index b69ae9aa38..5ce7c29bed 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -48,6 +48,9 @@ namespace ICSharpCode.NRefactory.VB.Ast Narrowing = 0x2000000, Widening = 0x4000000, + Iterator = 0x8000000, + Async = 0x10000000, + /// /// Special value used to match any modifiers during pattern matching. /// diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/YieldStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/YieldStatement.cs new file mode 100644 index 0000000000..895382aa1d --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/YieldStatement.cs @@ -0,0 +1,44 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Yield Expression + /// + /// VB 11 + public class YieldStatement : Statement + { + public VBTokenNode YieldToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public YieldStatement() + { + } + + public YieldStatement(Expression expression) + { + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitYieldStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + YieldStatement o = other as YieldStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs index 45b8997860..bd87cca4e7 100644 --- a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs +++ b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -66,6 +66,9 @@ namespace ICSharpCode.NRefactory.VB.Ast // operator modifiers new KeyValuePair(Modifiers.Narrowing, "Narrowing".Length), new KeyValuePair(Modifiers.Widening, "Widening".Length), + // VB 11 modifiers + new KeyValuePair(Modifiers.Async, "Async".Length), + new KeyValuePair(Modifiers.Iterator, "Iterator".Length), // even though it's used for patterns only, it needs to be in this table to be usable in the AST new KeyValuePair(Modifiers.Any, "Any".Length) }; @@ -136,6 +139,10 @@ namespace ICSharpCode.NRefactory.VB.Ast return "Widening"; case Modifiers.Narrowing: return "Narrowing"; + case Modifiers.Async: + return "Async"; + case Modifiers.Iterator: + return "Iterator"; default: throw new NotSupportedException("Invalid value for Modifiers: " + modifier); } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index c9bad327ce..c2753f2358 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -86,6 +86,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitForEachStatement(ForEachStatement forEachStatement, T data); S VisitExitStatement(ExitStatement exitStatement, T data); S VisitSelectStatement(SelectStatement selectStatement, T data); + S VisitYieldStatement(YieldStatement yieldStatement, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 8955b43d14..a961a368d7 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -102,6 +102,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 71d60b3c7a..aedffea21a 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2075,5 +2075,13 @@ namespace ICSharpCode.NRefactory.VB { throw new NotImplementedException(); } + + public object VisitYieldStatement(YieldStatement yieldStatement, object data) + { + StartNode(yieldStatement); + WriteKeyword("Yield"); + yieldStatement.Expression.AcceptVisitor(this, data); + return EndNode(yieldStatement); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index b5d81087ae..617f258e7f 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -26,6 +26,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors { IEnvironmentProvider provider; Stack blocks; + // TODO this should belong to the current type member or lambda + bool inIterator; public CSharpToVBConverterVisitor(IEnvironmentProvider provider) { @@ -929,12 +931,14 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitYieldBreakStatement(CSharp.YieldBreakStatement yieldBreakStatement, object data) { - throw new NotImplementedException(); + inIterator = true; + return EndNode(yieldBreakStatement, new ReturnStatement()); } public AstNode VisitYieldStatement(CSharp.YieldStatement yieldStatement, object data) { - throw new NotImplementedException(); + inIterator = true; + return EndNode(yieldStatement, new YieldStatement((Expression)yieldStatement.Expression.AcceptVisitor(this, data))); } public AstNode VisitAccessor(CSharp.Accessor accessor, object data) @@ -1078,6 +1082,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); + if (inIterator) { + result.Modifiers |= Modifiers.Iterator; + inIterator = false; + } + return EndNode(methodDeclaration, result); } @@ -1237,6 +1246,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors }); } + if (inIterator) { + decl.Modifiers |= Modifiers.Iterator; + inIterator = false; + } + return EndNode(propertyDeclaration, decl); } From 5cf130c51fba1ffdc8ba85ec7c92863615c0aa28 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 7 Jul 2011 10:38:31 +0200 Subject: [PATCH 25/57] correctly implement ForEachStatement and ForStatement; add output for ForStatement --- .../Ast/Expressions/Expression.cs | 36 ++++++++ .../Ast/Statements/ForEachStatement.cs | 8 +- .../Ast/Statements/ForStatement.cs | 24 ++++++ .../Ast/Statements/SelectStatement.cs | 6 +- .../Ast/TypeMembers/FieldDeclaration.cs | 33 +------- .../Ast/TypeMembers/VariableDeclarator.cs | 63 ++++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 5 +- .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 84 ++++++++++++++----- .../Visitors/CSharpToVBConverterVisitor.cs | 11 +-- 10 files changed, 202 insertions(+), 69 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index 5a6dbb3d5f..b26ec73bb0 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -312,6 +312,42 @@ namespace ICSharpCode.NRefactory.VB.Ast } } + /// + /// Identifier As Type = Expression + /// + public class VariableInitializer : AstNode + { + public VariableIdentifier Identifier { + get { return GetChildByRole(VariableIdentifier.VariableIdentifierRole); } + set { SetChildByRole(VariableIdentifier.VariableIdentifierRole, value); } + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public VBTokenNode AssignToken { + get { return GetChildByRole (Roles.Assign); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableInitializer(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + VariableInitializer o = other as VariableInitializer; + return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); + } + } + /// /// [ Key ] .Identifier = Expression /// diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs index 5f9532d146..7c0cd90b14 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs @@ -8,11 +8,11 @@ namespace ICSharpCode.NRefactory.VB.Ast { public class ForEachStatement : Statement { - public static readonly Role InitializerRole = new Role("InitializerRole", Statement.Null); + public static readonly Role VariableRole = new Role("Variable", AstNode.Null); - public Statement Initializer { - get { return GetChildByRole(InitializerRole); } - set { SetChildByRole(InitializerRole, value); } + public AstNode Variable { + get { return GetChildByRole(VariableRole); } + set { SetChildByRole(VariableRole, value); } } public Expression InExpression { diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs index f4abbebff9..c28ea0fd56 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs @@ -8,6 +8,30 @@ namespace ICSharpCode.NRefactory.VB.Ast { public class ForStatement : Statement { + public static readonly Role VariableRole = new Role("Variable", AstNode.Null); + public static readonly Role ToExpressionRole = new Role("ToExpression", Expression.Null); + public static readonly Role StepExpressionRole = new Role("StepExpression", Expression.Null); + + public AstNode Variable { + get { return GetChildByRole(VariableRole); } + set { SetChildByRole(VariableRole, value); } + } + + public Expression ToExpression { + get { return GetChildByRole(ToExpressionRole); } + set { SetChildByRole(ToExpressionRole, value); } + } + + public Expression StepExpression { + get { return GetChildByRole(StepExpressionRole); } + set { SetChildByRole(StepExpressionRole, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { throw new NotImplementedException(); diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs index 95b576fd7e..21de4c435d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs @@ -13,6 +13,10 @@ namespace ICSharpCode.NRefactory.VB.Ast set { SetChildByRole(Roles.Expression, value); } } + public AstNodeCollection Cases { + get { return GetChildrenByRole(CaseStatement.CaseStatementRole); } + } + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { throw new NotImplementedException(); @@ -26,7 +30,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public class CaseStatement : Statement { - + public static readonly Role CaseStatementRole = new Role("CaseStatement"); protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs index fa093e0457..e9679da636 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs @@ -25,38 +25,7 @@ namespace ICSharpCode.NRefactory.VB.Ast } } - /// - /// VariableIdentifiers As ObjectCreationExpression
- /// VariableIdentifiers ( As TypeName )? ( Equals Expression )? - ///
- public class VariableDeclarator : AstNode - { - public static readonly Role VariableDeclaratorRole = new Role("VariableDeclarator"); - - public AstNodeCollection Identifiers { - get { return GetChildrenByRole(VariableIdentifier.VariableIdentifierRole); } - } - - public AstType Type { - get { return GetChildByRole(Roles.Type); } - set { SetChildByRole(Roles.Type, value); } - } - - public Expression Initializer { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - throw new NotImplementedException(); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitVariableDeclarator(this, data); - } - } + /// /// Identifier IdentifierModifiers diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs new file mode 100644 index 0000000000..94227bdc7d --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs @@ -0,0 +1,63 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// VariableIdentifiers As ObjectCreationExpression
+ /// VariableIdentifiers ( As TypeName )? ( Equals Expression )? + ///
+ public abstract class VariableDeclarator : AstNode + { + public static readonly Role VariableDeclaratorRole = new Role("VariableDeclarator"); + + public AstNodeCollection Identifiers { + get { return GetChildrenByRole(VariableIdentifier.VariableIdentifierRole); } + } + } + + public class VariableDeclaratorWithTypeAndInitializer : VariableDeclarator + { + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public Expression Initializer { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableDeclaratorWithTypeAndInitializer(this, data); + } + } + + public class VariableDeclaratorWithObjectCreation : VariableDeclarator + { + public static readonly Role InitializerRole = new Role("InitializerRole"); + + public ObjectCreationExpression Initializer { + get { return GetChildByRole(InitializerRole); } + set { SetChildByRole(InitializerRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableDeclaratorWithObjectCreation(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index c2753f2358..3a4ed86737 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -36,7 +36,8 @@ namespace ICSharpCode.NRefactory.VB { S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data); S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data); S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data); - S VisitVariableDeclarator(VariableDeclarator variableDeclarator, T data); + S VisitVariableDeclaratorWithTypeAndInitializer(VariableDeclaratorWithTypeAndInitializer variableDeclaratorWithTypeAndInitializer, T data); + S VisitVariableDeclaratorWithObjectCreation(VariableDeclaratorWithObjectCreation variableDeclaratorWithObjectCreation, T data); S VisitVariableIdentifier(VariableIdentifier variableIdentifier, T data); S VisitAccessor(Accessor accessor, T data); S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data); @@ -94,5 +95,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitComposedType(ComposedType composedType, T data); S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data); S VisitSimpleType(SimpleType simpleType, T data); + + S VisitVariableInitializer(VariableInitializer variableInitializer, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index a961a368d7..948c353cdc 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -110,6 +110,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index aedffea21a..f85a48cb70 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1251,27 +1251,6 @@ namespace ICSharpCode.NRefactory.VB return EndNode(fieldDeclaration); } - public object VisitVariableDeclarator(VariableDeclarator variableDeclarator, object data) - { - StartNode(variableDeclarator); - - WriteCommaSeparatedList(variableDeclarator.Identifiers); - WriteKeyword("As"); - if (variableDeclarator.Initializer is ObjectCreationExpression) - variableDeclarator.Initializer.AcceptVisitor(this, data); - else { - variableDeclarator.Type.AcceptVisitor(this, data); - if (!variableDeclarator.Initializer.IsNull) { - Space(); - WriteToken("=", VariableDeclarator.Roles.Assign); - Space(); - variableDeclarator.Initializer.AcceptVisitor(this, data); - } - } - - return EndNode(variableDeclarator); - } - public object VisitVariableIdentifier(VariableIdentifier variableIdentifier, object data) { StartNode(variableIdentifier); @@ -1943,7 +1922,19 @@ namespace ICSharpCode.NRefactory.VB { StartNode(forStatement); - throw new NotImplementedException(); + WriteKeyword("For"); + forStatement.Variable.AcceptVisitor(this, data); + WriteKeyword("To"); + forStatement.ToExpression.AcceptVisitor(this, data); + if (!forStatement.StepExpression.IsNull) { + WriteKeyword("Step"); + forStatement.StepExpression.AcceptVisitor(this, data); + } + NewLine(); + Indent(); + forStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("Next"); return EndNode(forStatement); } @@ -1954,7 +1945,7 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("For"); WriteKeyword("Each"); - forEachStatement.Initializer.AcceptVisitor(this, data); + forEachStatement.Variable.AcceptVisitor(this, data); WriteKeyword("In"); forEachStatement.InExpression.AcceptVisitor(this, data); NewLine(); @@ -2083,5 +2074,52 @@ namespace ICSharpCode.NRefactory.VB yieldStatement.Expression.AcceptVisitor(this, data); return EndNode(yieldStatement); } + + public object VisitVariableInitializer(VariableInitializer variableInitializer, object data) + { + StartNode(variableInitializer); + + variableInitializer.Identifier.AcceptVisitor(this, data); + if (!variableInitializer.Type.IsNull) { + WriteKeyword("As"); + variableInitializer.Type.AcceptVisitor(this, data); + } + if (!variableInitializer.Expression.IsNull) { + Space(); + WriteToken("=", VariableInitializer.Roles.Assign); + Space(); + variableInitializer.Expression.AcceptVisitor(this, data); + } + + return EndNode(variableInitializer); + } + + public object VisitVariableDeclaratorWithTypeAndInitializer(VariableDeclaratorWithTypeAndInitializer variableDeclaratorWithTypeAndInitializer, object data) + { + StartNode(variableDeclaratorWithTypeAndInitializer); + + WriteCommaSeparatedList(variableDeclaratorWithTypeAndInitializer.Identifiers); + WriteKeyword("As"); + variableDeclaratorWithTypeAndInitializer.Type.AcceptVisitor(this, data); + if (!variableDeclaratorWithTypeAndInitializer.Initializer.IsNull) { + Space(); + WriteToken("=", VariableDeclarator.Roles.Assign); + Space(); + variableDeclaratorWithTypeAndInitializer.Initializer.AcceptVisitor(this, data); + } + + return EndNode(variableDeclaratorWithTypeAndInitializer); + } + + public object VisitVariableDeclaratorWithObjectCreation(VariableDeclaratorWithObjectCreation variableDeclaratorWithObjectCreation, object data) + { + StartNode(variableDeclaratorWithObjectCreation); + + WriteCommaSeparatedList(variableDeclaratorWithObjectCreation.Identifiers); + WriteKeyword("As"); + variableDeclaratorWithObjectCreation.Initializer.AcceptVisitor(this, data); + + return EndNode(variableDeclaratorWithObjectCreation); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 617f258e7f..35569db9c0 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -774,15 +774,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitForeachStatement(CSharp.ForeachStatement foreachStatement, object data) { - var var = new LocalDeclarationStatement(); - - var.Variables.Add(new VariableDeclarator() { Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) }); - var.Variables.Last().Identifiers.Add(new VariableIdentifier() { Name = foreachStatement.VariableName }); - var stmt = new ForEachStatement() { Body = (BlockStatement)foreachStatement.EmbeddedStatement.AcceptVisitor(this, data), InExpression = (Expression)foreachStatement.InExpression.AcceptVisitor(this, data), - Initializer = var + Variable = new VariableInitializer() { Identifier = new VariableIdentifier() { Name = foreachStatement.VariableName }, Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) } }; return EndNode(foreachStatement, stmt); @@ -1256,13 +1251,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitVariableInitializer(CSharp.VariableInitializer variableInitializer, object data) { - var decl = new VariableDeclarator(); + var decl = new VariableDeclaratorWithTypeAndInitializer(); // look for type in parent decl.Type = (AstType)variableInitializer.Parent .GetChildByRole(CSharp.VariableInitializer.Roles.Type) .AcceptVisitor(this, data); - decl.Identifiers.Add(new VariableIdentifier() { Name = new Identifier(variableInitializer.Name, AstLocation.Empty) }); + decl.Identifiers.Add(new VariableIdentifier() { Name = variableInitializer.Name }); decl.Initializer = (Expression)variableInitializer.Initializer.AcceptVisitor(this, data); return EndNode(variableInitializer, decl); From a3d75dbbf14f90d4060fb20217d68db342720a69 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 7 Jul 2011 16:31:24 +0200 Subject: [PATCH 26/57] implement conversion of switch to Select Case --- .../Ast/Statements/SelectStatement.cs | 102 +++++++++++++++ .../Ast/Statements/Statement.cs | 26 ++-- .../Ast/TypeMembers/FieldDeclaration.cs | 25 +++- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 4 + .../OutputVisitor/OutputVisitor.cs | 82 +++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 118 +++++++++++++----- 6 files changed, 309 insertions(+), 48 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs index 21de4c435d..70f2dd7209 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs @@ -32,14 +32,116 @@ namespace ICSharpCode.NRefactory.VB.Ast { public static readonly Role CaseStatementRole = new Role("CaseStatement"); + public AstNodeCollection Clauses { + get { return GetChildrenByRole(CaseClause.CaseClauseRole); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitCaseStatement(this, data); + } + } + + public abstract class CaseClause : AstNode + { + #region Null + public new static readonly CaseClause Null = new NullCaseClause(); + + sealed class NullCaseClause : CaseClause + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + public static readonly Role CaseClauseRole = new Role("CaseClause", CaseClause.Null); + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + } + + public class SimpleCaseClause : CaseClause + { + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitSimpleCaseClause(this, data); + } + } + + public class RangeCaseClause : CaseClause + { + public static readonly Role ToExpressionRole = ForStatement.ToExpressionRole; + + public Expression ToExpression { + get { return GetChildByRole(ToExpressionRole); } + set { SetChildByRole(ToExpressionRole, value); } + } + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { throw new NotImplementedException(); } public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitRangeCaseClause(this, data); + } + } + + public class ComparisonCaseClause : CaseClause + { + public static readonly Role OperatorRole = BinaryOperatorExpression.OperatorRole; + + public ComparisonOperator Operator { get; set; } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { throw new NotImplementedException(); } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitComparisonCaseClause(this, data); + } + } + + public enum ComparisonOperator + { + Equality = BinaryOperatorType.Equality, + InEquality = BinaryOperatorType.InEquality, + LessThan = BinaryOperatorType.LessThan, + GreaterThan = BinaryOperatorType.GreaterThan, + LessThanOrEqual = BinaryOperatorType.LessThanOrEqual, + GreaterThanOrEqual = BinaryOperatorType.GreaterThanOrEqual } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs index c20407051c..5b2a55bbb3 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs @@ -115,18 +115,18 @@ namespace ICSharpCode.NRefactory.VB.Ast } // Make debugging easier by giving Statements a ToString() implementation - public override string ToString() - { -// if (IsNull) -// return "Null"; -// StringWriter w = new StringWriter(); -// AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null); -// string text = w.ToString().TrimEnd().Replace("\t", "").Replace(w.NewLine, " "); -// if (text.Length > 100) -// return text.Substring(0, 97) + "..."; -// else -// return text; - throw new NotImplementedException(); - } +// public override string ToString() +// { +//// if (IsNull) +//// return "Null"; +//// StringWriter w = new StringWriter(); +//// AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null); +//// string text = w.ToString().TrimEnd().Replace("\t", "").Replace(w.NewLine, " "); +//// if (text.Length > 100) +//// return text.Substring(0, 97) + "..."; +//// else +//// return text; +// throw new NotImplementedException(); +// } } } diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs index e9679da636..06cf639d97 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs @@ -32,7 +32,30 @@ namespace ICSharpCode.NRefactory.VB.Ast ///
public class VariableIdentifier : AstNode { - public static readonly Role VariableIdentifierRole = new Role("VariableIdentifier"); + #region Null + public new static readonly VariableIdentifier Null = new NullVariableIdentifier(); + + sealed class NullVariableIdentifier : VariableIdentifier + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + public static readonly Role VariableIdentifierRole = new Role("VariableIdentifier", VariableIdentifier.Null); public Identifier Name { get { return GetChildByRole(Roles.Identifier); } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 3a4ed86737..ed4ddb06ff 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -97,5 +97,9 @@ namespace ICSharpCode.NRefactory.VB { S VisitSimpleType(SimpleType simpleType, T data); S VisitVariableInitializer(VariableInitializer variableInitializer, T data); + S VisitRangeCaseClause(RangeCaseClause rangeCaseClause, T data); + S VisitComparisonCaseClause(ComparisonCaseClause comparisonCaseClause, T data); + S VisitSimpleCaseClause(SimpleCaseClause simpleCaseClause, T data); + S VisitCaseStatement(CaseStatement caseStatement, T data); } } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index f85a48cb70..cf0d7310ea 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2064,9 +2064,89 @@ namespace ICSharpCode.NRefactory.VB public object VisitSelectStatement(SelectStatement selectStatement, object data) { - throw new NotImplementedException(); + StartNode(selectStatement); + + WriteKeyword("Select"); + WriteKeyword("Case"); + selectStatement.Expression.AcceptVisitor(this, data); + NewLine(); + Indent(); + + foreach (CaseStatement stmt in selectStatement.Cases) { + stmt.AcceptVisitor(this, data); + } + + Unindent(); + WriteKeyword("End"); + WriteKeyword("Select"); + + return EndNode(selectStatement); + } + + public object VisitCaseStatement(CaseStatement caseStatement, object data) + { + StartNode(caseStatement); + + WriteKeyword("Case"); + if (caseStatement.Clauses.Count == 1 && caseStatement.Clauses.First().Expression.IsNull) + WriteKeyword("Else"); + else + WriteCommaSeparatedList(caseStatement.Clauses); + NewLine(); + Indent(); + caseStatement.Body.AcceptVisitor(this, data); + Unindent(); + + return EndNode(caseStatement); } + public object VisitSimpleCaseClause(SimpleCaseClause simpleCaseClause, object data) + { + StartNode(simpleCaseClause); + simpleCaseClause.Expression.AcceptVisitor(this, data); + return EndNode(simpleCaseClause); + } + + public object VisitRangeCaseClause(RangeCaseClause rangeCaseClause, object data) + { + StartNode(rangeCaseClause); + rangeCaseClause.Expression.AcceptVisitor(this, data); + WriteKeyword("To"); + rangeCaseClause.ToExpression.AcceptVisitor(this, data); + return EndNode(rangeCaseClause); + } + + public object VisitComparisonCaseClause(ComparisonCaseClause comparisonCaseClause, object data) + { + StartNode(comparisonCaseClause); + switch (comparisonCaseClause.Operator) { + case ComparisonOperator.Equality: + WriteToken("=", ComparisonCaseClause.OperatorRole); + break; + case ComparisonOperator.InEquality: + WriteToken("<>", ComparisonCaseClause.OperatorRole); + break; + case ComparisonOperator.LessThan: + WriteToken("<", ComparisonCaseClause.OperatorRole); + break; + case ComparisonOperator.GreaterThan: + WriteToken(">", ComparisonCaseClause.OperatorRole); + break; + case ComparisonOperator.LessThanOrEqual: + WriteToken("<=", ComparisonCaseClause.OperatorRole); + break; + case ComparisonOperator.GreaterThanOrEqual: + WriteToken(">=", ComparisonCaseClause.OperatorRole); + break; + default: + throw new Exception("Invalid value for ComparisonOperator"); + } + Space(); + comparisonCaseClause.Expression.AcceptVisitor(this, data); + return EndNode(comparisonCaseClause); + } + + public object VisitYieldStatement(YieldStatement yieldStatement, object data) { StartNode(yieldStatement); diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 35569db9c0..2de4730590 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -77,6 +77,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors { var left = (Expression)assignmentExpression.Left.AcceptVisitor(this, data); var op = AssignmentOperatorType.None; + var right = (Expression)assignmentExpression.Right.AcceptVisitor(this, data); switch (assignmentExpression.Operator) { case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Assign: @@ -88,36 +89,38 @@ namespace ICSharpCode.NRefactory.VB.Visitors case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Subtract: op = AssignmentOperatorType.Subtract; break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply: -// -// break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Divide: -// -// break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Modulus: -// -// break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftLeft: -// -// break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftRight: -// -// break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseAnd: -// -// break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseOr: -// -// break; -// case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ExclusiveOr: -// -// break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply: + op = AssignmentOperatorType.Multiply; + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Divide: + op = AssignmentOperatorType.Divide; + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Modulus: + op = AssignmentOperatorType.Assign; + right = new BinaryOperatorExpression((Expression)left.Clone(), BinaryOperatorType.Modulus, right); + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftLeft: + op = AssignmentOperatorType.ShiftLeft; + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftRight: + op = AssignmentOperatorType.ShiftRight; + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseAnd: + op = AssignmentOperatorType.Assign; + right = new BinaryOperatorExpression((Expression)left.Clone(), BinaryOperatorType.BitwiseAnd, right); + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseOr: + op = AssignmentOperatorType.Assign; + right = new BinaryOperatorExpression((Expression)left.Clone(), BinaryOperatorType.BitwiseOr, right); + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ExclusiveOr: + op = AssignmentOperatorType.Assign; + right = new BinaryOperatorExpression((Expression)left.Clone(), BinaryOperatorType.ExclusiveOr, right); + break; default: throw new Exception("Invalid value for AssignmentOperatorType: " + assignmentExpression.Operator); } - var right = (Expression)assignmentExpression.Right.AcceptVisitor(this, data); - var expr = new AssignmentExpression(left, op, right); return EndNode(assignmentExpression, expr); } @@ -222,10 +225,38 @@ namespace ICSharpCode.NRefactory.VB.Visitors return CastType.CType; switch (primType.Keyword) { + case "Boolean": + return CastType.CBool; + case "Byte": + return CastType.CByte; + case "Char": + return CastType.CChar; + case "Date": + return CastType.CDate; + case "Double": + return CastType.CDbl; + case "Decimal": + return CastType.CDec; case "Integer": return CastType.CInt; + case "Long": + return CastType.CLng; + case "Object": + return CastType.CObj; + case "SByte": + return CastType.CSByte; + case "Short": + return CastType.CShort; + case "Single": + return CastType.CSng; case "String": return CastType.CStr; + case "UInteger": + return CastType.CUInt; + case "ULong": + return CastType.CULng; + case "UShort": + return CastType.CUShort; } return CastType.CType; @@ -367,8 +398,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors { Expression expr; - if (primitiveExpression.Value is string && ((string)primitiveExpression.Value).IndexOfAny(new[] {'\r', '\n'}) > -1) - expr = ConvertToConcat((string)primitiveExpression.Value); + if ((primitiveExpression.Value is string || primitiveExpression.Value is char) && primitiveExpression.Value.ToString().IndexOfAny(new[] {'\r', '\n'}) > -1) + expr = ConvertToConcat(primitiveExpression.Value.ToString()); else expr = new PrimitiveExpression(primitiveExpression.Value); @@ -383,7 +414,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors for (int i = 0; i < literal.Length; i++) { if (literal[i] == '\r') { string part = literal.Substring(start, i - start); - parts.Push(new PrimitiveExpression(part)); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); if (i + 1 < literal.Length && literal[i + 1] == '\n') { i++; parts.Push(new IdentifierExpression() { Identifier = "vbCrLf" }); @@ -392,9 +424,16 @@ namespace ICSharpCode.NRefactory.VB.Visitors start = i + 1; } else if (literal[i] == '\n') { string part = literal.Substring(start, i - start); - parts.Push(new PrimitiveExpression(part)); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); parts.Push(new IdentifierExpression() { Identifier = "vbLf" }); start = i + 1; + } else if (literal[i] == '\t') { + string part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression() { Identifier = "vbTab" }); + start = i + 1; } } @@ -850,17 +889,30 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitSwitchStatement(CSharp.SwitchStatement switchStatement, object data) { - throw new NotImplementedException(); + var stmt = new SelectStatement() { Expression = (Expression)switchStatement.Expression.AcceptVisitor(this, data) }; + ConvertNodes(switchStatement.SwitchSections, stmt.Cases); + + return EndNode(switchStatement, stmt); } public AstNode VisitSwitchSection(CSharp.SwitchSection switchSection, object data) { - throw new NotImplementedException(); + var caseStmt = new CaseStatement(); + ConvertNodes(switchSection.CaseLabels, caseStmt.Clauses); + if (switchSection.Statements.Count == 1 && switchSection.Statements.FirstOrDefault() is CSharp.BlockStatement) + caseStmt.Body = (BlockStatement)switchSection.Statements.FirstOrDefault().AcceptVisitor(this, data); + else { + caseStmt.Body = new BlockStatement(); + ConvertNodes(switchSection.Statements, caseStmt.Body.Statements); + } + if (caseStmt.Body.LastOrDefault() is ExitStatement && ((ExitStatement)caseStmt.Body.LastOrDefault()).ExitKind == ExitKind.Select) + caseStmt.Body.LastOrDefault().Remove(); + return EndNode(switchSection, caseStmt); } public AstNode VisitCaseLabel(CSharp.CaseLabel caseLabel, object data) { - throw new NotImplementedException(); + return EndNode(caseLabel, new SimpleCaseClause() { Expression = (Expression)caseLabel.Expression.AcceptVisitor(this, data) }); } public AstNode VisitThrowStatement(CSharp.ThrowStatement throwStatement, object data) From 3531735e970b3215658433fedd750014b3e3ee25 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 7 Jul 2011 17:43:33 +0200 Subject: [PATCH 27/57] implemented DoLoopStatement and UsingStatement --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 19 ++------ .../Ast/Statements/DoLoopStatement.cs | 14 +++++- .../Ast/Statements/UsingStatement.cs | 33 +++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 13 +++--- .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 46 +++++++++++++++++++ .../Visitors/CSharpToVBConverterVisitor.cs | 22 +++++++-- 7 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index 5ce7c29bed..c7f6dc08e1 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -102,25 +102,12 @@ namespace ICSharpCode.NRefactory.VB.Ast public enum ConditionType { None, - Until, - While, + LoopUntil, + LoopWhile, + DoUntil, DoWhile } - public enum ConditionPosition - { - None, - Start, - End - } - - public enum ConstructorInitializerType - { - None, - Base, - This - } - public enum ConversionType { None, diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs index 0b2101c176..9335926f89 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs @@ -8,6 +8,18 @@ namespace ICSharpCode.NRefactory.VB.Ast { public class DoLoopStatement : Statement { + public ConditionType ConditionType { get; set; } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { throw new NotImplementedException(); @@ -15,7 +27,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public override S AcceptVisitor(IAstVisitor visitor, T data) { - throw new NotImplementedException(); + return visitor.VisitDoLoopStatement(this, data); } } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs new file mode 100644 index 0000000000..c2147e447a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs @@ -0,0 +1,33 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class UsingStatement : Statement + { + public static readonly Role ResourceRole = new Role("Resource", AstNode.Null); + + /// either multiple VariableInitializers or one Expression + public AstNodeCollection Resources { + get { return GetChildrenByRole(ResourceRole); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitUsingStatement(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index ed4ddb06ff..4d7e638995 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -88,6 +88,13 @@ namespace ICSharpCode.NRefactory.VB { S VisitExitStatement(ExitStatement exitStatement, T data); S VisitSelectStatement(SelectStatement selectStatement, T data); S VisitYieldStatement(YieldStatement yieldStatement, T data); + S VisitVariableInitializer(VariableInitializer variableInitializer, T data); + S VisitRangeCaseClause(RangeCaseClause rangeCaseClause, T data); + S VisitComparisonCaseClause(ComparisonCaseClause comparisonCaseClause, T data); + S VisitSimpleCaseClause(SimpleCaseClause simpleCaseClause, T data); + S VisitCaseStatement(CaseStatement caseStatement, T data); + S VisitDoLoopStatement(DoLoopStatement doLoopStatement, T data); + S VisitUsingStatement(UsingStatement usingStatement, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); @@ -95,11 +102,5 @@ namespace ICSharpCode.NRefactory.VB { S VisitComposedType(ComposedType composedType, T data); S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data); S VisitSimpleType(SimpleType simpleType, T data); - - S VisitVariableInitializer(VariableInitializer variableInitializer, T data); - S VisitRangeCaseClause(RangeCaseClause rangeCaseClause, T data); - S VisitComparisonCaseClause(ComparisonCaseClause comparisonCaseClause, T data); - S VisitSimpleCaseClause(SimpleCaseClause simpleCaseClause, T data); - S VisitCaseStatement(CaseStatement caseStatement, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 948c353cdc..5a14a81400 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -100,6 +100,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index cf0d7310ea..e73946064f 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2201,5 +2201,51 @@ namespace ICSharpCode.NRefactory.VB return EndNode(variableDeclaratorWithObjectCreation); } + + public object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) + { + StartNode(doLoopStatement); + + WriteKeyword("Do"); + if (doLoopStatement.ConditionType == ConditionType.DoUntil) { + WriteKeyword("Until"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + if (doLoopStatement.ConditionType == ConditionType.DoWhile) { + WriteKeyword("While"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + NewLine(); + Indent(); + doLoopStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("Loop"); + if (doLoopStatement.ConditionType == ConditionType.LoopUntil) { + WriteKeyword("Until"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + if (doLoopStatement.ConditionType == ConditionType.LoopWhile) { + WriteKeyword("While"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + + return EndNode(doLoopStatement); + } + + public object VisitUsingStatement(UsingStatement usingStatement, object data) + { + StartNode(usingStatement); + + WriteKeyword("Using"); + WriteCommaSeparatedList(usingStatement.Resources); + NewLine(); + Indent(); + usingStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("End"); + WriteKeyword("Using"); + + return EndNode(usingStatement); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 2de4730590..48dc0c1d59 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -791,12 +791,18 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitDoWhileStatement(CSharp.DoWhileStatement doWhileStatement, object data) { - throw new NotImplementedException(); + var stmt = new DoLoopStatement(); + + stmt.ConditionType = ConditionType.LoopWhile; + stmt.Expression = (Expression)doWhileStatement.Condition.AcceptVisitor(this, data); + stmt.Body = (BlockStatement)doWhileStatement.EmbeddedStatement.AcceptVisitor(this, data); + + return EndNode(doWhileStatement, stmt); } public AstNode VisitEmptyStatement(CSharp.EmptyStatement emptyStatement, object data) { - throw new NotImplementedException(); + return EndNode(emptyStatement, null); } public AstNode VisitExpressionStatement(CSharp.ExpressionStatement expressionStatement, object data) @@ -816,7 +822,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors var stmt = new ForEachStatement() { Body = (BlockStatement)foreachStatement.EmbeddedStatement.AcceptVisitor(this, data), InExpression = (Expression)foreachStatement.InExpression.AcceptVisitor(this, data), - Variable = new VariableInitializer() { Identifier = new VariableIdentifier() { Name = foreachStatement.VariableName }, Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) } + Variable = new VariableInitializer() { + Identifier = new VariableIdentifier() { Name = foreachStatement.VariableName }, + Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) + } }; return EndNode(foreachStatement, stmt); @@ -954,7 +963,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitUsingStatement(CSharp.UsingStatement usingStatement, object data) { - throw new NotImplementedException(); + var stmt = new UsingStatement(); + + stmt.Resources.Add(usingStatement.ResourceAcquisition.AcceptVisitor(this, data)); + stmt.Body = (BlockStatement)usingStatement.EmbeddedStatement.AcceptVisitor(this, data); + + return EndNode(usingStatement, stmt); } public AstNode VisitVariableDeclarationStatement(CSharp.VariableDeclarationStatement variableDeclarationStatement, object data) From bf89db8e855151b1c3a48db8a35e42018873b290 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 7 Jul 2011 20:28:48 +0200 Subject: [PATCH 28/57] implement GoToStatement --- .../Ast/Statements/GoToStatement.cs | 27 +++++++++++++++++++ .../Statements/LabelDeclarationStatement.cs | 9 ++++--- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 ++ .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 17 +++++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 5 ++-- 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/GoToStatement.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/GoToStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/GoToStatement.cs new file mode 100644 index 0000000000..32dc7d7456 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/GoToStatement.cs @@ -0,0 +1,27 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class GoToStatement : Statement + { + /// either PrimitiveExpression or IdentifierExpression + public Expression Label { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitGoToStatement(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs index f613a76788..589fea5a6c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/LabelDeclarationStatement.cs @@ -11,9 +11,10 @@ namespace ICSharpCode.NRefactory.VB.Ast ///
public class LabelDeclarationStatement : Statement { - public Identifier Label { - get { return GetChildByRole(Roles.Identifier); } - set { SetChildByRole(Roles.Identifier, value); } + /// either PrimitiveExpression or IdentifierExpression + public Expression Label { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } } public VBTokenNode Colon { @@ -28,7 +29,7 @@ namespace ICSharpCode.NRefactory.VB.Ast protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { LabelDeclarationStatement o = other as LabelDeclarationStatement; - return o != null && MatchString(this.Label.Name, o.Label.Name); + return o != null && this.Label.DoMatch(o.Label, match); } } } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 4d7e638995..875ff210a5 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -102,5 +102,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitComposedType(ComposedType composedType, T data); S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data); S VisitSimpleType(SimpleType simpleType, T data); + + S VisitGoToStatement(GoToStatement goToStatement, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 5a14a81400..0cccd7a54d 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -91,6 +91,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index e73946064f..3de803f957 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1344,7 +1344,12 @@ namespace ICSharpCode.NRefactory.VB public object VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, object data) { - throw new NotImplementedException(); + StartNode(labelDeclarationStatement); + + labelDeclarationStatement.Label.AcceptVisitor(this, data); + WriteToken(":", LabelDeclarationStatement.Roles.Colon); + + return EndNode(labelDeclarationStatement); } public object VisitLocalDeclarationStatement(LocalDeclarationStatement localDeclarationStatement, object data) @@ -2247,5 +2252,15 @@ namespace ICSharpCode.NRefactory.VB return EndNode(usingStatement); } + + public object VisitGoToStatement(GoToStatement goToStatement, object data) + { + StartNode(goToStatement); + + WriteKeyword("GoTo"); + goToStatement.Label.AcceptVisitor(this, data); + + return EndNode(goToStatement); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 48dc0c1d59..bfd373a765 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -175,6 +175,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors op = BinaryOperatorType.LessThanOrEqual; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Add: + // TODO might be string concatenation op = BinaryOperatorType.Add; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Subtract: @@ -860,7 +861,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitGotoStatement(CSharp.GotoStatement gotoStatement, object data) { - throw new NotImplementedException(); + return EndNode(gotoStatement, new GoToStatement() { Label = new IdentifierExpression() { Identifier = gotoStatement.Label } }); } public AstNode VisitIfElseStatement(CSharp.IfElseStatement ifElseStatement, object data) @@ -876,7 +877,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitLabelStatement(CSharp.LabelStatement labelStatement, object data) { - throw new NotImplementedException(); + return EndNode(labelStatement, new LabelDeclarationStatement() { Label = new IdentifierExpression() { Identifier = labelStatement.Label } }); } public AstNode VisitLockStatement(CSharp.LockStatement lockStatement, object data) From d340669da1e99fadea470202a4e03de594c73a20 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 8 Jul 2011 08:22:02 +0200 Subject: [PATCH 29/57] make AddressOfExpression a UnaryOperatorExpression, move expressions to separate files, implement LambdaExpression --- .../Ast/Expressions/AddressOfExpression.cs | 31 -- .../Ast/Expressions/AssignmentExpression.cs | 44 ++ .../Expressions/BinaryOperatorExpression.cs | 110 +++++ .../Ast/Expressions/ConditionalExpression.cs | 44 ++ .../Ast/Expressions/Expression.cs | 393 ------------------ .../Expressions/FieldInitializerExpression.cs | 49 +++ .../Ast/Expressions/InvocationExpression.cs | 52 +++ .../Ast/Expressions/LambdaExpression.cs | 124 ++++++ .../Expressions/NamedArgumentExpression.cs | 39 ++ .../Expressions/UnaryOperatorExpression.cs | 80 ++++ .../Ast/Expressions/VariableInitializer.cs | 44 ++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 5 +- .../ICSharpCode.NRefactory.VB.csproj | 10 +- .../OutputVisitor/OutputVisitor.cs | 68 ++- .../Visitors/CSharpToVBConverterVisitor.cs | 18 +- 15 files changed, 671 insertions(+), 440 deletions(-) delete mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs deleted file mode 100644 index 81eaca8126..0000000000 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.NRefactory.VB.Ast -{ - public class AddressOfExpression : Expression - { - public AddressOfExpression() - { - } - - public Expression Expression { - get { return GetChildByRole(Roles.Expression); } - set { SetChildByRole(Roles.Expression, value); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - var expr = other as AddressOfExpression; - return expr != null && - Expression.DoMatch(expr.Expression, match); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAddressOfExpression(this, data); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs new file mode 100644 index 0000000000..250e27b71a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs @@ -0,0 +1,44 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class AssignmentExpression : Expression + { + public readonly static Role LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; + public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; + public readonly static Role RightExpressionRole = BinaryOperatorExpression.RightExpressionRole; + + public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right) + { + AddChild(left, LeftExpressionRole); + AddChild(right, RightExpressionRole); + Operator = type; + } + + public Expression Left { + get { return GetChildByRole(LeftExpressionRole); } + set { SetChildByRole(LeftExpressionRole, value); } + } + + public AssignmentOperatorType Operator { get; set; } + + public Expression Right { + get { return GetChildByRole(RightExpressionRole); } + set { SetChildByRole(RightExpressionRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAssignmentExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs new file mode 100644 index 0000000000..d406be1996 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs @@ -0,0 +1,110 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class BinaryOperatorExpression : Expression + { + public readonly static Role LeftExpressionRole = new Role("Left"); + public readonly static Role OperatorRole = new Role("Operator"); + public readonly static Role RightExpressionRole = new Role("Right"); + + public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right) + { + AddChild(left, LeftExpressionRole); + AddChild(right, RightExpressionRole); + Operator = type; + } + + public Expression Left { + get { return GetChildByRole(LeftExpressionRole); } + set { SetChildByRole(LeftExpressionRole, value); } + } + + public BinaryOperatorType Operator { get; set; } + + public Expression Right { + get { return GetChildByRole(RightExpressionRole); } + set { SetChildByRole(RightExpressionRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitBinaryOperatorExpression(this, data); + } + } + + public enum BinaryOperatorType + { + None, + + /// '&' in C#, 'And' in VB. + BitwiseAnd, + /// '|' in C#, 'Or' in VB. + BitwiseOr, + /// '&&' in C#, 'AndAlso' in VB. + LogicalAnd, + /// '||' in C#, 'OrElse' in VB. + LogicalOr, + /// '^' in C#, 'Xor' in VB. + ExclusiveOr, + + /// > + GreaterThan, + /// >= + GreaterThanOrEqual, + /// '==' in C#, '=' in VB. + Equality, + /// '!=' in C#, '<>' in VB. + InEquality, + /// < + LessThan, + /// <= + LessThanOrEqual, + + /// + + Add, + /// - + Subtract, + /// * + Multiply, + /// / + Divide, + /// '%' in C#, 'Mod' in VB. + Modulus, + /// VB-only: \ + DivideInteger, + /// VB-only: ^ + Power, + /// VB-only: & + Concat, + + /// C#: << + ShiftLeft, + /// C#: >> + ShiftRight, + /// VB-only: Is + ReferenceEquality, + /// VB-only: IsNot + ReferenceInequality, + + /// VB-only: Like + Like, + /// + /// C#: ?? + /// VB: IF(x, y) + /// + NullCoalescing, + + /// VB-only: ! + DictionaryAccess + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs new file mode 100644 index 0000000000..94d9949bda --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs @@ -0,0 +1,44 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ConditionalExpression : Expression + { + public readonly static Role ConditionExpressionRole = new Role("ConditionExpressionRole", Expression.Null); + public readonly static Role TrueExpressionRole = new Role("TrueExpressionRole", Expression.Null); + public readonly static Role FalseExpressionRole = new Role("FalseExpressionRole", Expression.Null); + + public VBTokenNode IfToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression ConditionExpression { + get { return GetChildByRole (ConditionExpressionRole); } + set { SetChildByRole (ConditionExpressionRole, value); } + } + + public Expression TrueExpression { + get { return GetChildByRole (TrueExpressionRole); } + set { SetChildByRole (TrueExpressionRole, value); } + } + + public Expression FalseExpression { + get { return GetChildByRole (FalseExpressionRole); } + set { SetChildByRole (FalseExpressionRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitConditionalExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index b26ec73bb0..26876e4161 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -31,397 +31,4 @@ namespace ICSharpCode.NRefactory.VB.Ast } #endregion } - - public class BinaryOperatorExpression : Expression - { - public readonly static Role LeftExpressionRole = new Role("Left"); - public readonly static Role OperatorRole = new Role("Operator"); - public readonly static Role RightExpressionRole = new Role("Right"); - - public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right) - { - AddChild(left, LeftExpressionRole); - AddChild(right, RightExpressionRole); - Operator = type; - } - - public Expression Left { - get { return GetChildByRole(LeftExpressionRole); } - set { SetChildByRole(LeftExpressionRole, value); } - } - - public BinaryOperatorType Operator { get; set; } - - public Expression Right { - get { return GetChildByRole(RightExpressionRole); } - set { SetChildByRole(RightExpressionRole, value); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - throw new NotImplementedException(); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitBinaryOperatorExpression(this, data); - } - } - - public enum BinaryOperatorType - { - None, - - /// '&' in C#, 'And' in VB. - BitwiseAnd, - /// '|' in C#, 'Or' in VB. - BitwiseOr, - /// '&&' in C#, 'AndAlso' in VB. - LogicalAnd, - /// '||' in C#, 'OrElse' in VB. - LogicalOr, - /// '^' in C#, 'Xor' in VB. - ExclusiveOr, - - /// > - GreaterThan, - /// >= - GreaterThanOrEqual, - /// '==' in C#, '=' in VB. - Equality, - /// '!=' in C#, '<>' in VB. - InEquality, - /// < - LessThan, - /// <= - LessThanOrEqual, - - /// + - Add, - /// - - Subtract, - /// * - Multiply, - /// / - Divide, - /// '%' in C#, 'Mod' in VB. - Modulus, - /// VB-only: \ - DivideInteger, - /// VB-only: ^ - Power, - /// VB-only: & - Concat, - - /// C#: << - ShiftLeft, - /// C#: >> - ShiftRight, - /// VB-only: Is - ReferenceEquality, - /// VB-only: IsNot - ReferenceInequality, - - /// VB-only: Like - Like, - /// - /// C#: ?? - /// VB: IF(x, y) - /// - NullCoalescing, - - /// VB-only: ! - DictionaryAccess - } - - public class AssignmentExpression : Expression - { - public readonly static Role LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; - public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; - public readonly static Role RightExpressionRole = BinaryOperatorExpression.RightExpressionRole; - - public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right) - { - AddChild(left, LeftExpressionRole); - AddChild(right, RightExpressionRole); - Operator = type; - } - - public Expression Left { - get { return GetChildByRole(LeftExpressionRole); } - set { SetChildByRole(LeftExpressionRole, value); } - } - - public AssignmentOperatorType Operator { get; set; } - - public Expression Right { - get { return GetChildByRole(RightExpressionRole); } - set { SetChildByRole(RightExpressionRole, value); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - throw new NotImplementedException(); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAssignmentExpression(this, data); - } - } - - /// - /// Target(Arguments) - /// - public class InvocationExpression : Expression - { - public Expression Target { - get { return GetChildByRole (Roles.TargetExpression); } - set { SetChildByRole(Roles.TargetExpression, value); } - } - - public AstNodeCollection Arguments { - get { return GetChildrenByRole(Roles.Argument); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitInvocationExpression(this, data); - } - - public InvocationExpression () - { - } - - public InvocationExpression (Expression target, IEnumerable arguments) - { - AddChild (target, Roles.TargetExpression); - if (arguments != null) { - foreach (var arg in arguments) { - AddChild (arg, Roles.Argument); - } - } - } - - public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable)arguments) - { - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - InvocationExpression o = other as InvocationExpression; - return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match); - } - } - - /// - /// Operator Expression - /// - public class UnaryOperatorExpression : Expression - { - public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; - - public UnaryOperatorExpression() - { - } - - public UnaryOperatorExpression(UnaryOperatorType op, Expression expression) - { - this.Operator = op; - this.Expression = expression; - } - - public UnaryOperatorType Operator { - get; - set; - } - - public VBTokenNode OperatorToken { - get { return GetChildByRole (OperatorRole); } - } - - public Expression Expression { - get { return GetChildByRole (Roles.Expression); } - set { SetChildByRole (Roles.Expression, value); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitUnaryOperatorExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - UnaryOperatorExpression o = other as UnaryOperatorExpression; - return o != null && this.Operator == o.Operator && this.Expression.DoMatch(o.Expression, match); - } - - public static string GetOperatorSymbol(UnaryOperatorType op) - { - switch (op) { - case UnaryOperatorType.Not: - return "Not"; - case UnaryOperatorType.Minus: - return "-"; - case UnaryOperatorType.Plus: - return "+"; - default: - throw new NotSupportedException("Invalid value for UnaryOperatorType"); - } - } - } - - public enum UnaryOperatorType - { - /// Logical/Bitwise not (Not a) - Not, - /// Unary minus (-a) - Minus, - /// Unary plus (+a) - Plus - } - - /// - /// Represents a named argument passed to a method or attribute. - /// - public class NamedArgumentExpression : Expression - { - public Identifier Identifier { - get { return GetChildByRole(Roles.Identifier); } - set { SetChildByRole(Roles.Identifier, value); } - } - - public VBTokenNode AssignToken { - get { return GetChildByRole (Roles.Assign); } - } - - public Expression Expression { - get { return GetChildByRole (Roles.Expression); } - set { SetChildByRole (Roles.Expression, value); } - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNamedArgumentExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - NamedArgumentExpression o = other as NamedArgumentExpression; - return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); - } - } - - /// - /// Identifier As Type = Expression - /// - public class VariableInitializer : AstNode - { - public VariableIdentifier Identifier { - get { return GetChildByRole(VariableIdentifier.VariableIdentifierRole); } - set { SetChildByRole(VariableIdentifier.VariableIdentifierRole, value); } - } - - public AstType Type { - get { return GetChildByRole(Roles.Type); } - set { SetChildByRole(Roles.Type, value); } - } - - public VBTokenNode AssignToken { - get { return GetChildByRole (Roles.Assign); } - } - - public Expression Expression { - get { return GetChildByRole (Roles.Expression); } - set { SetChildByRole (Roles.Expression, value); } - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitVariableInitializer(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - VariableInitializer o = other as VariableInitializer; - return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); - } - } - - /// - /// [ Key ] .Identifier = Expression - /// - public class FieldInitializerExpression : Expression - { - public bool IsKey { get; set; } - - public VBTokenNode KeyToken { - get { return GetChildByRole (Roles.Keyword); } - } - - public VBTokenNode DotToken { - get { return GetChildByRole (Roles.Dot); } - } - - public Identifier Identifier { - get { return GetChildByRole(Roles.Identifier); } - set { SetChildByRole(Roles.Identifier, value); } - } - - public VBTokenNode AssignToken { - get { return GetChildByRole (Roles.Assign); } - } - - public Expression Expression { - get { return GetChildByRole (Roles.Expression); } - set { SetChildByRole (Roles.Expression, value); } - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitFieldInitializerExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - FieldInitializerExpression o = other as FieldInitializerExpression; - return o != null && this.IsKey == o.IsKey && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); - } - } - - public class ConditionalExpression : Expression - { - public readonly static Role ConditionExpressionRole = new Role("ConditionExpressionRole", Expression.Null); - public readonly static Role TrueExpressionRole = new Role("TrueExpressionRole", Expression.Null); - public readonly static Role FalseExpressionRole = new Role("FalseExpressionRole", Expression.Null); - - public VBTokenNode IfToken { - get { return GetChildByRole (Roles.Keyword); } - } - - public Expression ConditionExpression { - get { return GetChildByRole (ConditionExpressionRole); } - set { SetChildByRole (ConditionExpressionRole, value); } - } - - public Expression TrueExpression { - get { return GetChildByRole (TrueExpressionRole); } - set { SetChildByRole (TrueExpressionRole, value); } - } - - public Expression FalseExpression { - get { return GetChildByRole (FalseExpressionRole); } - set { SetChildByRole (FalseExpressionRole, value); } - } - - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) - { - throw new NotImplementedException(); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitConditionalExpression(this, data); - } - } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs new file mode 100644 index 0000000000..7a005a4fdb --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs @@ -0,0 +1,49 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// [ Key ] .Identifier = Expression + /// + public class FieldInitializerExpression : Expression + { + public bool IsKey { get; set; } + + public VBTokenNode KeyToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public VBTokenNode DotToken { + get { return GetChildByRole (Roles.Dot); } + } + + public Identifier Identifier { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public VBTokenNode AssignToken { + get { return GetChildByRole (Roles.Assign); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitFieldInitializerExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + FieldInitializerExpression o = other as FieldInitializerExpression; + return o != null && this.IsKey == o.IsKey && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs new file mode 100644 index 0000000000..e0eec7b052 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs @@ -0,0 +1,52 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Target(Arguments) + /// + public class InvocationExpression : Expression + { + public Expression Target { + get { return GetChildByRole (Roles.TargetExpression); } + set { SetChildByRole(Roles.TargetExpression, value); } + } + + public AstNodeCollection Arguments { + get { return GetChildrenByRole(Roles.Argument); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitInvocationExpression(this, data); + } + + public InvocationExpression () + { + } + + public InvocationExpression (Expression target, IEnumerable arguments) + { + AddChild (target, Roles.TargetExpression); + if (arguments != null) { + foreach (var arg in arguments) { + AddChild (arg, Roles.Argument); + } + } + } + + public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable)arguments) + { + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + InvocationExpression o = other as InvocationExpression; + return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs new file mode 100644 index 0000000000..25090d7ad4 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs @@ -0,0 +1,124 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public abstract class LambdaExpression : Expression + { + public static readonly Role ModifierRole = AttributedNode.ModifierRole; + + public LambdaExpressionModifiers Modifiers { + get { return GetModifiers(this); } + set { SetModifiers(this, value); } + } + + public AstNodeCollection ModifierTokens { + get { return GetChildrenByRole (ModifierRole); } + } + + internal static LambdaExpressionModifiers GetModifiers(AstNode node) + { + LambdaExpressionModifiers m = 0; + foreach (VBModifierToken t in node.GetChildrenByRole (ModifierRole)) { + m |= (LambdaExpressionModifiers)t.Modifier; + } + return m; + } + + internal static void SetModifiers(AstNode node, LambdaExpressionModifiers newValue) + { + LambdaExpressionModifiers oldValue = GetModifiers(node); + AstNode insertionPos = null; + foreach (Modifiers m in VBModifierToken.AllModifiers) { + if ((m & (Modifiers)newValue) != 0) { + if ((m & (Modifiers)oldValue) == 0) { + // Modifier was added + var newToken = new VBModifierToken(AstLocation.Empty, m); + node.InsertChildAfter(insertionPos, newToken, ModifierRole); + insertionPos = newToken; + } else { + // Modifier already exists + insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m); + } + } else { + if ((m & (Modifiers)oldValue) != 0) { + // Modifier was removed + node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove(); + } + } + } + } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + } + + public class SingleLineSubLambdaExpression : LambdaExpression + { + public static readonly Role StatementRole = BlockStatement.StatementRole; + + public Statement EmbeddedStatement { + get { return GetChildByRole(StatementRole); } + set { SetChildByRole(StatementRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitSingleLineSubLambdaExpression(this, data); + } + } + + public class SingleLineFunctionLambdaExpression : LambdaExpression + { + public Expression EmbeddedExpression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitSingleLineFunctionLambdaExpression(this, data); + } + } + + public class MultiLineLambdaExpression : LambdaExpression + { + public bool IsSub { get; set; } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitMultiLineLambdaExpression(this, data); + } + } + + public enum LambdaExpressionModifiers + { + Async = Modifiers.Async, + Iterator = Modifiers.Iterator + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs new file mode 100644 index 0000000000..be4c3249da --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs @@ -0,0 +1,39 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Represents a named argument passed to a method or attribute. + /// + public class NamedArgumentExpression : Expression + { + public Identifier Identifier { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public VBTokenNode AssignToken { + get { return GetChildByRole (Roles.Assign); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitNamedArgumentExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + NamedArgumentExpression o = other as NamedArgumentExpression; + return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs new file mode 100644 index 0000000000..43c7881c86 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs @@ -0,0 +1,80 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Operator Expression + /// + public class UnaryOperatorExpression : Expression + { + public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; + + public UnaryOperatorExpression() + { + } + + public UnaryOperatorExpression(UnaryOperatorType op, Expression expression) + { + this.Operator = op; + this.Expression = expression; + } + + public UnaryOperatorType Operator { + get; + set; + } + + public VBTokenNode OperatorToken { + get { return GetChildByRole (OperatorRole); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitUnaryOperatorExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + UnaryOperatorExpression o = other as UnaryOperatorExpression; + return o != null && this.Operator == o.Operator && this.Expression.DoMatch(o.Expression, match); + } + + public static string GetOperatorSymbol(UnaryOperatorType op) + { + switch (op) { + case UnaryOperatorType.Not: + return "Not"; + case UnaryOperatorType.Minus: + return "-"; + case UnaryOperatorType.Plus: + return "+"; + default: + throw new NotSupportedException("Invalid value for UnaryOperatorType"); + } + } + } + + public enum UnaryOperatorType + { + /// Logical/Bitwise not (Not a) + Not, + /// Unary minus (-a) + Minus, + /// Unary plus (+a) + Plus, + /// AddressOf + AddressOf, + /// Await + Await + } + +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs new file mode 100644 index 0000000000..49acf4a3cd --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs @@ -0,0 +1,44 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Identifier As Type = Expression + /// + public class VariableInitializer : AstNode + { + public VariableIdentifier Identifier { + get { return GetChildByRole(VariableIdentifier.VariableIdentifierRole); } + set { SetChildByRole(VariableIdentifier.VariableIdentifierRole, value); } + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public VBTokenNode AssignToken { + get { return GetChildByRole (Roles.Assign); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitVariableInitializer(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + VariableInitializer o = other as VariableInitializer; + return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 875ff210a5..aa830d455d 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -52,7 +52,6 @@ namespace ICSharpCode.NRefactory.VB { S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); S VisitInstanceExpression(InstanceExpression instanceExpression, T data); S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data); - S VisitAddressOfExpression(AddressOfExpression addressOfExpression, T data); S VisitGetTypeExpression(GetTypeExpression getTypeExpression, T data); S VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, T data); S VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, T data); @@ -104,5 +103,9 @@ namespace ICSharpCode.NRefactory.VB { S VisitSimpleType(SimpleType simpleType, T data); S VisitGoToStatement(GoToStatement goToStatement, T data); + + S VisitSingleLineSubLambdaExpression(SingleLineSubLambdaExpression singleLineSubLambdaExpression, T data); + S VisitMultiLineLambdaExpression(MultiLineLambdaExpression multiLineLambdaExpression, T data); + S VisitSingleLineFunctionLambdaExpression(SingleLineFunctionLambdaExpression singleLineFunctionLambdaExpression, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 0cccd7a54d..d297fb2e0f 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -48,22 +48,30 @@ - + + + + + + + + + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 3de803f957..c3ad147afb 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -407,17 +407,6 @@ namespace ICSharpCode.NRefactory.VB return EndNode(parenthesizedExpression); } - public object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) - { - StartNode(addressOfExpression); - - WriteKeyword("AddressOf"); - addressOfExpression.Expression.AcceptVisitor(this, data); - - return EndNode(addressOfExpression); - } - - public object VisitGetTypeExpression(GetTypeExpression getTypeExpression, object data) { StartNode(getTypeExpression); @@ -1455,6 +1444,7 @@ namespace ICSharpCode.NRefactory.VB StartNode(ifElseStatement); WriteKeyword("If"); ifElseStatement.Condition.AcceptVisitor(this, data); + Space(); WriteKeyword("Then"); NewLine(); Indent(); @@ -1810,6 +1800,12 @@ namespace ICSharpCode.NRefactory.VB case UnaryOperatorType.Plus: WriteToken("+", UnaryOperatorExpression.OperatorRole); break; + case UnaryOperatorType.AddressOf: + WriteKeyword("AddressOf"); + break; + case UnaryOperatorType.Await: + WriteKeyword("Await"); + break; default: throw new Exception("Invalid value for UnaryOperatorType"); } @@ -2262,5 +2258,55 @@ namespace ICSharpCode.NRefactory.VB return EndNode(goToStatement); } + + public object VisitSingleLineSubLambdaExpression(SingleLineSubLambdaExpression singleLineSubLambdaExpression, object data) + { + StartNode(singleLineSubLambdaExpression); + + WriteModifiers(singleLineSubLambdaExpression.ModifierTokens); + WriteKeyword("Sub"); + WriteCommaSeparatedListInParenthesis(singleLineSubLambdaExpression.Parameters, false); + Space(); + singleLineSubLambdaExpression.EmbeddedStatement.AcceptVisitor(this, data); + + return EndNode(singleLineSubLambdaExpression); + } + + public object VisitSingleLineFunctionLambdaExpression(SingleLineFunctionLambdaExpression singleLineFunctionLambdaExpression, object data) + { + StartNode(singleLineFunctionLambdaExpression); + + WriteModifiers(singleLineFunctionLambdaExpression.ModifierTokens); + WriteKeyword("Function"); + WriteCommaSeparatedListInParenthesis(singleLineFunctionLambdaExpression.Parameters, false); + Space(); + singleLineFunctionLambdaExpression.EmbeddedExpression.AcceptVisitor(this, data); + + return EndNode(singleLineFunctionLambdaExpression); + } + + public object VisitMultiLineLambdaExpression(MultiLineLambdaExpression multiLineLambdaExpression, object data) + { + StartNode(multiLineLambdaExpression); + + WriteModifiers(multiLineLambdaExpression.ModifierTokens); + if (multiLineLambdaExpression.IsSub) + WriteKeyword("Sub"); + else + WriteKeyword("Function"); + WriteCommaSeparatedListInParenthesis(multiLineLambdaExpression.Parameters, false); + NewLine(); + Indent(); + multiLineLambdaExpression.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("End"); + if (multiLineLambdaExpression.IsSub) + WriteKeyword("Sub"); + else + WriteKeyword("Function"); + + return EndNode(multiLineLambdaExpression); + } + } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index bfd373a765..95c4db70a6 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -327,7 +327,18 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitLambdaExpression(CSharp.LambdaExpression lambdaExpression, object data) { - throw new NotImplementedException(); + LambdaExpression expr = null; + + if (lambdaExpression.Body is CSharp.Expression) { + var singleLine = new SingleLineFunctionLambdaExpression() { + EmbeddedExpression = (Expression)lambdaExpression.Body.AcceptVisitor(this, data) + }; + ConvertNodes(lambdaExpression.Parameters, singleLine.Parameters); + expr = singleLine; + } else + throw new NotImplementedException(); + + return EndNode(lambdaExpression, expr); } public AstNode VisitMemberReferenceExpression(CSharp.MemberReferenceExpression memberReferenceExpression, object data) @@ -526,8 +537,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.AddressOf: - expr = new AddressOfExpression() { - Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data) + expr = new UnaryOperatorExpression() { + Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data), + Operator = UnaryOperatorType.AddressOf }; break; // case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Dereference: From 2e3d9fa7abedeee3ab33bcd17a705e555dd2a877 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 8 Jul 2011 10:25:59 +0200 Subject: [PATCH 30/57] started implementation of QueryExpression --- .../Ast/Expressions/Expression.cs | 73 +++++++++++++++++++ .../Ast/Expressions/QueryExpression.cs | 68 +++++++++++++++++ .../Ast/TypeName/AstType.cs | 63 ++++++++-------- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 12 ++- .../Visitors/CSharpToVBConverterVisitor.cs | 24 ++++-- 7 files changed, 202 insertions(+), 41 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index 26876e4161..39d3878952 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -30,5 +30,78 @@ namespace ICSharpCode.NRefactory.VB.Ast } } #endregion + + #region Builder methods + /// + /// Builds an member reference expression using this expression as target. + /// + public MemberAccessExpression Member(string memberName) + { + return new MemberAccessExpression { Target = this, Member = memberName }; + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable arguments) + { + return Invoke(methodName, null, arguments); + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(string methodName, params Expression[] arguments) + { + return Invoke(methodName, null, arguments); + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) + { + InvocationExpression ie = new InvocationExpression(); + MemberAccessExpression mre = new MemberAccessExpression(); + mre.Target = this; + mre.Member = methodName; + mre.TypeArguments.AddRange(typeArguments); + ie.Target = mre; + ie.Arguments.AddRange(arguments); + return ie; + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(IEnumerable arguments) + { + InvocationExpression ie = new InvocationExpression(); + ie.Target = this; + ie.Arguments.AddRange(arguments); + return ie; + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(params Expression[] arguments) + { + InvocationExpression ie = new InvocationExpression(); + ie.Target = this; + ie.Arguments.AddRange(arguments); + return ie; + } + + public CastExpression CastTo(AstType type) + { + return new CastExpression { CastType = CastType.CType, Type = type, Expression = this }; + } + + public CastExpression CastTo(Type type) + { + return new CastExpression { CastType = CastType.CType, Type = AstType.Create(type), Expression = this }; + } + #endregion } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs new file mode 100644 index 0000000000..19cf4db4ec --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs @@ -0,0 +1,68 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class QueryExpression : Expression + { + public AstNodeCollection QueryOperators { + get { return GetChildrenByRole(QueryOperator.QueryOperatorRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitQueryExpression(this, data); + } + } + + public abstract class QueryOperator : AstNode + { + #region Null + public new static readonly QueryOperator Null = new NullQueryOperator(); + + sealed class NullQueryOperator : QueryOperator + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + public static readonly Role QueryOperatorRole = new Role("QueryOperator", QueryOperator.Null); + } + + public class FromQueryOperator : QueryOperator + { + + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs index 13ba3ee971..0fe6228a27 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs @@ -70,38 +70,37 @@ namespace ICSharpCode.NRefactory.VB.Ast return new ComposedType { BaseType = this }.MakeArrayType(rank); } - // TODO : reimplement this -// /// -// /// 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); -// } -// -// /// -// /// Builds an invocation expression using this type as target. -// /// -// public InvocationExpression Invoke(string methodName, IEnumerable arguments) -// { -// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); -// } -// -// /// -// /// Builds an invocation expression using this type as target. -// /// -// public InvocationExpression Invoke(string methodName, params Expression[] arguments) -// { -// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); -// } -// -// /// -// /// Builds an invocation expression using this type as target. -// /// -// public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) -// { -// return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments); -// } + /// + /// Builds an expression that can be used to access a static member on this type. + /// + public MemberAccessExpression Member(string memberName) + { + return new TypeReferenceExpression { Type = this }.Member(memberName); + } + + /// + /// Builds an invocation expression using this type as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable arguments) + { + return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); + } + + /// + /// Builds an invocation expression using this type as target. + /// + public InvocationExpression Invoke(string methodName, params Expression[] arguments) + { + return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); + } + + /// + /// Builds an invocation expression using this type as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) + { + return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments); + } public static AstType Create(Type type) { diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index aa830d455d..bf969a8430 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -107,5 +107,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitSingleLineSubLambdaExpression(SingleLineSubLambdaExpression singleLineSubLambdaExpression, T data); S VisitMultiLineLambdaExpression(MultiLineLambdaExpression multiLineLambdaExpression, T data); S VisitSingleLineFunctionLambdaExpression(SingleLineFunctionLambdaExpression singleLineFunctionLambdaExpression, T data); + + S VisitQueryExpression(QueryExpression queryExpression, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index d297fb2e0f..2f3ab9777e 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -66,6 +66,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index c3ad147afb..ea01b11265 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2307,6 +2307,16 @@ namespace ICSharpCode.NRefactory.VB return EndNode(multiLineLambdaExpression); } - + + public object VisitQueryExpression(QueryExpression queryExpression, object data) + { + StartNode(queryExpression); + + foreach (var op in queryExpression.QueryOperators) { + op.AcceptVisitor(this, data); + } + + return EndNode(queryExpression); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 95c4db70a6..3b0d7a1abd 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -469,13 +469,19 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitStackAllocExpression(CSharp.StackAllocExpression stackAllocExpression, object data) { - throw new NotImplementedException(); + return EndNode( + stackAllocExpression, + new InvocationExpression( + new IdentifierExpression() { Identifier = "__StackĄlloc" }, + new TypeReferenceExpression((AstType)stackAllocExpression.Type.AcceptVisitor(this, data)), + (Expression)stackAllocExpression.CountExpression.AcceptVisitor(this, data) + ) + ); } public AstNode VisitThisReferenceExpression(CSharp.ThisReferenceExpression thisReferenceExpression, object data) { - InstanceExpression result = new InstanceExpression(InstanceExpressionType.Me, ConvertLocation(thisReferenceExpression.StartLocation)); - + InstanceExpression result = new InstanceExpression(InstanceExpressionType.Me, ConvertLocation(thisReferenceExpression.StartLocation); return EndNode(thisReferenceExpression, result); } @@ -518,22 +524,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Increment: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "Increment" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__Increment" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.PostIncrement: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "PostIncrement" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__PostIncrement" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Decrement: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "Decrement" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__Decrement" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.PostDecrement: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "PostDecrement" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__PostDecrement" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.AddressOf: @@ -562,7 +568,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitQueryExpression(CSharp.QueryExpression queryExpression, object data) { - throw new NotImplementedException(); + var expr = new QueryExpression(); + ConvertNodes(queryExpression.Clauses, expr.QueryOperators); + return EndNode(queryExpression, expr); } public AstNode VisitQueryContinuationClause(CSharp.QueryContinuationClause queryContinuationClause, object data) From 95db1ebd710ee59650a865bf66151da386ae3191 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 12 Jul 2011 08:42:40 +0200 Subject: [PATCH 31/57] added conversion to VB ForStatement --- .../OutputVisitor/OutputVisitor.cs | 3 +- .../Visitors/CSharpToVBConverterVisitor.cs | 103 +++++++++++++++++- 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index ea01b11265..394aa98bc3 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -579,7 +579,7 @@ namespace ICSharpCode.NRefactory.VB StartNode(arraySpecifier); LPar(); - for (int i = 0; i < arraySpecifier.Dimensions; i++) { + for (int i = 0; i < arraySpecifier.Dimensions - 1; i++) { WriteToken(",", ArraySpecifier.Roles.Comma); } RPar(); @@ -1929,6 +1929,7 @@ namespace ICSharpCode.NRefactory.VB forStatement.ToExpression.AcceptVisitor(this, data); if (!forStatement.StepExpression.IsNull) { WriteKeyword("Step"); + Space(); forStatement.StepExpression.AcceptVisitor(this, data); } NewLine(); diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 3b0d7a1abd..1a9210e31b 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Security.Cryptography.X509Certificates; +using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.VB.Ast; @@ -481,7 +482,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitThisReferenceExpression(CSharp.ThisReferenceExpression thisReferenceExpression, object data) { - InstanceExpression result = new InstanceExpression(InstanceExpressionType.Me, ConvertLocation(thisReferenceExpression.StartLocation); + InstanceExpression result = new InstanceExpression(InstanceExpressionType.Me, ConvertLocation(thisReferenceExpression.StartLocation)); return EndNode(thisReferenceExpression, result); } @@ -802,6 +803,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitCheckedStatement(CSharp.CheckedStatement checkedStatement, object data) { + // overflow/underflow checks are default on in VB throw new NotImplementedException(); } @@ -858,6 +860,105 @@ namespace ICSharpCode.NRefactory.VB.Visitors if (!forStatement.Initializers.Any() && forStatement.Condition.IsNull && !forStatement.Iterators.Any()) return EndNode(forStatement, new WhileStatement() { Condition = new PrimitiveExpression(true), Body = (BlockStatement)forStatement.EmbeddedStatement.AcceptVisitor(this, data) }); + CSharp.AstNode counterLoop = new CSharp.ForStatement() { + Initializers = { + new NamedNode( + "iteratorVar", + new Choice { + new CSharp.VariableDeclarationStatement { + Type = new Choice { + new CSharp.PrimitiveType("long"), + new CSharp.PrimitiveType("ulong"), + new CSharp.PrimitiveType("int"), + new CSharp.PrimitiveType("uint"), + new CSharp.PrimitiveType("short"), + new CSharp.PrimitiveType("ushort"), + new CSharp.PrimitiveType("sbyte"), + new CSharp.PrimitiveType("byte") + }, + Variables = { + new AnyNode() + } + }, + new CSharp.ExpressionStatement( + new CSharp.AssignmentExpression() + ) + }) + }, + Condition = new NamedNode( + "condition", + new CSharp.BinaryOperatorExpression { + Left = new NamedNode("ident", new CSharp.IdentifierExpression()), + Operator = CSharp.BinaryOperatorType.Any, + Right = new AnyNode("endExpr") + }), + Iterators = { + new CSharp.ExpressionStatement( + new NamedNode( + "increment", + new CSharp.AssignmentExpression { + Left = new Backreference("ident"), + Operator = CSharp.AssignmentOperatorType.Any, + Right = new NamedNode("factor", new AnyNode()) + } + ) + ) + }, + EmbeddedStatement = new NamedNode("body", new AnyNode()) + }; + + var match = counterLoop.Match(forStatement); + + if (match.Success) { + var init = match.Get("iteratorVar").SingleOrDefault(); + + AstNode iteratorVariable; + + if (init is CSharp.VariableDeclarationStatement) { + var var = ((CSharp.VariableDeclarationStatement)init).Variables.First(); + iteratorVariable = new VariableInitializer() { + Identifier = new VariableIdentifier { Name = var.Name }, + Type = (AstType)((CSharp.VariableDeclarationStatement)init).Type.AcceptVisitor(this, data), + Expression = (Expression)var.Initializer.AcceptVisitor(this, data) + }; + } else if (init is CSharp.ExpressionStatement) { + iteratorVariable = init.AcceptVisitor(this, data); + } else goto end; + + Expression toExpr = Expression.Null; + + var cond = match.Get("condition").SingleOrDefault(); + var endExpr = (Expression)match.Get("endExpr").SingleOrDefault().AcceptVisitor(this, data); + + if (cond.Operator == CSharp.BinaryOperatorType.LessThanOrEqual || + cond.Operator == CSharp.BinaryOperatorType.GreaterThanOrEqual) { + toExpr = endExpr; + } + + if (cond.Operator == CSharp.BinaryOperatorType.LessThan) + toExpr = new BinaryOperatorExpression(endExpr, BinaryOperatorType.Subtract, new PrimitiveExpression(1)); + if (cond.Operator == CSharp.BinaryOperatorType.GreaterThan) + toExpr = new BinaryOperatorExpression(endExpr, BinaryOperatorType.Add, new PrimitiveExpression(1)); + + Expression stepExpr = Expression.Null; + + var increment = match.Get("increment").SingleOrDefault(); + var factorExpr = (Expression)match.Get("factor").SingleOrDefault().AcceptVisitor(this, data); + + if (increment.Operator == CSharp.AssignmentOperatorType.Add && (factorExpr is PrimitiveExpression && (int)((PrimitiveExpression)factorExpr).Value != 1)) + stepExpr = factorExpr; + if (increment.Operator == CSharp.AssignmentOperatorType.Subtract) + stepExpr = new UnaryOperatorExpression(UnaryOperatorType.Minus, factorExpr); + + return new ForStatement() { + Variable = iteratorVariable, + ToExpression = toExpr, + StepExpression = stepExpr, + Body = (BlockStatement)match.Get("body").Single().AcceptVisitor(this, data) + }; + } + + end: var stmt = new WhileStatement() { Condition = (Expression)forStatement.Condition.AcceptVisitor(this, data), Body = (BlockStatement)forStatement.EmbeddedStatement.AcceptVisitor(this, data) From eab1ac6611d8f2bcf490f205bcf5d7e9e1a705e4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 12 Jul 2011 09:02:21 +0200 Subject: [PATCH 32/57] add ContinueStatement --- .../Ast/Statements/ContinueStatement.cs | 50 +++++++++++++++++++ .../Ast/Statements/ExitStatement.cs | 2 +- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 1 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 23 +++++++++ .../Visitors/CSharpToVBConverterVisitor.cs | 21 +++++++- 6 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/ContinueStatement.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ContinueStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ContinueStatement.cs new file mode 100644 index 0000000000..4ec41f6284 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ContinueStatement.cs @@ -0,0 +1,50 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Continue ( Do | For | While ) + /// + public class ContinueStatement : Statement + { + public static readonly Role ContinueKindTokenRole = new Role("ContinueKindToken"); + + public ContinueKind ContinueKind { get; set; } + + public VBTokenNode ContinueToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public VBTokenNode ContinueKindToken { + get { return GetChildByRole (ContinueKindTokenRole); } + } + + public ContinueStatement(ContinueKind kind) + { + this.ContinueKind = kind; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitContinueStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ContinueStatement o = other as ContinueStatement; + return o != null && this.ContinueKind == o.ContinueKind; + } + } + + public enum ContinueKind + { + None, + Do, + For, + While + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs index 5868523259..b5f7c0ff3c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ExitStatement.cs @@ -11,7 +11,7 @@ namespace ICSharpCode.NRefactory.VB.Ast ///
public class ExitStatement : Statement { - public static readonly Role ExitKindTokenRole = new Role("ExitKindTokenRole"); + public static readonly Role ExitKindTokenRole = new Role("ExitKindToken"); public ExitKind ExitKind { get; set; } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index bf969a8430..c1f18edfbc 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -85,6 +85,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitForStatement(ForStatement forStatement, T data); S VisitForEachStatement(ForEachStatement forEachStatement, T data); S VisitExitStatement(ExitStatement exitStatement, T data); + S VisitContinueStatement(ContinueStatement continueStatement, T data); S VisitSelectStatement(SelectStatement selectStatement, T data); S VisitYieldStatement(YieldStatement yieldStatement, T data); S VisitVariableInitializer(VariableInitializer variableInitializer, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 2f3ab9777e..ef2ae0cb01 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -95,6 +95,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 394aa98bc3..f48f8e2f07 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2319,5 +2319,28 @@ namespace ICSharpCode.NRefactory.VB return EndNode(queryExpression); } + + public object VisitContinueStatement(ContinueStatement continueStatement, object data) + { + StartNode(continueStatement); + + WriteKeyword("Continue"); + + switch (continueStatement.ContinueKind) { + case ContinueKind.Do: + WriteKeyword("Do"); + break; + case ContinueKind.For: + WriteKeyword("For"); + break; + case ContinueKind.While: + WriteKeyword("While"); + break; + default: + throw new Exception("Invalid value for ContinueKind"); + } + + return EndNode(continueStatement); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 1a9210e31b..381d2f720d 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -803,13 +803,30 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitCheckedStatement(CSharp.CheckedStatement checkedStatement, object data) { - // overflow/underflow checks are default on in VB + // overflow/underflow checks are on by default in VB throw new NotImplementedException(); } public AstNode VisitContinueStatement(CSharp.ContinueStatement continueStatement, object data) { - throw new NotImplementedException(); + var @continue = new ContinueStatement(ContinueKind.None); + + foreach (var stmt in continueStatement.Ancestors) { + if (stmt is CSharp.DoWhileStatement) { + @continue.ContinueKind = ContinueKind.Do; + break; + } + if (stmt is CSharp.ForStatement || stmt is CSharp.ForeachStatement) { + @continue.ContinueKind = ContinueKind.For; + break; + } + if (stmt is CSharp.WhileStatement) { + @continue.ContinueKind = ContinueKind.While; + break; + } + } + + return EndNode(continueStatement, @continue); } public AstNode VisitDoWhileStatement(CSharp.DoWhileStatement doWhileStatement, object data) From da4b1bab67dfa4676372dd54510843e7912aed32 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 12 Jul 2011 11:50:32 +0200 Subject: [PATCH 33/57] improve conversion of event declarations --- .../OutputVisitor/OutputVisitor.cs | 2 +- .../Visitors/CSharpToVBConverterVisitor.cs | 68 +++++++++++++++---- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index f48f8e2f07..2c53696bab 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1766,7 +1766,7 @@ namespace ICSharpCode.NRefactory.VB Space(); WriteKeyword("As"); eventDeclaration.ReturnType.AcceptVisitor(this, data); - } + } WriteImplementsClause(eventDeclaration.ImplementsClause); if (eventDeclaration.IsCustom) { diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 381d2f720d..773a850e2d 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Security.Cryptography.X509Certificates; using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.VB.Ast; @@ -27,13 +26,20 @@ namespace ICSharpCode.NRefactory.VB.Visitors { IEnvironmentProvider provider; Stack blocks; - // TODO this should belong to the current type member or lambda - bool inIterator; + Stack types; + Stack members; + + class MemberInfo + { + public bool inIterator; + } public CSharpToVBConverterVisitor(IEnvironmentProvider provider) { this.provider = provider; this.blocks = new Stack(); + this.types = new Stack(); + this.members = new Stack(); } public AstNode VisitAnonymousMethodExpression(CSharp.AnonymousMethodExpression anonymousMethodExpression, object data) @@ -716,7 +722,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors type.Name = new Identifier(typeDeclaration.Name, AstLocation.Empty); + types.Push(type); ConvertNodes(typeDeclaration.Members, type.Members); + types.Pop(); return EndNode(typeDeclaration, type); } @@ -1131,13 +1139,15 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitYieldBreakStatement(CSharp.YieldBreakStatement yieldBreakStatement, object data) { - inIterator = true; + var frame = members.Peek(); + frame.inIterator = true; return EndNode(yieldBreakStatement, new ReturnStatement()); } public AstNode VisitYieldStatement(CSharp.YieldStatement yieldStatement, object data) { - inIterator = true; + var frame = members.Peek(); + frame.inIterator = true; return EndNode(yieldStatement, new YieldStatement((Expression)yieldStatement.Expression.AcceptVisitor(this, data))); } @@ -1197,19 +1207,30 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitEventDeclaration(CSharp.EventDeclaration eventDeclaration, object data) { - var result = new EventDeclaration(); - // TODO event declaration + members.Push(new MemberInfo()); + + foreach (var evt in eventDeclaration.Variables) { + var result = new EventDeclaration(); + + ConvertNodes(eventDeclaration.Attributes, result.Attributes); + result.Modifiers = ConvertModifiers(eventDeclaration.Modifiers, eventDeclaration); + result.Name = evt.Name; + result.ReturnType = (AstType)eventDeclaration.ReturnType.AcceptVisitor(this, data); + + types.Peek().Members.Add(result); + } -// ConvertNodes(eventDeclaration.Attributes, result.Attributes); -// result.Modifiers = ConvertModifiers(eventDeclaration.Modifiers, eventDeclaration); -// result.Name = new Identifier(eventDeclaration., AstLocation.Empty); + members.Pop(); - return EndNode(eventDeclaration, result); + return EndNode(eventDeclaration, null); } public AstNode VisitCustomEventDeclaration(CSharp.CustomEventDeclaration customEventDeclaration, object data) { var result = new EventDeclaration(); + + members.Push(new MemberInfo()); + ConvertNodes(customEventDeclaration.Attributes, result.Attributes); result.Modifiers = ConvertModifiers(customEventDeclaration.Modifiers, customEventDeclaration); result.IsCustom = true; @@ -1222,6 +1243,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors result.AddHandlerBlock = (Accessor)customEventDeclaration.AddAccessor.AcceptVisitor(this, data); result.RemoveHandlerBlock = (Accessor)customEventDeclaration.RemoveAccessor.AcceptVisitor(this, data); + members.Pop(); + return EndNode(customEventDeclaration, result); } @@ -1229,10 +1252,14 @@ namespace ICSharpCode.NRefactory.VB.Visitors { var decl = new FieldDeclaration(); + members.Push(new MemberInfo()); + ConvertNodes(fieldDeclaration.Attributes, decl.Attributes); decl.Modifiers = ConvertModifiers(fieldDeclaration.Modifiers, fieldDeclaration); ConvertNodes(fieldDeclaration.Variables, decl.Variables); + members.Pop(); + return EndNode(fieldDeclaration, decl); } @@ -1240,6 +1267,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors { var decl = new PropertyDeclaration(); + members.Push(new MemberInfo()); + ConvertNodes(indexerDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), decl.Attributes); decl.Getter = (Accessor)indexerDeclaration.Getter.AcceptVisitor(this, data); decl.Modifiers = ConvertModifiers(indexerDeclaration.Modifiers, indexerDeclaration); @@ -1260,6 +1289,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors }); } + members.Pop(); + return EndNode(indexerDeclaration, decl); } @@ -1267,6 +1298,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors { var result = new MethodDeclaration(); + members.Push(new MemberInfo()); + ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); ConvertNodes(methodDeclaration.ModifierTokens, result.ModifierTokens); result.Name = new Identifier(methodDeclaration.Name, AstLocation.Empty); @@ -1282,9 +1315,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); - if (inIterator) { + if (members.Pop().inIterator) { result.Modifiers |= Modifiers.Iterator; - inIterator = false; } return EndNode(methodDeclaration, result); @@ -1299,6 +1331,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitOperatorDeclaration(CSharp.OperatorDeclaration operatorDeclaration, object data) { var result = new OperatorDeclaration(); + + members.Push(new MemberInfo()); + ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); ConvertNodes(operatorDeclaration.ModifierTokens, result.ModifierTokens); switch (operatorDeclaration.OperatorType) { @@ -1381,6 +1416,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors result.ReturnType = (AstType)operatorDeclaration.ReturnType.AcceptVisitor(this, data); result.Body = (BlockStatement)operatorDeclaration.Body.AcceptVisitor(this, data); + members.Pop(); + return EndNode(operatorDeclaration, result); } @@ -1427,6 +1464,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors { var decl = new PropertyDeclaration(); + members.Push(new MemberInfo()); + ConvertNodes(propertyDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), decl.Attributes); decl.Getter = (Accessor)propertyDeclaration.Getter.AcceptVisitor(this, data); decl.Modifiers = ConvertModifiers(propertyDeclaration.Modifiers, propertyDeclaration); @@ -1446,9 +1485,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors }); } - if (inIterator) { + if (members.Pop().inIterator) { decl.Modifiers |= Modifiers.Iterator; - inIterator = false; } return EndNode(propertyDeclaration, decl); From 263971193ecfbdf4652b035cd6a0208bfe53daa4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 12 Jul 2011 12:01:20 +0200 Subject: [PATCH 34/57] convert dtor to Finalize Sub --- .../Visitors/CSharpToVBConverterVisitor.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 773a850e2d..55e88df1f2 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -1191,7 +1191,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitDestructorDeclaration(CSharp.DestructorDeclaration destructorDeclaration, object data) { - throw new NotImplementedException(); + var finalizer = new MethodDeclaration() { Name = "Finalize", IsSub = true }; + + ConvertNodes(destructorDeclaration.Attributes, finalizer.Attributes); + ConvertNodes(destructorDeclaration.ModifierTokens, finalizer.ModifierTokens); + finalizer.Body = (BlockStatement)destructorDeclaration.Body.AcceptVisitor(this, data); + + return EndNode(destructorDeclaration, finalizer); } public AstNode VisitEnumMemberDeclaration(CSharp.EnumMemberDeclaration enumMemberDeclaration, object data) From 354aefa430dab2cf7766c5f74413abdff3435f81 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 13 Jul 2011 11:55:13 +0200 Subject: [PATCH 35/57] add conversion of DllImports to ExternalMethodDeclarations --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 12 -- .../Ast/Expressions/PrimitiveExpression.cs | 2 +- .../TypeMembers/ExternalMethodDeclaration.cs | 71 ++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 3 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 64 ++++++++- .../Visitors/CSharpToVBConverterVisitor.cs | 123 +++++++++++++++--- 7 files changed, 241 insertions(+), 35 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index c7f6dc08e1..dce53fb2d1 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -115,18 +115,6 @@ namespace ICSharpCode.NRefactory.VB.Ast Explicit } - /// - /// Charset types, used in external methods - /// declarations (VB only). - /// - public enum CharsetModifier - { - None, - Auto, - Unicode, - Ansi - } - /// /// Specifies the ordering direction of a QueryExpressionOrdering node. /// diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs index c01adaf8ad..08e469b1a8 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.NRefactory.VB.Ast string stringValue; public string StringValue { - get { return stringValue; } // TODO ?? VBNetOutputVisitor.ToVBNetString(this); } + get { return stringValue ?? OutputVisitor.ToVBNetString(this); } } public PrimitiveExpression(object value) diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs new file mode 100644 index 0000000000..a706ceaaa8 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs @@ -0,0 +1,71 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Runtime.InteropServices; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class ExternalMethodDeclaration : MemberDeclaration + { + public ExternalMethodDeclaration() + { + } + + public CharsetModifier CharsetModifier { get; set; } + + public bool IsSub { get; set; } + + public Identifier Name { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public string Library { get; set; } + + public string Alias { get; set; } + + public AstNodeCollection Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + + public AstNodeCollection ReturnTypeAttributes { + get { return GetChildrenByRole(AttributeBlock.ReturnTypeAttributeBlockRole); } + } + + public AstType ReturnType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + // TODO : finish + var method = other as ExternalMethodDeclaration; + return method != null && + MatchAttributesAndModifiers(method, match) && + IsSub == method.IsSub && + Name.DoMatch(method.Name, match) && + Parameters.DoMatch(method.Parameters, match) && + ReturnTypeAttributes.DoMatch(method.ReturnTypeAttributes, match) && + ReturnType.DoMatch(method.ReturnType, match); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitExternalMethodDeclaration(this, data); + } + } + + /// + /// Charset types, used in external methods + /// declarations (VB only). + /// + public enum CharsetModifier + { + None, + Auto, + Unicode, + Ansi + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index c1f18edfbc..2386e7cf36 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.VB { // TypeMember scope S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data); S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data); + S VisitExternalMethodDeclaration(ExternalMethodDeclaration externalMethodDeclaration, T data); S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data); S VisitVariableDeclaratorWithTypeAndInitializer(VariableDeclaratorWithTypeAndInitializer variableDeclaratorWithTypeAndInitializer, T data); S VisitVariableDeclaratorWithObjectCreation(VariableDeclaratorWithObjectCreation variableDeclaratorWithObjectCreation, T data); @@ -110,5 +111,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitSingleLineFunctionLambdaExpression(SingleLineFunctionLambdaExpression singleLineFunctionLambdaExpression, T data); S VisitQueryExpression(QueryExpression queryExpression, T data); + + } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index ef2ae0cb01..9d611da297 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -118,6 +118,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 2c53696bab..b83854e871 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -113,6 +113,7 @@ namespace ICSharpCode.NRefactory.VB public object VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, object data) { StartNode(parameterDeclaration); + WriteAttributes(parameterDeclaration.Attributes); WriteModifiers(parameterDeclaration.ModifierTokens); WriteIdentifier(parameterDeclaration.Name.Name); if (!parameterDeclaration.Type.IsNull) { @@ -164,7 +165,10 @@ namespace ICSharpCode.NRefactory.VB WriteToken("<", AttributeBlock.Roles.LChevron); WriteCommaSeparatedList(attributeBlock.Attributes); WriteToken(">", AttributeBlock.Roles.RChevron); - NewLine(); + if (attributeBlock.Parent is ParameterDeclaration) + Space(); + else + NewLine(); return EndNode(attributeBlock); } @@ -1766,7 +1770,7 @@ namespace ICSharpCode.NRefactory.VB Space(); WriteKeyword("As"); eventDeclaration.ReturnType.AcceptVisitor(this, data); - } + } WriteImplementsClause(eventDeclaration.ImplementsClause); if (eventDeclaration.IsCustom) { @@ -2342,5 +2346,61 @@ namespace ICSharpCode.NRefactory.VB return EndNode(continueStatement); } + + public object VisitExternalMethodDeclaration(ExternalMethodDeclaration externalMethodDeclaration, object data) + { + StartNode(externalMethodDeclaration); + + WriteAttributes(externalMethodDeclaration.Attributes); + WriteModifiers(externalMethodDeclaration.ModifierTokens); + WriteKeyword("Declare"); + switch (externalMethodDeclaration.CharsetModifier) { + case CharsetModifier.None: + break; + case CharsetModifier.Auto: + WriteKeyword("Auto"); + break; + case CharsetModifier.Unicode: + WriteKeyword("Unicode"); + break; + case CharsetModifier.Ansi: + WriteKeyword("Ansi"); + break; + default: + throw new Exception("Invalid value for CharsetModifier"); + } + if (externalMethodDeclaration.IsSub) + WriteKeyword("Sub"); + else + WriteKeyword("Function"); + externalMethodDeclaration.Name.AcceptVisitor(this, data); + WriteKeyword("Lib"); + Space(); + WritePrimitiveValue(externalMethodDeclaration.Library); + Space(); + if (externalMethodDeclaration.Alias != null) { + WriteKeyword("Alias"); + Space(); + WritePrimitiveValue(externalMethodDeclaration.Alias); + Space(); + } + WriteCommaSeparatedListInParenthesis(externalMethodDeclaration.Parameters, false); + if (!externalMethodDeclaration.IsSub && !externalMethodDeclaration.ReturnType.IsNull) { + Space(); + WriteKeyword("As"); + WriteAttributes(externalMethodDeclaration.ReturnTypeAttributes); + externalMethodDeclaration.ReturnType.AcceptVisitor(this, data); + } + NewLine(); + + return EndNode(externalMethodDeclaration); + } + + public static string ToVBNetString(PrimitiveExpression primitiveExpression) + { + var writer = new StringWriter(); + new OutputVisitor(writer, new VBFormattingOptions()).WritePrimitiveValue(primitiveExpression.Value); + return writer.ToString(); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 55e88df1f2..3a24804e44 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; + using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.VB.Ast; @@ -1302,30 +1302,113 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitMethodDeclaration(CSharp.MethodDeclaration methodDeclaration, object data) { - var result = new MethodDeclaration(); + CSharp.Attribute attr; + if ((methodDeclaration.Modifiers & CSharp.Modifiers.Extern) == CSharp.Modifiers.Extern && HasAttribute(methodDeclaration.Attributes, "System.Runtime.InteropServices.DllImportAttribute", out attr)) { + var result = new ExternalMethodDeclaration(); + + members.Push(new MemberInfo()); + + // remove AttributeSection if only one attribute is present + var attrSec = (CSharp.AttributeSection)attr.Parent; + if (attrSec.Attributes.Count == 1) + attrSec.Remove(); + else + attr.Remove(); + + result.Library = (attr.Arguments.First().AcceptVisitor(this, data) as PrimitiveExpression).Value.ToString(); + result.CharsetModifier = ConvertCharset(attr.Arguments); + result.Alias = ConvertAlias(attr.Arguments); + + ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); + ConvertNodes(methodDeclaration.ModifierTokens, result.ModifierTokens); + result.Name = new Identifier(methodDeclaration.Name, AstLocation.Empty); + result.IsSub = IsSub(methodDeclaration.ReturnType); + ConvertNodes(methodDeclaration.Parameters, result.Parameters); + ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); + if (!result.IsSub) + result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); + + if (members.Pop().inIterator) { + result.Modifiers |= Modifiers.Iterator; + } + + return EndNode(methodDeclaration, result); + } else { + var result = new MethodDeclaration(); + + members.Push(new MemberInfo()); + + ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); + ConvertNodes(methodDeclaration.ModifierTokens, result.ModifierTokens); + result.Name = new Identifier(methodDeclaration.Name, AstLocation.Empty); + result.IsSub = IsSub(methodDeclaration.ReturnType); + ConvertNodes(methodDeclaration.Parameters, result.Parameters); + ConvertNodes(methodDeclaration.TypeParameters, result.TypeParameters); + ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); + if (!methodDeclaration.PrivateImplementationType.IsNull) + result.ImplementsClause.Add( + new InterfaceMemberSpecifier((AstType)methodDeclaration.PrivateImplementationType.AcceptVisitor(this, data), + methodDeclaration.Name)); + if (!result.IsSub) + result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); + result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); + + if (members.Pop().inIterator) { + result.Modifiers |= Modifiers.Iterator; + } + + return EndNode(methodDeclaration, result); + } + } + + string ConvertAlias(CSharp.AstNodeCollection arguments) + { + var pattern = new CSharp.AssignmentExpression() { + Left = new CSharp.IdentifierExpression("EntryPoint"), + Operator = CSharp.AssignmentOperatorType.Assign, + Right = new AnyNode("alias") + }; - members.Push(new MemberInfo()); + var result = arguments + .Select(expr => pattern.Match(expr)) + .FirstOrDefault(r => r.Success); - ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); - ConvertNodes(methodDeclaration.ModifierTokens, result.ModifierTokens); - result.Name = new Identifier(methodDeclaration.Name, AstLocation.Empty); - result.IsSub = IsSub(methodDeclaration.ReturnType); - ConvertNodes(methodDeclaration.Parameters, result.Parameters); - ConvertNodes(methodDeclaration.TypeParameters, result.TypeParameters); - ConvertNodes(methodDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); - if (!methodDeclaration.PrivateImplementationType.IsNull) - result.ImplementsClause.Add( - new InterfaceMemberSpecifier((AstType)methodDeclaration.PrivateImplementationType.AcceptVisitor(this, data), - methodDeclaration.Name)); - if (!result.IsSub) - result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); - result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); + if (result.Success && result.Has("alias")) { + return result.Get("alias") + .First().Value.ToString(); + } - if (members.Pop().inIterator) { - result.Modifiers |= Modifiers.Iterator; + return null; + } + + CharsetModifier ConvertCharset(CSharp.AstNodeCollection arguments) + { + var pattern = new CSharp.AssignmentExpression() { + Left = new CSharp.IdentifierExpression("CharSet"), + Operator = CSharp.AssignmentOperatorType.Assign, + Right = new NamedNode( + "modifier", + new CSharp.MemberReferenceExpression() { + Target = new CSharp.IdentifierExpression("CharSet") + }) + }; + + var result = arguments + .Select(expr => pattern.Match(expr)) + .FirstOrDefault(r => r.Success); + + if (result.Success && result.Has("modifier")) { + switch (result.Get("modifier").First().MemberName) { + case "Auto": + return CharsetModifier.Auto; + case "Ansi": + return CharsetModifier.Ansi; + case "Unicode": + return CharsetModifier.Unicode; + } } - return EndNode(methodDeclaration, result); + return CharsetModifier.None; } bool IsSub(CSharp.AstType returnType) From 12eb661dcd5730d68d22bd319f2d3a987e029e47 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 13 Jul 2011 12:01:29 +0200 Subject: [PATCH 36/57] convert anonymous methods to multiline sub lambdas --- .../Visitors/CSharpToVBConverterVisitor.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 3a24804e44..6beee618de 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -44,7 +44,20 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAnonymousMethodExpression(CSharp.AnonymousMethodExpression anonymousMethodExpression, object data) { - throw new NotImplementedException(); + members.Push(new MemberInfo()); + + var expr = new MultiLineLambdaExpression() { + IsSub = true, + Body = (BlockStatement)anonymousMethodExpression.Body.AcceptVisitor(this, data) + }; + + ConvertNodes(anonymousMethodExpression.Parameters, expr.Parameters); + + if (members.Pop().inIterator) { + expr.Modifiers |= Modifiers.Iterator; + } + + return EndNode(anonymousMethodExpression, expr); } public AstNode VisitUndocumentedExpression(CSharp.UndocumentedExpression undocumentedExpression, object data) From c431176e5c7fbea6a157b6656a150cdab8427319 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 13 Jul 2011 12:09:44 +0200 Subject: [PATCH 37/57] =?UTF-8?q?convert=20C#=CB=88s=20undocumented=20expr?= =?UTF-8?q?essions=20to=20method=20calls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Visitors/CSharpToVBConverterVisitor.cs | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 6beee618de..a069ecae2e 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(anonymousMethodExpression.Parameters, expr.Parameters); if (members.Pop().inIterator) { - expr.Modifiers |= Modifiers.Iterator; + expr.Modifiers |= LambdaExpressionModifiers.Iterator; } return EndNode(anonymousMethodExpression, expr); @@ -62,10 +62,29 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitUndocumentedExpression(CSharp.UndocumentedExpression undocumentedExpression, object data) { - // 29.06.2011 20:28:36 Siegfried Pammer: wie soll ich die behandeln? - // 29.06.2011 20:28:58 Siegfried Pammer: throw new NotSupportedException(); ? - // 29.06.2011 20:35:50 Daniel Grunwald: da würde ich wieder Pseudo-Funktionen einführen - throw new NotImplementedException(); + var invocation = new InvocationExpression(); + + switch (undocumentedExpression.UndocumentedExpressionType) { + case CSharp.UndocumentedExpressionType.ArgListAccess: + case CSharp.UndocumentedExpressionType.ArgList: + invocation.Target = new IdentifierExpression { Identifier = "__ArgList" }; + break; + case CSharp.UndocumentedExpressionType.RefValue: + invocation.Target = new IdentifierExpression { Identifier = "__RefValue" }; + break; + case CSharp.UndocumentedExpressionType.RefType: + invocation.Target = new IdentifierExpression { Identifier = "__RefType" }; + break; + case CSharp.UndocumentedExpressionType.MakeRef: + invocation.Target = new IdentifierExpression { Identifier = "__MakeRef" }; + break; + default: + throw new Exception("Invalid value for UndocumentedExpressionType"); + } + + ConvertNodes(undocumentedExpression.Arguments, invocation.Arguments); + + return EndNode(undocumentedExpression, invocation); } public AstNode VisitArrayCreateExpression(CSharp.ArrayCreateExpression arrayCreateExpression, object data) @@ -583,6 +602,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitEmptyExpression(CSharp.EmptyExpression emptyExpression, object data) { + // TODO : not used in ILSpy currently throw new NotImplementedException(); } From c007a2a244d674193b5b89e8f8b2afe21765708d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 13 Jul 2011 19:49:34 +0200 Subject: [PATCH 38/57] implemented fixed using GCHandle --- .../Visitors/CSharpToVBConverterVisitor.cs | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index a069ecae2e..faf17feda2 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -894,8 +894,32 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitFixedStatement(CSharp.FixedStatement fixedStatement, object data) { - // see http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.gchandle%28v=VS.100%29.aspx - throw new NotImplementedException(); + var block = blocks.Peek(); + block.AddChild(new Comment(" Emulating fixed-Statement, might not be entirely correct!", false), AstNode.Roles.Comment); + + var variables = new LocalDeclarationStatement(); + variables.Modifiers = Modifiers.Dim; + var stmt = new TryStatement(); + stmt.FinallyBlock = new BlockStatement(); + foreach (var decl in fixedStatement.Variables) { + var v = new VariableDeclaratorWithTypeAndInitializer { + Identifiers = { new VariableIdentifier { Name = decl.Name } }, + Type = new SimpleType("GCHandle"), + Initializer = new InvocationExpression( + new MemberAccessExpression { Target = new IdentifierExpression { Identifier = "GCHandle" }, Member = "Alloc" }, + (Expression)decl.Initializer.AcceptVisitor(this, data), + new MemberAccessExpression { Target = new IdentifierExpression { Identifier = "GCHandleType" }, Member = "Pinned" } + ) + }; + variables.Variables.Add(v); + stmt.FinallyBlock.Add(new IdentifierExpression { Identifier = decl.Name }.Invoke("Free")); + } + + block.Add(variables); + + stmt.Body = (BlockStatement)fixedStatement.EmbeddedStatement.AcceptVisitor(this, data); + + return EndNode(fixedStatement, stmt); } public AstNode VisitForeachStatement(CSharp.ForeachStatement foreachStatement, object data) @@ -1673,11 +1697,17 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitComposedType(CSharp.ComposedType composedType, object data) { - var type = new ComposedType(); + AstType type = new ComposedType(); - ConvertNodes(composedType.ArraySpecifiers, type.ArraySpecifiers); - type.BaseType = (AstType)composedType.BaseType.AcceptVisitor(this, data); - type.HasNullableSpecifier = composedType.HasNullableSpecifier; + ConvertNodes(composedType.ArraySpecifiers, ((ComposedType)type).ArraySpecifiers); + ((ComposedType)type).BaseType = (AstType)composedType.BaseType.AcceptVisitor(this, data); + ((ComposedType)type).HasNullableSpecifier = composedType.HasNullableSpecifier; + + for (int i = 0; i < composedType.PointerRank; i++) { + var tmp = new SimpleType() { Identifier = "__Pointer" }; + tmp.TypeArguments.Add(type); + type = tmp; + } return EndNode(composedType, type); } @@ -1747,6 +1777,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors case "class": typeName = "Class"; break; + case "void": + typeName = "Void"; + break; default: typeName = "unknown"; break; From e7dd90c3ed5079b2a8e48de0b48f96268806c8bb Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 13 Jul 2011 20:15:54 +0200 Subject: [PATCH 39/57] implemented unchecked/checked expression, pointer access and so on --- .../Ast/Expressions/Expression.cs | 4 +-- .../Ast/Expressions/MemberAccessExpression.cs | 4 +-- .../OutputVisitor/OutputVisitor.cs | 12 ++++--- .../Visitors/CSharpToVBConverterVisitor.cs | 34 +++++++++++++------ 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index 39d3878952..85ccf6ac4f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.VB.Ast ///
public MemberAccessExpression Member(string memberName) { - return new MemberAccessExpression { Target = this, Member = memberName }; + return new MemberAccessExpression { Target = this, MemberName = memberName }; } /// @@ -64,7 +64,7 @@ namespace ICSharpCode.NRefactory.VB.Ast InvocationExpression ie = new InvocationExpression(); MemberAccessExpression mre = new MemberAccessExpression(); mre.Target = this; - mre.Member = methodName; + mre.MemberName = methodName; mre.TypeArguments.AddRange(typeArguments); ie.Target = mre; ie.Arguments.AddRange(arguments); diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs index f9da04bcf8..ca030b2f12 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.VB.Ast set { SetChildByRole(Roles.Expression, value); } } - public Identifier Member { + public Identifier MemberName { get { return GetChildByRole(Roles.Identifier); } set { SetChildByRole(Roles.Identifier, value); } } @@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.VB.Ast var expr = other as MemberAccessExpression; return expr != null && Target.DoMatch(expr.Target, match) && - Member.DoMatch(expr.Member, match) && + MemberName.DoMatch(expr.MemberName, match) && TypeArguments.DoMatch(expr.TypeArguments, match); } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index b83854e871..7c72513979 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -446,7 +446,7 @@ namespace ICSharpCode.NRefactory.VB memberAccessExpression.Target.AcceptVisitor(this, data); WriteToken(".", MemberAccessExpression.Roles.Dot); - memberAccessExpression.Member.AcceptVisitor(this, data); + memberAccessExpression.MemberName.AcceptVisitor(this, data); WriteTypeArguments(memberAccessExpression.TypeArguments); return EndNode(memberAccessExpression); @@ -1644,10 +1644,12 @@ namespace ICSharpCode.NRefactory.VB foreach (var specifier in arrayCreateExpression.AdditionalArraySpecifiers) { specifier.AcceptVisitor(this, data); } - Space(); - WriteToken("=", ArrayCreateExpression.Roles.Assign); - Space(); - arrayCreateExpression.Initializer.AcceptVisitor(this, data); + if (!arrayCreateExpression.Initializer.IsNull) { + Space(); + WriteToken("=", ArrayCreateExpression.Roles.Assign); + Space(); + arrayCreateExpression.Initializer.AcceptVisitor(this, data); + } return EndNode(arrayCreateExpression); } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index faf17feda2..8bb3490709 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -304,7 +304,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitCheckedExpression(CSharp.CheckedExpression checkedExpression, object data) { - throw new NotImplementedException(); + blocks.Peek().AddChild(new Comment(" The following expression was wrapped in a checked-expression", false), AstNode.Roles.Comment); + return EndNode(checkedExpression, checkedExpression.Expression.AcceptVisitor(this, data)); } public AstNode VisitConditionalExpression(CSharp.ConditionalExpression conditionalExpression, object data) @@ -385,7 +386,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors var memberAccessExpression = new MemberAccessExpression(); memberAccessExpression.Target = (Expression)memberReferenceExpression.Target.AcceptVisitor(this, data); - memberAccessExpression.Member = new Identifier(memberReferenceExpression.MemberName, AstLocation.Empty); + memberAccessExpression.MemberName = new Identifier(memberReferenceExpression.MemberName, AstLocation.Empty); ConvertNodes(memberReferenceExpression.TypeArguments, memberAccessExpression.TypeArguments); return EndNode(memberReferenceExpression, memberAccessExpression); @@ -442,14 +443,14 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitPointerReferenceExpression(CSharp.PointerReferenceExpression pointerReferenceExpression, object data) { - throw new NotImplementedException(); + return EndNode(pointerReferenceExpression,((Expression)pointerReferenceExpression.Target.AcceptVisitor(this, data)).Invoke("Dereference").Member(pointerReferenceExpression.MemberName)); } public AstNode VisitPrimitiveExpression(CSharp.PrimitiveExpression primitiveExpression, object data) { Expression expr; - if ((primitiveExpression.Value is string || primitiveExpression.Value is char) && primitiveExpression.Value.ToString().IndexOfAny(new[] {'\r', '\n'}) > -1) + if ((primitiveExpression.Value is string || primitiveExpression.Value is char) && primitiveExpression.Value.ToString().IndexOfAny(new[] {'\r', '\n', '\t'}) > -1) expr = ConvertToConcat(primitiveExpression.Value.ToString()); else expr = new PrimitiveExpression(primitiveExpression.Value); @@ -503,7 +504,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitSizeOfExpression(CSharp.SizeOfExpression sizeOfExpression, object data) { - throw new NotImplementedException(); + return EndNode( + sizeOfExpression, + new InvocationExpression( + new IdentifierExpression() { Identifier = "__SizeOf" }, + new TypeReferenceExpression((AstType)sizeOfExpression.Type.AcceptVisitor(this, data)) + ) + ); } public AstNode VisitStackAllocExpression(CSharp.StackAllocExpression stackAllocExpression, object data) @@ -597,7 +604,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitUncheckedExpression(CSharp.UncheckedExpression uncheckedExpression, object data) { - throw new NotImplementedException(); + blocks.Peek().AddChild(new Comment(" The following expression was wrapped in a unchecked-expression", false), AstNode.Roles.Comment); + return EndNode(uncheckedExpression, uncheckedExpression.Expression.AcceptVisitor(this, data)); } public AstNode VisitEmptyExpression(CSharp.EmptyExpression emptyExpression, object data) @@ -844,8 +852,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitCheckedStatement(CSharp.CheckedStatement checkedStatement, object data) { - // overflow/underflow checks are on by default in VB - throw new NotImplementedException(); + blocks.Peek().AddChild(new Comment(" The following expression was wrapped in a checked-expression", false), AstNode.Roles.Comment); + var body = (BlockStatement)checkedStatement.Body.AcceptVisitor(this, data); + + blocks.Peek().AddRange(body); + + return EndNode(checkedStatement, null); } public AstNode VisitContinueStatement(CSharp.ContinueStatement continueStatement, object data) @@ -906,9 +918,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors Identifiers = { new VariableIdentifier { Name = decl.Name } }, Type = new SimpleType("GCHandle"), Initializer = new InvocationExpression( - new MemberAccessExpression { Target = new IdentifierExpression { Identifier = "GCHandle" }, Member = "Alloc" }, + new MemberAccessExpression { Target = new IdentifierExpression { Identifier = "GCHandle" }, MemberName = "Alloc" }, (Expression)decl.Initializer.AcceptVisitor(this, data), - new MemberAccessExpression { Target = new IdentifierExpression { Identifier = "GCHandleType" }, Member = "Pinned" } + new MemberAccessExpression { Target = new IdentifierExpression { Identifier = "GCHandleType" }, MemberName = "Pinned" } ) }; variables.Variables.Add(v); @@ -1238,7 +1250,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors var result = new InvocationExpression( new MemberAccessExpression() { Target = new InstanceExpression(constructorInitializer.ConstructorInitializerType == CSharp.ConstructorInitializerType.This ? InstanceExpressionType.Me : InstanceExpressionType.MyBase, AstLocation.Empty), - Member = new Identifier("New", AstLocation.Empty) + MemberName = new Identifier("New", AstLocation.Empty) } ); ConvertNodes(constructorInitializer.Arguments, result.Arguments); From 46b5f4394f044e31c4d043ad689abf594df174c3 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 13 Jul 2011 20:48:08 +0200 Subject: [PATCH 40/57] add EmptyExpression conversion, improve fixed-Statement conversion --- .../Ast/Expressions/ArrayCreateExpression.cs | 2 - .../Ast/Expressions/EmptyExpression.cs | 59 +++++++++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 +- .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 7 +++ .../Visitors/CSharpToVBConverterVisitor.cs | 13 +++- 6 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/EmptyExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs index 544213829b..b3f580894f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayCreateExpression.cs @@ -61,6 +61,4 @@ namespace ICSharpCode.NRefactory.VB.Ast return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) && this.Initializer.DoMatch(o.Initializer, match); } } - - } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/EmptyExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/EmptyExpression.cs new file mode 100644 index 0000000000..c475a2b515 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/EmptyExpression.cs @@ -0,0 +1,59 @@ +// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class EmptyExpression : Expression + { + AstLocation location; + + public override AstLocation StartLocation { + get { + return location; + } + } + + public override AstLocation EndLocation { + get { + return location; + } + } + + public EmptyExpression() + { + } + + public EmptyExpression(AstLocation location) + { + this.location = location; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitEmptyExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + var o = other as EmptyExpression; + return o != null; + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 2386e7cf36..746e6fdc91 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -112,6 +112,6 @@ namespace ICSharpCode.NRefactory.VB { S VisitQueryExpression(QueryExpression queryExpression, T data); - + S VisitEmptyExpression(EmptyExpression emptyExpression, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 9d611da297..7b97eb2630 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -54,6 +54,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 7c72513979..994eedd854 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2404,5 +2404,12 @@ namespace ICSharpCode.NRefactory.VB new OutputVisitor(writer, new VBFormattingOptions()).WritePrimitiveValue(primitiveExpression.Value); return writer.ToString(); } + + public object VisitEmptyExpression(EmptyExpression emptyExpression, object data) + { + StartNode(emptyExpression); + + return EndNode(emptyExpression); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 8bb3490709..34f3e8693f 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -594,7 +594,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors Operator = UnaryOperatorType.AddressOf }; break; -// case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Dereference: + case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Dereference: + expr = new InvocationExpression(); + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__Dereference" }; + ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); + break; default: throw new Exception("Invalid value for UnaryOperatorType"); } @@ -610,8 +614,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitEmptyExpression(CSharp.EmptyExpression emptyExpression, object data) { - // TODO : not used in ILSpy currently - throw new NotImplementedException(); + return EndNode(emptyExpression, new EmptyExpression()); } public AstNode VisitQueryExpression(CSharp.QueryExpression queryExpression, object data) @@ -931,6 +934,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors stmt.Body = (BlockStatement)fixedStatement.EmbeddedStatement.AcceptVisitor(this, data); + foreach (var ident in stmt.Body.Descendants.OfType()) { + ident.ReplaceWith(expr => ((Expression)expr).Invoke("AddrOfPinnedObject")); + } + return EndNode(fixedStatement, stmt); } From f7fcc9d68b7a842274286de1ebe1809545193d4b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 13 Jul 2011 21:07:50 +0200 Subject: [PATCH 41/57] implemented AnonymousObjectCreationExpression --- .../AnonymousObjectCreationExpression.cs | 41 +++++++++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 2 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 16 ++++++++ .../Visitors/CSharpToVBConverterVisitor.cs | 6 ++- 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs new file mode 100644 index 0000000000..98f7875a55 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs @@ -0,0 +1,41 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class AnonymousObjectCreationExpression : Expression + { + public AstNodeCollection Initializer { + get { return GetChildrenByRole(Roles.Expression); } + } + + public AnonymousObjectCreationExpression () + { + } + + public AnonymousObjectCreationExpression (IEnumerable initializer) + { + foreach (var ini in initializer) { + AddChild (ini, Roles.Expression); + } + } + + public AnonymousObjectCreationExpression (params Expression[] initializer) : this ((IEnumerable)initializer) + { + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitAnonymousObjectCreationExpression(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + var o = other as AnonymousObjectCreationExpression; + return o != null && this.Initializer.DoMatch(o.Initializer, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 746e6fdc91..7b8b1401dd 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -113,5 +113,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitQueryExpression(QueryExpression queryExpression, T data); S VisitEmptyExpression(EmptyExpression emptyExpression, T data); + + S VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpression anonymousObjectCreationExpression, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 7b97eb2630..f5bf9db7a7 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -48,6 +48,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 994eedd854..6b6139f107 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2411,5 +2411,21 @@ namespace ICSharpCode.NRefactory.VB return EndNode(emptyExpression); } + + public object VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpression anonymousObjectCreationExpression, object data) + { + StartNode(anonymousObjectCreationExpression); + + WriteKeyword("New"); + WriteKeyword("With"); + + WriteToken("{", AnonymousObjectCreationExpression.Roles.LBrace); + Space(); + WriteCommaSeparatedList(anonymousObjectCreationExpression.Initializer); + Space(); + WriteToken("}", AnonymousObjectCreationExpression.Roles.RBrace); + + return EndNode(anonymousObjectCreationExpression); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 34f3e8693f..d017f10e19 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -429,7 +429,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAnonymousTypeCreateExpression(CSharp.AnonymousTypeCreateExpression anonymousTypeCreateExpression, object data) { - throw new NotImplementedException(); + var expr = new AnonymousObjectCreationExpression(); + + ConvertNodes(anonymousTypeCreateExpression.Initializer, expr.Initializer); + + return EndNode(anonymousTypeCreateExpression, expr); } public AstNode VisitParenthesizedExpression(CSharp.ParenthesizedExpression parenthesizedExpression, object data) From e90fa22b4c89b71f1a979000b492af22678899d1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 14 Jul 2011 12:09:26 +0200 Subject: [PATCH 42/57] implement query expression AST --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 4 +- .../CollectionRangeVariableDeclaration.cs | 42 +++ .../Ast/Expressions/QueryExpression.cs | 280 ++++++++++++++++++ .../Ast/Expressions/VariableInitializer.cs | 4 +- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 16 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 214 +++++++++++++ .../Visitors/CSharpToVBConverterVisitor.cs | 46 ++- 8 files changed, 600 insertions(+), 7 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index dce53fb2d1..3d6e423698 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -118,7 +118,7 @@ namespace ICSharpCode.NRefactory.VB.Ast /// /// Specifies the ordering direction of a QueryExpressionOrdering node. /// - public enum QueryExpressionOrderingDirection + public enum QueryOrderingDirection { None, Ascending, @@ -129,7 +129,7 @@ namespace ICSharpCode.NRefactory.VB.Ast /// Specifies the partition type for a VB.NET /// query expression. /// - public enum QueryExpressionPartitionType + public enum PartitionKind { Take, TakeWhile, diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs new file mode 100644 index 0000000000..1e2fb7643a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs @@ -0,0 +1,42 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + /// + /// Identifier As Type In Expression + /// + public class CollectionRangeVariableDeclaration : AstNode + { + public static readonly Role CollectionRangeVariableDeclarationRole = new Role("CollectionRangeVariableDeclaration"); + + public VariableIdentifier Identifier { + get { return GetChildByRole(VariableIdentifier.VariableIdentifierRole); } + set { SetChildByRole(VariableIdentifier.VariableIdentifierRole, value); } + } + + public AstType Type { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitCollectionRangeVariableDeclaration(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + CollectionRangeVariableDeclaration o = other as CollectionRangeVariableDeclaration; + return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs index 19cf4db4ec..2350350340 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs @@ -53,7 +53,240 @@ namespace ICSharpCode.NRefactory.VB.Ast public class FromQueryOperator : QueryOperator { + public AstNodeCollection Variables { + get { return GetChildrenByRole (CollectionRangeVariableDeclaration.CollectionRangeVariableDeclarationRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitFromQueryOperator(this, data); + } + } + + public class AggregateQueryOperator : QueryOperator + { + public CollectionRangeVariableDeclaration Variable { + get { return GetChildByRole(CollectionRangeVariableDeclaration.CollectionRangeVariableDeclarationRole); } + set { SetChildByRole(CollectionRangeVariableDeclaration.CollectionRangeVariableDeclarationRole, value); } + } + + public AstNodeCollection SubQueryOperators { + get { return GetChildrenByRole(QueryOperatorRole); } + } + + public AstNodeCollection IntoExpressions { + get { return GetChildrenByRole(VariableInitializer.VariableInitializerRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitAggregateQueryOperator(this, data); + } + } + + public class SelectQueryOperator : QueryOperator + { + public AstNodeCollection Variables { + get { return GetChildrenByRole(VariableInitializer.VariableInitializerRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitSelectQueryOperator(this, data); + } + } + + public class DistinctQueryOperator : QueryOperator + { + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitDistinctQueryOperator(this, data); + } + } + + public class WhereQueryOperator : QueryOperator + { + public Expression Condition { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitWhereQueryOperator(this, data); + } + } + + public class OrderExpression : AstNode + { + public static readonly Role OrderExpressionRole = new Role("OrderExpression"); + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public QueryOrderingDirection Direction { get; set; } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitOrderExpression(this, data); + } + } + + public class OrderByQueryOperator : QueryOperator + { + public AstNodeCollection Expressions { + get { return GetChildrenByRole(OrderExpression.OrderExpressionRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitOrderByQueryOperator(this, data); + } + } + + public class PartitionQueryOperator : QueryOperator + { + public PartitionKind Kind { get; set; } + + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitPartitionQueryOperator(this, data); + } + } + + public class LetQueryOperator : QueryOperator + { + public AstNodeCollection Variables { + get { return GetChildrenByRole(VariableInitializer.VariableInitializerRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitLetQueryOperator(this, data); + } + } + + public class GroupByQueryOperator : QueryOperator + { + public static readonly Role GroupExpressionRole = new Role("GroupExpression"); + public static readonly Role ByExpressionRole = new Role("ByExpression"); + public static readonly Role IntoExpressionRole = new Role("IntoExpression"); + + public AstNodeCollection GroupExpressions { + get { return GetChildrenByRole(GroupExpressionRole); } + } + + public AstNodeCollection ByExpressions { + get { return GetChildrenByRole(ByExpressionRole); } + } + + public AstNodeCollection IntoExpressions { + get { return GetChildrenByRole(IntoExpressionRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitGroupByQueryOperator(this, data); + } + } + + public class JoinQueryOperator : QueryOperator + { + #region Null + public new static readonly JoinQueryOperator Null = new NullJoinQueryOperator(); + + sealed class NullJoinQueryOperator : JoinQueryOperator + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + public static readonly Role JoinQueryOperatorRole = new Role("JoinQueryOperator", JoinQueryOperator.Null); + + public CollectionRangeVariableDeclaration JoinVariable { + get { return GetChildByRole(CollectionRangeVariableDeclaration.CollectionRangeVariableDeclarationRole); } + set { SetChildByRole(CollectionRangeVariableDeclaration.CollectionRangeVariableDeclarationRole, value); } + } + + public JoinQueryOperator SubJoinQuery { + get { return GetChildByRole(JoinQueryOperatorRole); } + set { SetChildByRole(JoinQueryOperatorRole, value); } + } + + public AstNodeCollection JoinConditions { + get { return GetChildrenByRole(JoinCondition.JoinConditionRole); } + } protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { @@ -61,8 +294,55 @@ namespace ICSharpCode.NRefactory.VB.Ast } public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitJoinQueryOperator(this, data); + } + } + + public class JoinCondition : AstNode + { + public static readonly Role JoinConditionRole = new Role("JoinCondition"); + + public static readonly Role LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; + public static readonly Role RightExpressionRole = BinaryOperatorExpression.RightExpressionRole; + + public Expression Left { + get { return GetChildByRole (LeftExpressionRole); } + set { SetChildByRole (LeftExpressionRole, value); } + } + + public Expression Right { + get { return GetChildByRole (RightExpressionRole); } + set { SetChildByRole (RightExpressionRole, value); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitJoinCondition(this, data); + } + } + + public class GroupJoinQueryOperator : JoinQueryOperator + { + public static readonly Role IntoExpressionRole = GroupByQueryOperator.IntoExpressionRole; + + public AstNodeCollection IntoExpressions { + get { return GetChildrenByRole(IntoExpressionRole); } + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { throw new NotImplementedException(); } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitGroupJoinQueryOperator(this, data); + } } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs index 49acf4a3cd..f73833de4c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs @@ -11,6 +11,8 @@ namespace ICSharpCode.NRefactory.VB.Ast ///
public class VariableInitializer : AstNode { + public static readonly Role VariableInitializerRole = new Role("VariableInitializer"); + public VariableIdentifier Identifier { get { return GetChildByRole(VariableIdentifier.VariableIdentifierRole); } set { SetChildByRole(VariableIdentifier.VariableIdentifierRole, value); } @@ -38,7 +40,7 @@ namespace ICSharpCode.NRefactory.VB.Ast protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { VariableInitializer o = other as VariableInitializer; - return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); + return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match); } } } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 7b8b1401dd..c24e2b617b 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -115,5 +115,21 @@ namespace ICSharpCode.NRefactory.VB { S VisitEmptyExpression(EmptyExpression emptyExpression, T data); S VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpression anonymousObjectCreationExpression, T data); + + S VisitCollectionRangeVariableDeclaration(CollectionRangeVariableDeclaration collectionRangeVariableDeclaration, T data); + + S VisitFromQueryOperator(FromQueryOperator fromQueryOperator, T data); + S VisitAggregateQueryOperator(AggregateQueryOperator aggregateQueryOperator, T data); + S VisitSelectQueryOperator(SelectQueryOperator selectQueryOperator, T data); + S VisitDistinctQueryOperator(DistinctQueryOperator distinctQueryOperator, T data); + S VisitWhereQueryOperator(WhereQueryOperator whereQueryOperator, T data); + S VisitOrderExpression(OrderExpression orderExpression, T data); + S VisitOrderByQueryOperator(OrderByQueryOperator orderByQueryOperator, T data); + S VisitPartitionQueryOperator(PartitionQueryOperator partitionQueryOperator, T data); + S VisitLetQueryOperator(LetQueryOperator letQueryOperator, T data); + S VisitGroupByQueryOperator(GroupByQueryOperator groupByQueryOperator, T data); + S VisitJoinQueryOperator(JoinQueryOperator joinQueryOperator, T data); + S VisitJoinCondition(JoinCondition joinCondition, T data); + S VisitGroupJoinQueryOperator(GroupJoinQueryOperator groupJoinQueryOperator, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index f5bf9db7a7..136c0a5cc8 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -54,6 +54,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 6b6139f107..88d001350a 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2427,5 +2427,219 @@ namespace ICSharpCode.NRefactory.VB return EndNode(anonymousObjectCreationExpression); } + + public object VisitCollectionRangeVariableDeclaration(CollectionRangeVariableDeclaration collectionRangeVariableDeclaration, object data) + { + StartNode(collectionRangeVariableDeclaration); + + collectionRangeVariableDeclaration.Identifier.AcceptVisitor(this, data); + if (!collectionRangeVariableDeclaration.Type.IsNull) { + WriteKeyword("As"); + collectionRangeVariableDeclaration.Type.AcceptVisitor(this, data); + } + WriteKeyword("In"); + collectionRangeVariableDeclaration.Expression.AcceptVisitor(this, data); + + return EndNode(collectionRangeVariableDeclaration); + } + + public object VisitFromQueryOperator(FromQueryOperator fromQueryOperator, object data) + { + StartNode(fromQueryOperator); + + WriteKeyword("From"); + WriteCommaSeparatedList(fromQueryOperator.Variables); + + return EndNode(fromQueryOperator); + } + + public object VisitAggregateQueryOperator(AggregateQueryOperator aggregateQueryOperator, object data) + { + StartNode(aggregateQueryOperator); + + WriteKeyword("Aggregate"); + aggregateQueryOperator.Variable.AcceptVisitor(this, data); + + foreach (var operators in aggregateQueryOperator.SubQueryOperators) { + operators.AcceptVisitor(this, data); + } + + WriteKeyword("Into"); + WriteCommaSeparatedList(aggregateQueryOperator.IntoExpressions); + + return EndNode(aggregateQueryOperator); + } + + public object VisitSelectQueryOperator(SelectQueryOperator selectQueryOperator, object data) + { + StartNode(selectQueryOperator); + + WriteKeyword("Select"); + WriteCommaSeparatedList(selectQueryOperator.Variables); + + return EndNode(selectQueryOperator); + } + + public object VisitDistinctQueryOperator(DistinctQueryOperator distinctQueryOperator, object data) + { + StartNode(distinctQueryOperator); + + WriteKeyword("Distinct"); + + return EndNode(distinctQueryOperator); + } + + public object VisitWhereQueryOperator(WhereQueryOperator whereQueryOperator, object data) + { + StartNode(whereQueryOperator); + + WriteKeyword("Where"); + whereQueryOperator.Condition.AcceptVisitor(this, data); + + return EndNode(whereQueryOperator); + } + + public object VisitPartitionQueryOperator(PartitionQueryOperator partitionQueryOperator, object data) + { + StartNode(partitionQueryOperator); + + switch (partitionQueryOperator.Kind) { + case PartitionKind.Take: + WriteKeyword("Take"); + break; + case PartitionKind.TakeWhile: + WriteKeyword("Take"); + WriteKeyword("While"); + break; + case PartitionKind.Skip: + WriteKeyword("Skip"); + break; + case PartitionKind.SkipWhile: + WriteKeyword("Skip"); + WriteKeyword("While"); + break; + default: + throw new Exception("Invalid value for PartitionKind"); + } + + partitionQueryOperator.Expression.AcceptVisitor(this, data); + + return EndNode(partitionQueryOperator); + } + + public object VisitOrderExpression(OrderExpression orderExpression, object data) + { + StartNode(orderExpression); + + orderExpression.Expression.AcceptVisitor(this, data); + + switch (orderExpression.Direction) { + case QueryOrderingDirection.None: + break; + case QueryOrderingDirection.Ascending: + WriteKeyword("Ascending"); + break; + case QueryOrderingDirection.Descending: + WriteKeyword("Descending"); + break; + default: + throw new Exception("Invalid value for QueryExpressionOrderingDirection"); + } + + return EndNode(orderExpression); + } + + public object VisitOrderByQueryOperator(OrderByQueryOperator orderByQueryOperator, object data) + { + StartNode(orderByQueryOperator); + + WriteKeyword("Order"); + WriteKeyword("By"); + WriteCommaSeparatedList(orderByQueryOperator.Expressions); + + return EndNode(orderByQueryOperator); + } + + public object VisitLetQueryOperator(LetQueryOperator letQueryOperator, object data) + { + StartNode(letQueryOperator); + + WriteKeyword("Let"); + WriteCommaSeparatedList(letQueryOperator.Variables); + + return EndNode(letQueryOperator); + } + + public object VisitGroupByQueryOperator(GroupByQueryOperator groupByQueryOperator, object data) + { + StartNode(groupByQueryOperator); + + WriteKeyword("Group"); + WriteCommaSeparatedList(groupByQueryOperator.GroupExpressions); + WriteKeyword("By"); + WriteCommaSeparatedList(groupByQueryOperator.ByExpressions); + WriteKeyword("Into"); + WriteCommaSeparatedList(groupByQueryOperator.IntoExpressions); + + return EndNode(groupByQueryOperator); + } + + public object VisitJoinQueryOperator(JoinQueryOperator joinQueryOperator, object data) + { + StartNode(joinQueryOperator); + + WriteKeyword("Join"); + joinQueryOperator.JoinVariable.AcceptVisitor(this, data); + if (!joinQueryOperator.SubJoinQuery.IsNull) { + joinQueryOperator.SubJoinQuery.AcceptVisitor(this, data); + } + WriteKeyword("On"); + bool first = true; + foreach (var cond in joinQueryOperator.JoinConditions) { + if (first) + first = false; + else + WriteKeyword("And"); + cond.AcceptVisitor(this, data); + } + + return EndNode(joinQueryOperator); + } + + public object VisitJoinCondition(JoinCondition joinCondition, object data) + { + StartNode(joinCondition); + + joinCondition.Left.AcceptVisitor(this, data); + WriteKeyword("Equals"); + joinCondition.Right.AcceptVisitor(this, data); + + return EndNode(joinCondition); + } + + public object VisitGroupJoinQueryOperator(GroupJoinQueryOperator groupJoinQueryOperator, object data) + { + StartNode(groupJoinQueryOperator); + + WriteKeyword("Group"); + WriteKeyword("Join"); + groupJoinQueryOperator.JoinVariable.AcceptVisitor(this, data); + if (!groupJoinQueryOperator.SubJoinQuery.IsNull) { + groupJoinQueryOperator.SubJoinQuery.AcceptVisitor(this, data); + } + WriteKeyword("On"); + bool first = true; + foreach (var cond in groupJoinQueryOperator.JoinConditions) { + if (first) + first = false; + else + WriteKeyword("And"); + cond.AcceptVisitor(this, data); + } + WriteKeyword("Into"); + WriteCommaSeparatedList(groupJoinQueryOperator.IntoExpressions); + + return EndNode(groupJoinQueryOperator); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index b53ea5e30b..f1c6e3949d 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -235,6 +235,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftRight: op = BinaryOperatorType.ShiftRight; break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.NullCoalescing: + var nullCoalescing = new ConditionalExpression { + ConditionExpression = left, + FalseExpression = right + }; + return EndNode(binaryOperatorExpression, nullCoalescing); default: throw new Exception("Invalid value for BinaryOperatorType: " + binaryOperatorExpression.Operator); } @@ -635,7 +641,16 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitQueryFromClause(CSharp.QueryFromClause queryFromClause, object data) { - throw new NotImplementedException(); + var op = new FromQueryOperator(); + op.Variables.Add( + new CollectionRangeVariableDeclaration { + Identifier = new VariableIdentifier { Name = queryFromClause.Identifier }, + Type = (AstType)queryFromClause.Type.AcceptVisitor(this, data), + Expression = (Expression)queryFromClause.Expression.AcceptVisitor(this, data) + } + ); + + return EndNode(queryFromClause, op); } public AstNode VisitQueryLetClause(CSharp.QueryLetClause queryLetClause, object data) @@ -655,22 +670,45 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitQueryOrderClause(CSharp.QueryOrderClause queryOrderClause, object data) { - throw new NotImplementedException(); + var op = new OrderByQueryOperator(); + + ConvertNodes(queryOrderClause.Orderings, op.Expressions); + + return EndNode(queryOrderClause, op); } public AstNode VisitQueryOrdering(CSharp.QueryOrdering queryOrdering, object data) { - throw new NotImplementedException(); + var expr = new OrderExpression(); + + expr.Direction = (QueryOrderingDirection)queryOrdering.Direction; + expr.Expression = (Expression)queryOrdering.Expression.AcceptVisitor(this, data); + + return EndNode(queryOrdering, expr); } + int selectVarCount = 0; + public AstNode VisitQuerySelectClause(CSharp.QuerySelectClause querySelectClause, object data) { - throw new NotImplementedException(); + var op = new SelectQueryOperator(); + + op.Variables.Add( + new VariableInitializer { + Identifier = new VariableIdentifier { Name = "SelectVar" + selectVarCount }, + Expression = (Expression)querySelectClause.Expression.AcceptVisitor(this, data) + }); + + return EndNode(querySelectClause, op); } public AstNode VisitQueryGroupClause(CSharp.QueryGroupClause queryGroupClause, object data) { + var op = new GroupByQueryOperator(); + throw new NotImplementedException(); + + return EndNode(queryGroupClause, op); } public AstNode VisitAttribute(CSharp.Attribute attribute, object data) From d4eabd06f0198de907682c4ea86abb43bc86a7e4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 14 Jul 2011 12:17:11 +0200 Subject: [PATCH 43/57] relicense NR.VB under MIT X11 license --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 2 +- .../Ast/Expressions/AnonymousObjectCreationExpression.cs | 2 +- .../Ast/Expressions/ArrayInitializerExpression.cs | 2 +- .../Ast/Expressions/AssignmentExpression.cs | 2 +- .../Ast/Expressions/BinaryOperatorExpression.cs | 2 +- .../Ast/Expressions/CollectionRangeVariableDeclaration.cs | 2 +- .../Ast/Expressions/ConditionalExpression.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs | 2 +- .../Ast/Expressions/FieldInitializerExpression.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs | 2 +- .../Ast/Expressions/GetXmlNamespaceExpression.cs | 2 +- .../Ast/Expressions/IdentifierExpression.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs | 2 +- .../Ast/Expressions/InvocationExpression.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs | 2 +- .../Ast/Expressions/MemberAccessExpression.cs | 2 +- .../Ast/Expressions/NamedArgumentExpression.cs | 2 +- .../Ast/Expressions/ObjectCreationExpression.cs | 2 +- .../Ast/Expressions/ParenthesizedExpression.cs | 2 +- .../Ast/Expressions/PrimitiveExpression.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs | 2 +- .../Ast/Expressions/SimpleNameExpression.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs | 2 +- .../Ast/Expressions/TypeReferenceExpression.cs | 2 +- .../Ast/Expressions/UnaryOperatorExpression.cs | 2 +- .../Ast/Expressions/VariableInitializer.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs | 2 +- .../Ast/General/InterfaceMemberSpecifier.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs | 2 +- .../Ast/General/TypeParameterDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Generated.cs | 2 +- .../Ast/GlobalScope/DelegateDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs | 2 +- .../Ast/GlobalScope/EnumMemberDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs | 2 +- .../Ast/GlobalScope/NamespaceDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/INullable.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Identifier.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs | 2 +- .../Ast/TypeMembers/ConstructorDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs | 2 +- .../Ast/TypeMembers/ExternalMethodDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs | 2 +- .../Ast/TypeMembers/OperatorDeclaration.cs | 2 +- .../Ast/TypeMembers/PropertyDeclaration.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs | 2 +- ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs | 2 +- ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Block.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/ExpressionFinderState.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Extensions.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/LATextReader.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/LookupTable.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs | 2 +- .../Lexer/Special/PreProcessingDirective.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/Token.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/VBLexerMemento.cs | 2 +- ICSharpCode.NRefactory.VB/Lexer/XmlModeInfo.cs | 2 +- ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs | 2 +- ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs | 2 +- ICSharpCode.NRefactory.VB/Parser/Errors.cs | 2 +- ICSharpCode.NRefactory.VB/Parser/VBParser.cs | 2 +- .../PrettyPrinter/AbstractOutputFormatter.cs | 2 +- .../PrettyPrinter/AbstractPrettyPrintOptions.cs | 2 +- ICSharpCode.NRefactory.VB/PrettyPrinter/IOutputAstVisitor.cs | 2 +- ICSharpCode.NRefactory.VB/PrettyPrinter/SpecialNodesInserter.cs | 2 +- .../PrettyPrinter/VBNet/VBNetOutputFormatter.cs | 2 +- .../PrettyPrinter/VBNet/VBNetOutputVisitor.cs | 2 +- .../PrettyPrinter/VBNet/VBNetPrettyPrintOptions.cs | 2 +- ICSharpCode.NRefactory.VB/VBParser.cs | 2 +- .../Visitors/CSharpToVBConverterVisitor.cs | 2 +- 95 files changed, 95 insertions(+), 95 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index 3d6e423698..a3fa8d6184 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs index 98f7875a55..ac3f8d0daa 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/AnonymousObjectCreationExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs index 772602de9d..785f2c19b1 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ArrayInitializerExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs index 250e27b71a..bab517a579 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs index d406be1996..b83a0909fe 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs index 1e2fb7643a..711341d0cd 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/CollectionRangeVariableDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs index 94d9949bda..4b53d56633 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index 85ccf6ac4f..dad5cd9332 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs index 7a005a4fdb..bc77666c8a 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs index ce118eb638..573d1cf8b3 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetTypeExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs index 07a5237384..390281d3f6 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/GetXmlNamespaceExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs index 89e6d4ec14..fa3b642d54 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs index 80e376524b..d51972cb1d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/InstanceExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs index e0eec7b052..6a81c0376d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs index 25090d7ad4..75863cbfc3 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs index ca030b2f12..17e8057750 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/MemberAccessExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs index be4c3249da..730eaafafd 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs index 093efb737d..6e28b292d8 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ObjectCreationExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs index 492426b668..31c234044c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ParenthesizedExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs index 08e469b1a8..39eeabc07b 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/PrimitiveExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using ICSharpCode.NRefactory.VB.PrettyPrinter; using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs index 2350350340..2701d4e892 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs index 82250a8fa3..0face5c9e9 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/SimpleNameExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs index a1dfa6ea5f..54ef20f94f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeOfIsExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs index cfe920d1eb..d163fcd77b 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/TypeReferenceExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs index 43c7881c86..7876984849 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs index f73833de4c..7d1cb87e70 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs index 7d3a6ca0b9..97860526fb 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs index 3195bcd69a..90845e0fb7 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs b/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs index 22261575ef..a46e275497 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs b/ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs index 2e06d39172..57d69db33d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/AttributeBlock.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs b/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs index 160ab9145b..f7330195f9 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs b/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs index 6dbe784277..fcc2f2b1bb 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs b/ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs index 5550ed53ae..da1e14cf4f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/EventMemberSpecifier.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs b/ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs index 1cf0610188..84cc23da6b 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/InterfaceMemberSpecifier.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs index f382cfeb5c..61b4f2ae37 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/ParameterDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs index e82a50c90f..cfce070566 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/TypeParameterDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/Generated.cs b/ICSharpCode.NRefactory.VB/Ast/Generated.cs index bd973a0d79..dee6e4d96f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Generated.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Generated.cs @@ -1,5 +1,5 @@ //// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +//// This code is distributed under MIT X11 license (for details please see \doc\license.txt) //using System; //using System.Collections.Generic; // diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs index bc2d06ca03..8a88c91350 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/DelegateDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs index b24fc4b23c..736d579ffb 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs index 476ec56360..72e757c607 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/EnumMemberDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs index a7c8dfa17d..a9d7f45bf0 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs index 6691b852ba..24ea944d62 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsStatement.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; using ICSharpCode.NRefactory.PatternMatching; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs index 5c392a73af..5859cc40a9 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/NamespaceDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs index 903439c89a..299cc5b01e 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/OptionStatement.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; using ICSharpCode.NRefactory.PatternMatching; diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs index 1c7af29660..1780cb59d7 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/INullable.cs b/ICSharpCode.NRefactory.VB/Ast/INullable.cs index 14a65a444e..1ce646f6bb 100644 --- a/ICSharpCode.NRefactory.VB/Ast/INullable.cs +++ b/ICSharpCode.NRefactory.VB/Ast/INullable.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) namespace ICSharpCode.NRefactory.VB.Ast { diff --git a/ICSharpCode.NRefactory.VB/Ast/Identifier.cs b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs index 72f3cbdd20..99028a8964 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Identifier.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs index 2e03e0ab91..1cce01649d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs index be9751b6a2..7eb287c267 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs index 7076d2215a..9e57fc572d 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ConstructorDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs index 5357ef47d9..ce01819640 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs index a706ceaaa8..d5d9754472 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/ExternalMethodDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Runtime.InteropServices; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs index 06cf639d97..528d632cb4 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs index 7da71936a1..a6dd87159e 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs index 8e3574e530..f6591e4a4f 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/OperatorDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs index 1b0a7d7d22..6fdab3842a 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/PropertyDeclaration.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs index 94227bdc7d..a3ad2892ad 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs index 0fe6228a27..d9f7e4ce26 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs index e214a7e4b5..4b688366c9 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/ComposedType.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; using System.Linq; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs index 8d6badc8f3..d7dc0c2451 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/PrimitiveType.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; using System.Linq; diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs index 116f9918c9..4c3d93cd36 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/QualifiedType.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Linq; diff --git a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs index bd87cca4e7..2039901e47 100644 --- a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs +++ b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs b/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs index 402dc449f6..7ac2ef32ce 100644 --- a/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs +++ b/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs b/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs index 1f3541f15a..eb227171f9 100644 --- a/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs +++ b/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Block.cs b/ICSharpCode.NRefactory.VB/Lexer/Block.cs index c9ffba0d20..b568e0440d 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Block.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Block.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs index 15b9bdd6d2..cb6f236158 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinder.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinderState.cs b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinderState.cs index 485ed3d237..0feda1f93e 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinderState.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/ExpressionFinderState.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Extensions.cs b/ICSharpCode.NRefactory.VB/Lexer/Extensions.cs index 7b5d4163a5..0107d3f088 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Extensions.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Extensions.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/LATextReader.cs b/ICSharpCode.NRefactory.VB/Lexer/LATextReader.cs index f11043307b..eff8b821eb 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/LATextReader.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/LATextReader.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/LookupTable.cs b/ICSharpCode.NRefactory.VB/Lexer/LookupTable.cs index 2ec80b687a..eb2c94dfcf 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/LookupTable.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/LookupTable.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Globalization; diff --git a/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs b/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs index f3ee77a93f..651ecb71b7 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/SavepointEventArgs.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs index 5120bd7650..5821ca6a98 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/BlankLine.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs index 82772f2d42..ecfc393fa4 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/Comment.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs index 1c9bb63e92..7eac974d5c 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/CommentType.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs index a589642112..52c1abb37e 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/ISpecial.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs index 97c0a7481a..4b9222190e 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/PreProcessingDirective.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs index 2107163e4c..6ae334b2f6 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/SpecialTracker.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs b/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs index 3209cf162e..39863d1256 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Special/TagComment.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Lexer/Token.cs b/ICSharpCode.NRefactory.VB/Lexer/Token.cs index ae4ed7d63e..54df5cab67 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/Token.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/Token.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs b/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs index 6aac502c21..ea2dc116ee 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/VBLexer.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections; diff --git a/ICSharpCode.NRefactory.VB/Lexer/VBLexerMemento.cs b/ICSharpCode.NRefactory.VB/Lexer/VBLexerMemento.cs index 148475ccd8..30e9d0f8cd 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/VBLexerMemento.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/VBLexerMemento.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Lexer/XmlModeInfo.cs b/ICSharpCode.NRefactory.VB/Lexer/XmlModeInfo.cs index 4f3ef71e97..2141ac3532 100644 --- a/ICSharpCode.NRefactory.VB/Lexer/XmlModeInfo.cs +++ b/ICSharpCode.NRefactory.VB/Lexer/XmlModeInfo.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 88d001350a..925f7168a0 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs index 8888bf2ffe..5dbf95054c 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/VBFormattingOptions.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/Parser/Errors.cs b/ICSharpCode.NRefactory.VB/Parser/Errors.cs index 6cd0b2e249..ab9e615bdd 100644 --- a/ICSharpCode.NRefactory.VB/Parser/Errors.cs +++ b/ICSharpCode.NRefactory.VB/Parser/Errors.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Text; diff --git a/ICSharpCode.NRefactory.VB/Parser/VBParser.cs b/ICSharpCode.NRefactory.VB/Parser/VBParser.cs index c099d7981d..bb3516cb2d 100644 --- a/ICSharpCode.NRefactory.VB/Parser/VBParser.cs +++ b/ICSharpCode.NRefactory.VB/Parser/VBParser.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractOutputFormatter.cs b/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractOutputFormatter.cs index c69a56b126..c858d664bf 100644 --- a/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractOutputFormatter.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections; diff --git a/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractPrettyPrintOptions.cs b/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractPrettyPrintOptions.cs index 438fc54a3b..7da8a578cd 100644 --- a/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractPrettyPrintOptions.cs +++ b/ICSharpCode.NRefactory.VB/PrettyPrinter/AbstractPrettyPrintOptions.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) namespace ICSharpCode.NRefactory.VB.PrettyPrinter { diff --git a/ICSharpCode.NRefactory.VB/PrettyPrinter/IOutputAstVisitor.cs b/ICSharpCode.NRefactory.VB/PrettyPrinter/IOutputAstVisitor.cs index 71ccb5d0f0..049696dad4 100644 --- a/ICSharpCode.NRefactory.VB/PrettyPrinter/IOutputAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/PrettyPrinter/IOutputAstVisitor.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using ICSharpCode.NRefactory.VB.Parser; diff --git a/ICSharpCode.NRefactory.VB/PrettyPrinter/SpecialNodesInserter.cs b/ICSharpCode.NRefactory.VB/PrettyPrinter/SpecialNodesInserter.cs index 95fdcf389c..f44d91263c 100644 --- a/ICSharpCode.NRefactory.VB/PrettyPrinter/SpecialNodesInserter.cs +++ b/ICSharpCode.NRefactory.VB/PrettyPrinter/SpecialNodesInserter.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputFormatter.cs b/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputFormatter.cs index ca2325bbad..aadd790af1 100644 --- a/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputFormatter.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using ICSharpCode.NRefactory.VB.Parser; diff --git a/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputVisitor.cs b/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputVisitor.cs index 972c09260f..d4635d1d12 100644 --- a/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputVisitor.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Linq; diff --git a/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetPrettyPrintOptions.cs b/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetPrettyPrintOptions.cs index 0b6170a07d..8178afde06 100644 --- a/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetPrettyPrintOptions.cs +++ b/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetPrettyPrintOptions.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; diff --git a/ICSharpCode.NRefactory.VB/VBParser.cs b/ICSharpCode.NRefactory.VB/VBParser.cs index 27d244be1b..5f62f952ae 100644 --- a/ICSharpCode.NRefactory.VB/VBParser.cs +++ b/ICSharpCode.NRefactory.VB/VBParser.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index f1c6e3949d..683ae235ab 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -1,5 +1,5 @@ // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; From 3265ddc27f9ab69f1bddd18acdb762ebcd7b9d57 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 13:34:03 +0200 Subject: [PATCH 44/57] implement conversion of attribute targets --- .../Ast/General/Attribute.cs | 7 +++++-- .../OutputVisitor/OutputVisitor.cs | 18 +++++++++++++++--- .../Visitors/CSharpToVBConverterVisitor.cs | 6 +++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs b/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs index a46e275497..3ad4686092 100644 --- a/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs +++ b/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs @@ -42,7 +42,9 @@ namespace ICSharpCode.NRefactory.VB.Ast public static readonly Role AttributeRole = new Role("Attribute"); public static readonly Role TargetRole = new Role("Target", VBTokenNode.Null); - public VBTokenNode Target { + public AttributeTarget Target { get; set; } + + public VBTokenNode TargetKeyword { get { return GetChildByRole(TargetRole); } set { SetChildByRole(TargetRole, value); } } @@ -81,12 +83,13 @@ namespace ICSharpCode.NRefactory.VB.Ast protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { var node = other as Attribute; - return node != null && node.Target.DoMatch(this.Target, match) && node.Type.DoMatch(this.Type, match) && node.Arguments.DoMatch(this.Arguments, match); + return node != null && node.Target == Target && node.TargetKeyword.DoMatch(this.TargetKeyword, match) && node.Type.DoMatch(this.Type, match) && node.Arguments.DoMatch(this.Arguments, match); } } public enum AttributeTarget { + None, Assembly, Module } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 925f7168a0..0cbf435142 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -148,9 +148,21 @@ namespace ICSharpCode.NRefactory.VB { StartNode(attribute); - if (!attribute.Target.IsNull) { - attribute.Target.AcceptVisitor(this, data); - WriteToken(":", VB.Ast.Attribute.TargetRole); + if (attribute.Target != AttributeTarget.None) { + switch (attribute.Target) { + case AttributeTarget.None: + break; + case AttributeTarget.Assembly: + WriteKeyword("Assembly"); + break; + case AttributeTarget.Module: + WriteKeyword("Module"); + break; + default: + throw new Exception("Invalid value for AttributeTarget"); + } + WriteToken(":", Ast.Attribute.Roles.Colon); + Space(); } attribute.Type.AcceptVisitor(this, data); WriteCommaSeparatedListInParenthesis(attribute.Arguments, false); diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 683ae235ab..5dde5328e4 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -714,9 +714,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAttribute(CSharp.Attribute attribute, object data) { var attr = new VB.Ast.Attribute(); - - // TODO : attribute targets - + AttributeTarget target; + Enum.TryParse(((CSharp.AttributeSection)attribute.Parent).AttributeTarget, true, out target); + attr.Target = target; attr.Type = (AstType)attribute.Type.AcceptVisitor(this, data); ConvertNodes(attribute.Arguments, attr.Arguments); From 1d904e13c3eb0037708a1d22202f1ed9072d4fab Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 15:54:38 +0200 Subject: [PATCH 45/57] add folding --- .../OutputVisitor/IOutputFormatter.cs | 3 + .../OutputVisitor/OutputVisitor.cs | 127 +++++++++++------- .../TextWriterOutputFormatter.cs | 8 ++ 3 files changed, 87 insertions(+), 51 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs index 2d8d991a85..056b0d1cda 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs @@ -37,5 +37,8 @@ namespace ICSharpCode.NRefactory.VB void NewLine(); void WriteComment(bool isDocumentation, string content); + + void MarkFoldStart(); + void MarkFoldEnd(); } } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 0cbf435142..d6164785db 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -244,12 +244,14 @@ namespace ICSharpCode.NRefactory.VB typeDeclaration.InheritsType.AcceptVisitor(this, data); } WriteImplementsClause(typeDeclaration.ImplementsTypes); + MarkFoldStart(); NewLine(); WriteMembers(typeDeclaration.Members); WriteKeyword("End"); WriteClassTypeKeyword(typeDeclaration); + MarkFoldEnd(); NewLine(); return EndNode(typeDeclaration); } @@ -296,6 +298,7 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("As"); enumDeclaration.UnderlyingType.AcceptVisitor(this, data); } + MarkFoldStart(); NewLine(); Indent(); @@ -306,6 +309,7 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("End"); WriteKeyword("Enum"); + MarkFoldEnd(); NewLine(); return EndNode(enumDeclaration); @@ -505,6 +509,7 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("Sub"); WriteKeyword("New"); WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, false); + MarkFoldStart(); NewLine(); Indent(); @@ -513,6 +518,7 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("End"); WriteKeyword("Sub"); + MarkFoldEnd(); NewLine(); return EndNode(constructorDeclaration); @@ -540,6 +546,7 @@ namespace ICSharpCode.NRefactory.VB WriteHandlesClause(methodDeclaration.HandlesClause); WriteImplementsClause(methodDeclaration.ImplementsClause); if (!methodDeclaration.Body.IsNull) { + MarkFoldStart(); NewLine(); Indent(); WriteBlock(methodDeclaration.Body); @@ -549,11 +556,65 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("Sub"); else WriteKeyword("Function"); + MarkFoldEnd(); } NewLine(); return EndNode(methodDeclaration); } + + public object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) + { + StartNode(fieldDeclaration); + + WriteAttributes(fieldDeclaration.Attributes); + WriteModifiers(fieldDeclaration.ModifierTokens); + WriteCommaSeparatedList(fieldDeclaration.Variables); + NewLine(); + + return EndNode(fieldDeclaration); + } + + public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) + { + StartNode(propertyDeclaration); + + WriteAttributes(propertyDeclaration.Attributes); + WriteModifiers(propertyDeclaration.ModifierTokens); + WriteKeyword("Property"); + WriteIdentifier(propertyDeclaration.Name.Name); + WriteCommaSeparatedListInParenthesis(propertyDeclaration.Parameters, false); + if (!propertyDeclaration.ReturnType.IsNull) { + Space(); + WriteKeyword("As"); + WriteAttributes(propertyDeclaration.ReturnTypeAttributes); + propertyDeclaration.ReturnType.AcceptVisitor(this, data); + } + + bool needsBody = !propertyDeclaration.Getter.Body.IsNull || !propertyDeclaration.Setter.Body.IsNull; + + if (needsBody) { + MarkFoldStart(); + NewLine(); + Indent(); + + if (!propertyDeclaration.Getter.Body.IsNull) { + propertyDeclaration.Getter.AcceptVisitor(this, data); + } + + if (!propertyDeclaration.Setter.Body.IsNull) { + propertyDeclaration.Setter.AcceptVisitor(this, data); + } + Unindent(); + + WriteKeyword("End"); + WriteKeyword("Property"); + MarkFoldEnd(); + } + NewLine(); + + return EndNode(propertyDeclaration); + } #endregion #region TypeName @@ -968,6 +1029,16 @@ namespace ICSharpCode.NRefactory.VB { formatter.Unindent(); } + + void MarkFoldStart() + { + formatter.MarkFoldStart(); + } + + void MarkFoldEnd() + { + formatter.MarkFoldEnd(); + } #endregion #region IsKeyword Test @@ -1244,18 +1315,6 @@ namespace ICSharpCode.NRefactory.VB } #endregion - public object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) - { - StartNode(fieldDeclaration); - - WriteAttributes(fieldDeclaration.Attributes); - WriteModifiers(fieldDeclaration.ModifierTokens); - WriteCommaSeparatedList(fieldDeclaration.Variables); - NewLine(); - - return EndNode(fieldDeclaration); - } - public object VisitVariableIdentifier(VariableIdentifier variableIdentifier, object data) { StartNode(variableIdentifier); @@ -1307,45 +1366,7 @@ namespace ICSharpCode.NRefactory.VB return EndNode(accessor); } - - public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) - { - StartNode(propertyDeclaration); - - WriteAttributes(propertyDeclaration.Attributes); - WriteModifiers(propertyDeclaration.ModifierTokens); - WriteKeyword("Property"); - WriteIdentifier(propertyDeclaration.Name.Name); - WriteCommaSeparatedListInParenthesis(propertyDeclaration.Parameters, false); - if (!propertyDeclaration.ReturnType.IsNull) { - Space(); - WriteKeyword("As"); - WriteAttributes(propertyDeclaration.ReturnTypeAttributes); - propertyDeclaration.ReturnType.AcceptVisitor(this, data); - } - - bool needsBody = !propertyDeclaration.Getter.Body.IsNull || !propertyDeclaration.Setter.Body.IsNull; - - if (needsBody) { - NewLine(); - Indent(); - - if (!propertyDeclaration.Getter.Body.IsNull) { - propertyDeclaration.Getter.AcceptVisitor(this, data); - } - - if (!propertyDeclaration.Setter.Body.IsNull) { - propertyDeclaration.Setter.AcceptVisitor(this, data); - } - Unindent(); - - WriteKeyword("End"); - WriteKeyword("Property"); - } - NewLine(); - - return EndNode(propertyDeclaration); - } + public object VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, object data) { @@ -1788,6 +1809,7 @@ namespace ICSharpCode.NRefactory.VB WriteImplementsClause(eventDeclaration.ImplementsClause); if (eventDeclaration.IsCustom) { + MarkFoldStart(); NewLine(); Indent(); @@ -1798,6 +1820,7 @@ namespace ICSharpCode.NRefactory.VB Unindent(); WriteKeyword("End"); WriteKeyword("Event"); + MarkFoldEnd(); } NewLine(); @@ -2070,12 +2093,14 @@ namespace ICSharpCode.NRefactory.VB operatorDeclaration.ReturnType.AcceptVisitor(this, data); } if (!operatorDeclaration.Body.IsNull) { + MarkFoldStart(); NewLine(); Indent(); WriteBlock(operatorDeclaration.Body); Unindent(); WriteKeyword("End"); WriteKeyword("Operator"); + MarkFoldEnd(); } NewLine(); diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs index 933e966959..f5b610d163 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs @@ -89,5 +89,13 @@ namespace ICSharpCode.NRefactory.VB textWriter.Write("'"); textWriter.WriteLine(content); } + + public void MarkFoldStart() + { + } + + public void MarkFoldEnd() + { + } } } From 5a00a6cb6d6c9f71299c1562b0e3572e5d9880d9 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 15 Jul 2011 20:48:36 +0200 Subject: [PATCH 46/57] Mark ICSharpCode.NRefactory.VB as AnyCPU. --- .../ICSharpCode.NRefactory.VB.csproj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 136c0a5cc8..c100ed7176 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -3,16 +3,20 @@ {7B82B671-419F-45F4-B778-D9286F996EFA} Debug - x86 + AnyCPU Library ICSharpCode.NRefactory.VB ICSharpCode.NRefactory.VB v4.0 Properties Client + False + False + 4 + false - - x86 + + AnyCPU bin\Debug\ From 610924ed7cb4d9f2cda5402d92f5871d1e08ca9f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 22:21:09 +0200 Subject: [PATCH 47/57] fix InvalidCastException in For-Next detection --- .../Visitors/CSharpToVBConverterVisitor.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 5dde5328e4..c1334396b3 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -1088,7 +1088,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors var increment = match.Get("increment").SingleOrDefault(); var factorExpr = (Expression)match.Get("factor").SingleOrDefault().AcceptVisitor(this, data); - if (increment.Operator == CSharp.AssignmentOperatorType.Add && (factorExpr is PrimitiveExpression && (int)((PrimitiveExpression)factorExpr).Value != 1)) + if (increment.Operator == CSharp.AssignmentOperatorType.Add && (factorExpr is PrimitiveExpression && !IsEqual(((PrimitiveExpression)factorExpr).Value, 1))) stepExpr = factorExpr; if (increment.Operator == CSharp.AssignmentOperatorType.Subtract) stepExpr = new UnaryOperatorExpression(UnaryOperatorType.Minus, factorExpr); @@ -1113,6 +1113,28 @@ namespace ICSharpCode.NRefactory.VB.Visitors return EndNode(forStatement, stmt); } + bool IsEqual(object value, int num) + { + if (value is byte) + return (byte)value == num; + if (value is sbyte) + return (sbyte)value == num; + if (value is short) + return (short)value == num; + if (value is ushort) + return (ushort)value == num; + if (value is int) + return (int)value == num; + if (value is uint) + return (uint)value == num; + if (value is long) + return (long)value == num; + if (value is ulong) + return (ulong)value == (ulong)num; + + throw new InvalidCastException(); + } + public AstNode VisitGotoCaseStatement(CSharp.GotoCaseStatement gotoCaseStatement, object data) { throw new NotImplementedException(); From 04d816cdf9df02508d543731d2a3f3cbc0910758 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 22:30:24 +0200 Subject: [PATCH 48/57] fix bug in checked statement handling --- .../Visitors/CSharpToVBConverterVisitor.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index c1334396b3..8d4e2a9f6d 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -897,10 +897,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitCheckedStatement(CSharp.CheckedStatement checkedStatement, object data) { - blocks.Peek().AddChild(new Comment(" The following expression was wrapped in a checked-expression", false), AstNode.Roles.Comment); + blocks.Peek().AddChild(new Comment(" The following expression was wrapped in a checked-statement", false), AstNode.Roles.Comment); var body = (BlockStatement)checkedStatement.Body.AcceptVisitor(this, data); - blocks.Peek().AddRange(body); + foreach (var stmt in body) { + stmt.Remove(); + blocks.Peek().Add(stmt); + } return EndNode(checkedStatement, null); } From 4c8a11c89810f60f126f27006c0a460307217c03 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 23:08:28 +0200 Subject: [PATCH 49/57] improve conversion of special characters in string literals --- .../Ast/Expressions/IdentifierExpression.cs | 10 +++ .../Visitors/CSharpToVBConverterVisitor.cs | 90 ++++++++++++++----- 2 files changed, 77 insertions(+), 23 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs index fa3b642d54..6bd77cb9bd 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs @@ -7,6 +7,16 @@ namespace ICSharpCode.NRefactory.VB.Ast { public class IdentifierExpression : Expression { + public IdentifierExpression() + { + + } + + public IdentifierExpression(Identifier identifier) + { + this.Identifier = identifier; + } + public Identifier Identifier { get { return GetChildByRole(Roles.Identifier); } set { SetChildByRole(Roles.Identifier, value); } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 8d4e2a9f6d..0b3e290251 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -460,7 +460,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors { Expression expr; - if ((primitiveExpression.Value is string || primitiveExpression.Value is char) && primitiveExpression.Value.ToString().IndexOfAny(new[] {'\r', '\n', '\t'}) > -1) + if (!string.IsNullOrEmpty(primitiveExpression.Value as string) || primitiveExpression.Value is char) expr = ConvertToConcat(primitiveExpression.Value.ToString()); else expr = new PrimitiveExpression(primitiveExpression.Value); @@ -474,29 +474,73 @@ namespace ICSharpCode.NRefactory.VB.Visitors int start = 0; for (int i = 0; i < literal.Length; i++) { - if (literal[i] == '\r') { - string part = literal.Substring(start, i - start); - if (!string.IsNullOrEmpty(part)) - parts.Push(new PrimitiveExpression(part)); - if (i + 1 < literal.Length && literal[i + 1] == '\n') { - i++; - parts.Push(new IdentifierExpression() { Identifier = "vbCrLf" }); - } else - parts.Push(new IdentifierExpression() { Identifier = "vbCr" }); - start = i + 1; - } else if (literal[i] == '\n') { - string part = literal.Substring(start, i - start); - if (!string.IsNullOrEmpty(part)) - parts.Push(new PrimitiveExpression(part)); - parts.Push(new IdentifierExpression() { Identifier = "vbLf" }); - start = i + 1; - } else if (literal[i] == '\t') { - string part = literal.Substring(start, i - start); - if (!string.IsNullOrEmpty(part)) - parts.Push(new PrimitiveExpression(part)); - parts.Push(new IdentifierExpression() { Identifier = "vbTab" }); - start = i + 1; + string part; + switch (literal[i]) { + case '\0': + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression("vbNullChar")); + start = i + 1; + break; + case '\b': + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression("vbBack")); + start = i + 1; + break; + case '\f': + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression("vbFormFeed")); + start = i + 1; + break; + case '\r': + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + if (i + 1 < literal.Length && literal[i + 1] == '\n') { + i++; + parts.Push(new IdentifierExpression("vbCrLf")); + } else + parts.Push(new IdentifierExpression("vbCr")); + start = i + 1; + break; + case '\n': + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression("vbLf")); + start = i + 1; + break; + case '\t': + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression("vbTab")); + start = i + 1; + break; + case '\v': + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new IdentifierExpression("vbVerticalTab")); + start = i + 1; + break; + default: + if ((int)literal[i] > 255) { + part = literal.Substring(start, i - start); + if (!string.IsNullOrEmpty(part)) + parts.Push(new PrimitiveExpression(part)); + parts.Push(new InvocationExpression(new IdentifierExpression("ChrW"), new PrimitiveExpression((int)literal[i]))); + } else + continue; + start = i + 1; + break; } + } if (start < literal.Length) { From 1d8a2944f8dd913b99f7fde90c45ee151b1c9e62 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 23:15:17 +0200 Subject: [PATCH 50/57] map true/false operator to IsTrue/IsFalse --- .../Visitors/CSharpToVBConverterVisitor.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 0b3e290251..737228e86a 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -1619,9 +1619,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors break; case ICSharpCode.NRefactory.CSharp.OperatorType.Increment: case ICSharpCode.NRefactory.CSharp.OperatorType.Decrement: + throw new NotSupportedException(); case ICSharpCode.NRefactory.CSharp.OperatorType.True: + result.Operator = OverloadableOperatorType.IsTrue; + break; case ICSharpCode.NRefactory.CSharp.OperatorType.False: - throw new NotSupportedException(); + result.Operator = OverloadableOperatorType.IsFalse; + break; case ICSharpCode.NRefactory.CSharp.OperatorType.Implicit: result.Modifiers |= Modifiers.Widening; result.Operator = OverloadableOperatorType.CType; From ebeef27c8f14d546915ddd989be613d973eedf39 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 23:27:24 +0200 Subject: [PATCH 51/57] convert increment/decrement operator overloads to op_Increment/op_Decrement methods --- .../Visitors/CSharpToVBConverterVisitor.cs | 185 ++++++++++-------- 1 file changed, 99 insertions(+), 86 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 737228e86a..d18bc914e0 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -1606,99 +1606,112 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitOperatorDeclaration(CSharp.OperatorDeclaration operatorDeclaration, object data) { - var result = new OperatorDeclaration(); - + MemberDeclaration result; members.Push(new MemberInfo()); - ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), result.Attributes); - ConvertNodes(operatorDeclaration.ModifierTokens, result.ModifierTokens); - switch (operatorDeclaration.OperatorType) { - case ICSharpCode.NRefactory.CSharp.OperatorType.LogicalNot: - case ICSharpCode.NRefactory.CSharp.OperatorType.OnesComplement: - result.Operator = OverloadableOperatorType.Not; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Increment: - case ICSharpCode.NRefactory.CSharp.OperatorType.Decrement: - throw new NotSupportedException(); - case ICSharpCode.NRefactory.CSharp.OperatorType.True: - result.Operator = OverloadableOperatorType.IsTrue; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.False: - result.Operator = OverloadableOperatorType.IsFalse; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Implicit: - result.Modifiers |= Modifiers.Widening; - result.Operator = OverloadableOperatorType.CType; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Explicit: - result.Modifiers |= Modifiers.Narrowing; - result.Operator = OverloadableOperatorType.CType; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Addition: - result.Operator = OverloadableOperatorType.Add; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Subtraction: - result.Operator = OverloadableOperatorType.Subtract; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.UnaryPlus: - result.Operator = OverloadableOperatorType.UnaryPlus; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.UnaryNegation: - result.Operator = OverloadableOperatorType.UnaryMinus; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Multiply: - result.Operator = OverloadableOperatorType.Multiply; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Division: - result.Operator = OverloadableOperatorType.Divide; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Modulus: - result.Operator = OverloadableOperatorType.Modulus; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.BitwiseAnd: - result.Operator = OverloadableOperatorType.BitwiseAnd; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.BitwiseOr: - result.Operator = OverloadableOperatorType.BitwiseOr; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.ExclusiveOr: - result.Operator = OverloadableOperatorType.ExclusiveOr; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.LeftShift: - result.Operator = OverloadableOperatorType.ShiftLeft; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.RightShift: - result.Operator = OverloadableOperatorType.ShiftRight; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Equality: - result.Operator = OverloadableOperatorType.Equality; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.Inequality: - result.Operator = OverloadableOperatorType.InEquality; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.GreaterThan: - result.Operator = OverloadableOperatorType.GreaterThan; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.LessThan: - result.Operator = OverloadableOperatorType.LessThan; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.GreaterThanOrEqual: - result.Operator = OverloadableOperatorType.GreaterThanOrEqual; - break; - case ICSharpCode.NRefactory.CSharp.OperatorType.LessThanOrEqual: - result.Operator = OverloadableOperatorType.LessThanOrEqual; - break; - default: - throw new Exception("Invalid value for OperatorType"); + if (operatorDeclaration.OperatorType == CSharp.OperatorType.Increment || operatorDeclaration.OperatorType == CSharp.OperatorType.Decrement) { + var m = new MethodDeclaration(); + result = m; + + ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), m.Attributes); + ConvertNodes(operatorDeclaration.ModifierTokens, m.ModifierTokens); + m.Name = operatorDeclaration.OperatorType == CSharp.OperatorType.Increment ? "op_Increment" : "op_Decrement"; + ConvertNodes(operatorDeclaration.Parameters, m.Parameters); + ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), m.ReturnTypeAttributes); + m.ReturnType = (AstType)operatorDeclaration.ReturnType.AcceptVisitor(this, data); + m.Body = (BlockStatement)operatorDeclaration.Body.AcceptVisitor(this, data); + } else { + var op = new OperatorDeclaration(); + result = op; + + ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), op.Attributes); + ConvertNodes(operatorDeclaration.ModifierTokens, op.ModifierTokens); + switch (operatorDeclaration.OperatorType) { + case ICSharpCode.NRefactory.CSharp.OperatorType.LogicalNot: + case ICSharpCode.NRefactory.CSharp.OperatorType.OnesComplement: + op.Operator = OverloadableOperatorType.Not; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.True: + op.Operator = OverloadableOperatorType.IsTrue; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.False: + op.Operator = OverloadableOperatorType.IsFalse; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Implicit: + op.Modifiers |= Modifiers.Widening; + op.Operator = OverloadableOperatorType.CType; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Explicit: + op.Modifiers |= Modifiers.Narrowing; + op.Operator = OverloadableOperatorType.CType; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Addition: + op.Operator = OverloadableOperatorType.Add; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Subtraction: + op.Operator = OverloadableOperatorType.Subtract; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.UnaryPlus: + op.Operator = OverloadableOperatorType.UnaryPlus; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.UnaryNegation: + op.Operator = OverloadableOperatorType.UnaryMinus; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Multiply: + op.Operator = OverloadableOperatorType.Multiply; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Division: + op.Operator = OverloadableOperatorType.Divide; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Modulus: + op.Operator = OverloadableOperatorType.Modulus; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.BitwiseAnd: + op.Operator = OverloadableOperatorType.BitwiseAnd; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.BitwiseOr: + op.Operator = OverloadableOperatorType.BitwiseOr; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.ExclusiveOr: + op.Operator = OverloadableOperatorType.ExclusiveOr; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.LeftShift: + op.Operator = OverloadableOperatorType.ShiftLeft; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.RightShift: + op.Operator = OverloadableOperatorType.ShiftRight; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Equality: + op.Operator = OverloadableOperatorType.Equality; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.Inequality: + op.Operator = OverloadableOperatorType.InEquality; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.GreaterThan: + op.Operator = OverloadableOperatorType.GreaterThan; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.LessThan: + op.Operator = OverloadableOperatorType.LessThan; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.GreaterThanOrEqual: + op.Operator = OverloadableOperatorType.GreaterThanOrEqual; + break; + case ICSharpCode.NRefactory.CSharp.OperatorType.LessThanOrEqual: + op.Operator = OverloadableOperatorType.LessThanOrEqual; + break; + default: + throw new Exception("Invalid value for OperatorType"); + } + ConvertNodes(operatorDeclaration.Parameters, op.Parameters); + ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), op.ReturnTypeAttributes); + op.ReturnType = (AstType)operatorDeclaration.ReturnType.AcceptVisitor(this, data); + op.Body = (BlockStatement)operatorDeclaration.Body.AcceptVisitor(this, data); } - ConvertNodes(operatorDeclaration.Parameters, result.Parameters); - ConvertNodes(operatorDeclaration.Attributes.Where(section => section.AttributeTarget == "return"), result.ReturnTypeAttributes); - result.ReturnType = (AstType)operatorDeclaration.ReturnType.AcceptVisitor(this, data); - result.Body = (BlockStatement)operatorDeclaration.Body.AcceptVisitor(this, data); members.Pop(); return EndNode(operatorDeclaration, result); + } public AstNode VisitParameterDeclaration(CSharp.ParameterDeclaration parameterDeclaration, object data) From e3a301e09a3c1d4f335eb25d77b367fa7fc47632 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Jul 2011 08:24:33 +0200 Subject: [PATCH 52/57] fix output of Inherits/Implements clauses --- .../OutputVisitor/OutputVisitor.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index d6164785db..ac58945a37 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -238,13 +238,24 @@ namespace ICSharpCode.NRefactory.VB WriteModifiers(typeDeclaration.ModifierTokens); WriteClassTypeKeyword(typeDeclaration); WriteIdentifier(typeDeclaration.Name.Name); + MarkFoldStart(); + NewLine(); + if (!typeDeclaration.InheritsType.IsNull) { - Space(); + Indent(); WriteKeyword("Inherits"); typeDeclaration.InheritsType.AcceptVisitor(this, data); + Unindent(); + NewLine(); } - WriteImplementsClause(typeDeclaration.ImplementsTypes); - MarkFoldStart(); + if (typeDeclaration.ImplementsTypes.Any()) { + Indent(); + WriteImplementsClause(typeDeclaration.ImplementsTypes); + Unindent(); + NewLine(); + } + + if (!typeDeclaration.InheritsType.IsNull || typeDeclaration.ImplementsTypes.Any()) NewLine(); WriteMembers(typeDeclaration.Members); @@ -1196,7 +1207,6 @@ namespace ICSharpCode.NRefactory.VB void WriteImplementsClause(AstNodeCollection implementsClause) { if (implementsClause.Any()) { - Space(); WriteKeyword("Implements"); WriteCommaSeparatedList(implementsClause); } From fbc8b85221b7290915db356648e77f286d0ce589 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Jul 2011 09:48:17 +0200 Subject: [PATCH 53/57] convert static classes to modules --- .../Visitors/CSharpToVBConverterVisitor.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index d18bc914e0..99f74c2388 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -837,6 +837,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors } else type.ClassType = typeDeclaration.ClassType; + if ((typeDeclaration.Modifiers & CSharp.Modifiers.Static) == CSharp.Modifiers.Static) { + type.ClassType = ClassType.Module; + typeDeclaration.Modifiers &= ~CSharp.Modifiers.Static; + } + ConvertNodes(typeDeclaration.Attributes, type.Attributes); ConvertNodes(typeDeclaration.ModifierTokens, type.ModifierTokens); From 03465125950a97f638fb54a09faa3f247121a43a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Jul 2011 09:58:01 +0200 Subject: [PATCH 54/57] remove shared modifier from module members --- .../Visitors/CSharpToVBConverterVisitor.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 99f74c2388..15cfcec0dd 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -1411,6 +1411,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors var result = new EventDeclaration(); ConvertNodes(eventDeclaration.Attributes, result.Attributes); + if (types.Any() && types.Peek().ClassType == ClassType.Module) + eventDeclaration.Modifiers &= ~CSharp.Modifiers.Static; result.Modifiers = ConvertModifiers(eventDeclaration.Modifiers, eventDeclaration); result.Name = evt.Name; result.ReturnType = (AstType)eventDeclaration.ReturnType.AcceptVisitor(this, data); @@ -1430,6 +1432,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors members.Push(new MemberInfo()); ConvertNodes(customEventDeclaration.Attributes, result.Attributes); + if (types.Any() && types.Peek().ClassType == ClassType.Module) + customEventDeclaration.Modifiers &= ~CSharp.Modifiers.Static; result.Modifiers = ConvertModifiers(customEventDeclaration.Modifiers, customEventDeclaration); result.IsCustom = true; result.Name = new Identifier(customEventDeclaration.Name, AstLocation.Empty); @@ -1453,6 +1457,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors members.Push(new MemberInfo()); ConvertNodes(fieldDeclaration.Attributes, decl.Attributes); + if (types.Any() && types.Peek().ClassType == ClassType.Module) + fieldDeclaration.Modifiers &= ~CSharp.Modifiers.Static; decl.Modifiers = ConvertModifiers(fieldDeclaration.Modifiers, fieldDeclaration); ConvertNodes(fieldDeclaration.Variables, decl.Variables); @@ -1469,6 +1475,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(indexerDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), decl.Attributes); decl.Getter = (Accessor)indexerDeclaration.Getter.AcceptVisitor(this, data); + if (types.Any() && types.Peek().ClassType == ClassType.Module) + indexerDeclaration.Modifiers &= ~CSharp.Modifiers.Static; decl.Modifiers = ConvertModifiers(indexerDeclaration.Modifiers, indexerDeclaration); decl.Name = new Identifier(indexerDeclaration.Name, AstLocation.Empty); ConvertNodes(indexerDeclaration.Parameters, decl.Parameters); @@ -1495,6 +1503,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitMethodDeclaration(CSharp.MethodDeclaration methodDeclaration, object data) { CSharp.Attribute attr; + + if (types.Any() && types.Peek().ClassType == ClassType.Module) + methodDeclaration.Modifiers &= ~CSharp.Modifiers.Static; + if ((methodDeclaration.Modifiers & CSharp.Modifiers.Extern) == CSharp.Modifiers.Extern && HasAttribute(methodDeclaration.Attributes, "System.Runtime.InteropServices.DllImportAttribute", out attr)) { var result = new ExternalMethodDeclaration(); @@ -1543,6 +1555,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors methodDeclaration.Name)); if (!result.IsSub) result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); + result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); if (members.Pop().inIterator) { @@ -1614,6 +1627,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors MemberDeclaration result; members.Push(new MemberInfo()); + if (types.Any() && types.Peek().ClassType == ClassType.Module) + operatorDeclaration.Modifiers &= ~CSharp.Modifiers.Static; + if (operatorDeclaration.OperatorType == CSharp.OperatorType.Increment || operatorDeclaration.OperatorType == CSharp.OperatorType.Decrement) { var m = new MethodDeclaration(); result = m; @@ -1764,6 +1780,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors members.Push(new MemberInfo()); + if (types.Any() && types.Peek().ClassType == ClassType.Module) + propertyDeclaration.Modifiers &= ~CSharp.Modifiers.Static; + ConvertNodes(propertyDeclaration.Attributes.Where(section => section.AttributeTarget != "return"), decl.Attributes); decl.Getter = (Accessor)propertyDeclaration.Getter.AcceptVisitor(this, data); decl.Modifiers = ConvertModifiers(propertyDeclaration.Modifiers, propertyDeclaration); From c428246d2ce4a37f270a8d8ba3a6a98fa41525e5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Jul 2011 16:11:13 +0200 Subject: [PATCH 55/57] use Is/IsNot for reference equality checks; add extension attribute for extension methods --- ICSharpCode.NRefactory.VB/Ast/Identifier.cs | 4 +- .../Ast/TypeName/AstType.cs | 19 ++++ .../Visitors/CSharpToVBConverterVisitor.cs | 90 +++++++++++++++++-- 3 files changed, 105 insertions(+), 8 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Identifier.cs b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs index 99028a8964..0ffa568c96 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Identifier.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Identifier.cs @@ -89,8 +89,8 @@ namespace ICSharpCode.NRefactory.VB.Ast public override string ToString() { - return string.Format("[Identifier Name={0}, StartLocation={1}, TypeCharacter{4}]", - name, startLocation, TypeCharacter); + return string.Format("{0}", + name); } } } diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs index d9f7e4ce26..ca39bd369e 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs @@ -2,6 +2,7 @@ // This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; +using System.Linq; namespace ICSharpCode.NRefactory.VB.Ast { @@ -70,6 +71,24 @@ namespace ICSharpCode.NRefactory.VB.Ast return new ComposedType { BaseType = this }.MakeArrayType(rank); } + public static AstType FromName(string fullName) + { + if (string.IsNullOrEmpty(fullName)) + throw new ArgumentNullException("fullName"); + fullName = fullName.Trim(); + if (!fullName.Contains(".")) + return new SimpleType(fullName); + string[] parts = fullName.Split('.'); + + AstType type = new SimpleType(parts.First()); + + foreach (var part in parts.Skip(1)) { + type = new QualifiedType(type, part); + } + + return type; + } + /// /// Builds an expression that can be used to access a static member on this type. /// diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 15cfcec0dd..89ada8a5cc 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -16,7 +16,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors string RootNamespace { get; } string GetTypeNameForAttribute(CSharp.Attribute attribute); ClassType GetClassTypeForAstType(CSharp.AstType type); - IType ResolveExpression(CSharp.Expression expression); + TypeCode ResolveExpression(CSharp.Expression expression); + bool? IsReferenceType(CSharp.Expression expression); + ITypeResolveContext ResolveContext { get; } + IType ResolveType(AstType type, TypeDeclaration entity = null); } /// @@ -177,8 +180,6 @@ namespace ICSharpCode.NRefactory.VB.Visitors var op = BinaryOperatorType.None; var right = (Expression)binaryOperatorExpression.Right.AcceptVisitor(this, data); - // TODO obj <> Nothing is wrong; correct would be obj IsNot Nothing - switch (binaryOperatorExpression.Operator) { case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseAnd: op = BinaryOperatorType.BitwiseAnd; @@ -202,10 +203,16 @@ namespace ICSharpCode.NRefactory.VB.Visitors op = BinaryOperatorType.GreaterThanOrEqual; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Equality: - op = BinaryOperatorType.Equality; + if (IsReferentialEquality(binaryOperatorExpression)) + op = BinaryOperatorType.ReferenceEquality; + else + op = BinaryOperatorType.Equality; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.InEquality: - op = BinaryOperatorType.InEquality; + if (IsReferentialEquality(binaryOperatorExpression)) + op = BinaryOperatorType.ReferenceInequality; + else + op = BinaryOperatorType.InEquality; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThan: op = BinaryOperatorType.LessThan; @@ -248,6 +255,17 @@ namespace ICSharpCode.NRefactory.VB.Visitors return EndNode(binaryOperatorExpression, new BinaryOperatorExpression(left, op, right)); } + bool IsReferentialEquality(CSharp.BinaryOperatorExpression binaryOperatorExpression) + { + var left = provider.IsReferenceType(binaryOperatorExpression.Left); + var right = provider.IsReferenceType(binaryOperatorExpression.Right); + + var leftCode = provider.ResolveExpression(binaryOperatorExpression.Left); + var rightCode = provider.ResolveExpression(binaryOperatorExpression.Right); + + return (left == true || right == true) && (leftCode != TypeCode.String && rightCode != TypeCode.String); + } + public AstNode VisitCastExpression(CSharp.CastExpression castExpression, object data) { var expr = new CastExpression(); @@ -806,6 +824,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors if (typeDeclaration.ClassType == ClassType.Enum) { var type = new EnumDeclaration(); + CopyAnnotations(typeDeclaration, type); ConvertNodes(typeDeclaration.Attributes, type.Attributes); ConvertNodes(typeDeclaration.ModifierTokens, type.ModifierTokens); @@ -823,6 +842,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors return EndNode(typeDeclaration, type); } else { var type = new TypeDeclaration(); + CopyAnnotations(typeDeclaration, type); CSharp.Attribute stdModAttr; @@ -1417,6 +1437,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors result.Name = evt.Name; result.ReturnType = (AstType)eventDeclaration.ReturnType.AcceptVisitor(this, data); +// CreateImplementsClausesForEvent(result); + types.Peek().Members.Add(result); } @@ -1441,7 +1463,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors if (!customEventDeclaration.PrivateImplementationType.IsNull) result.ImplementsClause.Add( new InterfaceMemberSpecifier((AstType)customEventDeclaration.PrivateImplementationType.AcceptVisitor(this, data), customEventDeclaration.Name)); - +// else +// CreateImplementsClausesForEvent(result); result.AddHandlerBlock = (Accessor)customEventDeclaration.AddAccessor.AcceptVisitor(this, data); result.RemoveHandlerBlock = (Accessor)customEventDeclaration.RemoveAccessor.AcceptVisitor(this, data); @@ -1553,9 +1576,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors result.ImplementsClause.Add( new InterfaceMemberSpecifier((AstType)methodDeclaration.PrivateImplementationType.AcceptVisitor(this, data), methodDeclaration.Name)); +// else +// CreateImplementsClausesForMethod(result); if (!result.IsSub) result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); + if (methodDeclaration.IsExtensionMethod) { + result.Attributes.Add( + new AttributeBlock { + Attributes = { + new Ast.Attribute { + Type = AstType.FromName("System.Runtime.CompilerServices.ExtensionAttribute") + } + } + }); + } + result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); if (members.Pop().inIterator) { @@ -1566,6 +1602,38 @@ namespace ICSharpCode.NRefactory.VB.Visitors } } + void CreateImplementsClausesForMethod(MethodDeclaration result) + { + if (!types.Any()) return; + var current = types.Peek(); + if (current.ClassType == ClassType.Interface) + return; + + foreach (var type in current.ImplementsTypes) { + var resolved = provider.ResolveType(type, current); + var found = resolved.GetMembers(provider.ResolveContext, m => m.EntityType == EntityType.Method && m.Name == result.Name.Name); + if (found.FirstOrDefault() != null) { + result.ImplementsClause.Add(new InterfaceMemberSpecifier((AstType)type.Clone(), found.FirstOrDefault().Name)); + } + } + } + + void CreateImplementsClausesForEvent(EventDeclaration result) + { + if (!types.Any()) return; + var current = types.Peek(); + if (current.ClassType == ClassType.Interface) + return; + + foreach (var type in current.ImplementsTypes) { + var resolved = provider.ResolveType(type, current); + var found = resolved.GetMembers(provider.ResolveContext, m => m.EntityType == EntityType.Event && m.Name == result.Name.Name); + if (found.FirstOrDefault() != null) { + result.ImplementsClause.Add(new InterfaceMemberSpecifier((AstType)type.Clone(), found.FirstOrDefault().Name)); + } + } + } + string ConvertAlias(CSharp.AstNodeCollection arguments) { var pattern = new CSharp.AssignmentExpression() { @@ -2106,8 +2174,18 @@ namespace ICSharpCode.NRefactory.VB.Visitors T EndNode(CSharp.AstNode node, T result) where T : VB.AstNode { + if (result != null) { + CopyAnnotations(node, result); + } + return result; } + + void CopyAnnotations(CSharp.AstNode node, T result) where T : VB.AstNode + { + foreach (var ann in node.Annotations) + result.AddAnnotation(ann); + } bool HasAttribute(CSharp.AstNodeCollection attributes, string name, out CSharp.Attribute foundAttribute) { From a8544216691d9449a32b68161b567e199497feb9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 17 Jul 2011 18:56:43 +0200 Subject: [PATCH 56/57] corrected spelling of Overrides-modifier; convert virtual to Overridable and override to Overrides --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 2 +- ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs | 6 +++--- .../Visitors/CSharpToVBConverterVisitor.cs | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index a3fa8d6184..e030125433 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.VB.Ast Const = 0x0200, Shared = 0x0400, Static = 0x0800, - Override = 0x1000, + Overrides = 0x1000, ReadOnly = 0x2000, Shadows = 0x4000, Partial = 0x8000, diff --git a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs index 2039901e47..4b5a57ce3c 100644 --- a/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs +++ b/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -50,7 +50,7 @@ namespace ICSharpCode.NRefactory.VB.Ast new KeyValuePair(Modifiers.Const, "Const".Length), new KeyValuePair(Modifiers.Shared, "Shared".Length), new KeyValuePair(Modifiers.Static, "Static".Length), - new KeyValuePair(Modifiers.Override, "Override".Length), + new KeyValuePair(Modifiers.Overrides, "Overrides".Length), new KeyValuePair(Modifiers.ReadOnly, "ReadOnly".Length), new KeyValuePair(Modifiers.WriteOnly, "WriteOnly".Length), new KeyValuePair(Modifiers.Shadows, "Shadows".Length), @@ -109,8 +109,8 @@ namespace ICSharpCode.NRefactory.VB.Ast return "Shared"; case Modifiers.Static: return "Static"; - case Modifiers.Override: - return "Override"; + case Modifiers.Overrides: + return "Overrides"; case Modifiers.ReadOnly: return "ReadOnly"; case Modifiers.Shadows: diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 89ada8a5cc..10d142671b 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -2112,6 +2112,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors if (readable && !writeable) mod |= Modifiers.ReadOnly; + if ((modifier & CSharp.Modifiers.Override) == CSharp.Modifiers.Override) + mod |= Modifiers.Overrides; + if ((modifier & CSharp.Modifiers.Virtual) == CSharp.Modifiers.Virtual) + mod |= Modifiers.Overridable; return mod; } From 1398d8a39daddd53353907c308a622771805e404 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 18 Jul 2011 07:28:45 +0200 Subject: [PATCH 57/57] add missing space after Case keyword --- ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index ac58945a37..d359cb8973 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2145,8 +2145,10 @@ namespace ICSharpCode.NRefactory.VB WriteKeyword("Case"); if (caseStatement.Clauses.Count == 1 && caseStatement.Clauses.First().Expression.IsNull) WriteKeyword("Else"); - else + else { + Space(); WriteCommaSeparatedList(caseStatement.Clauses); + } NewLine(); Indent(); caseStatement.Body.AcceptVisitor(this, data);