From 5f5a38c0f6f2ff052585c9d9b426b33d4540592c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 8 May 2011 11:50:18 +0200 Subject: [PATCH] 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; + } + } +}