From 9b7a082e24e0be6a60586fdb2247e9d6692b6eed Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 22 Dec 2006 16:09:16 +0000 Subject: [PATCH] Add partial C# 3.0 support. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2191 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../CodeCompletionProvider.cs | 6 +- samples/CSharpCodeCompletion/MainForm.cs | 27 +- .../Boo/BooBinding/Project/BooBinding.csproj | 1 - .../Boo/BooBinding/Project/Src/BooAmbience.cs | 4 + .../Src/CodeCompletion/ConvertVisitor.cs | 6 +- .../Src/CodeCompletion/ElementReturnType.cs | 60 - .../Src/CodeCompletion/InferredReturnType.cs | 10 +- .../Src/CodeCompletion/ResolveVisitor.cs | 2 +- .../CodeCompletion/VariableLookupVisitor.cs | 6 +- .../Project/ConvertVisitorExpressions.cs | 22 +- .../Project/ConvertVisitorLINQ.cs | 67 + .../Project/NRefactoryToBooConverter.csproj | 1 + .../Src/Project/VBToCSharpConverter.cs | 2 +- .../Src/Project/CSharpToVBConverter.cs | 8 +- .../NRefactoryDesignerLoader.cs | 2 +- .../Project/Hornung.ResourceToolkit.addin | 4 +- .../Resolver/BclNRefactoryResourceResolver.cs | 26 +- .../Resolver/PositionTrackingAstVisitor.cs | 4 +- .../PropertyFieldAssociationVisitor.cs | 12 +- .../StartPage/Project/Src/ICSharpCodePage.cs | 2 +- src/Libraries/NRefactory/NRefactory.sln | 6 +- .../NRefactoryASTGenerator/AST/Expressions.cs | 85 +- .../NRefactoryASTGenerator/AST/TypeLevel.cs | 3 +- .../NRefactoryASTGenerator/Attributes.cs | 22 +- .../NRefactory/NRefactoryASTGenerator/Main.cs | 4 +- .../NRefactory/Project/NRefactory.csproj | 5 +- .../NRefactory/Project/Src/Ast/Enums.cs | 8 + .../Project/Src/Ast/General/BlockStatement.cs | 16 +- .../Project/Src/Ast/General/Expression.cs | 16 +- .../Project/Src/Ast/General/Statement.cs | 14 +- .../NRefactory/Project/Src/Ast/Generated.cs | 806 +++- .../Project/Src/Ast/TypeReference.cs | 15 +- .../Src/EnvironmentInformationProvider.cs | 4 +- .../NRefactory/Project/Src/IAstVisitor.cs | 24 +- .../Project/Src/Lexer/BuildKeywords.pl | 14 +- .../Project/Src/Lexer/CSharp/KeywordList.txt | 23 +- .../Project/Src/Lexer/CSharp/Keywords.cs | 24 +- .../Project/Src/Lexer/CSharp/Lexer.cs | 5 +- .../Project/Src/Lexer/CSharp/Tokens.cs | 206 +- .../Project/Src/Parser/CSharp/CSharpParser.cs | 122 +- .../Project/Src/Parser/CSharp/Parser.cs | 4143 ++++++++++------- .../Project/Src/Parser/CSharp/cs.ATG | 556 ++- .../Project/Src/Parser/VBNet/Parser.cs | 14 +- .../Project/Src/Parser/VBNet/VBNET.ATG | 18 +- .../NRefactory/Project/Src/Parser/gen.bat | 6 +- .../CSharp/CSharpOutputVisitor.cs | 680 +-- .../Src/PrettyPrinter/IOutputAstVisitor.cs | 8 +- .../Src/PrettyPrinter/NodeInformVisitor.cs | 67 - .../Src/PrettyPrinter/SpecialNodesInserter.cs | 4 +- .../PrettyPrinter/VBNet/VBNetOutputVisitor.cs | 565 ++- .../Src/Visitors/AbstractASTVisitor.cs | 106 +- .../Src/Visitors/AbstractAstTransformer.cs | 183 +- .../Src/Visitors/CSharpConstructsVisitor.cs | 8 +- .../Visitors/CSharpToVBNetConvertVisitor.cs | 25 - .../Src/Visitors/CodeDOMOutputVisitor.cs | 13 +- .../Src/Visitors/ConvertVisitorBase.cs | 19 + .../Src/Visitors/LookupTableVisitor.cs | 93 +- .../Src/Visitors/NodeTrackingAstVisitor.cs | 523 ++- .../Src/Visitors/RenameIdentifierVisitor.cs | 65 + .../Src/Visitors/ToCSharpConvertVisitor.cs | 2 +- .../Src/Visitors/ToVBNetConvertVisitor.cs | 18 +- .../ToVBNetRenameConflictingVariables.cs | 91 + .../Visitors/VBNetConstructsConvertVisitor.cs | 64 +- .../Visitors/VBNetToCSharpConvertVisitor.cs | 3 +- .../Test/Lexer/CSharp/CustomLexerTests.cs | 10 + .../Test/Lexer/CSharp/LexerTests.cs | 104 + .../NRefactory/Test/NRefactoryTests.csproj | 2 + .../Test/Output/CSharp/CSharpOutputTest.cs | 117 +- .../Output/CSharp/VBToCSharpConverterTest.cs | 10 + .../Output/VBNet/CSharpToVBConverterTest.cs | 15 +- .../Expressions/ArrayCreateExpressionTests.cs | 9 + .../Expressions/LambdaExpressionTests.cs | 69 + .../ObjectCreateExpressionTests.cs | 116 + .../Expressions/QueryExpressionTests.cs | 53 + .../GlobalScope/DelegateDeclarationTests.cs | 2 +- .../Parser/TypeLevel/FieldDeclarationTests.cs | 2 + .../TypeLevel/MethodDeclarationTests.cs | 27 +- .../Src/Commands/VBConverter/ConvertBuffer.cs | 5 +- .../Project/Converter/LanguageConverter.cs | 5 +- .../Services/AmbienceService/NetAmbience.cs | 7 +- .../MethodInsightDataProvider.cs | 6 +- src/Main/Base/Test/CodeConverterTests.cs | 198 + .../ICSharpCode.SharpDevelop.Tests.csproj | 1 + src/Main/Base/Test/MemberLookupHelperTests.cs | 267 +- src/Main/Base/Test/NRefactoryResolverTests.cs | 109 +- src/Main/Base/Test/OverloadFinding.cs | 2 +- .../ICSharpCode.SharpDevelop.Dom.csproj | 4 + .../Project/Src/CSharp/CSharpAmbience.cs | 2 + .../Src/Implementations/AbstractReturnType.cs | 29 +- .../AnonymousMethodReturnType.cs | 30 +- .../Src/Implementations/ArrayReturnType.cs | 43 +- .../Src/Implementations/CombinedReturnType.cs | 2 +- .../Implementations/ConstructedReturnType.cs | 48 +- .../Implementations/DecoratingReturnType.cs | 28 + .../Src/Implementations/DefaultClass.cs | 37 +- .../Src/Implementations/DefaultUsing.cs | 4 +- .../Src/Implementations/ElementReturnType.cs | 52 + .../Src/Implementations/GenericReturnType.cs | 43 +- .../Src/Implementations/GetClassReturnType.cs | 12 +- .../Src/Implementations/NullReturnType.cs | 2 +- .../Src/Implementations/ProxyReturnType.cs | 90 +- .../Implementations/SearchClassReturnType.cs | 20 +- .../Project/Src/Interfaces/IReturnType.cs | 14 +- .../Project/Src/LanguageProperties.cs | 68 +- .../Project/Src/MemberLookupHelper.cs | 184 +- .../CSharpToVBNetConvertVisitor.cs | 101 + .../NRefactoryResolver/InferredReturnType.cs | 49 + .../NRefactoryASTConvertVisitor.cs | 1 + .../NRefactoryInformationProvider.cs | 13 +- .../NRefactoryResolver/NRefactoryResolver.cs | 91 +- .../Src/NRefactoryResolver/TypeVisitor.cs | 94 +- .../Project/Src/ResolveResult.cs | 2 +- .../Project/Src/VBNet/VBNetAmbience.cs | 6 +- .../Project/Src/XmlDoc.cs | 10 +- src/SharpDevelop.Tests.sln | 3 +- 115 files changed, 7385 insertions(+), 3801 deletions(-) delete mode 100644 src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ElementReturnType.cs create mode 100644 src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorLINQ.cs delete mode 100644 src/Libraries/NRefactory/Project/Src/PrettyPrinter/NodeInformVisitor.cs delete mode 100644 src/Libraries/NRefactory/Project/Src/Visitors/CSharpToVBNetConvertVisitor.cs create mode 100644 src/Libraries/NRefactory/Project/Src/Visitors/ConvertVisitorBase.cs create mode 100644 src/Libraries/NRefactory/Project/Src/Visitors/RenameIdentifierVisitor.cs create mode 100644 src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetRenameConflictingVariables.cs create mode 100644 src/Libraries/NRefactory/Test/Parser/Expressions/LambdaExpressionTests.cs create mode 100644 src/Libraries/NRefactory/Test/Parser/Expressions/QueryExpressionTests.cs create mode 100644 src/Main/Base/Test/CodeConverterTests.cs create mode 100644 src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DecoratingReturnType.cs create mode 100644 src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ElementReturnType.cs create mode 100644 src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/CSharpToVBNetConvertVisitor.cs create mode 100644 src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/InferredReturnType.cs diff --git a/samples/CSharpCodeCompletion/CodeCompletionProvider.cs b/samples/CSharpCodeCompletion/CodeCompletionProvider.cs index 2b7812e79b..bf5a3170e9 100644 --- a/samples/CSharpCodeCompletion/CodeCompletionProvider.cs +++ b/samples/CSharpCodeCompletion/CodeCompletionProvider.cs @@ -92,7 +92,7 @@ namespace CSharpEditor // new DefaultCompletionData("Text", "Description", 1) //}; - NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent); + NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent, mainForm.myProjectContent.Language); Dom.ResolveResult rr = resolver.Resolve(FindExpression(textArea), textArea.Caret.Line, textArea.Caret.Column, @@ -115,8 +115,8 @@ namespace CSharpEditor /// Dom.ExpressionResult FindExpression(TextArea textArea) { - Dom.CSharp.CSharpExpressionFinder finder; - finder = new Dom.CSharp.CSharpExpressionFinder(MainForm.DummyFileName); + Dom.VBNet.VBExpressionFinder finder; + finder = new Dom.VBNet.VBExpressionFinder(); return finder.FindExpression(textArea.Document.TextContent, textArea.Caret.Offset); } diff --git a/samples/CSharpCodeCompletion/MainForm.cs b/samples/CSharpCodeCompletion/MainForm.cs index 376ea719d6..0695fbd496 100644 --- a/samples/CSharpCodeCompletion/MainForm.cs +++ b/samples/CSharpCodeCompletion/MainForm.cs @@ -59,7 +59,7 @@ namespace CSharpEditor /// SharpDevelop itself uses internal names of the kind "[randomId]/Class1.cs" to support /// code-completion in unsaved files. /// - public const string DummyFileName = "edited.cs"; + public const string DummyFileName = "edited.vb"; public MainForm() { @@ -68,17 +68,16 @@ namespace CSharpEditor // InitializeComponent(); - textEditorControl1.Text = @"using System; -using System.Collections.Generic; -class MainClass -{ - static void Main(string[] args) - { - - } -} + textEditorControl1.Text = @"Imports System + +Class A + Sub B + Dim x As String + + End Sub +End Class "; - textEditorControl1.SetHighlighting("C#"); + textEditorControl1.SetHighlighting("VB"); textEditorControl1.ShowEOLMarkers = false; CodeCompletionKeyHandler.Attach(this, textEditorControl1); HostCallbackImplementation.Register(this); @@ -92,7 +91,7 @@ class MainClass "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); - myProjectContent.Language = Dom.LanguageProperties.CSharp; + myProjectContent.Language = Dom.LanguageProperties.VBNet; } protected override void OnLoad(EventArgs e) @@ -114,7 +113,7 @@ class MainClass ParseStep(); string[] referencedAssemblies = { - "System", "System.Data", "System.Drawing", "System.Xml", "System.Windows.Forms" + "System", "System.Data", "System.Drawing", "System.Xml", "System.Windows.Forms", "Microsoft.VisualBasic" }; foreach (string assemblyName in referencedAssemblies) { { // block for anonymous method @@ -141,7 +140,7 @@ class MainClass })); TextReader textReader = new StringReader(code); Dom.ICompilationUnit newCompilationUnit; - using (NRefactory.IParser p = NRefactory.ParserFactory.CreateParser(NRefactory.SupportedLanguage.CSharp, textReader)) { + using (NRefactory.IParser p = NRefactory.ParserFactory.CreateParser(NRefactory.SupportedLanguage.VBNet, textReader)) { p.Parse(); newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit); } diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj b/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj index 52b2bcb394..bd9f0b5773 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj @@ -77,7 +77,6 @@ - diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooAmbience.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooAmbience.cs index 577b49dcc2..3eaabdd19c 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooAmbience.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooAmbience.cs @@ -418,6 +418,10 @@ namespace Grunwald.BooBinding public override string Convert(IMethod m) { StringBuilder builder = new StringBuilder(); + if (ShowModifiers && m.IsExtensionMethod) { + builder.Append("[Extension] "); + } + builder.Append(Convert(m.Modifiers)); if (ShowModifiers) { diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs index a7d1083555..8c5b398c21 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs @@ -278,7 +278,7 @@ namespace Grunwald.BooBinding.CodeCompletion { if (field.Type == null) { if (field.Initializer != null) - return new InferredReturnType(field.Initializer, OuterClass); + return new BooInferredReturnType(field.Initializer, OuterClass); else return GetDefaultReturnType(_cu.ProjectContent); } else { @@ -288,13 +288,13 @@ namespace Grunwald.BooBinding.CodeCompletion IReturnType CreateReturnType(AST.Method node, IMethod method) { if (node.ReturnType == null) - return new InferredReturnType(node.Body, OuterClass, false); + return new BooInferredReturnType(node.Body, OuterClass, false); return CreateReturnType(node.ReturnType, method); } IReturnType CreateReturnType(AST.Property property) { if (property.Type == null && property.Getter != null && property.Getter.Body != null) - return new InferredReturnType(property.Getter.Body, OuterClass, false); + return new BooInferredReturnType(property.Getter.Body, OuterClass, false); return CreateReturnType(property.Type); } diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ElementReturnType.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ElementReturnType.cs deleted file mode 100644 index 0013b7e4f7..0000000000 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ElementReturnType.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using ICSharpCode.SharpDevelop.Dom; - -namespace Grunwald.BooBinding.CodeCompletion -{ - /// - /// The return type that is the element of an enumerable. - /// Used to infer the type in "for x in enumerableVariable" loops. - /// - public class ElementReturnType : ProxyReturnType - { - IReturnType listType; - IProjectContent pc; - - public ElementReturnType(IProjectContent pc, IReturnType listType) - { - if (pc == null) - throw new ArgumentNullException("pc"); - // listType is probably an InferredReturnType - this.listType = listType; - this.pc = pc; - } - - public override IReturnType BaseType { - get { - // get element type from listType - if (listType.IsArrayReturnType) - return listType.CastToArrayReturnType().ArrayElementType; - - IClass c = listType.GetUnderlyingClass(); - if (c == null) - return null; - IClass genumerable = pc.GetClass("System.Collections.Generic.IEnumerable", 1); - if (c.IsTypeInInheritanceTree(genumerable)) { - return MemberLookupHelper.GetTypeParameterPassedToBaseClass(listType, genumerable, 0); - } - IClass enumerable = pc.GetClass("System.Collections.IEnumerable", 0); - if (c.IsTypeInInheritanceTree(enumerable)) { - // We can't use the EnumeratorItemType attribute because SharpDevelop - // does not store attribute argument values in the cache. - - // HACK: Hacked in support for range(), take out when RangeEnumerator implements IEnumerable - if (c.FullyQualifiedName == "Boo.Lang.Builtins.RangeEnumerator") { - return pc.SystemTypes.Int32; - } - - return pc.SystemTypes.Object; - } - return null; - } - } - } -} diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/InferredReturnType.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/InferredReturnType.cs index 7b9d91e6b8..b563629023 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/InferredReturnType.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/InferredReturnType.cs @@ -15,14 +15,14 @@ namespace Grunwald.BooBinding.CodeCompletion /// /// Return type that is inferred from an expression. /// - public class InferredReturnType : ProxyReturnType + public class BooInferredReturnType : ProxyReturnType { Expression expression; Block block; IReturnType cachedType; IClass context; - public InferredReturnType(Expression expression, IClass context) + public BooInferredReturnType(Expression expression, IClass context) { if (expression == null) throw new ArgumentNullException("expression"); this.context = context; @@ -31,7 +31,7 @@ namespace Grunwald.BooBinding.CodeCompletion bool useLastStatementIfNoReturnStatement; - public InferredReturnType(Block block, IClass context, bool useLastStatementIfNoReturnStatement) + public BooInferredReturnType(Block block, IClass context, bool useLastStatementIfNoReturnStatement) { if (block == null) throw new ArgumentNullException("block"); this.useLastStatementIfNoReturnStatement = useLastStatementIfNoReturnStatement; @@ -70,8 +70,8 @@ namespace Grunwald.BooBinding.CodeCompletion class GetReturnTypeVisitor : DepthFirstVisitor { IClass context; - InferredReturnType parentReturnType; - public GetReturnTypeVisitor(InferredReturnType parentReturnType) + BooInferredReturnType parentReturnType; + public GetReturnTypeVisitor(BooInferredReturnType parentReturnType) { this.context = parentReturnType.context; this.parentReturnType = parentReturnType; diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ResolveVisitor.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ResolveVisitor.cs index 46a9ca990f..94e3793a04 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ResolveVisitor.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ResolveVisitor.cs @@ -605,7 +605,7 @@ namespace Grunwald.BooBinding.CodeCompletion if (node.ReturnType != null) { amrt.MethodReturnType = ConvertType(node.ReturnType); } else { - amrt.MethodReturnType = new InferredReturnType(node.Body, resolver.CallingClass, + amrt.MethodReturnType = new BooInferredReturnType(node.Body, resolver.CallingClass, node.ContainsAnnotation("inline")); } ConvertVisitor.AddParameters(node.Parameters, amrt.MethodParameters, resolver.CallingMember, resolver.CallingClass ?? new DefaultClass(resolver.CompilationUnit, "__Dummy")); diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs index 4b2719a725..1f615049f8 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs @@ -178,7 +178,7 @@ namespace Grunwald.BooBinding.CodeCompletion if (expr.ContainsAnnotation("DomReturnType")) { returnType = (IReturnType)expr["DomReturnType"]; } else { - returnType = new InferredReturnType(expr, resolver.CallingClass); + returnType = new BooInferredReturnType(expr, resolver.CallingClass); expr.Annotate("DomReturnType", returnType); } if (useElementType) @@ -219,9 +219,9 @@ namespace Grunwald.BooBinding.CodeCompletion return; if (elementReturnType) results.Add(name, new ElementReturnType(resolver.ProjectContent, - new InferredReturnType(expr, resolver.CallingClass))); + new BooInferredReturnType(expr, resolver.CallingClass))); else - results.Add(name, new InferredReturnType(expr, resolver.CallingClass)); + results.Add(name, new BooInferredReturnType(expr, resolver.CallingClass)); } private void Add(string name, TypeReference reference) diff --git a/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs b/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs index ebe0e2d4ac..64f7affb64 100644 --- a/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs +++ b/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs @@ -455,7 +455,9 @@ namespace NRefactoryToBooConverter { if (!arrayCreateExpression.ArrayInitializer.IsNull) { B.ArrayLiteralExpression ale = ConvertArrayLiteralExpression(arrayCreateExpression.ArrayInitializer); - ale.Type = (B.ArrayTypeReference)ConvertTypeReference(arrayCreateExpression.CreateType); + if (!arrayCreateExpression.IsImplicitlyTyped) { + ale.Type = (B.ArrayTypeReference)ConvertTypeReference(arrayCreateExpression.CreateType); + } return ale; } string builtInName = (arrayCreateExpression.Arguments.Count > 1) ? "matrix" : "array"; @@ -477,12 +479,12 @@ namespace NRefactoryToBooConverter return mie; } - public object VisitArrayInitializerExpression(ArrayInitializerExpression aie, object data) + public object VisitCollectionInitializerExpression(CollectionInitializerExpression aie, object data) { return ConvertArrayLiteralExpression(aie); } - B.ArrayLiteralExpression ConvertArrayLiteralExpression(ArrayInitializerExpression aie) + B.ArrayLiteralExpression ConvertArrayLiteralExpression(CollectionInitializerExpression aie) { B.ArrayLiteralExpression dims = new B.ArrayLiteralExpression(GetLexicalInfo(aie)); ConvertExpressions(aie.CreateExpressions, dims.Items); @@ -508,6 +510,20 @@ namespace NRefactoryToBooConverter return cbe; } + public object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) + { + B.CallableBlockExpression cbe = new B.CallableBlockExpression(GetLexicalInfo(lambdaExpression)); + cbe.EndSourceLocation = GetLocation(lambdaExpression.EndLocation); + if (lambdaExpression.StatementBody.IsNull) { + cbe.Body = new B.Block(); + cbe.Body.Add(new B.ReturnStatement(ConvertExpression(lambdaExpression.ExpressionBody))); + } else { + cbe.Body = ConvertBlock(lambdaExpression.StatementBody); + } + ConvertParameters(lambdaExpression.Parameters, cbe.Parameters); + return cbe; + } + public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) { B.ConditionalExpression te = new B.ConditionalExpression(GetLexicalInfo(conditionalExpression)); diff --git a/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorLINQ.cs b/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorLINQ.cs new file mode 100644 index 0000000000..18a521770d --- /dev/null +++ b/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorLINQ.cs @@ -0,0 +1,67 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using Boo.Lang.Compiler; +using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.Ast; +using B = Boo.Lang.Compiler.Ast; + +namespace NRefactoryToBooConverter +{ + partial class ConvertVisitor + { + public object VisitQueryExpression(QueryExpression queryExpression, object data) + { + AddError(queryExpression, "QueryExpression is not supported."); + return null; + } + + public object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) + { + AddError(queryExpressionFromClause, "QueryExpressionFromClause is not supported."); + return null; + } + + public object VisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) + { + AddError(queryExpressionFromGenerator, "QueryExpressionFromGenerator is not supported."); + return null; + } + + public object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) + { + AddError(queryExpressionGroupClause, "QueryExpressionGroupClause is not supported."); + return null; + } + + public object VisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data) + { + AddError(queryExpressionIntoClause, "QueryExpressionIntoClause is not supported."); + return null; + } + + public object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) + { + AddError(queryExpressionOrdering, "QueryExpressionOrdering is not supported."); + return null; + } + + public object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) + { + AddError(queryExpressionSelectClause, "queryExpressionSelectClause is not supported."); + return null; + } + + public object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) + { + AddError(queryExpressionWhereClause, "QueryExpressionWhereClause is not supported."); + return null; + } + } +} diff --git a/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/NRefactoryToBooConverter.csproj b/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/NRefactoryToBooConverter.csproj index 615b80d515..ebcd862461 100644 --- a/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/NRefactoryToBooConverter.csproj +++ b/src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/NRefactoryToBooConverter.csproj @@ -54,6 +54,7 @@ + diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBToCSharpConverter.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBToCSharpConverter.cs index debf2f055d..baf5fb208d 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBToCSharpConverter.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBToCSharpConverter.cs @@ -39,7 +39,7 @@ namespace CSharpBinding delegate(string v) { return v.Replace(',', ';'); }); } - protected override void ConvertAst(CompilationUnit compilationUnit, List specials) + protected override void ConvertAst(CompilationUnit compilationUnit, List specials, FileProjectItem sourceItem) { PreprocessingDirective.VBToCSharp(specials); compilationUnit.AcceptVisitor(new VBNetToCSharpConvertVisitor(), null); diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBConverter.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBConverter.cs index 0d0f9af506..4b01ecad1b 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBConverter.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBConverter.cs @@ -16,6 +16,9 @@ using ICSharpCode.NRefactory.Visitors; using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project.Converter; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; +using ICSharpCode.SharpDevelop; namespace VBNetBinding { @@ -32,10 +35,11 @@ namespace VBNetBinding ConvertFile(sourceItem, targetItem, ".cs", ".vb", SupportedLanguage.CSharp, new VBNetOutputVisitor()); } - protected override void ConvertAst(CompilationUnit compilationUnit, List specials) + protected override void ConvertAst(CompilationUnit compilationUnit, List specials, FileProjectItem sourceItem) { PreprocessingDirective.CSharpToVB(specials); - compilationUnit.AcceptVisitor(new CSharpToVBNetConvertVisitor(), null); + IProjectContent pc = ParserService.GetProjectContent(sourceItem.Project) ?? ParserService.CurrentProjectContent; + compilationUnit.AcceptVisitor(new CSharpToVBNetConvertVisitor(pc, sourceItem.FileName), null); } protected override void CopyProperties(IProject sourceProject, IProject targetProject) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs index 2402f92cf6..41ad5e073c 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs @@ -233,7 +233,7 @@ namespace ICSharpCode.FormsDesigner } CodeDomVisitor visitor = new CodeDomVisitor(); - visitor.EnvironmentInformationProvider = new ICSharpCode.SharpDevelop.Dom.NRefactoryResolver.NRefactoryInformationProvider(formClass.ProjectContent, formClass); + visitor.EnvironmentInformationProvider = new ICSharpCode.SharpDevelop.Dom.NRefactoryResolver.NRefactoryInformationProvider(formClass.ProjectContent); visitor.VisitCompilationUnit(combinedCu, null); // output generated CodeDOM to the console : diff --git a/src/AddIns/Misc/ResourceToolkit/Project/Hornung.ResourceToolkit.addin b/src/AddIns/Misc/ResourceToolkit/Project/Hornung.ResourceToolkit.addin index 767ec9c904..95fe7c3f9e 100644 --- a/src/AddIns/Misc/ResourceToolkit/Project/Hornung.ResourceToolkit.addin +++ b/src/AddIns/Misc/ResourceToolkit/Project/Hornung.ResourceToolkit.addin @@ -5,8 +5,8 @@ description = "Provides tooltips and code completion for resource entries to simplify working with localizable resources using the standard .NET framework classes or ICSharpCode.Core."> - - + + diff --git a/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/BclNRefactoryResourceResolver.cs b/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/BclNRefactoryResourceResolver.cs index 6b64cbfa7c..9170be2efa 100644 --- a/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/BclNRefactoryResourceResolver.cs +++ b/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/BclNRefactoryResourceResolver.cs @@ -360,28 +360,28 @@ namespace Hornung.ResourceToolkit.Resolver } } - public override object TrackedVisit(CompilationUnit compilationUnit, object data) + public override object TrackedVisitCompilationUnit(CompilationUnit compilationUnit, object data) { this.compilationUnit = compilationUnit; - return base.TrackedVisit(compilationUnit, data); + return base.TrackedVisitCompilationUnit(compilationUnit, data); } - public override object TrackedVisit(LocalVariableDeclaration localVariableDeclaration, object data) + public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { - return base.TrackedVisit(localVariableDeclaration, localVariableDeclaration); + return base.TrackedVisitLocalVariableDeclaration(localVariableDeclaration, localVariableDeclaration); } - public override object TrackedVisit(FieldDeclaration fieldDeclaration, object data) + public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) { - return base.TrackedVisit(fieldDeclaration, fieldDeclaration); + return base.TrackedVisitFieldDeclaration(fieldDeclaration, fieldDeclaration); } - public override object TrackedVisit(VariableDeclaration variableDeclaration, object data) + public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) { // Resolving anything here only makes sense // if this declaration actually has an initializer. if (variableDeclaration.Initializer.IsNull) { - return base.TrackedVisit(variableDeclaration, data); + return base.TrackedVisitVariableDeclaration(variableDeclaration, data); } LocalVariableDeclaration localVariableDeclaration = data as LocalVariableDeclaration; @@ -434,10 +434,10 @@ namespace Hornung.ResourceToolkit.Resolver } } - return base.TrackedVisit(variableDeclaration, data); + return base.TrackedVisitVariableDeclaration(variableDeclaration, data); } - public override object TrackedVisit(AssignmentExpression assignmentExpression, object data) + public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { if (this.FoundResourceSet == null && // skip if already found to improve performance assignmentExpression.Op == AssignmentOperatorType.Assign && this.PositionAvailable && @@ -512,7 +512,7 @@ namespace Hornung.ResourceToolkit.Resolver } } - return base.TrackedVisit(assignmentExpression, data); + return base.TrackedVisitAssignmentExpression(assignmentExpression, data); } /// @@ -544,7 +544,7 @@ namespace Hornung.ResourceToolkit.Resolver } } - public override object TrackedVisit(ObjectCreateExpression objectCreateExpression, object data) + public override object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { if (data as bool? ?? false) { @@ -624,7 +624,7 @@ namespace Hornung.ResourceToolkit.Resolver } - return base.TrackedVisit(objectCreateExpression, data); + return base.TrackedVisitObjectCreateExpression(objectCreateExpression, data); } } diff --git a/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PositionTrackingAstVisitor.cs b/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PositionTrackingAstVisitor.cs index 084153e7b7..ab2bcd17c6 100644 --- a/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PositionTrackingAstVisitor.cs +++ b/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PositionTrackingAstVisitor.cs @@ -81,10 +81,10 @@ namespace Hornung.ResourceToolkit.Resolver private CompilationUnit compilationUnit; - public override object TrackedVisit(CompilationUnit compilationUnit, object data) + public override object TrackedVisitCompilationUnit(CompilationUnit compilationUnit, object data) { this.compilationUnit = compilationUnit; - return base.TrackedVisit(compilationUnit, data); + return base.TrackedVisitCompilationUnit(compilationUnit, data); } // ******************************************************************************************************************************** diff --git a/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PropertyFieldAssociationVisitor.cs b/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PropertyFieldAssociationVisitor.cs index 6784817b7a..280d2c2c1f 100644 --- a/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PropertyFieldAssociationVisitor.cs +++ b/src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PropertyFieldAssociationVisitor.cs @@ -68,7 +68,7 @@ namespace Hornung.ResourceToolkit.Resolver base.EndVisit(node); } - public override object TrackedVisit(PropertyDeclaration propertyDeclaration, object data) + public override object TrackedVisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { if (this.memberToFind is IProperty) { @@ -88,10 +88,10 @@ namespace Hornung.ResourceToolkit.Resolver } - return base.TrackedVisit(propertyDeclaration, data); + return base.TrackedVisitPropertyDeclaration(propertyDeclaration, data); } - public override object TrackedVisit(ReturnStatement returnStatement, object data) + public override object TrackedVisitReturnStatement(ReturnStatement returnStatement, object data) { // If we are in a property get region, // this may be the statement where the field value is returned. @@ -162,10 +162,10 @@ namespace Hornung.ResourceToolkit.Resolver } - return base.TrackedVisit(returnStatement, data); + return base.TrackedVisitReturnStatement(returnStatement, data); } - public override object TrackedVisit(AssignmentExpression assignmentExpression, object data) + public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { // If we are in a property set region, // this may be the statement where the field value is assigned. @@ -221,7 +221,7 @@ namespace Hornung.ResourceToolkit.Resolver } - return base.TrackedVisit(assignmentExpression, data); + return base.TrackedVisitAssignmentExpression(assignmentExpression, data); } // ******************************************************************************************************************************** diff --git a/src/AddIns/Misc/StartPage/Project/Src/ICSharpCodePage.cs b/src/AddIns/Misc/StartPage/Project/Src/ICSharpCodePage.cs index 2e23a185f9..b32a7ed99a 100644 --- a/src/AddIns/Misc/StartPage/Project/Src/ICSharpCodePage.cs +++ b/src/AddIns/Misc/StartPage/Project/Src/ICSharpCodePage.cs @@ -185,7 +185,7 @@ namespace ICSharpCode.StartPage public ICSharpCodePage() { - ColorScheme = ICSharpCode.StartPage.ColorScheme.brown; + ColorScheme = ICSharpCode.StartPage.ColorScheme.green; TopMenu = new List(); PopulateTopMenu(); diff --git a/src/Libraries/NRefactory/NRefactory.sln b/src/Libraries/NRefactory/NRefactory.sln index 9bde0d8af4..7afedef091 100644 --- a/src/Libraries/NRefactory/NRefactory.sln +++ b/src/Libraries/NRefactory/NRefactory.sln @@ -1,5 +1,7 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# SharpDevelop 2.1.0.1865 + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 2.1.0.2168 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryTests", "Test\NRefactoryTests.csproj", "{870115DD-960A-4406-A6B9-600BCDC36A03}" diff --git a/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs b/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs index 6a8b0a2479..a91048a1ed 100644 --- a/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs +++ b/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs @@ -38,22 +38,32 @@ namespace NRefactoryASTGenerator.Ast public NamedArgumentExpression(string name, Expression expression) {} } + [IncludeBoolProperty("IsAnonymousType", "return createType.IsNull || string.IsNullOrEmpty(createType.Type);")] + class ObjectCreateExpression : Expression { + TypeReference createType; + List parameters; + CollectionInitializerExpression objectInitializer; + + public ObjectCreateExpression(TypeReference createType, List parameters) {} + } + + [IncludeBoolProperty("IsImplicitlyTyped", "return createType.IsNull || string.IsNullOrEmpty(createType.Type);")] class ArrayCreateExpression : Expression { TypeReference createType; List arguments; - ArrayInitializerExpression arrayInitializer; + CollectionInitializerExpression arrayInitializer; public ArrayCreateExpression(TypeReference createType) {} public ArrayCreateExpression(TypeReference createType, List arguments) {} - public ArrayCreateExpression(TypeReference createType, ArrayInitializerExpression arrayInitializer) {} + public ArrayCreateExpression(TypeReference createType, CollectionInitializerExpression arrayInitializer) {} } [ImplementNullable(NullableImplementation.Shadow)] - class ArrayInitializerExpression : Expression { + class CollectionInitializerExpression : Expression { List createExpressions; - public ArrayInitializerExpression() {} - public ArrayInitializerExpression(List createExpressions) {} + public CollectionInitializerExpression() {} + public CollectionInitializerExpression(List createExpressions) {} } enum AssignmentOperatorType {} @@ -115,13 +125,6 @@ namespace NRefactoryASTGenerator.Ast public InvocationExpression(Expression targetObject, List arguments, List typeArguments) {} } - class ObjectCreateExpression : Expression { - TypeReference createType; - List parameters; - - public ObjectCreateExpression(TypeReference createType, List parameters) {} - } - class ParenthesizedExpression : Expression { Expression expression; @@ -159,6 +162,12 @@ namespace NRefactoryASTGenerator.Ast bool hasParameterList; } + class LambdaExpression : Expression { + List parameters; + BlockStatement statementBody; + Expression expressionBody; + } + class CheckedExpression : Expression { Expression expression; @@ -235,4 +244,56 @@ namespace NRefactoryASTGenerator.Ast public TypeOfIsExpression(Expression expression, TypeReference typeReference) {} } + + [ImplementNullable(NullableImplementation.Shadow)] + class QueryExpression : Expression { + QueryExpressionFromClause fromClause; + List fromOrWhereClauses; + List orderings; + QueryExpressionClause selectOrGroupClause; + QueryExpressionIntoClause intoClause; + } + + [ImplementNullable] + abstract class QueryExpressionClause : AbstractNode, INullable { } + + class QueryExpressionWhereClause : QueryExpressionClause { + Expression condition; + } + + [ImplementNullable(NullableImplementation.Shadow)] + class QueryExpressionFromClause : QueryExpressionClause { + List generators; + } + + class QueryExpressionFromGenerator : AbstractNode { + [QuestionMarkDefault] + string identifier; + Expression inExpression; + } + + class QueryExpressionOrdering : AbstractNode { + Expression criteria; + QueryExpressionOrderingDirection direction; + } + + enum QueryExpressionOrderingDirection { + None, Ascending, Descending + } + + class QueryExpressionSelectClause : QueryExpressionClause { + Expression projection; + } + + class QueryExpressionGroupClause : QueryExpressionClause { + Expression projection; + Expression groupBy; + } + + [ImplementNullable(NullableImplementation.Shadow)] + class QueryExpressionIntoClause : QueryExpressionClause { + [QuestionMarkDefault] + string intoIdentifier; + QueryExpression continuedQuery; + } } diff --git a/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs b/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs index 3acff12011..d6380ee349 100644 --- a/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs +++ b/src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs @@ -44,7 +44,7 @@ namespace NRefactoryASTGenerator.Ast enum ConstructorInitializerType { None } [ImplementNullable] - class ConstructorInitializer : AbstractNode + class ConstructorInitializer : AbstractNode, INullable { ConstructorInitializerType constructorInitializerType; List arguments; @@ -149,6 +149,7 @@ namespace NRefactoryASTGenerator.Ast List handlesClause; List interfaceImplementations; List templates; + bool isExtensionMethod; public MethodDeclaration(string name, Modifiers modifier, TypeReference typeReference, List parameters, List attributes) : base(modifier, attributes, name, parameters) {} } diff --git a/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs b/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs index 4d4a5982e7..df43745e85 100644 --- a/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs +++ b/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs @@ -7,6 +7,8 @@ using System; using System.CodeDom; +using System.Reflection; +using ICSharpCode.EasyCodeDom; namespace NRefactoryASTGenerator { @@ -132,33 +134,27 @@ namespace NRefactoryASTGenerator ctd.Members.Add(prop); } if (implementation != NullableImplementation.Abstract) { - CodeTypeDeclaration newType = new CodeTypeDeclaration("Null" + ctd.Name); + EasyTypeDeclaration newType = new EasyTypeDeclaration("Null" + ctd.Name); + newType.TypeAttributes = TypeAttributes.Class | TypeAttributes.NotPublic | TypeAttributes.Sealed; newType.BaseTypes.Add(new CodeTypeReference(ctd.Name)); cns.Types.Add(newType); System.Reflection.ConstructorInfo baseCtor = MainClass.GetBaseCtor(type); - CodeConstructor ctor = new CodeConstructor(); - ctor.Attributes = MemberAttributes.Private; if (baseCtor != null) { + CodeConstructor ctor = new CodeConstructor(); + ctor.Attributes = MemberAttributes.Private; foreach (object o in baseCtor.GetParameters()) { ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(null)); } + newType.Members.Add(ctor); } - newType.Members.Add(ctor); - CodeMemberField field = new CodeMemberField(newType.Name, "instance"); - field.Attributes = MemberAttributes.Static; + CodeMemberField field = new CodeMemberField(newType.Name, "Instance"); + field.Attributes = MemberAttributes.Static | MemberAttributes.Assembly; field.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference(newType.Name)); newType.Members.Add(field); CodeMemberProperty prop = new CodeMemberProperty(); - prop.Name = "Instance"; - prop.Type = new CodeTypeReference(newType.Name); - prop.Attributes = MemberAttributes.Public | MemberAttributes.Static; - prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("instance"))); - newType.Members.Add(prop); - - prop = new CodeMemberProperty(); prop.Name = "IsNull"; prop.Type = new CodeTypeReference(typeof(bool)); prop.Attributes = MemberAttributes.Public | MemberAttributes.Override; diff --git a/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs b/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs index d658477c56..7a1f1aded7 100644 --- a/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs +++ b/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs @@ -518,7 +518,7 @@ namespace NRefactoryASTGenerator // m.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("result"))); m.Body.InvokeMethod(Easy.This, "BeginVisit", var); m.Body.DeclareVariable(typeof(object), "result").InitExpression - = Easy.This.InvokeMethod("TrackedVisit", var, Easy.Var("data")); + = Easy.This.InvokeMethod("TrackedVisit" + type.Name, var, Easy.Var("data")); m.Body.InvokeMethod(Easy.This, "EndVisit", var); m.Body.Return(Easy.Var("result")); } @@ -527,7 +527,7 @@ namespace NRefactoryASTGenerator foreach (Type type in nodeTypes) { if (!type.IsAbstract) { - m = td.AddMethod(typeof(object), "TrackedVisit"); + m = td.AddMethod(typeof(object), "TrackedVisit" + type.Name); m.Attributes = MemberAttributes.Public; m.AddParameter(ConvertType(type), GetFieldName(type.Name)); m.AddParameter(new CodeTypeReference(typeof(object)), "data"); diff --git a/src/Libraries/NRefactory/Project/NRefactory.csproj b/src/Libraries/NRefactory/Project/NRefactory.csproj index 648eb9bb09..f8c98aa64f 100644 --- a/src/Libraries/NRefactory/Project/NRefactory.csproj +++ b/src/Libraries/NRefactory/Project/NRefactory.csproj @@ -90,18 +90,19 @@ - + - + + diff --git a/src/Libraries/NRefactory/Project/Src/Ast/Enums.cs b/src/Libraries/NRefactory/Project/Src/Ast/Enums.cs index a9974664a6..c6f4a9574d 100644 --- a/src/Libraries/NRefactory/Project/Src/Ast/Enums.cs +++ b/src/Libraries/NRefactory/Project/Src/Ast/Enums.cs @@ -358,4 +358,12 @@ namespace ICSharpCode.NRefactory.Ast CompareBinary, CompareText } + + /// + /// Specifies the ordering direction of a QueryExpressionOrdering node. + /// + public enum QueryExpressionOrderingDirection + { + None, Ascending, Descending + } } diff --git a/src/Libraries/NRefactory/Project/Src/Ast/General/BlockStatement.cs b/src/Libraries/NRefactory/Project/Src/Ast/General/BlockStatement.cs index 95d4f13141..34a3efde99 100644 --- a/src/Libraries/NRefactory/Project/Src/Ast/General/BlockStatement.cs +++ b/src/Libraries/NRefactory/Project/Src/Ast/General/BlockStatement.cs @@ -14,7 +14,7 @@ namespace ICSharpCode.NRefactory.Ast // Children in C#: LabelStatement, LocalVariableDeclaration, Statement // Children in VB: LabelStatement, EndStatement, Statement - public static new NullBlockStatement Null { + public static new BlockStatement Null { get { return NullBlockStatement.Instance; } @@ -32,9 +32,9 @@ namespace ICSharpCode.NRefactory.Ast } } - public class NullBlockStatement : BlockStatement + internal sealed class NullBlockStatement : BlockStatement { - static NullBlockStatement nullBlockStatement = new NullBlockStatement(); + public static readonly NullBlockStatement Instance = new NullBlockStatement(); public override bool IsNull { get { @@ -42,16 +42,6 @@ namespace ICSharpCode.NRefactory.Ast } } - public static NullBlockStatement Instance { - get { - return nullBlockStatement; - } - } - - NullBlockStatement() - { - } - public override object AcceptVisitor(IAstVisitor visitor, object data) { return data; diff --git a/src/Libraries/NRefactory/Project/Src/Ast/General/Expression.cs b/src/Libraries/NRefactory/Project/Src/Ast/General/Expression.cs index 94115c3576..15fb20b3ef 100644 --- a/src/Libraries/NRefactory/Project/Src/Ast/General/Expression.cs +++ b/src/Libraries/NRefactory/Project/Src/Ast/General/Expression.cs @@ -11,7 +11,7 @@ namespace ICSharpCode.NRefactory.Ast { public abstract class Expression : AbstractNode, INullable { - public static NullExpression Null { + public static Expression Null { get { return NullExpression.Instance; } @@ -77,9 +77,9 @@ namespace ICSharpCode.NRefactory.Ast } } - public class NullExpression : Expression + internal sealed class NullExpression : Expression { - static NullExpression nullExpression = new NullExpression(); + internal static readonly NullExpression Instance = new NullExpression(); public override bool IsNull { get { @@ -87,16 +87,6 @@ namespace ICSharpCode.NRefactory.Ast } } - public static NullExpression Instance { - get { - return nullExpression; - } - } - - NullExpression() - { - } - public override object AcceptVisitor(IAstVisitor visitor, object data) { return null; diff --git a/src/Libraries/NRefactory/Project/Src/Ast/General/Statement.cs b/src/Libraries/NRefactory/Project/Src/Ast/General/Statement.cs index 2f075e52ac..72bcb513d9 100644 --- a/src/Libraries/NRefactory/Project/Src/Ast/General/Statement.cs +++ b/src/Libraries/NRefactory/Project/Src/Ast/General/Statement.cs @@ -11,7 +11,7 @@ namespace ICSharpCode.NRefactory.Ast { public abstract class Statement : AbstractNode, INullable { - public static NullStatement Null { + public static Statement Null { get { return NullStatement.Instance; } @@ -45,22 +45,14 @@ namespace ICSharpCode.NRefactory.Ast } } - public class NullStatement : Statement + internal sealed class NullStatement : Statement { - static NullStatement nullStatement = new NullStatement(); + public static readonly NullStatement Instance = new NullStatement(); public override bool IsNull { get { return true; } } - public static NullStatement Instance { - get { return nullStatement; } - } - - NullStatement() - { - } - public override object AcceptVisitor(IAstVisitor visitor, object data) { return data; diff --git a/src/Libraries/NRefactory/Project/Src/Ast/Generated.cs b/src/Libraries/NRefactory/Project/Src/Ast/Generated.cs index 66e82b338f..80eb76d150 100644 --- a/src/Libraries/NRefactory/Project/Src/Ast/Generated.cs +++ b/src/Libraries/NRefactory/Project/Src/Ast/Generated.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.42 +// Runtime Version:2.0.50727.312 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -136,7 +136,7 @@ namespace ICSharpCode.NRefactory.Ast { List arguments; - ArrayInitializerExpression arrayInitializer; + CollectionInitializerExpression arrayInitializer; public TypeReference CreateType { get { @@ -156,12 +156,12 @@ namespace ICSharpCode.NRefactory.Ast { } } - public ArrayInitializerExpression ArrayInitializer { + public CollectionInitializerExpression ArrayInitializer { get { return arrayInitializer; } set { - arrayInitializer = value ?? ArrayInitializerExpression.Null; + arrayInitializer = value ?? CollectionInitializerExpression.Null; if (!arrayInitializer.IsNull) arrayInitializer.Parent = this; } } @@ -169,91 +169,33 @@ namespace ICSharpCode.NRefactory.Ast { public ArrayCreateExpression(TypeReference createType) { CreateType = createType; arguments = new List(); - arrayInitializer = ArrayInitializerExpression.Null; + arrayInitializer = CollectionInitializerExpression.Null; } public ArrayCreateExpression(TypeReference createType, List arguments) { CreateType = createType; Arguments = arguments; - arrayInitializer = ArrayInitializerExpression.Null; + arrayInitializer = CollectionInitializerExpression.Null; } - public ArrayCreateExpression(TypeReference createType, ArrayInitializerExpression arrayInitializer) { + public ArrayCreateExpression(TypeReference createType, CollectionInitializerExpression arrayInitializer) { CreateType = createType; ArrayInitializer = arrayInitializer; arguments = new List(); } - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitArrayCreateExpression(this, data); - } - - public override string ToString() { - return string.Format("[ArrayCreateExpression CreateType={0} Arguments={1} ArrayInitializer={2}]", CreateType, GetCollectionString(Arguments), ArrayInitializer); - } - } - - public class ArrayInitializerExpression : Expression { - - List createExpressions; - - public List CreateExpressions { - get { - return createExpressions; - } - set { - createExpressions = value ?? new List(); - } - } - - public ArrayInitializerExpression() { - createExpressions = new List(); - } - - public ArrayInitializerExpression(List createExpressions) { - CreateExpressions = createExpressions; - } - - public new static ArrayInitializerExpression Null { - get { - return NullArrayInitializerExpression.Instance; - } - } - - public override object AcceptVisitor(IAstVisitor visitor, object data) { - return visitor.VisitArrayInitializerExpression(this, data); - } - - public override string ToString() { - return string.Format("[ArrayInitializerExpression CreateExpressions={0}]", GetCollectionString(CreateExpressions)); - } - } - - public class NullArrayInitializerExpression : ArrayInitializerExpression { - - private NullArrayInitializerExpression() { - } - - static NullArrayInitializerExpression instance = new NullArrayInitializerExpression(); - - public static NullArrayInitializerExpression Instance { - get { - return instance; - } - } - - public override bool IsNull { + public bool IsImplicitlyTyped { get { - return true; + return createType.IsNull || string.IsNullOrEmpty(createType.Type); } } public override object AcceptVisitor(IAstVisitor visitor, object data) { - return null; + return visitor.VisitArrayCreateExpression(this, data); } public override string ToString() { - return "[NullArrayInitializerExpression]"; + return string.Format("[ArrayCreateExpression CreateType={0} Arguments={1} ArrayInitializer={2}]", CreateType, GetCollectionString(Arguments), ArrayInitializer); } } @@ -787,6 +729,61 @@ namespace ICSharpCode.NRefactory.Ast { } } + public class CollectionInitializerExpression : Expression { + + List createExpressions; + + public List CreateExpressions { + get { + return createExpressions; + } + set { + createExpressions = value ?? new List(); + } + } + + public CollectionInitializerExpression() { + createExpressions = new List(); + } + + public CollectionInitializerExpression(List createExpressions) { + CreateExpressions = createExpressions; + } + + public new static CollectionInitializerExpression Null { + get { + return NullCollectionInitializerExpression.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitCollectionInitializerExpression(this, data); + } + + public override string ToString() { + return string.Format("[CollectionInitializerExpression CreateExpressions={0}]", GetCollectionString(CreateExpressions)); + } + } + + internal sealed class NullCollectionInitializerExpression : CollectionInitializerExpression { + + internal static NullCollectionInitializerExpression Instance = new NullCollectionInitializerExpression(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullCollectionInitializerExpression]"; + } + } + public class ConditionalExpression : Expression { Expression condition; @@ -852,6 +849,7 @@ namespace ICSharpCode.NRefactory.Ast { } set { constructorInitializer = value ?? ConstructorInitializer.Null; + if (!constructorInitializer.IsNull) constructorInitializer.Parent = this; } } @@ -936,18 +934,9 @@ namespace ICSharpCode.NRefactory.Ast { } } - public class NullConstructorInitializer : ConstructorInitializer { + internal sealed class NullConstructorInitializer : ConstructorInitializer { - private NullConstructorInitializer() { - } - - static NullConstructorInitializer instance = new NullConstructorInitializer(); - - public static NullConstructorInitializer Instance { - get { - return instance; - } - } + internal static NullConstructorInitializer Instance = new NullConstructorInitializer(); public override bool IsNull { get { @@ -1415,19 +1404,13 @@ namespace ICSharpCode.NRefactory.Ast { } } - public class NullEventAddRegion : EventAddRegion { + internal sealed class NullEventAddRegion : EventAddRegion { private NullEventAddRegion() : base(null) { } - static NullEventAddRegion instance = new NullEventAddRegion(); - - public static NullEventAddRegion Instance { - get { - return instance; - } - } + internal static NullEventAddRegion Instance = new NullEventAddRegion(); public override bool IsNull { get { @@ -1597,15 +1580,15 @@ namespace ICSharpCode.NRefactory.Ast { initializer = Expression.Null; } - public bool HasRemoveRegion { + public bool HasRaiseRegion { get { - return !removeRegion.IsNull; + return !raiseRegion.IsNull; } } - public bool HasRaiseRegion { + public bool HasRemoveRegion { get { - return !raiseRegion.IsNull; + return !removeRegion.IsNull; } } @@ -1647,19 +1630,13 @@ namespace ICSharpCode.NRefactory.Ast { } } - public class NullEventRaiseRegion : EventRaiseRegion { + internal sealed class NullEventRaiseRegion : EventRaiseRegion { private NullEventRaiseRegion() : base(null) { } - static NullEventRaiseRegion instance = new NullEventRaiseRegion(); - - public static NullEventRaiseRegion Instance { - get { - return instance; - } - } + internal static NullEventRaiseRegion Instance = new NullEventRaiseRegion(); public override bool IsNull { get { @@ -1697,19 +1674,13 @@ namespace ICSharpCode.NRefactory.Ast { } } - public class NullEventRemoveRegion : EventRemoveRegion { + internal sealed class NullEventRemoveRegion : EventRemoveRegion { private NullEventRemoveRegion() : base(null) { } - static NullEventRemoveRegion instance = new NullEventRemoveRegion(); - - public static NullEventRemoveRegion Instance { - get { - return instance; - } - } + internal static NullEventRemoveRegion Instance = new NullEventRemoveRegion(); public override bool IsNull { get { @@ -1817,6 +1788,15 @@ namespace ICSharpCode.NRefactory.Ast { } + public TypeReference GetTypeForField(int fieldIndex) + { + if (!typeReference.IsNull) { + return typeReference; + } + return ((VariableDeclaration)Fields[fieldIndex]).TypeReference; + } + + public VariableDeclaration GetVariableDeclaration(string variableName) { foreach (VariableDeclaration variableDeclaration in Fields) { @@ -1827,15 +1807,6 @@ namespace ICSharpCode.NRefactory.Ast { return null; } - - public TypeReference GetTypeForField(int fieldIndex) - { - if (!typeReference.IsNull) { - return typeReference; - } - return ((VariableDeclaration)Fields[fieldIndex]).TypeReference; - } - public override object AcceptVisitor(IAstVisitor visitor, object data) { return visitor.VisitFieldDeclaration(this, data); } @@ -2279,6 +2250,12 @@ namespace ICSharpCode.NRefactory.Ast { elseIfSections = new List(); } + public bool HasElseIfSections { + get { + return elseIfSections.Count > 0; + } + } + public IfElseStatement(Expression condition, Statement trueStatement) : this(condition) { @@ -2298,12 +2275,6 @@ namespace ICSharpCode.NRefactory.Ast { } } - public bool HasElseIfSections { - get { - return elseIfSections.Count > 0; - } - } - public override object AcceptVisitor(IAstVisitor visitor, object data) { return visitor.VisitIfElseStatement(this, data); } @@ -2417,9 +2388,9 @@ namespace ICSharpCode.NRefactory.Ast { setRegion = PropertySetRegion.Null; } - public bool HasSetRegion { + public bool IsWriteOnly { get { - return !setRegion.IsNull; + return !HasGetRegion && HasSetRegion; } } @@ -2429,15 +2400,15 @@ namespace ICSharpCode.NRefactory.Ast { } } - public bool IsWriteOnly { + public bool HasGetRegion { get { - return !HasGetRegion && HasSetRegion; + return !getRegion.IsNull; } } - public bool HasGetRegion { + public bool HasSetRegion { get { - return !getRegion.IsNull; + return !setRegion.IsNull; } } @@ -2618,6 +2589,58 @@ namespace ICSharpCode.NRefactory.Ast { } } + public class LambdaExpression : Expression { + + List parameters; + + BlockStatement statementBody; + + Expression expressionBody; + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + public BlockStatement StatementBody { + get { + return statementBody; + } + set { + statementBody = value ?? BlockStatement.Null; + if (!statementBody.IsNull) statementBody.Parent = this; + } + } + + public Expression ExpressionBody { + get { + return expressionBody; + } + set { + expressionBody = value ?? Expression.Null; + if (!expressionBody.IsNull) expressionBody.Parent = this; + } + } + + public LambdaExpression() { + parameters = new List(); + statementBody = BlockStatement.Null; + expressionBody = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitLambdaExpression(this, data); + } + + public override string ToString() { + return string.Format("[LambdaExpression Parameters={0} StatementBody={1} ExpressionBody={2}]", GetCollectionString(Parameters), StatementBody, ExpressionBody); + } + } + public class LockStatement : StatementWithEmbeddedStatement { Expression lockExpression; @@ -2658,6 +2681,8 @@ namespace ICSharpCode.NRefactory.Ast { List templates; + bool isExtensionMethod; + public TypeReference TypeReference { get { return typeReference; @@ -2704,6 +2729,15 @@ namespace ICSharpCode.NRefactory.Ast { } } + public bool IsExtensionMethod { + get { + return isExtensionMethod; + } + set { + isExtensionMethod = value; + } + } + public MethodDeclaration(string name, Modifiers modifier, TypeReference typeReference, List parameters, List attributes) : base(modifier, attributes, name, parameters) { TypeReference = typeReference; @@ -2719,7 +2753,8 @@ namespace ICSharpCode.NRefactory.Ast { public override string ToString() { return string.Format("[MethodDeclaration TypeReference={0} Body={1} HandlesClause={2} InterfaceImplemen" + - "tations={3} Templates={4} Name={5} Parameters={6} Attributes={7} Modifier={8}]", TypeReference, Body, GetCollectionString(HandlesClause), GetCollectionString(InterfaceImplementations), GetCollectionString(Templates), Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + "tations={3} Templates={4} IsExtensionMethod={5} Name={6} Parameters={7} Attribut" + + "es={8} Modifier={9}]", TypeReference, Body, GetCollectionString(HandlesClause), GetCollectionString(InterfaceImplementations), GetCollectionString(Templates), IsExtensionMethod, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); } } @@ -2794,6 +2829,8 @@ namespace ICSharpCode.NRefactory.Ast { List parameters; + CollectionInitializerExpression objectInitializer; + public TypeReference CreateType { get { return createType; @@ -2812,9 +2849,26 @@ namespace ICSharpCode.NRefactory.Ast { } } + public CollectionInitializerExpression ObjectInitializer { + get { + return objectInitializer; + } + set { + objectInitializer = value ?? CollectionInitializerExpression.Null; + if (!objectInitializer.IsNull) objectInitializer.Parent = this; + } + } + public ObjectCreateExpression(TypeReference createType, List parameters) { CreateType = createType; Parameters = parameters; + objectInitializer = CollectionInitializerExpression.Null; + } + + public bool IsAnonymousType { + get { + return createType.IsNull || string.IsNullOrEmpty(createType.Type); + } } public override object AcceptVisitor(IAstVisitor visitor, object data) { @@ -2822,7 +2876,7 @@ namespace ICSharpCode.NRefactory.Ast { } public override string ToString() { - return string.Format("[ObjectCreateExpression CreateType={0} Parameters={1}]", CreateType, GetCollectionString(Parameters)); + return string.Format("[ObjectCreateExpression CreateType={0} Parameters={1} ObjectInitializer={2}]", CreateType, GetCollectionString(Parameters), ObjectInitializer); } } @@ -2901,7 +2955,8 @@ namespace ICSharpCode.NRefactory.Ast { public override string ToString() { return string.Format("[OperatorDeclaration ConversionType={0} ReturnTypeAttributes={1} OverloadableOper" + "ator={2} TypeReference={3} Body={4} HandlesClause={5} InterfaceImplementations={" + - "6} Templates={7} Name={8} Parameters={9} Attributes={10} Modifier={11}]", ConversionType, GetCollectionString(ReturnTypeAttributes), OverloadableOperator, TypeReference, Body, GetCollectionString(HandlesClause), GetCollectionString(InterfaceImplementations), GetCollectionString(Templates), Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + "6} Templates={7} IsExtensionMethod={8} Name={9} Parameters={10} Attributes={11} " + + "Modifier={12}]", ConversionType, GetCollectionString(ReturnTypeAttributes), OverloadableOperator, TypeReference, Body, GetCollectionString(HandlesClause), GetCollectionString(InterfaceImplementations), GetCollectionString(Templates), IsExtensionMethod, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); } } @@ -3223,6 +3278,18 @@ namespace ICSharpCode.NRefactory.Ast { } } + public bool HasSetRegion { + get { + return !setRegion.IsNull; + } + } + + public bool IsReadOnly { + get { + return HasGetRegion && !HasSetRegion; + } + } + public bool IsWriteOnly { get { return !HasGetRegion && HasSetRegion; @@ -3241,18 +3308,6 @@ namespace ICSharpCode.NRefactory.Ast { } } - public bool HasSetRegion { - get { - return !setRegion.IsNull; - } - } - - public bool IsReadOnly { - get { - return HasGetRegion && !HasSetRegion; - } - } - public override object AcceptVisitor(IAstVisitor visitor, object data) { return visitor.VisitPropertyDeclaration(this, data); } @@ -3285,19 +3340,13 @@ namespace ICSharpCode.NRefactory.Ast { } } - public class NullPropertyGetRegion : PropertyGetRegion { + internal sealed class NullPropertyGetRegion : PropertyGetRegion { private NullPropertyGetRegion() : base(null, null) { } - static NullPropertyGetRegion instance = new NullPropertyGetRegion(); - - public static NullPropertyGetRegion Instance { - get { - return instance; - } - } + internal static NullPropertyGetRegion Instance = new NullPropertyGetRegion(); public override bool IsNull { get { @@ -3373,19 +3422,13 @@ namespace ICSharpCode.NRefactory.Ast { } } - public class NullPropertySetRegion : PropertySetRegion { + internal sealed class NullPropertySetRegion : PropertySetRegion { private NullPropertySetRegion() : base(null, null) { } - static NullPropertySetRegion instance = new NullPropertySetRegion(); - - public static NullPropertySetRegion Instance { - get { - return instance; - } - } + internal static NullPropertySetRegion Instance = new NullPropertySetRegion(); public override bool IsNull { get { @@ -3402,15 +3445,438 @@ namespace ICSharpCode.NRefactory.Ast { } } - public class RaiseEventStatement : Statement { + public class QueryExpression : Expression { - string eventName; + QueryExpressionFromClause fromClause; - List arguments; + List fromOrWhereClauses; - public string EventName { - get { - return eventName; + List orderings; + + QueryExpressionClause selectOrGroupClause; + + QueryExpressionIntoClause intoClause; + + public QueryExpressionFromClause FromClause { + get { + return fromClause; + } + set { + fromClause = value ?? QueryExpressionFromClause.Null; + if (!fromClause.IsNull) fromClause.Parent = this; + } + } + + public List FromOrWhereClauses { + get { + return fromOrWhereClauses; + } + set { + fromOrWhereClauses = value ?? new List(); + } + } + + public List Orderings { + get { + return orderings; + } + set { + orderings = value ?? new List(); + } + } + + public QueryExpressionClause SelectOrGroupClause { + get { + return selectOrGroupClause; + } + set { + selectOrGroupClause = value ?? QueryExpressionClause.Null; + if (!selectOrGroupClause.IsNull) selectOrGroupClause.Parent = this; + } + } + + public QueryExpressionIntoClause IntoClause { + get { + return intoClause; + } + set { + intoClause = value ?? QueryExpressionIntoClause.Null; + if (!intoClause.IsNull) intoClause.Parent = this; + } + } + + public QueryExpression() { + fromClause = QueryExpressionFromClause.Null; + fromOrWhereClauses = new List(); + orderings = new List(); + selectOrGroupClause = QueryExpressionClause.Null; + intoClause = QueryExpressionIntoClause.Null; + } + + public new static QueryExpression Null { + get { + return NullQueryExpression.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpression(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpression FromClause={0} FromOrWhereClauses={1} Orderings={2} SelectOrGrou" + + "pClause={3} IntoClause={4}]", FromClause, GetCollectionString(FromOrWhereClauses), GetCollectionString(Orderings), SelectOrGroupClause, IntoClause); + } + } + + internal sealed class NullQueryExpression : QueryExpression { + + internal static NullQueryExpression Instance = new NullQueryExpression(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpression]"; + } + } + + public abstract class QueryExpressionClause : AbstractNode, INullable { + + public virtual bool IsNull { + get { + return false; + } + } + + public static QueryExpressionClause Null { + get { + return NullQueryExpressionClause.Instance; + } + } + } + + internal sealed class NullQueryExpressionClause : QueryExpressionClause { + + internal static NullQueryExpressionClause Instance = new NullQueryExpressionClause(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpressionClause]"; + } + } + + public class QueryExpressionFromClause : QueryExpressionClause { + + List generators; + + public List Generators { + get { + return generators; + } + set { + generators = value ?? new List(); + } + } + + public QueryExpressionFromClause() { + generators = new List(); + } + + public new static QueryExpressionFromClause Null { + get { + return NullQueryExpressionFromClause.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionFromClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionFromClause Generators={0}]", GetCollectionString(Generators)); + } + } + + internal sealed class NullQueryExpressionFromClause : QueryExpressionFromClause { + + internal static NullQueryExpressionFromClause Instance = new NullQueryExpressionFromClause(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpressionFromClause]"; + } + } + + public class QueryExpressionFromGenerator : AbstractNode { + + string identifier; + + Expression inExpression; + + public string Identifier { + get { + return identifier; + } + set { + identifier = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public Expression InExpression { + get { + return inExpression; + } + set { + inExpression = value ?? Expression.Null; + if (!inExpression.IsNull) inExpression.Parent = this; + } + } + + public QueryExpressionFromGenerator() { + identifier = "?"; + inExpression = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionFromGenerator(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionFromGenerator Identifier={0} InExpression={1}]", Identifier, InExpression); + } + } + + public class QueryExpressionGroupClause : QueryExpressionClause { + + Expression projection; + + Expression groupBy; + + public Expression Projection { + get { + return projection; + } + set { + projection = value ?? Expression.Null; + if (!projection.IsNull) projection.Parent = this; + } + } + + public Expression GroupBy { + get { + return groupBy; + } + set { + groupBy = value ?? Expression.Null; + if (!groupBy.IsNull) groupBy.Parent = this; + } + } + + public QueryExpressionGroupClause() { + projection = Expression.Null; + groupBy = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionGroupClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionGroupClause Projection={0} GroupBy={1}]", Projection, GroupBy); + } + } + + public class QueryExpressionIntoClause : QueryExpressionClause { + + string intoIdentifier; + + QueryExpression continuedQuery; + + public string IntoIdentifier { + get { + return intoIdentifier; + } + set { + intoIdentifier = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public QueryExpression ContinuedQuery { + get { + return continuedQuery; + } + set { + continuedQuery = value ?? QueryExpression.Null; + if (!continuedQuery.IsNull) continuedQuery.Parent = this; + } + } + + public QueryExpressionIntoClause() { + intoIdentifier = "?"; + continuedQuery = QueryExpression.Null; + } + + public new static QueryExpressionIntoClause Null { + get { + return NullQueryExpressionIntoClause.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionIntoClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionIntoClause IntoIdentifier={0} ContinuedQuery={1}]", IntoIdentifier, ContinuedQuery); + } + } + + internal sealed class NullQueryExpressionIntoClause : QueryExpressionIntoClause { + + internal static NullQueryExpressionIntoClause Instance = new NullQueryExpressionIntoClause(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpressionIntoClause]"; + } + } + + public class QueryExpressionOrdering : AbstractNode { + + Expression criteria; + + QueryExpressionOrderingDirection direction; + + public Expression Criteria { + get { + return criteria; + } + set { + criteria = value ?? Expression.Null; + if (!criteria.IsNull) criteria.Parent = this; + } + } + + public QueryExpressionOrderingDirection Direction { + get { + return direction; + } + set { + direction = value; + } + } + + public QueryExpressionOrdering() { + criteria = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionOrdering(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionOrdering Criteria={0} Direction={1}]", Criteria, Direction); + } + } + + public class QueryExpressionSelectClause : QueryExpressionClause { + + Expression projection; + + public Expression Projection { + get { + return projection; + } + set { + projection = value ?? Expression.Null; + if (!projection.IsNull) projection.Parent = this; + } + } + + public QueryExpressionSelectClause() { + projection = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionSelectClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionSelectClause Projection={0}]", Projection); + } + } + + public class QueryExpressionWhereClause : QueryExpressionClause { + + Expression condition; + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public QueryExpressionWhereClause() { + condition = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionWhereClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionWhereClause Condition={0}]", Condition); + } + } + + public class RaiseEventStatement : Statement { + + string eventName; + + List arguments; + + public string EventName { + get { + return eventName; } set { eventName = value ?? ""; @@ -4405,15 +4871,15 @@ public UsingDeclaration(string @namespace) : this(@namespace, null) {} Statement = statement; } - public bool IsYieldReturn { + public bool IsYieldBreak { get { - return statement is ReturnStatement; + return statement is BreakStatement; } } - public bool IsYieldBreak { + public bool IsYieldReturn { get { - return statement is BreakStatement; + return statement is ReturnStatement; } } diff --git a/src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs b/src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs index 2a51577b66..3f1f3ac854 100644 --- a/src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs +++ b/src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs @@ -197,6 +197,7 @@ namespace ICSharpCode.NRefactory.Ast return pointerNestingLevel; } set { + Debug.Assert(this.IsNull == false); pointerNestingLevel = value; } } @@ -212,6 +213,7 @@ namespace ICSharpCode.NRefactory.Ast return rankSpecifier; } set { + Debug.Assert(this.IsNull == false); rankSpecifier = value; } } @@ -233,7 +235,7 @@ namespace ICSharpCode.NRefactory.Ast return typeReference ?? NullTypeReference.Instance; } - public static NullTypeReference Null { + public static TypeReference Null { get { return NullTypeReference.Instance; } @@ -354,9 +356,9 @@ namespace ICSharpCode.NRefactory.Ast } } - public class NullTypeReference : TypeReference + internal sealed class NullTypeReference : TypeReference { - static NullTypeReference nullTypeReference = new NullTypeReference(); + public static readonly NullTypeReference Instance = new NullTypeReference(); public override bool IsNull { get { return true; @@ -366,12 +368,7 @@ namespace ICSharpCode.NRefactory.Ast { return null; } - public static NullTypeReference Instance { - get { - return nullTypeReference; - } - } - NullTypeReference() {} + public override string ToString() { return String.Format("[NullTypeReference]"); diff --git a/src/Libraries/NRefactory/Project/Src/EnvironmentInformationProvider.cs b/src/Libraries/NRefactory/Project/Src/EnvironmentInformationProvider.cs index 2926499ea8..4e2a7b9278 100644 --- a/src/Libraries/NRefactory/Project/Src/EnvironmentInformationProvider.cs +++ b/src/Libraries/NRefactory/Project/Src/EnvironmentInformationProvider.cs @@ -14,8 +14,10 @@ namespace ICSharpCode.NRefactory bool HasField(string fullTypeName, string fieldName); } - class DummyEnvironmentInformationProvider : IEnvironmentInformationProvider + sealed class DummyEnvironmentInformationProvider : IEnvironmentInformationProvider { + internal static readonly IEnvironmentInformationProvider Instance = new DummyEnvironmentInformationProvider(); + public bool HasField(string fullTypeName, string fieldName) { return false; diff --git a/src/Libraries/NRefactory/Project/Src/IAstVisitor.cs b/src/Libraries/NRefactory/Project/Src/IAstVisitor.cs index f3bbb2c091..e74db7d86a 100644 --- a/src/Libraries/NRefactory/Project/Src/IAstVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/IAstVisitor.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.42 +// Runtime Version:2.0.50727.312 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -23,8 +23,6 @@ namespace ICSharpCode.NRefactory { object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data); - object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data); - object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data); object VisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data); @@ -51,6 +49,8 @@ namespace ICSharpCode.NRefactory { object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data); + object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data); + object VisitCompilationUnit(CompilationUnit compilationUnit, object data); object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data); @@ -127,6 +127,8 @@ namespace ICSharpCode.NRefactory { object VisitLabelStatement(LabelStatement labelStatement, object data); + object VisitLambdaExpression(LambdaExpression lambdaExpression, object data); + object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data); object VisitLockStatement(LockStatement lockStatement, object data); @@ -159,6 +161,22 @@ namespace ICSharpCode.NRefactory { object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data); + object VisitQueryExpression(QueryExpression queryExpression, object data); + + object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data); + + object VisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data); + + object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data); + + object VisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data); + + object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data); + + object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data); + + object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data); + object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data); object VisitReDimStatement(ReDimStatement reDimStatement, object data); diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/BuildKeywords.pl b/src/Libraries/NRefactory/Project/Src/Lexer/BuildKeywords.pl index 083fe28f60..d5488dd73b 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/BuildKeywords.pl +++ b/src/Libraries/NRefactory/Project/Src/Lexer/BuildKeywords.pl @@ -78,7 +78,7 @@ sub write_keywordfile print DAT "\n"; print DAT "namespace " . $properties{'Namespace'} . "\n"; print DAT "{\n"; - print DAT "\tpublic class Keywords\n"; + print DAT "\tpublic static class Keywords\n"; print DAT "\t{\n"; print DAT "\t\tstatic readonly string[] keywordList = {\n"; if ($properties{'UpperCaseKeywords'} eq "True") { @@ -209,6 +209,14 @@ sub write_tokensfile { print DAT "\t\t\t}\n"; print DAT "\t\t\treturn bitArray;\n"; print DAT "\t\t}\n"; + print DAT "\t\tstatic BitArray NewSet(BitArray existing, params int[] values)\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\tBitArray bitArray = new BitArray(existing);\n"; + print DAT "\t\t\tforeach (int val in values) {\n"; + print DAT "\t\t\tbitArray[val] = true;\n"; + print DAT "\t\t\t}\n"; + print DAT "\t\t\treturn bitArray;\n"; + print DAT "\t\t}\n"; for ($i=0; $i <= $#sets; $i++) { print DAT "\t\tpublic static BitArray ". $sets[$i] . " = NewSet("; print_list($i); @@ -266,10 +274,10 @@ sub write_unittests { print DAT "\t{\n"; print DAT "\t\tILexer GenerateLexer(StringReader sr)\n"; print DAT "\t\t{\n"; - print DAT "\t\t\treturn ParserFactory.CreateLexer(SupportedLanguages.CSharp, sr);\n"; + print DAT "\t\t\treturn ParserFactory.CreateLexer(SupportedLanguage.CSharp, sr);\n"; print DAT "\t\t}\n\n"; - for ($i=0; $i < $#special_values; $i++) { + for ($i=0; $i <= $#special_values; $i++) { print DAT "\t\t[Test]\n"; print DAT "\t\tpublic void Test" . $special_chars[$i] ."()\n"; diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt index 6d0fffbd43..ab0b31e5bf 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt +++ b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt @@ -73,6 +73,7 @@ ShiftLeftAssign = "<<=" #Removed because of generics #ShiftRightAssign = ">>=" Pointer = "->" +LambdaArrow = "=>" # Keywordlist "abstract" @@ -153,15 +154,35 @@ Pointer = "->" "volatile" "while" +# Context dependent keywords. +"partial" +"where" +"get" +"set" +"add" +"remove" +"yield" +"select" +"group" +"by" +"into" +"from" +"ascending" +"descending" +"orderby" + #Sets +# When changing IdentifierTokens, ensure you also change the "Identifier" production in cs.ATG +IdentifierTokens(Identifier, "partial", "where", "get", "set", "add", "remove", "yield", "select", "group", "by", "into", "from", "ascending", "descending", "orderby") + OverloadableUnaryOp("+", "!", "~", "++", "--", "true", "false") OverloadableBinaryOp("+", "-", "*", "/", "%", "&", "|", "^", "<<", "==", "!=", ">", "<", ">=", "<=") TypeKW("char", "bool", "object", "string", "sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "float", "double", "decimal") UnaryHead("+", "-", "!", "~", "*", "++", "--", "&") AssnStartOp("+", "-", "!", "~", "*") -CastFollower(Identifier, Literal, "(", "new", "this", "base", "null", "checked", "unchecked", "typeof", "sizeof", "delegate", @OverloadableUnaryOp) +CastFollower(IdentifierTokens, Literal, "(", "new", "this", "base", "null", "checked", "unchecked", "typeof", "sizeof", "delegate", @OverloadableUnaryOp) AssgnOps("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=") UnaryOp("+", "-", "!", "~", "*", "++", "--", "&") TypeDeclarationKW("class", "interface", "struct", "enum", "delegate") diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Keywords.cs b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Keywords.cs index 1551d9dcce..e8742a17ff 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Keywords.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Keywords.cs @@ -1,10 +1,3 @@ -// -// -// -// -// $Revision$ -// - // this file was autogenerated by a tool. using System; @@ -89,7 +82,22 @@ namespace ICSharpCode.NRefactory.Parser.CSharp "virtual", "void", "volatile", - "while" + "while", + "partial", + "where", + "get", + "set", + "add", + "remove", + "yield", + "select", + "group", + "by", + "into", + "from", + "ascending", + "descending", + "orderby" }; static LookupTable keywords = new LookupTable(true); diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs index 1f59febb21..6ce9eff36b 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs @@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp string s = ReadIdent(ch); int keyWordToken = Keywords.GetToken(s); if (keyWordToken >= 0) { - return new Token(keyWordToken, x, y); + return new Token(keyWordToken, x, y, s); } return new Token(Tokens.Identifier, x, y, s); } else if (Char.IsDigit(ch)) { @@ -617,6 +617,9 @@ namespace ICSharpCode.NRefactory.Parser.CSharp case '=': ReaderRead(); return new Token(Tokens.Equal, x, y); + case '>': + ReaderRead(); + return new Token(Tokens.LambdaArrow, x, y); } return new Token(Tokens.Assign, x, y); case '<': diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs index 6a96598074..42b0ecb25b 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs @@ -1,10 +1,3 @@ -// -// -// -// -// $Revision$ -// - // this file was autogenerated by a tool. using System; using System.Collections; @@ -64,87 +57,103 @@ namespace ICSharpCode.NRefactory.Parser.CSharp public const int XorAssign = 45; public const int ShiftLeftAssign = 46; public const int Pointer = 47; + public const int LambdaArrow = 48; // ----- keywords ----- - public const int Abstract = 48; - public const int As = 49; - public const int Base = 50; - public const int Bool = 51; - public const int Break = 52; - public const int Byte = 53; - public const int Case = 54; - public const int Catch = 55; - public const int Char = 56; - public const int Checked = 57; - public const int Class = 58; - public const int Const = 59; - public const int Continue = 60; - public const int Decimal = 61; - public const int Default = 62; - public const int Delegate = 63; - public const int Do = 64; - public const int Double = 65; - public const int Else = 66; - public const int Enum = 67; - public const int Event = 68; - public const int Explicit = 69; - public const int Extern = 70; - public const int False = 71; - public const int Finally = 72; - public const int Fixed = 73; - public const int Float = 74; - public const int For = 75; - public const int Foreach = 76; - public const int Goto = 77; - public const int If = 78; - public const int Implicit = 79; - public const int In = 80; - public const int Int = 81; - public const int Interface = 82; - public const int Internal = 83; - public const int Is = 84; - public const int Lock = 85; - public const int Long = 86; - public const int Namespace = 87; - public const int New = 88; - public const int Null = 89; - public const int Object = 90; - public const int Operator = 91; - public const int Out = 92; - public const int Override = 93; - public const int Params = 94; - public const int Private = 95; - public const int Protected = 96; - public const int Public = 97; - public const int Readonly = 98; - public const int Ref = 99; - public const int Return = 100; - public const int Sbyte = 101; - public const int Sealed = 102; - public const int Short = 103; - public const int Sizeof = 104; - public const int Stackalloc = 105; - public const int Static = 106; - public const int String = 107; - public const int Struct = 108; - public const int Switch = 109; - public const int This = 110; - public const int Throw = 111; - public const int True = 112; - public const int Try = 113; - public const int Typeof = 114; - public const int Uint = 115; - public const int Ulong = 116; - public const int Unchecked = 117; - public const int Unsafe = 118; - public const int Ushort = 119; - public const int Using = 120; - public const int Virtual = 121; - public const int Void = 122; - public const int Volatile = 123; - public const int While = 124; + public const int Abstract = 49; + public const int As = 50; + public const int Base = 51; + public const int Bool = 52; + public const int Break = 53; + public const int Byte = 54; + public const int Case = 55; + public const int Catch = 56; + public const int Char = 57; + public const int Checked = 58; + public const int Class = 59; + public const int Const = 60; + public const int Continue = 61; + public const int Decimal = 62; + public const int Default = 63; + public const int Delegate = 64; + public const int Do = 65; + public const int Double = 66; + public const int Else = 67; + public const int Enum = 68; + public const int Event = 69; + public const int Explicit = 70; + public const int Extern = 71; + public const int False = 72; + public const int Finally = 73; + public const int Fixed = 74; + public const int Float = 75; + public const int For = 76; + public const int Foreach = 77; + public const int Goto = 78; + public const int If = 79; + public const int Implicit = 80; + public const int In = 81; + public const int Int = 82; + public const int Interface = 83; + public const int Internal = 84; + public const int Is = 85; + public const int Lock = 86; + public const int Long = 87; + public const int Namespace = 88; + public const int New = 89; + public const int Null = 90; + public const int Object = 91; + public const int Operator = 92; + public const int Out = 93; + public const int Override = 94; + public const int Params = 95; + public const int Private = 96; + public const int Protected = 97; + public const int Public = 98; + public const int Readonly = 99; + public const int Ref = 100; + public const int Return = 101; + public const int Sbyte = 102; + public const int Sealed = 103; + public const int Short = 104; + public const int Sizeof = 105; + public const int Stackalloc = 106; + public const int Static = 107; + public const int String = 108; + public const int Struct = 109; + public const int Switch = 110; + public const int This = 111; + public const int Throw = 112; + public const int True = 113; + public const int Try = 114; + public const int Typeof = 115; + public const int Uint = 116; + public const int Ulong = 117; + public const int Unchecked = 118; + public const int Unsafe = 119; + public const int Ushort = 120; + public const int Using = 121; + public const int Virtual = 122; + public const int Void = 123; + public const int Volatile = 124; + public const int While = 125; + public const int Partial = 126; + public const int Where = 127; + public const int Get = 128; + public const int Set = 129; + public const int Add = 130; + public const int Remove = 131; + public const int Yield = 132; + public const int Select = 133; + public const int Group = 134; + public const int By = 135; + public const int Into = 136; + public const int From = 137; + public const int Ascending = 138; + public const int Descending = 139; + public const int Orderby = 140; - public const int MaxToken = 125; + public const int MaxToken = 141; static BitArray NewSet(params int[] values) { BitArray bitArray = new BitArray(MaxToken); @@ -153,12 +162,21 @@ namespace ICSharpCode.NRefactory.Parser.CSharp } return bitArray; } + static BitArray NewSet(BitArray existing, params int[] values) + { + BitArray bitArray = new BitArray(existing); + foreach (int val in values) { + bitArray[val] = true; + } + return bitArray; + } + public static BitArray IdentifierTokens = NewSet(Identifier, Partial, Where, Get, Set, Add, Remove, Yield, Select, Group, By, Into, From, Ascending, Descending, Orderby); public static BitArray OverloadableUnaryOp = NewSet(Plus, Not, BitwiseComplement, Increment, Decrement, True, False); public static BitArray OverloadableBinaryOp = NewSet(Plus, Minus, Times, Div, Mod, BitwiseAnd, BitwiseOr, Xor, ShiftLeft, Equal, NotEqual, GreaterThan, LessThan, GreaterEqual, LessEqual); public static BitArray TypeKW = NewSet(Char, Bool, Object, String, Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Float, Double, Decimal); public static BitArray UnaryHead = NewSet(Plus, Minus, Not, BitwiseComplement, Times, Increment, Decrement, BitwiseAnd); public static BitArray AssnStartOp = NewSet(Plus, Minus, Not, BitwiseComplement, Times); - public static BitArray CastFollower = NewSet(Identifier, Literal, OpenParenthesis, New, This, Base, Null, Checked, Unchecked, Typeof, Sizeof, Delegate, Plus, Not, BitwiseComplement, Increment, Decrement, True, False); + public static BitArray CastFollower = NewSet(IdentifierTokens, Literal, OpenParenthesis, New, This, Base, Null, Checked, Unchecked, Typeof, Sizeof, Delegate, Plus, Not, BitwiseComplement, Increment, Decrement, True, False); public static BitArray AssgnOps = NewSet(Assign, PlusAssign, MinusAssign, TimesAssign, DivAssign, ModAssign, BitwiseAndAssign, BitwiseOrAssign, ShiftLeftAssign); public static BitArray UnaryOp = NewSet(Plus, Minus, Not, BitwiseComplement, Times, Increment, Decrement, BitwiseAnd); public static BitArray TypeDeclarationKW = NewSet(Class, Interface, Struct, Enum, Delegate); @@ -214,6 +232,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp "^=", "<<=", "->", + "=>", // ----- keywords ----- "abstract", "as", @@ -292,6 +311,21 @@ namespace ICSharpCode.NRefactory.Parser.CSharp "void", "volatile", "while", + "partial", + "where", + "get", + "set", + "add", + "remove", + "yield", + "select", + "group", + "by", + "into", + "from", + "ascending", + "descending", + "orderby", }; public static string GetTokenString(int token) { diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs index 5c3b838e96..ce02eaa2bc 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Diagnostics; using ICSharpCode.NRefactory.Ast; @@ -20,6 +21,9 @@ namespace ICSharpCode.NRefactory.Parser.CSharp public Parser(ILexer lexer) : base(lexer) { this.lexer = (Lexer)lexer; + // due to anonymous methods, we always need a compilation unit, so + // create it in the constructor + compilationUnit = new CompilationUnit(); } StringBuilder qualidentBuilder = new StringBuilder(); @@ -76,7 +80,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp if (!IsTypeKWForTypeCast(ref pt)) { return false; } - if (pt.kind == Tokens.Question) + if (pt.kind == Tokens.Question) // TODO: check if IsTypeKWForTypeCast doesn't already to this pt = lexer.Peek(); return pt.kind == Tokens.CloseParenthesis; } @@ -97,8 +101,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp /* !!! Proceeds from current peek position !!! */ bool IsTypeNameOrKWForTypeCast(ref Token pt) { - if (IsTypeKWForTypeCast(ref pt)) - return true; + if (Tokens.TypeKW[pt.kind] || pt.kind == Tokens.Void) + return IsTypeKWForTypeCast(ref pt); else return IsTypeNameForTypeCast(ref pt); } @@ -108,14 +112,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp bool IsTypeNameForTypeCast(ref Token pt) { // ident - if (pt.kind != Tokens.Identifier) { + if (!IsIdentifierToken(pt)) { return false; } pt = Peek(); // "::" ident if (pt.kind == Tokens.DoubleColon) { pt = Peek(); - if (pt.kind != Tokens.Identifier) { + if (!IsIdentifierToken(pt)) { return false; } pt = Peek(); @@ -172,18 +176,49 @@ namespace ICSharpCode.NRefactory.Parser.CSharp return Tokens.CastFollower[pt.kind] || (Tokens.TypeKW[pt.kind] && lexer.Peek().kind == Tokens.Dot); } // END IsTypeCast + + // ( { [TypeNameOrKWForTypeCast] ident "," } ) + bool IsLambdaExpression() + { + if (la.kind != Tokens.OpenParenthesis) { + return false; + } + StartPeek(); + Token pt = Peek(); + while (pt.kind != Tokens.CloseParenthesis) { + if (!IsTypeNameOrKWForTypeCast(ref pt)) { + return false; + } + if (IsIdentifierToken(pt)) { + // make ident optional: if implicitly typed lambda arguments are used, IsTypeNameForTypeCast + // has already accepted the identifier + pt = Peek(); + } + if (pt.kind == Tokens.CloseParenthesis) { + break; + } + // require comma between parameters: + if (pt.kind == Tokens.Comma) { + pt = Peek(); + } else { + return false; + } + } + pt = Peek(); + return pt.kind == Tokens.LambdaArrow; + } /* Checks whether the next sequences of tokens is a qualident * * and returns the qualident string */ /* !!! Proceeds from current peek position !!! */ bool IsQualident(ref Token pt, out string qualident) { - if (pt.kind == Tokens.Identifier) { + if (IsIdentifierToken(pt)) { qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val); pt = Peek(); while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) { pt = Peek(); - if (pt.kind != Tokens.Identifier) { + if (!IsIdentifierToken(pt)) { qualident = String.Empty; return false; } @@ -248,7 +283,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp /* True, if ident is followed by "=" */ bool IdentAndAsgn () { - return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Assign; + return IsIdentifierToken(la) && Peek(1).kind == Tokens.Assign; + } + + bool IdentAndDoubleColon () + { + return IsIdentifierToken(la) && Peek(1).kind == Tokens.DoubleColon; } bool IsAssignment () { return IdentAndAsgn(); } @@ -256,7 +296,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp /* True, if ident is followed by ",", "=", "[" or ";" */ bool IsVarDecl () { int peek = Peek(1).kind; - return la.kind == Tokens.Identifier && + return IsIdentifierToken(la) && (peek == Tokens.Comma || peek == Tokens.Assign || peek == Tokens.Semicolon || peek == Tokens.OpenSquareBracket); } @@ -281,19 +321,19 @@ namespace ICSharpCode.NRefactory.Parser.CSharp /* True, if "." is followed by an ident */ bool DotAndIdent () { - return la.kind == Tokens.Dot && Peek(1).kind == Tokens.Identifier; + return la.kind == Tokens.Dot && IsIdentifierToken(Peek(1)); } /* True, if ident is followed by ":" */ bool IdentAndColon () { - return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Colon; + return IsIdentifierToken(la) && Peek(1).kind == Tokens.Colon; } bool IsLabel () { return IdentAndColon(); } /* True, if ident is followed by "(" */ bool IdentAndLPar () { - return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.OpenParenthesis; + return IsIdentifierToken(la) && Peek(1).kind == Tokens.OpenParenthesis; } /* True, if "catch" is followed by "(" */ @@ -306,7 +346,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp bool IsGlobalAttrTarget () { Token pt = Peek(1); return la.kind == Tokens.OpenSquareBracket && - pt.kind == Tokens.Identifier && pt.val == "assembly"; + IsIdentifierToken(pt) && pt.val == "assembly"; } /* True, if "[" is followed by "," or "]" */ @@ -357,7 +397,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp StartPeek(); Token pt = la; - return IsTypeNameOrKWForTypeCast(ref pt) && pt.kind == Tokens.Identifier; + return IsTypeNameOrKWForTypeCast(ref pt) && IsIdentifierToken(pt); } /* True if lookahead is type parameters (<...>) followed by the specified token */ @@ -383,34 +423,9 @@ namespace ICSharpCode.NRefactory.Parser.CSharp return false; } - /* True, if lookahead ident is "where" */ - bool IdentIsWhere () { - return la.kind == Tokens.Identifier && la.val == "where"; - } - - /* True, if lookahead ident is "get" */ - bool IdentIsGet () { - return la.kind == Tokens.Identifier && la.val == "get"; - } - - /* True, if lookahead ident is "set" */ - bool IdentIsSet () { - return la.kind == Tokens.Identifier && la.val == "set"; - } - - /* True, if lookahead ident is "add" */ - bool IdentIsAdd () { - return la.kind == Tokens.Identifier && la.val == "add"; - } - - /* True, if lookahead ident is "remove" */ - bool IdentIsRemove () { - return la.kind == Tokens.Identifier && la.val == "remove"; - } - /* True, if lookahead ident is "yield" and than follows a break or return */ bool IsYieldStatement () { - return la.kind == Tokens.Identifier && la.val == "yield" && (Peek(1).kind == Tokens.Return || Peek(1).kind == Tokens.Break); + return la.kind == Tokens.Yield && (Peek(1).kind == Tokens.Return || Peek(1).kind == Tokens.Break); } /* True, if lookahead is a local attribute target specifier, * @@ -421,7 +436,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp string val = la.val; return (cur == Tokens.Event || cur == Tokens.Return || - (cur == Tokens.Identifier && + (Tokens.IdentifierTokens[cur] && (val == "field" || val == "method" || val == "module" || val == "param" || val == "property" || val == "type"))) && Peek(1).kind == Tokens.Colon; @@ -490,5 +505,30 @@ namespace ICSharpCode.NRefactory.Parser.CSharp return false; } } + + bool StartOfQueryExpression() + { + return la.kind == Tokens.From && IsIdentifierToken(Peek(1)); + } + + static bool IsIdentifierToken(Token tk) + { + return Tokens.IdentifierTokens[tk.kind]; + } + + /// + /// Adds a child item to a collection stored in the parent node. + /// Also set's the item's parent to . + /// Does nothing if item is null. + /// + static void SafeAdd(INode parent, List list, T item) where T : class, INode + { + Debug.Assert(parent != null); + Debug.Assert((parent is INullable) ? !(parent as INullable).IsNull : true); + if (item != null) { + list.Add(item); + item.Parent = parent; + } + } } } diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs index b547d201dd..80e99185cc 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs @@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp { partial class Parser : AbstractParser { - const int maxT = 125; + const int maxT = 141; const bool T = true; const bool x = false; @@ -35,14 +35,13 @@ partial class Parser : AbstractParser void CS() { -#line 159 "cs.ATG" - lexer.NextToken(); /* get the first token */ - compilationUnit = new CompilationUnit(); - while (la.kind == 120) { +#line 175 "cs.ATG" + lexer.NextToken(); /* get the first token */ + while (la.kind == 121) { UsingDirective(); } while ( -#line 163 "cs.ATG" +#line 178 "cs.ATG" IsGlobalAttrTarget()) { GlobalAttributeSection(); } @@ -54,25 +53,25 @@ IsGlobalAttrTarget()) { void UsingDirective() { -#line 170 "cs.ATG" +#line 185 "cs.ATG" string qualident = null; TypeReference aliasedType = null; - Expect(120); + Expect(121); -#line 173 "cs.ATG" +#line 188 "cs.ATG" Location startPos = t.Location; Qualident( -#line 174 "cs.ATG" +#line 189 "cs.ATG" out qualident); if (la.kind == 3) { lexer.NextToken(); NonArrayType( -#line 175 "cs.ATG" +#line 190 "cs.ATG" out aliasedType); } Expect(11); -#line 177 "cs.ATG" +#line 192 "cs.ATG" if (qualident != null && qualident.Length > 0) { INode node; if (aliasedType != null) { @@ -90,11 +89,11 @@ out aliasedType); void GlobalAttributeSection() { Expect(18); -#line 193 "cs.ATG" +#line 208 "cs.ATG" Location startPos = t.Location; - Expect(1); + Identifier(); -#line 194 "cs.ATG" +#line 209 "cs.ATG" if (t.val != "assembly") Error("global attribute target specifier (\"assembly\") expected"); string attributeTarget = t.val; List attributes = new List(); @@ -102,20 +101,20 @@ out aliasedType); Expect(9); Attribute( -#line 199 "cs.ATG" +#line 214 "cs.ATG" out attribute); -#line 199 "cs.ATG" +#line 214 "cs.ATG" attributes.Add(attribute); while ( -#line 200 "cs.ATG" +#line 215 "cs.ATG" NotFinalComma()) { Expect(14); Attribute( -#line 200 "cs.ATG" +#line 215 "cs.ATG" out attribute); -#line 200 "cs.ATG" +#line 215 "cs.ATG" attributes.Add(attribute); } if (la.kind == 14) { @@ -123,7 +122,7 @@ out attribute); } Expect(19); -#line 202 "cs.ATG" +#line 217 "cs.ATG" AttributeSection section = new AttributeSection(attributeTarget, attributes); section.StartLocation = startPos; section.EndLocation = t.EndLocation; @@ -133,29 +132,29 @@ out attribute); void NamespaceMemberDecl() { -#line 293 "cs.ATG" +#line 308 "cs.ATG" AttributeSection section; List attributes = new List(); ModifierList m = new ModifierList(); string qualident; - if (la.kind == 87) { + if (la.kind == 88) { lexer.NextToken(); -#line 299 "cs.ATG" +#line 314 "cs.ATG" Location startPos = t.Location; Qualident( -#line 300 "cs.ATG" +#line 315 "cs.ATG" out qualident); -#line 300 "cs.ATG" +#line 315 "cs.ATG" INode node = new NamespaceDeclaration(qualident); node.StartLocation = startPos; compilationUnit.AddChild(node); compilationUnit.BlockStart(node); Expect(16); - while (la.kind == 120) { + while (la.kind == 121) { UsingDirective(); } while (StartOf(1)) { @@ -166,162 +165,232 @@ out qualident); lexer.NextToken(); } -#line 309 "cs.ATG" +#line 324 "cs.ATG" node.EndLocation = t.EndLocation; compilationUnit.BlockEnd(); } else if (StartOf(2)) { while (la.kind == 18) { AttributeSection( -#line 313 "cs.ATG" +#line 328 "cs.ATG" out section); -#line 313 "cs.ATG" +#line 328 "cs.ATG" attributes.Add(section); } while (StartOf(3)) { TypeModifier( -#line 314 "cs.ATG" +#line 329 "cs.ATG" m); } TypeDecl( -#line 315 "cs.ATG" +#line 330 "cs.ATG" m, attributes); - } else SynErr(126); + } else SynErr(142); } void Qualident( -#line 437 "cs.ATG" +#line 452 "cs.ATG" out string qualident) { - Expect(1); + Identifier(); -#line 439 "cs.ATG" +#line 454 "cs.ATG" qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); while ( -#line 440 "cs.ATG" +#line 455 "cs.ATG" DotAndIdent()) { Expect(15); - Expect(1); + Identifier(); -#line 440 "cs.ATG" +#line 455 "cs.ATG" qualidentBuilder.Append('.'); qualidentBuilder.Append(t.val); } -#line 443 "cs.ATG" +#line 458 "cs.ATG" qualident = qualidentBuilder.ToString(); } void NonArrayType( -#line 552 "cs.ATG" +#line 567 "cs.ATG" out TypeReference type) { -#line 554 "cs.ATG" +#line 569 "cs.ATG" string name; int pointer = 0; type = null; - if (la.kind == 1 || la.kind == 90 || la.kind == 107) { + if (StartOf(4)) { ClassType( -#line 559 "cs.ATG" +#line 574 "cs.ATG" out type, false); - } else if (StartOf(4)) { + } else if (StartOf(5)) { SimpleType( -#line 560 "cs.ATG" +#line 575 "cs.ATG" out name); -#line 560 "cs.ATG" +#line 575 "cs.ATG" type = new TypeReference(name); - } else if (la.kind == 122) { + } else if (la.kind == 123) { lexer.NextToken(); Expect(6); -#line 561 "cs.ATG" +#line 576 "cs.ATG" pointer = 1; type = new TypeReference("void"); - } else SynErr(127); + } else SynErr(143); if (la.kind == 12) { NullableQuestionMark( -#line 564 "cs.ATG" +#line 579 "cs.ATG" ref type); } while ( -#line 566 "cs.ATG" +#line 581 "cs.ATG" IsPointer()) { Expect(6); -#line 567 "cs.ATG" +#line 582 "cs.ATG" ++pointer; } -#line 569 "cs.ATG" +#line 584 "cs.ATG" if (type != null) { type.PointerNestingLevel = pointer; } } + void Identifier() { + switch (la.kind) { + case 1: { + lexer.NextToken(); + break; + } + case 126: { + lexer.NextToken(); + break; + } + case 127: { + lexer.NextToken(); + break; + } + case 128: { + lexer.NextToken(); + break; + } + case 129: { + lexer.NextToken(); + break; + } + case 130: { + lexer.NextToken(); + break; + } + case 131: { + lexer.NextToken(); + break; + } + case 132: { + lexer.NextToken(); + break; + } + case 133: { + lexer.NextToken(); + break; + } + case 134: { + lexer.NextToken(); + break; + } + case 135: { + lexer.NextToken(); + break; + } + case 136: { + lexer.NextToken(); + break; + } + case 137: { + lexer.NextToken(); + break; + } + case 138: { + lexer.NextToken(); + break; + } + case 139: { + lexer.NextToken(); + break; + } + case 140: { + lexer.NextToken(); + break; + } + default: SynErr(144); break; + } + } + void Attribute( -#line 209 "cs.ATG" +#line 224 "cs.ATG" out ASTAttribute attribute) { -#line 210 "cs.ATG" +#line 225 "cs.ATG" string qualident; string alias = null; if ( -#line 214 "cs.ATG" -la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) { - lexer.NextToken(); +#line 229 "cs.ATG" +IdentAndDoubleColon()) { + Identifier(); -#line 215 "cs.ATG" +#line 230 "cs.ATG" alias = t.val; Expect(10); } Qualident( -#line 218 "cs.ATG" +#line 233 "cs.ATG" out qualident); -#line 219 "cs.ATG" +#line 234 "cs.ATG" List positional = new List(); List named = new List(); string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident; if (la.kind == 20) { AttributeArguments( -#line 223 "cs.ATG" +#line 238 "cs.ATG" positional, named); } -#line 223 "cs.ATG" +#line 238 "cs.ATG" attribute = new ASTAttribute(name, positional, named); } void AttributeArguments( -#line 226 "cs.ATG" +#line 241 "cs.ATG" List positional, List named) { -#line 228 "cs.ATG" +#line 243 "cs.ATG" bool nameFound = false; string name = ""; Expression expr; Expect(20); - if (StartOf(5)) { + if (StartOf(6)) { if ( -#line 236 "cs.ATG" +#line 251 "cs.ATG" IsAssignment()) { -#line 236 "cs.ATG" +#line 251 "cs.ATG" nameFound = true; - lexer.NextToken(); + Identifier(); -#line 237 "cs.ATG" +#line 252 "cs.ATG" name = t.val; Expect(3); } Expr( -#line 239 "cs.ATG" +#line 254 "cs.ATG" out expr); -#line 239 "cs.ATG" +#line 254 "cs.ATG" if (expr != null) {if(name == "") positional.Add(expr); else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } } @@ -329,26 +398,26 @@ out expr); while (la.kind == 14) { lexer.NextToken(); if ( -#line 247 "cs.ATG" +#line 262 "cs.ATG" IsAssignment()) { -#line 247 "cs.ATG" +#line 262 "cs.ATG" nameFound = true; - Expect(1); + Identifier(); -#line 248 "cs.ATG" +#line 263 "cs.ATG" name = t.val; Expect(3); - } else if (StartOf(5)) { + } else if (StartOf(6)) { -#line 250 "cs.ATG" +#line 265 "cs.ATG" if (nameFound) Error("no positional argument after named argument"); - } else SynErr(128); + } else SynErr(145); Expr( -#line 251 "cs.ATG" +#line 266 "cs.ATG" out expr); -#line 251 "cs.ATG" +#line 266 "cs.ATG" if (expr != null) { if(name == "") positional.Add(expr); else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } } @@ -359,70 +428,70 @@ out expr); } void Expr( -#line 1611 "cs.ATG" +#line 1649 "cs.ATG" out Expression expr) { -#line 1612 "cs.ATG" +#line 1650 "cs.ATG" expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; UnaryExpr( -#line 1614 "cs.ATG" +#line 1652 "cs.ATG" out expr); - if (StartOf(6)) { + if (StartOf(7)) { AssignmentOperator( -#line 1617 "cs.ATG" +#line 1655 "cs.ATG" out op); Expr( -#line 1617 "cs.ATG" +#line 1655 "cs.ATG" out expr1); -#line 1617 "cs.ATG" +#line 1655 "cs.ATG" expr = new AssignmentExpression(expr, op, expr1); } else if ( -#line 1618 "cs.ATG" +#line 1656 "cs.ATG" la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) { AssignmentOperator( -#line 1619 "cs.ATG" +#line 1657 "cs.ATG" out op); Expr( -#line 1619 "cs.ATG" +#line 1657 "cs.ATG" out expr1); -#line 1619 "cs.ATG" +#line 1657 "cs.ATG" expr = new AssignmentExpression(expr, op, expr1); - } else if (StartOf(7)) { + } else if (StartOf(8)) { ConditionalOrExpr( -#line 1621 "cs.ATG" +#line 1659 "cs.ATG" ref expr); if (la.kind == 13) { lexer.NextToken(); Expr( -#line 1622 "cs.ATG" +#line 1660 "cs.ATG" out expr1); -#line 1622 "cs.ATG" +#line 1660 "cs.ATG" expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); } if (la.kind == 12) { lexer.NextToken(); Expr( -#line 1623 "cs.ATG" +#line 1661 "cs.ATG" out expr1); Expect(9); Expr( -#line 1623 "cs.ATG" +#line 1661 "cs.ATG" out expr2); -#line 1623 "cs.ATG" +#line 1661 "cs.ATG" expr = new ConditionalExpression(expr, expr1, expr2); } - } else SynErr(129); + } else SynErr(146); } void AttributeSection( -#line 260 "cs.ATG" +#line 275 "cs.ATG" out AttributeSection section) { -#line 262 "cs.ATG" +#line 277 "cs.ATG" string attributeTarget = ""; List attributes = new List(); ASTAttribute attribute; @@ -430,25 +499,25 @@ out AttributeSection section) { Expect(18); -#line 268 "cs.ATG" +#line 283 "cs.ATG" Location startPos = t.Location; if ( -#line 269 "cs.ATG" +#line 284 "cs.ATG" IsLocalAttrTarget()) { - if (la.kind == 68) { + if (la.kind == 69) { lexer.NextToken(); -#line 270 "cs.ATG" +#line 285 "cs.ATG" attributeTarget = "event"; - } else if (la.kind == 100) { + } else if (la.kind == 101) { lexer.NextToken(); -#line 271 "cs.ATG" +#line 286 "cs.ATG" attributeTarget = "return"; } else { - lexer.NextToken(); + Identifier(); -#line 272 "cs.ATG" +#line 287 "cs.ATG" if (t.val != "field" || t.val != "method" || t.val != "module" || t.val != "param" || t.val != "property" || t.val != "type") @@ -460,20 +529,20 @@ IsLocalAttrTarget()) { Expect(9); } Attribute( -#line 282 "cs.ATG" +#line 297 "cs.ATG" out attribute); -#line 282 "cs.ATG" +#line 297 "cs.ATG" attributes.Add(attribute); while ( -#line 283 "cs.ATG" +#line 298 "cs.ATG" NotFinalComma()) { Expect(14); Attribute( -#line 283 "cs.ATG" +#line 298 "cs.ATG" out attribute); -#line 283 "cs.ATG" +#line 298 "cs.ATG" attributes.Add(attribute); } if (la.kind == 14) { @@ -481,7 +550,7 @@ out attribute); } Expect(19); -#line 285 "cs.ATG" +#line 300 "cs.ATG" section = new AttributeSection(attributeTarget, attributes); section.StartLocation = startPos; section.EndLocation = t.EndLocation; @@ -489,101 +558,101 @@ out attribute); } void TypeModifier( -#line 639 "cs.ATG" +#line 654 "cs.ATG" ModifierList m) { switch (la.kind) { - case 88: { + case 89: { lexer.NextToken(); -#line 641 "cs.ATG" +#line 656 "cs.ATG" m.Add(Modifiers.New, t.Location); break; } - case 97: { + case 98: { lexer.NextToken(); -#line 642 "cs.ATG" +#line 657 "cs.ATG" m.Add(Modifiers.Public, t.Location); break; } - case 96: { + case 97: { lexer.NextToken(); -#line 643 "cs.ATG" +#line 658 "cs.ATG" m.Add(Modifiers.Protected, t.Location); break; } - case 83: { + case 84: { lexer.NextToken(); -#line 644 "cs.ATG" +#line 659 "cs.ATG" m.Add(Modifiers.Internal, t.Location); break; } - case 95: { + case 96: { lexer.NextToken(); -#line 645 "cs.ATG" +#line 660 "cs.ATG" m.Add(Modifiers.Private, t.Location); break; } - case 118: { + case 119: { lexer.NextToken(); -#line 646 "cs.ATG" +#line 661 "cs.ATG" m.Add(Modifiers.Unsafe, t.Location); break; } - case 48: { + case 49: { lexer.NextToken(); -#line 647 "cs.ATG" +#line 662 "cs.ATG" m.Add(Modifiers.Abstract, t.Location); break; } - case 102: { + case 103: { lexer.NextToken(); -#line 648 "cs.ATG" +#line 663 "cs.ATG" m.Add(Modifiers.Sealed, t.Location); break; } - case 106: { + case 107: { lexer.NextToken(); -#line 649 "cs.ATG" +#line 664 "cs.ATG" m.Add(Modifiers.Static, t.Location); break; } - case 1: { + case 126: { lexer.NextToken(); -#line 650 "cs.ATG" - if (t.val == "partial") { m.Add(Modifiers.Partial, t.Location); } else { Error("Unexpected identifier"); } +#line 665 "cs.ATG" + m.Add(Modifiers.Partial, t.Location); break; } - default: SynErr(130); break; + default: SynErr(147); break; } } void TypeDecl( -#line 318 "cs.ATG" +#line 333 "cs.ATG" ModifierList m, List attributes) { -#line 320 "cs.ATG" +#line 335 "cs.ATG" TypeReference type; List names; List p = new List(); string name; List templates; - if (la.kind == 58) { + if (la.kind == 59) { -#line 326 "cs.ATG" +#line 341 "cs.ATG" m.Check(Modifiers.Classes); lexer.NextToken(); -#line 327 "cs.ATG" +#line 342 "cs.ATG" TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); templates = newType.Templates; compilationUnit.AddChild(newType); @@ -592,50 +661,48 @@ ModifierList m, List attributes) { newType.Type = Types.Class; - Expect(1); + Identifier(); -#line 335 "cs.ATG" +#line 350 "cs.ATG" newType.Name = t.val; if (la.kind == 23) { TypeParameterList( -#line 338 "cs.ATG" +#line 353 "cs.ATG" templates); } if (la.kind == 9) { ClassBase( -#line 340 "cs.ATG" +#line 355 "cs.ATG" out names); -#line 340 "cs.ATG" +#line 355 "cs.ATG" newType.BaseTypes = names; } - while ( -#line 343 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 343 "cs.ATG" +#line 358 "cs.ATG" templates); } -#line 345 "cs.ATG" +#line 360 "cs.ATG" newType.BodyStartLocation = t.EndLocation; ClassBody(); if (la.kind == 11) { lexer.NextToken(); } -#line 347 "cs.ATG" +#line 362 "cs.ATG" newType.EndLocation = t.Location; compilationUnit.BlockEnd(); - } else if (StartOf(8)) { + } else if (StartOf(9)) { -#line 350 "cs.ATG" +#line 365 "cs.ATG" m.Check(Modifiers.StructsInterfacesEnumsDelegates); - if (la.kind == 108) { + if (la.kind == 109) { lexer.NextToken(); -#line 351 "cs.ATG" +#line 366 "cs.ATG" TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); templates = newType.Templates; newType.StartLocation = m.GetDeclarationLocation(t.Location); @@ -643,46 +710,44 @@ templates); compilationUnit.BlockStart(newType); newType.Type = Types.Struct; - Expect(1); + Identifier(); -#line 358 "cs.ATG" +#line 373 "cs.ATG" newType.Name = t.val; if (la.kind == 23) { TypeParameterList( -#line 361 "cs.ATG" +#line 376 "cs.ATG" templates); } if (la.kind == 9) { StructInterfaces( -#line 363 "cs.ATG" +#line 378 "cs.ATG" out names); -#line 363 "cs.ATG" +#line 378 "cs.ATG" newType.BaseTypes = names; } - while ( -#line 366 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 366 "cs.ATG" +#line 381 "cs.ATG" templates); } -#line 369 "cs.ATG" +#line 384 "cs.ATG" newType.BodyStartLocation = t.EndLocation; StructBody(); if (la.kind == 11) { lexer.NextToken(); } -#line 371 "cs.ATG" +#line 386 "cs.ATG" newType.EndLocation = t.Location; compilationUnit.BlockEnd(); - } else if (la.kind == 82) { + } else if (la.kind == 83) { lexer.NextToken(); -#line 375 "cs.ATG" +#line 390 "cs.ATG" TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); templates = newType.Templates; compilationUnit.AddChild(newType); @@ -690,221 +755,214 @@ templates); newType.StartLocation = m.GetDeclarationLocation(t.Location); newType.Type = Types.Interface; - Expect(1); + Identifier(); -#line 382 "cs.ATG" +#line 397 "cs.ATG" newType.Name = t.val; if (la.kind == 23) { TypeParameterList( -#line 385 "cs.ATG" +#line 400 "cs.ATG" templates); } if (la.kind == 9) { InterfaceBase( -#line 387 "cs.ATG" +#line 402 "cs.ATG" out names); -#line 387 "cs.ATG" +#line 402 "cs.ATG" newType.BaseTypes = names; } - while ( -#line 390 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 390 "cs.ATG" +#line 405 "cs.ATG" templates); } -#line 392 "cs.ATG" +#line 407 "cs.ATG" newType.BodyStartLocation = t.EndLocation; InterfaceBody(); if (la.kind == 11) { lexer.NextToken(); } -#line 394 "cs.ATG" +#line 409 "cs.ATG" newType.EndLocation = t.Location; compilationUnit.BlockEnd(); - } else if (la.kind == 67) { + } else if (la.kind == 68) { lexer.NextToken(); -#line 398 "cs.ATG" +#line 413 "cs.ATG" TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); compilationUnit.AddChild(newType); compilationUnit.BlockStart(newType); newType.StartLocation = m.GetDeclarationLocation(t.Location); newType.Type = Types.Enum; - Expect(1); + Identifier(); -#line 404 "cs.ATG" +#line 419 "cs.ATG" newType.Name = t.val; if (la.kind == 9) { lexer.NextToken(); IntegralType( -#line 405 "cs.ATG" +#line 420 "cs.ATG" out name); -#line 405 "cs.ATG" +#line 420 "cs.ATG" newType.BaseTypes.Add(new TypeReference(name)); } -#line 407 "cs.ATG" +#line 422 "cs.ATG" newType.BodyStartLocation = t.EndLocation; EnumBody(); if (la.kind == 11) { lexer.NextToken(); } -#line 409 "cs.ATG" +#line 424 "cs.ATG" newType.EndLocation = t.Location; compilationUnit.BlockEnd(); } else { lexer.NextToken(); -#line 413 "cs.ATG" +#line 428 "cs.ATG" DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes); templates = delegateDeclr.Templates; delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location); if ( -#line 417 "cs.ATG" +#line 432 "cs.ATG" NotVoidPointer()) { - Expect(122); + Expect(123); -#line 417 "cs.ATG" +#line 432 "cs.ATG" delegateDeclr.ReturnType = new TypeReference("void", 0, null); - } else if (StartOf(9)) { + } else if (StartOf(10)) { Type( -#line 418 "cs.ATG" +#line 433 "cs.ATG" out type); -#line 418 "cs.ATG" +#line 433 "cs.ATG" delegateDeclr.ReturnType = type; - } else SynErr(131); - Expect(1); + } else SynErr(148); + Identifier(); -#line 420 "cs.ATG" +#line 435 "cs.ATG" delegateDeclr.Name = t.val; if (la.kind == 23) { TypeParameterList( -#line 423 "cs.ATG" +#line 438 "cs.ATG" templates); } Expect(20); - if (StartOf(10)) { + if (StartOf(11)) { FormalParameterList( -#line 425 "cs.ATG" +#line 440 "cs.ATG" p); -#line 425 "cs.ATG" +#line 440 "cs.ATG" delegateDeclr.Parameters = p; } Expect(21); - while ( -#line 429 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 429 "cs.ATG" +#line 444 "cs.ATG" templates); } Expect(11); -#line 431 "cs.ATG" +#line 446 "cs.ATG" delegateDeclr.EndLocation = t.Location; compilationUnit.AddChild(delegateDeclr); } - } else SynErr(132); + } else SynErr(149); } void TypeParameterList( -#line 2013 "cs.ATG" +#line 2153 "cs.ATG" List templates) { -#line 2015 "cs.ATG" +#line 2155 "cs.ATG" AttributeSection section; List attributes = new List(); Expect(23); while (la.kind == 18) { AttributeSection( -#line 2019 "cs.ATG" +#line 2159 "cs.ATG" out section); -#line 2019 "cs.ATG" +#line 2159 "cs.ATG" attributes.Add(section); } - Expect(1); + Identifier(); -#line 2020 "cs.ATG" +#line 2160 "cs.ATG" templates.Add(new TemplateDefinition(t.val, attributes)); while (la.kind == 14) { lexer.NextToken(); while (la.kind == 18) { AttributeSection( -#line 2021 "cs.ATG" +#line 2161 "cs.ATG" out section); -#line 2021 "cs.ATG" +#line 2161 "cs.ATG" attributes.Add(section); } - Expect(1); + Identifier(); -#line 2022 "cs.ATG" +#line 2162 "cs.ATG" templates.Add(new TemplateDefinition(t.val, attributes)); } Expect(22); } void ClassBase( -#line 446 "cs.ATG" +#line 461 "cs.ATG" out List names) { -#line 448 "cs.ATG" +#line 463 "cs.ATG" TypeReference typeRef; names = new List(); Expect(9); ClassType( -#line 452 "cs.ATG" +#line 467 "cs.ATG" out typeRef, false); -#line 452 "cs.ATG" +#line 467 "cs.ATG" if (typeRef != null) { names.Add(typeRef); } while (la.kind == 14) { lexer.NextToken(); TypeName( -#line 453 "cs.ATG" +#line 468 "cs.ATG" out typeRef, false); -#line 453 "cs.ATG" +#line 468 "cs.ATG" if (typeRef != null) { names.Add(typeRef); } } } void TypeParameterConstraintsClause( -#line 2026 "cs.ATG" +#line 2166 "cs.ATG" List templates) { -#line 2027 "cs.ATG" +#line 2167 "cs.ATG" string name = ""; TypeReference type; - Expect(1); - -#line 2029 "cs.ATG" - if (t.val != "where") Error("where expected"); - Expect(1); + Expect(127); + Identifier(); -#line 2030 "cs.ATG" +#line 2170 "cs.ATG" name = t.val; Expect(9); TypeParameterConstraintsClauseBase( -#line 2032 "cs.ATG" +#line 2172 "cs.ATG" out type); -#line 2033 "cs.ATG" +#line 2173 "cs.ATG" TemplateDefinition td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { @@ -917,10 +975,10 @@ out type); while (la.kind == 14) { lexer.NextToken(); TypeParameterConstraintsClauseBase( -#line 2042 "cs.ATG" +#line 2182 "cs.ATG" out type); -#line 2043 "cs.ATG" +#line 2183 "cs.ATG" td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { @@ -935,217 +993,217 @@ out type); void ClassBody() { -#line 457 "cs.ATG" +#line 472 "cs.ATG" AttributeSection section; Expect(16); - while (StartOf(11)) { + while (StartOf(12)) { -#line 460 "cs.ATG" +#line 475 "cs.ATG" List attributes = new List(); ModifierList m = new ModifierList(); while (la.kind == 18) { AttributeSection( -#line 463 "cs.ATG" +#line 478 "cs.ATG" out section); -#line 463 "cs.ATG" +#line 478 "cs.ATG" attributes.Add(section); } MemberModifiers( -#line 464 "cs.ATG" +#line 479 "cs.ATG" m); ClassMemberDecl( -#line 465 "cs.ATG" +#line 480 "cs.ATG" m, attributes); } Expect(17); } void StructInterfaces( -#line 470 "cs.ATG" +#line 485 "cs.ATG" out List names) { -#line 472 "cs.ATG" +#line 487 "cs.ATG" TypeReference typeRef; names = new List(); Expect(9); TypeName( -#line 476 "cs.ATG" +#line 491 "cs.ATG" out typeRef, false); -#line 476 "cs.ATG" +#line 491 "cs.ATG" if (typeRef != null) { names.Add(typeRef); } while (la.kind == 14) { lexer.NextToken(); TypeName( -#line 477 "cs.ATG" +#line 492 "cs.ATG" out typeRef, false); -#line 477 "cs.ATG" +#line 492 "cs.ATG" if (typeRef != null) { names.Add(typeRef); } } } void StructBody() { -#line 481 "cs.ATG" +#line 496 "cs.ATG" AttributeSection section; Expect(16); - while (StartOf(12)) { + while (StartOf(13)) { -#line 484 "cs.ATG" +#line 499 "cs.ATG" List attributes = new List(); ModifierList m = new ModifierList(); while (la.kind == 18) { AttributeSection( -#line 487 "cs.ATG" +#line 502 "cs.ATG" out section); -#line 487 "cs.ATG" +#line 502 "cs.ATG" attributes.Add(section); } MemberModifiers( -#line 488 "cs.ATG" +#line 503 "cs.ATG" m); StructMemberDecl( -#line 489 "cs.ATG" +#line 504 "cs.ATG" m, attributes); } Expect(17); } void InterfaceBase( -#line 494 "cs.ATG" +#line 509 "cs.ATG" out List names) { -#line 496 "cs.ATG" +#line 511 "cs.ATG" TypeReference typeRef; names = new List(); Expect(9); TypeName( -#line 500 "cs.ATG" +#line 515 "cs.ATG" out typeRef, false); -#line 500 "cs.ATG" +#line 515 "cs.ATG" if (typeRef != null) { names.Add(typeRef); } while (la.kind == 14) { lexer.NextToken(); TypeName( -#line 501 "cs.ATG" +#line 516 "cs.ATG" out typeRef, false); -#line 501 "cs.ATG" +#line 516 "cs.ATG" if (typeRef != null) { names.Add(typeRef); } } } void InterfaceBody() { Expect(16); - while (StartOf(13)) { + while (StartOf(14)) { InterfaceMemberDecl(); } Expect(17); } void IntegralType( -#line 661 "cs.ATG" +#line 676 "cs.ATG" out string name) { -#line 661 "cs.ATG" +#line 676 "cs.ATG" name = ""; switch (la.kind) { - case 101: { + case 102: { lexer.NextToken(); -#line 663 "cs.ATG" +#line 678 "cs.ATG" name = "sbyte"; break; } - case 53: { + case 54: { lexer.NextToken(); -#line 664 "cs.ATG" +#line 679 "cs.ATG" name = "byte"; break; } - case 103: { + case 104: { lexer.NextToken(); -#line 665 "cs.ATG" +#line 680 "cs.ATG" name = "short"; break; } - case 119: { + case 120: { lexer.NextToken(); -#line 666 "cs.ATG" +#line 681 "cs.ATG" name = "ushort"; break; } - case 81: { + case 82: { lexer.NextToken(); -#line 667 "cs.ATG" +#line 682 "cs.ATG" name = "int"; break; } - case 115: { + case 116: { lexer.NextToken(); -#line 668 "cs.ATG" +#line 683 "cs.ATG" name = "uint"; break; } - case 86: { + case 87: { lexer.NextToken(); -#line 669 "cs.ATG" +#line 684 "cs.ATG" name = "long"; break; } - case 116: { + case 117: { lexer.NextToken(); -#line 670 "cs.ATG" +#line 685 "cs.ATG" name = "ulong"; break; } - case 56: { + case 57: { lexer.NextToken(); -#line 671 "cs.ATG" +#line 686 "cs.ATG" name = "char"; break; } - default: SynErr(133); break; + default: SynErr(150); break; } } void EnumBody() { -#line 510 "cs.ATG" +#line 525 "cs.ATG" FieldDeclaration f; Expect(16); - if (la.kind == 1 || la.kind == 18) { + if (StartOf(15)) { EnumMemberDecl( -#line 513 "cs.ATG" +#line 528 "cs.ATG" out f); -#line 513 "cs.ATG" +#line 528 "cs.ATG" compilationUnit.AddChild(f); while ( -#line 514 "cs.ATG" +#line 529 "cs.ATG" NotFinalComma()) { Expect(14); EnumMemberDecl( -#line 515 "cs.ATG" +#line 530 "cs.ATG" out f); -#line 515 "cs.ATG" +#line 530 "cs.ATG" compilationUnit.AddChild(f); } if (la.kind == 14) { @@ -1156,36 +1214,36 @@ out f); } void Type( -#line 520 "cs.ATG" +#line 535 "cs.ATG" out TypeReference type) { TypeWithRestriction( -#line 522 "cs.ATG" +#line 537 "cs.ATG" out type, true, false); } void FormalParameterList( -#line 583 "cs.ATG" +#line 598 "cs.ATG" List parameter) { -#line 586 "cs.ATG" +#line 601 "cs.ATG" ParameterDeclarationExpression p; AttributeSection section; List attributes = new List(); while (la.kind == 18) { AttributeSection( -#line 591 "cs.ATG" +#line 606 "cs.ATG" out section); -#line 591 "cs.ATG" +#line 606 "cs.ATG" attributes.Add(section); } - if (StartOf(14)) { + if (StartOf(16)) { FixedParameter( -#line 593 "cs.ATG" +#line 608 "cs.ATG" out p); -#line 593 "cs.ATG" +#line 608 "cs.ATG" bool paramsFound = false; p.Attributes = attributes; parameter.Add(p); @@ -1193,96 +1251,96 @@ out p); while (la.kind == 14) { lexer.NextToken(); -#line 598 "cs.ATG" +#line 613 "cs.ATG" attributes = new List(); if (paramsFound) Error("params array must be at end of parameter list"); while (la.kind == 18) { AttributeSection( -#line 599 "cs.ATG" +#line 614 "cs.ATG" out section); -#line 599 "cs.ATG" +#line 614 "cs.ATG" attributes.Add(section); } - if (StartOf(14)) { + if (StartOf(16)) { FixedParameter( -#line 601 "cs.ATG" +#line 616 "cs.ATG" out p); -#line 601 "cs.ATG" +#line 616 "cs.ATG" p.Attributes = attributes; parameter.Add(p); - } else if (la.kind == 94) { + } else if (la.kind == 95) { ParameterArray( -#line 602 "cs.ATG" +#line 617 "cs.ATG" out p); -#line 602 "cs.ATG" +#line 617 "cs.ATG" paramsFound = true; p.Attributes = attributes; parameter.Add(p); - } else SynErr(134); + } else SynErr(151); } - } else if (la.kind == 94) { + } else if (la.kind == 95) { ParameterArray( -#line 605 "cs.ATG" +#line 620 "cs.ATG" out p); -#line 605 "cs.ATG" +#line 620 "cs.ATG" p.Attributes = attributes; parameter.Add(p); - } else SynErr(135); + } else SynErr(152); } void ClassType( -#line 653 "cs.ATG" +#line 668 "cs.ATG" out TypeReference typeRef, bool canBeUnbound) { -#line 654 "cs.ATG" +#line 669 "cs.ATG" TypeReference r; typeRef = null; - if (la.kind == 1) { + if (StartOf(17)) { TypeName( -#line 656 "cs.ATG" +#line 671 "cs.ATG" out r, canBeUnbound); -#line 656 "cs.ATG" +#line 671 "cs.ATG" typeRef = r; - } else if (la.kind == 90) { + } else if (la.kind == 91) { lexer.NextToken(); -#line 657 "cs.ATG" +#line 672 "cs.ATG" typeRef = new TypeReference("object"); - } else if (la.kind == 107) { + } else if (la.kind == 108) { lexer.NextToken(); -#line 658 "cs.ATG" +#line 673 "cs.ATG" typeRef = new TypeReference("string"); - } else SynErr(136); + } else SynErr(153); } void TypeName( -#line 1956 "cs.ATG" +#line 2096 "cs.ATG" out TypeReference typeRef, bool canBeUnbound) { -#line 1957 "cs.ATG" +#line 2097 "cs.ATG" List typeArguments = null; string alias = null; string qualident; if ( -#line 1962 "cs.ATG" -la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) { - lexer.NextToken(); +#line 2102 "cs.ATG" +IdentAndDoubleColon()) { + Identifier(); -#line 1963 "cs.ATG" +#line 2103 "cs.ATG" alias = t.val; Expect(10); } Qualident( -#line 1966 "cs.ATG" +#line 2106 "cs.ATG" out qualident); if (la.kind == 23) { TypeArgumentList( -#line 1967 "cs.ATG" +#line 2107 "cs.ATG" out typeArguments, canBeUnbound); } -#line 1969 "cs.ATG" +#line 2109 "cs.ATG" if (alias == null) { typeRef = new TypeReference(qualident, typeArguments); } else if (alias == "global") { @@ -1293,134 +1351,165 @@ out typeArguments, canBeUnbound); } while ( -#line 1978 "cs.ATG" +#line 2118 "cs.ATG" DotAndIdent()) { Expect(15); -#line 1979 "cs.ATG" +#line 2119 "cs.ATG" typeArguments = null; Qualident( -#line 1980 "cs.ATG" +#line 2120 "cs.ATG" out qualident); if (la.kind == 23) { TypeArgumentList( -#line 1981 "cs.ATG" +#line 2121 "cs.ATG" out typeArguments, canBeUnbound); } -#line 1982 "cs.ATG" +#line 2122 "cs.ATG" typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments); } } void MemberModifiers( -#line 674 "cs.ATG" +#line 689 "cs.ATG" ModifierList m) { - while (StartOf(15) || -#line 692 "cs.ATG" -la.kind == Tokens.Identifier && la.val == "partial") { - if (la.kind == 48) { + while (StartOf(18)) { + switch (la.kind) { + case 49: { lexer.NextToken(); -#line 677 "cs.ATG" +#line 692 "cs.ATG" m.Add(Modifiers.Abstract, t.Location); - } else if (la.kind == 70) { + break; + } + case 71: { lexer.NextToken(); -#line 678 "cs.ATG" +#line 693 "cs.ATG" m.Add(Modifiers.Extern, t.Location); - } else if (la.kind == 83) { + break; + } + case 84: { lexer.NextToken(); -#line 679 "cs.ATG" +#line 694 "cs.ATG" m.Add(Modifiers.Internal, t.Location); - } else if (la.kind == 88) { + break; + } + case 89: { lexer.NextToken(); -#line 680 "cs.ATG" +#line 695 "cs.ATG" m.Add(Modifiers.New, t.Location); - } else if (la.kind == 93) { + break; + } + case 94: { lexer.NextToken(); -#line 681 "cs.ATG" +#line 696 "cs.ATG" m.Add(Modifiers.Override, t.Location); - } else if (la.kind == 95) { + break; + } + case 96: { lexer.NextToken(); -#line 682 "cs.ATG" +#line 697 "cs.ATG" m.Add(Modifiers.Private, t.Location); - } else if (la.kind == 96) { + break; + } + case 97: { lexer.NextToken(); -#line 683 "cs.ATG" +#line 698 "cs.ATG" m.Add(Modifiers.Protected, t.Location); - } else if (la.kind == 97) { + break; + } + case 98: { lexer.NextToken(); -#line 684 "cs.ATG" +#line 699 "cs.ATG" m.Add(Modifiers.Public, t.Location); - } else if (la.kind == 98) { + break; + } + case 99: { lexer.NextToken(); -#line 685 "cs.ATG" +#line 700 "cs.ATG" m.Add(Modifiers.ReadOnly, t.Location); - } else if (la.kind == 102) { + break; + } + case 103: { lexer.NextToken(); -#line 686 "cs.ATG" +#line 701 "cs.ATG" m.Add(Modifiers.Sealed, t.Location); - } else if (la.kind == 106) { + break; + } + case 107: { lexer.NextToken(); -#line 687 "cs.ATG" +#line 702 "cs.ATG" m.Add(Modifiers.Static, t.Location); - } else if (la.kind == 73) { + break; + } + case 74: { lexer.NextToken(); -#line 688 "cs.ATG" +#line 703 "cs.ATG" m.Add(Modifiers.Fixed, t.Location); - } else if (la.kind == 118) { + break; + } + case 119: { lexer.NextToken(); -#line 689 "cs.ATG" +#line 704 "cs.ATG" m.Add(Modifiers.Unsafe, t.Location); - } else if (la.kind == 121) { + break; + } + case 122: { lexer.NextToken(); -#line 690 "cs.ATG" +#line 705 "cs.ATG" m.Add(Modifiers.Virtual, t.Location); - } else if (la.kind == 123) { + break; + } + case 124: { lexer.NextToken(); -#line 691 "cs.ATG" +#line 706 "cs.ATG" m.Add(Modifiers.Volatile, t.Location); - } else { - Expect(1); + break; + } + case 126: { + lexer.NextToken(); -#line 693 "cs.ATG" +#line 707 "cs.ATG" m.Add(Modifiers.Partial, t.Location); + break; + } } } } void ClassMemberDecl( -#line 985 "cs.ATG" +#line 1005 "cs.ATG" ModifierList m, List attributes) { -#line 986 "cs.ATG" +#line 1006 "cs.ATG" Statement stmt = null; - if (StartOf(16)) { + if (StartOf(19)) { StructMemberDecl( -#line 988 "cs.ATG" +#line 1008 "cs.ATG" m, attributes); } else if (la.kind == 27) { -#line 989 "cs.ATG" +#line 1009 "cs.ATG" m.Check(Modifiers.Destructors); Location startPos = t.Location; lexer.NextToken(); - Expect(1); + Identifier(); -#line 990 "cs.ATG" +#line 1010 "cs.ATG" DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes); d.Modifier = m.Modifier; d.StartLocation = m.GetDeclarationLocation(startPos); @@ -1428,28 +1517,28 @@ m, attributes); Expect(20); Expect(21); -#line 994 "cs.ATG" +#line 1014 "cs.ATG" d.EndLocation = t.EndLocation; if (la.kind == 16) { Block( -#line 994 "cs.ATG" +#line 1014 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(137); + } else SynErr(154); -#line 995 "cs.ATG" +#line 1015 "cs.ATG" d.Body = (BlockStatement)stmt; compilationUnit.AddChild(d); - } else SynErr(138); + } else SynErr(155); } void StructMemberDecl( -#line 698 "cs.ATG" +#line 711 "cs.ATG" ModifierList m, List attributes) { -#line 700 "cs.ATG" +#line 713 "cs.ATG" string qualident = null; TypeReference type; Expression expr; @@ -1458,21 +1547,22 @@ ModifierList m, List attributes) { List variableDeclarators = new List(); List templates = new List(); TypeReference explicitInterface = null; + bool isExtensionMethod = false; - if (la.kind == 59) { + if (la.kind == 60) { -#line 710 "cs.ATG" +#line 724 "cs.ATG" m.Check(Modifiers.Constants); lexer.NextToken(); -#line 711 "cs.ATG" +#line 725 "cs.ATG" Location startPos = t.Location; Type( -#line 712 "cs.ATG" +#line 726 "cs.ATG" out type); - Expect(1); + Identifier(); -#line 712 "cs.ATG" +#line 726 "cs.ATG" FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const); fd.StartLocation = m.GetDeclarationLocation(startPos); VariableDeclaration f = new VariableDeclaration(t.val); @@ -1480,72 +1570,78 @@ out type); Expect(3); Expr( -#line 717 "cs.ATG" +#line 731 "cs.ATG" out expr); -#line 717 "cs.ATG" +#line 731 "cs.ATG" f.Initializer = expr; while (la.kind == 14) { lexer.NextToken(); - Expect(1); + Identifier(); -#line 718 "cs.ATG" +#line 732 "cs.ATG" f = new VariableDeclaration(t.val); fd.Fields.Add(f); Expect(3); Expr( -#line 721 "cs.ATG" +#line 735 "cs.ATG" out expr); -#line 721 "cs.ATG" +#line 735 "cs.ATG" f.Initializer = expr; } Expect(11); -#line 722 "cs.ATG" +#line 736 "cs.ATG" fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); } else if ( -#line 726 "cs.ATG" +#line 740 "cs.ATG" NotVoidPointer()) { -#line 726 "cs.ATG" +#line 740 "cs.ATG" m.Check(Modifiers.PropertysEventsMethods); - Expect(122); + Expect(123); -#line 727 "cs.ATG" +#line 741 "cs.ATG" Location startPos = t.Location; if ( -#line 728 "cs.ATG" +#line 742 "cs.ATG" IsExplicitInterfaceImplementation()) { TypeName( -#line 729 "cs.ATG" +#line 743 "cs.ATG" out explicitInterface, false); -#line 730 "cs.ATG" +#line 744 "cs.ATG" if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } - } else if (la.kind == 1) { - lexer.NextToken(); + } else if (StartOf(17)) { + Identifier(); -#line 733 "cs.ATG" +#line 747 "cs.ATG" qualident = t.val; - } else SynErr(139); + } else SynErr(156); if (la.kind == 23) { TypeParameterList( -#line 736 "cs.ATG" +#line 750 "cs.ATG" templates); } Expect(20); - if (StartOf(10)) { + if (la.kind == 111) { + lexer.NextToken(); + +#line 753 "cs.ATG" + isExtensionMethod = true; /* C# 3.0 */ + } + if (StartOf(11)) { FormalParameterList( -#line 739 "cs.ATG" +#line 754 "cs.ATG" p); } Expect(21); -#line 740 "cs.ATG" +#line 755 "cs.ATG" MethodDeclaration methodDeclaration = new MethodDeclaration(qualident, m.Modifier, new TypeReference("void"), @@ -1554,37 +1650,36 @@ p); methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); methodDeclaration.EndLocation = t.EndLocation; methodDeclaration.Templates = templates; + methodDeclaration.IsExtensionMethod = isExtensionMethod; if (explicitInterface != null) methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); compilationUnit.AddChild(methodDeclaration); compilationUnit.BlockStart(methodDeclaration); - while ( -#line 755 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 755 "cs.ATG" +#line 771 "cs.ATG" templates); } if (la.kind == 16) { Block( -#line 757 "cs.ATG" +#line 773 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(140); + } else SynErr(157); -#line 757 "cs.ATG" +#line 773 "cs.ATG" compilationUnit.BlockEnd(); methodDeclaration.Body = (BlockStatement)stmt; - } else if (la.kind == 68) { + } else if (la.kind == 69) { -#line 761 "cs.ATG" +#line 777 "cs.ATG" m.Check(Modifiers.PropertysEventsMethods); lexer.NextToken(); -#line 762 "cs.ATG" +#line 778 "cs.ATG" EventDeclaration eventDecl = new EventDeclaration(null, null, m.Modifier, attributes, null); eventDecl.StartLocation = t.Location; compilationUnit.AddChild(eventDecl); @@ -1593,160 +1688,160 @@ out stmt); EventRemoveRegion removeBlock = null; Type( -#line 769 "cs.ATG" +#line 785 "cs.ATG" out type); -#line 769 "cs.ATG" +#line 785 "cs.ATG" eventDecl.TypeReference = type; if ( -#line 770 "cs.ATG" +#line 786 "cs.ATG" IsExplicitInterfaceImplementation()) { TypeName( -#line 771 "cs.ATG" +#line 787 "cs.ATG" out explicitInterface, false); -#line 772 "cs.ATG" +#line 788 "cs.ATG" qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); -#line 773 "cs.ATG" +#line 789 "cs.ATG" eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); - } else if (la.kind == 1) { - lexer.NextToken(); + } else if (StartOf(17)) { + Identifier(); -#line 775 "cs.ATG" +#line 791 "cs.ATG" qualident = t.val; - } else SynErr(141); + } else SynErr(158); -#line 777 "cs.ATG" +#line 793 "cs.ATG" eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; if (la.kind == 3) { lexer.NextToken(); Expr( -#line 778 "cs.ATG" +#line 794 "cs.ATG" out expr); -#line 778 "cs.ATG" +#line 794 "cs.ATG" eventDecl.Initializer = expr; } if (la.kind == 16) { lexer.NextToken(); -#line 779 "cs.ATG" +#line 795 "cs.ATG" eventDecl.BodyStart = t.Location; EventAccessorDecls( -#line 780 "cs.ATG" +#line 796 "cs.ATG" out addBlock, out removeBlock); Expect(17); -#line 781 "cs.ATG" +#line 797 "cs.ATG" eventDecl.BodyEnd = t.EndLocation; } if (la.kind == 11) { lexer.NextToken(); } -#line 784 "cs.ATG" +#line 800 "cs.ATG" compilationUnit.BlockEnd(); eventDecl.AddRegion = addBlock; eventDecl.RemoveRegion = removeBlock; } else if ( -#line 790 "cs.ATG" +#line 806 "cs.ATG" IdentAndLPar()) { -#line 790 "cs.ATG" +#line 806 "cs.ATG" m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); - Expect(1); + Identifier(); -#line 791 "cs.ATG" +#line 807 "cs.ATG" string name = t.val; Location startPos = t.Location; Expect(20); - if (StartOf(10)) { + if (StartOf(11)) { -#line 791 "cs.ATG" +#line 807 "cs.ATG" m.Check(Modifiers.Constructors); FormalParameterList( -#line 792 "cs.ATG" +#line 808 "cs.ATG" p); } Expect(21); -#line 794 "cs.ATG" +#line 810 "cs.ATG" ConstructorInitializer init = null; if (la.kind == 9) { -#line 795 "cs.ATG" +#line 811 "cs.ATG" m.Check(Modifiers.Constructors); ConstructorInitializer( -#line 796 "cs.ATG" +#line 812 "cs.ATG" out init); } -#line 798 "cs.ATG" +#line 814 "cs.ATG" ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes); cd.StartLocation = startPos; cd.EndLocation = t.EndLocation; if (la.kind == 16) { Block( -#line 803 "cs.ATG" +#line 819 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(142); + } else SynErr(159); -#line 803 "cs.ATG" +#line 819 "cs.ATG" cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); - } else if (la.kind == 69 || la.kind == 79) { + } else if (la.kind == 70 || la.kind == 80) { -#line 806 "cs.ATG" +#line 822 "cs.ATG" m.Check(Modifiers.Operators); if (m.isNone) Error("at least one modifier must be set"); bool isImplicit = true; Location startPos = Location.Empty; - if (la.kind == 79) { + if (la.kind == 80) { lexer.NextToken(); -#line 811 "cs.ATG" +#line 827 "cs.ATG" startPos = t.Location; } else { lexer.NextToken(); -#line 811 "cs.ATG" +#line 827 "cs.ATG" isImplicit = false; startPos = t.Location; } - Expect(91); + Expect(92); Type( -#line 812 "cs.ATG" +#line 828 "cs.ATG" out type); -#line 812 "cs.ATG" +#line 828 "cs.ATG" TypeReference operatorType = type; Expect(20); Type( -#line 813 "cs.ATG" +#line 829 "cs.ATG" out type); - Expect(1); + Identifier(); -#line 813 "cs.ATG" +#line 829 "cs.ATG" string varName = t.val; Expect(21); -#line 814 "cs.ATG" +#line 830 "cs.ATG" Location endPos = t.Location; if (la.kind == 16) { Block( -#line 815 "cs.ATG" +#line 831 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); -#line 815 "cs.ATG" +#line 831 "cs.ATG" stmt = null; - } else SynErr(143); + } else SynErr(160); -#line 818 "cs.ATG" +#line 834 "cs.ATG" List parameters = new List(); parameters.Add(new ParameterDeclarationExpression(type, varName)); OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier, @@ -1760,63 +1855,63 @@ out stmt); operatorDeclaration.EndLocation = endPos; compilationUnit.AddChild(operatorDeclaration); - } else if (StartOf(17)) { + } else if (StartOf(20)) { TypeDecl( -#line 834 "cs.ATG" +#line 850 "cs.ATG" m, attributes); - } else if (StartOf(9)) { + } else if (StartOf(10)) { Type( -#line 836 "cs.ATG" +#line 852 "cs.ATG" out type); -#line 836 "cs.ATG" +#line 852 "cs.ATG" Location startPos = t.Location; - if (la.kind == 91) { + if (la.kind == 92) { -#line 838 "cs.ATG" +#line 854 "cs.ATG" OverloadableOperatorType op; m.Check(Modifiers.Operators); if (m.isNone) Error("at least one modifier must be set"); lexer.NextToken(); OverloadableOperator( -#line 842 "cs.ATG" +#line 858 "cs.ATG" out op); -#line 842 "cs.ATG" +#line 858 "cs.ATG" TypeReference firstType, secondType = null; string secondName = null; Expect(20); Type( -#line 843 "cs.ATG" +#line 859 "cs.ATG" out firstType); - Expect(1); + Identifier(); -#line 843 "cs.ATG" +#line 859 "cs.ATG" string firstName = t.val; if (la.kind == 14) { lexer.NextToken(); Type( -#line 844 "cs.ATG" +#line 860 "cs.ATG" out secondType); - Expect(1); + Identifier(); -#line 844 "cs.ATG" +#line 860 "cs.ATG" secondName = t.val; } else if (la.kind == 21) { - } else SynErr(144); + } else SynErr(161); -#line 852 "cs.ATG" +#line 868 "cs.ATG" Location endPos = t.Location; Expect(21); if (la.kind == 16) { Block( -#line 853 "cs.ATG" +#line 869 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(145); + } else SynErr(162); -#line 855 "cs.ATG" +#line 871 "cs.ATG" List parameters = new List(); parameters.Add(new ParameterDeclarationExpression(firstType, firstName)); if (secondType != null) { @@ -1833,75 +1928,75 @@ out stmt); compilationUnit.AddChild(operatorDeclaration); } else if ( -#line 872 "cs.ATG" +#line 888 "cs.ATG" IsVarDecl()) { -#line 873 "cs.ATG" +#line 889 "cs.ATG" m.Check(Modifiers.Fields); FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier); fd.StartLocation = m.GetDeclarationLocation(startPos); if ( -#line 877 "cs.ATG" +#line 893 "cs.ATG" m.Contains(Modifiers.Fixed)) { VariableDeclarator( -#line 878 "cs.ATG" +#line 894 "cs.ATG" variableDeclarators); Expect(18); Expr( -#line 880 "cs.ATG" +#line 896 "cs.ATG" out expr); -#line 880 "cs.ATG" +#line 896 "cs.ATG" if (variableDeclarators.Count > 0) variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; Expect(19); while (la.kind == 14) { lexer.NextToken(); VariableDeclarator( -#line 884 "cs.ATG" +#line 900 "cs.ATG" variableDeclarators); Expect(18); Expr( -#line 886 "cs.ATG" +#line 902 "cs.ATG" out expr); -#line 886 "cs.ATG" +#line 902 "cs.ATG" if (variableDeclarators.Count > 0) variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; Expect(19); } - } else if (la.kind == 1) { + } else if (StartOf(17)) { VariableDeclarator( -#line 891 "cs.ATG" +#line 907 "cs.ATG" variableDeclarators); while (la.kind == 14) { lexer.NextToken(); VariableDeclarator( -#line 892 "cs.ATG" +#line 908 "cs.ATG" variableDeclarators); } - } else SynErr(146); + } else SynErr(163); Expect(11); -#line 894 "cs.ATG" +#line 910 "cs.ATG" fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); - } else if (la.kind == 110) { + } else if (la.kind == 111) { -#line 897 "cs.ATG" +#line 913 "cs.ATG" m.Check(Modifiers.Indexers); lexer.NextToken(); Expect(18); FormalParameterList( -#line 898 "cs.ATG" +#line 914 "cs.ATG" p); Expect(19); -#line 898 "cs.ATG" +#line 914 "cs.ATG" Location endLocation = t.EndLocation; Expect(16); -#line 899 "cs.ATG" +#line 915 "cs.ATG" IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); indexer.StartLocation = startPos; indexer.EndLocation = endLocation; @@ -1910,58 +2005,64 @@ p); PropertySetRegion setRegion; AccessorDecls( -#line 906 "cs.ATG" +#line 922 "cs.ATG" out getRegion, out setRegion); Expect(17); -#line 907 "cs.ATG" +#line 923 "cs.ATG" indexer.BodyEnd = t.EndLocation; indexer.GetRegion = getRegion; indexer.SetRegion = setRegion; compilationUnit.AddChild(indexer); } else if ( -#line 912 "cs.ATG" -la.kind == Tokens.Identifier) { +#line 928 "cs.ATG" +IsIdentifierToken(la)) { if ( -#line 913 "cs.ATG" +#line 929 "cs.ATG" IsExplicitInterfaceImplementation()) { TypeName( -#line 914 "cs.ATG" +#line 930 "cs.ATG" out explicitInterface, false); -#line 915 "cs.ATG" +#line 931 "cs.ATG" if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } - } else if (la.kind == 1) { - lexer.NextToken(); + } else if (StartOf(17)) { + Identifier(); -#line 918 "cs.ATG" +#line 934 "cs.ATG" qualident = t.val; - } else SynErr(147); + } else SynErr(164); -#line 920 "cs.ATG" +#line 936 "cs.ATG" Location qualIdentEndLocation = t.EndLocation; if (la.kind == 16 || la.kind == 20 || la.kind == 23) { if (la.kind == 20 || la.kind == 23) { -#line 924 "cs.ATG" +#line 940 "cs.ATG" m.Check(Modifiers.PropertysEventsMethods); if (la.kind == 23) { TypeParameterList( -#line 926 "cs.ATG" +#line 942 "cs.ATG" templates); } Expect(20); - if (StartOf(10)) { + if (la.kind == 111) { + lexer.NextToken(); + +#line 944 "cs.ATG" + isExtensionMethod = true; + } + if (StartOf(11)) { FormalParameterList( -#line 927 "cs.ATG" +#line 945 "cs.ATG" p); } Expect(21); -#line 928 "cs.ATG" +#line 947 "cs.ATG" MethodDeclaration methodDeclaration = new MethodDeclaration(qualident, m.Modifier, type, @@ -1971,30 +2072,29 @@ p); methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); methodDeclaration.EndLocation = t.EndLocation; + methodDeclaration.IsExtensionMethod = isExtensionMethod; methodDeclaration.Templates = templates; compilationUnit.AddChild(methodDeclaration); - while ( -#line 940 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 940 "cs.ATG" +#line 960 "cs.ATG" templates); } if (la.kind == 16) { Block( -#line 941 "cs.ATG" +#line 961 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(148); + } else SynErr(165); -#line 941 "cs.ATG" +#line 961 "cs.ATG" methodDeclaration.Body = (BlockStatement)stmt; } else { lexer.NextToken(); -#line 944 "cs.ATG" +#line 964 "cs.ATG" PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes); if (explicitInterface != null) pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); @@ -2005,11 +2105,11 @@ out stmt); PropertySetRegion setRegion; AccessorDecls( -#line 953 "cs.ATG" +#line 973 "cs.ATG" out getRegion, out setRegion); Expect(17); -#line 955 "cs.ATG" +#line 975 "cs.ATG" pDecl.GetRegion = getRegion; pDecl.SetRegion = setRegion; pDecl.BodyEnd = t.EndLocation; @@ -2018,17 +2118,17 @@ out getRegion, out setRegion); } } else if (la.kind == 15) { -#line 963 "cs.ATG" +#line 983 "cs.ATG" m.Check(Modifiers.Indexers); lexer.NextToken(); - Expect(110); + Expect(111); Expect(18); FormalParameterList( -#line 964 "cs.ATG" +#line 984 "cs.ATG" p); Expect(19); -#line 965 "cs.ATG" +#line 985 "cs.ATG" IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); indexer.StartLocation = m.GetDeclarationLocation(startPos); indexer.EndLocation = t.EndLocation; @@ -2039,28 +2139,28 @@ p); Expect(16); -#line 973 "cs.ATG" +#line 993 "cs.ATG" Location bodyStart = t.Location; AccessorDecls( -#line 974 "cs.ATG" +#line 994 "cs.ATG" out getRegion, out setRegion); Expect(17); -#line 975 "cs.ATG" +#line 995 "cs.ATG" indexer.BodyStart = bodyStart; indexer.BodyEnd = t.EndLocation; indexer.GetRegion = getRegion; indexer.SetRegion = setRegion; compilationUnit.AddChild(indexer); - } else SynErr(149); - } else SynErr(150); - } else SynErr(151); + } else SynErr(166); + } else SynErr(167); + } else SynErr(168); } void InterfaceMemberDecl() { -#line 1002 "cs.ATG" +#line 1022 "cs.ATG" TypeReference type; AttributeSection section; @@ -2075,93 +2175,89 @@ out getRegion, out setRegion); while (la.kind == 18) { AttributeSection( -#line 1015 "cs.ATG" +#line 1035 "cs.ATG" out section); -#line 1015 "cs.ATG" +#line 1035 "cs.ATG" attributes.Add(section); } - if (la.kind == 88) { + if (la.kind == 89) { lexer.NextToken(); -#line 1016 "cs.ATG" +#line 1036 "cs.ATG" mod = Modifiers.New; startLocation = t.Location; } if ( -#line 1019 "cs.ATG" +#line 1039 "cs.ATG" NotVoidPointer()) { - Expect(122); + Expect(123); -#line 1019 "cs.ATG" +#line 1039 "cs.ATG" if (startLocation.X == -1) startLocation = t.Location; - Expect(1); + Identifier(); -#line 1019 "cs.ATG" +#line 1040 "cs.ATG" name = t.val; if (la.kind == 23) { TypeParameterList( -#line 1020 "cs.ATG" +#line 1041 "cs.ATG" templates); } Expect(20); - if (StartOf(10)) { + if (StartOf(11)) { FormalParameterList( -#line 1021 "cs.ATG" +#line 1042 "cs.ATG" parameters); } Expect(21); - while ( -#line 1022 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 1022 "cs.ATG" +#line 1043 "cs.ATG" templates); } Expect(11); -#line 1024 "cs.ATG" +#line 1045 "cs.ATG" MethodDeclaration md = new MethodDeclaration(name, mod, new TypeReference("void"), parameters, attributes); md.StartLocation = startLocation; md.EndLocation = t.EndLocation; md.Templates = templates; compilationUnit.AddChild(md); - } else if (StartOf(18)) { - if (StartOf(9)) { + } else if (StartOf(21)) { + if (StartOf(10)) { Type( -#line 1031 "cs.ATG" +#line 1052 "cs.ATG" out type); -#line 1031 "cs.ATG" +#line 1052 "cs.ATG" if (startLocation.X == -1) startLocation = t.Location; - if (la.kind == 1) { - lexer.NextToken(); + if (StartOf(17)) { + Identifier(); -#line 1033 "cs.ATG" +#line 1054 "cs.ATG" name = t.val; Location qualIdentEndLocation = t.EndLocation; if (la.kind == 20 || la.kind == 23) { if (la.kind == 23) { TypeParameterList( -#line 1037 "cs.ATG" +#line 1058 "cs.ATG" templates); } Expect(20); - if (StartOf(10)) { + if (StartOf(11)) { FormalParameterList( -#line 1038 "cs.ATG" +#line 1059 "cs.ATG" parameters); } Expect(21); - while ( -#line 1040 "cs.ATG" -IdentIsWhere()) { + while (la.kind == 127) { TypeParameterConstraintsClause( -#line 1040 "cs.ATG" +#line 1061 "cs.ATG" templates); } Expect(11); -#line 1041 "cs.ATG" +#line 1062 "cs.ATG" MethodDeclaration md = new MethodDeclaration(name, mod, type, parameters, attributes); md.StartLocation = startLocation; md.EndLocation = t.EndLocation; @@ -2170,72 +2266,72 @@ templates); } else if (la.kind == 16) { -#line 1048 "cs.ATG" +#line 1069 "cs.ATG" PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); lexer.NextToken(); -#line 1049 "cs.ATG" +#line 1070 "cs.ATG" Location bodyStart = t.Location; InterfaceAccessors( -#line 1049 "cs.ATG" +#line 1070 "cs.ATG" out getBlock, out setBlock); Expect(17); -#line 1049 "cs.ATG" +#line 1070 "cs.ATG" pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; - } else SynErr(152); - } else if (la.kind == 110) { + } else SynErr(169); + } else if (la.kind == 111) { lexer.NextToken(); Expect(18); FormalParameterList( -#line 1052 "cs.ATG" +#line 1073 "cs.ATG" parameters); Expect(19); -#line 1052 "cs.ATG" +#line 1073 "cs.ATG" Location bracketEndLocation = t.EndLocation; -#line 1052 "cs.ATG" +#line 1073 "cs.ATG" IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); Expect(16); -#line 1053 "cs.ATG" +#line 1074 "cs.ATG" Location bodyStart = t.Location; InterfaceAccessors( -#line 1053 "cs.ATG" +#line 1074 "cs.ATG" out getBlock, out setBlock); Expect(17); -#line 1053 "cs.ATG" +#line 1074 "cs.ATG" id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation; - } else SynErr(153); + } else SynErr(170); } else { lexer.NextToken(); -#line 1056 "cs.ATG" +#line 1077 "cs.ATG" if (startLocation.X == -1) startLocation = t.Location; Type( -#line 1056 "cs.ATG" +#line 1078 "cs.ATG" out type); - Expect(1); + Identifier(); -#line 1056 "cs.ATG" +#line 1078 "cs.ATG" EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes, null); compilationUnit.AddChild(ed); Expect(11); -#line 1059 "cs.ATG" +#line 1081 "cs.ATG" ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; } - } else SynErr(154); + } else SynErr(171); } void EnumMemberDecl( -#line 1064 "cs.ATG" +#line 1086 "cs.ATG" out FieldDeclaration f) { -#line 1066 "cs.ATG" +#line 1088 "cs.ATG" Expression expr = null; List attributes = new List(); AttributeSection section = null; @@ -2243,15 +2339,15 @@ out FieldDeclaration f) { while (la.kind == 18) { AttributeSection( -#line 1072 "cs.ATG" +#line 1094 "cs.ATG" out section); -#line 1072 "cs.ATG" +#line 1094 "cs.ATG" attributes.Add(section); } - Expect(1); + Identifier(); -#line 1073 "cs.ATG" +#line 1095 "cs.ATG" f = new FieldDeclaration(attributes); varDecl = new VariableDeclaration(t.val); f.Fields.Add(varDecl); @@ -2260,78 +2356,78 @@ out section); if (la.kind == 3) { lexer.NextToken(); Expr( -#line 1078 "cs.ATG" +#line 1100 "cs.ATG" out expr); -#line 1078 "cs.ATG" +#line 1100 "cs.ATG" varDecl.Initializer = expr; } } void TypeWithRestriction( -#line 525 "cs.ATG" +#line 540 "cs.ATG" out TypeReference type, bool allowNullable, bool canBeUnbound) { -#line 527 "cs.ATG" +#line 542 "cs.ATG" string name; int pointer = 0; type = null; - if (la.kind == 1 || la.kind == 90 || la.kind == 107) { + if (StartOf(4)) { ClassType( -#line 532 "cs.ATG" +#line 547 "cs.ATG" out type, canBeUnbound); - } else if (StartOf(4)) { + } else if (StartOf(5)) { SimpleType( -#line 533 "cs.ATG" +#line 548 "cs.ATG" out name); -#line 533 "cs.ATG" +#line 548 "cs.ATG" type = new TypeReference(name); - } else if (la.kind == 122) { + } else if (la.kind == 123) { lexer.NextToken(); Expect(6); -#line 534 "cs.ATG" +#line 549 "cs.ATG" pointer = 1; type = new TypeReference("void"); - } else SynErr(155); + } else SynErr(172); -#line 535 "cs.ATG" +#line 550 "cs.ATG" List r = new List(); if ( -#line 537 "cs.ATG" +#line 552 "cs.ATG" allowNullable && la.kind == Tokens.Question) { NullableQuestionMark( -#line 537 "cs.ATG" +#line 552 "cs.ATG" ref type); } while ( -#line 539 "cs.ATG" +#line 554 "cs.ATG" IsPointerOrDims()) { -#line 539 "cs.ATG" +#line 554 "cs.ATG" int i = 0; if (la.kind == 6) { lexer.NextToken(); -#line 540 "cs.ATG" +#line 555 "cs.ATG" ++pointer; } else if (la.kind == 18) { lexer.NextToken(); while (la.kind == 14) { lexer.NextToken(); -#line 541 "cs.ATG" +#line 556 "cs.ATG" ++i; } Expect(19); -#line 541 "cs.ATG" +#line 556 "cs.ATG" r.Add(i); - } else SynErr(156); + } else SynErr(173); } -#line 544 "cs.ATG" +#line 559 "cs.ATG" if (type != null) { type.RankSpecifier = r.ToArray(); type.PointerNestingLevel = pointer; @@ -2340,152 +2436,152 @@ IsPointerOrDims()) { } void SimpleType( -#line 572 "cs.ATG" +#line 587 "cs.ATG" out string name) { -#line 573 "cs.ATG" +#line 588 "cs.ATG" name = String.Empty; - if (StartOf(19)) { + if (StartOf(22)) { IntegralType( -#line 575 "cs.ATG" +#line 590 "cs.ATG" out name); - } else if (la.kind == 74) { + } else if (la.kind == 75) { lexer.NextToken(); -#line 576 "cs.ATG" +#line 591 "cs.ATG" name = "float"; - } else if (la.kind == 65) { + } else if (la.kind == 66) { lexer.NextToken(); -#line 577 "cs.ATG" +#line 592 "cs.ATG" name = "double"; - } else if (la.kind == 61) { + } else if (la.kind == 62) { lexer.NextToken(); -#line 578 "cs.ATG" +#line 593 "cs.ATG" name = "decimal"; - } else if (la.kind == 51) { + } else if (la.kind == 52) { lexer.NextToken(); -#line 579 "cs.ATG" +#line 594 "cs.ATG" name = "bool"; - } else SynErr(157); + } else SynErr(174); } void NullableQuestionMark( -#line 1987 "cs.ATG" +#line 2127 "cs.ATG" ref TypeReference typeRef) { -#line 1988 "cs.ATG" +#line 2128 "cs.ATG" List typeArguments = new List(1); Expect(12); -#line 1992 "cs.ATG" +#line 2132 "cs.ATG" if (typeRef != null) typeArguments.Add(typeRef); typeRef = new TypeReference("System.Nullable", typeArguments); } void FixedParameter( -#line 609 "cs.ATG" +#line 624 "cs.ATG" out ParameterDeclarationExpression p) { -#line 611 "cs.ATG" +#line 626 "cs.ATG" TypeReference type; ParameterModifiers mod = ParameterModifiers.In; Location start = t.Location; - if (la.kind == 92 || la.kind == 99) { - if (la.kind == 99) { + if (la.kind == 93 || la.kind == 100) { + if (la.kind == 100) { lexer.NextToken(); -#line 617 "cs.ATG" +#line 632 "cs.ATG" mod = ParameterModifiers.Ref; } else { lexer.NextToken(); -#line 618 "cs.ATG" +#line 633 "cs.ATG" mod = ParameterModifiers.Out; } } Type( -#line 620 "cs.ATG" +#line 635 "cs.ATG" out type); - Expect(1); + Identifier(); -#line 620 "cs.ATG" +#line 635 "cs.ATG" p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; } void ParameterArray( -#line 623 "cs.ATG" +#line 638 "cs.ATG" out ParameterDeclarationExpression p) { -#line 624 "cs.ATG" +#line 639 "cs.ATG" TypeReference type; - Expect(94); + Expect(95); Type( -#line 626 "cs.ATG" +#line 641 "cs.ATG" out type); - Expect(1); + Identifier(); -#line 626 "cs.ATG" +#line 641 "cs.ATG" p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); } void AccessorModifiers( -#line 629 "cs.ATG" +#line 644 "cs.ATG" out ModifierList m) { -#line 630 "cs.ATG" +#line 645 "cs.ATG" m = new ModifierList(); - if (la.kind == 95) { + if (la.kind == 96) { lexer.NextToken(); -#line 632 "cs.ATG" +#line 647 "cs.ATG" m.Add(Modifiers.Private, t.Location); - } else if (la.kind == 96) { + } else if (la.kind == 97) { lexer.NextToken(); -#line 633 "cs.ATG" +#line 648 "cs.ATG" m.Add(Modifiers.Protected, t.Location); - if (la.kind == 83) { + if (la.kind == 84) { lexer.NextToken(); -#line 634 "cs.ATG" +#line 649 "cs.ATG" m.Add(Modifiers.Internal, t.Location); } - } else if (la.kind == 83) { + } else if (la.kind == 84) { lexer.NextToken(); -#line 635 "cs.ATG" +#line 650 "cs.ATG" m.Add(Modifiers.Internal, t.Location); - if (la.kind == 96) { + if (la.kind == 97) { lexer.NextToken(); -#line 636 "cs.ATG" +#line 651 "cs.ATG" m.Add(Modifiers.Protected, t.Location); } - } else SynErr(158); + } else SynErr(175); } void Block( -#line 1203 "cs.ATG" +#line 1219 "cs.ATG" out Statement stmt) { Expect(16); -#line 1205 "cs.ATG" +#line 1221 "cs.ATG" BlockStatement blockStmt = new BlockStatement(); blockStmt.StartLocation = t.Location; compilationUnit.BlockStart(blockStmt); if (!ParseMethodBodies) lexer.SkipCurrentBlock(0); - while (StartOf(20)) { + while (StartOf(23)) { Statement(); } Expect(17); -#line 1212 "cs.ATG" +#line 1228 "cs.ATG" stmt = blockStmt; blockStmt.EndLocation = t.EndLocation; compilationUnit.BlockEnd(); @@ -2493,10 +2589,10 @@ out Statement stmt) { } void EventAccessorDecls( -#line 1138 "cs.ATG" +#line 1157 "cs.ATG" out EventAddRegion addBlock, out EventRemoveRegion removeBlock) { -#line 1139 "cs.ATG" +#line 1158 "cs.ATG" AttributeSection section; List attributes = new List(); Statement stmt; @@ -2505,102 +2601,93 @@ out EventAddRegion addBlock, out EventRemoveRegion removeBlock) { while (la.kind == 18) { AttributeSection( -#line 1146 "cs.ATG" +#line 1165 "cs.ATG" out section); -#line 1146 "cs.ATG" +#line 1165 "cs.ATG" attributes.Add(section); } - if ( -#line 1148 "cs.ATG" -IdentIsAdd()) { + if (la.kind == 130) { -#line 1148 "cs.ATG" +#line 1167 "cs.ATG" addBlock = new EventAddRegion(attributes); AddAccessorDecl( -#line 1149 "cs.ATG" +#line 1168 "cs.ATG" out stmt); -#line 1149 "cs.ATG" +#line 1168 "cs.ATG" attributes = new List(); addBlock.Block = (BlockStatement)stmt; while (la.kind == 18) { AttributeSection( -#line 1150 "cs.ATG" +#line 1169 "cs.ATG" out section); -#line 1150 "cs.ATG" +#line 1169 "cs.ATG" attributes.Add(section); } RemoveAccessorDecl( -#line 1151 "cs.ATG" +#line 1170 "cs.ATG" out stmt); -#line 1151 "cs.ATG" +#line 1170 "cs.ATG" removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; - } else if ( -#line 1152 "cs.ATG" -IdentIsRemove()) { + } else if (la.kind == 131) { RemoveAccessorDecl( -#line 1153 "cs.ATG" +#line 1172 "cs.ATG" out stmt); -#line 1153 "cs.ATG" +#line 1172 "cs.ATG" removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new List(); while (la.kind == 18) { AttributeSection( -#line 1154 "cs.ATG" +#line 1173 "cs.ATG" out section); -#line 1154 "cs.ATG" +#line 1173 "cs.ATG" attributes.Add(section); } AddAccessorDecl( -#line 1155 "cs.ATG" +#line 1174 "cs.ATG" out stmt); -#line 1155 "cs.ATG" +#line 1174 "cs.ATG" addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; - } else if (la.kind == 1) { - lexer.NextToken(); - -#line 1156 "cs.ATG" - Error("add or remove accessor declaration expected"); - } else SynErr(159); + } else SynErr(176); } void ConstructorInitializer( -#line 1234 "cs.ATG" +#line 1248 "cs.ATG" out ConstructorInitializer ci) { -#line 1235 "cs.ATG" +#line 1249 "cs.ATG" Expression expr; ci = new ConstructorInitializer(); Expect(9); - if (la.kind == 50) { + if (la.kind == 51) { lexer.NextToken(); -#line 1239 "cs.ATG" +#line 1253 "cs.ATG" ci.ConstructorInitializerType = ConstructorInitializerType.Base; - } else if (la.kind == 110) { + } else if (la.kind == 111) { lexer.NextToken(); -#line 1240 "cs.ATG" +#line 1254 "cs.ATG" ci.ConstructorInitializerType = ConstructorInitializerType.This; - } else SynErr(160); + } else SynErr(177); Expect(20); - if (StartOf(21)) { + if (StartOf(24)) { Argument( -#line 1243 "cs.ATG" +#line 1257 "cs.ATG" out expr); -#line 1243 "cs.ATG" +#line 1257 "cs.ATG" if (expr != null) { ci.Arguments.Add(expr); } while (la.kind == 14) { lexer.NextToken(); Argument( -#line 1243 "cs.ATG" +#line 1257 "cs.ATG" out expr); -#line 1243 "cs.ATG" +#line 1257 "cs.ATG" if (expr != null) { ci.Arguments.Add(expr); } } } @@ -2608,198 +2695,198 @@ out expr); } void OverloadableOperator( -#line 1255 "cs.ATG" +#line 1269 "cs.ATG" out OverloadableOperatorType op) { -#line 1256 "cs.ATG" +#line 1270 "cs.ATG" op = OverloadableOperatorType.None; switch (la.kind) { case 4: { lexer.NextToken(); -#line 1258 "cs.ATG" +#line 1272 "cs.ATG" op = OverloadableOperatorType.Add; break; } case 5: { lexer.NextToken(); -#line 1259 "cs.ATG" +#line 1273 "cs.ATG" op = OverloadableOperatorType.Subtract; break; } case 24: { lexer.NextToken(); -#line 1261 "cs.ATG" +#line 1275 "cs.ATG" op = OverloadableOperatorType.Not; break; } case 27: { lexer.NextToken(); -#line 1262 "cs.ATG" +#line 1276 "cs.ATG" op = OverloadableOperatorType.BitNot; break; } case 31: { lexer.NextToken(); -#line 1264 "cs.ATG" +#line 1278 "cs.ATG" op = OverloadableOperatorType.Increment; break; } case 32: { lexer.NextToken(); -#line 1265 "cs.ATG" +#line 1279 "cs.ATG" op = OverloadableOperatorType.Decrement; break; } - case 112: { + case 113: { lexer.NextToken(); -#line 1267 "cs.ATG" +#line 1281 "cs.ATG" op = OverloadableOperatorType.IsTrue; break; } - case 71: { + case 72: { lexer.NextToken(); -#line 1268 "cs.ATG" +#line 1282 "cs.ATG" op = OverloadableOperatorType.IsFalse; break; } case 6: { lexer.NextToken(); -#line 1270 "cs.ATG" +#line 1284 "cs.ATG" op = OverloadableOperatorType.Multiply; break; } case 7: { lexer.NextToken(); -#line 1271 "cs.ATG" +#line 1285 "cs.ATG" op = OverloadableOperatorType.Divide; break; } case 8: { lexer.NextToken(); -#line 1272 "cs.ATG" +#line 1286 "cs.ATG" op = OverloadableOperatorType.Modulus; break; } case 28: { lexer.NextToken(); -#line 1274 "cs.ATG" +#line 1288 "cs.ATG" op = OverloadableOperatorType.BitwiseAnd; break; } case 29: { lexer.NextToken(); -#line 1275 "cs.ATG" +#line 1289 "cs.ATG" op = OverloadableOperatorType.BitwiseOr; break; } case 30: { lexer.NextToken(); -#line 1276 "cs.ATG" +#line 1290 "cs.ATG" op = OverloadableOperatorType.ExclusiveOr; break; } case 37: { lexer.NextToken(); -#line 1278 "cs.ATG" +#line 1292 "cs.ATG" op = OverloadableOperatorType.ShiftLeft; break; } case 33: { lexer.NextToken(); -#line 1279 "cs.ATG" +#line 1293 "cs.ATG" op = OverloadableOperatorType.Equality; break; } case 34: { lexer.NextToken(); -#line 1280 "cs.ATG" +#line 1294 "cs.ATG" op = OverloadableOperatorType.InEquality; break; } case 23: { lexer.NextToken(); -#line 1281 "cs.ATG" +#line 1295 "cs.ATG" op = OverloadableOperatorType.LessThan; break; } case 35: { lexer.NextToken(); -#line 1282 "cs.ATG" +#line 1296 "cs.ATG" op = OverloadableOperatorType.GreaterThanOrEqual; break; } case 36: { lexer.NextToken(); -#line 1283 "cs.ATG" +#line 1297 "cs.ATG" op = OverloadableOperatorType.LessThanOrEqual; break; } case 22: { lexer.NextToken(); -#line 1284 "cs.ATG" +#line 1298 "cs.ATG" op = OverloadableOperatorType.GreaterThan; if (la.kind == 22) { lexer.NextToken(); -#line 1284 "cs.ATG" +#line 1298 "cs.ATG" op = OverloadableOperatorType.ShiftRight; } break; } - default: SynErr(161); break; + default: SynErr(178); break; } } void VariableDeclarator( -#line 1196 "cs.ATG" +#line 1212 "cs.ATG" List fieldDeclaration) { -#line 1197 "cs.ATG" +#line 1213 "cs.ATG" Expression expr = null; - Expect(1); + Identifier(); -#line 1199 "cs.ATG" +#line 1215 "cs.ATG" VariableDeclaration f = new VariableDeclaration(t.val); if (la.kind == 3) { lexer.NextToken(); VariableInitializer( -#line 1200 "cs.ATG" +#line 1216 "cs.ATG" out expr); -#line 1200 "cs.ATG" +#line 1216 "cs.ATG" f.Initializer = expr; } -#line 1200 "cs.ATG" +#line 1216 "cs.ATG" fieldDeclaration.Add(f); } void AccessorDecls( -#line 1082 "cs.ATG" +#line 1104 "cs.ATG" out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { -#line 1084 "cs.ATG" +#line 1106 "cs.ATG" List attributes = new List(); AttributeSection section; getBlock = null; @@ -2808,96 +2895,92 @@ out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { while (la.kind == 18) { AttributeSection( -#line 1091 "cs.ATG" +#line 1113 "cs.ATG" out section); -#line 1091 "cs.ATG" +#line 1113 "cs.ATG" attributes.Add(section); } - if (la.kind == 83 || la.kind == 95 || la.kind == 96) { + if (la.kind == 84 || la.kind == 96 || la.kind == 97) { AccessorModifiers( -#line 1092 "cs.ATG" +#line 1114 "cs.ATG" out modifiers); } - if ( -#line 1094 "cs.ATG" -IdentIsGet()) { + if (la.kind == 128) { GetAccessorDecl( -#line 1095 "cs.ATG" +#line 1116 "cs.ATG" out getBlock, attributes); -#line 1096 "cs.ATG" +#line 1117 "cs.ATG" if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } - if (StartOf(22)) { + if (StartOf(25)) { -#line 1097 "cs.ATG" +#line 1118 "cs.ATG" attributes = new List(); modifiers = null; while (la.kind == 18) { AttributeSection( -#line 1098 "cs.ATG" +#line 1119 "cs.ATG" out section); -#line 1098 "cs.ATG" +#line 1119 "cs.ATG" attributes.Add(section); } - if (la.kind == 83 || la.kind == 95 || la.kind == 96) { + if (la.kind == 84 || la.kind == 96 || la.kind == 97) { AccessorModifiers( -#line 1099 "cs.ATG" +#line 1120 "cs.ATG" out modifiers); } SetAccessorDecl( -#line 1100 "cs.ATG" +#line 1121 "cs.ATG" out setBlock, attributes); -#line 1101 "cs.ATG" +#line 1122 "cs.ATG" if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } } - } else if ( -#line 1103 "cs.ATG" -IdentIsSet()) { + } else if (la.kind == 129) { SetAccessorDecl( -#line 1104 "cs.ATG" +#line 1125 "cs.ATG" out setBlock, attributes); -#line 1105 "cs.ATG" +#line 1126 "cs.ATG" if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } - if (StartOf(22)) { + if (StartOf(26)) { -#line 1106 "cs.ATG" +#line 1127 "cs.ATG" attributes = new List(); modifiers = null; while (la.kind == 18) { AttributeSection( -#line 1107 "cs.ATG" +#line 1128 "cs.ATG" out section); -#line 1107 "cs.ATG" +#line 1128 "cs.ATG" attributes.Add(section); } - if (la.kind == 83 || la.kind == 95 || la.kind == 96) { + if (la.kind == 84 || la.kind == 96 || la.kind == 97) { AccessorModifiers( -#line 1108 "cs.ATG" +#line 1129 "cs.ATG" out modifiers); } GetAccessorDecl( -#line 1109 "cs.ATG" +#line 1130 "cs.ATG" out getBlock, attributes); -#line 1110 "cs.ATG" +#line 1131 "cs.ATG" if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } } - } else if (la.kind == 1) { - lexer.NextToken(); + } else if (StartOf(17)) { + Identifier(); -#line 1112 "cs.ATG" +#line 1133 "cs.ATG" Error("get or set accessor declaration expected"); - } else SynErr(162); + } else SynErr(179); } void InterfaceAccessors( -#line 1160 "cs.ATG" +#line 1178 "cs.ATG" out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { -#line 1162 "cs.ATG" +#line 1180 "cs.ATG" AttributeSection section; List attributes = new List(); getBlock = null; setBlock = null; @@ -2905,274 +2988,244 @@ out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { while (la.kind == 18) { AttributeSection( -#line 1168 "cs.ATG" +#line 1186 "cs.ATG" out section); -#line 1168 "cs.ATG" +#line 1186 "cs.ATG" attributes.Add(section); } -#line 1169 "cs.ATG" +#line 1187 "cs.ATG" Location startLocation = la.Location; - if ( -#line 1171 "cs.ATG" -IdentIsGet()) { - Expect(1); + if (la.kind == 128) { + lexer.NextToken(); -#line 1171 "cs.ATG" +#line 1189 "cs.ATG" getBlock = new PropertyGetRegion(null, attributes); - } else if ( -#line 1172 "cs.ATG" -IdentIsSet()) { - Expect(1); - -#line 1172 "cs.ATG" - setBlock = new PropertySetRegion(null, attributes); - } else if (la.kind == 1) { + } else if (la.kind == 129) { lexer.NextToken(); -#line 1173 "cs.ATG" - Error("set or get expected"); - } else SynErr(163); +#line 1190 "cs.ATG" + setBlock = new PropertySetRegion(null, attributes); + } else SynErr(180); Expect(11); -#line 1176 "cs.ATG" +#line 1193 "cs.ATG" if (getBlock != null) { getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; } if (setBlock != null) { setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; } attributes = new List(); - if (la.kind == 1 || la.kind == 18) { + if (la.kind == 18 || la.kind == 128 || la.kind == 129) { while (la.kind == 18) { AttributeSection( -#line 1180 "cs.ATG" +#line 1197 "cs.ATG" out section); -#line 1180 "cs.ATG" +#line 1197 "cs.ATG" attributes.Add(section); } -#line 1181 "cs.ATG" +#line 1198 "cs.ATG" startLocation = la.Location; - if ( -#line 1183 "cs.ATG" -IdentIsGet()) { - Expect(1); + if (la.kind == 128) { + lexer.NextToken(); -#line 1183 "cs.ATG" +#line 1200 "cs.ATG" if (getBlock != null) Error("get already declared"); - else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; } - - } else if ( -#line 1186 "cs.ATG" -IdentIsSet()) { - Expect(1); - -#line 1186 "cs.ATG" - if (setBlock != null) Error("set already declared"); - else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; } - - } else if (la.kind == 1) { + else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; } + + } else if (la.kind == 129) { lexer.NextToken(); -#line 1189 "cs.ATG" - Error("set or get expected"); - } else SynErr(164); +#line 1203 "cs.ATG" + if (setBlock != null) Error("set already declared"); + else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; } + + } else SynErr(181); Expect(11); -#line 1192 "cs.ATG" +#line 1208 "cs.ATG" if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } } } void GetAccessorDecl( -#line 1116 "cs.ATG" +#line 1137 "cs.ATG" out PropertyGetRegion getBlock, List attributes) { -#line 1117 "cs.ATG" +#line 1138 "cs.ATG" Statement stmt = null; - Expect(1); + Expect(128); -#line 1120 "cs.ATG" - if (t.val != "get") Error("get expected"); - -#line 1121 "cs.ATG" +#line 1141 "cs.ATG" Location startLocation = t.Location; if (la.kind == 16) { Block( -#line 1122 "cs.ATG" +#line 1142 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(165); + } else SynErr(182); -#line 1123 "cs.ATG" +#line 1143 "cs.ATG" getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); -#line 1124 "cs.ATG" +#line 1144 "cs.ATG" getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; } void SetAccessorDecl( -#line 1127 "cs.ATG" +#line 1147 "cs.ATG" out PropertySetRegion setBlock, List attributes) { -#line 1128 "cs.ATG" +#line 1148 "cs.ATG" Statement stmt = null; - Expect(1); - -#line 1131 "cs.ATG" - if (t.val != "set") Error("set expected"); + Expect(129); -#line 1132 "cs.ATG" +#line 1151 "cs.ATG" Location startLocation = t.Location; if (la.kind == 16) { Block( -#line 1133 "cs.ATG" +#line 1152 "cs.ATG" out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(166); + } else SynErr(183); -#line 1134 "cs.ATG" +#line 1153 "cs.ATG" setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); -#line 1135 "cs.ATG" +#line 1154 "cs.ATG" setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; } void AddAccessorDecl( -#line 1218 "cs.ATG" +#line 1234 "cs.ATG" out Statement stmt) { -#line 1219 "cs.ATG" +#line 1235 "cs.ATG" stmt = null; - Expect(1); - -#line 1222 "cs.ATG" - if (t.val != "add") Error("add expected"); + Expect(130); Block( -#line 1223 "cs.ATG" +#line 1238 "cs.ATG" out stmt); } void RemoveAccessorDecl( -#line 1226 "cs.ATG" +#line 1241 "cs.ATG" out Statement stmt) { -#line 1227 "cs.ATG" +#line 1242 "cs.ATG" stmt = null; - Expect(1); - -#line 1230 "cs.ATG" - if (t.val != "remove") Error("remove expected"); + Expect(131); Block( -#line 1231 "cs.ATG" +#line 1245 "cs.ATG" out stmt); } void VariableInitializer( -#line 1247 "cs.ATG" +#line 1261 "cs.ATG" out Expression initializerExpression) { -#line 1248 "cs.ATG" +#line 1262 "cs.ATG" TypeReference type = null; Expression expr = null; initializerExpression = null; - if (StartOf(5)) { + if (StartOf(6)) { Expr( -#line 1250 "cs.ATG" +#line 1264 "cs.ATG" out initializerExpression); } else if (la.kind == 16) { - ArrayInitializer( -#line 1251 "cs.ATG" + CollectionInitializer( +#line 1265 "cs.ATG" out initializerExpression); - } else if (la.kind == 105) { + } else if (la.kind == 106) { lexer.NextToken(); Type( -#line 1252 "cs.ATG" +#line 1266 "cs.ATG" out type); Expect(18); Expr( -#line 1252 "cs.ATG" +#line 1266 "cs.ATG" out expr); Expect(19); -#line 1252 "cs.ATG" +#line 1266 "cs.ATG" initializerExpression = new StackAllocExpression(type, expr); - } else SynErr(167); + } else SynErr(184); } void Statement() { -#line 1364 "cs.ATG" +#line 1402 "cs.ATG" TypeReference type; Expression expr; Statement stmt = null; Location startPos = la.Location; if ( -#line 1372 "cs.ATG" +#line 1410 "cs.ATG" IsLabel()) { - Expect(1); + Identifier(); -#line 1372 "cs.ATG" +#line 1410 "cs.ATG" compilationUnit.AddChild(new LabelStatement(t.val)); Expect(9); Statement(); - } else if (la.kind == 59) { + } else if (la.kind == 60) { lexer.NextToken(); Type( -#line 1375 "cs.ATG" +#line 1413 "cs.ATG" out type); -#line 1375 "cs.ATG" +#line 1413 "cs.ATG" LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; - Expect(1); + Identifier(); -#line 1376 "cs.ATG" +#line 1414 "cs.ATG" ident = t.val; Expect(3); Expr( -#line 1377 "cs.ATG" +#line 1415 "cs.ATG" out expr); -#line 1377 "cs.ATG" +#line 1415 "cs.ATG" var.Variables.Add(new VariableDeclaration(ident, expr)); while (la.kind == 14) { lexer.NextToken(); - Expect(1); + Identifier(); -#line 1378 "cs.ATG" +#line 1416 "cs.ATG" ident = t.val; Expect(3); Expr( -#line 1378 "cs.ATG" +#line 1416 "cs.ATG" out expr); -#line 1378 "cs.ATG" +#line 1416 "cs.ATG" var.Variables.Add(new VariableDeclaration(ident, expr)); } Expect(11); -#line 1379 "cs.ATG" +#line 1417 "cs.ATG" compilationUnit.AddChild(var); } else if ( -#line 1381 "cs.ATG" +#line 1419 "cs.ATG" IsLocalVarDecl()) { LocalVariableDecl( -#line 1381 "cs.ATG" +#line 1419 "cs.ATG" out stmt); Expect(11); -#line 1381 "cs.ATG" +#line 1419 "cs.ATG" compilationUnit.AddChild(stmt); - } else if (StartOf(23)) { + } else if (StartOf(27)) { EmbeddedStatement( -#line 1382 "cs.ATG" +#line 1420 "cs.ATG" out stmt); -#line 1382 "cs.ATG" +#line 1420 "cs.ATG" compilationUnit.AddChild(stmt); - } else SynErr(168); + } else SynErr(185); -#line 1388 "cs.ATG" +#line 1426 "cs.ATG" if (stmt != null) { stmt.StartLocation = startPos; stmt.EndLocation = t.EndLocation; @@ -3181,59 +3234,59 @@ out stmt); } void Argument( -#line 1287 "cs.ATG" +#line 1301 "cs.ATG" out Expression argumentexpr) { -#line 1289 "cs.ATG" +#line 1303 "cs.ATG" Expression expr; FieldDirection fd = FieldDirection.None; - if (la.kind == 92 || la.kind == 99) { - if (la.kind == 99) { + if (la.kind == 93 || la.kind == 100) { + if (la.kind == 100) { lexer.NextToken(); -#line 1294 "cs.ATG" +#line 1308 "cs.ATG" fd = FieldDirection.Ref; } else { lexer.NextToken(); -#line 1295 "cs.ATG" +#line 1309 "cs.ATG" fd = FieldDirection.Out; } } Expr( -#line 1297 "cs.ATG" +#line 1311 "cs.ATG" out expr); -#line 1297 "cs.ATG" +#line 1311 "cs.ATG" argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; } - void ArrayInitializer( -#line 1317 "cs.ATG" + void CollectionInitializer( +#line 1331 "cs.ATG" out Expression outExpr) { -#line 1319 "cs.ATG" +#line 1333 "cs.ATG" Expression expr = null; - ArrayInitializerExpression initializer = new ArrayInitializerExpression(); + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); Expect(16); - if (StartOf(24)) { + if (StartOf(28)) { VariableInitializer( -#line 1324 "cs.ATG" +#line 1338 "cs.ATG" out expr); -#line 1325 "cs.ATG" +#line 1339 "cs.ATG" if (expr != null) { initializer.CreateExpressions.Add(expr); } while ( -#line 1326 "cs.ATG" +#line 1340 "cs.ATG" NotFinalComma()) { Expect(14); VariableInitializer( -#line 1327 "cs.ATG" +#line 1341 "cs.ATG" out expr); -#line 1328 "cs.ATG" +#line 1342 "cs.ATG" if (expr != null) { initializer.CreateExpressions.Add(expr); } } if (la.kind == 14) { @@ -3242,138 +3295,204 @@ out expr); } Expect(17); -#line 1332 "cs.ATG" +#line 1346 "cs.ATG" outExpr = initializer; } void AssignmentOperator( -#line 1300 "cs.ATG" +#line 1314 "cs.ATG" out AssignmentOperatorType op) { -#line 1301 "cs.ATG" +#line 1315 "cs.ATG" op = AssignmentOperatorType.None; if (la.kind == 3) { lexer.NextToken(); -#line 1303 "cs.ATG" +#line 1317 "cs.ATG" op = AssignmentOperatorType.Assign; } else if (la.kind == 38) { lexer.NextToken(); -#line 1304 "cs.ATG" +#line 1318 "cs.ATG" op = AssignmentOperatorType.Add; } else if (la.kind == 39) { lexer.NextToken(); -#line 1305 "cs.ATG" +#line 1319 "cs.ATG" op = AssignmentOperatorType.Subtract; } else if (la.kind == 40) { lexer.NextToken(); -#line 1306 "cs.ATG" +#line 1320 "cs.ATG" op = AssignmentOperatorType.Multiply; } else if (la.kind == 41) { lexer.NextToken(); -#line 1307 "cs.ATG" +#line 1321 "cs.ATG" op = AssignmentOperatorType.Divide; } else if (la.kind == 42) { lexer.NextToken(); -#line 1308 "cs.ATG" +#line 1322 "cs.ATG" op = AssignmentOperatorType.Modulus; } else if (la.kind == 43) { lexer.NextToken(); -#line 1309 "cs.ATG" +#line 1323 "cs.ATG" op = AssignmentOperatorType.BitwiseAnd; } else if (la.kind == 44) { lexer.NextToken(); -#line 1310 "cs.ATG" +#line 1324 "cs.ATG" op = AssignmentOperatorType.BitwiseOr; } else if (la.kind == 45) { lexer.NextToken(); -#line 1311 "cs.ATG" +#line 1325 "cs.ATG" op = AssignmentOperatorType.ExclusiveOr; } else if (la.kind == 46) { lexer.NextToken(); -#line 1312 "cs.ATG" +#line 1326 "cs.ATG" op = AssignmentOperatorType.ShiftLeft; } else if ( -#line 1313 "cs.ATG" +#line 1327 "cs.ATG" la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) { Expect(22); Expect(35); -#line 1314 "cs.ATG" +#line 1328 "cs.ATG" op = AssignmentOperatorType.ShiftRight; - } else SynErr(169); + } else SynErr(186); } - void LocalVariableDecl( -#line 1335 "cs.ATG" -out Statement stmt) { + void CollectionOrObjectInitializer( +#line 1349 "cs.ATG" +out Expression outExpr) { -#line 1337 "cs.ATG" - TypeReference type; - VariableDeclaration var = null; - LocalVariableDeclaration localVariableDeclaration; +#line 1351 "cs.ATG" + Expression expr = null; + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); - Type( -#line 1342 "cs.ATG" -out type); - -#line 1342 "cs.ATG" - localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = t.Location; - LocalVariableDeclarator( -#line 1343 "cs.ATG" -out var); + Expect(16); + if (StartOf(28)) { + ObjectPropertyInitializerOrVariableInitializer( +#line 1356 "cs.ATG" +out expr); -#line 1343 "cs.ATG" - localVariableDeclaration.Variables.Add(var); - while (la.kind == 14) { - lexer.NextToken(); - LocalVariableDeclarator( -#line 1344 "cs.ATG" -out var); +#line 1357 "cs.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + while ( +#line 1358 "cs.ATG" +NotFinalComma()) { + Expect(14); + ObjectPropertyInitializerOrVariableInitializer( +#line 1359 "cs.ATG" +out expr); -#line 1344 "cs.ATG" - localVariableDeclaration.Variables.Add(var); +#line 1360 "cs.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + } + if (la.kind == 14) { + lexer.NextToken(); + } } + Expect(17); -#line 1345 "cs.ATG" - stmt = localVariableDeclaration; +#line 1364 "cs.ATG" + outExpr = initializer; } - void LocalVariableDeclarator( -#line 1348 "cs.ATG" -out VariableDeclaration var) { + void ObjectPropertyInitializerOrVariableInitializer( +#line 1367 "cs.ATG" +out Expression expr) { -#line 1349 "cs.ATG" - Expression expr = null; - Expect(1); +#line 1368 "cs.ATG" + expr = null; + if ( +#line 1370 "cs.ATG" +IdentAndAsgn()) { + Identifier(); -#line 1352 "cs.ATG" +#line 1372 "cs.ATG" + IdentifierExpression l = new IdentifierExpression(t.val); + l.StartLocation = t.Location; l.EndLocation = t.EndLocation; + Expression r = null; + Expect(3); + VariableInitializer( +#line 1375 "cs.ATG" +out r); + +#line 1376 "cs.ATG" + expr = new AssignmentExpression(l, AssignmentOperatorType.Assign, r); + } else if (StartOf(28)) { + VariableInitializer( +#line 1377 "cs.ATG" +out expr); + } else SynErr(187); + } + + void LocalVariableDecl( +#line 1381 "cs.ATG" +out Statement stmt) { + +#line 1383 "cs.ATG" + TypeReference type; + VariableDeclaration var = null; + LocalVariableDeclaration localVariableDeclaration; + + Type( +#line 1388 "cs.ATG" +out type); + +#line 1388 "cs.ATG" + localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = t.Location; + LocalVariableDeclarator( +#line 1389 "cs.ATG" +out var); + +#line 1389 "cs.ATG" + localVariableDeclaration.Variables.Add(var); + while (la.kind == 14) { + lexer.NextToken(); + LocalVariableDeclarator( +#line 1390 "cs.ATG" +out var); + +#line 1390 "cs.ATG" + localVariableDeclaration.Variables.Add(var); + } + +#line 1391 "cs.ATG" + stmt = localVariableDeclaration; + } + + void LocalVariableDeclarator( +#line 1394 "cs.ATG" +out VariableDeclaration var) { + +#line 1395 "cs.ATG" + Expression expr = null; + Identifier(); + +#line 1397 "cs.ATG" var = new VariableDeclaration(t.val); if (la.kind == 3) { lexer.NextToken(); VariableInitializer( -#line 1352 "cs.ATG" +#line 1397 "cs.ATG" out expr); -#line 1352 "cs.ATG" +#line 1397 "cs.ATG" var.Initializer = expr; } } void EmbeddedStatement( -#line 1395 "cs.ATG" +#line 1433 "cs.ATG" out Statement statement) { -#line 1397 "cs.ATG" +#line 1435 "cs.ATG" TypeReference type = null; Expression expr = null; Statement embeddedStatement = null; @@ -3381,57 +3500,57 @@ out Statement statement) { if (la.kind == 16) { Block( -#line 1403 "cs.ATG" +#line 1441 "cs.ATG" out statement); } else if (la.kind == 11) { lexer.NextToken(); -#line 1405 "cs.ATG" +#line 1443 "cs.ATG" statement = new EmptyStatement(); } else if ( -#line 1407 "cs.ATG" +#line 1445 "cs.ATG" UnCheckedAndLBrace()) { -#line 1407 "cs.ATG" +#line 1445 "cs.ATG" Statement block; bool isChecked = true; - if (la.kind == 57) { + if (la.kind == 58) { lexer.NextToken(); - } else if (la.kind == 117) { + } else if (la.kind == 118) { lexer.NextToken(); -#line 1408 "cs.ATG" +#line 1446 "cs.ATG" isChecked = false; - } else SynErr(170); + } else SynErr(188); Block( -#line 1409 "cs.ATG" +#line 1447 "cs.ATG" out block); -#line 1409 "cs.ATG" +#line 1447 "cs.ATG" statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); - } else if (la.kind == 78) { + } else if (la.kind == 79) { lexer.NextToken(); -#line 1411 "cs.ATG" +#line 1449 "cs.ATG" Statement elseStatement = null; Expect(20); Expr( -#line 1412 "cs.ATG" +#line 1450 "cs.ATG" out expr); Expect(21); EmbeddedStatement( -#line 1413 "cs.ATG" +#line 1451 "cs.ATG" out embeddedStatement); - if (la.kind == 66) { + if (la.kind == 67) { lexer.NextToken(); EmbeddedStatement( -#line 1414 "cs.ATG" +#line 1452 "cs.ATG" out elseStatement); } -#line 1415 "cs.ATG" +#line 1453 "cs.ATG" statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); -#line 1416 "cs.ATG" +#line 1454 "cs.ATG" if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) { /* else if-section (otherwise we would have a BlockStatment) */ (statement as IfElseStatement).ElseIfSections.Add( @@ -3440,278 +3559,278 @@ out elseStatement); (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections); (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement; } - } else if (la.kind == 109) { + } else if (la.kind == 110) { lexer.NextToken(); -#line 1424 "cs.ATG" +#line 1462 "cs.ATG" List switchSections = new List(); Expect(20); Expr( -#line 1425 "cs.ATG" +#line 1463 "cs.ATG" out expr); Expect(21); Expect(16); SwitchSections( -#line 1426 "cs.ATG" +#line 1464 "cs.ATG" switchSections); Expect(17); -#line 1427 "cs.ATG" +#line 1465 "cs.ATG" statement = new SwitchStatement(expr, switchSections); - } else if (la.kind == 124) { + } else if (la.kind == 125) { lexer.NextToken(); Expect(20); Expr( -#line 1429 "cs.ATG" +#line 1467 "cs.ATG" out expr); Expect(21); EmbeddedStatement( -#line 1431 "cs.ATG" +#line 1469 "cs.ATG" out embeddedStatement); -#line 1431 "cs.ATG" +#line 1469 "cs.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); - } else if (la.kind == 64) { + } else if (la.kind == 65) { lexer.NextToken(); EmbeddedStatement( -#line 1432 "cs.ATG" +#line 1470 "cs.ATG" out embeddedStatement); - Expect(124); + Expect(125); Expect(20); Expr( -#line 1433 "cs.ATG" +#line 1471 "cs.ATG" out expr); Expect(21); Expect(11); -#line 1433 "cs.ATG" +#line 1471 "cs.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); - } else if (la.kind == 75) { + } else if (la.kind == 76) { lexer.NextToken(); -#line 1434 "cs.ATG" +#line 1472 "cs.ATG" List initializer = null; List iterator = null; Expect(20); - if (StartOf(5)) { + if (StartOf(6)) { ForInitializer( -#line 1435 "cs.ATG" +#line 1473 "cs.ATG" out initializer); } Expect(11); - if (StartOf(5)) { + if (StartOf(6)) { Expr( -#line 1436 "cs.ATG" +#line 1474 "cs.ATG" out expr); } Expect(11); - if (StartOf(5)) { + if (StartOf(6)) { ForIterator( -#line 1437 "cs.ATG" +#line 1475 "cs.ATG" out iterator); } Expect(21); EmbeddedStatement( -#line 1438 "cs.ATG" +#line 1476 "cs.ATG" out embeddedStatement); -#line 1438 "cs.ATG" +#line 1476 "cs.ATG" statement = new ForStatement(initializer, expr, iterator, embeddedStatement); - } else if (la.kind == 76) { + } else if (la.kind == 77) { lexer.NextToken(); Expect(20); Type( -#line 1439 "cs.ATG" +#line 1477 "cs.ATG" out type); - Expect(1); + Identifier(); -#line 1439 "cs.ATG" +#line 1477 "cs.ATG" string varName = t.val; Location start = t.Location; - Expect(80); + Expect(81); Expr( -#line 1440 "cs.ATG" +#line 1478 "cs.ATG" out expr); Expect(21); EmbeddedStatement( -#line 1441 "cs.ATG" +#line 1479 "cs.ATG" out embeddedStatement); -#line 1441 "cs.ATG" +#line 1479 "cs.ATG" statement = new ForeachStatement(type, varName , expr, embeddedStatement); statement.EndLocation = t.EndLocation; - } else if (la.kind == 52) { + } else if (la.kind == 53) { lexer.NextToken(); Expect(11); -#line 1445 "cs.ATG" +#line 1483 "cs.ATG" statement = new BreakStatement(); - } else if (la.kind == 60) { + } else if (la.kind == 61) { lexer.NextToken(); Expect(11); -#line 1446 "cs.ATG" +#line 1484 "cs.ATG" statement = new ContinueStatement(); - } else if (la.kind == 77) { + } else if (la.kind == 78) { GotoStatement( -#line 1447 "cs.ATG" +#line 1485 "cs.ATG" out statement); } else if ( -#line 1448 "cs.ATG" +#line 1486 "cs.ATG" IsYieldStatement()) { - Expect(1); - if (la.kind == 100) { + Expect(132); + if (la.kind == 101) { lexer.NextToken(); Expr( -#line 1448 "cs.ATG" +#line 1486 "cs.ATG" out expr); -#line 1448 "cs.ATG" +#line 1486 "cs.ATG" statement = new YieldStatement(new ReturnStatement(expr)); - } else if (la.kind == 52) { + } else if (la.kind == 53) { lexer.NextToken(); -#line 1449 "cs.ATG" +#line 1487 "cs.ATG" statement = new YieldStatement(new BreakStatement()); - } else SynErr(171); + } else SynErr(189); Expect(11); - } else if (la.kind == 100) { + } else if (la.kind == 101) { lexer.NextToken(); - if (StartOf(5)) { + if (StartOf(6)) { Expr( -#line 1450 "cs.ATG" +#line 1488 "cs.ATG" out expr); } Expect(11); -#line 1450 "cs.ATG" +#line 1488 "cs.ATG" statement = new ReturnStatement(expr); - } else if (la.kind == 111) { + } else if (la.kind == 112) { lexer.NextToken(); - if (StartOf(5)) { + if (StartOf(6)) { Expr( -#line 1451 "cs.ATG" +#line 1489 "cs.ATG" out expr); } Expect(11); -#line 1451 "cs.ATG" +#line 1489 "cs.ATG" statement = new ThrowStatement(expr); - } else if (StartOf(5)) { + } else if (StartOf(6)) { StatementExpr( -#line 1454 "cs.ATG" +#line 1492 "cs.ATG" out statement); Expect(11); - } else if (la.kind == 113) { + } else if (la.kind == 114) { TryStatement( -#line 1456 "cs.ATG" +#line 1494 "cs.ATG" out statement); - } else if (la.kind == 85) { + } else if (la.kind == 86) { lexer.NextToken(); Expect(20); Expr( -#line 1458 "cs.ATG" +#line 1496 "cs.ATG" out expr); Expect(21); EmbeddedStatement( -#line 1459 "cs.ATG" +#line 1497 "cs.ATG" out embeddedStatement); -#line 1459 "cs.ATG" +#line 1497 "cs.ATG" statement = new LockStatement(expr, embeddedStatement); - } else if (la.kind == 120) { + } else if (la.kind == 121) { -#line 1461 "cs.ATG" +#line 1499 "cs.ATG" Statement resourceAcquisitionStmt = null; lexer.NextToken(); Expect(20); ResourceAcquisition( -#line 1463 "cs.ATG" +#line 1501 "cs.ATG" out resourceAcquisitionStmt); Expect(21); EmbeddedStatement( -#line 1464 "cs.ATG" +#line 1502 "cs.ATG" out embeddedStatement); -#line 1464 "cs.ATG" +#line 1502 "cs.ATG" statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); - } else if (la.kind == 118) { + } else if (la.kind == 119) { lexer.NextToken(); Block( -#line 1466 "cs.ATG" +#line 1504 "cs.ATG" out embeddedStatement); -#line 1466 "cs.ATG" +#line 1504 "cs.ATG" statement = new UnsafeStatement(embeddedStatement); - } else if (la.kind == 73) { + } else if (la.kind == 74) { lexer.NextToken(); Expect(20); Type( -#line 1469 "cs.ATG" +#line 1507 "cs.ATG" out type); -#line 1469 "cs.ATG" +#line 1507 "cs.ATG" if (type.PointerNestingLevel == 0) Error("can only fix pointer types"); List pointerDeclarators = new List(1); - Expect(1); + Identifier(); -#line 1472 "cs.ATG" +#line 1510 "cs.ATG" string identifier = t.val; Expect(3); Expr( -#line 1473 "cs.ATG" +#line 1511 "cs.ATG" out expr); -#line 1473 "cs.ATG" +#line 1511 "cs.ATG" pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); while (la.kind == 14) { lexer.NextToken(); - Expect(1); + Identifier(); -#line 1475 "cs.ATG" +#line 1513 "cs.ATG" identifier = t.val; Expect(3); Expr( -#line 1476 "cs.ATG" +#line 1514 "cs.ATG" out expr); -#line 1476 "cs.ATG" +#line 1514 "cs.ATG" pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); } Expect(21); EmbeddedStatement( -#line 1478 "cs.ATG" +#line 1516 "cs.ATG" out embeddedStatement); -#line 1478 "cs.ATG" +#line 1516 "cs.ATG" statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); - } else SynErr(172); + } else SynErr(190); } void SwitchSections( -#line 1500 "cs.ATG" +#line 1538 "cs.ATG" List switchSections) { -#line 1502 "cs.ATG" +#line 1540 "cs.ATG" SwitchSection switchSection = new SwitchSection(); CaseLabel label; SwitchLabel( -#line 1506 "cs.ATG" +#line 1544 "cs.ATG" out label); -#line 1506 "cs.ATG" +#line 1544 "cs.ATG" if (label != null) { switchSection.SwitchLabels.Add(label); } -#line 1507 "cs.ATG" +#line 1545 "cs.ATG" compilationUnit.BlockStart(switchSection); - while (StartOf(25)) { - if (la.kind == 54 || la.kind == 62) { + while (StartOf(29)) { + if (la.kind == 55 || la.kind == 63) { SwitchLabel( -#line 1509 "cs.ATG" +#line 1547 "cs.ATG" out label); -#line 1510 "cs.ATG" +#line 1548 "cs.ATG" if (label != null) { if (switchSection.Children.Count > 0) { // open new section @@ -3727,346 +3846,346 @@ out label); } } -#line 1522 "cs.ATG" +#line 1560 "cs.ATG" compilationUnit.BlockEnd(); switchSections.Add(switchSection); } void ForInitializer( -#line 1481 "cs.ATG" +#line 1519 "cs.ATG" out List initializer) { -#line 1483 "cs.ATG" +#line 1521 "cs.ATG" Statement stmt; initializer = new List(); if ( -#line 1487 "cs.ATG" +#line 1525 "cs.ATG" IsLocalVarDecl()) { LocalVariableDecl( -#line 1487 "cs.ATG" +#line 1525 "cs.ATG" out stmt); -#line 1487 "cs.ATG" +#line 1525 "cs.ATG" initializer.Add(stmt); - } else if (StartOf(5)) { + } else if (StartOf(6)) { StatementExpr( -#line 1488 "cs.ATG" +#line 1526 "cs.ATG" out stmt); -#line 1488 "cs.ATG" +#line 1526 "cs.ATG" initializer.Add(stmt); while (la.kind == 14) { lexer.NextToken(); StatementExpr( -#line 1488 "cs.ATG" +#line 1526 "cs.ATG" out stmt); -#line 1488 "cs.ATG" +#line 1526 "cs.ATG" initializer.Add(stmt); } - } else SynErr(173); + } else SynErr(191); } void ForIterator( -#line 1491 "cs.ATG" +#line 1529 "cs.ATG" out List iterator) { -#line 1493 "cs.ATG" +#line 1531 "cs.ATG" Statement stmt; iterator = new List(); StatementExpr( -#line 1497 "cs.ATG" +#line 1535 "cs.ATG" out stmt); -#line 1497 "cs.ATG" +#line 1535 "cs.ATG" iterator.Add(stmt); while (la.kind == 14) { lexer.NextToken(); StatementExpr( -#line 1497 "cs.ATG" +#line 1535 "cs.ATG" out stmt); -#line 1497 "cs.ATG" +#line 1535 "cs.ATG" iterator.Add(stmt); } } void GotoStatement( -#line 1575 "cs.ATG" +#line 1613 "cs.ATG" out Statement stmt) { -#line 1576 "cs.ATG" +#line 1614 "cs.ATG" Expression expr; stmt = null; - Expect(77); - if (la.kind == 1) { - lexer.NextToken(); + Expect(78); + if (StartOf(17)) { + Identifier(); -#line 1580 "cs.ATG" +#line 1618 "cs.ATG" stmt = new GotoStatement(t.val); Expect(11); - } else if (la.kind == 54) { + } else if (la.kind == 55) { lexer.NextToken(); Expr( -#line 1581 "cs.ATG" +#line 1619 "cs.ATG" out expr); Expect(11); -#line 1581 "cs.ATG" +#line 1619 "cs.ATG" stmt = new GotoCaseStatement(expr); - } else if (la.kind == 62) { + } else if (la.kind == 63) { lexer.NextToken(); Expect(11); -#line 1582 "cs.ATG" +#line 1620 "cs.ATG" stmt = new GotoCaseStatement(null); - } else SynErr(174); + } else SynErr(192); } void StatementExpr( -#line 1602 "cs.ATG" +#line 1640 "cs.ATG" out Statement stmt) { -#line 1603 "cs.ATG" +#line 1641 "cs.ATG" Expression expr; Expr( -#line 1605 "cs.ATG" +#line 1643 "cs.ATG" out expr); -#line 1608 "cs.ATG" +#line 1646 "cs.ATG" stmt = new ExpressionStatement(expr); } void TryStatement( -#line 1532 "cs.ATG" +#line 1570 "cs.ATG" out Statement tryStatement) { -#line 1534 "cs.ATG" +#line 1572 "cs.ATG" Statement blockStmt = null, finallyStmt = null; List catchClauses = null; - Expect(113); + Expect(114); Block( -#line 1538 "cs.ATG" +#line 1576 "cs.ATG" out blockStmt); - if (la.kind == 55) { + if (la.kind == 56) { CatchClauses( -#line 1540 "cs.ATG" +#line 1578 "cs.ATG" out catchClauses); - if (la.kind == 72) { + if (la.kind == 73) { lexer.NextToken(); Block( -#line 1540 "cs.ATG" +#line 1578 "cs.ATG" out finallyStmt); } - } else if (la.kind == 72) { + } else if (la.kind == 73) { lexer.NextToken(); Block( -#line 1541 "cs.ATG" +#line 1579 "cs.ATG" out finallyStmt); - } else SynErr(175); + } else SynErr(193); -#line 1544 "cs.ATG" +#line 1582 "cs.ATG" tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); } void ResourceAcquisition( -#line 1586 "cs.ATG" +#line 1624 "cs.ATG" out Statement stmt) { -#line 1588 "cs.ATG" +#line 1626 "cs.ATG" stmt = null; Expression expr; if ( -#line 1593 "cs.ATG" +#line 1631 "cs.ATG" IsLocalVarDecl()) { LocalVariableDecl( -#line 1593 "cs.ATG" +#line 1631 "cs.ATG" out stmt); - } else if (StartOf(5)) { + } else if (StartOf(6)) { Expr( -#line 1594 "cs.ATG" +#line 1632 "cs.ATG" out expr); -#line 1598 "cs.ATG" +#line 1636 "cs.ATG" stmt = new ExpressionStatement(expr); - } else SynErr(176); + } else SynErr(194); } void SwitchLabel( -#line 1525 "cs.ATG" +#line 1563 "cs.ATG" out CaseLabel label) { -#line 1526 "cs.ATG" +#line 1564 "cs.ATG" Expression expr = null; label = null; - if (la.kind == 54) { + if (la.kind == 55) { lexer.NextToken(); Expr( -#line 1528 "cs.ATG" +#line 1566 "cs.ATG" out expr); Expect(9); -#line 1528 "cs.ATG" +#line 1566 "cs.ATG" label = new CaseLabel(expr); - } else if (la.kind == 62) { + } else if (la.kind == 63) { lexer.NextToken(); Expect(9); -#line 1529 "cs.ATG" +#line 1567 "cs.ATG" label = new CaseLabel(); - } else SynErr(177); + } else SynErr(195); } void CatchClauses( -#line 1549 "cs.ATG" +#line 1587 "cs.ATG" out List catchClauses) { -#line 1551 "cs.ATG" +#line 1589 "cs.ATG" catchClauses = new List(); - Expect(55); + Expect(56); -#line 1554 "cs.ATG" +#line 1592 "cs.ATG" string identifier; Statement stmt; TypeReference typeRef; if (la.kind == 16) { Block( -#line 1560 "cs.ATG" +#line 1598 "cs.ATG" out stmt); -#line 1560 "cs.ATG" +#line 1598 "cs.ATG" catchClauses.Add(new CatchClause(stmt)); } else if (la.kind == 20) { lexer.NextToken(); ClassType( -#line 1562 "cs.ATG" +#line 1600 "cs.ATG" out typeRef, false); -#line 1562 "cs.ATG" +#line 1600 "cs.ATG" identifier = null; - if (la.kind == 1) { - lexer.NextToken(); + if (StartOf(17)) { + Identifier(); -#line 1563 "cs.ATG" +#line 1601 "cs.ATG" identifier = t.val; } Expect(21); Block( -#line 1564 "cs.ATG" +#line 1602 "cs.ATG" out stmt); -#line 1565 "cs.ATG" +#line 1603 "cs.ATG" catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); while ( -#line 1566 "cs.ATG" +#line 1604 "cs.ATG" IsTypedCatch()) { - Expect(55); + Expect(56); Expect(20); ClassType( -#line 1566 "cs.ATG" +#line 1604 "cs.ATG" out typeRef, false); -#line 1566 "cs.ATG" +#line 1604 "cs.ATG" identifier = null; - if (la.kind == 1) { - lexer.NextToken(); + if (StartOf(17)) { + Identifier(); -#line 1567 "cs.ATG" +#line 1605 "cs.ATG" identifier = t.val; } Expect(21); Block( -#line 1568 "cs.ATG" +#line 1606 "cs.ATG" out stmt); -#line 1569 "cs.ATG" +#line 1607 "cs.ATG" catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); } - if (la.kind == 55) { + if (la.kind == 56) { lexer.NextToken(); Block( -#line 1571 "cs.ATG" +#line 1609 "cs.ATG" out stmt); -#line 1571 "cs.ATG" +#line 1609 "cs.ATG" catchClauses.Add(new CatchClause(stmt)); } - } else SynErr(178); + } else SynErr(196); } void UnaryExpr( -#line 1629 "cs.ATG" +#line 1667 "cs.ATG" out Expression uExpr) { -#line 1631 "cs.ATG" +#line 1669 "cs.ATG" TypeReference type = null; Expression expr; ArrayList expressions = new ArrayList(); uExpr = null; - while (StartOf(26) || -#line 1653 "cs.ATG" + while (StartOf(30) || +#line 1691 "cs.ATG" IsTypeCast()) { if (la.kind == 4) { lexer.NextToken(); -#line 1640 "cs.ATG" +#line 1678 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); } else if (la.kind == 5) { lexer.NextToken(); -#line 1641 "cs.ATG" +#line 1679 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); } else if (la.kind == 24) { lexer.NextToken(); -#line 1642 "cs.ATG" +#line 1680 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); } else if (la.kind == 27) { lexer.NextToken(); -#line 1643 "cs.ATG" +#line 1681 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); } else if (la.kind == 6) { lexer.NextToken(); -#line 1644 "cs.ATG" +#line 1682 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Star)); } else if (la.kind == 31) { lexer.NextToken(); -#line 1645 "cs.ATG" +#line 1683 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); } else if (la.kind == 32) { lexer.NextToken(); -#line 1646 "cs.ATG" +#line 1684 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); } else if (la.kind == 28) { lexer.NextToken(); -#line 1647 "cs.ATG" +#line 1685 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitWiseAnd)); } else { Expect(20); Type( -#line 1653 "cs.ATG" +#line 1691 "cs.ATG" out type); Expect(21); -#line 1653 "cs.ATG" +#line 1691 "cs.ATG" expressions.Add(new CastExpression(type)); } } PrimaryExpr( -#line 1657 "cs.ATG" +#line 1695 "cs.ATG" out expr); -#line 1657 "cs.ATG" +#line 1695 "cs.ATG" for (int i = 0; i < expressions.Count; ++i) { Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr; if (expressions[i] is CastExpression) { @@ -4084,944 +4203,1153 @@ out expr); } void ConditionalOrExpr( -#line 1827 "cs.ATG" +#line 1967 "cs.ATG" ref Expression outExpr) { -#line 1828 "cs.ATG" +#line 1968 "cs.ATG" Expression expr; ConditionalAndExpr( -#line 1830 "cs.ATG" +#line 1970 "cs.ATG" ref outExpr); while (la.kind == 26) { lexer.NextToken(); UnaryExpr( -#line 1830 "cs.ATG" +#line 1970 "cs.ATG" out expr); ConditionalAndExpr( -#line 1830 "cs.ATG" +#line 1970 "cs.ATG" ref expr); -#line 1830 "cs.ATG" +#line 1970 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); } } void PrimaryExpr( -#line 1674 "cs.ATG" +#line 1712 "cs.ATG" out Expression pexpr) { -#line 1676 "cs.ATG" +#line 1714 "cs.ATG" TypeReference type = null; List typeList = null; - bool isArrayCreation = false; Expression expr; pexpr = null; - if (la.kind == 112) { + if (la.kind == 113) { lexer.NextToken(); -#line 1684 "cs.ATG" +#line 1721 "cs.ATG" pexpr = new PrimitiveExpression(true, "true"); - } else if (la.kind == 71) { + } else if (la.kind == 72) { lexer.NextToken(); -#line 1685 "cs.ATG" +#line 1722 "cs.ATG" pexpr = new PrimitiveExpression(false, "false"); - } else if (la.kind == 89) { + } else if (la.kind == 90) { lexer.NextToken(); -#line 1686 "cs.ATG" +#line 1723 "cs.ATG" pexpr = new PrimitiveExpression(null, "null"); } else if (la.kind == 2) { lexer.NextToken(); -#line 1687 "cs.ATG" +#line 1724 "cs.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); } else if ( -#line 1688 "cs.ATG" -la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) { - Expect(1); - -#line 1689 "cs.ATG" - type = new TypeReference(t.val); +#line 1725 "cs.ATG" +StartOfQueryExpression()) { + QueryExpression( +#line 1726 "cs.ATG" +out pexpr); + } else if ( +#line 1727 "cs.ATG" +IdentAndDoubleColon()) { + Identifier(); + +#line 1728 "cs.ATG" + type = new TypeReference(t.val); Expect(10); -#line 1690 "cs.ATG" +#line 1729 "cs.ATG" pexpr = new TypeReferenceExpression(type); - Expect(1); + Identifier(); -#line 1691 "cs.ATG" +#line 1730 "cs.ATG" if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); - } else if (la.kind == 1) { - lexer.NextToken(); + } else if (StartOf(17)) { + Identifier(); -#line 1693 "cs.ATG" +#line 1733 "cs.ATG" pexpr = new IdentifierExpression(t.val); + +#line 1734 "cs.ATG" + pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; + if (la.kind == 48) { + ShortedLambdaExpression( +#line 1736 "cs.ATG" +(IdentifierExpression)pexpr, out pexpr); + } + } else if ( +#line 1737 "cs.ATG" +IsLambdaExpression()) { + LambdaExpression( +#line 1738 "cs.ATG" +out pexpr); } else if (la.kind == 20) { lexer.NextToken(); Expr( -#line 1695 "cs.ATG" +#line 1740 "cs.ATG" out expr); Expect(21); -#line 1695 "cs.ATG" +#line 1740 "cs.ATG" pexpr = new ParenthesizedExpression(expr); - } else if (StartOf(27)) { + } else if (StartOf(31)) { -#line 1697 "cs.ATG" +#line 1742 "cs.ATG" string val = null; switch (la.kind) { - case 51: { + case 52: { lexer.NextToken(); -#line 1699 "cs.ATG" +#line 1744 "cs.ATG" val = "bool"; break; } - case 53: { + case 54: { lexer.NextToken(); -#line 1700 "cs.ATG" +#line 1745 "cs.ATG" val = "byte"; break; } - case 56: { + case 57: { lexer.NextToken(); -#line 1701 "cs.ATG" +#line 1746 "cs.ATG" val = "char"; break; } - case 61: { + case 62: { lexer.NextToken(); -#line 1702 "cs.ATG" +#line 1747 "cs.ATG" val = "decimal"; break; } - case 65: { + case 66: { lexer.NextToken(); -#line 1703 "cs.ATG" +#line 1748 "cs.ATG" val = "double"; break; } - case 74: { + case 75: { lexer.NextToken(); -#line 1704 "cs.ATG" +#line 1749 "cs.ATG" val = "float"; break; } - case 81: { + case 82: { lexer.NextToken(); -#line 1705 "cs.ATG" +#line 1750 "cs.ATG" val = "int"; break; } - case 86: { + case 87: { lexer.NextToken(); -#line 1706 "cs.ATG" +#line 1751 "cs.ATG" val = "long"; break; } - case 90: { + case 91: { lexer.NextToken(); -#line 1707 "cs.ATG" +#line 1752 "cs.ATG" val = "object"; break; } - case 101: { + case 102: { lexer.NextToken(); -#line 1708 "cs.ATG" +#line 1753 "cs.ATG" val = "sbyte"; break; } - case 103: { + case 104: { lexer.NextToken(); -#line 1709 "cs.ATG" +#line 1754 "cs.ATG" val = "short"; break; } - case 107: { + case 108: { lexer.NextToken(); -#line 1710 "cs.ATG" +#line 1755 "cs.ATG" val = "string"; break; } - case 115: { + case 116: { lexer.NextToken(); -#line 1711 "cs.ATG" +#line 1756 "cs.ATG" val = "uint"; break; } - case 116: { + case 117: { lexer.NextToken(); -#line 1712 "cs.ATG" +#line 1757 "cs.ATG" val = "ulong"; break; } - case 119: { + case 120: { lexer.NextToken(); -#line 1713 "cs.ATG" +#line 1758 "cs.ATG" val = "ushort"; break; } } -#line 1714 "cs.ATG" +#line 1759 "cs.ATG" t.val = ""; Expect(15); - Expect(1); + Identifier(); -#line 1714 "cs.ATG" +#line 1759 "cs.ATG" pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); - } else if (la.kind == 110) { + } else if (la.kind == 111) { lexer.NextToken(); -#line 1716 "cs.ATG" +#line 1761 "cs.ATG" pexpr = new ThisReferenceExpression(); - } else if (la.kind == 50) { + } else if (la.kind == 51) { lexer.NextToken(); -#line 1718 "cs.ATG" +#line 1763 "cs.ATG" Expression retExpr = new BaseReferenceExpression(); if (la.kind == 15) { lexer.NextToken(); - Expect(1); + Identifier(); -#line 1720 "cs.ATG" +#line 1765 "cs.ATG" retExpr = new FieldReferenceExpression(retExpr, t.val); } else if (la.kind == 18) { lexer.NextToken(); Expr( -#line 1721 "cs.ATG" +#line 1766 "cs.ATG" out expr); -#line 1721 "cs.ATG" +#line 1766 "cs.ATG" List indices = new List(); if (expr != null) { indices.Add(expr); } while (la.kind == 14) { lexer.NextToken(); Expr( -#line 1722 "cs.ATG" +#line 1767 "cs.ATG" out expr); -#line 1722 "cs.ATG" +#line 1767 "cs.ATG" if (expr != null) { indices.Add(expr); } } Expect(19); -#line 1723 "cs.ATG" +#line 1768 "cs.ATG" retExpr = new IndexerExpression(retExpr, indices); - } else SynErr(179); + } else SynErr(197); -#line 1724 "cs.ATG" +#line 1769 "cs.ATG" pexpr = retExpr; - } else if (la.kind == 88) { - lexer.NextToken(); - NonArrayType( -#line 1725 "cs.ATG" -out type); - -#line 1726 "cs.ATG" - List parameters = new List(); - if (la.kind == 20) { - lexer.NextToken(); - -#line 1731 "cs.ATG" - ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); - if (StartOf(21)) { - Argument( -#line 1732 "cs.ATG" -out expr); - -#line 1732 "cs.ATG" - if (expr != null) { parameters.Add(expr); } - while (la.kind == 14) { - lexer.NextToken(); - Argument( -#line 1733 "cs.ATG" -out expr); - -#line 1733 "cs.ATG" - if (expr != null) { parameters.Add(expr); } - } - } - Expect(21); - -#line 1735 "cs.ATG" - pexpr = oce; - } else if (la.kind == 18) { - lexer.NextToken(); - -#line 1737 "cs.ATG" - isArrayCreation = true; ArrayCreateExpression ace = new ArrayCreateExpression(type); pexpr = ace; - -#line 1738 "cs.ATG" - int dims = 0; List ranks = new List(); - if (la.kind == 14 || la.kind == 19) { - while (la.kind == 14) { - lexer.NextToken(); - -#line 1740 "cs.ATG" - dims += 1; - } - Expect(19); - -#line 1741 "cs.ATG" - ranks.Add(dims); dims = 0; - while (la.kind == 18) { - lexer.NextToken(); - while (la.kind == 14) { - lexer.NextToken(); - -#line 1742 "cs.ATG" - ++dims; - } - Expect(19); - -#line 1742 "cs.ATG" - ranks.Add(dims); dims = 0; - } - -#line 1743 "cs.ATG" - ace.CreateType.RankSpecifier = ranks.ToArray(); - ArrayInitializer( -#line 1744 "cs.ATG" -out expr); - -#line 1744 "cs.ATG" - ace.ArrayInitializer = (ArrayInitializerExpression)expr; - } else if (StartOf(5)) { - Expr( -#line 1745 "cs.ATG" -out expr); - -#line 1745 "cs.ATG" - if (expr != null) parameters.Add(expr); - while (la.kind == 14) { - lexer.NextToken(); - -#line 1746 "cs.ATG" - dims += 1; - Expr( -#line 1747 "cs.ATG" -out expr); - -#line 1747 "cs.ATG" - if (expr != null) parameters.Add(expr); - } - Expect(19); - -#line 1749 "cs.ATG" - ranks.Add(dims); ace.Arguments = parameters; dims = 0; - while (la.kind == 18) { - lexer.NextToken(); - while (la.kind == 14) { - lexer.NextToken(); - -#line 1750 "cs.ATG" - ++dims; - } - Expect(19); - -#line 1750 "cs.ATG" - ranks.Add(dims); dims = 0; - } - -#line 1751 "cs.ATG" - ace.CreateType.RankSpecifier = ranks.ToArray(); - if (la.kind == 16) { - ArrayInitializer( -#line 1752 "cs.ATG" + } else if (la.kind == 89) { + NewExpression( +#line 1772 "cs.ATG" out expr); -#line 1752 "cs.ATG" - ace.ArrayInitializer = (ArrayInitializerExpression)expr; - } - } else SynErr(180); - } else SynErr(181); - } else if (la.kind == 114) { +#line 1772 "cs.ATG" + pexpr = expr; + } else if (la.kind == 115) { lexer.NextToken(); Expect(20); if ( -#line 1757 "cs.ATG" +#line 1776 "cs.ATG" NotVoidPointer()) { - Expect(122); + Expect(123); -#line 1757 "cs.ATG" +#line 1776 "cs.ATG" type = new TypeReference("void"); - } else if (StartOf(9)) { + } else if (StartOf(10)) { TypeWithRestriction( -#line 1758 "cs.ATG" +#line 1777 "cs.ATG" out type, true, true); - } else SynErr(182); + } else SynErr(198); Expect(21); -#line 1759 "cs.ATG" +#line 1778 "cs.ATG" pexpr = new TypeOfExpression(type); - } else if (la.kind == 62) { + } else if (la.kind == 63) { lexer.NextToken(); Expect(20); Type( -#line 1761 "cs.ATG" +#line 1780 "cs.ATG" out type); Expect(21); -#line 1761 "cs.ATG" +#line 1780 "cs.ATG" pexpr = new DefaultValueExpression(type); - } else if (la.kind == 104) { + } else if (la.kind == 105) { lexer.NextToken(); Expect(20); Type( -#line 1762 "cs.ATG" +#line 1781 "cs.ATG" out type); Expect(21); -#line 1762 "cs.ATG" +#line 1781 "cs.ATG" pexpr = new SizeOfExpression(type); - } else if (la.kind == 57) { + } else if (la.kind == 58) { lexer.NextToken(); Expect(20); Expr( -#line 1763 "cs.ATG" +#line 1782 "cs.ATG" out expr); Expect(21); -#line 1763 "cs.ATG" +#line 1782 "cs.ATG" pexpr = new CheckedExpression(expr); - } else if (la.kind == 117) { + } else if (la.kind == 118) { lexer.NextToken(); Expect(20); Expr( -#line 1764 "cs.ATG" +#line 1783 "cs.ATG" out expr); Expect(21); -#line 1764 "cs.ATG" +#line 1783 "cs.ATG" pexpr = new UncheckedExpression(expr); - } else if (la.kind == 63) { + } else if (la.kind == 64) { lexer.NextToken(); AnonymousMethodExpr( -#line 1765 "cs.ATG" +#line 1784 "cs.ATG" out expr); -#line 1765 "cs.ATG" +#line 1784 "cs.ATG" pexpr = expr; - } else SynErr(183); - while (StartOf(28) || -#line 1776 "cs.ATG" + } else SynErr(199); + while (StartOf(32) || +#line 1795 "cs.ATG" IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr) || -#line 1785 "cs.ATG" +#line 1804 "cs.ATG" IsGenericFollowedBy(Tokens.OpenParenthesis)) { if (la.kind == 31 || la.kind == 32) { if (la.kind == 31) { lexer.NextToken(); -#line 1769 "cs.ATG" +#line 1788 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); } else if (la.kind == 32) { lexer.NextToken(); -#line 1770 "cs.ATG" +#line 1789 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); - } else SynErr(184); + } else SynErr(200); } else if (la.kind == 47) { lexer.NextToken(); - Expect(1); + Identifier(); -#line 1773 "cs.ATG" +#line 1792 "cs.ATG" pexpr = new PointerReferenceExpression(pexpr, t.val); } else if (la.kind == 15) { lexer.NextToken(); - Expect(1); + Identifier(); -#line 1774 "cs.ATG" +#line 1793 "cs.ATG" pexpr = new FieldReferenceExpression(pexpr, t.val); } else if ( -#line 1776 "cs.ATG" +#line 1795 "cs.ATG" IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr)) { TypeArgumentList( -#line 1777 "cs.ATG" +#line 1796 "cs.ATG" out typeList, false); Expect(15); - Expect(1); + Identifier(); -#line 1779 "cs.ATG" +#line 1798 "cs.ATG" pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeList), t.val); } else if (la.kind == 20) { lexer.NextToken(); -#line 1781 "cs.ATG" +#line 1800 "cs.ATG" List parameters = new List(); - if (StartOf(21)) { + if (StartOf(24)) { Argument( -#line 1782 "cs.ATG" +#line 1801 "cs.ATG" out expr); -#line 1782 "cs.ATG" +#line 1801 "cs.ATG" if (expr != null) {parameters.Add(expr);} while (la.kind == 14) { lexer.NextToken(); Argument( -#line 1783 "cs.ATG" +#line 1802 "cs.ATG" out expr); -#line 1783 "cs.ATG" +#line 1802 "cs.ATG" if (expr != null) {parameters.Add(expr);} } } Expect(21); -#line 1784 "cs.ATG" +#line 1803 "cs.ATG" pexpr = new InvocationExpression(pexpr, parameters); } else if ( -#line 1785 "cs.ATG" +#line 1804 "cs.ATG" IsGenericFollowedBy(Tokens.OpenParenthesis)) { TypeArgumentList( -#line 1785 "cs.ATG" +#line 1804 "cs.ATG" out typeList, false); Expect(20); -#line 1786 "cs.ATG" +#line 1805 "cs.ATG" List parameters = new List(); - if (StartOf(21)) { + if (StartOf(24)) { Argument( -#line 1787 "cs.ATG" +#line 1806 "cs.ATG" out expr); -#line 1787 "cs.ATG" +#line 1806 "cs.ATG" if (expr != null) {parameters.Add(expr);} while (la.kind == 14) { lexer.NextToken(); Argument( -#line 1788 "cs.ATG" +#line 1807 "cs.ATG" out expr); -#line 1788 "cs.ATG" +#line 1807 "cs.ATG" if (expr != null) {parameters.Add(expr);} } } Expect(21); -#line 1789 "cs.ATG" +#line 1808 "cs.ATG" pexpr = new InvocationExpression(pexpr, parameters, typeList); } else { -#line 1791 "cs.ATG" - if (isArrayCreation) Error("element access not allow on array creation"); +#line 1811 "cs.ATG" List indices = new List(); lexer.NextToken(); Expr( -#line 1794 "cs.ATG" +#line 1813 "cs.ATG" out expr); -#line 1794 "cs.ATG" - if (expr != null) { indices.Add(expr); } - while (la.kind == 14) { - lexer.NextToken(); - Expr( -#line 1795 "cs.ATG" +#line 1813 "cs.ATG" + if (expr != null) { indices.Add(expr); } + while (la.kind == 14) { + lexer.NextToken(); + Expr( +#line 1814 "cs.ATG" +out expr); + +#line 1814 "cs.ATG" + if (expr != null) { indices.Add(expr); } + } + Expect(19); + +#line 1815 "cs.ATG" + pexpr = new IndexerExpression(pexpr, indices); + } + } + } + + void QueryExpression( +#line 2203 "cs.ATG" +out Expression outExpr) { + +#line 2204 "cs.ATG" + QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location; + QueryExpressionFromClause fromClause; + + QueryExpressionFromClause( +#line 2208 "cs.ATG" +out fromClause); + +#line 2208 "cs.ATG" + q.FromClause = fromClause; + QueryExpressionBody( +#line 2209 "cs.ATG" +q); + +#line 2210 "cs.ATG" + q.EndLocation = t.EndLocation; + } + + void ShortedLambdaExpression( +#line 1892 "cs.ATG" +IdentifierExpression ident, out Expression pexpr) { + +#line 1893 "cs.ATG" + LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; + Expect(48); + +#line 1898 "cs.ATG" + lambda.StartLocation = ident.StartLocation; + lambda.Parameters.Add(new ParameterDeclarationExpression(null, ident.Identifier)); + lambda.Parameters[0].StartLocation = ident.StartLocation; + lambda.Parameters[0].EndLocation = ident.EndLocation; + + LambdaExpressionBody( +#line 1903 "cs.ATG" +lambda); + } + + void LambdaExpression( +#line 1872 "cs.ATG" +out Expression outExpr) { + +#line 1874 "cs.ATG" + LambdaExpression lambda = new LambdaExpression(); + lambda.StartLocation = la.Location; + ParameterDeclarationExpression p; + outExpr = lambda; + + Expect(20); + if (StartOf(10)) { + LambdaExpressionParameter( +#line 1882 "cs.ATG" +out p); + +#line 1882 "cs.ATG" + if (p != null) lambda.Parameters.Add(p); + while (la.kind == 14) { + lexer.NextToken(); + LambdaExpressionParameter( +#line 1884 "cs.ATG" +out p); + +#line 1884 "cs.ATG" + if (p != null) lambda.Parameters.Add(p); + } + } + Expect(21); + Expect(48); + LambdaExpressionBody( +#line 1889 "cs.ATG" +lambda); + } + + void NewExpression( +#line 1819 "cs.ATG" +out Expression pexpr) { + +#line 1820 "cs.ATG" + pexpr = null; + List parameters = new List(); + TypeReference type = null; + Expression expr; + + Expect(89); + if (StartOf(10)) { + NonArrayType( +#line 1827 "cs.ATG" +out type); + } + if (la.kind == 16 || la.kind == 20) { + if (la.kind == 20) { + +#line 1833 "cs.ATG" + ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); + lexer.NextToken(); + +#line 1834 "cs.ATG" + if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); + if (StartOf(24)) { + Argument( +#line 1835 "cs.ATG" +out expr); + +#line 1835 "cs.ATG" + if (expr != null) { parameters.Add(expr); } + while (la.kind == 14) { + lexer.NextToken(); + Argument( +#line 1836 "cs.ATG" +out expr); + +#line 1836 "cs.ATG" + if (expr != null) { parameters.Add(expr); } + } + } + Expect(21); + +#line 1838 "cs.ATG" + pexpr = oce; + if (la.kind == 16) { + CollectionOrObjectInitializer( +#line 1839 "cs.ATG" +out expr); + +#line 1839 "cs.ATG" + oce.ObjectInitializer = (CollectionInitializerExpression)expr; + } + } else { + +#line 1840 "cs.ATG" + ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); + CollectionOrObjectInitializer( +#line 1841 "cs.ATG" +out expr); + +#line 1841 "cs.ATG" + oce.ObjectInitializer = (CollectionInitializerExpression)expr; + +#line 1842 "cs.ATG" + pexpr = oce; + } + } else if (la.kind == 18) { + lexer.NextToken(); + +#line 1847 "cs.ATG" + ArrayCreateExpression ace = new ArrayCreateExpression(type); + /* we must not change RankSpecifier on the null type reference*/ + if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); } + pexpr = ace; + int dims = 0; List ranks = new List(); + + if (la.kind == 14 || la.kind == 19) { + while (la.kind == 14) { + lexer.NextToken(); + +#line 1854 "cs.ATG" + dims += 1; + } + Expect(19); + +#line 1855 "cs.ATG" + ranks.Add(dims); dims = 0; + while (la.kind == 18) { + lexer.NextToken(); + while (la.kind == 14) { + lexer.NextToken(); + +#line 1856 "cs.ATG" + ++dims; + } + Expect(19); + +#line 1856 "cs.ATG" + ranks.Add(dims); dims = 0; + } + +#line 1857 "cs.ATG" + ace.CreateType.RankSpecifier = ranks.ToArray(); + CollectionInitializer( +#line 1858 "cs.ATG" +out expr); + +#line 1858 "cs.ATG" + ace.ArrayInitializer = (CollectionInitializerExpression)expr; + } else if (StartOf(6)) { + Expr( +#line 1859 "cs.ATG" +out expr); + +#line 1859 "cs.ATG" + if (expr != null) parameters.Add(expr); + while (la.kind == 14) { + lexer.NextToken(); + +#line 1860 "cs.ATG" + dims += 1; + Expr( +#line 1861 "cs.ATG" +out expr); + +#line 1861 "cs.ATG" + if (expr != null) parameters.Add(expr); + } + Expect(19); + +#line 1863 "cs.ATG" + ranks.Add(dims); ace.Arguments = parameters; dims = 0; + while (la.kind == 18) { + lexer.NextToken(); + while (la.kind == 14) { + lexer.NextToken(); + +#line 1864 "cs.ATG" + ++dims; + } + Expect(19); + +#line 1864 "cs.ATG" + ranks.Add(dims); dims = 0; + } + +#line 1865 "cs.ATG" + ace.CreateType.RankSpecifier = ranks.ToArray(); + if (la.kind == 16) { + CollectionInitializer( +#line 1866 "cs.ATG" out expr); -#line 1795 "cs.ATG" - if (expr != null) { indices.Add(expr); } +#line 1866 "cs.ATG" + ace.ArrayInitializer = (CollectionInitializerExpression)expr; } - Expect(19); - -#line 1796 "cs.ATG" - pexpr = new IndexerExpression(pexpr, indices); - } - } + } else SynErr(201); + } else SynErr(202); } void AnonymousMethodExpr( -#line 1800 "cs.ATG" +#line 1934 "cs.ATG" out Expression outExpr) { -#line 1802 "cs.ATG" +#line 1936 "cs.ATG" AnonymousMethodExpression expr = new AnonymousMethodExpression(); expr.StartLocation = t.Location; - Statement stmt; + BlockStatement stmt; List p = new List(); outExpr = expr; if (la.kind == 20) { lexer.NextToken(); - if (StartOf(10)) { + if (StartOf(11)) { FormalParameterList( -#line 1811 "cs.ATG" +#line 1945 "cs.ATG" p); -#line 1811 "cs.ATG" +#line 1945 "cs.ATG" expr.Parameters = p; } Expect(21); -#line 1813 "cs.ATG" +#line 1947 "cs.ATG" expr.HasParameterList = true; } - -#line 1817 "cs.ATG" - if (compilationUnit != null) { - Block( -#line 1818 "cs.ATG" + BlockInsideExpression( +#line 1949 "cs.ATG" out stmt); -#line 1818 "cs.ATG" - expr.Body = (BlockStatement)stmt; +#line 1949 "cs.ATG" + expr.Body = stmt; -#line 1819 "cs.ATG" - } else { - Expect(16); - -#line 1821 "cs.ATG" - lexer.SkipCurrentBlock(0); - Expect(17); - -#line 1823 "cs.ATG" - } - -#line 1824 "cs.ATG" +#line 1950 "cs.ATG" expr.EndLocation = t.Location; } void TypeArgumentList( -#line 1997 "cs.ATG" +#line 2137 "cs.ATG" out List types, bool canBeUnbound) { -#line 1999 "cs.ATG" +#line 2139 "cs.ATG" types = new List(); TypeReference type = null; Expect(23); if ( -#line 2004 "cs.ATG" +#line 2144 "cs.ATG" canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma)) { -#line 2005 "cs.ATG" +#line 2145 "cs.ATG" types.Add(TypeReference.Null); while (la.kind == 14) { lexer.NextToken(); -#line 2006 "cs.ATG" +#line 2146 "cs.ATG" types.Add(TypeReference.Null); } - } else if (StartOf(9)) { + } else if (StartOf(10)) { Type( -#line 2007 "cs.ATG" +#line 2147 "cs.ATG" out type); -#line 2007 "cs.ATG" +#line 2147 "cs.ATG" if (type != null) { types.Add(type); } while (la.kind == 14) { lexer.NextToken(); Type( -#line 2008 "cs.ATG" +#line 2148 "cs.ATG" out type); -#line 2008 "cs.ATG" +#line 2148 "cs.ATG" if (type != null) { types.Add(type); } } - } else SynErr(185); + } else SynErr(203); Expect(22); } + void LambdaExpressionParameter( +#line 1906 "cs.ATG" +out ParameterDeclarationExpression p) { + +#line 1907 "cs.ATG" + Location start = la.Location; p = null; + TypeReference type; + + if ( +#line 1911 "cs.ATG" +Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis) { + Identifier(); + +#line 1913 "cs.ATG" + p = new ParameterDeclarationExpression(null, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + + } else if (StartOf(10)) { + Type( +#line 1916 "cs.ATG" +out type); + Identifier(); + +#line 1918 "cs.ATG" + p = new ParameterDeclarationExpression(type, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + + } else SynErr(204); + } + + void LambdaExpressionBody( +#line 1924 "cs.ATG" +LambdaExpression lambda) { + +#line 1925 "cs.ATG" + Expression expr; BlockStatement stmt; + if (la.kind == 16) { + BlockInsideExpression( +#line 1928 "cs.ATG" +out stmt); + +#line 1928 "cs.ATG" + lambda.StatementBody = stmt; + } else if (StartOf(6)) { + Expr( +#line 1929 "cs.ATG" +out expr); + +#line 1929 "cs.ATG" + lambda.ExpressionBody = expr; + } else SynErr(205); + +#line 1931 "cs.ATG" + lambda.EndLocation = t.EndLocation; + } + + void BlockInsideExpression( +#line 1953 "cs.ATG" +out BlockStatement outStmt) { + +#line 1954 "cs.ATG" + Statement stmt = null; outStmt = null; + +#line 1958 "cs.ATG" + if (compilationUnit != null) { + Block( +#line 1959 "cs.ATG" +out stmt); + +#line 1959 "cs.ATG" + outStmt = (BlockStatement)stmt; + +#line 1960 "cs.ATG" + } else { + Expect(16); + +#line 1962 "cs.ATG" + lexer.SkipCurrentBlock(0); + Expect(17); + +#line 1964 "cs.ATG" + } + } + void ConditionalAndExpr( -#line 1833 "cs.ATG" +#line 1973 "cs.ATG" ref Expression outExpr) { -#line 1834 "cs.ATG" +#line 1974 "cs.ATG" Expression expr; InclusiveOrExpr( -#line 1836 "cs.ATG" +#line 1976 "cs.ATG" ref outExpr); while (la.kind == 25) { lexer.NextToken(); UnaryExpr( -#line 1836 "cs.ATG" +#line 1976 "cs.ATG" out expr); InclusiveOrExpr( -#line 1836 "cs.ATG" +#line 1976 "cs.ATG" ref expr); -#line 1836 "cs.ATG" +#line 1976 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); } } void InclusiveOrExpr( -#line 1839 "cs.ATG" +#line 1979 "cs.ATG" ref Expression outExpr) { -#line 1840 "cs.ATG" +#line 1980 "cs.ATG" Expression expr; ExclusiveOrExpr( -#line 1842 "cs.ATG" +#line 1982 "cs.ATG" ref outExpr); while (la.kind == 29) { lexer.NextToken(); UnaryExpr( -#line 1842 "cs.ATG" +#line 1982 "cs.ATG" out expr); ExclusiveOrExpr( -#line 1842 "cs.ATG" +#line 1982 "cs.ATG" ref expr); -#line 1842 "cs.ATG" +#line 1982 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); } } void ExclusiveOrExpr( -#line 1845 "cs.ATG" +#line 1985 "cs.ATG" ref Expression outExpr) { -#line 1846 "cs.ATG" +#line 1986 "cs.ATG" Expression expr; AndExpr( -#line 1848 "cs.ATG" +#line 1988 "cs.ATG" ref outExpr); while (la.kind == 30) { lexer.NextToken(); UnaryExpr( -#line 1848 "cs.ATG" +#line 1988 "cs.ATG" out expr); AndExpr( -#line 1848 "cs.ATG" +#line 1988 "cs.ATG" ref expr); -#line 1848 "cs.ATG" +#line 1988 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); } } void AndExpr( -#line 1851 "cs.ATG" +#line 1991 "cs.ATG" ref Expression outExpr) { -#line 1852 "cs.ATG" +#line 1992 "cs.ATG" Expression expr; EqualityExpr( -#line 1854 "cs.ATG" +#line 1994 "cs.ATG" ref outExpr); while (la.kind == 28) { lexer.NextToken(); UnaryExpr( -#line 1854 "cs.ATG" +#line 1994 "cs.ATG" out expr); EqualityExpr( -#line 1854 "cs.ATG" +#line 1994 "cs.ATG" ref expr); -#line 1854 "cs.ATG" +#line 1994 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); } } void EqualityExpr( -#line 1857 "cs.ATG" +#line 1997 "cs.ATG" ref Expression outExpr) { -#line 1859 "cs.ATG" +#line 1999 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; RelationalExpr( -#line 1863 "cs.ATG" +#line 2003 "cs.ATG" ref outExpr); while (la.kind == 33 || la.kind == 34) { if (la.kind == 34) { lexer.NextToken(); -#line 1866 "cs.ATG" +#line 2006 "cs.ATG" op = BinaryOperatorType.InEquality; } else { lexer.NextToken(); -#line 1867 "cs.ATG" +#line 2007 "cs.ATG" op = BinaryOperatorType.Equality; } UnaryExpr( -#line 1869 "cs.ATG" +#line 2009 "cs.ATG" out expr); RelationalExpr( -#line 1869 "cs.ATG" +#line 2009 "cs.ATG" ref expr); -#line 1869 "cs.ATG" +#line 2009 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void RelationalExpr( -#line 1873 "cs.ATG" +#line 2013 "cs.ATG" ref Expression outExpr) { -#line 1875 "cs.ATG" +#line 2015 "cs.ATG" TypeReference type; Expression expr; BinaryOperatorType op = BinaryOperatorType.None; ShiftExpr( -#line 1880 "cs.ATG" +#line 2020 "cs.ATG" ref outExpr); - while (StartOf(29)) { - if (StartOf(30)) { + while (StartOf(33)) { + if (StartOf(34)) { if (la.kind == 23) { lexer.NextToken(); -#line 1882 "cs.ATG" +#line 2022 "cs.ATG" op = BinaryOperatorType.LessThan; } else if (la.kind == 22) { lexer.NextToken(); -#line 1883 "cs.ATG" +#line 2023 "cs.ATG" op = BinaryOperatorType.GreaterThan; } else if (la.kind == 36) { lexer.NextToken(); -#line 1884 "cs.ATG" +#line 2024 "cs.ATG" op = BinaryOperatorType.LessThanOrEqual; } else if (la.kind == 35) { lexer.NextToken(); -#line 1885 "cs.ATG" +#line 2025 "cs.ATG" op = BinaryOperatorType.GreaterThanOrEqual; - } else SynErr(186); + } else SynErr(206); UnaryExpr( -#line 1887 "cs.ATG" +#line 2027 "cs.ATG" out expr); ShiftExpr( -#line 1888 "cs.ATG" +#line 2028 "cs.ATG" ref expr); -#line 1889 "cs.ATG" +#line 2029 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } else { - if (la.kind == 84) { + if (la.kind == 85) { lexer.NextToken(); TypeWithRestriction( -#line 1892 "cs.ATG" +#line 2032 "cs.ATG" out type, false, false); if ( -#line 1893 "cs.ATG" +#line 2033 "cs.ATG" la.kind == Tokens.Question && Tokens.CastFollower[Peek(1).kind] == false) { NullableQuestionMark( -#line 1894 "cs.ATG" +#line 2034 "cs.ATG" ref type); } -#line 1895 "cs.ATG" +#line 2035 "cs.ATG" outExpr = new TypeOfIsExpression(outExpr, type); - } else if (la.kind == 49) { + } else if (la.kind == 50) { lexer.NextToken(); TypeWithRestriction( -#line 1897 "cs.ATG" +#line 2037 "cs.ATG" out type, false, false); if ( -#line 1898 "cs.ATG" +#line 2038 "cs.ATG" la.kind == Tokens.Question && Tokens.CastFollower[Peek(1).kind] == false) { NullableQuestionMark( -#line 1899 "cs.ATG" +#line 2039 "cs.ATG" ref type); } -#line 1900 "cs.ATG" +#line 2040 "cs.ATG" outExpr = new CastExpression(type, outExpr, CastType.TryCast); - } else SynErr(187); + } else SynErr(207); } } } void ShiftExpr( -#line 1905 "cs.ATG" +#line 2045 "cs.ATG" ref Expression outExpr) { -#line 1907 "cs.ATG" +#line 2047 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; AdditiveExpr( -#line 1911 "cs.ATG" +#line 2051 "cs.ATG" ref outExpr); while (la.kind == 37 || -#line 1914 "cs.ATG" +#line 2054 "cs.ATG" IsShiftRight()) { if (la.kind == 37) { lexer.NextToken(); -#line 1913 "cs.ATG" +#line 2053 "cs.ATG" op = BinaryOperatorType.ShiftLeft; } else { Expect(22); Expect(22); -#line 1915 "cs.ATG" +#line 2055 "cs.ATG" op = BinaryOperatorType.ShiftRight; } UnaryExpr( -#line 1918 "cs.ATG" +#line 2058 "cs.ATG" out expr); AdditiveExpr( -#line 1918 "cs.ATG" +#line 2058 "cs.ATG" ref expr); -#line 1918 "cs.ATG" +#line 2058 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void AdditiveExpr( -#line 1922 "cs.ATG" +#line 2062 "cs.ATG" ref Expression outExpr) { -#line 1924 "cs.ATG" +#line 2064 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; MultiplicativeExpr( -#line 1928 "cs.ATG" +#line 2068 "cs.ATG" ref outExpr); while (la.kind == 4 || la.kind == 5) { if (la.kind == 4) { lexer.NextToken(); -#line 1931 "cs.ATG" +#line 2071 "cs.ATG" op = BinaryOperatorType.Add; } else { lexer.NextToken(); -#line 1932 "cs.ATG" +#line 2072 "cs.ATG" op = BinaryOperatorType.Subtract; } UnaryExpr( -#line 1934 "cs.ATG" +#line 2074 "cs.ATG" out expr); MultiplicativeExpr( -#line 1934 "cs.ATG" +#line 2074 "cs.ATG" ref expr); -#line 1934 "cs.ATG" +#line 2074 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void MultiplicativeExpr( -#line 1938 "cs.ATG" +#line 2078 "cs.ATG" ref Expression outExpr) { -#line 1940 "cs.ATG" +#line 2080 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; @@ -5029,59 +5357,309 @@ ref Expression outExpr) { if (la.kind == 6) { lexer.NextToken(); -#line 1946 "cs.ATG" +#line 2086 "cs.ATG" op = BinaryOperatorType.Multiply; } else if (la.kind == 7) { lexer.NextToken(); -#line 1947 "cs.ATG" +#line 2087 "cs.ATG" op = BinaryOperatorType.Divide; } else { lexer.NextToken(); -#line 1948 "cs.ATG" +#line 2088 "cs.ATG" op = BinaryOperatorType.Modulus; } UnaryExpr( -#line 1950 "cs.ATG" +#line 2090 "cs.ATG" out expr); -#line 1950 "cs.ATG" +#line 2090 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void TypeParameterConstraintsClauseBase( -#line 2054 "cs.ATG" +#line 2194 "cs.ATG" out TypeReference type) { -#line 2055 "cs.ATG" +#line 2195 "cs.ATG" TypeReference t; type = null; - if (la.kind == 108) { + if (la.kind == 109) { lexer.NextToken(); -#line 2057 "cs.ATG" +#line 2197 "cs.ATG" type = TypeReference.StructConstraint; - } else if (la.kind == 58) { + } else if (la.kind == 59) { lexer.NextToken(); -#line 2058 "cs.ATG" +#line 2198 "cs.ATG" type = TypeReference.ClassConstraint; - } else if (la.kind == 88) { + } else if (la.kind == 89) { lexer.NextToken(); Expect(20); Expect(21); -#line 2059 "cs.ATG" +#line 2199 "cs.ATG" type = TypeReference.NewConstraint; - } else if (StartOf(9)) { + } else if (StartOf(10)) { Type( -#line 2060 "cs.ATG" +#line 2200 "cs.ATG" out t); -#line 2060 "cs.ATG" +#line 2200 "cs.ATG" type = t; - } else SynErr(188); + } else SynErr(208); + } + + void QueryExpressionFromClause( +#line 2213 "cs.ATG" +out QueryExpressionFromClause fc) { + +#line 2214 "cs.ATG" + fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location; + QueryExpressionFromGenerator fg; + + Expect(137); + QueryExpressionFromGenerator( +#line 2219 "cs.ATG" +out fg); + +#line 2219 "cs.ATG" + SafeAdd(fc, fc.Generators, fg); + while (la.kind == 14) { + lexer.NextToken(); + QueryExpressionFromGenerator( +#line 2221 "cs.ATG" +out fg); + +#line 2221 "cs.ATG" + SafeAdd(fc, fc.Generators, fg); + } + +#line 2223 "cs.ATG" + fc.EndLocation = t.EndLocation; + } + + void QueryExpressionBody( +#line 2235 "cs.ATG" +QueryExpression q) { + +#line 2236 "cs.ATG" + QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause; + QueryExpressionSelectClause selectClause; QueryExpressionGroupClause groupClause; + QueryExpressionIntoClause intoClause; + + while (la.kind == 127 || la.kind == 137) { + if (la.kind == 137) { + QueryExpressionFromClause( +#line 2241 "cs.ATG" +out fromClause); + +#line 2241 "cs.ATG" + SafeAdd(q, q.FromOrWhereClauses, fromClause); + } else { + QueryExpressionWhereClause( +#line 2242 "cs.ATG" +out whereClause); + +#line 2242 "cs.ATG" + SafeAdd(q, q.FromOrWhereClauses, whereClause); + } + } + if (la.kind == 140) { + QueryExpressionOrderByClause( +#line 2244 "cs.ATG" +q); + } + if (la.kind == 133) { + QueryExpressionSelectClause( +#line 2245 "cs.ATG" +out selectClause); + +#line 2245 "cs.ATG" + q.SelectOrGroupClause = selectClause; + } else if (la.kind == 134) { + QueryExpressionGroupClause( +#line 2246 "cs.ATG" +out groupClause); + +#line 2246 "cs.ATG" + q.SelectOrGroupClause = groupClause; + } else SynErr(209); + if (la.kind == 136) { + QueryExpressionIntoClause( +#line 2248 "cs.ATG" +out intoClause); + +#line 2248 "cs.ATG" + q.IntoClause = intoClause; + } + } + + void QueryExpressionFromGenerator( +#line 2226 "cs.ATG" +out QueryExpressionFromGenerator fg) { + +#line 2227 "cs.ATG" + Expression expr; fg = new QueryExpressionFromGenerator(); fg.StartLocation = la.Location; + Identifier(); + +#line 2229 "cs.ATG" + fg.Identifier = t.val; + Expect(81); + Expr( +#line 2231 "cs.ATG" +out expr); + +#line 2231 "cs.ATG" + fg.InExpression = expr; + +#line 2232 "cs.ATG" + fg.EndLocation = t.EndLocation; + } + + void QueryExpressionWhereClause( +#line 2251 "cs.ATG" +out QueryExpressionWhereClause wc) { + +#line 2252 "cs.ATG" + Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location; + Expect(127); + Expr( +#line 2255 "cs.ATG" +out expr); + +#line 2255 "cs.ATG" + wc.Condition = expr; + +#line 2256 "cs.ATG" + wc.EndLocation = t.EndLocation; + } + + void QueryExpressionOrderByClause( +#line 2259 "cs.ATG" +QueryExpression q) { + +#line 2260 "cs.ATG" + QueryExpressionOrdering ordering; + Expect(140); + QueryExpressionOrderingClause( +#line 2263 "cs.ATG" +out ordering); + +#line 2263 "cs.ATG" + SafeAdd(q, q.Orderings, ordering); + while (la.kind == 14) { + lexer.NextToken(); + QueryExpressionOrderingClause( +#line 2265 "cs.ATG" +out ordering); + +#line 2265 "cs.ATG" + SafeAdd(q, q.Orderings, ordering); + } + } + + void QueryExpressionSelectClause( +#line 2279 "cs.ATG" +out QueryExpressionSelectClause sc) { + +#line 2280 "cs.ATG" + Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location; + Expect(133); + Expr( +#line 2283 "cs.ATG" +out expr); + +#line 2283 "cs.ATG" + sc.Projection = expr; + +#line 2284 "cs.ATG" + sc.EndLocation = t.EndLocation; + } + + void QueryExpressionGroupClause( +#line 2287 "cs.ATG" +out QueryExpressionGroupClause gc) { + +#line 2288 "cs.ATG" + Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; + Expect(134); + Expr( +#line 2291 "cs.ATG" +out expr); + +#line 2291 "cs.ATG" + gc.Projection = expr; + Expect(135); + Expr( +#line 2293 "cs.ATG" +out expr); + +#line 2293 "cs.ATG" + gc.GroupBy = expr; + +#line 2294 "cs.ATG" + gc.EndLocation = t.EndLocation; + } + + void QueryExpressionIntoClause( +#line 2297 "cs.ATG" +out QueryExpressionIntoClause ic) { + +#line 2298 "cs.ATG" + ic = new QueryExpressionIntoClause(); ic.StartLocation = la.Location; + Expect(136); + Identifier(); + +#line 2301 "cs.ATG" + ic.IntoIdentifier = t.val; + +#line 2302 "cs.ATG" + ic.ContinuedQuery = new QueryExpression(); + +#line 2303 "cs.ATG" + ic.ContinuedQuery.StartLocation = la.Location; + QueryExpressionBody( +#line 2304 "cs.ATG" +ic.ContinuedQuery); + +#line 2305 "cs.ATG" + ic.ContinuedQuery.EndLocation = t.EndLocation; + +#line 2306 "cs.ATG" + ic.EndLocation = t.EndLocation; + } + + void QueryExpressionOrderingClause( +#line 2269 "cs.ATG" +out QueryExpressionOrdering ordering) { + +#line 2270 "cs.ATG" + Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location; + Expr( +#line 2272 "cs.ATG" +out expr); + +#line 2272 "cs.ATG" + ordering.Criteria = expr; + if (la.kind == 138 || la.kind == 139) { + if (la.kind == 138) { + lexer.NextToken(); + +#line 2273 "cs.ATG" + ordering.Direction = QueryExpressionOrderingDirection.Ascending; + } else { + lexer.NextToken(); + +#line 2274 "cs.ATG" + ordering.Direction = QueryExpressionOrderingDirection.Descending; + } + } + +#line 2276 "cs.ATG" + ordering.EndLocation = t.EndLocation; } @@ -5144,147 +5722,168 @@ out t); case 45: s = "\"^=\" expected"; break; case 46: s = "\"<<=\" expected"; break; case 47: s = "\"->\" expected"; break; - case 48: s = "\"abstract\" expected"; break; - case 49: s = "\"as\" expected"; break; - case 50: s = "\"base\" expected"; break; - case 51: s = "\"bool\" expected"; break; - case 52: s = "\"break\" expected"; break; - case 53: s = "\"byte\" expected"; break; - case 54: s = "\"case\" expected"; break; - case 55: s = "\"catch\" expected"; break; - case 56: s = "\"char\" expected"; break; - case 57: s = "\"checked\" expected"; break; - case 58: s = "\"class\" expected"; break; - case 59: s = "\"const\" expected"; break; - case 60: s = "\"continue\" expected"; break; - case 61: s = "\"decimal\" expected"; break; - case 62: s = "\"default\" expected"; break; - case 63: s = "\"delegate\" expected"; break; - case 64: s = "\"do\" expected"; break; - case 65: s = "\"double\" expected"; break; - case 66: s = "\"else\" expected"; break; - case 67: s = "\"enum\" expected"; break; - case 68: s = "\"event\" expected"; break; - case 69: s = "\"explicit\" expected"; break; - case 70: s = "\"extern\" expected"; break; - case 71: s = "\"false\" expected"; break; - case 72: s = "\"finally\" expected"; break; - case 73: s = "\"fixed\" expected"; break; - case 74: s = "\"float\" expected"; break; - case 75: s = "\"for\" expected"; break; - case 76: s = "\"foreach\" expected"; break; - case 77: s = "\"goto\" expected"; break; - case 78: s = "\"if\" expected"; break; - case 79: s = "\"implicit\" expected"; break; - case 80: s = "\"in\" expected"; break; - case 81: s = "\"int\" expected"; break; - case 82: s = "\"interface\" expected"; break; - case 83: s = "\"internal\" expected"; break; - case 84: s = "\"is\" expected"; break; - case 85: s = "\"lock\" expected"; break; - case 86: s = "\"long\" expected"; break; - case 87: s = "\"namespace\" expected"; break; - case 88: s = "\"new\" expected"; break; - case 89: s = "\"null\" expected"; break; - case 90: s = "\"object\" expected"; break; - case 91: s = "\"operator\" expected"; break; - case 92: s = "\"out\" expected"; break; - case 93: s = "\"override\" expected"; break; - case 94: s = "\"params\" expected"; break; - case 95: s = "\"private\" expected"; break; - case 96: s = "\"protected\" expected"; break; - case 97: s = "\"public\" expected"; break; - case 98: s = "\"readonly\" expected"; break; - case 99: s = "\"ref\" expected"; break; - case 100: s = "\"return\" expected"; break; - case 101: s = "\"sbyte\" expected"; break; - case 102: s = "\"sealed\" expected"; break; - case 103: s = "\"short\" expected"; break; - case 104: s = "\"sizeof\" expected"; break; - case 105: s = "\"stackalloc\" expected"; break; - case 106: s = "\"static\" expected"; break; - case 107: s = "\"string\" expected"; break; - case 108: s = "\"struct\" expected"; break; - case 109: s = "\"switch\" expected"; break; - case 110: s = "\"this\" expected"; break; - case 111: s = "\"throw\" expected"; break; - case 112: s = "\"true\" expected"; break; - case 113: s = "\"try\" expected"; break; - case 114: s = "\"typeof\" expected"; break; - case 115: s = "\"uint\" expected"; break; - case 116: s = "\"ulong\" expected"; break; - case 117: s = "\"unchecked\" expected"; break; - case 118: s = "\"unsafe\" expected"; break; - case 119: s = "\"ushort\" expected"; break; - case 120: s = "\"using\" expected"; break; - case 121: s = "\"virtual\" expected"; break; - case 122: s = "\"void\" expected"; break; - case 123: s = "\"volatile\" expected"; break; - case 124: s = "\"while\" expected"; break; - case 125: s = "??? expected"; break; - case 126: s = "invalid NamespaceMemberDecl"; break; - case 127: s = "invalid NonArrayType"; break; - case 128: s = "invalid AttributeArguments"; break; - case 129: s = "invalid Expr"; break; - case 130: s = "invalid TypeModifier"; break; - case 131: s = "invalid TypeDecl"; break; - case 132: s = "invalid TypeDecl"; break; - case 133: s = "invalid IntegralType"; break; - case 134: s = "invalid FormalParameterList"; break; - case 135: s = "invalid FormalParameterList"; break; - case 136: s = "invalid ClassType"; break; - case 137: s = "invalid ClassMemberDecl"; break; - case 138: s = "invalid ClassMemberDecl"; break; - case 139: s = "invalid StructMemberDecl"; break; - case 140: s = "invalid StructMemberDecl"; break; - case 141: s = "invalid StructMemberDecl"; break; - case 142: s = "invalid StructMemberDecl"; break; - case 143: s = "invalid StructMemberDecl"; break; - case 144: s = "invalid StructMemberDecl"; break; - case 145: s = "invalid StructMemberDecl"; break; - case 146: s = "invalid StructMemberDecl"; break; - case 147: s = "invalid StructMemberDecl"; break; - case 148: s = "invalid StructMemberDecl"; break; - case 149: s = "invalid StructMemberDecl"; break; - case 150: s = "invalid StructMemberDecl"; break; - case 151: s = "invalid StructMemberDecl"; break; - case 152: s = "invalid InterfaceMemberDecl"; break; - case 153: s = "invalid InterfaceMemberDecl"; break; - case 154: s = "invalid InterfaceMemberDecl"; break; - case 155: s = "invalid TypeWithRestriction"; break; - case 156: s = "invalid TypeWithRestriction"; break; - case 157: s = "invalid SimpleType"; break; - case 158: s = "invalid AccessorModifiers"; break; - case 159: s = "invalid EventAccessorDecls"; break; - case 160: s = "invalid ConstructorInitializer"; break; - case 161: s = "invalid OverloadableOperator"; break; - case 162: s = "invalid AccessorDecls"; break; - case 163: s = "invalid InterfaceAccessors"; break; - case 164: s = "invalid InterfaceAccessors"; break; - case 165: s = "invalid GetAccessorDecl"; break; - case 166: s = "invalid SetAccessorDecl"; break; - case 167: s = "invalid VariableInitializer"; break; - case 168: s = "invalid Statement"; break; - case 169: s = "invalid AssignmentOperator"; break; - case 170: s = "invalid EmbeddedStatement"; break; - case 171: s = "invalid EmbeddedStatement"; break; - case 172: s = "invalid EmbeddedStatement"; break; - case 173: s = "invalid ForInitializer"; break; - case 174: s = "invalid GotoStatement"; break; - case 175: s = "invalid TryStatement"; break; - case 176: s = "invalid ResourceAcquisition"; break; - case 177: s = "invalid SwitchLabel"; break; - case 178: s = "invalid CatchClauses"; break; - case 179: s = "invalid PrimaryExpr"; break; - case 180: s = "invalid PrimaryExpr"; break; - case 181: s = "invalid PrimaryExpr"; break; - case 182: s = "invalid PrimaryExpr"; break; - case 183: s = "invalid PrimaryExpr"; break; - case 184: s = "invalid PrimaryExpr"; break; - case 185: s = "invalid TypeArgumentList"; break; - case 186: s = "invalid RelationalExpr"; break; - case 187: s = "invalid RelationalExpr"; break; - case 188: s = "invalid TypeParameterConstraintsClauseBase"; break; + case 48: s = "\"=>\" expected"; break; + case 49: s = "\"abstract\" expected"; break; + case 50: s = "\"as\" expected"; break; + case 51: s = "\"base\" expected"; break; + case 52: s = "\"bool\" expected"; break; + case 53: s = "\"break\" expected"; break; + case 54: s = "\"byte\" expected"; break; + case 55: s = "\"case\" expected"; break; + case 56: s = "\"catch\" expected"; break; + case 57: s = "\"char\" expected"; break; + case 58: s = "\"checked\" expected"; break; + case 59: s = "\"class\" expected"; break; + case 60: s = "\"const\" expected"; break; + case 61: s = "\"continue\" expected"; break; + case 62: s = "\"decimal\" expected"; break; + case 63: s = "\"default\" expected"; break; + case 64: s = "\"delegate\" expected"; break; + case 65: s = "\"do\" expected"; break; + case 66: s = "\"double\" expected"; break; + case 67: s = "\"else\" expected"; break; + case 68: s = "\"enum\" expected"; break; + case 69: s = "\"event\" expected"; break; + case 70: s = "\"explicit\" expected"; break; + case 71: s = "\"extern\" expected"; break; + case 72: s = "\"false\" expected"; break; + case 73: s = "\"finally\" expected"; break; + case 74: s = "\"fixed\" expected"; break; + case 75: s = "\"float\" expected"; break; + case 76: s = "\"for\" expected"; break; + case 77: s = "\"foreach\" expected"; break; + case 78: s = "\"goto\" expected"; break; + case 79: s = "\"if\" expected"; break; + case 80: s = "\"implicit\" expected"; break; + case 81: s = "\"in\" expected"; break; + case 82: s = "\"int\" expected"; break; + case 83: s = "\"interface\" expected"; break; + case 84: s = "\"internal\" expected"; break; + case 85: s = "\"is\" expected"; break; + case 86: s = "\"lock\" expected"; break; + case 87: s = "\"long\" expected"; break; + case 88: s = "\"namespace\" expected"; break; + case 89: s = "\"new\" expected"; break; + case 90: s = "\"null\" expected"; break; + case 91: s = "\"object\" expected"; break; + case 92: s = "\"operator\" expected"; break; + case 93: s = "\"out\" expected"; break; + case 94: s = "\"override\" expected"; break; + case 95: s = "\"params\" expected"; break; + case 96: s = "\"private\" expected"; break; + case 97: s = "\"protected\" expected"; break; + case 98: s = "\"public\" expected"; break; + case 99: s = "\"readonly\" expected"; break; + case 100: s = "\"ref\" expected"; break; + case 101: s = "\"return\" expected"; break; + case 102: s = "\"sbyte\" expected"; break; + case 103: s = "\"sealed\" expected"; break; + case 104: s = "\"short\" expected"; break; + case 105: s = "\"sizeof\" expected"; break; + case 106: s = "\"stackalloc\" expected"; break; + case 107: s = "\"static\" expected"; break; + case 108: s = "\"string\" expected"; break; + case 109: s = "\"struct\" expected"; break; + case 110: s = "\"switch\" expected"; break; + case 111: s = "\"this\" expected"; break; + case 112: s = "\"throw\" expected"; break; + case 113: s = "\"true\" expected"; break; + case 114: s = "\"try\" expected"; break; + case 115: s = "\"typeof\" expected"; break; + case 116: s = "\"uint\" expected"; break; + case 117: s = "\"ulong\" expected"; break; + case 118: s = "\"unchecked\" expected"; break; + case 119: s = "\"unsafe\" expected"; break; + case 120: s = "\"ushort\" expected"; break; + case 121: s = "\"using\" expected"; break; + case 122: s = "\"virtual\" expected"; break; + case 123: s = "\"void\" expected"; break; + case 124: s = "\"volatile\" expected"; break; + case 125: s = "\"while\" expected"; break; + case 126: s = "\"partial\" expected"; break; + case 127: s = "\"where\" expected"; break; + case 128: s = "\"get\" expected"; break; + case 129: s = "\"set\" expected"; break; + case 130: s = "\"add\" expected"; break; + case 131: s = "\"remove\" expected"; break; + case 132: s = "\"yield\" expected"; break; + case 133: s = "\"select\" expected"; break; + case 134: s = "\"group\" expected"; break; + case 135: s = "\"by\" expected"; break; + case 136: s = "\"into\" expected"; break; + case 137: s = "\"from\" expected"; break; + case 138: s = "\"ascending\" expected"; break; + case 139: s = "\"descending\" expected"; break; + case 140: s = "\"orderby\" expected"; break; + case 141: s = "??? expected"; break; + case 142: s = "invalid NamespaceMemberDecl"; break; + case 143: s = "invalid NonArrayType"; break; + case 144: s = "invalid Identifier"; break; + case 145: s = "invalid AttributeArguments"; break; + case 146: s = "invalid Expr"; break; + case 147: s = "invalid TypeModifier"; break; + case 148: s = "invalid TypeDecl"; break; + case 149: s = "invalid TypeDecl"; break; + case 150: s = "invalid IntegralType"; break; + case 151: s = "invalid FormalParameterList"; break; + case 152: s = "invalid FormalParameterList"; break; + case 153: s = "invalid ClassType"; break; + case 154: s = "invalid ClassMemberDecl"; break; + case 155: s = "invalid ClassMemberDecl"; break; + case 156: s = "invalid StructMemberDecl"; break; + case 157: s = "invalid StructMemberDecl"; break; + case 158: s = "invalid StructMemberDecl"; break; + case 159: s = "invalid StructMemberDecl"; break; + case 160: s = "invalid StructMemberDecl"; break; + case 161: s = "invalid StructMemberDecl"; break; + case 162: s = "invalid StructMemberDecl"; break; + case 163: s = "invalid StructMemberDecl"; break; + case 164: s = "invalid StructMemberDecl"; break; + case 165: s = "invalid StructMemberDecl"; break; + case 166: s = "invalid StructMemberDecl"; break; + case 167: s = "invalid StructMemberDecl"; break; + case 168: s = "invalid StructMemberDecl"; break; + case 169: s = "invalid InterfaceMemberDecl"; break; + case 170: s = "invalid InterfaceMemberDecl"; break; + case 171: s = "invalid InterfaceMemberDecl"; break; + case 172: s = "invalid TypeWithRestriction"; break; + case 173: s = "invalid TypeWithRestriction"; break; + case 174: s = "invalid SimpleType"; break; + case 175: s = "invalid AccessorModifiers"; break; + case 176: s = "invalid EventAccessorDecls"; break; + case 177: s = "invalid ConstructorInitializer"; break; + case 178: s = "invalid OverloadableOperator"; break; + case 179: s = "invalid AccessorDecls"; break; + case 180: s = "invalid InterfaceAccessors"; break; + case 181: s = "invalid InterfaceAccessors"; break; + case 182: s = "invalid GetAccessorDecl"; break; + case 183: s = "invalid SetAccessorDecl"; break; + case 184: s = "invalid VariableInitializer"; break; + case 185: s = "invalid Statement"; break; + case 186: s = "invalid AssignmentOperator"; break; + case 187: s = "invalid ObjectPropertyInitializerOrVariableInitializer"; break; + case 188: s = "invalid EmbeddedStatement"; break; + case 189: s = "invalid EmbeddedStatement"; break; + case 190: s = "invalid EmbeddedStatement"; break; + case 191: s = "invalid ForInitializer"; break; + case 192: s = "invalid GotoStatement"; break; + case 193: s = "invalid TryStatement"; break; + case 194: s = "invalid ResourceAcquisition"; break; + case 195: s = "invalid SwitchLabel"; break; + case 196: s = "invalid CatchClauses"; break; + case 197: s = "invalid PrimaryExpr"; break; + case 198: s = "invalid PrimaryExpr"; break; + case 199: s = "invalid PrimaryExpr"; break; + case 200: s = "invalid PrimaryExpr"; break; + case 201: s = "invalid NewExpression"; break; + case 202: s = "invalid NewExpression"; break; + case 203: s = "invalid TypeArgumentList"; break; + case 204: s = "invalid LambdaExpressionParameter"; break; + case 205: s = "invalid LambdaExpressionBody"; break; + case 206: s = "invalid RelationalExpr"; break; + case 207: s = "invalid RelationalExpr"; break; + case 208: s = "invalid TypeParameterConstraintsClauseBase"; break; + case 209: s = "invalid QueryExpressionBody"; break; default: s = "error " + errorNumber; break; } @@ -5297,37 +5896,41 @@ out t); } static bool[,] set = { - {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,T, T,x,x,x, x,x,x,T, T,T,x,x, x,x,T,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, T,x,x,x, x,x,x,T, T,T,x,x, x,x,T,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, x,x,x,T, T,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,T, x,x,x,x, x,x,x}, - {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,T,x,x, T,T,x,x, x,T,T,T, x,T,x,x, x,x,x,T, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,T, x,x,T,x, T,x,T,T, T,T,x,T, x,x,x,x, x,x,x}, - {x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,T,x,x, T,T,T,T, T,T,x,T, T,T,T,x, T,T,T,T, x,T,T,T, x,T,T,T, T,T,T,x, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, T,T,x,T, x,T,x,x, T,x,T,T, x,T,x,T, x,T,x,T, T,T,T,x, x,T,T,x, x,x,x,T, x,T,T,T, T,x,T,x, T,x,T,x, x,T,x,T, T,T,T,x, x,T,T,T, x,x,T,T, T,x,x,x, x,x,x,T, T,x,T,T, x,T,T,T, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,T, T,x,x,T, x,x,T,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, T,x,T,x, x,x,x,T, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,T, T,x,x,T, x,x,T,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, x,T,x,x, T,x,T,T, x,T,x,T, x,T,x,T, T,T,T,x, x,T,T,x, x,x,x,T, x,T,T,T, x,x,T,x, T,x,T,x, x,T,x,T, T,T,T,x, x,T,T,T, x,x,T,T, T,x,x,x, x,x,x,T, T,x,T,T, x,T,T,T, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, x,T,x,x, T,x,T,T, x,T,x,T, x,T,x,T, T,T,T,x, x,T,T,x, x,x,x,T, x,T,T,T, x,x,T,x, T,x,T,x, x,T,x,T, T,T,T,x, x,T,T,T, x,x,T,T, T,x,x,x, x,x,x,T, T,x,T,T, x,T,T,T, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, x,T,x,x, x,T,x,x, T,x,x,x, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, T,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,T, T,x,x,T, x,x,T,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, T,x,x,x, x,x,x,T, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,T, T,x,x,T, x,x,T,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, x,T,x,T, T,T,T,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,T, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,T,T, x,T,x,T, x,T,x,T, T,T,x,x, x,x,T,x, x,x,x,T, x,T,T,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,T, T,x,x,x, x,x,x,T, T,x,x,T, x,x,T,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, x,T,x,x, x,T,x,x, T,x,x,x, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,T, T,x,x,T, x,x,T,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,T, x,x,x,x, x,x,x}, - {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, T,T,x,T, T,T,T,T, T,T,x,x, x,x,x,T, x,T,T,T, T,T,T,x, x,T,x,x, x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, T,T,x,T, T,x,x,T, x,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, T,x,x}, - {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,T,x,x, T,T,x,x, x,T,T,T, x,T,x,x, x,x,x,T, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, T,T,T,x, T,x,x,x, x,x,x,T, x,T,x,T, T,x,x,T, x,x,T,x, T,x,T,T, T,T,x,T, x,x,x,x, x,x,x}, - {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, T,T,x,x, T,T,T,T, T,T,x,x, x,x,x,T, x,T,T,T, T,T,T,x, x,T,x,x, x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, T,T,x,T, T,x,x,T, x,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, T,x,x}, - {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,T,x,x, T,T,x,x, x,T,T,T, x,T,x,x, x,x,x,T, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,T,x,T, T,T,x,T, x,x,T,x, T,x,T,T, T,T,x,T, x,x,x,x, x,x,x}, - {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,x, T,T,x,T, T,T,T,T, T,T,x,x, x,x,x,T, x,T,T,T, T,T,T,x, x,T,x,x, x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, T,T,x,T, T,x,x,T, x,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, T,x,x}, - {x,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,T, T,x,x,T, x,x,x,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x} + {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, T,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,T,T,x, x,x,T,T, T,x,T,x, x,x,x,x, T,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,T,x, T,T,x,x, T,x,x,T, x,T,x,T, T,T,T,x, T,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,T, T,T,T,T, T,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, x,T,T,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,T, x,x,T,T, x,x,x,x, T,x,T,T, T,T,x,T, x,T,x,T, x,x,T,x, T,T,T,T, x,x,T,T, T,x,x,T, T,T,x,x, x,x,x,x, T,T,x,T, T,x,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,T,x,T, x,x,x,x, T,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,T, x,x,T,T, x,x,x,x, T,x,T,T, T,x,x,T, x,T,x,T, x,x,T,x, T,T,T,T, x,x,T,T, T,x,x,T, T,T,x,x, x,x,x,x, T,T,x,T, T,x,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,T, x,x,T,T, x,x,x,x, T,x,T,T, T,x,x,T, x,T,x,T, x,x,T,x, T,T,T,T, x,x,T,T, T,x,x,T, T,T,x,x, x,x,x,x, T,T,x,T, T,x,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,T,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, T,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,x,T,x, T,T,T,T, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,T,T, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,T,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,T,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,T,T,x, T,T,T,T, T,T,T,x, x,x,x,x, T,x,T,T, T,T,T,T, x,x,T,x, x,x,T,T, x,T,T,T, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, T,x,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,T,T,x, x,x,T,T, T,x,T,x, x,x,x,x, T,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,T,T, x,T,x,x, x,x,x,x, T,x,T,x, T,T,x,x, T,x,x,T, x,T,x,T, T,T,T,x, T,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,T,T,x, x,T,T,T, T,T,T,x, x,x,x,x, T,x,T,T, T,T,T,T, x,x,T,x, x,x,T,T, x,T,T,T, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, T,x,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,T,T,x, x,x,T,T, T,x,T,x, x,x,x,x, T,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,T,x, T,T,T,x, T,x,x,T, x,T,x,T, T,T,T,x, T,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,T,T,x, T,T,T,T, T,T,T,x, x,x,x,x, T,x,T,T, T,T,T,T, x,x,T,x, x,x,T,T, x,T,T,T, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, T,x,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x} }; } // end Parser diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG index 8f394bcbbe..d929fcfb4a 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG @@ -67,6 +67,7 @@ TOKENS "^=" "<<=" "->" + "=>" /* ----- keywords ----- */ "abstract" @@ -146,6 +147,21 @@ TOKENS "void" "volatile" "while" + "partial" + "where" + "get" + "set" + "add" + "remove" + "yield" + "select" + "group" + "by" + "into" + "from" + "ascending" + "descending" + "orderby" /* END AUTOGENERATED TOKENS SECTION */ /*------------------------------------------------------------------------* @@ -156,8 +172,7 @@ PRODUCTIONS /*--- compilation unit: */ CS -(. lexer.NextToken(); /* get the first token */ - compilationUnit = new CompilationUnit(); .) +(. lexer.NextToken(); /* get the first token */ .) = { UsingDirective } { IF (IsGlobalAttrTarget()) GlobalAttributeSection } @@ -190,7 +205,7 @@ UsingDirective GlobalAttributeSection = - "[" (. Location startPos = t.Location; .) ident + "[" (. Location startPos = t.Location; .) Identifier (. if (t.val != "assembly") Error("global attribute target specifier (\"assembly\") expected"); string attributeTarget = t.val; List attributes = new List(); @@ -211,8 +226,8 @@ Attribute string alias = null; .) = - [ IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) - ident (. alias = t.val; .) + [ IF (IdentAndDoubleColon()) + Identifier (. alias = t.val; .) "::" ] Qualident @@ -234,7 +249,7 @@ AttributeArguments positional, List na [ [ IF (IsAssignment()) (. nameFound = true; .) - ident (. name = t.val; .) + Identifier (. name = t.val; .) "=" ] Expr (. if (expr != null) {if(name == "") positional.Add(expr); else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } @@ -245,7 +260,7 @@ AttributeArguments positional, List na "," ( IF (IsAssignment()) (. nameFound = true; .) - ident (. name = t.val; .) + Identifier (. name = t.val; .) "=" | /*Empty*/ (. if (nameFound) Error("no positional argument after named argument"); .) ) Expr (. if (expr != null) { if(name == "") positional.Add(expr); @@ -269,7 +284,7 @@ AttributeSection [ IF (IsLocalAttrTarget()) ( "event" (. attributeTarget = "event";.) | "return" (. attributeTarget = "return";.) - | ident (. if (t.val != "field" || t.val != "method" || + | Identifier (. if (t.val != "field" || t.val != "method" || t.val != "module" || t.val != "param" || t.val != "property" || t.val != "type") Error("attribute target specifier (event, return, field," + @@ -332,7 +347,7 @@ TypeDecl attributes> newType.Type = Types.Class; .) - ident (. newType.Name = t.val; .) + Identifier (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] @@ -340,7 +355,7 @@ TypeDecl attributes> [ ClassBase (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } (. newType.BodyStartLocation = t.EndLocation; .) ClassBody @@ -355,7 +370,7 @@ TypeDecl attributes> compilationUnit.BlockStart(newType); newType.Type = Types.Struct; .) - ident (. newType.Name = t.val; .) + Identifier (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] @@ -363,7 +378,7 @@ TypeDecl attributes> [ StructInterfaces (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } (. newType.BodyStartLocation = t.EndLocation; .) @@ -379,7 +394,7 @@ TypeDecl attributes> newType.StartLocation = m.GetDeclarationLocation(t.Location); newType.Type = Types.Interface; .) - ident (. newType.Name = t.val; .) + Identifier (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] @@ -387,7 +402,7 @@ TypeDecl attributes> [ InterfaceBase (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } (. newType.BodyStartLocation = t.EndLocation; .) InterfaceBody @@ -401,7 +416,7 @@ TypeDecl attributes> newType.StartLocation = m.GetDeclarationLocation(t.Location); newType.Type = Types.Enum; .) - ident (. newType.Name = t.val; .) + Identifier (. newType.Name = t.val; .) [ ":" IntegralType (. newType.BaseTypes.Add(new TypeReference(name)); .) ] (. newType.BodyStartLocation = t.EndLocation; .) @@ -417,7 +432,7 @@ TypeDecl attributes> ( IF (NotVoidPointer()) "void" (. delegateDeclr.ReturnType = new TypeReference("void", 0, null); .) | Type (. delegateDeclr.ReturnType = type; .) ) - ident (. delegateDeclr.Name = t.val; .) + Identifier (. delegateDeclr.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] @@ -426,7 +441,7 @@ TypeDecl attributes> ] ")" /* .NET 2.0 */ - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } ";" (. delegateDeclr.EndLocation = t.Location; compilationUnit.AddChild(delegateDeclr); @@ -436,8 +451,8 @@ TypeDecl attributes> Qualident = - ident (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .) - { IF (DotAndIdent()) "." ident (. qualidentBuilder.Append('.'); + Identifier (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .) + { IF (DotAndIdent()) "." Identifier (. qualidentBuilder.Append('.'); qualidentBuilder.Append(t.val); .) } (. qualident = qualidentBuilder.ToString(); .) @@ -617,13 +632,13 @@ FixedParameter "ref" (. mod = ParameterModifiers.Ref; .) | "out" (. mod = ParameterModifiers.Out; .) ] - Type ident (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .) + Type Identifier (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .) . ParameterArray (. TypeReference type; .) = - "params" Type ident (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .) + "params" Type Identifier (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .) . AccessorModifiers @@ -647,7 +662,7 @@ TypeModifier | "abstract" (. m.Add(Modifiers.Abstract, t.Location); .) | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .) | "static" (. m.Add(Modifiers.Static, t.Location); .) - | ident (. if (t.val == "partial") { m.Add(Modifiers.Partial, t.Location); } else { Error("Unexpected identifier"); } .) + | "partial" (. m.Add(Modifiers.Partial, t.Location); .) . ClassType @@ -689,9 +704,7 @@ MemberModifiers | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .) | "virtual" (. m.Add(Modifiers.Virtual, t.Location); .) | "volatile" (. m.Add(Modifiers.Volatile, t.Location); .) - | ( IF(la.kind == Tokens.Identifier && la.val == "partial") - ident (. m.Add(Modifiers.Partial, t.Location); .) - ) + | "partial" (. m.Add(Modifiers.Partial, t.Location); .) } . @@ -705,17 +718,18 @@ StructMemberDecl attributes> List variableDeclarators = new List(); List templates = new List(); TypeReference explicitInterface = null; + bool isExtensionMethod = false; .) = /*--- constant declaration: */ (. m.Check(Modifiers.Constants); .) "const" (.Location startPos = t.Location; .) - Type ident (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const); + Type Identifier (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const); fd.StartLocation = m.GetDeclarationLocation(startPos); VariableDeclaration f = new VariableDeclaration(t.val); fd.Fields.Add(f); .) "=" Expr (. f.Initializer = expr; .) - { "," ident (. f = new VariableDeclaration(t.val); + { "," Identifier (. f = new VariableDeclaration(t.val); fd.Fields.Add(f); .) "=" Expr (. f.Initializer = expr; .) @@ -730,12 +744,13 @@ StructMemberDecl attributes> (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } .) - | ident (. qualident = t.val; .) + | Identifier (. qualident = t.val; .) ) /* .NET 2.0 */ [ TypeParameterList ] "(" + [ "this" (. isExtensionMethod = true; /* C# 3.0 */ .) ] [ FormalParameterList

] ")" (. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident, m.Modifier, @@ -745,6 +760,7 @@ StructMemberDecl attributes> methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); methodDeclaration.EndLocation = t.EndLocation; methodDeclaration.Templates = templates; + methodDeclaration.IsExtensionMethod = isExtensionMethod; if (explicitInterface != null) methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); compilationUnit.AddChild(methodDeclaration); @@ -752,7 +768,7 @@ StructMemberDecl attributes> .) /* .NET 2.0 */ - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } ( Block | ";" ) (. compilationUnit.BlockEnd(); methodDeclaration.Body = (BlockStatement)stmt; @@ -772,7 +788,7 @@ StructMemberDecl attributes> (. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); .) (. eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); .) - | ident (. qualident = t.val; .) + | Identifier (. qualident = t.val; .) ) (. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .) [ "=" Expr (. eventDecl.Initializer = expr; .) ] @@ -788,7 +804,7 @@ StructMemberDecl attributes> | /*--- constructor or static contructor declaration: */ IF (IdentAndLPar()) (. m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); .) - ident (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .) + Identifier (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .) FormalParameterList

] ")" (.ConstructorInitializer init = null; .) @@ -810,7 +826,7 @@ StructMemberDecl attributes> .) ( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) ) "operator" Type (. TypeReference operatorType = type; .) - "(" Type ident (. string varName = t.val; .) ")" + "(" Type Identifier (. string varName = t.val; .) ")" (. Location endPos = t.Location; .) ( Block | ";" (. stmt = null; .) ) (. @@ -840,8 +856,8 @@ StructMemberDecl attributes> if (m.isNone) Error("at least one modifier must be set"); .) "operator" OverloadableOperator (. TypeReference firstType, secondType = null; string secondName = null; .) - "(" Type ident (. string firstName = t.val; .) - ( "," Type ident (. secondName = t.val; .) /* (. if (Tokens.OverloadableUnaryOp[op.kind] && !Tokens.OverloadableBinaryOp[op.kind]) + "(" Type Identifier (. string firstName = t.val; .) + ( "," Type Identifier (. secondName = t.val; .) /* (. if (Tokens.OverloadableUnaryOp[op.kind] && !Tokens.OverloadableBinaryOp[op.kind]) Error("too many operands for unary operator"); .)*/ | /* empty */ /*(. if (Tokens.OverloadableBinaryOp[op.kind]){ @@ -909,13 +925,13 @@ StructMemberDecl attributes> indexer.SetRegion = setRegion; compilationUnit.AddChild(indexer); .) - | IF (la.kind == Tokens.Identifier) + | IF (IsIdentifierToken(la)) ( IF (IsExplicitInterfaceImplementation()) TypeName (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } .) - | ident (. qualident = t.val; .) + | Identifier (. qualident = t.val; .) ) (. Location qualIdentEndLocation = t.EndLocation; .) @@ -924,7 +940,10 @@ StructMemberDecl attributes> ( (. m.Check(Modifiers.PropertysEventsMethods); .) /* .NET 2.0 */ [ TypeParameterList ] - "(" [ FormalParameterList

] ")" (. + "(" + [ "this" (. isExtensionMethod = true; .) ] + [ FormalParameterList

] ")" + (. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident, m.Modifier, type, @@ -934,10 +953,11 @@ StructMemberDecl attributes> methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); methodDeclaration.EndLocation = t.EndLocation; + methodDeclaration.IsExtensionMethod = isExtensionMethod; methodDeclaration.Templates = templates; compilationUnit.AddChild(methodDeclaration); .) - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } ( Block | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .) /*--- property declaration: */ @@ -987,7 +1007,7 @@ ClassMemberDecl attributes> = StructMemberDecl | /*--- destructor declaration: */ (. m.Check(Modifiers.Destructors); Location startPos = t.Location; .) - "~" ident (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes); + "~" Identifier (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes); d.Modifier = m.Modifier; d.StartLocation = m.GetDeclarationLocation(startPos); .) @@ -1016,10 +1036,11 @@ InterfaceMemberDecl [ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ] ( /*--- interface void method (procedure) declaration: */ - IF (NotVoidPointer()) "void" (. if (startLocation.X == -1) startLocation = t.Location; .) ident (. name = t.val; .) + IF (NotVoidPointer()) "void" (. if (startLocation.X == -1) startLocation = t.Location; .) + Identifier (. name = t.val; .) [ TypeParameterList ] "(" [ FormalParameterList ] ")" - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } ";" (. MethodDeclaration md = new MethodDeclaration(name, mod, new TypeReference("void"), parameters, attributes); md.StartLocation = startLocation; @@ -1030,14 +1051,14 @@ InterfaceMemberDecl | ( Type (. if (startLocation.X == -1) startLocation = t.Location; .) ( - ident (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .) + Identifier (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .) ( /*--- interface "not void" method (function) declaration: */ /* .NET 2.0 */ [ TypeParameterList ] "(" [ FormalParameterList ] ")" /* .NET 2.0 */ - { IF (IdentIsWhere()) TypeParameterConstraintsClause } + { TypeParameterConstraintsClause } ";" (. MethodDeclaration md = new MethodDeclaration(name, mod, type, parameters, attributes); md.StartLocation = startLocation; md.EndLocation = t.EndLocation; @@ -1049,14 +1070,15 @@ InterfaceMemberDecl "{" (. Location bodyStart = t.Location;.) InterfaceAccessors "}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .) ) /*--- interface indexer declaration: */ - | "this" "[" FormalParameterList "]" (.Location bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); .) + | "this" "[" FormalParameterList "]" (.Location bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); .) "{" (. Location bodyStart = t.Location;.) InterfaceAccessors "}" (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.) ) /*--- interface event declaration: */ - | "event" (. if (startLocation.X == -1) startLocation = t.Location; .) Type ident (. EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes, null); - compilationUnit.AddChild(ed); - .) - ";" (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .) + | "event" (. if (startLocation.X == -1) startLocation = t.Location; .) + Type Identifier (. EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes, null); + compilationUnit.AddChild(ed); + .) + ";" (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .) ) ) . @@ -1070,7 +1092,7 @@ EnumMemberDecl .) = { AttributeSection (. attributes.Add(section); .) } - ident (. f = new FieldDeclaration(attributes); + Identifier (. f = new FieldDeclaration(attributes); varDecl = new VariableDeclaration(t.val); f.Fields.Add(varDecl); f.StartLocation = t.Location; @@ -1091,7 +1113,6 @@ AccessorDecls { AttributeSection (. attributes.Add(section); .) } [ AccessorModifiers ] ( - IF (IdentIsGet()) GetAccessorDecl (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .) [ (. attributes = new List(); modifiers = null; .) @@ -1100,7 +1121,7 @@ AccessorDecls SetAccessorDecl (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .) ] - | IF (IdentIsSet()) + | SetAccessorDecl (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .) [ (. attributes = new List(); modifiers = null; .) @@ -1109,15 +1130,14 @@ AccessorDecls GetAccessorDecl (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .) ] - | ident (. Error("get or set accessor declaration expected"); .) + | Identifier (. Error("get or set accessor declaration expected"); .) ) . GetAccessorDecl attributes> (. Statement stmt = null; .) = - ident /* "get" is not a keyword! */ - (. if (t.val != "get") Error("get expected"); .) + "get" (. Location startLocation = t.Location; .) ( Block | ";" ) (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .) @@ -1127,8 +1147,7 @@ GetAccessorDecl attribute SetAccessorDecl attributes> (. Statement stmt = null; .) = - ident /* "set" is not a keyword! */ - (. if (t.val != "set") Error("set expected"); .) + "set" (. Location startLocation = t.Location; .) ( Block | ";" ) (. setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); .) @@ -1145,15 +1164,14 @@ EventAccessorDecls (. attributes.Add(section); .) } ( - IF (IdentIsAdd()) (. addBlock = new EventAddRegion(attributes); .) + (. addBlock = new EventAddRegion(attributes); .) AddAccessorDecl (. attributes = new List(); addBlock.Block = (BlockStatement)stmt; .) { AttributeSection (. attributes.Add(section); .)} RemoveAccessorDecl (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; .) - | IF (IdentIsRemove()) + | RemoveAccessorDecl (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new List(); .) { AttributeSection (. attributes.Add(section); .) } AddAccessorDecl (. addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; .) - | ident (. Error("add or remove accessor declaration expected"); .) ) . @@ -1168,9 +1186,8 @@ InterfaceAccessors (. attributes.Add(section); .) } (. Location startLocation = la.Location; .) ( - IF (IdentIsGet()) ident (. getBlock = new PropertyGetRegion(null, attributes); .) - | IF (IdentIsSet()) ident (. setBlock = new PropertySetRegion(null, attributes); .) - | ident (. Error("set or get expected"); .) + "get" (. getBlock = new PropertyGetRegion(null, attributes); .) + | "set" (. setBlock = new PropertySetRegion(null, attributes); .) ) ";" (. if (getBlock != null) { getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; } @@ -1180,13 +1197,12 @@ InterfaceAccessors (. attributes.Add(section); .) } (. startLocation = la.Location; .) ( - IF (IdentIsGet()) ident (. if (getBlock != null) Error("get already declared"); + "get" (. if (getBlock != null) Error("get already declared"); else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; } .) - | IF (IdentIsSet()) ident (. if (setBlock != null) Error("set already declared"); + | "set" (. if (setBlock != null) Error("set already declared"); else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; } .) - | ident (. Error("set or get expected"); .) ) ";" (. if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } .) @@ -1196,7 +1212,7 @@ InterfaceAccessors fieldDeclaration> (. Expression expr = null; .) = - ident (. VariableDeclaration f = new VariableDeclaration(t.val); .) + Identifier (. VariableDeclaration f = new VariableDeclaration(t.val); .) [ "=" VariableInitializer (. f.Initializer = expr; .) ] (. fieldDeclaration.Add(f); .) . @@ -1218,16 +1234,14 @@ Block /* not BlockStatement because of EmbeddedStatement */ AddAccessorDecl (.stmt = null;.) = - /* "add" is not a keyword!? */ - ident (. if (t.val != "add") Error("add expected"); .) + "add" Block . RemoveAccessorDecl (.stmt = null;.) = - /* "remove" is not a keyword!? */ - ident (. if (t.val != "remove") Error("remove expected"); .) + "remove" Block . @@ -1248,7 +1262,7 @@ VariableInitializer (. TypeReference type = null; Expression expr = null; initializerExpression = null; .) = Expr - | ArrayInitializer + | CollectionInitializer | "stackalloc" Type "[" Expr "]" (. initializerExpression = new StackAllocExpression(type, expr); .) . @@ -1314,10 +1328,10 @@ AssignmentOperator ">" ">=" (. op = AssignmentOperatorType.ShiftRight; .) . -ArrayInitializer +CollectionInitializer (. Expression expr = null; - ArrayInitializerExpression initializer = new ArrayInitializerExpression(); + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); .) = "{" @@ -1332,6 +1346,38 @@ ArrayInitializer "}" (. outExpr = initializer; .) . +CollectionOrObjectInitializer +(. + Expression expr = null; + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); +.) += + "{" + [ ObjectPropertyInitializerOrVariableInitializer + (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) + { IF (NotFinalComma()) + "," ObjectPropertyInitializerOrVariableInitializer + (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) + } + [ "," ] + ] + "}" (. outExpr = initializer; .) +. + +ObjectPropertyInitializerOrVariableInitializer +(. expr = null; .) += +( IF (IdentAndAsgn()) + Identifier + (. IdentifierExpression l = new IdentifierExpression(t.val); + l.StartLocation = t.Location; l.EndLocation = t.EndLocation; + Expression r = null; .) + "=" VariableInitializer + (. expr = new AssignmentExpression(l, AssignmentOperatorType.Assign, r); .) +| VariableInitializer +) +. + LocalVariableDecl (. TypeReference type; @@ -1348,17 +1394,9 @@ LocalVariableDecl LocalVariableDeclarator (. Expression expr = null; .) = -/* ident (. var = new VariableDeclaration(t.val); .) [ "=" LocalVariableInitializer (. var.Initializer = expr; .) ]*/ - ident (. var = new VariableDeclaration(t.val); .) [ "=" VariableInitializer (. var.Initializer = expr; .) ] -. -/* -LocalVariableInitializer -(. expr = null; .) -= - Expr - | ArrayInitializer + Identifier (. var = new VariableDeclaration(t.val); .) [ "=" VariableInitializer (. var.Initializer = expr; .) ] . -*/ + Statement (. TypeReference type; @@ -1369,13 +1407,13 @@ Statement = ( /*--- labeled statement: */ - IF (IsLabel()) ident (. compilationUnit.AddChild(new LabelStatement(t.val)); .) + IF (IsLabel()) Identifier (. compilationUnit.AddChild(new LabelStatement(t.val)); .) ":" Statement /*--- local constant declaration: */ | "const" Type (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; .) - ident (. ident = t.val; .) + Identifier (. ident = t.val; .) "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) - { "," ident (. ident = t.val; .) "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) } + { "," Identifier (. ident = t.val; .) "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) } ";" (. compilationUnit.AddChild(var); .) /*--- local variable declaration: */ | IF (IsLocalVarDecl()) LocalVariableDecl ";" (. compilationUnit.AddChild(stmt); .) @@ -1436,7 +1474,7 @@ EmbeddedStatement [ Expr ] ";" [ ForIterator ] ")" EmbeddedStatement (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .) - | "foreach" "(" Type ident (. string varName = t.val; Location start = t.Location;.) + | "foreach" "(" Type Identifier (. string varName = t.val; Location start = t.Location;.) "in" Expr ")" EmbeddedStatement (. statement = new ForeachStatement(type, varName , expr, embeddedStatement); statement.EndLocation = t.EndLocation; @@ -1445,7 +1483,7 @@ EmbeddedStatement | "break" ";" (. statement = new BreakStatement(); .) | "continue" ";" (. statement = new ContinueStatement(); .) | GotoStatement - | IF (IsYieldStatement()) ident ( "return" Expr (. statement = new YieldStatement(new ReturnStatement(expr)); .) + | IF (IsYieldStatement()) "yield" ( "return" Expr (. statement = new YieldStatement(new ReturnStatement(expr)); .) | "break" (. statement = new YieldStatement(new BreakStatement()); .) ) ";" | "return" [ Expr ] ";" (. statement = new ReturnStatement(expr); .) | "throw" [ Expr ] ";" (. statement = new ThrowStatement(expr); .) @@ -1469,10 +1507,10 @@ EmbeddedStatement "(" Type (. if (type.PointerNestingLevel == 0) Error("can only fix pointer types"); List pointerDeclarators = new List(1); .) - ident (. string identifier = t.val; .) + Identifier (. string identifier = t.val; .) "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) { - "," ident (. identifier = t.val; .) + "," Identifier (. identifier = t.val; .) "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) } ")" EmbeddedStatement (. statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); .) @@ -1560,11 +1598,11 @@ CatchClauses catchClauses> Block (. catchClauses.Add(new CatchClause(stmt)); .) /*--- specific catch clause */ | "(" ClassType (. identifier = null; .) - [ ident (. identifier = t.val; .) ] + [ Identifier (. identifier = t.val; .) ] ")" Block (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) { IF (IsTypedCatch()) "catch" "(" ClassType (. identifier = null; .) - [ ident (. identifier = t.val; .) ] + [ Identifier (. identifier = t.val; .) ] ")" Block (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) } /*--- general catch clause (after specific catch clauses, optional) */ @@ -1577,7 +1615,7 @@ GotoStatement = "goto" ( - ident (. stmt = new GotoStatement(t.val); .) ";" + Identifier (. stmt = new GotoStatement(t.val); .) ";" | "case" Expr ";" (. stmt = new GotoCaseStatement(expr); .) | "default" ";" (. stmt = new GotoCaseStatement(null); .) ) @@ -1675,7 +1713,6 @@ PrimaryExpr (. TypeReference type = null; List typeList = null; - bool isArrayCreation = false; Expression expr; pexpr = null; .) @@ -1685,12 +1722,20 @@ PrimaryExpr | "false" (.pexpr = new PrimitiveExpression(false, "false"); .) | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */ | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .) - | IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) - ident (. type = new TypeReference(t.val); .) + | IF (StartOfQueryExpression()) + QueryExpression + | IF (IdentAndDoubleColon()) + Identifier (. type = new TypeReference(t.val); .) "::" (. pexpr = new TypeReferenceExpression(type); .) - ident (. if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); .) - /*--- simple name: */ - | ident (. pexpr = new IdentifierExpression(t.val); .) + Identifier (. if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); .) + /*--- simple name (IdentifierExpression): */ + | Identifier + (. pexpr = new IdentifierExpression(t.val); .) + (. pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .) + + [ ShortedLambdaExpression<(IdentifierExpression)pexpr, out pexpr> ] + | IF (IsLambdaExpression()) /* Lambda expression */ + LambdaExpression /*--- parenthesized expression: */ | "(" Expr ")" (. pexpr = new ParenthesizedExpression(expr); .) | /*--- predefined type member access: */ @@ -1711,47 +1756,21 @@ PrimaryExpr | "uint" (. val = "uint"; .) | "ulong" (. val = "ulong"; .) | "ushort" (. val = "ushort"; .) - ) (. t.val = ""; .) "." ident (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .) + ) (. t.val = ""; .) "." Identifier (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .) /*--- this access: */ | "this" (. pexpr = new ThisReferenceExpression(); .) /*--- base access: */ | "base" (. Expression retExpr = new BaseReferenceExpression(); .) ( - "." ident (. retExpr = new FieldReferenceExpression(retExpr, t.val); .) + "." Identifier (. retExpr = new FieldReferenceExpression(retExpr, t.val); .) | "[" Expr (. List indices = new List(); if (expr != null) { indices.Add(expr); } .) { "," Expr (. if (expr != null) { indices.Add(expr); } .) } "]" (. retExpr = new IndexerExpression(retExpr, indices); .) ) (. pexpr = retExpr; .) - | "new" NonArrayType - (. List parameters = new List(); .) - /*--- delegate / object creation expression: */ - /* Note: a delegate creation expression allow only a single Expr */ - /* not an argument list, but this is not distinguished here */ - ( - "(" (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .) - [ Argument (. if (expr != null) { parameters.Add(expr); } .) - { "," Argument (. if (expr != null) { parameters.Add(expr); } .) } - ] - ")" (. pexpr = oce; .) - | "[" /*--- array creation expression: */ - (. isArrayCreation = true; ArrayCreateExpression ace = new ArrayCreateExpression(type); pexpr = ace; .) - (. int dims = 0; List ranks = new List(); .) - ( - { "," (. dims += 1; .) } - "]" (. ranks.Add(dims); dims = 0; .) - { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } - (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) - ArrayInitializer (. ace.ArrayInitializer = (ArrayInitializerExpression)expr; .) - | Expr (. if (expr != null) parameters.Add(expr); .) - { "," (. dims += 1; .) - Expr (. if (expr != null) parameters.Add(expr); .) - } - "]" (. ranks.Add(dims); ace.Arguments = parameters; dims = 0; .) - { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } - (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) - [ ArrayInitializer (. ace.ArrayInitializer = (ArrayInitializerExpression)expr; .) ] - ) - ) + + /* new ... - ObjectCreationExpression or ArrayCreateExpression */ + | NewExpression (.pexpr = expr; .) + | "typeof" "(" ( IF (NotVoidPointer()) "void" (. type = new TypeReference("void"); .) @@ -1770,12 +1789,12 @@ PrimaryExpr | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .) ) /*--- member access */ - | "->" ident (. pexpr = new PointerReferenceExpression(pexpr, t.val); .) - | "." ident (. pexpr = new FieldReferenceExpression(pexpr, t.val);.) + | "->" Identifier (. pexpr = new PointerReferenceExpression(pexpr, t.val); .) + | "." Identifier (. pexpr = new FieldReferenceExpression(pexpr, t.val);.) /* member access on generic type */ | ( IF (IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr)) TypeArgumentList ) - "." ident + "." Identifier (. pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeList), t.val);.) /*--- invocation expression: */ | "(" (. List parameters = new List(); .) @@ -1788,7 +1807,7 @@ PrimaryExpr { "," Argument (. if (expr != null) {parameters.Add(expr);} .) } ] ")" (. pexpr = new InvocationExpression(pexpr, parameters, typeList); .) /*--- element access */ - | (. if (isArrayCreation) Error("element access not allow on array creation"); + | (. /*if (isArrayCreation) Error("element access not allow on array creation");*/ List indices = new List(); .) "[" Expr (. if (expr != null) { indices.Add(expr); } .) @@ -1797,11 +1816,126 @@ PrimaryExpr } . +NewExpression +(. pexpr = null; + List parameters = new List(); + TypeReference type = null; + Expression expr; +.) += + "new" + [ NonArrayType ] /* optional since .NET 3.0 */ + + /*--- delegate / object creation expression: */ + /* Note: a delegate creation expression allow only a single Expr */ + /* not an argument list, but this is not distinguished here */ + ( + ( (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .) + "(" (. if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); .) + [ Argument (. if (expr != null) { parameters.Add(expr); } .) + { "," Argument (. if (expr != null) { parameters.Add(expr); } .) } + ] + ")" (. pexpr = oce; .) + [ CollectionOrObjectInitializer (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) ] + | (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .) + CollectionOrObjectInitializer (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) + (. pexpr = oce; .) + ) + + /*--- array creation expression: */ + | "[" + (. ArrayCreateExpression ace = new ArrayCreateExpression(type); + /* we must not change RankSpecifier on the null type reference*/ + if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); } + pexpr = ace; + int dims = 0; List ranks = new List(); + .) + ( + { "," (. dims += 1; .) } + "]" (. ranks.Add(dims); dims = 0; .) + { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } + (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) + CollectionInitializer (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) + | Expr (. if (expr != null) parameters.Add(expr); .) + { "," (. dims += 1; .) + Expr (. if (expr != null) parameters.Add(expr); .) + } + "]" (. ranks.Add(dims); ace.Arguments = parameters; dims = 0; .) + { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } + (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) + [ CollectionInitializer (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) ] + ) + ) +. + +/* Lambda expression with parameter list */ +LambdaExpression +(. + LambdaExpression lambda = new LambdaExpression(); + lambda.StartLocation = la.Location; + ParameterDeclarationExpression p; + outExpr = lambda; +.) += + "(" + [ + LambdaExpressionParameter (. if (p != null) lambda.Parameters.Add(p); .) + { "," + LambdaExpressionParameter (. if (p != null) lambda.Parameters.Add(p); .) + } + ] + ")" + "=>" + LambdaExpressionBody +. + +ShortedLambdaExpression +(. LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; .) += + "=>" + /* not an IdentifierExpression, but a short lambda expression*/ + (. + lambda.StartLocation = ident.StartLocation; + lambda.Parameters.Add(new ParameterDeclarationExpression(null, ident.Identifier)); + lambda.Parameters[0].StartLocation = ident.StartLocation; + lambda.Parameters[0].EndLocation = ident.EndLocation; + .) + LambdaExpressionBody +. + +LambdaExpressionParameter +(. Location start = la.Location; p = null; + TypeReference type; +.) += + ( IF (Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis) + Identifier + (. p = new ParameterDeclarationExpression(null, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + .) + | Type + Identifier + (. p = new ParameterDeclarationExpression(type, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + .) + ) +. + +LambdaExpressionBody +(. Expression expr; BlockStatement stmt; .) += + ( + BlockInsideExpression (. lambda.StatementBody = stmt; .) + | Expr (. lambda.ExpressionBody = expr; .) + ) + (. lambda.EndLocation = t.EndLocation; .) +. + AnonymousMethodExpr (. AnonymousMethodExpression expr = new AnonymousMethodExpression(); expr.StartLocation = t.Location; - Statement stmt; + BlockStatement stmt; List p = new List(); outExpr = expr; .) @@ -1812,16 +1946,22 @@ AnonymousMethodExpr ")" (. expr.HasParameterList = true; .) ] + BlockInsideExpression (. expr.Body = stmt; .) + (. expr.EndLocation = t.Location; .) +. + +BlockInsideExpression +(. Statement stmt = null; outStmt = null; .) += /*--- ParseExpression doesn't set a compilation unit, */ /*--- so we can't use block then -> skip body of anonymous method */ (. if (compilationUnit != null) { .) - Block (. expr.Body = (BlockStatement)stmt; .) + Block (. outStmt = (BlockStatement)stmt; .) (. } else { .) "{" (. lexer.SkipCurrentBlock(0); .) "}" (. } .) - (. expr.EndLocation = t.Location; .) . ConditionalOrExpr @@ -1959,8 +2099,8 @@ TypeName string qualident; .) = - [ IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) - ident (. alias = t.val; .) + [ IF (IdentAndDoubleColon()) + Identifier (. alias = t.val; .) "::" ] Qualident @@ -2017,17 +2157,17 @@ TypeParameterList templates> .) = "<" { AttributeSection (. attributes.Add(section); .) } - ident (. templates.Add(new TemplateDefinition(t.val, attributes)); .) + Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .) { "," { AttributeSection (. attributes.Add(section); .) } - ident (. templates.Add(new TemplateDefinition(t.val, attributes)); .)} + Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)} ">" . TypeParameterConstraintsClause templates> (. string name = ""; TypeReference type; .) = - ident (. if (t.val != "where") Error("where expected"); .) - ident (. name = t.val; .) + "where" + Identifier (. name = t.val; .) ":" TypeParameterConstraintsClauseBase (. TemplateDefinition td = null; @@ -2060,5 +2200,133 @@ TypeParameterConstraintsClauseBase | Type (. type = t; .) . +QueryExpression +(. QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location; + QueryExpressionFromClause fromClause; +.) += + QueryExpressionFromClause (. q.FromClause = fromClause; .) + QueryExpressionBody + (. q.EndLocation = t.EndLocation; .) +. + +QueryExpressionFromClause +(. fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location; + QueryExpressionFromGenerator fg; +.) += + "from" + QueryExpressionFromGenerator (. SafeAdd(fc, fc.Generators, fg); .) + { "," + QueryExpressionFromGenerator (. SafeAdd(fc, fc.Generators, fg); .) + } + (. fc.EndLocation = t.EndLocation; .) +. + +QueryExpressionFromGenerator +(. Expression expr; fg = new QueryExpressionFromGenerator(); fg.StartLocation = la.Location; .) += + Identifier (. fg.Identifier = t.val; .) + "in" + Expr (. fg.InExpression = expr; .) + (. fg.EndLocation = t.EndLocation; .) +. + +QueryExpressionBody +(. QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause; + QueryExpressionSelectClause selectClause; QueryExpressionGroupClause groupClause; + QueryExpressionIntoClause intoClause; +.) += + { ( QueryExpressionFromClause (. SafeAdd(q, q.FromOrWhereClauses, fromClause); .) + | QueryExpressionWhereClause (. SafeAdd(q, q.FromOrWhereClauses, whereClause); .) + ) } + [ QueryExpressionOrderByClause ] + ( QueryExpressionSelectClause (. q.SelectOrGroupClause = selectClause; .) + | QueryExpressionGroupClause (. q.SelectOrGroupClause = groupClause; .) + ) + [ QueryExpressionIntoClause (. q.IntoClause = intoClause; .) ] +. + +QueryExpressionWhereClause +(. Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location; .) += + "where" + Expr (. wc.Condition = expr; .) + (. wc.EndLocation = t.EndLocation; .) +. + +QueryExpressionOrderByClause +(. QueryExpressionOrdering ordering; .) += + "orderby" + QueryExpressionOrderingClause (. SafeAdd(q, q.Orderings, ordering); .) + { "," + QueryExpressionOrderingClause (. SafeAdd(q, q.Orderings, ordering); .) + } +. + +QueryExpressionOrderingClause +(. Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location; .) += + Expr (. ordering.Criteria = expr; .) + [ "ascending" (. ordering.Direction = QueryExpressionOrderingDirection.Ascending; .) + | "descending" (. ordering.Direction = QueryExpressionOrderingDirection.Descending; .) + ] + (. ordering.EndLocation = t.EndLocation; .) +. + +QueryExpressionSelectClause +(. Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location; .) += + "select" + Expr (. sc.Projection = expr; .) + (. sc.EndLocation = t.EndLocation; .) +. + +QueryExpressionGroupClause +(. Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; .) += + "group" + Expr (. gc.Projection = expr; .) + "by" + Expr (. gc.GroupBy = expr; .) + (. gc.EndLocation = t.EndLocation; .) +. + +QueryExpressionIntoClause +(. ic = new QueryExpressionIntoClause(); ic.StartLocation = la.Location; .) += + "into" + Identifier (. ic.IntoIdentifier = t.val; .) + (. ic.ContinuedQuery = new QueryExpression(); .) + (. ic.ContinuedQuery.StartLocation = la.Location; .) + QueryExpressionBody + (. ic.ContinuedQuery.EndLocation = t.EndLocation; .) + (. ic.EndLocation = t.EndLocation; .) +. + +/* allow usage of context sensitive keywords as identifiers */ +Identifier += +/* when updating this list, ensure you also change KeywordList.IdentifierTokens*/ + ident +| "partial" +| "where" +| "get" +| "set" +| "add" +| "remove" +| "yield" +| "select" +| "group" +| "by" +| "into" +| "from" +| "ascending" +| "descending" +| "orderby" +. + END CS. diff --git a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs index b85f8c3826..be5b770187 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs @@ -3202,18 +3202,18 @@ la.kind == Tokens.OpenParenthesis) { ArrayTypeModifiers( #line 1846 "VBNET.ATG" out dimensions); - ArrayInitializer( + CollectionInitializer( #line 1847 "VBNET.ATG" out initializer); } else { - ArrayInitializer( + CollectionInitializer( #line 1848 "VBNET.ATG" out initializer); } } #line 1850 "VBNET.ATG" - if (canBeReDim && !canBeNormal && initializer == null) initializer = new ArrayInitializerExpression(); + if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression(); } #line 1853 "VBNET.ATG" @@ -3224,7 +3224,7 @@ out initializer); if (dimensions == null) dimensions = new ArrayList(); dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0)); type.RankSpecifier = (int[])dimensions.ToArray(typeof(int)); - ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as ArrayInitializerExpression); + ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression); ace.Arguments = arguments; oce = ace; } @@ -3243,7 +3243,7 @@ out Expression initializerExpression) { #line 1437 "VBNET.ATG" out initializerExpression); } else if (la.kind == 22) { - ArrayInitializer( + CollectionInitializer( #line 1438 "VBNET.ATG" out initializerExpression); } else SynErr(236); @@ -3292,13 +3292,13 @@ out expr); } } - void ArrayInitializer( + void CollectionInitializer( #line 1442 "VBNET.ATG" out Expression outExpr) { #line 1444 "VBNET.ATG" Expression expr = null; - ArrayInitializerExpression initializer = new ArrayInitializerExpression(); + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); Expect(22); if (StartOf(28)) { diff --git a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG index ba34c300fa..5d5ecdcbd1 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG @@ -1435,14 +1435,14 @@ VariableInitializer initializerExpression = null; .) = Expr - | ArrayInitializer + | CollectionInitializer . /* 9.6.3.4 */ -ArrayInitializer +CollectionInitializer (. Expression expr = null; - ArrayInitializerExpression initializer = new ArrayInitializerExpression(); + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); .) = "{" [ @@ -1588,7 +1588,9 @@ SimpleNonInvocationExpression | "False" (.pexpr = new PrimitiveExpression(false, "false"); .) | "Nothing" (.pexpr = new PrimitiveExpression(null, "null"); .) | /* 11.4.2 */ "(" Expr ")" (. pexpr = new ParenthesizedExpression(expr); .) - | /* 11.4.4 */ Identifier (. pexpr = new IdentifierExpression(t.val); .) + | /* 11.4.4 */ Identifier + (. pexpr = new IdentifierExpression(t.val); .) + (. pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .) | (. string val = String.Empty; .) ( PrimitiveTypeName | "Object" (. val = "Object"; .) ) "." (. t.val = ""; .) Identifier (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .) @@ -1844,10 +1846,10 @@ ObjectCreateExpression ["(" NormalOrReDimArgumentList ")" [ IF (la.kind == Tokens.OpenParenthesis) ArrayTypeModifiers - ArrayInitializer - | ArrayInitializer + CollectionInitializer + | CollectionInitializer ] - (. if (canBeReDim && !canBeNormal && initializer == null) initializer = new ArrayInitializerExpression(); .) + (. if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression(); .) ] (. if (type == null) type = new TypeReference("Object"); // fallback type on parser errors @@ -1857,7 +1859,7 @@ ObjectCreateExpression if (dimensions == null) dimensions = new ArrayList(); dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0)); type.RankSpecifier = (int[])dimensions.ToArray(typeof(int)); - ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as ArrayInitializerExpression); + ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression); ace.Arguments = arguments; oce = ace; } diff --git a/src/Libraries/NRefactory/Project/Src/Parser/gen.bat b/src/Libraries/NRefactory/Project/Src/Parser/gen.bat index 7e67c5d71d..2c32b7a095 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/gen.bat +++ b/src/Libraries/NRefactory/Project/Src/Parser/gen.bat @@ -22,6 +22,6 @@ del VBNET.ATG :exit pause cd .. -pushd ..\..\.. -%windir%\microsoft.net\framework\v2.0.50727\msbuild -popd \ No newline at end of file +rem pushd ..\..\.. +rem %windir%\microsoft.net\framework\v2.0.50727\msbuild +rem popd \ No newline at end of file diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs index 2bbdcf11da..a2adfcedff 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs @@ -15,15 +15,15 @@ using System.Text; using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Parser; using ICSharpCode.NRefactory.Parser.CSharp; +using ICSharpCode.NRefactory.Visitors; namespace ICSharpCode.NRefactory.PrettyPrinter { - public sealed class CSharpOutputVisitor : IOutputAstVisitor + public sealed class CSharpOutputVisitor : NodeTrackingAstVisitor, IOutputAstVisitor { Errors errors = new Errors(); CSharpOutputFormatter outputFormatter; PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions(); - NodeTracker nodeTracker; Stack withExpressionStack = new Stack(); bool printFullSystemType; @@ -39,13 +39,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object Options { - get { - return prettyPrintOptions; - } - set { - prettyPrintOptions = value as PrettyPrintOptions; - } + AbstractPrettyPrintOptions IOutputAstVisitor.Options { + get { return prettyPrintOptions; } + set { prettyPrintOptions = (PrettyPrintOptions)value; } + } + + public PrettyPrintOptions Options { + get { return prettyPrintOptions; } + set { prettyPrintOptions = value; } } public IOutputFormatter OutputFormatter { @@ -54,16 +55,28 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public NodeTracker NodeTracker { - get { - return nodeTracker; + public CSharpOutputVisitor() + { + outputFormatter = new CSharpOutputFormatter(prettyPrintOptions); + } + + public event Action BeforeNodeVisit; + public event Action AfterNodeVisit; + + protected override void BeginVisit(INode node) + { + if (BeforeNodeVisit != null) { + BeforeNodeVisit(node); } + base.BeginVisit(node); } - public CSharpOutputVisitor() + protected override void EndVisit(INode node) { - outputFormatter = new CSharpOutputFormatter(prettyPrintOptions); - nodeTracker = new NodeTracker(this); + base.EndVisit(node); + if (AfterNodeVisit != null) { + AfterNodeVisit(node); + } } void Error(INode node, string message) @@ -78,9 +91,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } #region ICSharpCode.NRefactory.Parser.IASTVisitor interface implementation - public object VisitCompilationUnit(CompilationUnit compilationUnit, object data) + public override object TrackedVisitCompilationUnit(CompilationUnit compilationUnit, object data) { - nodeTracker.TrackedVisitChildren(compilationUnit, data); + compilationUnit.AcceptChildren(this, data); outputFormatter.EndFile(); return null; } @@ -109,7 +122,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.GreaterThan); } - public object VisitTypeReference(TypeReference typeReference, object data) + public override object TrackedVisitTypeReference(TypeReference typeReference, object data) { if (typeReference == TypeReference.ClassConstraint) { outputFormatter.PrintToken(Tokens.Class); @@ -155,7 +168,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } else if (typeReference.SystemType == "System.Nullable" && typeReference.GenericTypes != null && typeReference.GenericTypes.Count == 1 && !typeReference.IsGlobal) { - nodeTracker.TrackedVisit(typeReference.GenericTypes[0], null); + TrackedVisit(typeReference.GenericTypes[0], null); outputFormatter.PrintText("?"); } else { if (typeReference.SystemType.Length > 0) { @@ -178,9 +191,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) + public override object TrackedVisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) { - nodeTracker.TrackedVisit(innerClassTypeReference.BaseType, data); + TrackedVisit(innerClassTypeReference.BaseType, data); outputFormatter.PrintToken(Tokens.Dot); return VisitTypeReference((TypeReference)innerClassTypeReference, data); } @@ -192,7 +205,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return; } foreach (AttributeSection section in attributes) { - nodeTracker.TrackedVisit(section, data); + TrackedVisit(section, data); } } void PrintFormattedComma() @@ -206,7 +219,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object VisitAttributeSection(AttributeSection attributeSection, object data) + public override object TrackedVisitAttributeSection(AttributeSection attributeSection, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.OpenSquareBracket); @@ -220,7 +233,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } Debug.Assert(attributeSection.Attributes != null); for (int j = 0; j < attributeSection.Attributes.Count; ++j) { - nodeTracker.TrackedVisit((INode)attributeSection.Attributes[j], data); + TrackedVisit((INode)attributeSection.Attributes[j], data); if (j + 1 < attributeSection.Attributes.Count) { PrintFormattedComma(); } @@ -233,7 +246,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data) + public override object TrackedVisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data) { outputFormatter.PrintIdentifier(attribute.Name); outputFormatter.PrintToken(Tokens.OpenParenthesis); @@ -244,7 +257,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter PrintFormattedComma(); } for (int i = 0; i < attribute.NamedArguments.Count; ++i) { - nodeTracker.TrackedVisit((INode)attribute.NamedArguments[i], data); + TrackedVisit((INode)attribute.NamedArguments[i], data); if (i + 1 < attribute.NamedArguments.Count) { PrintFormattedComma(); } @@ -254,17 +267,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) + public override object TrackedVisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) { outputFormatter.PrintIdentifier(namedArgumentExpression.Name); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(namedArgumentExpression.Expression, data); + TrackedVisit(namedArgumentExpression.Expression, data); return null; } - public object VisitUsing(Using @using, object data) + public override object TrackedVisitUsing(Using @using, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Using); @@ -277,7 +290,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); printFullSystemType = true; - nodeTracker.TrackedVisit(@using.Alias, data); + TrackedVisit(@using.Alias, data); printFullSystemType = false; } @@ -286,15 +299,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data) + public override object TrackedVisitUsingDeclaration(UsingDeclaration usingDeclaration, object data) { foreach (Using u in usingDeclaration.Usings) { - nodeTracker.TrackedVisit(u, data); + TrackedVisit(u, data); } return null; } - public object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) + public override object TrackedVisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Namespace); @@ -303,7 +316,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.BeginBrace(this.prettyPrintOptions.NamespaceBraceStyle); - nodeTracker.TrackedVisitChildren(namespaceDeclaration, data); + namespaceDeclaration.AcceptChildren(this, data); outputFormatter.EndBrace(); @@ -315,7 +328,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { for (int i = 0; i < typeDeclaration.Children.Count; i++) { FieldDeclaration fieldDeclaration = (FieldDeclaration)typeDeclaration.Children[i]; - nodeTracker.BeginNode(fieldDeclaration); + BeginVisit(fieldDeclaration); VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0]; VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); @@ -324,19 +337,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(f.Initializer, data); + TrackedVisit(f.Initializer, data); } if (i < typeDeclaration.Children.Count - 1) { outputFormatter.PrintToken(Tokens.Comma); } outputFormatter.NewLine(); - nodeTracker.EndNode(fieldDeclaration); + EndVisit(fieldDeclaration); } } TypeDeclaration currentType = null; - public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) + public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { VisitAttributes(typeDeclaration.Attributes, data); outputFormatter.Indent(); @@ -368,12 +381,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (i > 0) { PrintFormattedComma(); } - nodeTracker.TrackedVisit(typeDeclaration.BaseTypes[i], data); + TrackedVisit(typeDeclaration.BaseTypes[i], data); } } foreach (TemplateDefinition templateDefinition in typeDeclaration.Templates) { - nodeTracker.TrackedVisit(templateDefinition, data); + TrackedVisit(templateDefinition, data); } switch (typeDeclaration.Type) { @@ -396,7 +409,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (typeDeclaration.Type == ClassType.Enum) { OutputEnumMembers(typeDeclaration, data); } else { - nodeTracker.TrackedVisitChildren(typeDeclaration, data); + typeDeclaration.AcceptChildren(this, data); } currentType = oldType; outputFormatter.EndBrace(); @@ -404,7 +417,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitTemplateDefinition(TemplateDefinition templateDefinition, object data) + public override object TrackedVisitTemplateDefinition(TemplateDefinition templateDefinition, object data) { if (templateDefinition.Bases.Count == 0) return null; @@ -418,7 +431,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); for (int i = 0; i < templateDefinition.Bases.Count; ++i) { - nodeTracker.TrackedVisit(templateDefinition.Bases[i], data); + TrackedVisit(templateDefinition.Bases[i], data); if (i + 1 < templateDefinition.Bases.Count) { PrintFormattedComma(); } @@ -426,14 +439,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) + public override object TrackedVisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) { VisitAttributes(delegateDeclaration.Attributes, data); outputFormatter.Indent(); OutputModifier(delegateDeclaration.Modifier); outputFormatter.PrintToken(Tokens.Delegate); outputFormatter.Space(); - nodeTracker.TrackedVisit(delegateDeclaration.ReturnType, data); + TrackedVisit(delegateDeclaration.ReturnType, data); outputFormatter.Space(); outputFormatter.PrintIdentifier(delegateDeclaration.Name); PrintTemplates(delegateDeclaration.Templates); @@ -444,14 +457,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter AppendCommaSeparatedList(delegateDeclaration.Parameters); outputFormatter.PrintToken(Tokens.CloseParenthesis); foreach (TemplateDefinition templateDefinition in delegateDeclaration.Templates) { - nodeTracker.TrackedVisit(templateDefinition, data); + TrackedVisit(templateDefinition, data); } outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.NewLine(); return null; } - public object VisitOptionDeclaration(OptionDeclaration optionDeclaration, object data) + public override object TrackedVisitOptionDeclaration(OptionDeclaration optionDeclaration, object data) { NotSupported(optionDeclaration); return null; @@ -459,13 +472,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter #endregion #region Type level - public object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) + public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) { if (!fieldDeclaration.TypeReference.IsNull) { VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); OutputModifier(fieldDeclaration.Modifier); - nodeTracker.TrackedVisit(fieldDeclaration.TypeReference, data); + TrackedVisit(fieldDeclaration.TypeReference, data); outputFormatter.Space(); AppendCommaSeparatedList(fieldDeclaration.Fields); outputFormatter.PrintToken(Tokens.Semicolon); @@ -475,9 +488,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); OutputModifier(fieldDeclaration.Modifier); - nodeTracker.TrackedVisit(fieldDeclaration.GetTypeForField(i), data); + TrackedVisit(fieldDeclaration.GetTypeForField(i), data); outputFormatter.Space(); - nodeTracker.TrackedVisit(fieldDeclaration.Fields[i], data); + TrackedVisit(fieldDeclaration.Fields[i], data); outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.NewLine(); } @@ -485,47 +498,47 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) + public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) { outputFormatter.PrintIdentifier(variableDeclaration.Name); if (!variableDeclaration.FixedArrayInitialization.IsNull) { outputFormatter.PrintToken(Tokens.OpenSquareBracket); - nodeTracker.TrackedVisit(variableDeclaration.FixedArrayInitialization, data); + TrackedVisit(variableDeclaration.FixedArrayInitialization, data); outputFormatter.PrintToken(Tokens.CloseSquareBracket); } if (!variableDeclaration.Initializer.IsNull) { outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(variableDeclaration.Initializer, data); + TrackedVisit(variableDeclaration.Initializer, data); } return null; } - public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) + public override object TrackedVisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { VisitAttributes(propertyDeclaration.Attributes, data); outputFormatter.Indent(); propertyDeclaration.Modifier &= ~Modifiers.ReadOnly; OutputModifier(propertyDeclaration.Modifier); - nodeTracker.TrackedVisit(propertyDeclaration.TypeReference, data); + TrackedVisit(propertyDeclaration.TypeReference, data); outputFormatter.Space(); if (propertyDeclaration.InterfaceImplementations.Count > 0) { - nodeTracker.TrackedVisit(propertyDeclaration.InterfaceImplementations[0].InterfaceType, data); + TrackedVisit(propertyDeclaration.InterfaceImplementations[0].InterfaceType, data); outputFormatter.PrintToken(Tokens.Dot); } outputFormatter.PrintIdentifier(propertyDeclaration.Name); outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle); - nodeTracker.TrackedVisit(propertyDeclaration.GetRegion, data); - nodeTracker.TrackedVisit(propertyDeclaration.SetRegion, data); + TrackedVisit(propertyDeclaration.GetRegion, data); + TrackedVisit(propertyDeclaration.SetRegion, data); outputFormatter.EndBrace(); return null; } - public object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) + public override object TrackedVisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) { this.VisitAttributes(propertyGetRegion.Attributes, data); outputFormatter.Indent(); @@ -535,7 +548,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data) + public override object TrackedVisitPropertySetRegion(PropertySetRegion propertySetRegion, object data) { this.VisitAttributes(propertySetRegion.Attributes, data); outputFormatter.Indent(); @@ -545,18 +558,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) + public override object TrackedVisitEventDeclaration(EventDeclaration eventDeclaration, object data) { VisitAttributes(eventDeclaration.Attributes, data); outputFormatter.Indent(); OutputModifier(eventDeclaration.Modifier); outputFormatter.PrintToken(Tokens.Event); outputFormatter.Space(); - nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data); + TrackedVisit(eventDeclaration.TypeReference, data); outputFormatter.Space(); if (eventDeclaration.InterfaceImplementations.Count > 0) { - nodeTracker.TrackedVisit(eventDeclaration.InterfaceImplementations[0].InterfaceType, data); + TrackedVisit(eventDeclaration.InterfaceImplementations[0].InterfaceType, data); outputFormatter.PrintToken(Tokens.Dot); } @@ -566,7 +579,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(eventDeclaration.Initializer, data); + TrackedVisit(eventDeclaration.Initializer, data); } if (eventDeclaration.AddRegion.IsNull && eventDeclaration.RemoveRegion.IsNull) { @@ -574,14 +587,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); } else { outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle); - nodeTracker.TrackedVisit(eventDeclaration.AddRegion, data); - nodeTracker.TrackedVisit(eventDeclaration.RemoveRegion, data); + TrackedVisit(eventDeclaration.AddRegion, data); + TrackedVisit(eventDeclaration.RemoveRegion, data); outputFormatter.EndBrace(); } return null; } - public object VisitEventAddRegion(EventAddRegion eventAddRegion, object data) + public override object TrackedVisitEventAddRegion(EventAddRegion eventAddRegion, object data) { VisitAttributes(eventAddRegion.Attributes, data); outputFormatter.Indent(); @@ -590,7 +603,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data) + public override object TrackedVisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data) { VisitAttributes(eventRemoveRegion.Attributes, data); outputFormatter.Indent(); @@ -599,32 +612,34 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data) + public override object TrackedVisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data) { // VB.NET only NotSupported(eventRaiseRegion); return null; } - public object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) + public override object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) { VisitAttributes(parameterDeclarationExpression.Attributes, data); OutputModifier(parameterDeclarationExpression.ParamModifier, parameterDeclarationExpression); - nodeTracker.TrackedVisit(parameterDeclarationExpression.TypeReference, data); - outputFormatter.Space(); + if (!parameterDeclarationExpression.TypeReference.IsNull) { + TrackedVisit(parameterDeclarationExpression.TypeReference, data); + outputFormatter.Space(); + } outputFormatter.PrintIdentifier(parameterDeclarationExpression.ParameterName); return null; } - public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) + public override object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { VisitAttributes(methodDeclaration.Attributes, data); outputFormatter.Indent(); OutputModifier(methodDeclaration.Modifier); - nodeTracker.TrackedVisit(methodDeclaration.TypeReference, data); + TrackedVisit(methodDeclaration.TypeReference, data); outputFormatter.Space(); if (methodDeclaration.InterfaceImplementations.Count > 0) { - nodeTracker.TrackedVisit(methodDeclaration.InterfaceImplementations[0].InterfaceType, data); + TrackedVisit(methodDeclaration.InterfaceImplementations[0].InterfaceType, data); outputFormatter.PrintToken(Tokens.Dot); } outputFormatter.PrintIdentifier(methodDeclaration.Name); @@ -640,15 +655,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); + if (methodDeclaration.IsExtensionMethod) { + outputFormatter.PrintToken(Tokens.This); + outputFormatter.Space(); + } AppendCommaSeparatedList(methodDeclaration.Parameters); outputFormatter.PrintToken(Tokens.CloseParenthesis); foreach (TemplateDefinition templateDefinition in methodDeclaration.Templates) { - nodeTracker.TrackedVisit(templateDefinition, null); + TrackedVisit(templateDefinition, null); } OutputBlock(methodDeclaration.Body, this.prettyPrintOptions.MethodBraceStyle); } - public object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) + public override object TrackedVisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) { VisitAttributes(operatorDeclaration.Attributes, data); outputFormatter.Indent(); @@ -661,14 +680,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Explicit); } } else { - nodeTracker.TrackedVisit(operatorDeclaration.TypeReference, data); + TrackedVisit(operatorDeclaration.TypeReference, data); } outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Operator); outputFormatter.Space(); if (operatorDeclaration.IsConversionOperator) { - nodeTracker.TrackedVisit(operatorDeclaration.TypeReference, data); + TrackedVisit(operatorDeclaration.TypeReference, data); } else { switch (operatorDeclaration.OverloadableOperator) { case OverloadableOperatorType.Add: @@ -758,12 +777,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) + public override object TrackedVisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) { throw new InvalidOperationException(); } - public object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) + public override object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { VisitAttributes(constructorDeclaration.Attributes, data); outputFormatter.Indent(); @@ -779,12 +798,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.OpenParenthesis); AppendCommaSeparatedList(constructorDeclaration.Parameters); outputFormatter.PrintToken(Tokens.CloseParenthesis); - nodeTracker.TrackedVisit(constructorDeclaration.ConstructorInitializer, data); + TrackedVisit(constructorDeclaration.ConstructorInitializer, data); OutputBlock(constructorDeclaration.Body, this.prettyPrintOptions.ConstructorBraceStyle); return null; } - public object VisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data) + public override object TrackedVisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data) { if (constructorInitializer.IsNull) { return null; @@ -803,15 +822,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) + public override object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { VisitAttributes(indexerDeclaration.Attributes, data); outputFormatter.Indent(); OutputModifier(indexerDeclaration.Modifier); - nodeTracker.TrackedVisit(indexerDeclaration.TypeReference, data); + TrackedVisit(indexerDeclaration.TypeReference, data); outputFormatter.Space(); if (indexerDeclaration.InterfaceImplementations.Count > 0) { - nodeTracker.TrackedVisit(indexerDeclaration.InterfaceImplementations[0].InterfaceType, data); + TrackedVisit(indexerDeclaration.InterfaceImplementations[0].InterfaceType, data); outputFormatter.PrintToken(Tokens.Dot); } outputFormatter.PrintToken(Tokens.This); @@ -829,8 +848,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.OpenCurlyBrace); outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(indexerDeclaration.GetRegion, data); - nodeTracker.TrackedVisit(indexerDeclaration.SetRegion, data); + TrackedVisit(indexerDeclaration.GetRegion, data); + TrackedVisit(indexerDeclaration.SetRegion, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.CloseCurlyBrace); @@ -838,7 +857,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) + public override object TrackedVisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) { VisitAttributes(destructorDeclaration.Attributes, data); outputFormatter.Indent(); @@ -858,7 +877,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data) + public override object TrackedVisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data) { NotSupported(declareDeclaration); return null; @@ -869,7 +888,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter void OutputBlock(BlockStatement blockStatement, BraceStyle braceStyle) { - nodeTracker.BeginNode(blockStatement); + BeginVisit(blockStatement); if (blockStatement.IsNull) { outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.NewLine(); @@ -877,13 +896,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.BeginBrace(braceStyle); foreach (Statement stmt in blockStatement.Children) { outputFormatter.Indent(); - nodeTracker.TrackedVisit(stmt, null); + TrackedVisit(stmt, null); if (!outputFormatter.LastCharacterIsNewLine) outputFormatter.NewLine(); } outputFormatter.EndBrace(); } - nodeTracker.EndNode(blockStatement); + EndVisit(blockStatement); } void OutputBlockAllowInline(BlockStatement blockStatement, BraceStyle braceStyle) @@ -910,7 +929,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.DoIndent = false; outputFormatter.DoNewLine = false; - nodeTracker.TrackedVisit(blockStatement.Children[0], null); + TrackedVisit(blockStatement.Children[0], null); outputFormatter.DoIndent = doIndent; outputFormatter.DoNewLine = doNewLine; @@ -926,7 +945,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object VisitBlockStatement(BlockStatement blockStatement, object data) + public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data) { if (data is BraceStyle) OutputBlock(blockStatement, (BraceStyle)data); @@ -935,29 +954,29 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) + public override object TrackedVisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) { - nodeTracker.TrackedVisit(addHandlerStatement.EventExpression, data); + TrackedVisit(addHandlerStatement.EventExpression, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.PlusAssign); outputFormatter.Space(); - nodeTracker.TrackedVisit(addHandlerStatement.HandlerExpression, data); + TrackedVisit(addHandlerStatement.HandlerExpression, data); outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data) + public override object TrackedVisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data) { - nodeTracker.TrackedVisit(removeHandlerStatement.EventExpression, data); + TrackedVisit(removeHandlerStatement.EventExpression, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.MinusAssign); outputFormatter.Space(); - nodeTracker.TrackedVisit(removeHandlerStatement.HandlerExpression, data); + TrackedVisit(removeHandlerStatement.HandlerExpression, data); outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) + public override object TrackedVisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { outputFormatter.PrintToken(Tokens.If); outputFormatter.Space(); @@ -984,14 +1003,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEraseStatement(EraseStatement eraseStatement, object data) + public override object TrackedVisitEraseStatement(EraseStatement eraseStatement, object data) { for (int i = 0; i < eraseStatement.Expressions.Count; i++) { if (i > 0) { outputFormatter.NewLine(); outputFormatter.Indent(); } - nodeTracker.TrackedVisit(eraseStatement.Expressions[i], data); + TrackedVisit(eraseStatement.Expressions[i], data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); @@ -1001,32 +1020,32 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitErrorStatement(ErrorStatement errorStatement, object data) + public override object TrackedVisitErrorStatement(ErrorStatement errorStatement, object data) { NotSupported(errorStatement); return null; } - public object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) + public override object TrackedVisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) { NotSupported(onErrorStatement); return null; } - public object VisitReDimStatement(ReDimStatement reDimStatement, object data) + public override object TrackedVisitReDimStatement(ReDimStatement reDimStatement, object data) { NotSupported(reDimStatement); return null; } - public object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) + public override object TrackedVisitExpressionStatement(ExpressionStatement expressionStatement, object data) { - nodeTracker.TrackedVisit(expressionStatement.Expression, data); + TrackedVisit(expressionStatement.Expression, data); outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) + public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) { VariableDeclaration v = (VariableDeclaration)localVariableDeclaration.Variables[i]; @@ -1035,55 +1054,55 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Indent(); } OutputModifier(localVariableDeclaration.Modifier); - nodeTracker.TrackedVisit(localVariableDeclaration.GetTypeForVariable(i) ?? new TypeReference("object"), data); + TrackedVisit(localVariableDeclaration.GetTypeForVariable(i) ?? new TypeReference("object"), data); outputFormatter.Space(); - nodeTracker.TrackedVisit(v, data); + TrackedVisit(v, data); outputFormatter.PrintToken(Tokens.Semicolon); } return null; } - public object VisitEmptyStatement(EmptyStatement emptyStatement, object data) + public override object TrackedVisitEmptyStatement(EmptyStatement emptyStatement, object data) { outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitYieldStatement(YieldStatement yieldStatement, object data) + public override object TrackedVisitYieldStatement(YieldStatement yieldStatement, object data) { Debug.Assert(yieldStatement != null); Debug.Assert(yieldStatement.Statement != null); outputFormatter.PrintText("yield"); outputFormatter.Space(); - nodeTracker.TrackedVisit(yieldStatement.Statement, data); + TrackedVisit(yieldStatement.Statement, data); return null; } - public object VisitReturnStatement(ReturnStatement returnStatement, object data) + public override object TrackedVisitReturnStatement(ReturnStatement returnStatement, object data) { outputFormatter.PrintToken(Tokens.Return); if (!returnStatement.Expression.IsNull) { outputFormatter.Space(); - nodeTracker.TrackedVisit(returnStatement.Expression, data); + TrackedVisit(returnStatement.Expression, data); } outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) + public override object TrackedVisitIfElseStatement(IfElseStatement ifElseStatement, object data) { outputFormatter.PrintToken(Tokens.If); if (this.prettyPrintOptions.IfParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(ifElseStatement.Condition, data); + TrackedVisit(ifElseStatement.Condition, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); PrintIfSection(ifElseStatement.TrueStatement); foreach (ElseIfSection elseIfSection in ifElseStatement.ElseIfSections) { - nodeTracker.TrackedVisit(elseIfSection, data); + TrackedVisit(elseIfSection, data); } if (ifElseStatement.HasElseStatements) { @@ -1104,7 +1123,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.OpenCurlyBrace); } foreach (Statement stmt in statements) { - nodeTracker.TrackedVisit(stmt, null); + TrackedVisit(stmt, null); } if (statements.Count != 1) { outputFormatter.PrintToken(Tokens.CloseCurlyBrace); @@ -1114,7 +1133,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object VisitElseIfSection(ElseIfSection elseIfSection, object data) + public override object TrackedVisitElseIfSection(ElseIfSection elseIfSection, object data) { outputFormatter.PrintToken(Tokens.Else); outputFormatter.Space(); @@ -1123,7 +1142,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(elseIfSection.Condition, data); + TrackedVisit(elseIfSection.Condition, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); WriteEmbeddedStatement(elseIfSection.EmbeddedStatement); @@ -1131,7 +1150,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitForStatement(ForStatement forStatement, object data) + public override object TrackedVisitForStatement(ForStatement forStatement, object data) { outputFormatter.PrintToken(Tokens.For); if (this.prettyPrintOptions.ForParentheses) { @@ -1143,7 +1162,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.EmitSemicolon = false; for (int i = 0; i < forStatement.Initializers.Count; ++i) { INode node = (INode)forStatement.Initializers[i]; - nodeTracker.TrackedVisit(node, data); + TrackedVisit(node, data); if (i + 1 < forStatement.Initializers.Count) { outputFormatter.PrintToken(Tokens.Comma); } @@ -1155,7 +1174,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (this.prettyPrintOptions.SpacesAfterSemicolon) { outputFormatter.Space(); } - nodeTracker.TrackedVisit(forStatement.Condition, data); + TrackedVisit(forStatement.Condition, data); } outputFormatter.EmitSemicolon = true; outputFormatter.PrintToken(Tokens.Semicolon); @@ -1167,7 +1186,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter for (int i = 0; i < forStatement.Iterator.Count; ++i) { INode node = (INode)forStatement.Iterator[i]; - nodeTracker.TrackedVisit(node, data); + TrackedVisit(node, data); if (i + 1 < forStatement.Iterator.Count) { outputFormatter.PrintToken(Tokens.Comma); } @@ -1186,24 +1205,24 @@ namespace ICSharpCode.NRefactory.PrettyPrinter void WriteEmbeddedStatement(Statement statement) { if (statement is BlockStatement) { - nodeTracker.TrackedVisit(statement, prettyPrintOptions.StatementBraceStyle); + TrackedVisit(statement, prettyPrintOptions.StatementBraceStyle); } else { ++outputFormatter.IndentationLevel; outputFormatter.NewLine(); - nodeTracker.TrackedVisit(statement, null); + TrackedVisit(statement, null); outputFormatter.NewLine(); --outputFormatter.IndentationLevel; } } - public object VisitLabelStatement(LabelStatement labelStatement, object data) + public override object TrackedVisitLabelStatement(LabelStatement labelStatement, object data) { outputFormatter.PrintIdentifier(labelStatement.Label); outputFormatter.PrintToken(Tokens.Colon); return null; } - public object VisitGotoStatement(GotoStatement gotoStatement, object data) + public override object TrackedVisitGotoStatement(GotoStatement gotoStatement, object data) { outputFormatter.PrintToken(Tokens.Goto); outputFormatter.Space(); @@ -1212,21 +1231,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitSwitchStatement(SwitchStatement switchStatement, object data) + public override object TrackedVisitSwitchStatement(SwitchStatement switchStatement, object data) { outputFormatter.PrintToken(Tokens.Switch); if (this.prettyPrintOptions.SwitchParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(switchStatement.SwitchExpression, data); + TrackedVisit(switchStatement.SwitchExpression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.OpenCurlyBrace); outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; foreach (SwitchSection section in switchStatement.SwitchSections) { - nodeTracker.TrackedVisit(section, data); + TrackedVisit(section, data); } --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -1234,16 +1253,16 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitSwitchSection(SwitchSection switchSection, object data) + public override object TrackedVisitSwitchSection(SwitchSection switchSection, object data) { foreach (CaseLabel label in switchSection.SwitchLabels) { - nodeTracker.TrackedVisit(label, data); + TrackedVisit(label, data); } ++outputFormatter.IndentationLevel; foreach (Statement stmt in switchSection.Children) { outputFormatter.Indent(); - nodeTracker.TrackedVisit(stmt, data); + TrackedVisit(stmt, data); outputFormatter.NewLine(); } @@ -1262,7 +1281,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitCaseLabel(CaseLabel caseLabel, object data) + public override object TrackedVisitCaseLabel(CaseLabel caseLabel, object data) { outputFormatter.Indent(); if (caseLabel.IsDefault) { @@ -1273,7 +1292,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (caseLabel.BinaryOperatorType != BinaryOperatorType.None) { Error(caseLabel, String.Format("Case labels with binary operators are unsupported : {0}", caseLabel.BinaryOperatorType)); } - nodeTracker.TrackedVisit(caseLabel.Label, data); + TrackedVisit(caseLabel.Label, data); } outputFormatter.PrintToken(Tokens.Colon); if (!caseLabel.ToExpression.IsNull) { @@ -1293,52 +1312,52 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } else { outputFormatter.PrintText(" // TODO: to "); - nodeTracker.TrackedVisit(caseLabel.ToExpression, data); + TrackedVisit(caseLabel.ToExpression, data); } } else { outputFormatter.PrintText(" // TODO: to "); - nodeTracker.TrackedVisit(caseLabel.ToExpression, data); + TrackedVisit(caseLabel.ToExpression, data); } } outputFormatter.NewLine(); return null; } - public object VisitBreakStatement(BreakStatement breakStatement, object data) + public override object TrackedVisitBreakStatement(BreakStatement breakStatement, object data) { outputFormatter.PrintToken(Tokens.Break); outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitStopStatement(StopStatement stopStatement, object data) + public override object TrackedVisitStopStatement(StopStatement stopStatement, object data) { outputFormatter.PrintText("System.Diagnostics.Debugger.Break()"); outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitResumeStatement(ResumeStatement resumeStatement, object data) + public override object TrackedVisitResumeStatement(ResumeStatement resumeStatement, object data) { NotSupported(resumeStatement); return null; } - public object VisitEndStatement(EndStatement endStatement, object data) + public override object TrackedVisitEndStatement(EndStatement endStatement, object data) { outputFormatter.PrintText("System.Environment.Exit(0)"); outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitContinueStatement(ContinueStatement continueStatement, object data) + public override object TrackedVisitContinueStatement(ContinueStatement continueStatement, object data) { outputFormatter.PrintToken(Tokens.Continue); outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) + public override object TrackedVisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) { outputFormatter.PrintToken(Tokens.Goto); outputFormatter.Space(); @@ -1347,7 +1366,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } else { outputFormatter.PrintToken(Tokens.Case); outputFormatter.Space(); - nodeTracker.TrackedVisit(gotoCaseStatement.Expression, data); + TrackedVisit(gotoCaseStatement.Expression, data); } outputFormatter.PrintToken(Tokens.Semicolon); return null; @@ -1369,7 +1388,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (doLoopStatement.Condition.IsNull) { outputFormatter.PrintToken(Tokens.True); } else { - nodeTracker.TrackedVisit(doLoopStatement.Condition, null); + TrackedVisit(doLoopStatement.Condition, null); } if (doLoopStatement.ConditionType == ConditionType.Until) { @@ -1378,7 +1397,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.CloseParenthesis); } - public object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) + public override object TrackedVisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) { if (doLoopStatement.ConditionPosition == ConditionPosition.None) { Error(doLoopStatement, String.Format("Unknown condition position for loop : {0}.", doLoopStatement)); @@ -1402,20 +1421,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitForeachStatement(ForeachStatement foreachStatement, object data) + public override object TrackedVisitForeachStatement(ForeachStatement foreachStatement, object data) { outputFormatter.PrintToken(Tokens.Foreach); if (this.prettyPrintOptions.ForeachParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(foreachStatement.TypeReference, data); + TrackedVisit(foreachStatement.TypeReference, data); outputFormatter.Space(); outputFormatter.PrintIdentifier(foreachStatement.VariableName); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.In); outputFormatter.Space(); - nodeTracker.TrackedVisit(foreachStatement.Expression, data); + TrackedVisit(foreachStatement.Expression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); WriteEmbeddedStatement(foreachStatement.EmbeddedStatement); @@ -1423,14 +1442,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitLockStatement(LockStatement lockStatement, object data) + public override object TrackedVisitLockStatement(LockStatement lockStatement, object data) { outputFormatter.PrintToken(Tokens.Lock); if (this.prettyPrintOptions.LockParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(lockStatement.LockExpression, data); + TrackedVisit(lockStatement.LockExpression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); WriteEmbeddedStatement(lockStatement.EmbeddedStatement); @@ -1438,7 +1457,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitUsingStatement(UsingStatement usingStatement, object data) + public override object TrackedVisitUsingStatement(UsingStatement usingStatement, object data) { outputFormatter.PrintToken(Tokens.Using); if (this.prettyPrintOptions.UsingParentheses) { @@ -1449,7 +1468,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.DoNewLine = false; outputFormatter.EmitSemicolon = false; - nodeTracker.TrackedVisit(usingStatement.ResourceAcquisition, data); + TrackedVisit(usingStatement.ResourceAcquisition, data); outputFormatter.DoIndent = true; outputFormatter.DoNewLine = true; outputFormatter.EmitSemicolon = true; @@ -1461,21 +1480,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitWithStatement(WithStatement withStatement, object data) + public override object TrackedVisitWithStatement(WithStatement withStatement, object data) { withExpressionStack.Push(withStatement); - nodeTracker.TrackedVisit(withStatement.Body, BraceStyle.EndOfLine); + TrackedVisit(withStatement.Body, BraceStyle.EndOfLine); withExpressionStack.Pop(); return null; } - public object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) + public override object TrackedVisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) { outputFormatter.PrintToken(Tokens.Try); WriteEmbeddedStatement(tryCatchStatement.StatementBlock); foreach (CatchClause catchClause in tryCatchStatement.CatchClauses) { - nodeTracker.TrackedVisit(catchClause, data); + TrackedVisit(catchClause, data); } if (!tryCatchStatement.FinallyBlock.IsNull) { @@ -1486,7 +1505,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitCatchClause(CatchClause catchClause, object data) + public override object TrackedVisitCatchClause(CatchClause catchClause, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Catch); @@ -1507,25 +1526,25 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitThrowStatement(ThrowStatement throwStatement, object data) + public override object TrackedVisitThrowStatement(ThrowStatement throwStatement, object data) { outputFormatter.PrintToken(Tokens.Throw); if (!throwStatement.Expression.IsNull) { outputFormatter.Space(); - nodeTracker.TrackedVisit(throwStatement.Expression, data); + TrackedVisit(throwStatement.Expression, data); } outputFormatter.PrintToken(Tokens.Semicolon); return null; } - public object VisitFixedStatement(FixedStatement fixedStatement, object data) + public override object TrackedVisitFixedStatement(FixedStatement fixedStatement, object data) { outputFormatter.PrintToken(Tokens.Fixed); if (this.prettyPrintOptions.FixedParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(fixedStatement.TypeReference, data); + TrackedVisit(fixedStatement.TypeReference, data); outputFormatter.Space(); AppendCommaSeparatedList(fixedStatement.PointerDeclarators); outputFormatter.PrintToken(Tokens.CloseParenthesis); @@ -1534,28 +1553,28 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitUnsafeStatement(UnsafeStatement unsafeStatement, object data) + public override object TrackedVisitUnsafeStatement(UnsafeStatement unsafeStatement, object data) { outputFormatter.PrintToken(Tokens.Unsafe); WriteEmbeddedStatement(unsafeStatement.Block); return null; } - public object VisitCheckedStatement(CheckedStatement checkedStatement, object data) + public override object TrackedVisitCheckedStatement(CheckedStatement checkedStatement, object data) { outputFormatter.PrintToken(Tokens.Checked); WriteEmbeddedStatement(checkedStatement.Block); return null; } - public object VisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data) + public override object TrackedVisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data) { outputFormatter.PrintToken(Tokens.Unchecked); WriteEmbeddedStatement(uncheckedStatement.Block); return null; } - public object VisitExitStatement(ExitStatement exitStatement, object data) + public override object TrackedVisitExitStatement(ExitStatement exitStatement, object data) { if (exitStatement.ExitType == ExitType.Function || exitStatement.ExitType == ExitType.Sub || exitStatement.ExitType == ExitType.Property) { outputFormatter.PrintToken(Tokens.Return); @@ -1568,20 +1587,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitForNextStatement(ForNextStatement forNextStatement, object data) + public override object TrackedVisitForNextStatement(ForNextStatement forNextStatement, object data) { outputFormatter.PrintToken(Tokens.For); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.OpenParenthesis); if (!forNextStatement.TypeReference.IsNull) { - nodeTracker.TrackedVisit(forNextStatement.TypeReference, data); + TrackedVisit(forNextStatement.TypeReference, data); outputFormatter.Space(); } outputFormatter.PrintIdentifier(forNextStatement.VariableName); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(forNextStatement.Start, data); + TrackedVisit(forNextStatement.Start, data); outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.Space(); outputFormatter.PrintIdentifier(forNextStatement.VariableName); @@ -1593,7 +1612,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter else outputFormatter.PrintToken(Tokens.GreaterEqual); outputFormatter.Space(); - nodeTracker.TrackedVisit(forNextStatement.End, data); + TrackedVisit(forNextStatement.End, data); outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.Space(); outputFormatter.PrintIdentifier(forNextStatement.VariableName); @@ -1603,7 +1622,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.PlusAssign); outputFormatter.Space(); - nodeTracker.TrackedVisit(forNextStatement.Step, data); + TrackedVisit(forNextStatement.Step, data); } outputFormatter.PrintToken(Tokens.CloseParenthesis); @@ -1613,7 +1632,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter #endregion #region Expressions - public object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data) + public override object TrackedVisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data) { NotSupported(classReferenceExpression); return null; @@ -1667,7 +1686,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return sb.ToString(); } - public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) + public override object TrackedVisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) { if (primitiveExpression.Value == null) { outputFormatter.PrintToken(Tokens.Null); @@ -1736,7 +1755,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return pe.Value == null; } - public object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) + public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { // VB-operators that require special representation: switch (binaryOperatorExpression.Op) { @@ -1755,9 +1774,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); + TrackedVisit(binaryOperatorExpression.Left, data); PrintFormattedComma(); - nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data); + TrackedVisit(binaryOperatorExpression.Right, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; case BinaryOperatorType.Power: @@ -1766,13 +1785,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); + TrackedVisit(binaryOperatorExpression.Left, data); PrintFormattedComma(); - nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data); + TrackedVisit(binaryOperatorExpression.Right, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); + TrackedVisit(binaryOperatorExpression.Left, data); switch (binaryOperatorExpression.Op) { case BinaryOperatorType.Add: case BinaryOperatorType.Concat: // translate Concatenation to + @@ -1964,21 +1983,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter Error(binaryOperatorExpression, String.Format("Unknown binary operator {0}", binaryOperatorExpression.Op)); return null; } - nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data); + TrackedVisit(binaryOperatorExpression.Right, data); return null; } - public object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) + public override object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) { outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(parenthesizedExpression.Expression, data); + TrackedVisit(parenthesizedExpression.Expression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitInvocationExpression(InvocationExpression invocationExpression, object data) + public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data) { - nodeTracker.TrackedVisit(invocationExpression.TargetObject, data); + TrackedVisit(invocationExpression.TargetObject, data); if (invocationExpression.TypeArguments != null && invocationExpression.TypeArguments.Count > 0) { outputFormatter.PrintToken(Tokens.LessThan); @@ -1996,19 +2015,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) + public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { outputFormatter.PrintIdentifier(identifierExpression.Identifier); return null; } - public object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) + public override object TrackedVisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) { - nodeTracker.TrackedVisit(typeReferenceExpression.TypeReference, data); + TrackedVisit(typeReferenceExpression.TypeReference, data); return null; } - public object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) + public override object TrackedVisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { switch (unaryOperatorExpression.Op) { case UnaryOperatorType.BitNot: @@ -2030,11 +2049,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Plus); break; case UnaryOperatorType.PostDecrement: - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintToken(Tokens.Decrement); return null; case UnaryOperatorType.PostIncrement: - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintToken(Tokens.Increment); return null; case UnaryOperatorType.Star: @@ -2047,13 +2066,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter Error(unaryOperatorExpression, String.Format("Unknown unary operator {0}", unaryOperatorExpression.Op)); return null; } - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); return null; } - public object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) + public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { - nodeTracker.TrackedVisit(assignmentExpression.Left, data); + TrackedVisit(assignmentExpression.Left, data); if (this.prettyPrintOptions.AroundAssignmentParentheses) { outputFormatter.Space(); } @@ -2109,63 +2128,63 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (this.prettyPrintOptions.AroundAssignmentParentheses) { outputFormatter.Space(); } - nodeTracker.TrackedVisit(assignmentExpression.Right, data); + TrackedVisit(assignmentExpression.Right, data); return null; } - public object VisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data) + public override object TrackedVisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data) { outputFormatter.PrintToken(Tokens.Sizeof); if (prettyPrintOptions.SizeOfParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(sizeOfExpression.TypeReference, data); + TrackedVisit(sizeOfExpression.TypeReference, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data) + public override object TrackedVisitTypeOfExpression(TypeOfExpression typeOfExpression, object data) { outputFormatter.PrintToken(Tokens.Typeof); if (prettyPrintOptions.TypeOfParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(typeOfExpression.TypeReference, data); + TrackedVisit(typeOfExpression.TypeReference, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data) + public override object TrackedVisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data) { outputFormatter.PrintToken(Tokens.Default); if (prettyPrintOptions.TypeOfParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(defaultValueExpression.TypeReference, data); + TrackedVisit(defaultValueExpression.TypeReference, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) + public override object TrackedVisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { - nodeTracker.TrackedVisit(typeOfIsExpression.Expression, data); + TrackedVisit(typeOfIsExpression.Expression, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Is); outputFormatter.Space(); - nodeTracker.TrackedVisit(typeOfIsExpression.TypeReference, data); + TrackedVisit(typeOfIsExpression.TypeReference, data); return null; } - public object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) + public override object TrackedVisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) { // C# 2.0 can reference methods directly - return nodeTracker.TrackedVisit(addressOfExpression.Expression, data); + return TrackedVisit(addressOfExpression.Expression, data); } - public object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) + public override object TrackedVisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) { outputFormatter.PrintToken(Tokens.Delegate); @@ -2178,7 +2197,29 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitCheckedExpression(CheckedExpression checkedExpression, object data) + public override object TrackedVisitLambdaExpression(LambdaExpression lambdaExpression, object data) + { + if (lambdaExpression.Parameters.Count == 1 && lambdaExpression.Parameters[0].TypeReference.IsNull) { + // short syntax + outputFormatter.PrintIdentifier(lambdaExpression.Parameters[0].ParameterName); + } else { + outputFormatter.PrintToken(Tokens.OpenParenthesis); + AppendCommaSeparatedList(lambdaExpression.Parameters); + outputFormatter.PrintToken(Tokens.CloseParenthesis); + } + outputFormatter.Space(); + outputFormatter.PrintToken(Tokens.LambdaArrow); + outputFormatter.Space(); + if (!lambdaExpression.ExpressionBody.IsNull) { + TrackedVisit(lambdaExpression.ExpressionBody, null); + } + if (!lambdaExpression.StatementBody.IsNull) { + OutputBlockAllowInline(lambdaExpression.StatementBody, this.prettyPrintOptions.MethodBraceStyle, false); + } + return null; + } + + public override object TrackedVisitCheckedExpression(CheckedExpression checkedExpression, object data) { outputFormatter.PrintToken(Tokens.Checked); if (prettyPrintOptions.CheckedParentheses) { @@ -2186,61 +2227,61 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(checkedExpression.Expression, data); + TrackedVisit(checkedExpression.Expression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data) + public override object TrackedVisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data) { outputFormatter.PrintToken(Tokens.Unchecked); if (prettyPrintOptions.UncheckedParentheses) { outputFormatter.Space(); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(uncheckedExpression.Expression, data); + TrackedVisit(uncheckedExpression.Expression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) + public override object TrackedVisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) { - nodeTracker.TrackedVisit(pointerReferenceExpression.TargetObject, data); + TrackedVisit(pointerReferenceExpression.TargetObject, data); outputFormatter.PrintToken(Tokens.Pointer); outputFormatter.PrintIdentifier(pointerReferenceExpression.Identifier); return null; } - public object VisitCastExpression(CastExpression castExpression, object data) + public override object TrackedVisitCastExpression(CastExpression castExpression, object data) { if (castExpression.CastType == CastType.TryCast) { - nodeTracker.TrackedVisit(castExpression.Expression, data); + TrackedVisit(castExpression.Expression, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(castExpression.CastTo, data); + TrackedVisit(castExpression.CastTo, data); } else { outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(castExpression.CastTo, data); + TrackedVisit(castExpression.CastTo, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); if (this.prettyPrintOptions.SpacesAfterTypecast) { outputFormatter.Space(); } - nodeTracker.TrackedVisit(castExpression.Expression, data); + TrackedVisit(castExpression.Expression, data); } return null; } - public object VisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data) + public override object TrackedVisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data) { outputFormatter.PrintToken(Tokens.Stackalloc); outputFormatter.Space(); - nodeTracker.TrackedVisit(stackAllocExpression.TypeReference, data); + TrackedVisit(stackAllocExpression.TypeReference, data); outputFormatter.PrintToken(Tokens.OpenSquareBracket); if (this.prettyPrintOptions.SpacesWithinBrackets) { outputFormatter.Space(); } - nodeTracker.TrackedVisit(stackAllocExpression.Expression, data); + TrackedVisit(stackAllocExpression.Expression, data); if (this.prettyPrintOptions.SpacesWithinBrackets) { outputFormatter.Space(); } @@ -2248,9 +2289,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitIndexerExpression(IndexerExpression indexerExpression, object data) + public override object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data) { - nodeTracker.TrackedVisit(indexerExpression.TargetObject, data); + TrackedVisit(indexerExpression.TargetObject, data); outputFormatter.PrintToken(Tokens.OpenSquareBracket); if (this.prettyPrintOptions.SpacesWithinBrackets) { outputFormatter.Space(); @@ -2263,63 +2304,76 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) + public override object TrackedVisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) { outputFormatter.PrintToken(Tokens.This); return null; } - public object VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data) { + public override object TrackedVisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data) { outputFormatter.PrintToken(Tokens.Base); return null; } - public object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) + public override object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { outputFormatter.PrintToken(Tokens.New); - outputFormatter.Space(); - nodeTracker.TrackedVisit(objectCreateExpression.CreateType, data); - if (prettyPrintOptions.NewParentheses) { + if (!objectCreateExpression.CreateType.IsNull) { outputFormatter.Space(); + TrackedVisit(objectCreateExpression.CreateType, data); + } + if (objectCreateExpression.Parameters.Count > 0 || objectCreateExpression.ObjectInitializer.IsNull) { + if (prettyPrintOptions.NewParentheses) { + outputFormatter.Space(); + } + outputFormatter.PrintToken(Tokens.OpenParenthesis); + AppendCommaSeparatedList(objectCreateExpression.Parameters); + outputFormatter.PrintToken(Tokens.CloseParenthesis); + } + if (!objectCreateExpression.ObjectInitializer.IsNull) { + outputFormatter.Space(); + TrackedVisit(objectCreateExpression.ObjectInitializer, data); } - outputFormatter.PrintToken(Tokens.OpenParenthesis); - AppendCommaSeparatedList(objectCreateExpression.Parameters); - outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) + public override object TrackedVisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { outputFormatter.PrintToken(Tokens.New); - outputFormatter.Space(); - PrintTypeReferenceWithoutArray(arrayCreateExpression.CreateType); - - if (arrayCreateExpression.Arguments.Count > 0) { + if (arrayCreateExpression.IsImplicitlyTyped) { outputFormatter.PrintToken(Tokens.OpenSquareBracket); - if (this.prettyPrintOptions.SpacesWithinBrackets) { - outputFormatter.Space(); - } - for (int i = 0; i < arrayCreateExpression.Arguments.Count; ++i) { - if (i > 0) PrintFormattedComma(); - nodeTracker.TrackedVisit(arrayCreateExpression.Arguments[i], data); - } - if (this.prettyPrintOptions.SpacesWithinBrackets) { - outputFormatter.Space(); - } outputFormatter.PrintToken(Tokens.CloseSquareBracket); - PrintArrayRank(arrayCreateExpression.CreateType.RankSpecifier, 1); } else { - PrintArrayRank(arrayCreateExpression.CreateType.RankSpecifier, 0); + outputFormatter.Space(); + PrintTypeReferenceWithoutArray(arrayCreateExpression.CreateType); + + if (arrayCreateExpression.Arguments.Count > 0) { + outputFormatter.PrintToken(Tokens.OpenSquareBracket); + if (this.prettyPrintOptions.SpacesWithinBrackets) { + outputFormatter.Space(); + } + for (int i = 0; i < arrayCreateExpression.Arguments.Count; ++i) { + if (i > 0) PrintFormattedComma(); + TrackedVisit(arrayCreateExpression.Arguments[i], data); + } + if (this.prettyPrintOptions.SpacesWithinBrackets) { + outputFormatter.Space(); + } + outputFormatter.PrintToken(Tokens.CloseSquareBracket); + PrintArrayRank(arrayCreateExpression.CreateType.RankSpecifier, 1); + } else { + PrintArrayRank(arrayCreateExpression.CreateType.RankSpecifier, 0); + } } if (!arrayCreateExpression.ArrayInitializer.IsNull) { outputFormatter.Space(); - nodeTracker.TrackedVisit(arrayCreateExpression.ArrayInitializer, data); + TrackedVisit(arrayCreateExpression.ArrayInitializer, data); } return null; } - public object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) + public override object TrackedVisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) { Expression target = fieldReferenceExpression.TargetObject; if (target.IsNull && withExpressionStack.Count > 0) { @@ -2329,7 +2383,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (target is BinaryOperatorExpression || target is CastExpression) { outputFormatter.PrintToken(Tokens.OpenParenthesis); } - nodeTracker.TrackedVisit(target, data); + TrackedVisit(target, data); if (target is BinaryOperatorExpression || target is CastExpression) { outputFormatter.PrintToken(Tokens.CloseParenthesis); } @@ -2338,7 +2392,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitDirectionExpression(DirectionExpression directionExpression, object data) + public override object TrackedVisitDirectionExpression(DirectionExpression directionExpression, object data) { switch (directionExpression.FieldDirection) { case FieldDirection.Out: @@ -2350,21 +2404,23 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); break; } - nodeTracker.TrackedVisit(directionExpression.Expression, data); + TrackedVisit(directionExpression.Expression, data); return null; } - public object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data) + public override object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression arrayInitializerExpression, object data) { outputFormatter.PrintToken(Tokens.OpenCurlyBrace); + outputFormatter.Space(); this.AppendCommaSeparatedList(arrayInitializerExpression.CreateExpressions); + outputFormatter.Space(); outputFormatter.PrintToken(Tokens.CloseCurlyBrace); return null; } - public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) + public override object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data) { - nodeTracker.TrackedVisit(conditionalExpression.Condition, data); + TrackedVisit(conditionalExpression.Condition, data); if (this.prettyPrintOptions.ConditionalOperatorBeforeConditionSpace) { outputFormatter.Space(); } @@ -2372,7 +2428,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (this.prettyPrintOptions.ConditionalOperatorAfterConditionSpace) { outputFormatter.Space(); } - nodeTracker.TrackedVisit(conditionalExpression.TrueExpression, data); + TrackedVisit(conditionalExpression.TrueExpression, data); if (this.prettyPrintOptions.ConditionalOperatorBeforeSeparatorSpace) { outputFormatter.Space(); } @@ -2380,7 +2436,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (this.prettyPrintOptions.ConditionalOperatorAfterSeparatorSpace) { outputFormatter.Space(); } - nodeTracker.TrackedVisit(conditionalExpression.FalseExpression, data); + TrackedVisit(conditionalExpression.FalseExpression, data); return null; } @@ -2472,12 +2528,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } + object TrackedVisit(INode node, object data) + { + return node.AcceptVisitor(this, data); + } + public void AppendCommaSeparatedList(ICollection list) where T : class, INode { if (list != null) { int i = 0; foreach (T node in list) { - nodeTracker.TrackedVisit(node, null); + node.AcceptVisitor(this, null); if (i + 1 < list.Count) { PrintFormattedComma(); } @@ -2489,5 +2550,96 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } } + + public override object TrackedVisitQueryExpression(QueryExpression queryExpression, object data) + { + outputFormatter.IndentationLevel++; + queryExpression.FromClause.AcceptVisitor(this, data); + queryExpression.FromOrWhereClauses.ForEach(PrintClause); + if (queryExpression.Orderings.Count > 0) { + outputFormatter.NewLine(); + outputFormatter.Indent(); + outputFormatter.PrintToken(Tokens.Orderby); + outputFormatter.Space(); + AppendCommaSeparatedList(queryExpression.Orderings); + } + PrintClause(queryExpression.SelectOrGroupClause); + PrintClause(queryExpression.IntoClause); + outputFormatter.IndentationLevel--; + return null; + } + + void PrintClause(QueryExpressionClause clause) + { + if (!clause.IsNull) { + outputFormatter.NewLine(); + outputFormatter.Indent(); + clause.AcceptVisitor(this, null); + } + } + + public override object TrackedVisitQueryExpressionFromClause(QueryExpressionFromClause fromClause, object data) + { + outputFormatter.PrintToken(Tokens.From); + outputFormatter.Space(); + AppendCommaSeparatedList(fromClause.Generators); + return null; + } + + public override object TrackedVisitQueryExpressionFromGenerator(QueryExpressionFromGenerator fromGenerator, object data) + { + outputFormatter.PrintIdentifier(fromGenerator.Identifier); + outputFormatter.Space(); + outputFormatter.PrintToken(Tokens.In); + outputFormatter.Space(); + return fromGenerator.InExpression.AcceptVisitor(this, data); + } + + public override object TrackedVisitQueryExpressionGroupClause(QueryExpressionGroupClause groupClause, object data) + { + outputFormatter.PrintToken(Tokens.Group); + outputFormatter.Space(); + groupClause.Projection.AcceptVisitor(this, data); + outputFormatter.Space(); + outputFormatter.PrintToken(Tokens.By); + outputFormatter.Space(); + return groupClause.GroupBy.AcceptVisitor(this, data); + } + + public override object TrackedVisitQueryExpressionIntoClause(QueryExpressionIntoClause intoClause, object data) + { + outputFormatter.PrintToken(Tokens.Into); + outputFormatter.Space(); + outputFormatter.PrintIdentifier(intoClause.IntoIdentifier); + outputFormatter.Space(); + return intoClause.ContinuedQuery.AcceptVisitor(this, data); + } + + public override object TrackedVisitQueryExpressionOrdering(QueryExpressionOrdering ordering, object data) + { + ordering.Criteria.AcceptVisitor(this, data); + if (ordering.Direction == QueryExpressionOrderingDirection.Ascending) { + outputFormatter.Space(); + outputFormatter.PrintToken(Tokens.Ascending); + } else if (ordering.Direction == QueryExpressionOrderingDirection.Descending) { + outputFormatter.Space(); + outputFormatter.PrintToken(Tokens.Descending); + } + return null; + } + + public override object TrackedVisitQueryExpressionSelectClause(QueryExpressionSelectClause selectClause, object data) + { + outputFormatter.PrintToken(Tokens.Select); + outputFormatter.Space(); + return selectClause.Projection.AcceptVisitor(this, data); + } + + public override object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause whereClause, object data) + { + outputFormatter.PrintToken(Tokens.Where); + outputFormatter.Space(); + return whereClause.Condition.AcceptVisitor(this, data); + } } } diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/IOutputAstVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/IOutputAstVisitor.cs index 8d8435b179..5b710e082a 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/IOutputAstVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/IOutputAstVisitor.cs @@ -7,6 +7,7 @@ using System; using ICSharpCode.NRefactory.Parser; +using ICSharpCode.NRefactory.Ast; namespace ICSharpCode.NRefactory.PrettyPrinter { @@ -15,9 +16,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter ///

public interface IOutputAstVisitor : IAstVisitor { - NodeTracker NodeTracker { - get; - } + event Action BeforeNodeVisit; + event Action AfterNodeVisit; string Text { get; @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter get; } - object Options { + AbstractPrettyPrintOptions Options { get; set; } diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/NodeInformVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/NodeInformVisitor.cs deleted file mode 100644 index 6b0587a561..0000000000 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/NodeInformVisitor.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using ICSharpCode.NRefactory.Ast; - -namespace ICSharpCode.NRefactory.PrettyPrinter -{ - public delegate void InformNode(INode node); - - public class NodeTracker - { - IAstVisitor callVisitor; - - public IAstVisitor CallVisitor { - get { - return callVisitor; - } - } - - public NodeTracker(IAstVisitor callVisitor) - { - this.callVisitor = callVisitor; - } - - public void BeginNode(INode node) - { - if (NodeVisiting != null) { - NodeVisiting(node); - } - } - - public void EndNode(INode node) - { - if (NodeVisited != null) { - NodeVisited(node); - } - } - - public object TrackedVisit(INode node, object data) - { - BeginNode(node); - object ret = node.AcceptVisitor(callVisitor, data); - EndNode(node); - return ret; - } - - public object TrackedVisitChildren(INode node, object data) - { - foreach (INode child in node.Children) { - TrackedVisit(child, data); - } - if (NodeChildrenVisited != null) { - NodeChildrenVisited(node); - } - return data; - } - - public event InformNode NodeVisiting; - public event InformNode NodeChildrenVisited; - public event InformNode NodeVisited; - } -} diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/SpecialNodesInserter.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/SpecialNodesInserter.cs index 3957454817..b3ddd6f1dc 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/SpecialNodesInserter.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/SpecialNodesInserter.cs @@ -122,8 +122,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter public static SpecialNodesInserter Install(IEnumerable specials, IOutputAstVisitor outputVisitor) { SpecialNodesInserter sni = new SpecialNodesInserter(specials, new SpecialOutputVisitor(outputVisitor.OutputFormatter)); - outputVisitor.NodeTracker.NodeVisiting += sni.AcceptNodeStart; - outputVisitor.NodeTracker.NodeVisited += sni.AcceptNodeEnd; + outputVisitor.BeforeNodeVisit += sni.AcceptNodeStart; + outputVisitor.AfterNodeVisit += sni.AcceptNodeEnd; return sni; } } diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs index f79b2348aa..99abfc843a 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs @@ -15,15 +15,15 @@ using System.Text; using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Parser; using ICSharpCode.NRefactory.Parser.VB; +using ICSharpCode.NRefactory.Visitors; namespace ICSharpCode.NRefactory.PrettyPrinter { - public class VBNetOutputVisitor : IOutputAstVisitor + public sealed class VBNetOutputVisitor : NodeTrackingAstVisitor, IOutputAstVisitor { Errors errors = new Errors(); VBNetOutputFormatter outputFormatter; VBNetPrettyPrintOptions prettyPrintOptions = new VBNetPrettyPrintOptions(); - NodeTracker nodeTracker; TypeDeclaration currentType; bool printFullSystemType; @@ -41,19 +41,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object Options { - get { - return prettyPrintOptions; - } - set { - prettyPrintOptions = value as VBNetPrettyPrintOptions; - } + AbstractPrettyPrintOptions IOutputAstVisitor.Options { + get { return prettyPrintOptions; } + set { prettyPrintOptions = (VBNetPrettyPrintOptions)value; } } - public NodeTracker NodeTracker { - get { - return nodeTracker; - } + public VBNetPrettyPrintOptions Options { + get { return prettyPrintOptions; } + set { prettyPrintOptions = value; } } public IOutputFormatter OutputFormatter { @@ -65,7 +60,30 @@ namespace ICSharpCode.NRefactory.PrettyPrinter public VBNetOutputVisitor() { outputFormatter = new VBNetOutputFormatter(prettyPrintOptions); - nodeTracker = new NodeTracker(this); + } + + public event Action BeforeNodeVisit; + public event Action AfterNodeVisit; + + protected override void BeginVisit(INode node) + { + if (BeforeNodeVisit != null) { + BeforeNodeVisit(node); + } + base.BeginVisit(node); + } + + protected override void EndVisit(INode node) + { + base.EndVisit(node); + if (AfterNodeVisit != null) { + AfterNodeVisit(node); + } + } + + object TrackedVisit(INode node, object data) + { + return node.AcceptVisitor(this, data); } void Error(string text, Location position) @@ -79,9 +97,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } #region ICSharpCode.NRefactory.Parser.IASTVisitor interface implementation - public object VisitCompilationUnit(CompilationUnit compilationUnit, object data) + public override object TrackedVisitCompilationUnit(CompilationUnit compilationUnit, object data) { - nodeTracker.TrackedVisitChildren(compilationUnit, data); + compilationUnit.AcceptChildren(this, data); outputFormatter.EndFile(); return null; } @@ -97,7 +115,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return primitiveType; } - public object VisitTypeReference(TypeReference typeReference, object data) + public override object TrackedVisitTypeReference(TypeReference typeReference, object data) { if (typeReference == TypeReference.ClassConstraint) { outputFormatter.PrintToken(Tokens.Class); @@ -155,15 +173,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) + public override object TrackedVisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) { - nodeTracker.TrackedVisit(innerClassTypeReference.BaseType, data); + TrackedVisit(innerClassTypeReference.BaseType, data); outputFormatter.PrintToken(Tokens.Dot); return VisitTypeReference((TypeReference)innerClassTypeReference, data); } #region Global scope - public object VisitAttributeSection(AttributeSection attributeSection, object data) + public override object TrackedVisitAttributeSection(AttributeSection attributeSection, object data) { outputFormatter.Indent(); outputFormatter.PrintText("<"); @@ -187,7 +205,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data) + public override object TrackedVisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data) { outputFormatter.PrintIdentifier(attribute.Name); outputFormatter.PrintToken(Tokens.OpenParenthesis); @@ -204,24 +222,24 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) + public override object TrackedVisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) { outputFormatter.PrintIdentifier(namedArgumentExpression.Name); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Colon); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(namedArgumentExpression.Expression, data); + TrackedVisit(namedArgumentExpression.Expression, data); return null; } - public object VisitUsing(Using @using, object data) + public override object TrackedVisitUsing(Using @using, object data) { Debug.Fail("Should never be called. The usings should be handled in Visit(UsingDeclaration)"); return null; } - public object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data) + public override object TrackedVisitUsingDeclaration(UsingDeclaration usingDeclaration, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Imports); @@ -233,7 +251,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); printFullSystemType = true; - nodeTracker.TrackedVisit(((Using)usingDeclaration.Usings[i]).Alias, data); + TrackedVisit(((Using)usingDeclaration.Usings[i]).Alias, data); printFullSystemType = false; } if (i + 1 < usingDeclaration.Usings.Count) { @@ -245,7 +263,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) + public override object TrackedVisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Namespace); @@ -254,7 +272,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisitChildren(namespaceDeclaration, data); + namespaceDeclaration.AcceptChildren(this, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -292,7 +310,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) + public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { VisitAttributes(typeDeclaration.Attributes, data); @@ -313,7 +331,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); foreach (TypeReference baseTypeRef in typeDeclaration.BaseTypes) { - nodeTracker.TrackedVisit(baseTypeRef, data); + TrackedVisit(baseTypeRef, data); } } @@ -336,7 +354,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Implements); } outputFormatter.Space(); - nodeTracker.TrackedVisit(baseTypeRef, data); + TrackedVisit(baseTypeRef, data); outputFormatter.NewLine(); } } @@ -347,7 +365,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (typeDeclaration.Type == ClassType.Enum) { OutputEnumMembers(typeDeclaration, data); } else { - nodeTracker.TrackedVisitChildren(typeDeclaration, data); + typeDeclaration.AcceptChildren(this, data); } currentType = oldType; @@ -365,7 +383,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter void OutputEnumMembers(TypeDeclaration typeDeclaration, object data) { foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) { - nodeTracker.BeginNode(fieldDeclaration); + BeginVisit(fieldDeclaration); VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0]; VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); @@ -374,20 +392,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(f.Initializer, data); + TrackedVisit(f.Initializer, data); } outputFormatter.NewLine(); - nodeTracker.EndNode(fieldDeclaration); + EndVisit(fieldDeclaration); } } - public object VisitTemplateDefinition(TemplateDefinition templateDefinition, object data) + public override object TrackedVisitTemplateDefinition(TemplateDefinition templateDefinition, object data) { outputFormatter.PrintIdentifier(templateDefinition.Name); if (templateDefinition.Bases.Count > 0) { outputFormatter.PrintText(" As "); if (templateDefinition.Bases.Count == 1) { - nodeTracker.TrackedVisit(templateDefinition.Bases[0], data); + TrackedVisit(templateDefinition.Bases[0], data); } else { outputFormatter.PrintToken(Tokens.OpenCurlyBrace); AppendCommaSeparatedList(templateDefinition.Bases); @@ -397,7 +415,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) + public override object TrackedVisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) { VisitAttributes(delegateDeclaration.Attributes, data); @@ -426,13 +444,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(delegateDeclaration.ReturnType, data); + TrackedVisit(delegateDeclaration.ReturnType, data); } outputFormatter.NewLine(); return null; } - public object VisitOptionDeclaration(OptionDeclaration optionDeclaration, object data) + public override object TrackedVisitOptionDeclaration(OptionDeclaration optionDeclaration, object data) { outputFormatter.PrintToken(Tokens.Option); outputFormatter.Space(); @@ -470,7 +488,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter #region Type level TypeReference currentVariableType; - public object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) + public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) { VisitAttributes(fieldDeclaration.Attributes, data); @@ -493,7 +511,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) + public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) { outputFormatter.PrintIdentifier(variableDeclaration.Name); @@ -509,10 +527,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); ObjectCreateExpression init = variableDeclaration.Initializer as ObjectCreateExpression; if (init != null && TypeReference.AreEqualReferences(init.CreateType, varType)) { - nodeTracker.TrackedVisit(variableDeclaration.Initializer, data); + TrackedVisit(variableDeclaration.Initializer, data); return null; } else { - nodeTracker.TrackedVisit(varType, data); + TrackedVisit(varType, data); } } @@ -520,12 +538,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(variableDeclaration.Initializer, data); + TrackedVisit(variableDeclaration.Initializer, data); } return null; } - public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) + public override object TrackedVisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { VisitAttributes(propertyDeclaration.Attributes, data); outputFormatter.Indent(); @@ -551,7 +569,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(propertyDeclaration.TypeReference, data); + TrackedVisit(propertyDeclaration.TypeReference, data); PrintInterfaceImplementations(propertyDeclaration.InterfaceImplementations); @@ -560,8 +578,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (!IsAbstract(propertyDeclaration)) { ++outputFormatter.IndentationLevel; exitTokenStack.Push(Tokens.Property); - nodeTracker.TrackedVisit(propertyDeclaration.GetRegion, data); - nodeTracker.TrackedVisit(propertyDeclaration.SetRegion, data); + TrackedVisit(propertyDeclaration.GetRegion, data); + TrackedVisit(propertyDeclaration.SetRegion, data); exitTokenStack.Pop(); --outputFormatter.IndentationLevel; @@ -575,7 +593,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) + public override object TrackedVisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) { VisitAttributes(propertyGetRegion.Attributes, data); outputFormatter.Indent(); @@ -584,7 +602,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(propertyGetRegion.Block, data); + TrackedVisit(propertyGetRegion.Block, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.End); @@ -594,7 +612,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data) + public override object TrackedVisitPropertySetRegion(PropertySetRegion propertySetRegion, object data) { VisitAttributes(propertySetRegion.Attributes, data); outputFormatter.Indent(); @@ -603,7 +621,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(propertySetRegion.Block, data); + TrackedVisit(propertySetRegion.Block, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.End); @@ -614,7 +632,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } TypeReference currentEventType = null; - public object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) + public override object TrackedVisitEventDeclaration(EventDeclaration eventDeclaration, object data) { bool customEvent = eventDeclaration.HasAddRegion || eventDeclaration.HasRemoveRegion; @@ -638,7 +656,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data); + TrackedVisit(eventDeclaration.TypeReference, data); PrintInterfaceImplementations(eventDeclaration.InterfaceImplementations); @@ -646,7 +664,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(eventDeclaration.Initializer, data); + TrackedVisit(eventDeclaration.Initializer, data); } outputFormatter.NewLine(); @@ -655,8 +673,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter ++outputFormatter.IndentationLevel; currentEventType = eventDeclaration.TypeReference; exitTokenStack.Push(Tokens.Sub); - nodeTracker.TrackedVisit(eventDeclaration.AddRegion, data); - nodeTracker.TrackedVisit(eventDeclaration.RemoveRegion, data); + TrackedVisit(eventDeclaration.AddRegion, data); + TrackedVisit(eventDeclaration.RemoveRegion, data); exitTokenStack.Pop(); --outputFormatter.IndentationLevel; @@ -679,13 +697,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (i > 0) outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); - nodeTracker.TrackedVisit(list[i].InterfaceType, null); + TrackedVisit(list[i].InterfaceType, null); outputFormatter.PrintToken(Tokens.Dot); outputFormatter.PrintIdentifier(list[i].MemberName); } } - public object VisitEventAddRegion(EventAddRegion eventAddRegion, object data) + public override object TrackedVisitEventAddRegion(EventAddRegion eventAddRegion, object data) { VisitAttributes(eventAddRegion.Attributes, data); outputFormatter.Indent(); @@ -697,7 +715,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(currentEventType, data); + TrackedVisit(currentEventType, data); } else { this.AppendCommaSeparatedList(eventAddRegion.Parameters); } @@ -705,7 +723,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(eventAddRegion.Block, data); + TrackedVisit(eventAddRegion.Block, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -716,7 +734,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data) + public override object TrackedVisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data) { VisitAttributes(eventRemoveRegion.Attributes, data); outputFormatter.Indent(); @@ -729,7 +747,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(currentEventType, data); + TrackedVisit(currentEventType, data); } else { this.AppendCommaSeparatedList(eventRemoveRegion.Parameters); } @@ -737,7 +755,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(eventRemoveRegion.Block, data); + TrackedVisit(eventRemoveRegion.Block, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -748,7 +766,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data) + public override object TrackedVisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data) { VisitAttributes(eventRaiseRegion.Attributes, data); outputFormatter.Indent(); @@ -761,7 +779,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(currentEventType, data); + TrackedVisit(currentEventType, data); } else { this.AppendCommaSeparatedList(eventRaiseRegion.Parameters); } @@ -769,7 +787,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(eventRaiseRegion.Block, data); + TrackedVisit(eventRaiseRegion.Block, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -780,7 +798,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) + public override object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) { VisitAttributes(parameterDeclarationExpression.Attributes, data); OutputModifier(parameterDeclarationExpression.ParamModifier, parameterDeclarationExpression.StartLocation); @@ -788,13 +806,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(parameterDeclarationExpression.TypeReference, data); + TrackedVisit(parameterDeclarationExpression.TypeReference, data); return null; } - public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) + public override object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { VisitAttributes(methodDeclaration.Attributes, data); + if (methodDeclaration.IsExtensionMethod) { + outputFormatter.Indent(); + outputFormatter.PrintText(" _"); + outputFormatter.NewLine(); + } outputFormatter.Indent(); OutputModifier(methodDeclaration.Modifier); @@ -819,7 +842,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(methodDeclaration.TypeReference, data); + TrackedVisit(methodDeclaration.TypeReference, data); } PrintInterfaceImplementations(methodDeclaration.InterfaceImplementations); @@ -827,10 +850,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); if (!IsAbstract(methodDeclaration)) { - nodeTracker.BeginNode(methodDeclaration.Body); + BeginVisit(methodDeclaration.Body); ++outputFormatter.IndentationLevel; exitTokenStack.Push(isSub ? Tokens.Sub : Tokens.Function); - methodDeclaration.Body.AcceptVisitor(this, data); + // we're doing the tracking manually using BeginVisit/EndVisit, so call Tracked... directly + this.TrackedVisitBlockStatement(methodDeclaration.Body, data); exitTokenStack.Pop(); --outputFormatter.IndentationLevel; @@ -843,12 +867,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Function); } outputFormatter.NewLine(); - nodeTracker.EndNode(methodDeclaration.Body); + EndVisit(methodDeclaration.Body); } return null; } - public object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) + public override object TrackedVisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) { throw new InvalidOperationException(); } @@ -860,7 +884,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return currentType != null && currentType.Type == ClassType.Interface; } - public object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) + public override object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { VisitAttributes(constructorDeclaration.Attributes, data); outputFormatter.Indent(); @@ -876,9 +900,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter ++outputFormatter.IndentationLevel; exitTokenStack.Push(Tokens.Sub); - nodeTracker.TrackedVisit(constructorDeclaration.ConstructorInitializer, data); + TrackedVisit(constructorDeclaration.ConstructorInitializer, data); - nodeTracker.TrackedVisit(constructorDeclaration.Body, data); + TrackedVisit(constructorDeclaration.Body, data); exitTokenStack.Pop(); --outputFormatter.IndentationLevel; @@ -891,7 +915,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data) + public override object TrackedVisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data) { outputFormatter.Indent(); if (constructorInitializer.ConstructorInitializerType == ConstructorInitializerType.This) { @@ -909,7 +933,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) + public override object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { VisitAttributes(indexerDeclaration.Attributes, data); outputFormatter.Indent(); @@ -934,14 +958,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(indexerDeclaration.TypeReference, data); + TrackedVisit(indexerDeclaration.TypeReference, data); PrintInterfaceImplementations(indexerDeclaration.InterfaceImplementations); outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; exitTokenStack.Push(Tokens.Property); - nodeTracker.TrackedVisit(indexerDeclaration.GetRegion, data); - nodeTracker.TrackedVisit(indexerDeclaration.SetRegion, data); + TrackedVisit(indexerDeclaration.GetRegion, data); + TrackedVisit(indexerDeclaration.SetRegion, data); exitTokenStack.Pop(); --outputFormatter.IndentationLevel; @@ -953,7 +977,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) + public override object TrackedVisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) { outputFormatter.Indent(); outputFormatter.PrintText("Protected Overrides Sub Finalize()"); @@ -967,7 +991,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(destructorDeclaration.Body, data); + TrackedVisit(destructorDeclaration.Body, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -998,7 +1022,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) + public override object TrackedVisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) { VisitAttributes(operatorDeclaration.Attributes, data); outputFormatter.Indent(); @@ -1119,13 +1143,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(operatorDeclaration.TypeReference, data); + TrackedVisit(operatorDeclaration.TypeReference, data); } outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - nodeTracker.TrackedVisit(operatorDeclaration.Body, data); + TrackedVisit(operatorDeclaration.Body, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -1137,7 +1161,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data) + public override object TrackedVisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data) { VisitAttributes(declareDeclaration.Attributes, data); outputFormatter.Indent(); @@ -1190,7 +1214,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(declareDeclaration.TypeReference, data); + TrackedVisit(declareDeclaration.TypeReference, data); } outputFormatter.NewLine(); @@ -1200,7 +1224,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter #endregion #region Statements - public object VisitBlockStatement(BlockStatement blockStatement, object data) + public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data) { VisitStatementList(blockStatement.Children); return null; @@ -1210,10 +1234,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { outputFormatter.IndentationLevel += 1; if (stmt is BlockStatement) { - nodeTracker.TrackedVisit(stmt, null); + TrackedVisit(stmt, null); } else { outputFormatter.Indent(); - nodeTracker.TrackedVisit(stmt, null); + TrackedVisit(stmt, null); outputFormatter.NewLine(); } outputFormatter.IndentationLevel -= 1; @@ -1230,38 +1254,38 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { foreach (Statement stmt in statements) { if (stmt is BlockStatement) { - nodeTracker.TrackedVisit(stmt, null); + TrackedVisit(stmt, null); } else { outputFormatter.Indent(); - nodeTracker.TrackedVisit(stmt, null); + TrackedVisit(stmt, null); outputFormatter.NewLine(); } } } - public object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) + public override object TrackedVisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) { outputFormatter.PrintToken(Tokens.AddHandler); outputFormatter.Space(); - nodeTracker.TrackedVisit(addHandlerStatement.EventExpression, data); + TrackedVisit(addHandlerStatement.EventExpression, data); outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); - nodeTracker.TrackedVisit(addHandlerStatement.HandlerExpression, data); + TrackedVisit(addHandlerStatement.HandlerExpression, data); return null; } - public object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data) + public override object TrackedVisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data) { outputFormatter.PrintToken(Tokens.RemoveHandler); outputFormatter.Space(); - nodeTracker.TrackedVisit(removeHandlerStatement.EventExpression, data); + TrackedVisit(removeHandlerStatement.EventExpression, data); outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); - nodeTracker.TrackedVisit(removeHandlerStatement.HandlerExpression, data); + TrackedVisit(removeHandlerStatement.HandlerExpression, data); return null; } - public object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) + public override object TrackedVisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { outputFormatter.PrintToken(Tokens.RaiseEvent); outputFormatter.Space(); @@ -1272,7 +1296,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEraseStatement(EraseStatement eraseStatement, object data) + public override object TrackedVisitEraseStatement(EraseStatement eraseStatement, object data) { outputFormatter.PrintToken(Tokens.Erase); outputFormatter.Space(); @@ -1280,25 +1304,25 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitErrorStatement(ErrorStatement errorStatement, object data) + public override object TrackedVisitErrorStatement(ErrorStatement errorStatement, object data) { outputFormatter.PrintToken(Tokens.Error); outputFormatter.Space(); - nodeTracker.TrackedVisit(errorStatement.Expression, data); + TrackedVisit(errorStatement.Expression, data); return null; } - public object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) + public override object TrackedVisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) { outputFormatter.PrintToken(Tokens.On); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Error); outputFormatter.Space(); - nodeTracker.TrackedVisit(onErrorStatement.EmbeddedStatement, data); + TrackedVisit(onErrorStatement.EmbeddedStatement, data); return null; } - public object VisitReDimStatement(ReDimStatement reDimStatement, object data) + public override object TrackedVisitReDimStatement(ReDimStatement reDimStatement, object data) { outputFormatter.PrintToken(Tokens.ReDim); outputFormatter.Space(); @@ -1311,13 +1335,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) + public override object TrackedVisitExpressionStatement(ExpressionStatement expressionStatement, object data) { - nodeTracker.TrackedVisit(expressionStatement.Expression, data); + TrackedVisit(expressionStatement.Expression, data); return null; } - public object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) + public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if (localVariableDeclaration.Modifier != Modifiers.None) { OutputModifier(localVariableDeclaration.Modifier); @@ -1336,33 +1360,33 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEmptyStatement(EmptyStatement emptyStatement, object data) + public override object TrackedVisitEmptyStatement(EmptyStatement emptyStatement, object data) { outputFormatter.NewLine(); return null; } - public virtual object VisitYieldStatement(YieldStatement yieldStatement, object data) + public override object TrackedVisitYieldStatement(YieldStatement yieldStatement, object data) { UnsupportedNode(yieldStatement); return null; } - public object VisitReturnStatement(ReturnStatement returnStatement, object data) + public override object TrackedVisitReturnStatement(ReturnStatement returnStatement, object data) { outputFormatter.PrintToken(Tokens.Return); if (!returnStatement.Expression.IsNull) { outputFormatter.Space(); - nodeTracker.TrackedVisit(returnStatement.Expression, data); + TrackedVisit(returnStatement.Expression, data); } return null; } - public object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) + public override object TrackedVisitIfElseStatement(IfElseStatement ifElseStatement, object data) { outputFormatter.PrintToken(Tokens.If); outputFormatter.Space(); - nodeTracker.TrackedVisit(ifElseStatement.Condition, data); + TrackedVisit(ifElseStatement.Condition, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Then); outputFormatter.NewLine(); @@ -1370,7 +1394,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter PrintIndentedBlock(ifElseStatement.TrueStatement); foreach (ElseIfSection elseIfSection in ifElseStatement.ElseIfSections) { - nodeTracker.TrackedVisit(elseIfSection, data); + TrackedVisit(elseIfSection, data); } if (ifElseStatement.HasElseStatements) { @@ -1387,11 +1411,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitElseIfSection(ElseIfSection elseIfSection, object data) + public override object TrackedVisitElseIfSection(ElseIfSection elseIfSection, object data) { outputFormatter.PrintToken(Tokens.ElseIf); outputFormatter.Space(); - nodeTracker.TrackedVisit(elseIfSection.Condition, data); + TrackedVisit(elseIfSection.Condition, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Then); outputFormatter.NewLine(); @@ -1399,7 +1423,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitForStatement(ForStatement forStatement, object data) + public override object TrackedVisitForStatement(ForStatement forStatement, object data) { // Is converted to {initializer} while {Embedded} {Iterators} end while exitTokenStack.Push(Tokens.While); @@ -1408,7 +1432,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (!isFirstLine) outputFormatter.Indent(); isFirstLine = false; - nodeTracker.TrackedVisit(node, data); + TrackedVisit(node, data); outputFormatter.NewLine(); } if (!isFirstLine) @@ -1418,7 +1442,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (forStatement.Condition.IsNull) { outputFormatter.PrintToken(Tokens.True); } else { - nodeTracker.TrackedVisit(forStatement.Condition, data); + TrackedVisit(forStatement.Condition, data); } outputFormatter.NewLine(); @@ -1433,14 +1457,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitLabelStatement(LabelStatement labelStatement, object data) + public override object TrackedVisitLabelStatement(LabelStatement labelStatement, object data) { outputFormatter.PrintIdentifier(labelStatement.Label); outputFormatter.PrintToken(Tokens.Colon); return null; } - public object VisitGotoStatement(GotoStatement gotoStatement, object data) + public override object TrackedVisitGotoStatement(GotoStatement gotoStatement, object data) { outputFormatter.PrintToken(Tokens.GoTo); outputFormatter.Space(); @@ -1448,18 +1472,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitSwitchStatement(SwitchStatement switchStatement, object data) + public override object TrackedVisitSwitchStatement(SwitchStatement switchStatement, object data) { exitTokenStack.Push(Tokens.Select); outputFormatter.PrintToken(Tokens.Select); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Case); outputFormatter.Space(); - nodeTracker.TrackedVisit(switchStatement.SwitchExpression, data); + TrackedVisit(switchStatement.SwitchExpression, data); outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; foreach (SwitchSection section in switchStatement.SwitchSections) { - nodeTracker.TrackedVisit(section, data); + TrackedVisit(section, data); } --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -1470,7 +1494,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitSwitchSection(SwitchSection switchSection, object data) + public override object TrackedVisitSwitchSection(SwitchSection switchSection, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Case); @@ -1483,7 +1507,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitCaseLabel(CaseLabel caseLabel, object data) + public override object TrackedVisitCaseLabel(CaseLabel caseLabel, object data) { if (caseLabel.IsDefault) { outputFormatter.PrintToken(Tokens.Else); @@ -1514,19 +1538,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } - nodeTracker.TrackedVisit(caseLabel.Label, data); + TrackedVisit(caseLabel.Label, data); if (!caseLabel.ToExpression.IsNull) { outputFormatter.Space(); outputFormatter.PrintToken(Tokens.To); outputFormatter.Space(); - nodeTracker.TrackedVisit(caseLabel.ToExpression, data); + TrackedVisit(caseLabel.ToExpression, data); } } return null; } - public object VisitBreakStatement(BreakStatement breakStatement, object data) + public override object TrackedVisitBreakStatement(BreakStatement breakStatement, object data) { outputFormatter.PrintToken(Tokens.Exit); if (exitTokenStack.Count > 0) { @@ -1536,13 +1560,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitStopStatement(StopStatement stopStatement, object data) + public override object TrackedVisitStopStatement(StopStatement stopStatement, object data) { outputFormatter.PrintToken(Tokens.Stop); return null; } - public object VisitResumeStatement(ResumeStatement resumeStatement, object data) + public override object TrackedVisitResumeStatement(ResumeStatement resumeStatement, object data) { outputFormatter.PrintToken(Tokens.Resume); outputFormatter.Space(); @@ -1554,13 +1578,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitEndStatement(EndStatement endStatement, object data) + public override object TrackedVisitEndStatement(EndStatement endStatement, object data) { outputFormatter.PrintToken(Tokens.End); return null; } - public object VisitContinueStatement(ContinueStatement continueStatement, object data) + public override object TrackedVisitContinueStatement(ContinueStatement continueStatement, object data) { outputFormatter.PrintToken(Tokens.Continue); outputFormatter.Space(); @@ -1581,18 +1605,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) + public override object TrackedVisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) { outputFormatter.PrintText("goto case "); if (gotoCaseStatement.IsDefaultCase) { outputFormatter.PrintText("default"); } else { - nodeTracker.TrackedVisit(gotoCaseStatement.Expression, null); + TrackedVisit(gotoCaseStatement.Expression, null); } return null; } - public object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) + public override object TrackedVisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) { if (doLoopStatement.ConditionPosition == ConditionPosition.None) { Error(String.Format("Unknown condition position for loop : {0}.", doLoopStatement), doLoopStatement.StartLocation); @@ -1620,7 +1644,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter throw new InvalidOperationException(); } outputFormatter.Space(); - nodeTracker.TrackedVisit(doLoopStatement.Condition, null); + TrackedVisit(doLoopStatement.Condition, null); } else { exitTokenStack.Push(Tokens.Do); outputFormatter.PrintToken(Tokens.Do); @@ -1651,13 +1675,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter break; } outputFormatter.Space(); - nodeTracker.TrackedVisit(doLoopStatement.Condition, null); + TrackedVisit(doLoopStatement.Condition, null); } exitTokenStack.Pop(); return null; } - public object VisitForeachStatement(ForeachStatement foreachStatement, object data) + public override object TrackedVisitForeachStatement(ForeachStatement foreachStatement, object data) { exitTokenStack.Push(Tokens.For); outputFormatter.PrintToken(Tokens.For); @@ -1670,13 +1694,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(foreachStatement.TypeReference, data); + TrackedVisit(foreachStatement.TypeReference, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.In); outputFormatter.Space(); - nodeTracker.TrackedVisit(foreachStatement.Expression, data); + TrackedVisit(foreachStatement.Expression, data); outputFormatter.NewLine(); PrintIndentedBlock(foreachStatement.EmbeddedStatement); @@ -1685,17 +1709,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Next); if (!foreachStatement.NextExpression.IsNull) { outputFormatter.Space(); - nodeTracker.TrackedVisit(foreachStatement.NextExpression, data); + TrackedVisit(foreachStatement.NextExpression, data); } exitTokenStack.Pop(); return null; } - public object VisitLockStatement(LockStatement lockStatement, object data) + public override object TrackedVisitLockStatement(LockStatement lockStatement, object data) { outputFormatter.PrintToken(Tokens.SyncLock); outputFormatter.Space(); - nodeTracker.TrackedVisit(lockStatement.LockExpression, data); + TrackedVisit(lockStatement.LockExpression, data); outputFormatter.NewLine(); PrintIndentedBlock(lockStatement.EmbeddedStatement); @@ -1709,13 +1733,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter bool isUsingResourceAcquisition; - public object VisitUsingStatement(UsingStatement usingStatement, object data) + public override object TrackedVisitUsingStatement(UsingStatement usingStatement, object data) { outputFormatter.PrintToken(Tokens.Using); outputFormatter.Space(); isUsingResourceAcquisition = true; - nodeTracker.TrackedVisit(usingStatement.ResourceAcquisition, data); + TrackedVisit(usingStatement.ResourceAcquisition, data); isUsingResourceAcquisition = false; outputFormatter.NewLine(); @@ -1729,11 +1753,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitWithStatement(WithStatement withStatement, object data) + public override object TrackedVisitWithStatement(WithStatement withStatement, object data) { outputFormatter.PrintToken(Tokens.With); outputFormatter.Space(); - nodeTracker.TrackedVisit(withStatement.Expression, data); + TrackedVisit(withStatement.Expression, data); outputFormatter.NewLine(); PrintIndentedBlock(withStatement.Body); @@ -1744,7 +1768,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) + public override object TrackedVisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) { exitTokenStack.Push(Tokens.Try); outputFormatter.PrintToken(Tokens.Try); @@ -1753,7 +1777,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter PrintIndentedBlock(tryCatchStatement.StatementBlock); foreach (CatchClause catchClause in tryCatchStatement.CatchClauses) { - nodeTracker.TrackedVisit(catchClause, data); + TrackedVisit(catchClause, data); } if (!tryCatchStatement.FinallyBlock.IsNull) { @@ -1770,7 +1794,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitCatchClause(CatchClause catchClause, object data) + public override object TrackedVisitCatchClause(CatchClause catchClause, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Catch); @@ -1792,7 +1816,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.When); outputFormatter.Space(); - nodeTracker.TrackedVisit(catchClause.Condition, data); + TrackedVisit(catchClause.Condition, data); } outputFormatter.NewLine(); @@ -1801,41 +1825,41 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitThrowStatement(ThrowStatement throwStatement, object data) + public override object TrackedVisitThrowStatement(ThrowStatement throwStatement, object data) { outputFormatter.PrintToken(Tokens.Throw); if (!throwStatement.Expression.IsNull) { outputFormatter.Space(); - nodeTracker.TrackedVisit(throwStatement.Expression, data); + TrackedVisit(throwStatement.Expression, data); } return null; } - public object VisitFixedStatement(FixedStatement fixedStatement, object data) + public override object TrackedVisitFixedStatement(FixedStatement fixedStatement, object data) { UnsupportedNode(fixedStatement); - return nodeTracker.TrackedVisit(fixedStatement.EmbeddedStatement, data); + return TrackedVisit(fixedStatement.EmbeddedStatement, data); } - public object VisitUnsafeStatement(UnsafeStatement unsafeStatement, object data) + public override object TrackedVisitUnsafeStatement(UnsafeStatement unsafeStatement, object data) { UnsupportedNode(unsafeStatement); - return nodeTracker.TrackedVisit(unsafeStatement.Block, data); + return TrackedVisit(unsafeStatement.Block, data); } - public object VisitCheckedStatement(CheckedStatement checkedStatement, object data) + public override object TrackedVisitCheckedStatement(CheckedStatement checkedStatement, object data) { UnsupportedNode(checkedStatement); - return nodeTracker.TrackedVisit(checkedStatement.Block, data); + return TrackedVisit(checkedStatement.Block, data); } - public object VisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data) + public override object TrackedVisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data) { UnsupportedNode(uncheckedStatement); - return nodeTracker.TrackedVisit(uncheckedStatement.Block, data); + return TrackedVisit(uncheckedStatement.Block, data); } - public object VisitExitStatement(ExitStatement exitStatement, object data) + public override object TrackedVisitExitStatement(ExitStatement exitStatement, object data) { outputFormatter.PrintToken(Tokens.Exit); if (exitStatement.ExitType != ExitType.None) { @@ -1874,7 +1898,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitForNextStatement(ForNextStatement forNextStatement, object data) + public override object TrackedVisitForNextStatement(ForNextStatement forNextStatement, object data) { exitTokenStack.Push(Tokens.For); outputFormatter.PrintToken(Tokens.For); @@ -1886,26 +1910,26 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(forNextStatement.TypeReference, data); + TrackedVisit(forNextStatement.TypeReference, data); } outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(forNextStatement.Start, data); + TrackedVisit(forNextStatement.Start, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.To); outputFormatter.Space(); - nodeTracker.TrackedVisit(forNextStatement.End, data); + TrackedVisit(forNextStatement.End, data); if (!forNextStatement.Step.IsNull) { outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Step); outputFormatter.Space(); - nodeTracker.TrackedVisit(forNextStatement.Step, data); + TrackedVisit(forNextStatement.Step, data); } outputFormatter.NewLine(); @@ -1925,7 +1949,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter #region Expressions - public object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data) + public override object TrackedVisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data) { outputFormatter.PrintToken(Tokens.MyClass); return null; @@ -1959,7 +1983,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return sb.ToString(); } - public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) + public override object TrackedVisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) { object val = primitiveExpression.Value; if (val == null) { @@ -2004,7 +2028,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) + public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { int op = 0; switch (binaryOperatorExpression.Op) { @@ -2069,21 +2093,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter op = Tokens.GreaterEqual; break; case BinaryOperatorType.InEquality: - nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); + TrackedVisit(binaryOperatorExpression.Left, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.LessThan); outputFormatter.PrintToken(Tokens.GreaterThan); outputFormatter.Space(); - nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data); + TrackedVisit(binaryOperatorExpression.Right, data); return null; case BinaryOperatorType.NullCoalescing: outputFormatter.PrintText("IIf("); - nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); + TrackedVisit(binaryOperatorExpression.Left, data); outputFormatter.PrintText(" Is Nothing, "); - nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data); + TrackedVisit(binaryOperatorExpression.Right, data); outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); - nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); + TrackedVisit(binaryOperatorExpression.Left, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; case BinaryOperatorType.LessThan: @@ -2094,26 +2118,26 @@ namespace ICSharpCode.NRefactory.PrettyPrinter break; } - nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); + TrackedVisit(binaryOperatorExpression.Left, data); outputFormatter.Space(); outputFormatter.PrintToken(op); outputFormatter.Space(); - nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data); + TrackedVisit(binaryOperatorExpression.Right, data); return null; } - public object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) + public override object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) { outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(parenthesizedExpression.Expression, data); + TrackedVisit(parenthesizedExpression.Expression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitInvocationExpression(InvocationExpression invocationExpression, object data) + public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data) { - nodeTracker.TrackedVisit(invocationExpression.TargetObject, data); + TrackedVisit(invocationExpression.TargetObject, data); if (invocationExpression.TypeArguments != null && invocationExpression.TypeArguments.Count > 0) { outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.Of); @@ -2127,63 +2151,63 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) + public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { outputFormatter.PrintIdentifier(identifierExpression.Identifier); return null; } - public object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) + public override object TrackedVisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) { - nodeTracker.TrackedVisit(typeReferenceExpression.TypeReference, data); + TrackedVisit(typeReferenceExpression.TypeReference, data); return null; } - public object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) + public override object TrackedVisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { switch (unaryOperatorExpression.Op) { case UnaryOperatorType.Not: case UnaryOperatorType.BitNot: outputFormatter.PrintToken(Tokens.Not); outputFormatter.Space(); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); return null; case UnaryOperatorType.Decrement: outputFormatter.PrintText("System.Threading.Interlocked.Decrement("); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintText(")"); return null; case UnaryOperatorType.Increment: outputFormatter.PrintText("System.Threading.Interlocked.Increment("); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintText(")"); return null; case UnaryOperatorType.Minus: outputFormatter.PrintToken(Tokens.Minus); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); return null; case UnaryOperatorType.Plus: outputFormatter.PrintToken(Tokens.Plus); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); return null; case UnaryOperatorType.PostDecrement: outputFormatter.PrintText("System.Math.Max(System.Threading.Interlocked.Decrement("); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintText("),"); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintText(" + 1)"); return null; case UnaryOperatorType.PostIncrement: outputFormatter.PrintText("System.Math.Max(System.Threading.Interlocked.Increment("); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintText("),"); - nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); + TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintText(" - 1)"); return null; @@ -2199,7 +2223,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) + public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { int op = 0; bool unsupportedOpAssignment = false; @@ -2212,12 +2236,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (IsEventHandlerCreation(assignmentExpression.Right)) { outputFormatter.PrintToken(Tokens.AddHandler); outputFormatter.Space(); - nodeTracker.TrackedVisit(assignmentExpression.Left, data); + TrackedVisit(assignmentExpression.Left, data); outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.AddressOf); outputFormatter.Space(); - nodeTracker.TrackedVisit(GetEventHandlerMethod(assignmentExpression.Right), data); + TrackedVisit(GetEventHandlerMethod(assignmentExpression.Right), data); return null; } break; @@ -2226,12 +2250,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (IsEventHandlerCreation(assignmentExpression.Right)) { outputFormatter.PrintToken(Tokens.RemoveHandler); outputFormatter.Space(); - nodeTracker.TrackedVisit(assignmentExpression.Left, data); + TrackedVisit(assignmentExpression.Left, data); outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.AddressOf); outputFormatter.Space(); - nodeTracker.TrackedVisit(GetEventHandlerMethod(assignmentExpression.Right), data); + TrackedVisit(GetEventHandlerMethod(assignmentExpression.Right), data); return null; } break; @@ -2266,90 +2290,90 @@ namespace ICSharpCode.NRefactory.PrettyPrinter break; } - nodeTracker.TrackedVisit(assignmentExpression.Left, data); + TrackedVisit(assignmentExpression.Left, data); outputFormatter.Space(); if (unsupportedOpAssignment) { // left = left OP right outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - nodeTracker.TrackedVisit(assignmentExpression.Left, data); + TrackedVisit(assignmentExpression.Left, data); outputFormatter.Space(); } outputFormatter.PrintToken(op); outputFormatter.Space(); - nodeTracker.TrackedVisit(assignmentExpression.Right, data); + TrackedVisit(assignmentExpression.Right, data); return null; } - public object VisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data) + public override object TrackedVisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data) { UnsupportedNode(sizeOfExpression); return null; } - public object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data) + public override object TrackedVisitTypeOfExpression(TypeOfExpression typeOfExpression, object data) { outputFormatter.PrintToken(Tokens.GetType); outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(typeOfExpression.TypeReference, data); + TrackedVisit(typeOfExpression.TypeReference, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data) + public override object TrackedVisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data) { // assigning nothing to a generic type in VB compiles to a DefaultValueExpression outputFormatter.PrintToken(Tokens.Nothing); return null; } - public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) + public override object TrackedVisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { outputFormatter.PrintToken(Tokens.TypeOf); outputFormatter.Space(); - nodeTracker.TrackedVisit(typeOfIsExpression.Expression, data); + TrackedVisit(typeOfIsExpression.Expression, data); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Is); outputFormatter.Space(); - nodeTracker.TrackedVisit(typeOfIsExpression.TypeReference, data); + TrackedVisit(typeOfIsExpression.TypeReference, data); return null; } - public object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) + public override object TrackedVisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) { outputFormatter.PrintToken(Tokens.AddressOf); outputFormatter.Space(); - nodeTracker.TrackedVisit(addressOfExpression.Expression, data); + TrackedVisit(addressOfExpression.Expression, data); return null; } - public object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) + public override object TrackedVisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) { UnsupportedNode(anonymousMethodExpression); return null; } - public object VisitCheckedExpression(CheckedExpression checkedExpression, object data) + public override object TrackedVisitCheckedExpression(CheckedExpression checkedExpression, object data) { UnsupportedNode(checkedExpression); - return nodeTracker.TrackedVisit(checkedExpression.Expression, data); + return TrackedVisit(checkedExpression.Expression, data); } - public object VisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data) + public override object TrackedVisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data) { UnsupportedNode(uncheckedExpression); - return nodeTracker.TrackedVisit(uncheckedExpression.Expression, data); + return TrackedVisit(uncheckedExpression.Expression, data); } - public object VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) + public override object TrackedVisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) { UnsupportedNode(pointerReferenceExpression); return null; } - public object VisitCastExpression(CastExpression castExpression, object data) + public override object TrackedVisitCastExpression(CastExpression castExpression, object data) { if (castExpression.CastType == CastType.Cast) { return PrintCast(Tokens.DirectCast, castExpression); @@ -2410,7 +2434,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return PrintCast(Tokens.CType, castExpression); } outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(castExpression.Expression, data); + TrackedVisit(castExpression.Expression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } @@ -2419,53 +2443,53 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { outputFormatter.PrintToken(castToken); outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(castExpression.Expression, null); + TrackedVisit(castExpression.Expression, null); outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); - nodeTracker.TrackedVisit(castExpression.CastTo, null); + TrackedVisit(castExpression.CastTo, null); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data) + public override object TrackedVisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data) { UnsupportedNode(stackAllocExpression); return null; } - public object VisitIndexerExpression(IndexerExpression indexerExpression, object data) + public override object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data) { - nodeTracker.TrackedVisit(indexerExpression.TargetObject, data); + TrackedVisit(indexerExpression.TargetObject, data); outputFormatter.PrintToken(Tokens.OpenParenthesis); AppendCommaSeparatedList(indexerExpression.Indexes); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) + public override object TrackedVisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) { outputFormatter.PrintToken(Tokens.Me); return null; } - public object VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data) + public override object TrackedVisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data) { outputFormatter.PrintToken(Tokens.MyBase); return null; } - public object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) + public override object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { outputFormatter.PrintToken(Tokens.New); outputFormatter.Space(); - nodeTracker.TrackedVisit(objectCreateExpression.CreateType, data); + TrackedVisit(objectCreateExpression.CreateType, data); outputFormatter.PrintToken(Tokens.OpenParenthesis); AppendCommaSeparatedList(objectCreateExpression.Parameters); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - public object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) + public override object TrackedVisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { outputFormatter.PrintToken(Tokens.New); outputFormatter.Space(); @@ -2486,12 +2510,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.OpenCurlyBrace); outputFormatter.PrintToken(Tokens.CloseCurlyBrace); } else { - nodeTracker.TrackedVisit(arrayCreateExpression.ArrayInitializer, data); + TrackedVisit(arrayCreateExpression.ArrayInitializer, data); } return null; } - public object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data) + public override object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression arrayInitializerExpression, object data) { outputFormatter.PrintToken(Tokens.OpenCurlyBrace); this.AppendCommaSeparatedList(arrayInitializerExpression.CreateExpressions); @@ -2499,32 +2523,32 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) + public override object TrackedVisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) { - nodeTracker.TrackedVisit(fieldReferenceExpression.TargetObject, data); + TrackedVisit(fieldReferenceExpression.TargetObject, data); outputFormatter.PrintToken(Tokens.Dot); outputFormatter.PrintIdentifier(fieldReferenceExpression.FieldName); return null; } - public object VisitDirectionExpression(DirectionExpression directionExpression, object data) + public override object TrackedVisitDirectionExpression(DirectionExpression directionExpression, object data) { // VB does not need to specify the direction in method calls - nodeTracker.TrackedVisit(directionExpression.Expression, data); + TrackedVisit(directionExpression.Expression, data); return null; } - public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) + public override object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data) { // No representation in VB.NET, but VB conversion is possible. outputFormatter.PrintText("IIf"); outputFormatter.PrintToken(Tokens.OpenParenthesis); - nodeTracker.TrackedVisit(conditionalExpression.Condition, data); + TrackedVisit(conditionalExpression.Condition, data); outputFormatter.PrintToken(Tokens.Comma); - nodeTracker.TrackedVisit(conditionalExpression.TrueExpression, data); + TrackedVisit(conditionalExpression.TrueExpression, data); outputFormatter.PrintToken(Tokens.Comma); - nodeTracker.TrackedVisit(conditionalExpression.FalseExpression, data); + TrackedVisit(conditionalExpression.FalseExpression, data); outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } @@ -2635,12 +2659,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter // not required in VB } - // TODO : Volatile if ((modifier & Modifiers.Volatile) == Modifiers.Volatile) { Error("'Volatile' modifier not convertable", Location.Empty); } - // TODO : Unsafe if ((modifier & Modifiers.Unsafe) == Modifiers.Unsafe) { Error("'Unsafe' modifier not convertable", Location.Empty); } @@ -2651,7 +2673,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (list != null) { int i = 0; foreach (T node in list) { - nodeTracker.TrackedVisit(node, null); + TrackedVisit(node, null); if (i + 1 < list.Count) { outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); @@ -2672,7 +2694,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return; } foreach (AttributeSection section in attributes) { - nodeTracker.TrackedVisit(section, data); + TrackedVisit(section, data); } } @@ -2694,5 +2716,50 @@ namespace ICSharpCode.NRefactory.PrettyPrinter ObjectCreateExpression oce = (ObjectCreateExpression)expr; return oce.Parameters[0]; } + + public override object TrackedVisitLambdaExpression(LambdaExpression lambdaExpression, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpression(QueryExpression queryExpression, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) + { + throw new NotImplementedException(); + } + + public override object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) + { + throw new NotImplementedException(); + } } } diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs index e64a6ad0a2..963e7a85b8 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.42 +// Runtime Version:2.0.50727.312 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -55,16 +55,6 @@ namespace ICSharpCode.NRefactory.Visitors { return arrayCreateExpression.ArrayInitializer.AcceptVisitor(this, data); } - public virtual object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data) { - Debug.Assert((arrayInitializerExpression != null)); - Debug.Assert((arrayInitializerExpression.CreateExpressions != null)); - foreach (Expression o in arrayInitializerExpression.CreateExpressions) { - Debug.Assert(o != null); - o.AcceptVisitor(this, data); - } - return null; - } - public virtual object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { Debug.Assert((assignmentExpression != null)); Debug.Assert((assignmentExpression.Left != null)); @@ -164,6 +154,16 @@ namespace ICSharpCode.NRefactory.Visitors { return null; } + public virtual object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data) { + Debug.Assert((collectionInitializerExpression != null)); + Debug.Assert((collectionInitializerExpression.CreateExpressions != null)); + foreach (Expression o in collectionInitializerExpression.CreateExpressions) { + Debug.Assert(o != null); + o.AcceptVisitor(this, data); + } + return null; + } + public virtual object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { Debug.Assert((compilationUnit != null)); return compilationUnit.AcceptChildren(this, data); @@ -605,6 +605,19 @@ namespace ICSharpCode.NRefactory.Visitors { return null; } + public virtual object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) { + Debug.Assert((lambdaExpression != null)); + Debug.Assert((lambdaExpression.Parameters != null)); + Debug.Assert((lambdaExpression.StatementBody != null)); + Debug.Assert((lambdaExpression.ExpressionBody != null)); + foreach (ParameterDeclarationExpression o in lambdaExpression.Parameters) { + Debug.Assert(o != null); + o.AcceptVisitor(this, data); + } + lambdaExpression.StatementBody.AcceptVisitor(this, data); + return lambdaExpression.ExpressionBody.AcceptVisitor(this, data); + } + public virtual object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { Debug.Assert((localVariableDeclaration != null)); Debug.Assert((localVariableDeclaration.TypeReference != null)); @@ -669,12 +682,13 @@ namespace ICSharpCode.NRefactory.Visitors { Debug.Assert((objectCreateExpression != null)); Debug.Assert((objectCreateExpression.CreateType != null)); Debug.Assert((objectCreateExpression.Parameters != null)); + Debug.Assert((objectCreateExpression.ObjectInitializer != null)); objectCreateExpression.CreateType.AcceptVisitor(this, data); foreach (Expression o in objectCreateExpression.Parameters) { Debug.Assert(o != null); o.AcceptVisitor(this, data); } - return null; + return objectCreateExpression.ObjectInitializer.AcceptVisitor(this, data); } public virtual object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) { @@ -805,6 +819,74 @@ namespace ICSharpCode.NRefactory.Visitors { return null; } + public virtual object VisitQueryExpression(QueryExpression queryExpression, object data) { + Debug.Assert((queryExpression != null)); + Debug.Assert((queryExpression.FromClause != null)); + Debug.Assert((queryExpression.FromOrWhereClauses != null)); + Debug.Assert((queryExpression.Orderings != null)); + Debug.Assert((queryExpression.SelectOrGroupClause != null)); + Debug.Assert((queryExpression.IntoClause != null)); + queryExpression.FromClause.AcceptVisitor(this, data); + foreach (QueryExpressionClause o in queryExpression.FromOrWhereClauses) { + Debug.Assert(o != null); + o.AcceptVisitor(this, data); + } + foreach (QueryExpressionOrdering o in queryExpression.Orderings) { + Debug.Assert(o != null); + o.AcceptVisitor(this, data); + } + queryExpression.SelectOrGroupClause.AcceptVisitor(this, data); + return queryExpression.IntoClause.AcceptVisitor(this, data); + } + + public virtual object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) { + Debug.Assert((queryExpressionFromClause != null)); + Debug.Assert((queryExpressionFromClause.Generators != null)); + foreach (QueryExpressionFromGenerator o in queryExpressionFromClause.Generators) { + Debug.Assert(o != null); + o.AcceptVisitor(this, data); + } + return null; + } + + public virtual object VisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) { + Debug.Assert((queryExpressionFromGenerator != null)); + Debug.Assert((queryExpressionFromGenerator.InExpression != null)); + return queryExpressionFromGenerator.InExpression.AcceptVisitor(this, data); + } + + public virtual object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) { + Debug.Assert((queryExpressionGroupClause != null)); + Debug.Assert((queryExpressionGroupClause.Projection != null)); + Debug.Assert((queryExpressionGroupClause.GroupBy != null)); + queryExpressionGroupClause.Projection.AcceptVisitor(this, data); + return queryExpressionGroupClause.GroupBy.AcceptVisitor(this, data); + } + + public virtual object VisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data) { + Debug.Assert((queryExpressionIntoClause != null)); + Debug.Assert((queryExpressionIntoClause.ContinuedQuery != null)); + return queryExpressionIntoClause.ContinuedQuery.AcceptVisitor(this, data); + } + + public virtual object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) { + Debug.Assert((queryExpressionOrdering != null)); + Debug.Assert((queryExpressionOrdering.Criteria != null)); + return queryExpressionOrdering.Criteria.AcceptVisitor(this, data); + } + + public virtual object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) { + Debug.Assert((queryExpressionSelectClause != null)); + Debug.Assert((queryExpressionSelectClause.Projection != null)); + return queryExpressionSelectClause.Projection.AcceptVisitor(this, data); + } + + public virtual object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) { + Debug.Assert((queryExpressionWhereClause != null)); + Debug.Assert((queryExpressionWhereClause.Condition != null)); + return queryExpressionWhereClause.Condition.AcceptVisitor(this, data); + } + public virtual object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { Debug.Assert((raiseEventStatement != null)); Debug.Assert((raiseEventStatement.Arguments != null)); diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs b/src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs index 2facd3e4ab..99963e2769 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.42 +// Runtime Version:2.0.50727.312 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -102,24 +102,7 @@ namespace ICSharpCode.NRefactory.Visitors { } nodeStack.Push(arrayCreateExpression.ArrayInitializer); arrayCreateExpression.ArrayInitializer.AcceptVisitor(this, data); - arrayCreateExpression.ArrayInitializer = ((ArrayInitializerExpression)(nodeStack.Pop())); - return null; - } - - public virtual object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data) { - Debug.Assert((arrayInitializerExpression != null)); - Debug.Assert((arrayInitializerExpression.CreateExpressions != null)); - for (int i = 0; i < arrayInitializerExpression.CreateExpressions.Count; i++) { - Expression o = arrayInitializerExpression.CreateExpressions[i]; - Debug.Assert(o != null); - nodeStack.Push(o); - o.AcceptVisitor(this, data); - o = (Expression)nodeStack.Pop(); - if (o == null) - arrayInitializerExpression.CreateExpressions.RemoveAt(i--); - else - arrayInitializerExpression.CreateExpressions[i] = o; - } + arrayCreateExpression.ArrayInitializer = ((CollectionInitializerExpression)(nodeStack.Pop())); return null; } @@ -287,6 +270,23 @@ namespace ICSharpCode.NRefactory.Visitors { return null; } + public virtual object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data) { + Debug.Assert((collectionInitializerExpression != null)); + Debug.Assert((collectionInitializerExpression.CreateExpressions != null)); + for (int i = 0; i < collectionInitializerExpression.CreateExpressions.Count; i++) { + Expression o = collectionInitializerExpression.CreateExpressions[i]; + Debug.Assert(o != null); + nodeStack.Push(o); + o.AcceptVisitor(this, data); + o = (Expression)nodeStack.Pop(); + if (o == null) + collectionInitializerExpression.CreateExpressions.RemoveAt(i--); + else + collectionInitializerExpression.CreateExpressions[i] = o; + } + return null; + } + public virtual object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { Debug.Assert((compilationUnit != null)); for (int i = 0; i < compilationUnit.Children.Count; i++) { @@ -1100,6 +1100,31 @@ namespace ICSharpCode.NRefactory.Visitors { return null; } + public virtual object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) { + Debug.Assert((lambdaExpression != null)); + Debug.Assert((lambdaExpression.Parameters != null)); + Debug.Assert((lambdaExpression.StatementBody != null)); + Debug.Assert((lambdaExpression.ExpressionBody != null)); + for (int i = 0; i < lambdaExpression.Parameters.Count; i++) { + ParameterDeclarationExpression o = lambdaExpression.Parameters[i]; + Debug.Assert(o != null); + nodeStack.Push(o); + o.AcceptVisitor(this, data); + o = (ParameterDeclarationExpression)nodeStack.Pop(); + if (o == null) + lambdaExpression.Parameters.RemoveAt(i--); + else + lambdaExpression.Parameters[i] = o; + } + nodeStack.Push(lambdaExpression.StatementBody); + lambdaExpression.StatementBody.AcceptVisitor(this, data); + lambdaExpression.StatementBody = ((BlockStatement)(nodeStack.Pop())); + nodeStack.Push(lambdaExpression.ExpressionBody); + lambdaExpression.ExpressionBody.AcceptVisitor(this, data); + lambdaExpression.ExpressionBody = ((Expression)(nodeStack.Pop())); + return null; + } + public virtual object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { Debug.Assert((localVariableDeclaration != null)); Debug.Assert((localVariableDeclaration.TypeReference != null)); @@ -1224,6 +1249,7 @@ namespace ICSharpCode.NRefactory.Visitors { Debug.Assert((objectCreateExpression != null)); Debug.Assert((objectCreateExpression.CreateType != null)); Debug.Assert((objectCreateExpression.Parameters != null)); + Debug.Assert((objectCreateExpression.ObjectInitializer != null)); nodeStack.Push(objectCreateExpression.CreateType); objectCreateExpression.CreateType.AcceptVisitor(this, data); objectCreateExpression.CreateType = ((TypeReference)(nodeStack.Pop())); @@ -1238,6 +1264,9 @@ namespace ICSharpCode.NRefactory.Visitors { else objectCreateExpression.Parameters[i] = o; } + nodeStack.Push(objectCreateExpression.ObjectInitializer); + objectCreateExpression.ObjectInitializer.AcceptVisitor(this, data); + objectCreateExpression.ObjectInitializer = ((CollectionInitializerExpression)(nodeStack.Pop())); return null; } @@ -1483,6 +1512,122 @@ namespace ICSharpCode.NRefactory.Visitors { return null; } + public virtual object VisitQueryExpression(QueryExpression queryExpression, object data) { + Debug.Assert((queryExpression != null)); + Debug.Assert((queryExpression.FromClause != null)); + Debug.Assert((queryExpression.FromOrWhereClauses != null)); + Debug.Assert((queryExpression.Orderings != null)); + Debug.Assert((queryExpression.SelectOrGroupClause != null)); + Debug.Assert((queryExpression.IntoClause != null)); + nodeStack.Push(queryExpression.FromClause); + queryExpression.FromClause.AcceptVisitor(this, data); + queryExpression.FromClause = ((QueryExpressionFromClause)(nodeStack.Pop())); + for (int i = 0; i < queryExpression.FromOrWhereClauses.Count; i++) { + QueryExpressionClause o = queryExpression.FromOrWhereClauses[i]; + Debug.Assert(o != null); + nodeStack.Push(o); + o.AcceptVisitor(this, data); + o = (QueryExpressionClause)nodeStack.Pop(); + if (o == null) + queryExpression.FromOrWhereClauses.RemoveAt(i--); + else + queryExpression.FromOrWhereClauses[i] = o; + } + for (int i = 0; i < queryExpression.Orderings.Count; i++) { + QueryExpressionOrdering o = queryExpression.Orderings[i]; + Debug.Assert(o != null); + nodeStack.Push(o); + o.AcceptVisitor(this, data); + o = (QueryExpressionOrdering)nodeStack.Pop(); + if (o == null) + queryExpression.Orderings.RemoveAt(i--); + else + queryExpression.Orderings[i] = o; + } + nodeStack.Push(queryExpression.SelectOrGroupClause); + queryExpression.SelectOrGroupClause.AcceptVisitor(this, data); + queryExpression.SelectOrGroupClause = ((QueryExpressionClause)(nodeStack.Pop())); + nodeStack.Push(queryExpression.IntoClause); + queryExpression.IntoClause.AcceptVisitor(this, data); + queryExpression.IntoClause = ((QueryExpressionIntoClause)(nodeStack.Pop())); + return null; + } + + public virtual object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) { + Debug.Assert((queryExpressionFromClause != null)); + Debug.Assert((queryExpressionFromClause.Generators != null)); + for (int i = 0; i < queryExpressionFromClause.Generators.Count; i++) { + QueryExpressionFromGenerator o = queryExpressionFromClause.Generators[i]; + Debug.Assert(o != null); + nodeStack.Push(o); + o.AcceptVisitor(this, data); + o = (QueryExpressionFromGenerator)nodeStack.Pop(); + if (o == null) + queryExpressionFromClause.Generators.RemoveAt(i--); + else + queryExpressionFromClause.Generators[i] = o; + } + return null; + } + + public virtual object VisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) { + Debug.Assert((queryExpressionFromGenerator != null)); + Debug.Assert((queryExpressionFromGenerator.InExpression != null)); + nodeStack.Push(queryExpressionFromGenerator.InExpression); + queryExpressionFromGenerator.InExpression.AcceptVisitor(this, data); + queryExpressionFromGenerator.InExpression = ((Expression)(nodeStack.Pop())); + return null; + } + + public virtual object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) { + Debug.Assert((queryExpressionGroupClause != null)); + Debug.Assert((queryExpressionGroupClause.Projection != null)); + Debug.Assert((queryExpressionGroupClause.GroupBy != null)); + nodeStack.Push(queryExpressionGroupClause.Projection); + queryExpressionGroupClause.Projection.AcceptVisitor(this, data); + queryExpressionGroupClause.Projection = ((Expression)(nodeStack.Pop())); + nodeStack.Push(queryExpressionGroupClause.GroupBy); + queryExpressionGroupClause.GroupBy.AcceptVisitor(this, data); + queryExpressionGroupClause.GroupBy = ((Expression)(nodeStack.Pop())); + return null; + } + + public virtual object VisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data) { + Debug.Assert((queryExpressionIntoClause != null)); + Debug.Assert((queryExpressionIntoClause.ContinuedQuery != null)); + nodeStack.Push(queryExpressionIntoClause.ContinuedQuery); + queryExpressionIntoClause.ContinuedQuery.AcceptVisitor(this, data); + queryExpressionIntoClause.ContinuedQuery = ((QueryExpression)(nodeStack.Pop())); + return null; + } + + public virtual object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) { + Debug.Assert((queryExpressionOrdering != null)); + Debug.Assert((queryExpressionOrdering.Criteria != null)); + nodeStack.Push(queryExpressionOrdering.Criteria); + queryExpressionOrdering.Criteria.AcceptVisitor(this, data); + queryExpressionOrdering.Criteria = ((Expression)(nodeStack.Pop())); + return null; + } + + public virtual object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) { + Debug.Assert((queryExpressionSelectClause != null)); + Debug.Assert((queryExpressionSelectClause.Projection != null)); + nodeStack.Push(queryExpressionSelectClause.Projection); + queryExpressionSelectClause.Projection.AcceptVisitor(this, data); + queryExpressionSelectClause.Projection = ((Expression)(nodeStack.Pop())); + return null; + } + + public virtual object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) { + Debug.Assert((queryExpressionWhereClause != null)); + Debug.Assert((queryExpressionWhereClause.Condition != null)); + nodeStack.Push(queryExpressionWhereClause.Condition); + queryExpressionWhereClause.Condition.AcceptVisitor(this, data); + queryExpressionWhereClause.Condition = ((Expression)(nodeStack.Pop())); + return null; + } + public virtual object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { Debug.Assert((raiseEventStatement != null)); Debug.Assert((raiseEventStatement.Arguments != null)); diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/CSharpConstructsVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/CSharpConstructsVisitor.cs index 10f5de60e6..a819eb0590 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/CSharpConstructsVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/CSharpConstructsVisitor.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.NRefactory.Visitors /// /// Converts special C# constructs to use more general AST classes. /// - public class CSharpConstructsVisitor : AbstractAstTransformer + public class CSharpConstructsVisitor : ConvertVisitorBase { // The following conversions are implemented: // a == null -> a Is Nothing @@ -69,16 +69,14 @@ namespace ICSharpCode.NRefactory.Visitors return base.VisitExpressionStatement(expressionStatement, data); } - public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) { - base.VisitIfElseStatement(ifElseStatement, data); BinaryOperatorExpression boe = ifElseStatement.Condition as BinaryOperatorExpression; if (ifElseStatement.ElseIfSections.Count == 0 && ifElseStatement.FalseStatement.Count == 0 && ifElseStatement.TrueStatement.Count == 1 && boe != null - && boe.Op == BinaryOperatorType.ReferenceInequality + && boe.Op == BinaryOperatorType.InEquality && (IsNullLiteralExpression(boe.Left) || IsNullLiteralExpression(boe.Right)) ) { @@ -102,7 +100,7 @@ namespace ICSharpCode.NRefactory.Visitors } } } - return null; + return base.VisitIfElseStatement(ifElseStatement, data); } public override object VisitForStatement(ForStatement forStatement, object data) diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/CSharpToVBNetConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/CSharpToVBNetConvertVisitor.cs deleted file mode 100644 index 7e01474e4b..0000000000 --- a/src/Libraries/NRefactory/Project/Src/Visitors/CSharpToVBNetConvertVisitor.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using ICSharpCode.NRefactory.Ast; - -namespace ICSharpCode.NRefactory.Visitors -{ - /// - /// This class converts C# constructs to their VB.NET equivalents. - /// - public class CSharpToVBNetConvertVisitor : CSharpConstructsVisitor - { - public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data) - { - base.VisitCompilationUnit(compilationUnit, data); - compilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), data); - return null; - } - } -} diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs index cee2f8b68b..82362f64fd 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs @@ -24,13 +24,13 @@ namespace ICSharpCode.NRefactory.Visitors TypeDeclaration currentTypeDeclaration = null; - IEnvironmentInformationProvider environmentInformationProvider = new DummyEnvironmentInformationProvider(); + IEnvironmentInformationProvider environmentInformationProvider = DummyEnvironmentInformationProvider.Instance; public IEnvironmentInformationProvider EnvironmentInformationProvider { - get { - return environmentInformationProvider; - } + get { return environmentInformationProvider; } set { + if (value == null) + throw new ArgumentNullException("value"); environmentInformationProvider = value; } } @@ -70,7 +70,6 @@ namespace ICSharpCode.NRefactory.Visitors } } - // FIXME: map all modifiers correctly static MemberAttributes ConvMemberAttributes(Modifiers modifier) { MemberAttributes attr = (MemberAttributes)0; @@ -131,7 +130,7 @@ namespace ICSharpCode.NRefactory.Visitors namespaceDeclarations.Pop(); codeCompileUnit.Namespaces.Add(currentNamespace); - // TODO : Nested namespaces allowed in CodeDOM ? Doesn't seem so :( + // Nested namespaces are not allowed in CodeDOM return null; } @@ -538,7 +537,7 @@ namespace ICSharpCode.NRefactory.Visitors break; case BinaryOperatorType.ExclusiveOr: - // TODO ExclusiveOr + // CodeDom doesn't support ExclusiveOr op = CodeBinaryOperatorType.BitwiseAnd; break; } diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/ConvertVisitorBase.cs b/src/Libraries/NRefactory/Project/Src/Visitors/ConvertVisitorBase.cs new file mode 100644 index 0000000000..a8d3f9ee68 --- /dev/null +++ b/src/Libraries/NRefactory/Project/Src/Visitors/ConvertVisitorBase.cs @@ -0,0 +1,19 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Visitors +{ + /// + /// Base class for the conversion visitors. + /// + public class ConvertVisitorBase : AbstractAstTransformer + { + + } +} diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/LookupTableVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/LookupTableVisitor.cs index 808d0d4b0b..c737530662 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/LookupTableVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/LookupTableVisitor.cs @@ -12,45 +12,27 @@ using ICSharpCode.NRefactory.Ast; namespace ICSharpCode.NRefactory.Visitors { - public class LocalLookupVariable + public sealed class LocalLookupVariable { - TypeReference typeRef; - Location startPos; - Location endPos; - bool isConst; - - public TypeReference TypeRef { - get { - return typeRef; - } - } - public Location StartPos { - get { - return startPos; - } - } - public Location EndPos { - get { - return endPos; - } - } - - public bool IsConst { - get { - return isConst; - } - } - - public LocalLookupVariable(TypeReference typeRef, Location startPos, Location endPos, bool isConst) + public readonly TypeReference TypeRef; + public readonly Location StartPos; + public readonly Location EndPos; + public readonly bool IsConst; + public readonly bool IsLoopVariable; + public readonly Expression Initializer; + + public LocalLookupVariable(TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer) { - this.typeRef = typeRef; - this.startPos = startPos; - this.endPos = endPos; - this.isConst = isConst; + this.TypeRef = typeRef; + this.StartPos = startPos; + this.EndPos = endPos; + this.IsConst = isConst; + this.IsLoopVariable = isLoopVariable; + this.Initializer = initializer; } } - public class LookupTableVisitor : AbstractAstVisitor + public sealed class LookupTableVisitor : AbstractAstVisitor { Dictionary> variables; @@ -74,7 +56,9 @@ namespace ICSharpCode.NRefactory.Visitors variables = new Dictionary>(nameComparer); } - public void AddVariable(TypeReference typeRef, string name, Location startPos, Location endPos, bool isConst) + public void AddVariable(TypeReference typeRef, string name, + Location startPos, Location endPos, bool isConst, + bool isLoopVariable, Expression initializer) { if (name == null || name.Length == 0) { return; @@ -85,7 +69,7 @@ namespace ICSharpCode.NRefactory.Visitors } else { list = (List)variables[name]; } - list.Add(new LocalLookupVariable(typeRef, startPos, endPos, isConst)); + list.Add(new LocalLookupVariable(typeRef, startPos, endPos, isConst, isLoopVariable, initializer)); } public override object VisitWithStatement(WithStatement withStatement, object data) @@ -119,7 +103,8 @@ namespace ICSharpCode.NRefactory.Visitors varDecl.Name, localVariableDeclaration.StartLocation, CurrentEndLocation, - (localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const); + (localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const, + false, varDecl.Initializer); } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); } @@ -127,11 +112,38 @@ namespace ICSharpCode.NRefactory.Visitors public override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) { foreach (ParameterDeclarationExpression p in anonymousMethodExpression.Parameters) { - AddVariable(p.TypeReference, p.ParameterName, anonymousMethodExpression.StartLocation, anonymousMethodExpression.EndLocation, false); + AddVariable(p.TypeReference, p.ParameterName, + anonymousMethodExpression.StartLocation, anonymousMethodExpression.EndLocation, + false, false, null); } return base.VisitAnonymousMethodExpression(anonymousMethodExpression, data); } + public override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) + { + foreach (ParameterDeclarationExpression p in lambdaExpression.Parameters) { + AddVariable(p.TypeReference, p.ParameterName, + lambdaExpression.StartLocation, lambdaExpression.EndLocation, + false, false, null); + } + return base.VisitLambdaExpression(lambdaExpression, data); + } + + public override object VisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) + { + if (queryExpressionFromGenerator.Parent != null) { + // find parent QueryExpression + QueryExpression parentExpression = queryExpressionFromGenerator.Parent.Parent as QueryExpression; + + if (parentExpression != null) { + AddVariable(null, queryExpressionFromGenerator.Identifier, + parentExpression.StartLocation, parentExpression.EndLocation, + false, true, queryExpressionFromGenerator.InExpression); + } + } + return base.VisitQueryExpressionFromGenerator(queryExpressionFromGenerator, data); + } + public override object VisitForNextStatement(ForNextStatement forNextStatement, object data) { // uses LocalVariableDeclaration, we just have to put the end location on the stack @@ -177,7 +189,8 @@ namespace ICSharpCode.NRefactory.Visitors foreachStatement.VariableName, foreachStatement.StartLocation, foreachStatement.EndLocation, - false); + false, true, + foreachStatement.Expression); if (foreachStatement.Expression != null) { foreachStatement.Expression.AcceptVisitor(this, data); @@ -204,7 +217,7 @@ namespace ICSharpCode.NRefactory.Visitors catchClause.VariableName, catchClause.StatementBlock.StartLocation, catchClause.StatementBlock.EndLocation, - false); + false, false, null); } catchClause.StatementBlock.AcceptVisitor(this, data); } diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs index c6781ce474..b4d1b8c0cc 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.42 +// Runtime Version:2.0.50727.312 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -33,1112 +33,1211 @@ namespace ICSharpCode.NRefactory.Visitors { public sealed override object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) { this.BeginVisit(addHandlerStatement); - object result = this.TrackedVisit(addHandlerStatement, data); + object result = this.TrackedVisitAddHandlerStatement(addHandlerStatement, data); this.EndVisit(addHandlerStatement); return result; } public sealed override object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) { this.BeginVisit(addressOfExpression); - object result = this.TrackedVisit(addressOfExpression, data); + object result = this.TrackedVisitAddressOfExpression(addressOfExpression, data); this.EndVisit(addressOfExpression); return result; } public sealed override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) { this.BeginVisit(anonymousMethodExpression); - object result = this.TrackedVisit(anonymousMethodExpression, data); + object result = this.TrackedVisitAnonymousMethodExpression(anonymousMethodExpression, data); this.EndVisit(anonymousMethodExpression); return result; } public sealed override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { this.BeginVisit(arrayCreateExpression); - object result = this.TrackedVisit(arrayCreateExpression, data); + object result = this.TrackedVisitArrayCreateExpression(arrayCreateExpression, data); this.EndVisit(arrayCreateExpression); return result; } - public sealed override object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data) { - this.BeginVisit(arrayInitializerExpression); - object result = this.TrackedVisit(arrayInitializerExpression, data); - this.EndVisit(arrayInitializerExpression); - return result; - } - public sealed override object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { this.BeginVisit(assignmentExpression); - object result = this.TrackedVisit(assignmentExpression, data); + object result = this.TrackedVisitAssignmentExpression(assignmentExpression, data); this.EndVisit(assignmentExpression); return result; } public sealed override object VisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data) { this.BeginVisit(attribute); - object result = this.TrackedVisit(attribute, data); + object result = this.TrackedVisitAttribute(attribute, data); this.EndVisit(attribute); return result; } public sealed override object VisitAttributeSection(AttributeSection attributeSection, object data) { this.BeginVisit(attributeSection); - object result = this.TrackedVisit(attributeSection, data); + object result = this.TrackedVisitAttributeSection(attributeSection, data); this.EndVisit(attributeSection); return result; } public sealed override object VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data) { this.BeginVisit(baseReferenceExpression); - object result = this.TrackedVisit(baseReferenceExpression, data); + object result = this.TrackedVisitBaseReferenceExpression(baseReferenceExpression, data); this.EndVisit(baseReferenceExpression); return result; } public sealed override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { this.BeginVisit(binaryOperatorExpression); - object result = this.TrackedVisit(binaryOperatorExpression, data); + object result = this.TrackedVisitBinaryOperatorExpression(binaryOperatorExpression, data); this.EndVisit(binaryOperatorExpression); return result; } public sealed override object VisitBlockStatement(BlockStatement blockStatement, object data) { this.BeginVisit(blockStatement); - object result = this.TrackedVisit(blockStatement, data); + object result = this.TrackedVisitBlockStatement(blockStatement, data); this.EndVisit(blockStatement); return result; } public sealed override object VisitBreakStatement(BreakStatement breakStatement, object data) { this.BeginVisit(breakStatement); - object result = this.TrackedVisit(breakStatement, data); + object result = this.TrackedVisitBreakStatement(breakStatement, data); this.EndVisit(breakStatement); return result; } public sealed override object VisitCaseLabel(CaseLabel caseLabel, object data) { this.BeginVisit(caseLabel); - object result = this.TrackedVisit(caseLabel, data); + object result = this.TrackedVisitCaseLabel(caseLabel, data); this.EndVisit(caseLabel); return result; } public sealed override object VisitCastExpression(CastExpression castExpression, object data) { this.BeginVisit(castExpression); - object result = this.TrackedVisit(castExpression, data); + object result = this.TrackedVisitCastExpression(castExpression, data); this.EndVisit(castExpression); return result; } public sealed override object VisitCatchClause(CatchClause catchClause, object data) { this.BeginVisit(catchClause); - object result = this.TrackedVisit(catchClause, data); + object result = this.TrackedVisitCatchClause(catchClause, data); this.EndVisit(catchClause); return result; } public sealed override object VisitCheckedExpression(CheckedExpression checkedExpression, object data) { this.BeginVisit(checkedExpression); - object result = this.TrackedVisit(checkedExpression, data); + object result = this.TrackedVisitCheckedExpression(checkedExpression, data); this.EndVisit(checkedExpression); return result; } public sealed override object VisitCheckedStatement(CheckedStatement checkedStatement, object data) { this.BeginVisit(checkedStatement); - object result = this.TrackedVisit(checkedStatement, data); + object result = this.TrackedVisitCheckedStatement(checkedStatement, data); this.EndVisit(checkedStatement); return result; } public sealed override object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data) { this.BeginVisit(classReferenceExpression); - object result = this.TrackedVisit(classReferenceExpression, data); + object result = this.TrackedVisitClassReferenceExpression(classReferenceExpression, data); this.EndVisit(classReferenceExpression); return result; } + public sealed override object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data) { + this.BeginVisit(collectionInitializerExpression); + object result = this.TrackedVisitCollectionInitializerExpression(collectionInitializerExpression, data); + this.EndVisit(collectionInitializerExpression); + return result; + } + public sealed override object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { this.BeginVisit(compilationUnit); - object result = this.TrackedVisit(compilationUnit, data); + object result = this.TrackedVisitCompilationUnit(compilationUnit, data); this.EndVisit(compilationUnit); return result; } public sealed override object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) { this.BeginVisit(conditionalExpression); - object result = this.TrackedVisit(conditionalExpression, data); + object result = this.TrackedVisitConditionalExpression(conditionalExpression, data); this.EndVisit(conditionalExpression); return result; } public sealed override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { this.BeginVisit(constructorDeclaration); - object result = this.TrackedVisit(constructorDeclaration, data); + object result = this.TrackedVisitConstructorDeclaration(constructorDeclaration, data); this.EndVisit(constructorDeclaration); return result; } public sealed override object VisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data) { this.BeginVisit(constructorInitializer); - object result = this.TrackedVisit(constructorInitializer, data); + object result = this.TrackedVisitConstructorInitializer(constructorInitializer, data); this.EndVisit(constructorInitializer); return result; } public sealed override object VisitContinueStatement(ContinueStatement continueStatement, object data) { this.BeginVisit(continueStatement); - object result = this.TrackedVisit(continueStatement, data); + object result = this.TrackedVisitContinueStatement(continueStatement, data); this.EndVisit(continueStatement); return result; } public sealed override object VisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data) { this.BeginVisit(declareDeclaration); - object result = this.TrackedVisit(declareDeclaration, data); + object result = this.TrackedVisitDeclareDeclaration(declareDeclaration, data); this.EndVisit(declareDeclaration); return result; } public sealed override object VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data) { this.BeginVisit(defaultValueExpression); - object result = this.TrackedVisit(defaultValueExpression, data); + object result = this.TrackedVisitDefaultValueExpression(defaultValueExpression, data); this.EndVisit(defaultValueExpression); return result; } public sealed override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) { this.BeginVisit(delegateDeclaration); - object result = this.TrackedVisit(delegateDeclaration, data); + object result = this.TrackedVisitDelegateDeclaration(delegateDeclaration, data); this.EndVisit(delegateDeclaration); return result; } public sealed override object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) { this.BeginVisit(destructorDeclaration); - object result = this.TrackedVisit(destructorDeclaration, data); + object result = this.TrackedVisitDestructorDeclaration(destructorDeclaration, data); this.EndVisit(destructorDeclaration); return result; } public sealed override object VisitDirectionExpression(DirectionExpression directionExpression, object data) { this.BeginVisit(directionExpression); - object result = this.TrackedVisit(directionExpression, data); + object result = this.TrackedVisitDirectionExpression(directionExpression, data); this.EndVisit(directionExpression); return result; } public sealed override object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) { this.BeginVisit(doLoopStatement); - object result = this.TrackedVisit(doLoopStatement, data); + object result = this.TrackedVisitDoLoopStatement(doLoopStatement, data); this.EndVisit(doLoopStatement); return result; } public sealed override object VisitElseIfSection(ElseIfSection elseIfSection, object data) { this.BeginVisit(elseIfSection); - object result = this.TrackedVisit(elseIfSection, data); + object result = this.TrackedVisitElseIfSection(elseIfSection, data); this.EndVisit(elseIfSection); return result; } public sealed override object VisitEmptyStatement(EmptyStatement emptyStatement, object data) { this.BeginVisit(emptyStatement); - object result = this.TrackedVisit(emptyStatement, data); + object result = this.TrackedVisitEmptyStatement(emptyStatement, data); this.EndVisit(emptyStatement); return result; } public sealed override object VisitEndStatement(EndStatement endStatement, object data) { this.BeginVisit(endStatement); - object result = this.TrackedVisit(endStatement, data); + object result = this.TrackedVisitEndStatement(endStatement, data); this.EndVisit(endStatement); return result; } public sealed override object VisitEraseStatement(EraseStatement eraseStatement, object data) { this.BeginVisit(eraseStatement); - object result = this.TrackedVisit(eraseStatement, data); + object result = this.TrackedVisitEraseStatement(eraseStatement, data); this.EndVisit(eraseStatement); return result; } public sealed override object VisitErrorStatement(ErrorStatement errorStatement, object data) { this.BeginVisit(errorStatement); - object result = this.TrackedVisit(errorStatement, data); + object result = this.TrackedVisitErrorStatement(errorStatement, data); this.EndVisit(errorStatement); return result; } public sealed override object VisitEventAddRegion(EventAddRegion eventAddRegion, object data) { this.BeginVisit(eventAddRegion); - object result = this.TrackedVisit(eventAddRegion, data); + object result = this.TrackedVisitEventAddRegion(eventAddRegion, data); this.EndVisit(eventAddRegion); return result; } public sealed override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) { this.BeginVisit(eventDeclaration); - object result = this.TrackedVisit(eventDeclaration, data); + object result = this.TrackedVisitEventDeclaration(eventDeclaration, data); this.EndVisit(eventDeclaration); return result; } public sealed override object VisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data) { this.BeginVisit(eventRaiseRegion); - object result = this.TrackedVisit(eventRaiseRegion, data); + object result = this.TrackedVisitEventRaiseRegion(eventRaiseRegion, data); this.EndVisit(eventRaiseRegion); return result; } public sealed override object VisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data) { this.BeginVisit(eventRemoveRegion); - object result = this.TrackedVisit(eventRemoveRegion, data); + object result = this.TrackedVisitEventRemoveRegion(eventRemoveRegion, data); this.EndVisit(eventRemoveRegion); return result; } public sealed override object VisitExitStatement(ExitStatement exitStatement, object data) { this.BeginVisit(exitStatement); - object result = this.TrackedVisit(exitStatement, data); + object result = this.TrackedVisitExitStatement(exitStatement, data); this.EndVisit(exitStatement); return result; } public sealed override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) { this.BeginVisit(expressionStatement); - object result = this.TrackedVisit(expressionStatement, data); + object result = this.TrackedVisitExpressionStatement(expressionStatement, data); this.EndVisit(expressionStatement); return result; } public sealed override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) { this.BeginVisit(fieldDeclaration); - object result = this.TrackedVisit(fieldDeclaration, data); + object result = this.TrackedVisitFieldDeclaration(fieldDeclaration, data); this.EndVisit(fieldDeclaration); return result; } public sealed override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) { this.BeginVisit(fieldReferenceExpression); - object result = this.TrackedVisit(fieldReferenceExpression, data); + object result = this.TrackedVisitFieldReferenceExpression(fieldReferenceExpression, data); this.EndVisit(fieldReferenceExpression); return result; } public sealed override object VisitFixedStatement(FixedStatement fixedStatement, object data) { this.BeginVisit(fixedStatement); - object result = this.TrackedVisit(fixedStatement, data); + object result = this.TrackedVisitFixedStatement(fixedStatement, data); this.EndVisit(fixedStatement); return result; } public sealed override object VisitForeachStatement(ForeachStatement foreachStatement, object data) { this.BeginVisit(foreachStatement); - object result = this.TrackedVisit(foreachStatement, data); + object result = this.TrackedVisitForeachStatement(foreachStatement, data); this.EndVisit(foreachStatement); return result; } public sealed override object VisitForNextStatement(ForNextStatement forNextStatement, object data) { this.BeginVisit(forNextStatement); - object result = this.TrackedVisit(forNextStatement, data); + object result = this.TrackedVisitForNextStatement(forNextStatement, data); this.EndVisit(forNextStatement); return result; } public sealed override object VisitForStatement(ForStatement forStatement, object data) { this.BeginVisit(forStatement); - object result = this.TrackedVisit(forStatement, data); + object result = this.TrackedVisitForStatement(forStatement, data); this.EndVisit(forStatement); return result; } public sealed override object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) { this.BeginVisit(gotoCaseStatement); - object result = this.TrackedVisit(gotoCaseStatement, data); + object result = this.TrackedVisitGotoCaseStatement(gotoCaseStatement, data); this.EndVisit(gotoCaseStatement); return result; } public sealed override object VisitGotoStatement(GotoStatement gotoStatement, object data) { this.BeginVisit(gotoStatement); - object result = this.TrackedVisit(gotoStatement, data); + object result = this.TrackedVisitGotoStatement(gotoStatement, data); this.EndVisit(gotoStatement); return result; } public sealed override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { this.BeginVisit(identifierExpression); - object result = this.TrackedVisit(identifierExpression, data); + object result = this.TrackedVisitIdentifierExpression(identifierExpression, data); this.EndVisit(identifierExpression); return result; } public sealed override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) { this.BeginVisit(ifElseStatement); - object result = this.TrackedVisit(ifElseStatement, data); + object result = this.TrackedVisitIfElseStatement(ifElseStatement, data); this.EndVisit(ifElseStatement); return result; } public sealed override object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { this.BeginVisit(indexerDeclaration); - object result = this.TrackedVisit(indexerDeclaration, data); + object result = this.TrackedVisitIndexerDeclaration(indexerDeclaration, data); this.EndVisit(indexerDeclaration); return result; } public sealed override object VisitIndexerExpression(IndexerExpression indexerExpression, object data) { this.BeginVisit(indexerExpression); - object result = this.TrackedVisit(indexerExpression, data); + object result = this.TrackedVisitIndexerExpression(indexerExpression, data); this.EndVisit(indexerExpression); return result; } public sealed override object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) { this.BeginVisit(innerClassTypeReference); - object result = this.TrackedVisit(innerClassTypeReference, data); + object result = this.TrackedVisitInnerClassTypeReference(innerClassTypeReference, data); this.EndVisit(innerClassTypeReference); return result; } public sealed override object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) { this.BeginVisit(interfaceImplementation); - object result = this.TrackedVisit(interfaceImplementation, data); + object result = this.TrackedVisitInterfaceImplementation(interfaceImplementation, data); this.EndVisit(interfaceImplementation); return result; } public sealed override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { this.BeginVisit(invocationExpression); - object result = this.TrackedVisit(invocationExpression, data); + object result = this.TrackedVisitInvocationExpression(invocationExpression, data); this.EndVisit(invocationExpression); return result; } public sealed override object VisitLabelStatement(LabelStatement labelStatement, object data) { this.BeginVisit(labelStatement); - object result = this.TrackedVisit(labelStatement, data); + object result = this.TrackedVisitLabelStatement(labelStatement, data); this.EndVisit(labelStatement); return result; } + public sealed override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) { + this.BeginVisit(lambdaExpression); + object result = this.TrackedVisitLambdaExpression(lambdaExpression, data); + this.EndVisit(lambdaExpression); + return result; + } + public sealed override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { this.BeginVisit(localVariableDeclaration); - object result = this.TrackedVisit(localVariableDeclaration, data); + object result = this.TrackedVisitLocalVariableDeclaration(localVariableDeclaration, data); this.EndVisit(localVariableDeclaration); return result; } public sealed override object VisitLockStatement(LockStatement lockStatement, object data) { this.BeginVisit(lockStatement); - object result = this.TrackedVisit(lockStatement, data); + object result = this.TrackedVisitLockStatement(lockStatement, data); this.EndVisit(lockStatement); return result; } public sealed override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { this.BeginVisit(methodDeclaration); - object result = this.TrackedVisit(methodDeclaration, data); + object result = this.TrackedVisitMethodDeclaration(methodDeclaration, data); this.EndVisit(methodDeclaration); return result; } public sealed override object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) { this.BeginVisit(namedArgumentExpression); - object result = this.TrackedVisit(namedArgumentExpression, data); + object result = this.TrackedVisitNamedArgumentExpression(namedArgumentExpression, data); this.EndVisit(namedArgumentExpression); return result; } public sealed override object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { this.BeginVisit(namespaceDeclaration); - object result = this.TrackedVisit(namespaceDeclaration, data); + object result = this.TrackedVisitNamespaceDeclaration(namespaceDeclaration, data); this.EndVisit(namespaceDeclaration); return result; } public sealed override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { this.BeginVisit(objectCreateExpression); - object result = this.TrackedVisit(objectCreateExpression, data); + object result = this.TrackedVisitObjectCreateExpression(objectCreateExpression, data); this.EndVisit(objectCreateExpression); return result; } public sealed override object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) { this.BeginVisit(onErrorStatement); - object result = this.TrackedVisit(onErrorStatement, data); + object result = this.TrackedVisitOnErrorStatement(onErrorStatement, data); this.EndVisit(onErrorStatement); return result; } public sealed override object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) { this.BeginVisit(operatorDeclaration); - object result = this.TrackedVisit(operatorDeclaration, data); + object result = this.TrackedVisitOperatorDeclaration(operatorDeclaration, data); this.EndVisit(operatorDeclaration); return result; } public sealed override object VisitOptionDeclaration(OptionDeclaration optionDeclaration, object data) { this.BeginVisit(optionDeclaration); - object result = this.TrackedVisit(optionDeclaration, data); + object result = this.TrackedVisitOptionDeclaration(optionDeclaration, data); this.EndVisit(optionDeclaration); return result; } public sealed override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) { this.BeginVisit(parameterDeclarationExpression); - object result = this.TrackedVisit(parameterDeclarationExpression, data); + object result = this.TrackedVisitParameterDeclarationExpression(parameterDeclarationExpression, data); this.EndVisit(parameterDeclarationExpression); return result; } public sealed override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) { this.BeginVisit(parenthesizedExpression); - object result = this.TrackedVisit(parenthesizedExpression, data); + object result = this.TrackedVisitParenthesizedExpression(parenthesizedExpression, data); this.EndVisit(parenthesizedExpression); return result; } public sealed override object VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) { this.BeginVisit(pointerReferenceExpression); - object result = this.TrackedVisit(pointerReferenceExpression, data); + object result = this.TrackedVisitPointerReferenceExpression(pointerReferenceExpression, data); this.EndVisit(pointerReferenceExpression); return result; } public sealed override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) { this.BeginVisit(primitiveExpression); - object result = this.TrackedVisit(primitiveExpression, data); + object result = this.TrackedVisitPrimitiveExpression(primitiveExpression, data); this.EndVisit(primitiveExpression); return result; } public sealed override object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { this.BeginVisit(propertyDeclaration); - object result = this.TrackedVisit(propertyDeclaration, data); + object result = this.TrackedVisitPropertyDeclaration(propertyDeclaration, data); this.EndVisit(propertyDeclaration); return result; } public sealed override object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) { this.BeginVisit(propertyGetRegion); - object result = this.TrackedVisit(propertyGetRegion, data); + object result = this.TrackedVisitPropertyGetRegion(propertyGetRegion, data); this.EndVisit(propertyGetRegion); return result; } public sealed override object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data) { this.BeginVisit(propertySetRegion); - object result = this.TrackedVisit(propertySetRegion, data); + object result = this.TrackedVisitPropertySetRegion(propertySetRegion, data); this.EndVisit(propertySetRegion); return result; } + public sealed override object VisitQueryExpression(QueryExpression queryExpression, object data) { + this.BeginVisit(queryExpression); + object result = this.TrackedVisitQueryExpression(queryExpression, data); + this.EndVisit(queryExpression); + return result; + } + + public sealed override object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) { + this.BeginVisit(queryExpressionFromClause); + object result = this.TrackedVisitQueryExpressionFromClause(queryExpressionFromClause, data); + this.EndVisit(queryExpressionFromClause); + return result; + } + + public sealed override object VisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) { + this.BeginVisit(queryExpressionFromGenerator); + object result = this.TrackedVisitQueryExpressionFromGenerator(queryExpressionFromGenerator, data); + this.EndVisit(queryExpressionFromGenerator); + return result; + } + + public sealed override object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) { + this.BeginVisit(queryExpressionGroupClause); + object result = this.TrackedVisitQueryExpressionGroupClause(queryExpressionGroupClause, data); + this.EndVisit(queryExpressionGroupClause); + return result; + } + + public sealed override object VisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data) { + this.BeginVisit(queryExpressionIntoClause); + object result = this.TrackedVisitQueryExpressionIntoClause(queryExpressionIntoClause, data); + this.EndVisit(queryExpressionIntoClause); + return result; + } + + public sealed override object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) { + this.BeginVisit(queryExpressionOrdering); + object result = this.TrackedVisitQueryExpressionOrdering(queryExpressionOrdering, data); + this.EndVisit(queryExpressionOrdering); + return result; + } + + public sealed override object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) { + this.BeginVisit(queryExpressionSelectClause); + object result = this.TrackedVisitQueryExpressionSelectClause(queryExpressionSelectClause, data); + this.EndVisit(queryExpressionSelectClause); + return result; + } + + public sealed override object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) { + this.BeginVisit(queryExpressionWhereClause); + object result = this.TrackedVisitQueryExpressionWhereClause(queryExpressionWhereClause, data); + this.EndVisit(queryExpressionWhereClause); + return result; + } + public sealed override object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { this.BeginVisit(raiseEventStatement); - object result = this.TrackedVisit(raiseEventStatement, data); + object result = this.TrackedVisitRaiseEventStatement(raiseEventStatement, data); this.EndVisit(raiseEventStatement); return result; } public sealed override object VisitReDimStatement(ReDimStatement reDimStatement, object data) { this.BeginVisit(reDimStatement); - object result = this.TrackedVisit(reDimStatement, data); + object result = this.TrackedVisitReDimStatement(reDimStatement, data); this.EndVisit(reDimStatement); return result; } public sealed override object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data) { this.BeginVisit(removeHandlerStatement); - object result = this.TrackedVisit(removeHandlerStatement, data); + object result = this.TrackedVisitRemoveHandlerStatement(removeHandlerStatement, data); this.EndVisit(removeHandlerStatement); return result; } public sealed override object VisitResumeStatement(ResumeStatement resumeStatement, object data) { this.BeginVisit(resumeStatement); - object result = this.TrackedVisit(resumeStatement, data); + object result = this.TrackedVisitResumeStatement(resumeStatement, data); this.EndVisit(resumeStatement); return result; } public sealed override object VisitReturnStatement(ReturnStatement returnStatement, object data) { this.BeginVisit(returnStatement); - object result = this.TrackedVisit(returnStatement, data); + object result = this.TrackedVisitReturnStatement(returnStatement, data); this.EndVisit(returnStatement); return result; } public sealed override object VisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data) { this.BeginVisit(sizeOfExpression); - object result = this.TrackedVisit(sizeOfExpression, data); + object result = this.TrackedVisitSizeOfExpression(sizeOfExpression, data); this.EndVisit(sizeOfExpression); return result; } public sealed override object VisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data) { this.BeginVisit(stackAllocExpression); - object result = this.TrackedVisit(stackAllocExpression, data); + object result = this.TrackedVisitStackAllocExpression(stackAllocExpression, data); this.EndVisit(stackAllocExpression); return result; } public sealed override object VisitStopStatement(StopStatement stopStatement, object data) { this.BeginVisit(stopStatement); - object result = this.TrackedVisit(stopStatement, data); + object result = this.TrackedVisitStopStatement(stopStatement, data); this.EndVisit(stopStatement); return result; } public sealed override object VisitSwitchSection(SwitchSection switchSection, object data) { this.BeginVisit(switchSection); - object result = this.TrackedVisit(switchSection, data); + object result = this.TrackedVisitSwitchSection(switchSection, data); this.EndVisit(switchSection); return result; } public sealed override object VisitSwitchStatement(SwitchStatement switchStatement, object data) { this.BeginVisit(switchStatement); - object result = this.TrackedVisit(switchStatement, data); + object result = this.TrackedVisitSwitchStatement(switchStatement, data); this.EndVisit(switchStatement); return result; } public sealed override object VisitTemplateDefinition(TemplateDefinition templateDefinition, object data) { this.BeginVisit(templateDefinition); - object result = this.TrackedVisit(templateDefinition, data); + object result = this.TrackedVisitTemplateDefinition(templateDefinition, data); this.EndVisit(templateDefinition); return result; } public sealed override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) { this.BeginVisit(thisReferenceExpression); - object result = this.TrackedVisit(thisReferenceExpression, data); + object result = this.TrackedVisitThisReferenceExpression(thisReferenceExpression, data); this.EndVisit(thisReferenceExpression); return result; } public sealed override object VisitThrowStatement(ThrowStatement throwStatement, object data) { this.BeginVisit(throwStatement); - object result = this.TrackedVisit(throwStatement, data); + object result = this.TrackedVisitThrowStatement(throwStatement, data); this.EndVisit(throwStatement); return result; } public sealed override object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) { this.BeginVisit(tryCatchStatement); - object result = this.TrackedVisit(tryCatchStatement, data); + object result = this.TrackedVisitTryCatchStatement(tryCatchStatement, data); this.EndVisit(tryCatchStatement); return result; } public sealed override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { this.BeginVisit(typeDeclaration); - object result = this.TrackedVisit(typeDeclaration, data); + object result = this.TrackedVisitTypeDeclaration(typeDeclaration, data); this.EndVisit(typeDeclaration); return result; } public sealed override object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data) { this.BeginVisit(typeOfExpression); - object result = this.TrackedVisit(typeOfExpression, data); + object result = this.TrackedVisitTypeOfExpression(typeOfExpression, data); this.EndVisit(typeOfExpression); return result; } public sealed override object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { this.BeginVisit(typeOfIsExpression); - object result = this.TrackedVisit(typeOfIsExpression, data); + object result = this.TrackedVisitTypeOfIsExpression(typeOfIsExpression, data); this.EndVisit(typeOfIsExpression); return result; } public sealed override object VisitTypeReference(TypeReference typeReference, object data) { this.BeginVisit(typeReference); - object result = this.TrackedVisit(typeReference, data); + object result = this.TrackedVisitTypeReference(typeReference, data); this.EndVisit(typeReference); return result; } public sealed override object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) { this.BeginVisit(typeReferenceExpression); - object result = this.TrackedVisit(typeReferenceExpression, data); + object result = this.TrackedVisitTypeReferenceExpression(typeReferenceExpression, data); this.EndVisit(typeReferenceExpression); return result; } public sealed override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { this.BeginVisit(unaryOperatorExpression); - object result = this.TrackedVisit(unaryOperatorExpression, data); + object result = this.TrackedVisitUnaryOperatorExpression(unaryOperatorExpression, data); this.EndVisit(unaryOperatorExpression); return result; } public sealed override object VisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data) { this.BeginVisit(uncheckedExpression); - object result = this.TrackedVisit(uncheckedExpression, data); + object result = this.TrackedVisitUncheckedExpression(uncheckedExpression, data); this.EndVisit(uncheckedExpression); return result; } public sealed override object VisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data) { this.BeginVisit(uncheckedStatement); - object result = this.TrackedVisit(uncheckedStatement, data); + object result = this.TrackedVisitUncheckedStatement(uncheckedStatement, data); this.EndVisit(uncheckedStatement); return result; } public sealed override object VisitUnsafeStatement(UnsafeStatement unsafeStatement, object data) { this.BeginVisit(unsafeStatement); - object result = this.TrackedVisit(unsafeStatement, data); + object result = this.TrackedVisitUnsafeStatement(unsafeStatement, data); this.EndVisit(unsafeStatement); return result; } public sealed override object VisitUsing(Using @using, object data) { this.BeginVisit(@using); - object result = this.TrackedVisit(@using, data); + object result = this.TrackedVisitUsing(@using, data); this.EndVisit(@using); return result; } public sealed override object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data) { this.BeginVisit(usingDeclaration); - object result = this.TrackedVisit(usingDeclaration, data); + object result = this.TrackedVisitUsingDeclaration(usingDeclaration, data); this.EndVisit(usingDeclaration); return result; } public sealed override object VisitUsingStatement(UsingStatement usingStatement, object data) { this.BeginVisit(usingStatement); - object result = this.TrackedVisit(usingStatement, data); + object result = this.TrackedVisitUsingStatement(usingStatement, data); this.EndVisit(usingStatement); return result; } public sealed override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) { this.BeginVisit(variableDeclaration); - object result = this.TrackedVisit(variableDeclaration, data); + object result = this.TrackedVisitVariableDeclaration(variableDeclaration, data); this.EndVisit(variableDeclaration); return result; } public sealed override object VisitWithStatement(WithStatement withStatement, object data) { this.BeginVisit(withStatement); - object result = this.TrackedVisit(withStatement, data); + object result = this.TrackedVisitWithStatement(withStatement, data); this.EndVisit(withStatement); return result; } public sealed override object VisitYieldStatement(YieldStatement yieldStatement, object data) { this.BeginVisit(yieldStatement); - object result = this.TrackedVisit(yieldStatement, data); + object result = this.TrackedVisitYieldStatement(yieldStatement, data); this.EndVisit(yieldStatement); return result; } - public virtual object TrackedVisit(AddHandlerStatement addHandlerStatement, object data) { + public virtual object TrackedVisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) { return base.VisitAddHandlerStatement(addHandlerStatement, data); } - public virtual object TrackedVisit(AddressOfExpression addressOfExpression, object data) { + public virtual object TrackedVisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) { return base.VisitAddressOfExpression(addressOfExpression, data); } - public virtual object TrackedVisit(AnonymousMethodExpression anonymousMethodExpression, object data) { + public virtual object TrackedVisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) { return base.VisitAnonymousMethodExpression(anonymousMethodExpression, data); } - public virtual object TrackedVisit(ArrayCreateExpression arrayCreateExpression, object data) { + public virtual object TrackedVisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { return base.VisitArrayCreateExpression(arrayCreateExpression, data); } - public virtual object TrackedVisit(ArrayInitializerExpression arrayInitializerExpression, object data) { - return base.VisitArrayInitializerExpression(arrayInitializerExpression, data); - } - - public virtual object TrackedVisit(AssignmentExpression assignmentExpression, object data) { + public virtual object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { return base.VisitAssignmentExpression(assignmentExpression, data); } - public virtual object TrackedVisit(ICSharpCode.NRefactory.Ast.Attribute attribute, object data) { + public virtual object TrackedVisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data) { return base.VisitAttribute(attribute, data); } - public virtual object TrackedVisit(AttributeSection attributeSection, object data) { + public virtual object TrackedVisitAttributeSection(AttributeSection attributeSection, object data) { return base.VisitAttributeSection(attributeSection, data); } - public virtual object TrackedVisit(BaseReferenceExpression baseReferenceExpression, object data) { + public virtual object TrackedVisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data) { return base.VisitBaseReferenceExpression(baseReferenceExpression, data); } - public virtual object TrackedVisit(BinaryOperatorExpression binaryOperatorExpression, object data) { + public virtual object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); } - public virtual object TrackedVisit(BlockStatement blockStatement, object data) { + public virtual object TrackedVisitBlockStatement(BlockStatement blockStatement, object data) { return base.VisitBlockStatement(blockStatement, data); } - public virtual object TrackedVisit(BreakStatement breakStatement, object data) { + public virtual object TrackedVisitBreakStatement(BreakStatement breakStatement, object data) { return base.VisitBreakStatement(breakStatement, data); } - public virtual object TrackedVisit(CaseLabel caseLabel, object data) { + public virtual object TrackedVisitCaseLabel(CaseLabel caseLabel, object data) { return base.VisitCaseLabel(caseLabel, data); } - public virtual object TrackedVisit(CastExpression castExpression, object data) { + public virtual object TrackedVisitCastExpression(CastExpression castExpression, object data) { return base.VisitCastExpression(castExpression, data); } - public virtual object TrackedVisit(CatchClause catchClause, object data) { + public virtual object TrackedVisitCatchClause(CatchClause catchClause, object data) { return base.VisitCatchClause(catchClause, data); } - public virtual object TrackedVisit(CheckedExpression checkedExpression, object data) { + public virtual object TrackedVisitCheckedExpression(CheckedExpression checkedExpression, object data) { return base.VisitCheckedExpression(checkedExpression, data); } - public virtual object TrackedVisit(CheckedStatement checkedStatement, object data) { + public virtual object TrackedVisitCheckedStatement(CheckedStatement checkedStatement, object data) { return base.VisitCheckedStatement(checkedStatement, data); } - public virtual object TrackedVisit(ClassReferenceExpression classReferenceExpression, object data) { + public virtual object TrackedVisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data) { return base.VisitClassReferenceExpression(classReferenceExpression, data); } - public virtual object TrackedVisit(CompilationUnit compilationUnit, object data) { + public virtual object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data) { + return base.VisitCollectionInitializerExpression(collectionInitializerExpression, data); + } + + public virtual object TrackedVisitCompilationUnit(CompilationUnit compilationUnit, object data) { return base.VisitCompilationUnit(compilationUnit, data); } - public virtual object TrackedVisit(ConditionalExpression conditionalExpression, object data) { + public virtual object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data) { return base.VisitConditionalExpression(conditionalExpression, data); } - public virtual object TrackedVisit(ConstructorDeclaration constructorDeclaration, object data) { + public virtual object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { return base.VisitConstructorDeclaration(constructorDeclaration, data); } - public virtual object TrackedVisit(ConstructorInitializer constructorInitializer, object data) { + public virtual object TrackedVisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data) { return base.VisitConstructorInitializer(constructorInitializer, data); } - public virtual object TrackedVisit(ContinueStatement continueStatement, object data) { + public virtual object TrackedVisitContinueStatement(ContinueStatement continueStatement, object data) { return base.VisitContinueStatement(continueStatement, data); } - public virtual object TrackedVisit(DeclareDeclaration declareDeclaration, object data) { + public virtual object TrackedVisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data) { return base.VisitDeclareDeclaration(declareDeclaration, data); } - public virtual object TrackedVisit(DefaultValueExpression defaultValueExpression, object data) { + public virtual object TrackedVisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data) { return base.VisitDefaultValueExpression(defaultValueExpression, data); } - public virtual object TrackedVisit(DelegateDeclaration delegateDeclaration, object data) { + public virtual object TrackedVisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) { return base.VisitDelegateDeclaration(delegateDeclaration, data); } - public virtual object TrackedVisit(DestructorDeclaration destructorDeclaration, object data) { + public virtual object TrackedVisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) { return base.VisitDestructorDeclaration(destructorDeclaration, data); } - public virtual object TrackedVisit(DirectionExpression directionExpression, object data) { + public virtual object TrackedVisitDirectionExpression(DirectionExpression directionExpression, object data) { return base.VisitDirectionExpression(directionExpression, data); } - public virtual object TrackedVisit(DoLoopStatement doLoopStatement, object data) { + public virtual object TrackedVisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) { return base.VisitDoLoopStatement(doLoopStatement, data); } - public virtual object TrackedVisit(ElseIfSection elseIfSection, object data) { + public virtual object TrackedVisitElseIfSection(ElseIfSection elseIfSection, object data) { return base.VisitElseIfSection(elseIfSection, data); } - public virtual object TrackedVisit(EmptyStatement emptyStatement, object data) { + public virtual object TrackedVisitEmptyStatement(EmptyStatement emptyStatement, object data) { return base.VisitEmptyStatement(emptyStatement, data); } - public virtual object TrackedVisit(EndStatement endStatement, object data) { + public virtual object TrackedVisitEndStatement(EndStatement endStatement, object data) { return base.VisitEndStatement(endStatement, data); } - public virtual object TrackedVisit(EraseStatement eraseStatement, object data) { + public virtual object TrackedVisitEraseStatement(EraseStatement eraseStatement, object data) { return base.VisitEraseStatement(eraseStatement, data); } - public virtual object TrackedVisit(ErrorStatement errorStatement, object data) { + public virtual object TrackedVisitErrorStatement(ErrorStatement errorStatement, object data) { return base.VisitErrorStatement(errorStatement, data); } - public virtual object TrackedVisit(EventAddRegion eventAddRegion, object data) { + public virtual object TrackedVisitEventAddRegion(EventAddRegion eventAddRegion, object data) { return base.VisitEventAddRegion(eventAddRegion, data); } - public virtual object TrackedVisit(EventDeclaration eventDeclaration, object data) { + public virtual object TrackedVisitEventDeclaration(EventDeclaration eventDeclaration, object data) { return base.VisitEventDeclaration(eventDeclaration, data); } - public virtual object TrackedVisit(EventRaiseRegion eventRaiseRegion, object data) { + public virtual object TrackedVisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data) { return base.VisitEventRaiseRegion(eventRaiseRegion, data); } - public virtual object TrackedVisit(EventRemoveRegion eventRemoveRegion, object data) { + public virtual object TrackedVisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data) { return base.VisitEventRemoveRegion(eventRemoveRegion, data); } - public virtual object TrackedVisit(ExitStatement exitStatement, object data) { + public virtual object TrackedVisitExitStatement(ExitStatement exitStatement, object data) { return base.VisitExitStatement(exitStatement, data); } - public virtual object TrackedVisit(ExpressionStatement expressionStatement, object data) { + public virtual object TrackedVisitExpressionStatement(ExpressionStatement expressionStatement, object data) { return base.VisitExpressionStatement(expressionStatement, data); } - public virtual object TrackedVisit(FieldDeclaration fieldDeclaration, object data) { + public virtual object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) { return base.VisitFieldDeclaration(fieldDeclaration, data); } - public virtual object TrackedVisit(FieldReferenceExpression fieldReferenceExpression, object data) { + public virtual object TrackedVisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) { return base.VisitFieldReferenceExpression(fieldReferenceExpression, data); } - public virtual object TrackedVisit(FixedStatement fixedStatement, object data) { + public virtual object TrackedVisitFixedStatement(FixedStatement fixedStatement, object data) { return base.VisitFixedStatement(fixedStatement, data); } - public virtual object TrackedVisit(ForeachStatement foreachStatement, object data) { + public virtual object TrackedVisitForeachStatement(ForeachStatement foreachStatement, object data) { return base.VisitForeachStatement(foreachStatement, data); } - public virtual object TrackedVisit(ForNextStatement forNextStatement, object data) { + public virtual object TrackedVisitForNextStatement(ForNextStatement forNextStatement, object data) { return base.VisitForNextStatement(forNextStatement, data); } - public virtual object TrackedVisit(ForStatement forStatement, object data) { + public virtual object TrackedVisitForStatement(ForStatement forStatement, object data) { return base.VisitForStatement(forStatement, data); } - public virtual object TrackedVisit(GotoCaseStatement gotoCaseStatement, object data) { + public virtual object TrackedVisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) { return base.VisitGotoCaseStatement(gotoCaseStatement, data); } - public virtual object TrackedVisit(GotoStatement gotoStatement, object data) { + public virtual object TrackedVisitGotoStatement(GotoStatement gotoStatement, object data) { return base.VisitGotoStatement(gotoStatement, data); } - public virtual object TrackedVisit(IdentifierExpression identifierExpression, object data) { + public virtual object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { return base.VisitIdentifierExpression(identifierExpression, data); } - public virtual object TrackedVisit(IfElseStatement ifElseStatement, object data) { + public virtual object TrackedVisitIfElseStatement(IfElseStatement ifElseStatement, object data) { return base.VisitIfElseStatement(ifElseStatement, data); } - public virtual object TrackedVisit(IndexerDeclaration indexerDeclaration, object data) { + public virtual object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { return base.VisitIndexerDeclaration(indexerDeclaration, data); } - public virtual object TrackedVisit(IndexerExpression indexerExpression, object data) { + public virtual object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data) { return base.VisitIndexerExpression(indexerExpression, data); } - public virtual object TrackedVisit(InnerClassTypeReference innerClassTypeReference, object data) { + public virtual object TrackedVisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) { return base.VisitInnerClassTypeReference(innerClassTypeReference, data); } - public virtual object TrackedVisit(InterfaceImplementation interfaceImplementation, object data) { + public virtual object TrackedVisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) { return base.VisitInterfaceImplementation(interfaceImplementation, data); } - public virtual object TrackedVisit(InvocationExpression invocationExpression, object data) { + public virtual object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data) { return base.VisitInvocationExpression(invocationExpression, data); } - public virtual object TrackedVisit(LabelStatement labelStatement, object data) { + public virtual object TrackedVisitLabelStatement(LabelStatement labelStatement, object data) { return base.VisitLabelStatement(labelStatement, data); } - public virtual object TrackedVisit(LocalVariableDeclaration localVariableDeclaration, object data) { + public virtual object TrackedVisitLambdaExpression(LambdaExpression lambdaExpression, object data) { + return base.VisitLambdaExpression(lambdaExpression, data); + } + + public virtual object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); } - public virtual object TrackedVisit(LockStatement lockStatement, object data) { + public virtual object TrackedVisitLockStatement(LockStatement lockStatement, object data) { return base.VisitLockStatement(lockStatement, data); } - public virtual object TrackedVisit(MethodDeclaration methodDeclaration, object data) { + public virtual object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { return base.VisitMethodDeclaration(methodDeclaration, data); } - public virtual object TrackedVisit(NamedArgumentExpression namedArgumentExpression, object data) { + public virtual object TrackedVisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) { return base.VisitNamedArgumentExpression(namedArgumentExpression, data); } - public virtual object TrackedVisit(NamespaceDeclaration namespaceDeclaration, object data) { + public virtual object TrackedVisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { return base.VisitNamespaceDeclaration(namespaceDeclaration, data); } - public virtual object TrackedVisit(ObjectCreateExpression objectCreateExpression, object data) { + public virtual object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { return base.VisitObjectCreateExpression(objectCreateExpression, data); } - public virtual object TrackedVisit(OnErrorStatement onErrorStatement, object data) { + public virtual object TrackedVisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) { return base.VisitOnErrorStatement(onErrorStatement, data); } - public virtual object TrackedVisit(OperatorDeclaration operatorDeclaration, object data) { + public virtual object TrackedVisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) { return base.VisitOperatorDeclaration(operatorDeclaration, data); } - public virtual object TrackedVisit(OptionDeclaration optionDeclaration, object data) { + public virtual object TrackedVisitOptionDeclaration(OptionDeclaration optionDeclaration, object data) { return base.VisitOptionDeclaration(optionDeclaration, data); } - public virtual object TrackedVisit(ParameterDeclarationExpression parameterDeclarationExpression, object data) { + public virtual object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) { return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data); } - public virtual object TrackedVisit(ParenthesizedExpression parenthesizedExpression, object data) { + public virtual object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) { return base.VisitParenthesizedExpression(parenthesizedExpression, data); } - public virtual object TrackedVisit(PointerReferenceExpression pointerReferenceExpression, object data) { + public virtual object TrackedVisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) { return base.VisitPointerReferenceExpression(pointerReferenceExpression, data); } - public virtual object TrackedVisit(PrimitiveExpression primitiveExpression, object data) { + public virtual object TrackedVisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) { return base.VisitPrimitiveExpression(primitiveExpression, data); } - public virtual object TrackedVisit(PropertyDeclaration propertyDeclaration, object data) { + public virtual object TrackedVisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { return base.VisitPropertyDeclaration(propertyDeclaration, data); } - public virtual object TrackedVisit(PropertyGetRegion propertyGetRegion, object data) { + public virtual object TrackedVisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) { return base.VisitPropertyGetRegion(propertyGetRegion, data); } - public virtual object TrackedVisit(PropertySetRegion propertySetRegion, object data) { + public virtual object TrackedVisitPropertySetRegion(PropertySetRegion propertySetRegion, object data) { return base.VisitPropertySetRegion(propertySetRegion, data); } - public virtual object TrackedVisit(RaiseEventStatement raiseEventStatement, object data) { + public virtual object TrackedVisitQueryExpression(QueryExpression queryExpression, object data) { + return base.VisitQueryExpression(queryExpression, data); + } + + public virtual object TrackedVisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) { + return base.VisitQueryExpressionFromClause(queryExpressionFromClause, data); + } + + public virtual object TrackedVisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) { + return base.VisitQueryExpressionFromGenerator(queryExpressionFromGenerator, data); + } + + public virtual object TrackedVisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) { + return base.VisitQueryExpressionGroupClause(queryExpressionGroupClause, data); + } + + public virtual object TrackedVisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data) { + return base.VisitQueryExpressionIntoClause(queryExpressionIntoClause, data); + } + + public virtual object TrackedVisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) { + return base.VisitQueryExpressionOrdering(queryExpressionOrdering, data); + } + + public virtual object TrackedVisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) { + return base.VisitQueryExpressionSelectClause(queryExpressionSelectClause, data); + } + + public virtual object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) { + return base.VisitQueryExpressionWhereClause(queryExpressionWhereClause, data); + } + + public virtual object TrackedVisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { return base.VisitRaiseEventStatement(raiseEventStatement, data); } - public virtual object TrackedVisit(ReDimStatement reDimStatement, object data) { + public virtual object TrackedVisitReDimStatement(ReDimStatement reDimStatement, object data) { return base.VisitReDimStatement(reDimStatement, data); } - public virtual object TrackedVisit(RemoveHandlerStatement removeHandlerStatement, object data) { + public virtual object TrackedVisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data) { return base.VisitRemoveHandlerStatement(removeHandlerStatement, data); } - public virtual object TrackedVisit(ResumeStatement resumeStatement, object data) { + public virtual object TrackedVisitResumeStatement(ResumeStatement resumeStatement, object data) { return base.VisitResumeStatement(resumeStatement, data); } - public virtual object TrackedVisit(ReturnStatement returnStatement, object data) { + public virtual object TrackedVisitReturnStatement(ReturnStatement returnStatement, object data) { return base.VisitReturnStatement(returnStatement, data); } - public virtual object TrackedVisit(SizeOfExpression sizeOfExpression, object data) { + public virtual object TrackedVisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data) { return base.VisitSizeOfExpression(sizeOfExpression, data); } - public virtual object TrackedVisit(StackAllocExpression stackAllocExpression, object data) { + public virtual object TrackedVisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data) { return base.VisitStackAllocExpression(stackAllocExpression, data); } - public virtual object TrackedVisit(StopStatement stopStatement, object data) { + public virtual object TrackedVisitStopStatement(StopStatement stopStatement, object data) { return base.VisitStopStatement(stopStatement, data); } - public virtual object TrackedVisit(SwitchSection switchSection, object data) { + public virtual object TrackedVisitSwitchSection(SwitchSection switchSection, object data) { return base.VisitSwitchSection(switchSection, data); } - public virtual object TrackedVisit(SwitchStatement switchStatement, object data) { + public virtual object TrackedVisitSwitchStatement(SwitchStatement switchStatement, object data) { return base.VisitSwitchStatement(switchStatement, data); } - public virtual object TrackedVisit(TemplateDefinition templateDefinition, object data) { + public virtual object TrackedVisitTemplateDefinition(TemplateDefinition templateDefinition, object data) { return base.VisitTemplateDefinition(templateDefinition, data); } - public virtual object TrackedVisit(ThisReferenceExpression thisReferenceExpression, object data) { + public virtual object TrackedVisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) { return base.VisitThisReferenceExpression(thisReferenceExpression, data); } - public virtual object TrackedVisit(ThrowStatement throwStatement, object data) { + public virtual object TrackedVisitThrowStatement(ThrowStatement throwStatement, object data) { return base.VisitThrowStatement(throwStatement, data); } - public virtual object TrackedVisit(TryCatchStatement tryCatchStatement, object data) { + public virtual object TrackedVisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) { return base.VisitTryCatchStatement(tryCatchStatement, data); } - public virtual object TrackedVisit(TypeDeclaration typeDeclaration, object data) { + public virtual object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { return base.VisitTypeDeclaration(typeDeclaration, data); } - public virtual object TrackedVisit(TypeOfExpression typeOfExpression, object data) { + public virtual object TrackedVisitTypeOfExpression(TypeOfExpression typeOfExpression, object data) { return base.VisitTypeOfExpression(typeOfExpression, data); } - public virtual object TrackedVisit(TypeOfIsExpression typeOfIsExpression, object data) { + public virtual object TrackedVisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { return base.VisitTypeOfIsExpression(typeOfIsExpression, data); } - public virtual object TrackedVisit(TypeReference typeReference, object data) { + public virtual object TrackedVisitTypeReference(TypeReference typeReference, object data) { return base.VisitTypeReference(typeReference, data); } - public virtual object TrackedVisit(TypeReferenceExpression typeReferenceExpression, object data) { + public virtual object TrackedVisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) { return base.VisitTypeReferenceExpression(typeReferenceExpression, data); } - public virtual object TrackedVisit(UnaryOperatorExpression unaryOperatorExpression, object data) { + public virtual object TrackedVisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { return base.VisitUnaryOperatorExpression(unaryOperatorExpression, data); } - public virtual object TrackedVisit(UncheckedExpression uncheckedExpression, object data) { + public virtual object TrackedVisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data) { return base.VisitUncheckedExpression(uncheckedExpression, data); } - public virtual object TrackedVisit(UncheckedStatement uncheckedStatement, object data) { + public virtual object TrackedVisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data) { return base.VisitUncheckedStatement(uncheckedStatement, data); } - public virtual object TrackedVisit(UnsafeStatement unsafeStatement, object data) { + public virtual object TrackedVisitUnsafeStatement(UnsafeStatement unsafeStatement, object data) { return base.VisitUnsafeStatement(unsafeStatement, data); } - public virtual object TrackedVisit(Using @using, object data) { + public virtual object TrackedVisitUsing(Using @using, object data) { return base.VisitUsing(@using, data); } - public virtual object TrackedVisit(UsingDeclaration usingDeclaration, object data) { + public virtual object TrackedVisitUsingDeclaration(UsingDeclaration usingDeclaration, object data) { return base.VisitUsingDeclaration(usingDeclaration, data); } - public virtual object TrackedVisit(UsingStatement usingStatement, object data) { + public virtual object TrackedVisitUsingStatement(UsingStatement usingStatement, object data) { return base.VisitUsingStatement(usingStatement, data); } - public virtual object TrackedVisit(VariableDeclaration variableDeclaration, object data) { + public virtual object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) { return base.VisitVariableDeclaration(variableDeclaration, data); } - public virtual object TrackedVisit(WithStatement withStatement, object data) { + public virtual object TrackedVisitWithStatement(WithStatement withStatement, object data) { return base.VisitWithStatement(withStatement, data); } - public virtual object TrackedVisit(YieldStatement yieldStatement, object data) { + public virtual object TrackedVisitYieldStatement(YieldStatement yieldStatement, object data) { return base.VisitYieldStatement(yieldStatement, data); } } diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/RenameIdentifierVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/RenameIdentifierVisitor.cs new file mode 100644 index 0000000000..4ec36caa6f --- /dev/null +++ b/src/Libraries/NRefactory/Project/Src/Visitors/RenameIdentifierVisitor.cs @@ -0,0 +1,65 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Visitors +{ + class RenameIdentifierVisitor : AbstractAstVisitor + { + protected StringComparer nameComparer; + protected string from, to; + + public RenameIdentifierVisitor(string from, string to, StringComparer nameComparer) + { + this.nameComparer = nameComparer; + this.from = from; + this.to = to; + } + + public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) + { + if (nameComparer.Equals(identifierExpression.Identifier, from)) { + identifierExpression.Identifier = to; + } + return base.VisitIdentifierExpression(identifierExpression, data); + } + } + + sealed class RenameLocalVariableVisitor : RenameIdentifierVisitor + { + public RenameLocalVariableVisitor(string from, string to, StringComparer nameComparer) + : base(from, to, nameComparer) + { + } + + public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) + { + if (nameComparer.Equals(from, variableDeclaration.Name)) { + variableDeclaration.Name = to; + } + return base.VisitVariableDeclaration(variableDeclaration, data); + } + + public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) + { + if (nameComparer.Equals(from, parameterDeclarationExpression.ParameterName)) { + parameterDeclarationExpression.ParameterName = to; + } + return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data); + } + + public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) + { + if (nameComparer.Equals(from, foreachStatement.VariableName)) { + foreachStatement.VariableName = to; + } + return base.VisitForeachStatement(foreachStatement, data); + } + } +} diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs index 091752ddd2..9cc5f0960c 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs @@ -15,7 +15,7 @@ namespace ICSharpCode.NRefactory.Visitors /// Not all elements are converted here, most simple elements (e.g. StopStatement) /// are converted in the output visitor. /// - public class ToCSharpConvertVisitor : AbstractAstTransformer + public class ToCSharpConvertVisitor : ConvertVisitorBase { // The following conversions are implemented: // Public Event EventName(param As String) -> automatic delegate declaration diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs index 9d79754aad..a06a3803ab 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs @@ -17,10 +17,11 @@ namespace ICSharpCode.NRefactory.Visitors /// Not all elements are converted here, most simple elements (e.g. ConditionalExpression) /// are converted in the output visitor. /// - public class ToVBNetConvertVisitor : AbstractAstTransformer + public class ToVBNetConvertVisitor : ConvertVisitorBase { // The following conversions are implemented: // Conflicting field/property names -> m_field + // Conflicting variable names inside methods // Anonymous methods are put into new methods // Simple event handler creation is replaced with AddressOfExpression // Move Imports-statements out of namespaces @@ -218,6 +219,9 @@ namespace ICSharpCode.NRefactory.Visitors } } } + + ToVBNetRenameConflictingVariablesVisitor.RenameConflicting(methodDeclaration); + return null; } @@ -300,7 +304,11 @@ namespace ICSharpCode.NRefactory.Visitors { if (!IsClassType(ClassType.Interface) && (propertyDeclaration.Modifier & Modifiers.Visibility) == 0) propertyDeclaration.Modifier |= Modifiers.Private; - return base.VisitPropertyDeclaration(propertyDeclaration, data); + base.VisitPropertyDeclaration(propertyDeclaration, data); + + ToVBNetRenameConflictingVariablesVisitor.RenameConflicting(propertyDeclaration); + + return null; } public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) @@ -315,7 +323,11 @@ namespace ICSharpCode.NRefactory.Visitors // make constructor private if visiblity is not set (unless constructor is static) if ((constructorDeclaration.Modifier & (Modifiers.Visibility | Modifiers.Static)) == 0) constructorDeclaration.Modifier |= Modifiers.Private; - return base.VisitConstructorDeclaration(constructorDeclaration, data); + base.VisitConstructorDeclaration(constructorDeclaration, data); + + ToVBNetRenameConflictingVariablesVisitor.RenameConflicting(constructorDeclaration); + + return null; } public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetRenameConflictingVariables.cs b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetRenameConflictingVariables.cs new file mode 100644 index 0000000000..75575aedfe --- /dev/null +++ b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetRenameConflictingVariables.cs @@ -0,0 +1,91 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Visitors +{ + /// + /// Renames local variables if they conflict with other locals, fields or parameters. + /// + static class ToVBNetRenameConflictingVariablesVisitor + { + public static void RenameConflicting(ParametrizedNode method) + { + // variable name => case sensitive variable name + // value is null if there are multiple casings for the variable -> the variable is conflicting + Dictionary caseInsensitive = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + + LookupTableVisitor ltv = new LookupTableVisitor(StringComparer.InvariantCulture); + method.AcceptVisitor(ltv, null); + + // add method parameters to caseInsensitive + foreach (ParameterDeclarationExpression pde in method.Parameters) { + AddVariableToDict(caseInsensitive, pde.ParameterName, true); + } + + // add local variables to caseInsensitive + foreach (KeyValuePair> var in ltv.Variables) { + AddVariableToDict(caseInsensitive, var.Key, true); + } + + // add used identifiers to caseInsensitive + FindIdentifiersVisitor fvv = new FindIdentifiersVisitor(); + method.AcceptVisitor(fvv, null); + + foreach (KeyValuePair pair in fvv.usedIdentifiers) { + AddVariableToDict(caseInsensitive, pair.Key, false); + } + + int index = 0; + foreach (ParameterDeclarationExpression pde in method.Parameters) { + if (caseInsensitive[pde.ParameterName] == null) { + RenameVariable(method, pde.ParameterName, ref index); + } + } + foreach (KeyValuePair> var in ltv.Variables) { + if (caseInsensitive[var.Key] == null) { + RenameVariable(method, var.Key, ref index); + } + } + } + + static void RenameVariable(INode method, string from, ref int index) + { + index += 1; + method.AcceptVisitor(new RenameLocalVariableVisitor(from, from + "__" + index, StringComparer.InvariantCulture), null); + } + + static void AddVariableToDict(Dictionary caseInsensitive, string varName, bool hasDeclaration) + { + string existing; + if (caseInsensitive.TryGetValue(varName, out existing)) { + if (existing != null && existing != varName) { + caseInsensitive[varName] = null; + } + } else { + if (hasDeclaration) { + caseInsensitive.Add(varName, varName); + } + } + } + + sealed class FindIdentifiersVisitor : AbstractAstVisitor + { + // use dictionary as HashSet to remember used identifiers + internal readonly Dictionary usedIdentifiers = new Dictionary(); + + public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) + { + usedIdentifiers[identifierExpression.Identifier] = null; + return null; + } + } + } +} diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs index 330e371fd8..34127c0d8f 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.Visitors /// /// Converts special VB constructs to use more general AST classes. /// - public class VBNetConstructsConvertVisitor : AbstractAstTransformer + public class VBNetConstructsConvertVisitor : ConvertVisitorBase { // The following conversions are implemented: // MyBase.New() and MyClass.New() calls inside the constructor are converted to :base() and :this() @@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Visitors // IIF(cond, true, false) => ConditionalExpression // Built-in methods => Prefix with class name // Function A() \n A = SomeValue \n End Function -> convert to return statement + // Comparison with empty string literal -> Dictionary usings; List addedUsings; @@ -326,31 +327,12 @@ namespace ICSharpCode.NRefactory.Visitors from = p.ParameterName; p.ParameterName = "Value"; } - propertyDeclaration.SetRegion.AcceptVisitor(new RenameIdentifierVisitor(from, "value"), null); + propertyDeclaration.SetRegion.AcceptVisitor(new RenameIdentifierVisitor(from, "value", StringComparer.InvariantCultureIgnoreCase), null); } return base.VisitPropertyDeclaration(propertyDeclaration, data); } - class RenameIdentifierVisitor : AbstractAstVisitor - { - string from, to; - - public RenameIdentifierVisitor(string from, string to) - { - this.from = from; - this.to = to; - } - - public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) - { - if (string.Equals(identifierExpression.Identifier, from, StringComparison.InvariantCultureIgnoreCase)) { - identifierExpression.Identifier = to; - } - return base.VisitIdentifierExpression(identifierExpression, data); - } - } - static volatile Dictionary constantTable; static volatile Dictionary methodTable; @@ -456,5 +438,45 @@ namespace ICSharpCode.NRefactory.Visitors } return base.VisitUsingStatement(usingStatement, data); } + + bool IsEmptyStringLiteral(Expression expression) + { + PrimitiveExpression pe = expression as PrimitiveExpression; + if (pe != null) { + return (pe.Value as string) == ""; + } else { + return false; + } + } + + Expression CallStringIsNullOrEmpty(Expression stringVariable) + { + List arguments = new List(); + arguments.Add(stringVariable); + return new InvocationExpression( + new FieldReferenceExpression(new TypeReferenceExpression("System.String"), "IsNullOrEmpty"), + arguments); + } + + public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) + { + base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); + if (IsEmptyStringLiteral(binaryOperatorExpression.Right)) { + if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) { + ReplaceCurrentNode(CallStringIsNullOrEmpty(binaryOperatorExpression.Left)); + } else if (binaryOperatorExpression.Op == BinaryOperatorType.InEquality) { + ReplaceCurrentNode(new UnaryOperatorExpression(CallStringIsNullOrEmpty(binaryOperatorExpression.Left), + UnaryOperatorType.Not)); + } + } else if (IsEmptyStringLiteral(binaryOperatorExpression.Left)) { + if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) { + ReplaceCurrentNode(CallStringIsNullOrEmpty(binaryOperatorExpression.Right)); + } else if (binaryOperatorExpression.Op == BinaryOperatorType.InEquality) { + ReplaceCurrentNode(new UnaryOperatorExpression(CallStringIsNullOrEmpty(binaryOperatorExpression.Right), + UnaryOperatorType.Not)); + } + } + return null; + } } } diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/VBNetToCSharpConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/VBNetToCSharpConvertVisitor.cs index 8a24170fdf..fabc0f59f1 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/VBNetToCSharpConvertVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/VBNetToCSharpConvertVisitor.cs @@ -20,7 +20,8 @@ namespace ICSharpCode.NRefactory.Visitors public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { base.VisitCompilationUnit(compilationUnit, data); - compilationUnit.AcceptVisitor(new ToCSharpConvertVisitor(), data); + ToCSharpConvertVisitor v = new ToCSharpConvertVisitor(); + compilationUnit.AcceptVisitor(v, data); return null; } } diff --git a/src/Libraries/NRefactory/Test/Lexer/CSharp/CustomLexerTests.cs b/src/Libraries/NRefactory/Test/Lexer/CSharp/CustomLexerTests.cs index 386a45dc83..5c7eb79cab 100644 --- a/src/Libraries/NRefactory/Test/Lexer/CSharp/CustomLexerTests.cs +++ b/src/Libraries/NRefactory/Test/Lexer/CSharp/CustomLexerTests.cs @@ -41,6 +41,16 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp Assert.AreEqual("a_Bc05", t.val); } + [Test] + public void TestYieldAsIdentifier() + { + ILexer lexer = GenerateLexer(new StringReader("yield")); + Token t = lexer.NextToken(); + Assert.AreEqual(Tokens.Yield, t.kind); + Assert.IsTrue(Tokens.IdentifierTokens[t.kind]); + Assert.AreEqual("yield", t.val); + } + [Test] public void TestSkippedEmptyBlock() { diff --git a/src/Libraries/NRefactory/Test/Lexer/CSharp/LexerTests.cs b/src/Libraries/NRefactory/Test/Lexer/CSharp/LexerTests.cs index 2eeb6d6b9a..c88e1411fc 100644 --- a/src/Libraries/NRefactory/Test/Lexer/CSharp/LexerTests.cs +++ b/src/Libraries/NRefactory/Test/Lexer/CSharp/LexerTests.cs @@ -330,6 +330,20 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp Assert.AreEqual(Tokens.ShiftLeftAssign, lexer.NextToken().kind); } + [Test] + public void TestPointer() + { + ILexer lexer = GenerateLexer(new StringReader("->")); + Assert.AreEqual(Tokens.Pointer, lexer.NextToken().kind); + } + + [Test] + public void TestLambdaArrow() + { + ILexer lexer = GenerateLexer(new StringReader("=>")); + Assert.AreEqual(Tokens.LambdaArrow, lexer.NextToken().kind); + } + [Test()] public void TestAbstract() { @@ -792,5 +806,95 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp ILexer lexer = GenerateLexer(new StringReader("while")); Assert.AreEqual(Tokens.While, lexer.NextToken().kind); } + [Test()] + public void TestPartial() + { + ILexer lexer = GenerateLexer(new StringReader("partial")); + Assert.AreEqual(Tokens.Partial, lexer.NextToken().kind); + } + [Test()] + public void TestWhere() + { + ILexer lexer = GenerateLexer(new StringReader("where")); + Assert.AreEqual(Tokens.Where, lexer.NextToken().kind); + } + [Test()] + public void TestGet() + { + ILexer lexer = GenerateLexer(new StringReader("get")); + Assert.AreEqual(Tokens.Get, lexer.NextToken().kind); + } + [Test()] + public void TestSet() + { + ILexer lexer = GenerateLexer(new StringReader("set")); + Assert.AreEqual(Tokens.Set, lexer.NextToken().kind); + } + [Test()] + public void TestAdd() + { + ILexer lexer = GenerateLexer(new StringReader("add")); + Assert.AreEqual(Tokens.Add, lexer.NextToken().kind); + } + [Test()] + public void TestRemove() + { + ILexer lexer = GenerateLexer(new StringReader("remove")); + Assert.AreEqual(Tokens.Remove, lexer.NextToken().kind); + } + [Test()] + public void TestYield() + { + ILexer lexer = GenerateLexer(new StringReader("yield")); + Assert.AreEqual(Tokens.Yield, lexer.NextToken().kind); + } + [Test()] + public void TestSelect() + { + ILexer lexer = GenerateLexer(new StringReader("select")); + Assert.AreEqual(Tokens.Select, lexer.NextToken().kind); + } + [Test()] + public void TestGroup() + { + ILexer lexer = GenerateLexer(new StringReader("group")); + Assert.AreEqual(Tokens.Group, lexer.NextToken().kind); + } + [Test()] + public void TestBy() + { + ILexer lexer = GenerateLexer(new StringReader("by")); + Assert.AreEqual(Tokens.By, lexer.NextToken().kind); + } + [Test()] + public void TestInto() + { + ILexer lexer = GenerateLexer(new StringReader("into")); + Assert.AreEqual(Tokens.Into, lexer.NextToken().kind); + } + [Test()] + public void TestFrom() + { + ILexer lexer = GenerateLexer(new StringReader("from")); + Assert.AreEqual(Tokens.From, lexer.NextToken().kind); + } + [Test()] + public void TestAscending() + { + ILexer lexer = GenerateLexer(new StringReader("ascending")); + Assert.AreEqual(Tokens.Ascending, lexer.NextToken().kind); + } + [Test()] + public void TestDescending() + { + ILexer lexer = GenerateLexer(new StringReader("descending")); + Assert.AreEqual(Tokens.Descending, lexer.NextToken().kind); + } + [Test()] + public void TestOrderby() + { + ILexer lexer = GenerateLexer(new StringReader("orderby")); + Assert.AreEqual(Tokens.Orderby, lexer.NextToken().kind); + } } } diff --git a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj index 369d7fe5c0..43b953d96a 100644 --- a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj +++ b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj @@ -46,6 +46,8 @@ + + diff --git a/src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs b/src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs index 6209f0e45a..40537a9440 100644 --- a/src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs +++ b/src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs @@ -48,6 +48,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(expression + ";")); Expression e = parser.ParseExpression(); Assert.AreEqual("", parser.Errors.ErrorOutput); + Assert.IsNotNull(e, "ParseExpression returned null"); CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor(); e.AcceptVisitor(outputVisitor, null); Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); @@ -126,7 +127,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter [Test] public void ArrayInitializer() { - TestStatement("object[] a = new object[] {1, 2, 3};"); + TestStatement("object[] a = new object[] { 1, 2, 3 };"); } [Test] @@ -414,6 +415,12 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter TestProgram("public struct Rational where O : class\n{\n}"); } + [Test] + public void ExtensionMethod() + { + TestTypeMember("public static T[] Slice(this T[] source, int index, int count)\n{ }"); + } + [Test] public void FixedStructField() { @@ -431,5 +438,113 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter fixed byte data[4 * sizeof(int)], data2[10]; }"); } + + [Test] + public void ImplicitlyTypedLambda() + { + TestExpression("x => x + 1"); + } + + [Test] + public void ImplicitlyTypedLambdaWithBody() + { + TestExpression("x => { return x + 1; }"); + TestStatement("Func f = x => { return x + 1; };"); + } + + [Test] + public void ExplicitlyTypedLambda() + { + TestExpression("(int x) => x + 1"); + } + + [Test] + public void ExplicitlyTypedLambdaWithBody() + { + TestExpression("(int x) => { return x + 1; }"); + } + + [Test] + public void LambdaMultipleParameters() + { + TestExpression("(x, y) => x * y"); + TestExpression("(x, y) => { return x * y; }"); + TestExpression("(int x, int y) => x * y"); + TestExpression("(int x, int y) => { return x * y; }"); + } + + [Test] + public void LambdaNoParameters() + { + TestExpression("() => Console.WriteLine()"); + TestExpression("() => { Console.WriteLine(); }"); + } + + [Test] + public void ObjectInitializer() + { + TestExpression("new Point { X = 0, Y = 1 }"); + TestExpression("new Rectangle { P1 = new Point { X = 0, Y = 1 }, P2 = new Point { X = 2, Y = 3 } }"); + TestExpression("new Rectangle(arguments) { P1 = { X = 0, Y = 1 }, P2 = { X = 2, Y = 3 } }"); + } + + [Test] + public void CollectionInitializer() + { + TestExpression("new List { 0, 1, 2, 3, 4, 5 }"); + TestExpression(@"new List { new Contact { Name = ""Chris Smith"", PhoneNumbers = { ""206-555-0101"", ""425-882-8080"" } }, new Contact { Name = ""Bob Harris"", PhoneNumbers = { ""650-555-0199"" } } }"); + } + + [Test] + public void AnonymousTypeCreation() + { + TestExpression("new { obj.Name, Price = 26.9, ident }"); + } + + [Test] + public void ImplicitlyTypedArrayCreation() + { + TestExpression("new[] { 1, 10, 100, 1000 }"); + } + + [Test] + public void QuerySimpleWhere() + { + TestExpression("from n in numbers where n < 5 select n"); + } + + [Test] + public void QueryMultipleFrom() + { + TestExpression("from c in customers" + + " where c.Region == \"WA\"" + + " from o in c.Orders" + + " where o.OrderDate >= cutoffDate" + + " select new { c.CustomerID, o.OrderID }"); + } + + [Test] + public void QuerySimpleOrdering() + { + TestExpression("from w in words" + + " orderby w" + + " select w"); + } + + [Test] + public void QueryComplexOrdering() + { + TestExpression("from w in words" + + " orderby w.Length descending, w ascending" + + " select w"); + } + + [Test] + public void QueryGroupInto() + { + TestExpression("from n in numbers" + + " group n by n % 5 into g" + + " select new { Remainder = g.Key, Numbers = g }"); + } } } diff --git a/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs b/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs index c2ed261514..ecff316f54 100644 --- a/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs +++ b/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs @@ -598,5 +598,15 @@ static int static_Test2_j = 0;"); { TestStatement("CType(obj, IDisposable).Dispose()", "((IDisposable)obj).Dispose();"); } + + [Test] + public void ComparisonWithEmptyStringLiteral() + { + TestStatement("If a = \"\" Then Return", "if (string.IsNullOrEmpty(a)) return; "); + TestStatement("If a <> \"\" Then Return", "if (!string.IsNullOrEmpty(a)) return; "); + + TestStatement("If \"\" = a Then Return", "if (string.IsNullOrEmpty(a)) return; "); + TestStatement("If \"\" <> a Then Return", "if (!string.IsNullOrEmpty(a)) return; "); + } } } diff --git a/src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs b/src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs index c856415033..ecf7a31091 100644 --- a/src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs +++ b/src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs @@ -24,7 +24,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); - parser.CompilationUnit.AcceptVisitor(new CSharpToVBNetConvertVisitor(), null); + parser.CompilationUnit.AcceptVisitor(new CSharpConstructsVisitor(), null); + parser.CompilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), null); VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); @@ -224,7 +225,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter "\tReturn argument * 2\n" + "End Function"); } - */ + */ [Test] public void RegisterEvent() @@ -449,5 +450,15 @@ End Class { TestStatement("a = (int)number;", "a = CInt(number)"); } + + [Test] + public void CaseConflictingMethod() + { + TestMember("void T(int v) { int V = v; M(V, v); }", + "Private Sub T(ByVal v__1 As Integer)\n" + + "\tDim V__2 As Integer = v__1\n" + + "\tM(V__2, v__1)\n" + + "End Sub"); + } } } diff --git a/src/Libraries/NRefactory/Test/Parser/Expressions/ArrayCreateExpressionTests.cs b/src/Libraries/NRefactory/Test/Parser/Expressions/ArrayCreateExpressionTests.cs index 82b5c11c5e..dc7fc78087 100644 --- a/src/Libraries/NRefactory/Test/Parser/Expressions/ArrayCreateExpressionTests.cs +++ b/src/Libraries/NRefactory/Test/Parser/Expressions/ArrayCreateExpressionTests.cs @@ -25,6 +25,15 @@ namespace ICSharpCode.NRefactory.Tests.Ast Assert.AreEqual(1, ace.Arguments.Count); Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier); } + + [Test] + public void CSharpImplicitlyTypedArrayCreateExpression() + { + ArrayCreateExpression ace = ParseUtilCSharp.ParseExpression("new[] { 1, 10, 100, 1000 }"); + Assert.AreEqual("", ace.CreateType.Type); + Assert.AreEqual(0, ace.Arguments.Count); + Assert.AreEqual(4, ace.ArrayInitializer.CreateExpressions.Count); + } #endregion #region VB.NET diff --git a/src/Libraries/NRefactory/Test/Parser/Expressions/LambdaExpressionTests.cs b/src/Libraries/NRefactory/Test/Parser/Expressions/LambdaExpressionTests.cs new file mode 100644 index 0000000000..1e012e7bd6 --- /dev/null +++ b/src/Libraries/NRefactory/Test/Parser/Expressions/LambdaExpressionTests.cs @@ -0,0 +1,69 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using NUnit.Framework; +using ICSharpCode.NRefactory.Parser; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Tests.Ast +{ + [TestFixture] + public class LambdaExpressionTests + { + static LambdaExpression Parse(string program) + { + return ParseUtilCSharp.ParseExpression(program); + } + + [Test] + public void ImplicitlyTypedExpressionBody() + { + LambdaExpression e = Parse("(x) => x + 1"); + Assert.AreEqual("x", e.Parameters[0].ParameterName); + Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); + Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); + } + + [Test] + public void ImplicitlyTypedExpressionBodyWithoutParenthesis() + { + LambdaExpression e = Parse("x => x + 1"); + Assert.AreEqual("x", e.Parameters[0].ParameterName); + Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); + Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); + } + + [Test] + public void ImplicitlyTypedStatementBody() + { + LambdaExpression e = Parse("(x) => { return x + 1; }"); + Assert.AreEqual("x", e.Parameters[0].ParameterName); + Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); + Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); + } + + [Test] + public void ImplicitlyTypedStatementBodyWithoutParenthesis() + { + LambdaExpression e = Parse("x => { return x + 1; }"); + Assert.AreEqual("x", e.Parameters[0].ParameterName); + Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); + Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); + } + + [Test] + public void ExplicitlyTypedStatementBody() + { + LambdaExpression e = Parse("(int x) => { return x + 1; }"); + Assert.AreEqual("x", e.Parameters[0].ParameterName); + Assert.AreEqual("int", e.Parameters[0].TypeReference.Type); + Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); + } + } +} diff --git a/src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs b/src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs index ba7354048e..9988053544 100644 --- a/src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs +++ b/src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs @@ -20,6 +20,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast { Assert.AreEqual("MyObject", oce.CreateType.Type); Assert.AreEqual(3, oce.Parameters.Count); + Assert.IsTrue(oce.ObjectInitializer.IsNull); for (int i = 0; i < oce.Parameters.Count; ++i) { Assert.IsTrue(oce.Parameters[i] is PrimitiveExpression); @@ -64,6 +65,121 @@ namespace ICSharpCode.NRefactory.Tests.Ast Assert.AreEqual(1, typeRef.GenericTypes.Count); Assert.AreEqual("int", typeRef.GenericTypes[0].Type); } + + Expression CheckPropertyInitializationExpression(Expression e, string name) + { + Assert.IsInstanceOfType(typeof(AssignmentExpression), e); + Expression left = ((AssignmentExpression)e).Left; + Assert.IsInstanceOfType(typeof(IdentifierExpression), left); + Assert.AreEqual(name, ((IdentifierExpression)left).Identifier); + return ((AssignmentExpression)e).Right; + } + + void CheckPointObjectCreation(ObjectCreateExpression oce) + { + Assert.AreEqual(0, oce.Parameters.Count); + Assert.AreEqual(2, oce.ObjectInitializer.CreateExpressions.Count); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "X")); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[1], "Y")); + } + + [Test] + public void CSharpObjectInitializer() + { + CheckPointObjectCreation(ParseUtilCSharp.ParseExpression("new Point() { X = 0, Y = 1 }")); + } + + [Test] + public void CSharpObjectInitializerWithoutParenthesis() + { + CheckPointObjectCreation(ParseUtilCSharp.ParseExpression("new Point { X = 0, Y = 1 }")); + } + + [Test] + public void CSharpObjectInitializerTrailingComma() + { + CheckPointObjectCreation(ParseUtilCSharp.ParseExpression("new Point() { X = 0, Y = 1, }")); + } + + [Test] + public void CSharpNestedObjectInitializer() + { + ObjectCreateExpression oce = ParseUtilCSharp.ParseExpression( + "new Rectangle { P1 = new Point { X = 0, Y = 1 }, P2 = new Point { X = 2, Y = 3 } }" + ); + Assert.AreEqual(0, oce.Parameters.Count); + Assert.AreEqual(2, oce.ObjectInitializer.CreateExpressions.Count); + CheckPointObjectCreation((ObjectCreateExpression)CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "P1")); + CheckPointObjectCreation((ObjectCreateExpression)CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[1], "P2")); + } + + [Test] + public void CSharpNestedObjectInitializerForPreinitializedProperty() + { + ObjectCreateExpression oce = ParseUtilCSharp.ParseExpression( + "new Rectangle { P1 = { X = 0, Y = 1 }, P2 = { X = 2, Y = 3 } }" + ); + Assert.AreEqual(0, oce.Parameters.Count); + Assert.AreEqual(2, oce.ObjectInitializer.CreateExpressions.Count); + CollectionInitializerExpression aie = (CollectionInitializerExpression)CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "P1"); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(aie.CreateExpressions[0], "X")); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(aie.CreateExpressions[1], "Y")); + aie = (CollectionInitializerExpression)CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[1], "P2"); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(aie.CreateExpressions[0], "X")); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(aie.CreateExpressions[1], "Y")); + } + + [Test] + public void CSharpCollectionInitializer() + { + ObjectCreateExpression oce = ParseUtilCSharp.ParseExpression( + "new List { 0, 1, 2 }" + ); + Assert.AreEqual(0, oce.Parameters.Count); + Assert.AreEqual(3, oce.ObjectInitializer.CreateExpressions.Count); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), oce.ObjectInitializer.CreateExpressions[0]); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), oce.ObjectInitializer.CreateExpressions[1]); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), oce.ObjectInitializer.CreateExpressions[2]); + } + + [Test] + public void CSharpComplexCollectionInitializer() + { + ObjectCreateExpression oce = ParseUtilCSharp.ParseExpression( + @"new List { + new Contact { + Name = ""Chris"", + PhoneNumbers = { ""206-555-0101"" } + }, + new Contact(additionalParameter) { + Name = ""Bob"", + PhoneNumbers = { ""650-555-0199"", ""425-882-8080"" } + } +}" ); + Assert.AreEqual(0, oce.Parameters.Count); + Assert.AreEqual(2, oce.ObjectInitializer.CreateExpressions.Count); + + oce = (ObjectCreateExpression)oce.ObjectInitializer.CreateExpressions[1]; // look at Bob + Assert.AreEqual(1, oce.Parameters.Count); + Assert.IsInstanceOfType(typeof(IdentifierExpression), oce.Parameters[0]); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "Name")); + CollectionInitializerExpression phoneNumbers = (CollectionInitializerExpression)CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[1], "PhoneNumbers"); + Assert.AreEqual(2, phoneNumbers.CreateExpressions.Count); + } + + [Test] + public void CSharpAnonymousType() + { + ObjectCreateExpression oce = ParseUtilCSharp.ParseExpression( + "new { Name = \"Test\", Price, Something.Property }" + ); + Assert.IsTrue(oce.CreateType.IsNull); + Assert.AreEqual(0, oce.Parameters.Count); + Assert.AreEqual(3, oce.ObjectInitializer.CreateExpressions.Count); + Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "Name")); + Assert.IsInstanceOfType(typeof(IdentifierExpression), oce.ObjectInitializer.CreateExpressions[1]); + Assert.IsInstanceOfType(typeof(FieldReferenceExpression), oce.ObjectInitializer.CreateExpressions[2]); + } #endregion #region VB.NET diff --git a/src/Libraries/NRefactory/Test/Parser/Expressions/QueryExpressionTests.cs b/src/Libraries/NRefactory/Test/Parser/Expressions/QueryExpressionTests.cs new file mode 100644 index 0000000000..d75d88d36d --- /dev/null +++ b/src/Libraries/NRefactory/Test/Parser/Expressions/QueryExpressionTests.cs @@ -0,0 +1,53 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using NUnit.Framework; +using ICSharpCode.NRefactory.Parser; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Tests.Ast +{ + [TestFixture] + public class QueryExpressionTests + { + [Test] + public void SimpleExpression() + { + QueryExpression qe = ParseUtilCSharp.ParseExpression( + "from c in customers where c.City == \"London\" select c" + ); + Assert.AreEqual(1, qe.FromClause.Generators.Count); + Assert.AreEqual("c", qe.FromClause.Generators[0].Identifier); + Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Generators[0].InExpression).Identifier); + Assert.AreEqual(1, qe.FromOrWhereClauses.Count); + Assert.IsInstanceOfType(typeof(QueryExpressionWhereClause), qe.FromOrWhereClauses[0]); + QueryExpressionWhereClause wc = (QueryExpressionWhereClause)qe.FromOrWhereClauses[0]; + Assert.IsInstanceOfType(typeof(BinaryOperatorExpression), wc.Condition); + Assert.IsInstanceOfType(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); + } + + [Test] + public void MultipleGenerators() + { + QueryExpression qe = ParseUtilCSharp.ParseExpression(@" +from c in customers +where c.City == ""London"" +from o in c.Orders +where o.OrderDate.Year == 2005 +select new { c.Name, o.OrderID, o.Total }"); + Assert.AreEqual(1, qe.FromClause.Generators.Count); + Assert.AreEqual(3, qe.FromOrWhereClauses.Count); + Assert.IsInstanceOfType(typeof(QueryExpressionWhereClause), qe.FromOrWhereClauses[0]); + Assert.IsInstanceOfType(typeof(QueryExpressionFromClause), qe.FromOrWhereClauses[1]); + Assert.IsInstanceOfType(typeof(QueryExpressionWhereClause), qe.FromOrWhereClauses[2]); + + Assert.IsInstanceOfType(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); + } + } +} diff --git a/src/Libraries/NRefactory/Test/Parser/GlobalScope/DelegateDeclarationTests.cs b/src/Libraries/NRefactory/Test/Parser/GlobalScope/DelegateDeclarationTests.cs index 0b01151921..7cd1ca1bbf 100644 --- a/src/Libraries/NRefactory/Test/Parser/GlobalScope/DelegateDeclarationTests.cs +++ b/src/Libraries/NRefactory/Test/Parser/GlobalScope/DelegateDeclarationTests.cs @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast string program = "public delegate void(int a, int secondParam, MyObj lastParam);\n"; DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal(program, true); Assert.AreEqual("System.Void", dd.ReturnType.SystemType); - Assert.AreEqual("?", dd.Name); + //Assert.AreEqual("?", dd.Name); TestParameters(dd); } diff --git a/src/Libraries/NRefactory/Test/Parser/TypeLevel/FieldDeclarationTests.cs b/src/Libraries/NRefactory/Test/Parser/TypeLevel/FieldDeclarationTests.cs index 0b2737b72d..2c6a31ed09 100644 --- a/src/Libraries/NRefactory/Test/Parser/TypeLevel/FieldDeclarationTests.cs +++ b/src/Libraries/NRefactory/Test/Parser/TypeLevel/FieldDeclarationTests.cs @@ -47,7 +47,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast Assert.AreEqual(2, fd.Fields.Count); Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type); + Assert.IsFalse(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType); Assert.AreEqual("String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type); + Assert.IsFalse(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType); } [Test] diff --git a/src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs b/src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs index 623838b5c4..c9d88018e7 100644 --- a/src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs +++ b/src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs @@ -21,6 +21,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast MethodDeclaration md = ParseUtilCSharp.ParseTypeMember("void MyMethod() {} "); Assert.AreEqual("void", md.TypeReference.Type); Assert.AreEqual(0, md.Parameters.Count); + Assert.IsFalse(md.IsExtensionMethod); } [Test] @@ -62,7 +63,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast MethodDeclaration md = ParseUtilCSharp.ParseTypeMember("void MyMethod(int) {} ", true); Assert.AreEqual("void", md.TypeReference.Type); Assert.AreEqual(1, md.Parameters.Count); - Assert.AreEqual("?", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName); + //Assert.AreEqual("?", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName); } [Test] @@ -196,6 +197,30 @@ namespace ICSharpCode.NRefactory.Tests.Ast Assert.AreEqual("T", md.Templates[0].Name); Assert.AreEqual(0, md.Templates[0].Bases.Count); } + + [Test] + public void CSharpExtensionMethodTest() + { + MethodDeclaration md = ParseUtilCSharp.ParseTypeMember( + "public static int ToInt32(this string s) { return int.Parse(s); }" + ); + Assert.AreEqual("ToInt32", md.Name); + Assert.IsTrue(md.IsExtensionMethod); + Assert.AreEqual("s", md.Parameters[0].ParameterName); + Assert.AreEqual("string", md.Parameters[0].TypeReference.Type); + } + + [Test] + public void CSharpVoidExtensionMethodTest() + { + MethodDeclaration md = ParseUtilCSharp.ParseTypeMember( + "public static void Print(this string s) { Console.WriteLine(s); }" + ); + Assert.AreEqual("Print", md.Name); + Assert.IsTrue(md.IsExtensionMethod); + Assert.AreEqual("s", md.Parameters[0].ParameterName); + Assert.AreEqual("string", md.Parameters[0].TypeReference.Type); + } #endregion #region VB.NET diff --git a/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs b/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs index f9f8f8a15c..26c78ae619 100644 --- a/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs +++ b/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs @@ -14,6 +14,7 @@ using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.PrettyPrinter; using ICSharpCode.NRefactory.Visitors; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; namespace ICSharpCode.SharpDevelop.Commands { @@ -36,7 +37,9 @@ namespace ICSharpCode.SharpDevelop.Commands List specials = p.Lexer.SpecialTracker.CurrentSpecials; PreprocessingDirective.CSharpToVB(specials); - new CSharpToVBNetConvertVisitor().VisitCompilationUnit(p.CompilationUnit, null); + IAstVisitor v = new CSharpToVBNetConvertVisitor(ParserService.CurrentProjectContent, + window.ViewContent.FileName); + v.VisitCompilationUnit(p.CompilationUnit, null); using (SpecialNodesInserter.Install(specials, vbv)) { vbv.VisitCompilationUnit(p.CompilationUnit, null); } diff --git a/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs b/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs index 7784e4bb2c..babf1c4ab7 100644 --- a/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs +++ b/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs @@ -190,7 +190,8 @@ namespace ICSharpCode.SharpDevelop.Project.Converter public abstract class NRefactoryLanguageConverter : LanguageConverter { - protected abstract void ConvertAst(CompilationUnit compilationUnit, List specials); + protected abstract void ConvertAst(CompilationUnit compilationUnit, List specials, + FileProjectItem sourceItem); protected void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem, string sourceExtension, string targetExtension, @@ -214,7 +215,7 @@ namespace ICSharpCode.SharpDevelop.Project.Converter List specials = p.Lexer.SpecialTracker.CurrentSpecials; - ConvertAst(p.CompilationUnit, specials); + ConvertAst(p.CompilationUnit, specials, sourceItem); using (SpecialNodesInserter.Install(specials, outputVisitor)) { outputVisitor.VisitCompilationUnit(p.CompilationUnit, null); diff --git a/src/Main/Base/Project/Src/Services/AmbienceService/NetAmbience.cs b/src/Main/Base/Project/Src/Services/AmbienceService/NetAmbience.cs index 16a406e0c5..d4b05bfa5b 100644 --- a/src/Main/Base/Project/Src/Services/AmbienceService/NetAmbience.cs +++ b/src/Main/Base/Project/Src/Services/AmbienceService/NetAmbience.cs @@ -132,8 +132,8 @@ namespace ICSharpCode.SharpDevelop if (ShowModifiers) { if (property.IsIndexer) builder.Append("Indexer "); - else - builder.Append("Property "); + else + builder.Append("Property "); } if (UseFullyQualifiedNames) { @@ -184,6 +184,9 @@ namespace ICSharpCode.SharpDevelop { StringBuilder builder = new StringBuilder(); if (ShowModifiers) { + if (m.IsExtensionMethod) { + builder.Append("[Extension] "); + } builder.Append("Method "); } diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/InsightWindow/MethodInsightDataProvider.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/InsightWindow/MethodInsightDataProvider.cs index 7387f5878d..3fad50613f 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/InsightWindow/MethodInsightDataProvider.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/InsightWindow/MethodInsightDataProvider.cs @@ -172,7 +172,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor ResolveResult.AddExtensions(language, list, result.CallingClass, result.ContainingType); foreach (IMethodOrProperty mp in list) { if (language.NameComparer.Equals(mp.Name, result.Name) && mp is IMethod) { - IMethod m = (IMethod)mp.Clone(); + DefaultMethod m = (DefaultMethod)mp.Clone(); + // for the insight window, remove first parameter and mark the + // method as normal - this is required to show the list of + // parameters the method expects. + m.IsExtensionMethod = false; m.Parameters.RemoveAt(0); methods.Add(m); } diff --git a/src/Main/Base/Test/CodeConverterTests.cs b/src/Main/Base/Test/CodeConverterTests.cs new file mode 100644 index 0000000000..73f1207bb6 --- /dev/null +++ b/src/Main/Base/Test/CodeConverterTests.cs @@ -0,0 +1,198 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; +using System.Diagnostics; +using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.PrettyPrinter; +using ICSharpCode.NRefactory.Visitors; +using NUnit.Framework; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; + +namespace ICSharpCode.SharpDevelop.Tests +{ + /// + /// Tests advanced code-conversion features that rely on the type system. + /// + [TestFixture] + public class CodeConverterTests + { + #region TestProgram (converting code) + ProjectContentRegistry projectContentRegistry = ParserService.DefaultProjectContentRegistry; + + void TestProgramCS2VB(string sourceCode, string expectedOutput) + { + TestProgram(SupportedLanguage.CSharp, sourceCode, expectedOutput); + } + + void TestProgramVB2CS(string sourceCode, string expectedOutput) + { + TestProgram(SupportedLanguage.CSharp, sourceCode, expectedOutput); + } + + void TestProgram(SupportedLanguage sourceLanguage, string sourceCode, string expectedOutput) + { + DefaultProjectContent pc = new DefaultProjectContent(); + pc.ReferencedContents.Add(projectContentRegistry.Mscorlib); + if (sourceLanguage == SupportedLanguage.VBNet) { + pc.DefaultImports = new DefaultUsing(pc); + pc.DefaultImports.Usings.Add("System"); + pc.DefaultImports.Usings.Add("Microsoft.VisualBasic"); + } + pc.Language = sourceLanguage == SupportedLanguage.CSharp ? LanguageProperties.CSharp : LanguageProperties.VBNet; + HostCallback.GetCurrentProjectContent = delegate { + return pc; + }; + + ICSharpCode.NRefactory.IParser parser = ParserFactory.CreateParser(sourceLanguage, new StringReader(sourceCode)); + parser.Parse(); + Assert.AreEqual("", parser.Errors.ErrorOutput); + + NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(pc); + visitor.VisitCompilationUnit(parser.CompilationUnit, null); + visitor.Cu.FileName = sourceLanguage == SupportedLanguage.CSharp ? "a.cs" : "a.vb"; + foreach (IClass c in visitor.Cu.Classes) { + pc.AddClassToNamespaceList(c); + } + + HostCallback.GetParseInformation = delegate(string fileName) { + ParseInformation pi = new ParseInformation(); + pi.ValidCompilationUnit = visitor.Cu; + return pi; + }; + + if (sourceLanguage == SupportedLanguage.CSharp) { + CSharpToVBNetConvertVisitor convertVisitor = new CSharpToVBNetConvertVisitor(pc, visitor.Cu.FileName); + parser.CompilationUnit.AcceptVisitor(convertVisitor, null); + } else { + VBNetToCSharpConvertVisitor convertVisitor = new VBNetToCSharpConvertVisitor(); + parser.CompilationUnit.AcceptVisitor(convertVisitor, null); + } + + IOutputAstVisitor outputVisitor = sourceLanguage == SupportedLanguage.CSharp ? (IOutputAstVisitor)new VBNetOutputVisitor() : new CSharpOutputVisitor(); + outputVisitor.Options.IndentationChar = ' '; + outputVisitor.Options.IndentSize = 2; + using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), + outputVisitor)) { + outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); + } + Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); + Assert.AreEqual(expectedOutput.Replace("\r", ""), outputVisitor.Text.Trim().Replace("\r", "")); + } + #endregion + + #region TestMember/TestStatement/TestExpression + string IndentAllLines(string code) + { + StringBuilder b = new StringBuilder(); + using (StringReader r = new StringReader(code)) { + string line; + while ((line = r.ReadLine()) != null) { + b.Append(" "); + b.AppendLine(line); + } + } + return b.ToString(); + } + + void TestMemberCS2VB(string sourceCode, string expectedCode) + { + TestProgramCS2VB("using System;\n" + + "class MyClassName {\n" + + IndentAllLines(sourceCode) + + "}", + + "Imports System\n" + + "Class MyClassName\n" + + IndentAllLines(expectedCode) + + "End Class"); + } + + void TestMemberVB2CS(string sourceCode, string expectedCode) + { + TestProgramVB2CS("Class MyClassName\n" + + IndentAllLines(sourceCode) + + "End Class", + + "using System;\n" + + "using Microsoft.VisualBasic;\n" + + "class MyClassName {\n" + + IndentAllLines(expectedCode) + + "}"); + } + + void TestStatementsCS2VB(string sourceCode, string expectedCode) + { + TestMemberCS2VB("void T() {\n" + + IndentAllLines(sourceCode) + + "}", + + "Private Sub T()\n" + + IndentAllLines(expectedCode) + + "End Sub"); + } + #endregion + + [Test] + public void RaiseEventCS2VB() + { + TestMemberCS2VB("public event EventHandler Click;" + + "void T() { if (Click != null) { Click(this, EventArgs.Empty); } }", + "Public Event Click As EventHandler\n" + + "Private Sub T()\n" + + " RaiseEvent Click(Me, EventArgs.Empty)\n" + + "End Sub"); + + TestMemberCS2VB("public event EventHandler Click;" + + "void T() { Click(this, EventArgs.Empty); }", + "Public Event Click As EventHandler\n" + + "Private Sub T()\n" + + " RaiseEvent Click(Me, EventArgs.Empty)\n" + + "End Sub"); + } + + [Test] + public void ReferenceEqualityAndValueEquality() + { + // Reference equality: + TestStatementsCS2VB("object a = new object();\n" + + "object b = new object();\n" + + "if (a == b) {\n" + + "}", + + "Dim a As New Object()\n" + + "Dim b As New Object()\n" + + "If a Is b Then\n" + + "End If"); + + // Value type equality: + TestStatementsCS2VB("int a = 3;\n" + + "int b = 4;\n" + + "if (a == b) {\n" + + "}", + + "Dim a As Integer = 3\n" + + "Dim b As Integer = 4\n" + + "If a = b Then\n" + + "End If"); + + // String equality: + TestStatementsCS2VB("string a = \"3\";\n" + + "string b = \"4\";\n" + + "if (a == b) {\n" + + "}", + + "Dim a As String = \"3\"\n" + + "Dim b As String = \"4\"\n" + + "If a = b Then\n" + + "End If"); + } + } +} diff --git a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj index ca4a5665f0..28bac3a542 100644 --- a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj +++ b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj @@ -49,6 +49,7 @@ + diff --git a/src/Main/Base/Test/MemberLookupHelperTests.cs b/src/Main/Base/Test/MemberLookupHelperTests.cs index 140c3dd44e..f78cb00df7 100644 --- a/src/Main/Base/Test/MemberLookupHelperTests.cs +++ b/src/Main/Base/Test/MemberLookupHelperTests.cs @@ -7,6 +7,7 @@ using System; using ICSharpCode.Core; +using System.Collections.Generic; using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; @@ -27,20 +28,35 @@ namespace ICSharpCode.SharpDevelop.Tests swf = r.GetProjectContentForReference("System.Windows.Forms", "System.Windows.Forms"); } - public IReturnType DictionaryRT { + IReturnType DictionaryRT { get { return new GetClassReturnType(msc, "System.Collections.Generic.Dictionary", 2); } } - public IClass EnumerableClass { + IClass EnumerableClass { get { return msc.GetClass("System.Collections.Generic.IEnumerable", 1); } } + ConstructedReturnType EnumerableOf(IReturnType element) + { + return new ConstructedReturnType(EnumerableClass.DefaultReturnType, new IReturnType[] { element }); + } + + ConstructedReturnType IListOf(IReturnType element) + { + return new ConstructedReturnType(msc.GetClass("System.Collections.Generic.IList", 1).DefaultReturnType, new IReturnType[] { element }); + } + + ConstructedReturnType ListOf(IReturnType element) + { + return new ConstructedReturnType(msc.GetClass("System.Collections.Generic.List", 1).DefaultReturnType, new IReturnType[] { element }); + } + [Test] - public void TypeParameterPassedToBaseClassTest() + public void TypeParameterPassedToBaseClassTestDictionary() { IReturnType[] stringInt = { msc.SystemTypes.String, msc.SystemTypes.Int32 }; IReturnType rrt = new ConstructedReturnType(DictionaryRT, stringInt); @@ -51,6 +67,74 @@ namespace ICSharpCode.SharpDevelop.Tests Assert.AreEqual("System.Int32", resc.TypeArguments[1].FullyQualifiedName); } + [Test] + public void TypeParameterPassedToBaseClassTestString() + { + IReturnType res = MemberLookupHelper.GetTypeParameterPassedToBaseClass(msc.SystemTypes.String, EnumerableClass, 0); + Assert.AreEqual("System.Char", res.FullyQualifiedName); + } + + DefaultClass CreateClassDerivingFromListOfString() + { + DefaultProjectContent dpc = new DefaultProjectContent(); + dpc.ReferencedContents.Add(msc); + DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc); + cu.Usings.Add(new DefaultUsing(dpc, new DomRegion(1,1, 5,5))); + cu.Usings[0].Usings.Add("System.Collections.Generic"); + + DefaultClass listDerivingClass = new DefaultClass(cu, "DerivesFromList"); + cu.Classes.Add(listDerivingClass); + listDerivingClass.BaseTypes.Add(new ConstructedReturnType(new SearchClassReturnType(dpc, listDerivingClass, 3, 1, + "List", 1), + new IReturnType[] { + new GetClassReturnType(dpc, "System.String", 0) + })); + + return listDerivingClass; + } + + DefaultClass CreateGenericClassDerivingFromList() + { + DefaultProjectContent dpc = new DefaultProjectContent(); + dpc.ReferencedContents.Add(msc); + DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc); + cu.Usings.Add(new DefaultUsing(dpc, new DomRegion(1,1, 5,5))); + cu.Usings[0].Usings.Add("System.Collections.Generic"); + + DefaultClass listDerivingClass = new DefaultClass(cu, "DerivesFromList"); + cu.Classes.Add(listDerivingClass); + listDerivingClass.TypeParameters.Add(new DefaultTypeParameter(listDerivingClass, "T", 0)); + listDerivingClass.BaseTypes.Add(new ConstructedReturnType(new SearchClassReturnType(dpc, listDerivingClass, 3, 1, + "List", 1), + new IReturnType[] { + new GenericReturnType(listDerivingClass.TypeParameters[0]) + })); + return listDerivingClass; + } + + [Test] + public void TypeParameterPassedToBaseClassTestClassDerivingFromList() + { + DefaultClass listDerivingClass = CreateClassDerivingFromListOfString(); + + IReturnType res = MemberLookupHelper.GetTypeParameterPassedToBaseClass(listDerivingClass.DefaultReturnType, + EnumerableClass, 0); + Assert.AreEqual("System.String", res.FullyQualifiedName); + } + + [Test] + public void TypeParameterPassedToBaseClassTestGenericClassDerivingFromList() + { + DefaultClass listDerivingClass = CreateGenericClassDerivingFromList(); + + ConstructedReturnType testType = new ConstructedReturnType(listDerivingClass.DefaultReturnType, + new IReturnType[] { msc.SystemTypes.String }); + + IReturnType res = MemberLookupHelper.GetTypeParameterPassedToBaseClass(testType, + EnumerableClass, 0); + Assert.AreEqual("System.String", res.FullyQualifiedName); + } + [Test] public void TypeParameterPassedToBaseClassSameClass() { @@ -68,5 +152,182 @@ namespace ICSharpCode.SharpDevelop.Tests swf.GetClass("System.Windows.Forms.ToolStripSeparator").DefaultReturnType); Assert.AreEqual("System.Windows.Forms.ToolStripItem", res.FullyQualifiedName); } + + [Test] + public void GetTypeInheritanceTreeOfClassDerivingFromListOfString() + { + List results = new List( + MemberLookupHelper.GetTypeInheritanceTree(CreateClassDerivingFromListOfString().DefaultReturnType) + ).ConvertAll(delegate (IReturnType rt) { return rt.DotNetName; }); + + results.Sort(); // order is not guaranteed, so sort for the unit test + + Assert.AreEqual("DerivesFromList;" + + "System.Collections.Generic.ICollection{System.String};" + + "System.Collections.Generic.IEnumerable{System.String};" + + "System.Collections.Generic.IList{System.String};" + + "System.Collections.Generic.List{System.String};" + + "System.Collections.ICollection;" + + "System.Collections.IEnumerable;" + + "System.Collections.IList;" + + "System.Object", + string.Join(";", results.ToArray())); + } + + [Test] + public void GetTypeInheritanceTreeOfStringArray() + { + List results = new List( + MemberLookupHelper.GetTypeInheritanceTree(new ArrayReturnType(msc, msc.SystemTypes.String, 1)) + ).ConvertAll(delegate (IReturnType rt) { return rt.DotNetName; }); + + results.Sort(); // order is not guaranteed, so sort for the unit test + + Assert.AreEqual("System.Collections.Generic.ICollection{System.String};" + + "System.Collections.Generic.IEnumerable{System.String};" + + "System.Collections.Generic.IList{System.String};" + + "System.Collections.ICollection;" + + "System.Collections.IEnumerable;" + + "System.Collections.IList;" + + "System.Object;" + + "System.String[]", + string.Join(";", results.ToArray())); + } + + [Test] + public void ConversionExistsFromStringArrayToObjectArray() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(new ArrayReturnType(msc, msc.SystemTypes.String, 1), + new ArrayReturnType(msc, msc.SystemTypes.Object, 1))); + } + + [Test] + public void NoConversionExistsFromObjectArrayToStringArray() + { + Assert.IsFalse(MemberLookupHelper.ConversionExists(new ArrayReturnType(msc, msc.SystemTypes.Object, 1), + new ArrayReturnType(msc, msc.SystemTypes.String, 1))); + } + + [Test] + public void ConversionExistsFromStringArrayToStringEnumerable() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(new ArrayReturnType(msc, msc.SystemTypes.String, 1), + EnumerableOf(msc.SystemTypes.String))); + } + + [Test] + public void NoConversionExistsFromStringEnumerableToObjectEnumerable() + { + Assert.IsFalse(MemberLookupHelper.ConversionExists(EnumerableOf(msc.SystemTypes.String), + EnumerableOf(msc.SystemTypes.Object))); + } + + [Test] + public void ConversionExistsFromStringIListToStringEnumerable() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(IListOf(msc.SystemTypes.String), + EnumerableOf(msc.SystemTypes.String))); + } + + [Test] + public void NoConversionExistsFromStringIListToIntEnumerable() + { + Assert.IsFalse(MemberLookupHelper.ConversionExists(IListOf(msc.SystemTypes.String), + EnumerableOf(msc.SystemTypes.Int32))); + } + + [Test] + public void ConversionExistsFromStringListToStringEnumerable() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(ListOf(msc.SystemTypes.String), + EnumerableOf(msc.SystemTypes.String))); + } + + [Test] + public void ConversionExistsFromClassDerivingFromListOfStringToStringEnumerable() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(CreateClassDerivingFromListOfString().DefaultReturnType, + EnumerableOf(msc.SystemTypes.String))); + } + + [Test] + public void ConversionExistsFromClassDerivingFromListOfStringToListOfString() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(CreateClassDerivingFromListOfString().DefaultReturnType, + ListOf(msc.SystemTypes.String))); + } + + GenericReturnType CreateT() + { + DefaultProjectContent dpc = new DefaultProjectContent(); + dpc.ReferencedContents.Add(msc); + DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc); + DefaultClass c = new DefaultClass(cu, "DummyClass"); + cu.Classes.Add(c); + DefaultMethod m = new DefaultMethod(c, "DummyMethod"); + c.Methods.Add(m); + m.TypeParameters.Add(new DefaultTypeParameter(m, "T", 0)); + return new GenericReturnType(m.TypeParameters[0]); + } + + GenericReturnType CreateTWithDisposableConstraint() + { + GenericReturnType rt = CreateT(); + rt.TypeParameter.Constraints.Add(msc.GetClass("System.IDisposable").DefaultReturnType); + return rt; + } + + [Test] + public void StringIsApplicableOnT() + { + // no conversion exists + Assert.IsFalse(MemberLookupHelper.ConversionExists(msc.SystemTypes.String, + CreateT())); + + // but it is applicable + Assert.IsTrue(MemberLookupHelper.IsApplicable(msc.SystemTypes.String, + CreateT())); + } + + [Test] + public void NoConversionExistsFromStringToDisposableT() + { + Assert.IsFalse(MemberLookupHelper.IsApplicable(msc.SystemTypes.String, + CreateTWithDisposableConstraint())); + + Assert.IsFalse(MemberLookupHelper.ConversionExists(msc.SystemTypes.String, + CreateTWithDisposableConstraint())); + } + + [Test] + public void DisposableClassIsApplicableOnDisposableT() + { + Assert.IsFalse(MemberLookupHelper.ConversionExists(msc.GetClass("System.CharEnumerator").DefaultReturnType, + CreateTWithDisposableConstraint())); + + Assert.IsTrue(MemberLookupHelper.IsApplicable(msc.GetClass("System.CharEnumerator").DefaultReturnType, + CreateTWithDisposableConstraint())); + } + + [Test] + public void ConversionExistsFromListOfStringToListOfT() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(ListOf(msc.SystemTypes.String), + ListOf(CreateT()))); + } + + [Test] + public void ConversionExistsFromListOfStringToIEnumerableOfT() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(ListOf(msc.SystemTypes.String), + EnumerableOf(CreateT()))); + } + + [Test] + public void ConversionExistsFromArrayOfStringToIListOfT() + { + Assert.IsTrue(MemberLookupHelper.ConversionExists(new ArrayReturnType(msc, msc.SystemTypes.String, 1), + IListOf(CreateT()))); + } } } diff --git a/src/Main/Base/Test/NRefactoryResolverTests.cs b/src/Main/Base/Test/NRefactoryResolverTests.cs index 516ed908e6..ab534ea20c 100644 --- a/src/Main/Base/Test/NRefactoryResolverTests.cs +++ b/src/Main/Base/Test/NRefactoryResolverTests.cs @@ -106,7 +106,7 @@ namespace ICSharpCode.SharpDevelop.Tests { ResolveResult rr = Resolve(program, expression, line); Assert.IsNotNull(rr, "Resolve returned null"); - Assert.IsTrue(rr is T, "result is " + typeof(T).Name); + Assert.AreEqual(typeof(T), rr.GetType()); return (T)rr; } @@ -114,7 +114,7 @@ namespace ICSharpCode.SharpDevelop.Tests { ResolveResult rr = ResolveVB(program, expression, line); Assert.IsNotNull(rr, "Resolve returned null"); - Assert.IsTrue(rr is T, "result is " + typeof(T).Name); + Assert.AreEqual(typeof(T), rr.GetType()); return (T)rr; } #endregion @@ -204,50 +204,6 @@ End Module #endregion #region Simple Tests - const string arrayListConflictProgram = @"using System.Collections; -class A { - void Test() { - - } - - ArrayList arrayList; - public ArrayList ArrayList { - get { - return arrayList; - } - } -} -"; - - [Test] - public void PropertyTypeConflictTest() - { - ResolveResult result = Resolve(arrayListConflictProgram, "arrayList", 4); - Assert.AreEqual("System.Collections.ArrayList", result.ResolvedType.FullyQualifiedName); - } - - [Test] - public void PropertyTypeConflictCompletionResultTest() - { - ResolveResult result = Resolve(arrayListConflictProgram, "ArrayList", 4); - // CC should offer both static and non-static results - ArrayList list = result.GetCompletionData(lastPC); - bool ok = false; - foreach (object o in list) { - IMethod method = o as IMethod; - if (method != null && method.Name == "AddRange") - ok = true; - } - Assert.IsTrue(ok, "AddRange should exist"); - ok = false; - foreach (object o in list) { - IMethod method = o as IMethod; - if (method != null && method.Name == "Adapter") - ok = true; - } - Assert.IsTrue(ok, "Adapter should exist"); - } - [Test] public void InheritedInterfaceResolveTest() { @@ -615,6 +571,23 @@ class TestClass { lr = Resolve(program, "i", 8); Assert.AreEqual("System.Int64", lr.ResolvedType.FullyQualifiedName); } + + [Test] + public void ShortMaxValueTest() + { + string program = @"using System; +class TestClass { + void Test() { + + } +} +"; + ResolveResult rr = Resolve(program, "short.MaxValue", 4); + Assert.AreEqual("System.Int16", rr.ResolvedType.FullyQualifiedName); + + rr = Resolve(program, "(short.MaxValue)", 4); + Assert.AreEqual("System.Int16", rr.ResolvedType.FullyQualifiedName); + } #endregion #region Import namespace tests @@ -931,6 +904,50 @@ class B { #endregion #region MixedType tests + const string arrayListMixedTypeProgram = @"using System.Collections; +class A { + void Test() { + + } + + ArrayList arrayList; + public ArrayList ArrayList { + get { + return arrayList; + } + } +} +"; + + [Test] + public void PropertyTypeConflictTest() + { + ResolveResult result = Resolve(arrayListMixedTypeProgram, "arrayList", 4); + Assert.AreEqual("System.Collections.ArrayList", result.ResolvedType.FullyQualifiedName); + } + + [Test] + public void PropertyTypeConflictCompletionResultTest() + { + ResolveResult result = Resolve(arrayListMixedTypeProgram, "ArrayList", 4); + // CC should offer both static and non-static results + ArrayList list = result.GetCompletionData(lastPC); + bool ok = false; + foreach (object o in list) { + IMethod method = o as IMethod; + if (method != null && method.Name == "AddRange") + ok = true; + } + Assert.IsTrue(ok, "AddRange should exist"); + ok = false; + foreach (object o in list) { + IMethod method = o as IMethod; + if (method != null && method.Name == "Adapter") + ok = true; + } + Assert.IsTrue(ok, "Adapter should exist"); + } + const string mixedTypeTestProgram = @"using System; class A { void TestMethod() { diff --git a/src/Main/Base/Test/OverloadFinding.cs b/src/Main/Base/Test/OverloadFinding.cs index cef9e5890b..683dc02fb5 100644 --- a/src/Main/Base/Test/OverloadFinding.cs +++ b/src/Main/Base/Test/OverloadFinding.cs @@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.Tests { string[] overloads = {"(T a)", "(int a)"}; Test("(1)", 1, overloads); - Test("(short.MaxValue)", 1, overloads); + Test("(short.MaxValue)", 0, overloads); Test("(long.MaxValue)", 0, overloads); } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj index 5bcbb4f6bd..beb99f0f79 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj @@ -65,6 +65,7 @@ + @@ -77,6 +78,7 @@ + @@ -84,6 +86,8 @@ + + diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/CSharpAmbience.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/CSharpAmbience.cs index 47e6bcab27..702bd54d55 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/CSharpAmbience.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/CSharpAmbience.cs @@ -406,6 +406,8 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp builder.Append("("); if (IncludeHTMLMarkup) builder.Append("
"); + if (m.IsExtensionMethod) builder.Append("this "); + for (int i = 0; i < m.Parameters.Count; ++i) { if (IncludeHTMLMarkup) builder.Append("   "); builder.Append(Convert(m.Parameters[i])); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AbstractReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AbstractReturnType.cs index bdbc2dc4ab..6c7ab20677 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AbstractReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AbstractReturnType.cs @@ -27,11 +27,16 @@ namespace ICSharpCode.SharpDevelop.Dom } } - public override bool Equals(object o) + public virtual bool Equals(IReturnType other) { - IReturnType rt = o as IReturnType; - if (rt == null) return false; - return rt.IsDefaultReturnType && this.FullyQualifiedName == rt.FullyQualifiedName && this.TypeParameterCount == rt.TypeParameterCount; + if (other == null) + return false; + return other.IsDefaultReturnType && this.FullyQualifiedName == other.FullyQualifiedName && this.TypeParameterCount == other.TypeParameterCount; + } + + public sealed override bool Equals(object o) + { + return Equals(o as IReturnType); } public override int GetHashCode() @@ -92,7 +97,7 @@ namespace ICSharpCode.SharpDevelop.Dom } public virtual ArrayReturnType CastToArrayReturnType() { - throw new InvalidCastException("Cannot cast " + ToString() + " to expected type."); + return null; } public virtual bool IsGenericReturnType { @@ -102,7 +107,7 @@ namespace ICSharpCode.SharpDevelop.Dom } public virtual GenericReturnType CastToGenericReturnType() { - throw new InvalidCastException("Cannot cast " + ToString() + " to expected type."); + return null; } public virtual bool IsConstructedReturnType { @@ -112,7 +117,17 @@ namespace ICSharpCode.SharpDevelop.Dom } public virtual ConstructedReturnType CastToConstructedReturnType() { - throw new InvalidCastException("Cannot cast " + ToString() + " to expected type."); + return null; + } + + public bool IsDecoratingReturnType() where T : DecoratingReturnType + { + return false; + } + + public T CastToDecoratingReturnType() where T : DecoratingReturnType + { + return null; } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AnonymousMethodReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AnonymousMethodReturnType.cs index c89ca9ebbb..d1f52a9e9f 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AnonymousMethodReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AnonymousMethodReturnType.cs @@ -14,7 +14,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// /// The return type of anonymous method expressions or lambda expressions. /// - public sealed class AnonymousMethodReturnType : ProxyReturnType + public sealed class AnonymousMethodReturnType : DecoratingReturnType { IReturnType returnType; IList parameters = new List(); @@ -25,6 +25,28 @@ namespace ICSharpCode.SharpDevelop.Dom this.cu = cu; } + public override bool Equals(IReturnType other) + { + if (other == null) return false; + AnonymousMethodReturnType o = other.CastToDecoratingReturnType(); + if (o == null) return false; + return this.FullyQualifiedName == o.FullyQualifiedName; + } + + public override int GetHashCode() + { + return this.FullyQualifiedName.GetHashCode(); + } + + public override T CastToDecoratingReturnType() + { + if (typeof(T) == typeof(AnonymousMethodReturnType)) { + return (T)(object)this; + } else { + return null; + } + } + /// /// Return type of the anonymous method. Can be null if inferred from context. /// @@ -50,12 +72,6 @@ namespace ICSharpCode.SharpDevelop.Dom } } - public override bool IsDefaultReturnType { - get { - return false; - } - } - volatile DefaultClass cachedClass; public override IClass GetUnderlyingClass() diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ArrayReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ArrayReturnType.cs index db5c382e60..f4eae495e3 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ArrayReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ArrayReturnType.cs @@ -17,7 +17,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// The element type is only used as return type for the indexer; all methods and fields /// are retrieved from System.Array. /// - public sealed class ArrayReturnType : ProxyReturnType + public sealed class ArrayReturnType : DecoratingReturnType { IReturnType elementType; int dimensions; @@ -42,9 +42,8 @@ namespace ICSharpCode.SharpDevelop.Dom this.dimensions = dimensions; } - public override bool Equals(object o) + public override bool Equals(IReturnType rt) { - IReturnType rt = o as IReturnType; if (rt == null || !rt.IsArrayReturnType) return false; ArrayReturnType art = rt.CastToArrayReturnType(); if (art.ArrayDimensions != dimensions) return false; @@ -58,6 +57,15 @@ namespace ICSharpCode.SharpDevelop.Dom } } + public override T CastToDecoratingReturnType() + { + if (typeof(T) == typeof(ArrayReturnType)) { + return (T)(object)this; + } else { + return null; + } + } + public IReturnType ArrayElementType { get { return elementType; @@ -136,34 +144,5 @@ namespace ICSharpCode.SharpDevelop.Dom { return String.Format("[ArrayReturnType: {0}, dimensions={1}]", elementType, AppendArrayString("")); } - - public override bool IsDefaultReturnType { - get { - return false; - } - } - - public override bool IsArrayReturnType { - get { - return true; - } - } - - public override ArrayReturnType CastToArrayReturnType() - { - return this; - } - - public override bool IsConstructedReturnType { - get { - return false; - } - } - - public override bool IsGenericReturnType { - get { - return false; - } - } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CombinedReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CombinedReturnType.cs index 1aeae1ce99..ec0320461f 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CombinedReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CombinedReturnType.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.SharpDevelop.Dom string @namespace; string dotnetName; - public override bool Equals(object obj) + public override bool Equals(IReturnType obj) { CombinedReturnType combined = obj as CombinedReturnType; if (combined == null) return false; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs index 8adc0384bf..a765f24170 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs @@ -18,7 +18,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// collection. /// Example: List<string> /// - public sealed class ConstructedReturnType : ProxyReturnType + public sealed class ConstructedReturnType : DecoratingReturnType { // Return types that should be substituted for the generic types // If a substitution is unknown (type could not be resolved), the list @@ -42,11 +42,20 @@ namespace ICSharpCode.SharpDevelop.Dom this.baseType = baseType; } - public override bool Equals(object o) + public override T CastToDecoratingReturnType() { - IReturnType rt = o as IReturnType; - if (rt == null) return false; - return this.DotNetName == rt.DotNetName; + if (typeof(T) == typeof(ConstructedReturnType)) { + return (T)(object)this; + } else { + return null; + } + } + + public override bool Equals(IReturnType rt) + { + return rt != null + && rt.IsConstructedReturnType + && this.DotNetName == rt.DotNetName; } public override int GetHashCode() @@ -235,34 +244,5 @@ namespace ICSharpCode.SharpDevelop.Dom } return r + ">]"; } - - public override bool IsDefaultReturnType { - get { - return false; - } - } - - public override bool IsArrayReturnType { - get { - return false; - } - } - - public override bool IsConstructedReturnType { - get { - return true; - } - } - - public override ConstructedReturnType CastToConstructedReturnType() - { - return this; - } - - public override bool IsGenericReturnType { - get { - return false; - } - } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DecoratingReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DecoratingReturnType.cs new file mode 100644 index 0000000000..6760ce56ff --- /dev/null +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DecoratingReturnType.cs @@ -0,0 +1,28 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.SharpDevelop.Dom +{ + /// + /// A return type that modifies the base return type and is not regarded equal to its base type. + /// + public abstract class DecoratingReturnType : ProxyReturnType + { + public abstract override bool Equals(IReturnType other); + public abstract override int GetHashCode(); + + public sealed override bool IsDefaultReturnType { + get { + return false; + } + } + + public abstract override T CastToDecoratingReturnType(); + } +} diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs index 4f9ee0d330..07d6f6a579 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs @@ -317,7 +317,7 @@ namespace ICSharpCode.SharpDevelop.Dom if (typesToVisit.Count > 0) { nextType = typesToVisit.Dequeue(); } else { - nextType = enqueuedLastBaseType ? null : GetBaseTypeByClassType(); + nextType = enqueuedLastBaseType ? null : GetBaseTypeByClassType(this); enqueuedLastBaseType = true; } if (nextType != null) { @@ -357,28 +357,28 @@ namespace ICSharpCode.SharpDevelop.Dom } } if (cachedBaseType == null) { - return GetBaseTypeByClassType(); + return GetBaseTypeByClassType(this); } else { return cachedBaseType; } } } - IReturnType GetBaseTypeByClassType() + internal static IReturnType GetBaseTypeByClassType(IClass c) { - switch (ClassType) { + switch (c.ClassType) { case ClassType.Class: case ClassType.Interface: - if (FullyQualifiedName != "System.Object") { - return this.ProjectContent.SystemTypes.Object; + if (c.FullyQualifiedName != "System.Object") { + return c.ProjectContent.SystemTypes.Object; } break; case ClassType.Enum: - return this.ProjectContent.SystemTypes.Enum; + return c.ProjectContent.SystemTypes.Enum; case ClassType.Delegate: - return this.ProjectContent.SystemTypes.Delegate; + return c.ProjectContent.SystemTypes.Delegate; case ClassType.Struct: - return this.ProjectContent.SystemTypes.ValueType; + return c.ProjectContent.SystemTypes.ValueType; } return null; } @@ -390,20 +390,11 @@ namespace ICSharpCode.SharpDevelop.Dom if (baseClass != null && baseClass.ClassType == this.ClassType) return baseClass; } - switch (ClassType) { - case ClassType.Class: - if (FullyQualifiedName != "System.Object") { - return this.ProjectContent.SystemTypes.Object.GetUnderlyingClass(); - } - break; - case ClassType.Enum: - return this.ProjectContent.SystemTypes.Enum.GetUnderlyingClass(); - case ClassType.Delegate: - return this.ProjectContent.SystemTypes.Delegate.GetUnderlyingClass(); - case ClassType.Struct: - return this.ProjectContent.SystemTypes.ValueType.GetUnderlyingClass(); - } - return null; + IReturnType defaultBaseType = GetBaseTypeByClassType(this); + if (defaultBaseType != null) + return defaultBaseType.GetUnderlyingClass(); + else + return null; } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultUsing.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultUsing.cs index 67e3cecfe0..de95e1e66b 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultUsing.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultUsing.cs @@ -63,8 +63,6 @@ namespace ICSharpCode.SharpDevelop.Dom { if (HasAliases) { foreach (KeyValuePair entry in aliases) { - if (!entry.Value.IsDefaultReturnType) - continue; string aliasString = entry.Key; string nsName; if (projectContent.Language.NameComparer.Equals(partialNamespaceName, aliasString)) { @@ -104,7 +102,7 @@ namespace ICSharpCode.SharpDevelop.Dom foreach (KeyValuePair entry in aliases) { string aliasString = entry.Key; if (projectContent.Language.NameComparer.Equals(partialTypeName, aliasString)) { - if (entry.Value.IsDefaultReturnType && entry.Value.GetUnderlyingClass() == null) + if (entry.Value.GetUnderlyingClass() == null) continue; // type not found, maybe entry was a namespace yield return entry.Value; } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ElementReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ElementReturnType.cs new file mode 100644 index 0000000000..fdf61eae79 --- /dev/null +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ElementReturnType.cs @@ -0,0 +1,52 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.SharpDevelop.Dom +{ + /// + /// The type reference that is the element of an enumerable. + /// This class is used in combination with an InferredReturnType to + /// represent the implicitly typed loop variable v in + /// "foreach (var v in enumerableInstance) {}" + /// + public class ElementReturnType : ProxyReturnType + { + IReturnType enumerableType; + IProjectContent pc; + + public ElementReturnType(IProjectContent pc, IReturnType enumerableType) + { + if (pc == null) + throw new ArgumentNullException("pc"); + this.enumerableType = enumerableType; + this.pc = pc; + } + + public override IReturnType BaseType { + get { + // get element type from enumerableType + if (enumerableType.IsArrayReturnType) + return enumerableType.CastToArrayReturnType().ArrayElementType; + + IClass c = enumerableType.GetUnderlyingClass(); + if (c == null) + return null; + IClass genumerable = pc.GetClass("System.Collections.Generic.IEnumerable", 1); + if (c.IsTypeInInheritanceTree(genumerable)) { + return MemberLookupHelper.GetTypeParameterPassedToBaseClass(enumerableType, genumerable, 0); + } + IClass enumerable = pc.GetClass("System.Collections.IEnumerable", 0); + if (c.IsTypeInInheritanceTree(enumerable)) { + return pc.SystemTypes.Object; + } + return null; + } + } + } +} diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GenericReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GenericReturnType.cs index 86a2792510..62faab54fc 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GenericReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GenericReturnType.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// /// GenericReturnType is a reference to a type parameter. /// - public sealed class GenericReturnType : ProxyReturnType + public sealed class GenericReturnType : DecoratingReturnType { ITypeParameter typeParameter; @@ -23,14 +23,22 @@ namespace ICSharpCode.SharpDevelop.Dom } } - public override bool Equals(object o) + public override bool Equals(IReturnType rt) { - IReturnType rt = o as IReturnType; if (rt == null || !rt.IsGenericReturnType) return false; return typeParameter.Equals(rt.CastToGenericReturnType().typeParameter); } + public override T CastToDecoratingReturnType() + { + if (typeof(T) == typeof(GenericReturnType)) { + return (T)(object)this; + } else { + return null; + } + } + public override int GetHashCode() { return typeParameter.GetHashCode(); @@ -107,34 +115,5 @@ namespace ICSharpCode.SharpDevelop.Dom { return String.Format("[GenericReturnType: {0}]", typeParameter); } - - public override bool IsDefaultReturnType { - get { - return false; - } - } - - public override bool IsArrayReturnType { - get { - return false; - } - } - - public override bool IsConstructedReturnType { - get { - return false; - } - } - - public override bool IsGenericReturnType { - get { - return true; - } - } - - public override ICSharpCode.SharpDevelop.Dom.GenericReturnType CastToGenericReturnType() - { - return this; - } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GetClassReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GetClassReturnType.cs index 2ee45cdf5c..0f0e67626b 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GetClassReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GetClassReturnType.cs @@ -39,17 +39,13 @@ namespace ICSharpCode.SharpDevelop.Dom } } - public override bool Equals(object o) + public override bool Equals(IReturnType o) { GetClassReturnType rt = o as GetClassReturnType; - if (rt == null) { - IReturnType rt2 = o as IReturnType; - if (rt2 != null && rt2.IsDefaultReturnType) - return rt2.FullyQualifiedName == fullName && rt2.TypeParameterCount == this.TypeParameterCount; - else - return false; + if (rt != null) { + return fullName == rt.fullName && typeParameterCount == rt.typeParameterCount && content == rt.content; } - return fullName == rt.fullName && typeParameterCount == rt.typeParameterCount && content == rt.content; + return base.Equals(o); } public override int GetHashCode() diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/NullReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/NullReturnType.cs index 23987a76a4..47c428075c 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/NullReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/NullReturnType.cs @@ -15,7 +15,7 @@ namespace ICSharpCode.SharpDevelop.Dom { public static readonly NullReturnType Instance = new NullReturnType(); - public override bool Equals(object o) + public override bool Equals(IReturnType o) { return o is NullReturnType; } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ProxyReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ProxyReturnType.cs index 48ab842e07..7ddeb21232 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ProxyReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ProxyReturnType.cs @@ -19,6 +19,30 @@ namespace ICSharpCode.SharpDevelop.Dom get; } + public sealed override bool Equals(object obj) + { + if (obj == this) + return true; + else + return Equals(obj as IReturnType); + } + + public virtual bool Equals(IReturnType other) + { + IReturnType baseType = BaseType; + bool tmp = (baseType != null && TryEnter()) ? baseType.Equals(other) : false; + busy = false; + return tmp; + } + + public override int GetHashCode() + { + IReturnType baseType = BaseType; + int tmp = (baseType != null && TryEnter()) ? baseType.GetHashCode() : 0; + busy = false; + return tmp; + } + // Required to prevent stack overflow on inferrence cycles bool busy = false; @@ -133,64 +157,52 @@ namespace ICSharpCode.SharpDevelop.Dom } } - public virtual bool IsArrayReturnType { - get { - IReturnType baseType = BaseType; - bool tmp = (baseType != null && TryEnter()) ? baseType.IsArrayReturnType : false; - busy = false; - return tmp; - } + public bool IsDecoratingReturnType() where T : DecoratingReturnType + { + return CastToDecoratingReturnType() != null; } - public virtual ArrayReturnType CastToArrayReturnType() + + public virtual T CastToDecoratingReturnType() where T : DecoratingReturnType { IReturnType baseType = BaseType; - ArrayReturnType temp; + T temp; if (baseType != null && TryEnter()) - temp = baseType.CastToArrayReturnType(); + temp = baseType.CastToDecoratingReturnType(); else - throw new InvalidCastException("Cannot cast " + ToString() + " to expected type."); + temp = null; busy = false; return temp; } - public virtual bool IsGenericReturnType { + + public bool IsArrayReturnType { get { - IReturnType baseType = BaseType; - bool tmp = (baseType != null && TryEnter()) ? baseType.IsGenericReturnType : false; - busy = false; - return tmp; + return IsDecoratingReturnType(); } } - public virtual GenericReturnType CastToGenericReturnType() + public ArrayReturnType CastToArrayReturnType() { - IReturnType baseType = BaseType; - GenericReturnType temp; - if (baseType != null && TryEnter()) - temp = baseType.CastToGenericReturnType(); - else - throw new InvalidCastException("Cannot cast " + ToString() + " to expected type."); - busy = false; - return temp; + return CastToDecoratingReturnType(); } - public virtual bool IsConstructedReturnType { + public bool IsGenericReturnType { get { - IReturnType baseType = BaseType; - bool tmp = (baseType != null && TryEnter()) ? baseType.IsConstructedReturnType : false; - busy = false; - return tmp; + return IsDecoratingReturnType(); } } - public virtual ConstructedReturnType CastToConstructedReturnType() + public GenericReturnType CastToGenericReturnType() { - IReturnType baseType = BaseType; - ConstructedReturnType temp; - if (baseType != null && TryEnter()) - temp = baseType.CastToConstructedReturnType(); - else - throw new InvalidCastException("Cannot cast " + ToString() + " to expected type."); - busy = false; - return temp; + return CastToDecoratingReturnType(); + } + + public bool IsConstructedReturnType { + get { + return IsDecoratingReturnType(); + } + } + public ConstructedReturnType CastToConstructedReturnType() + { + return CastToDecoratingReturnType(); } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs index b63108d3eb..4638c74469 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs @@ -41,13 +41,7 @@ namespace ICSharpCode.SharpDevelop.Dom shortName = name.Substring(pos + 1); } - public override int TypeParameterCount { - get { - return typeParameterCount; - } - } - - public override bool Equals(object o) + public override bool Equals(IReturnType o) { SearchClassReturnType rt = o as SearchClassReturnType; if (rt != null) { @@ -61,11 +55,7 @@ namespace ICSharpCode.SharpDevelop.Dom return true; } } - IReturnType rt2 = o as IReturnType; - if (rt2 != null && rt2.IsDefaultReturnType) - return rt2.FullyQualifiedName == this.FullyQualifiedName && rt2.TypeParameterCount == this.TypeParameterCount; - else - return false; + return base.Equals(o); } public override int GetHashCode() @@ -164,12 +154,6 @@ namespace ICSharpCode.SharpDevelop.Dom } } - public override bool IsDefaultReturnType { - get { - return true; - } - } - public override string ToString() { return String.Format("[SearchClassReturnType: {0}]", name); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IReturnType.cs index 510471d331..47fa98aaf5 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IReturnType.cs @@ -15,7 +15,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// Such a reference can be direct (DefaultReturnType), lazy (SearchClassReturnType) or /// returns types that stand for special references (e.g. ArrayReturnType) /// - public interface IReturnType + public interface IReturnType : IEquatable { /// /// Gets the fully qualified name of the class the return type is pointing to. @@ -105,6 +105,18 @@ namespace ICSharpCode.SharpDevelop.Dom /// bool IsDefaultReturnType { get; } + /// + /// Gets if the cast to the specified decorating return type would be valid. + /// + bool IsDecoratingReturnType() where T : DecoratingReturnType; + + /// + /// Casts this return type to the decorating return type specified as type parameter. + /// This methods casts correctly even when the return type is wrapped by a ProxyReturnType. + /// When the cast is invalid, null is returned. + /// + T CastToDecoratingReturnType() where T : DecoratingReturnType; + bool IsArrayReturnType { get; } ArrayReturnType CastToArrayReturnType(); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs index 33c59cdd55..0a478d76dc 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs @@ -87,9 +87,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// (first parameter = instance parameter) /// public virtual bool SupportsExtensionMethods { - get { - return false; - } + get { return false; } } /// @@ -97,9 +95,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// (first parameter = instance parameter) /// public virtual bool SupportsExtensionProperties { - get { - return false; - } + get { return false; } } /// @@ -108,36 +104,28 @@ namespace ICSharpCode.SharpDevelop.Dom /// (returns false). This property has no effect if the language doesn't support /// public virtual bool SearchExtensionsInClasses { - get { - return false; - } + get { return false; } } /// /// Gets if namespaces are imported (i.e. Imports System, Dim a As Collections.ArrayList) /// public virtual bool ImportNamespaces { - get { - return false; - } + get { return false; } } /// /// Gets if modules are imported with their namespace (i.e. Microsoft.VisualBasic.Randomize()). /// public virtual bool ImportModules { - get { - return false; - } + get { return false; } } /// /// Gets if classes can be imported (i.e. Imports System.Math) /// public virtual bool CanImportClasses { - get { - return false; - } + get { return false; } } /// @@ -145,9 +133,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// used on any part. /// public virtual bool ImplicitPartialClasses { - get { - return false; - } + get { return false; } } /// @@ -155,18 +141,14 @@ namespace ICSharpCode.SharpDevelop.Dom /// Used for Boo, which creates instances like this: 'self.Size = Size(10, 20)' /// public virtual bool AllowObjectConstructionOutsideContext { - get { - return false; - } + get { return false; } } /// /// Gets if the language supports implicit interface implementations. /// public virtual bool SupportsImplicitInterfaceImplementation { - get { - return false; - } + get { return false; } } /// @@ -176,27 +158,21 @@ namespace ICSharpCode.SharpDevelop.Dom /// with conflicting return types are invalid unless they are renamed. /// public virtual bool ExplicitInterfaceImplementationIsPrivateScope { - get { - return false; - } + get { return false; } } /// /// Gets if events explicitly implementing an interface require add {} remove {} regions. /// public virtual bool RequiresAddRemoveRegionInExplicitInterfaceImplementation { - get { - return false; - } + get { return false; } } /// /// Gets the token that denotes a possible beginning of an indexer expression. /// public virtual string IndexerExpressionStartToken { - get { - return "["; - } + get { return "["; } } public virtual bool IsClassWithImplicitlyStaticMembers(IClass c) @@ -257,24 +233,26 @@ namespace ICSharpCode.SharpDevelop.Dom } public override bool SupportsImplicitInterfaceImplementation { - get { - return true; - } + get { return true; } } public override bool ExplicitInterfaceImplementationIsPrivateScope { - get { - return true; - } + get { return true; } } /// /// Gets if events explicitly implementing an interface require add {} remove {} regions. /// public override bool RequiresAddRemoveRegionInExplicitInterfaceImplementation { - get { - return true; - } + get { return true; } + } + + public override bool SupportsExtensionMethods { + get { return true; } + } + + public override bool SearchExtensionsInClasses { + get { return true; } } public override string ToString() diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/MemberLookupHelper.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/MemberLookupHelper.cs index 030d0d5d0b..1f1ac9f3b4 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/MemberLookupHelper.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/MemberLookupHelper.cs @@ -211,8 +211,8 @@ namespace ICSharpCode.SharpDevelop.Dom case 2: // the old member is better ranking[i] = score - 1; - // this is not really correct, normally we would need to - // compare the member with other members + // this is not really correct, we would need to compare the member with other members + // but this works as we're mostly interested in the best overload only break; } } @@ -503,7 +503,7 @@ namespace ICSharpCode.SharpDevelop.Dom return ok; } - static bool IsApplicable(IReturnType argument, IReturnType expected) + public static bool IsApplicable(IReturnType argument, IReturnType expected) { if (argument == null) // TODO: Use NullReturnType instead of no return type return true; // "null" can be passed for any argument @@ -513,8 +513,10 @@ namespace ICSharpCode.SharpDevelop.Dom return false; } } + return true; + } else { + return ConversionExists(argument, expected); } - return ConversionExists(argument, expected); } #endregion @@ -564,13 +566,16 @@ namespace ICSharpCode.SharpDevelop.Dom if (toIsDefault && to.FullyQualifiedName == "System.Object") { return true; // from any type to object } - if (toIsDefault && (fromIsDefault || from.IsArrayReturnType)) { - IClass c1 = from.GetUnderlyingClass(); - IClass c2 = to.GetUnderlyingClass(); - if (c1 != null && c1.IsTypeInInheritanceTree(c2)) { - return true; + + if ((toIsDefault || to.IsConstructedReturnType) + && (fromIsDefault || from.IsArrayReturnType || from.IsConstructedReturnType)) + { + foreach (IReturnType baseTypeOfFrom in GetTypeInheritanceTree(from)) { + if (IsConstructedConversionToGenericReturnType(baseTypeOfFrom, to)) + return true; } } + if (from.IsArrayReturnType && to.IsArrayReturnType) { ArrayReturnType fromArt = from.CastToArrayReturnType(); ArrayReturnType toArt = to.CastToArrayReturnType(); @@ -580,24 +585,35 @@ namespace ICSharpCode.SharpDevelop.Dom } } - if (from.IsConstructedReturnType && to.IsConstructedReturnType) { - if (from.FullyQualifiedName == to.FullyQualifiedName) { - IList fromTypeArguments = from.CastToConstructedReturnType().TypeArguments; - IList toTypeArguments = to.CastToConstructedReturnType().TypeArguments; - if (fromTypeArguments.Count == toTypeArguments.Count) { - for (int i = 0; i < fromTypeArguments.Count; i++) { - if (fromTypeArguments[i] == toTypeArguments[i]) - continue; - if (object.Equals(fromTypeArguments[i], toTypeArguments[i])) - continue; - if (!(toTypeArguments[i].IsGenericReturnType)) - return false; - } - return true; + return false; + } + + static bool IsConstructedConversionToGenericReturnType(IReturnType from, IReturnType to) + { + if (from.Equals(to)) + return true; + + if (to.IsGenericReturnType) { + foreach (IReturnType constraintType in to.CastToGenericReturnType().TypeParameter.Constraints) { + if (!ConversionExists(from, constraintType)) { + return false; } } + return true; } + // for conversions like from IEnumerable to IEnumerable, where T is a GenericReturnType + ConstructedReturnType cFrom = from.CastToConstructedReturnType(); + ConstructedReturnType cTo = to.CastToConstructedReturnType(); + if (cFrom != null && cTo != null) { + if (cFrom.FullyQualifiedName == cTo.FullyQualifiedName && cFrom.TypeArguments.Count == cTo.TypeArguments.Count) { + for (int i = 0; i < cFrom.TypeArguments.Count; i++) { + if (!IsConstructedConversionToGenericReturnType(cFrom.TypeArguments[i], cTo.TypeArguments[i])) + return false; + } + return true; + } + } return false; } #endregion @@ -719,22 +735,11 @@ namespace ICSharpCode.SharpDevelop.Dom if (b == null) return a; if (ConversionExists(a, b)) return b; - if (ConversionExists(b, a)) - return a; - IClass c = a.GetUnderlyingClass(); - if (c != null) { - foreach (IClass baseClass in c.ClassInheritanceTree) { - IReturnType baseType = baseClass.DefaultReturnType; - if (baseClass.TypeParameters.Count > 0) { - IReturnType[] typeArguments = new IReturnType[baseClass.TypeParameters.Count]; - for (int i = 0; i < typeArguments.Length; i++) { - typeArguments[i] = GetTypeParameterPassedToBaseClass(a, baseClass, i); - } - baseType = new ConstructedReturnType(baseType, typeArguments); - } - if (ConversionExists(b, baseType)) - return baseType; - } + //if (ConversionExists(b, a)) - not required because the first baseTypeOfA is a + // return a; + foreach (IReturnType baseTypeOfA in GetTypeInheritanceTree(a)) { + if (ConversionExists(b, baseTypeOfA)) + return baseTypeOfA; } return projectContent.SystemTypes.Object; } @@ -746,31 +751,90 @@ namespace ICSharpCode.SharpDevelop.Dom /// public static IReturnType GetTypeParameterPassedToBaseClass(IReturnType parentType, IClass baseClass, int baseClassTypeParameterIndex) { - if (!parentType.IsConstructedReturnType) - return null; - ConstructedReturnType returnType = parentType.CastToConstructedReturnType(); - IClass c = returnType.GetUnderlyingClass(); - if (c == null) return null; - if (baseClass.CompareTo(c) == 0) { - if (baseClassTypeParameterIndex >= returnType.TypeArguments.Count) - return null; - return returnType.TypeArguments[baseClassTypeParameterIndex]; - } - foreach (IReturnType baseType in c.BaseTypes) { - if (baseClass.CompareTo(baseType.GetUnderlyingClass()) == 0) { - if (!baseType.IsConstructedReturnType) - return null; - ConstructedReturnType baseTypeCRT = baseType.CastToConstructedReturnType(); - if (baseClassTypeParameterIndex >= baseTypeCRT.TypeArguments.Count) - return null; - IReturnType result = baseTypeCRT.TypeArguments[baseClassTypeParameterIndex]; - if (returnType.TypeArguments != null) { - result = ConstructedReturnType.TranslateType(result, returnType.TypeArguments, false); + foreach (IReturnType rt in GetTypeInheritanceTree(parentType)) { + ConstructedReturnType crt = rt.CastToConstructedReturnType(); + if (crt != null && baseClass.CompareTo(rt.GetUnderlyingClass()) == 0) { + if (baseClassTypeParameterIndex < crt.TypeArguments.Count) { + return crt.TypeArguments[baseClassTypeParameterIndex]; } - return result; } } return null; } + + /// + /// Translates typeToTranslate using the type arguments from parentType; + /// + static IReturnType TranslateIfRequired(IReturnType parentType, IReturnType typeToTranslate) + { + if (typeToTranslate == null) + return null; + ConstructedReturnType parentConstructedType = parentType.CastToConstructedReturnType(); + if (parentConstructedType != null) { + return ConstructedReturnType.TranslateType(typeToTranslate, parentConstructedType.TypeArguments, false); + } else { + return typeToTranslate; + } + } + + /// + /// Gets all types the specified type inherits from (all classes and interfaces). + /// Unlike the class inheritance tree, this method takes care of type arguments and calculates the type + /// arguments that are passed to base classes. + /// + public static IEnumerable GetTypeInheritanceTree(IReturnType typeToListInheritanceTreeFor) + { + if (typeToListInheritanceTreeFor == null) + throw new ArgumentNullException("typeToListInheritanceTreeFor"); + + IClass classToListInheritanceTreeFor = typeToListInheritanceTreeFor.GetUnderlyingClass(); + if (classToListInheritanceTreeFor == null) + return new IReturnType[0]; + + if (typeToListInheritanceTreeFor.IsArrayReturnType) { + IReturnType elementType = typeToListInheritanceTreeFor.CastToArrayReturnType().ArrayElementType; + List resultList = new List(); + resultList.Add(typeToListInheritanceTreeFor); + resultList.AddRange(GetTypeInheritanceTree( + new ConstructedReturnType( + classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.Generic.IList", 1).DefaultReturnType, + new IReturnType[] { elementType } + ) + )); + resultList.Add(classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.IList", 0).DefaultReturnType); + resultList.Add(classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.ICollection", 0).DefaultReturnType); + // non-generic IEnumerable is already added by generic IEnumerable + return resultList; + } + + List visitedList = new List(); + Queue typesToVisit = new Queue(); + bool enqueuedLastBaseType = false; + + IReturnType currentType = typeToListInheritanceTreeFor; + IClass currentClass = classToListInheritanceTreeFor; + IReturnType nextType; + do { + if (currentClass != null) { + if (!visitedList.Contains(currentType)) { + visitedList.Add(currentType); + foreach (IReturnType type in currentClass.BaseTypes) { + typesToVisit.Enqueue(TranslateIfRequired(currentType, type)); + } + } + } + if (typesToVisit.Count > 0) { + nextType = typesToVisit.Dequeue(); + } else { + nextType = enqueuedLastBaseType ? null : DefaultClass.GetBaseTypeByClassType(classToListInheritanceTreeFor); + enqueuedLastBaseType = true; + } + if (nextType != null) { + currentType = nextType; + currentClass = nextType.GetUnderlyingClass(); + } + } while (nextType != null); + return visitedList; + } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/CSharpToVBNetConvertVisitor.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/CSharpToVBNetConvertVisitor.cs new file mode 100644 index 0000000000..5d547d80be --- /dev/null +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/CSharpToVBNetConvertVisitor.cs @@ -0,0 +1,101 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.Ast; +using ICSharpCode.NRefactory.Visitors; + +namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver +{ + /// + /// This class converts C# constructs to their VB.NET equivalents. + /// + public class CSharpToVBNetConvertVisitor : CSharpConstructsVisitor + { + NRefactoryResolver _resolver; + string _fileName; + + public CSharpToVBNetConvertVisitor(IProjectContent pc, string fileName) + { + _resolver = new NRefactoryResolver(pc, LanguageProperties.CSharp); + _fileName = fileName; + } + + public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data) + { + base.VisitCompilationUnit(compilationUnit, data); + ToVBNetConvertVisitor v = new ToVBNetConvertVisitor(); + compilationUnit.AcceptVisitor(v, data); + return null; + } + + public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) + { + // Initialize resolver for method: + if (!methodDeclaration.Body.IsNull) { + if (_resolver.Initialize(_fileName, methodDeclaration.Body.StartLocation.Y, methodDeclaration.Body.StartLocation.X)) { + _resolver.RunLookupTableVisitor(methodDeclaration); + } else { + LoggingService.Warn("Resolver initialization failed"); + } + } + return base.VisitMethodDeclaration(methodDeclaration, data); + } + + public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) + { + if (_resolver.CompilationUnit == null) + return base.VisitExpressionStatement(expressionStatement, data); + + // Transform event invocations that aren't already transformed by a parent IfStatement to RaiseEvent statement + InvocationExpression eventInvocation = expressionStatement.Expression as InvocationExpression; + if (eventInvocation != null && eventInvocation.TargetObject is IdentifierExpression) { + MemberResolveResult mrr = _resolver.ResolveInternal(eventInvocation.TargetObject, ExpressionContext.Default) as MemberResolveResult; + if (mrr != null && mrr.ResolvedMember is IEvent) { + ReplaceCurrentNode(new RaiseEventStatement( + ((IdentifierExpression)eventInvocation.TargetObject).Identifier, + eventInvocation.Arguments)); + } + } + return base.VisitExpressionStatement(expressionStatement, data); + } + + public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) + { + if (_resolver.CompilationUnit == null) + return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); + + base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); + if (binaryOperatorExpression.Op == BinaryOperatorType.Equality || binaryOperatorExpression.Op == BinaryOperatorType.InEquality) { + // maybe we have to convert Equality operator to ReferenceEquality + ResolveResult left = _resolver.ResolveInternal(binaryOperatorExpression.Left, ExpressionContext.Default); + ResolveResult right = _resolver.ResolveInternal(binaryOperatorExpression.Right, ExpressionContext.Default); + if (left != null && right != null && left.ResolvedType != null && right.ResolvedType != null) { + IClass cLeft = left.ResolvedType.GetUnderlyingClass(); + IClass cRight = right.ResolvedType.GetUnderlyingClass(); + if (cLeft != null && cRight != null) { + if ((cLeft.ClassType != ClassType.Struct && cLeft.ClassType != ClassType.Enum) + || (cRight.ClassType != ClassType.Struct && cRight.ClassType != ClassType.Enum)) + { + // this is a reference comparison + if (cLeft.FullyQualifiedName != "System.String") { + // and it's not a string comparison, so we'll use reference equality + if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) { + binaryOperatorExpression.Op = BinaryOperatorType.ReferenceEquality; + } else { + binaryOperatorExpression.Op = BinaryOperatorType.ReferenceInequality; + } + } + } + } + } + } + return null; + } + } +} diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/InferredReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/InferredReturnType.cs new file mode 100644 index 0000000000..4224f7b72e --- /dev/null +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/InferredReturnType.cs @@ -0,0 +1,49 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver +{ + /// + /// Used for the type of implicitly typed local variables in C# 3.0 or VB 9. + /// + public sealed class InferredReturnType : ProxyReturnType + { + NRefactoryResolver _resolver; + Expression _expression; + IReturnType _baseType; + + internal InferredReturnType(Expression expression, NRefactoryResolver resolver) + { + if (resolver == null) + throw new ArgumentNullException("resolver"); + + _expression = expression; + _resolver = resolver; + } + + public override IReturnType BaseType { + get { + if (_expression != null) { + // prevent infinite recursion: + Expression expr = _expression; + _expression = null; + + ResolveResult rr = _resolver.ResolveInternal(expr, ExpressionContext.Default); + if (rr != null) { + _baseType = rr.ResolvedType; + } + + _resolver = null; + } + return _baseType; + } + } + } +} diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs index bc5dc58608..f5b16be8d2 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs @@ -446,6 +446,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver DefaultClass c = GetCurrentClass(); DefaultMethod method = new DefaultMethod(methodDeclaration.Name, null, ConvertModifier(methodDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); + method.IsExtensionMethod = methodDeclaration.IsExtensionMethod; method.Documentation = GetDocumentation(region.BeginLine, methodDeclaration.Attributes); ConvertTemplates(methodDeclaration.Templates, method); method.ReturnType = CreateReturnType(methodDeclaration.TypeReference, method); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryInformationProvider.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryInformationProvider.cs index 459dae90b7..47ca0b90a8 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryInformationProvider.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryInformationProvider.cs @@ -7,23 +7,24 @@ using System; using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.Ast; namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver { public class NRefactoryInformationProvider : IEnvironmentInformationProvider { - IProjectContent pc; - IClass callingClass; + IProjectContent _projectContent; - public NRefactoryInformationProvider(IProjectContent pc, IClass callingClass) + public NRefactoryInformationProvider(IProjectContent projectContent) { - this.pc = pc; - this.callingClass = callingClass; + if (projectContent == null) + throw new ArgumentNullException("projectContent"); + _projectContent = projectContent; } public bool HasField(string fullTypeName, string fieldName) { - IClass c = pc.GetClass(fullTypeName); + IClass c = _projectContent.GetClass(fullTypeName); if (c == null) return false; foreach (IField field in c.DefaultReturnType.GetFields()) { diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs index a5450eece4..5c56a2142b 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs @@ -9,6 +9,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; +using System.Diagnostics; using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Visitors; @@ -99,21 +100,38 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } } - [Obsolete("Use the IProjectContent, LanguageProperties overload instead to support .cs files inside vb projects or similar.")] - public NRefactoryResolver(IProjectContent projectContent) - : this(projectContent, projectContent.Language) {} - Expression ParseExpression(string expression) { Expression expr = SpecialConstructs(expression); if (expr == null) { using (NR.IParser p = NR.ParserFactory.CreateParser(language, new System.IO.StringReader(expression))) { expr = p.ParseExpression(); + if (expr != null) { + expr.AcceptVisitor(new SetAllNodePoints(new NR.Location(caretColumn, caretLine), + new NR.Location(caretColumn + 1, caretLine)), null); + } } } return expr; } + sealed class SetAllNodePoints : NodeTrackingAstVisitor + { + readonly NR.Location start, end; + + public SetAllNodePoints(ICSharpCode.NRefactory.Location start, ICSharpCode.NRefactory.Location end) + { + this.start = start; + this.end = end; + } + + protected override void BeginVisit(INode node) + { + node.StartLocation = start; + node.EndLocation = end; + } + } + string GetFixedExpression(ExpressionResult expressionResult) { string expression = expressionResult.Expression; @@ -189,7 +207,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } if (expressionResult.Context.IsAttributeContext) { - return ResolveAttribute(expr); + return ResolveAttribute(expr, new NR.Location(caretColumn, caretLineNumber)); } RunLookupTableVisitor(fileContent); @@ -297,28 +315,28 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver return null; } - IClass GetAttribute(string name) + IClass GetAttribute(string name, NR.Location position) { if (name == null) return null; - IClass c = SearchClass(name); + IClass c = SearchClass(name, position); if (c != null) { if (c.IsTypeInInheritanceTree(c.ProjectContent.SystemTypes.Attribute.GetUnderlyingClass())) return c; } - return SearchClass(name + "Attribute"); + return SearchClass(name + "Attribute", position); } - ResolveResult ResolveAttribute(Expression expr) + ResolveResult ResolveAttribute(Expression expr, NR.Location position) { string attributeName = GetAttributeName(expr); - IClass c = GetAttribute(attributeName); + IClass c = GetAttribute(attributeName, position); if (c != null) { return new TypeResolveResult(callingClass, callingMember, c); } else if (expr is InvocationExpression) { InvocationExpression ie = (InvocationExpression)expr; attributeName = GetAttributeName(ie.TargetObject); - c = GetAttribute(attributeName); + c = GetAttribute(attributeName, position); if (c != null) { List ctors = new List(); foreach (IMethod m in c.Methods) { @@ -387,7 +405,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver return result; } } else if (expr is IdentifierExpression) { - ResolveResult result = ResolveIdentifier(((IdentifierExpression)expr).Identifier, context); + ResolveResult result = ResolveIdentifier(((IdentifierExpression)expr).Identifier, expr.StartLocation, context); if (result != null) return result; } else if (expr is TypeReferenceExpression) { @@ -566,15 +584,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } #region Resolve Identifier - ResolveResult ResolveIdentifier(string identifier, ExpressionContext context) + ResolveResult ResolveIdentifier(string identifier, NR.Location position, ExpressionContext context) { - ResolveResult result = ResolveIdentifierInternal(identifier); + ResolveResult result = ResolveIdentifierInternal(identifier, position); if (result is TypeResolveResult) return result; ResolveResult result2 = null; - IReturnType t = SearchType(identifier); + IReturnType t = SearchType(identifier, position); if (t != null) { result2 = new TypeResolveResult(callingClass, callingMember, t); } else { @@ -611,10 +629,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver return f; } - ResolveResult ResolveIdentifierInternal(string identifier) + ResolveResult ResolveIdentifierInternal(string identifier, NR.Location position) { if (callingMember != null) { // LocalResolveResult requires callingMember to be set - LocalLookupVariable var = SearchVariable(identifier); + LocalLookupVariable var = SearchVariable(identifier, position); if (var != null) { return new LocalResolveResult(callingMember, CreateLocalVariableField(var, identifier)); } @@ -625,7 +643,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } if (IsSameName(identifier, "value")) { IProperty property = callingMember as IProperty; - if (property != null && property.SetterRegion.IsInside(caretLine, caretColumn)) { + if (property != null && property.SetterRegion.IsInside(position.Line, position.Column)) { IField field = new DefaultField.ParameterField(property.ReturnType, "value", property.Region, callingClass); return new LocalResolveResult(callingMember, field); } @@ -642,7 +660,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } // try if there exists a static member in outer classes named typeName - List classes = cu.GetOuterClasses(caretLine, caretColumn); + List classes = cu.GetOuterClasses(position.Line, position.Column); foreach (IClass c in classes) { IMember member = GetMember(c.DefaultReturnType, identifier); if (member != null && member.IsStatic) { @@ -650,7 +668,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } } - string namespaceName = SearchNamespace(identifier); + string namespaceName = SearchNamespace(identifier, position); if (namespaceName != null && namespaceName.Length > 0) { return new NamespaceResolveResult(callingClass, callingMember, namespaceName); } @@ -790,9 +808,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver /// /// use the usings to find the correct name of a namespace /// - public string SearchNamespace(string name) + public string SearchNamespace(string name, NR.Location position) { - return projectContent.SearchNamespace(name, callingClass, cu, caretLine, caretColumn); + return projectContent.SearchNamespace(name, callingClass, cu, position.Line, position.Column); } public IClass GetClass(string fullName) @@ -803,15 +821,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver /// /// use the usings and the name of the namespace to find a class /// - public IClass SearchClass(string name) + public IClass SearchClass(string name, NR.Location position) { - IReturnType t = SearchType(name); + IReturnType t = SearchType(name, position); return (t != null) ? t.GetUnderlyingClass() : null; } - public IReturnType SearchType(string name) + public IReturnType SearchType(string name, NR.Location position) { - return projectContent.SearchType(new SearchTypeRequest(name, 0, callingClass, cu, caretLine, caretColumn)).Result; + Debug.Assert(!position.IsEmpty); + return projectContent.SearchType(new SearchTypeRequest(name, 0, callingClass, cu, position.Line, position.Column)).Result; } #region Helper for TypeVisitor @@ -928,9 +947,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver /// /// does the dynamic lookup for the identifier /// - public IReturnType DynamicLookup(string identifier) + public IReturnType DynamicLookup(string identifier, NR.Location position) { - ResolveResult rr = ResolveIdentifierInternal(identifier); + ResolveResult rr = ResolveIdentifierInternal(identifier, position); if (rr is NamespaceResolveResult) { return new TypeVisitor.NamespaceReturnType((rr as NamespaceResolveResult).Name); } @@ -956,10 +975,20 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver if (v == null) { return null; } - return TypeVisitor.CreateReturnType(v.TypeRef, this); + + if (v.TypeRef == null || v.TypeRef.Type == "var") { + if (v.IsLoopVariable) { + return new ElementReturnType(this.projectContent, + new InferredReturnType(v.Initializer, this)); + } else { + return new InferredReturnType(v.Initializer, this); + } + } else { + return TypeVisitor.CreateReturnType(v.TypeRef, this); + } } - LocalLookupVariable SearchVariable(string name) + LocalLookupVariable SearchVariable(string name, NR.Location position) { if (lookupTableVisitor == null || !lookupTableVisitor.Variables.ContainsKey(name)) return null; @@ -969,7 +998,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } foreach (LocalLookupVariable v in variables) { - if (IsInside(new NR.Location(caretColumn, caretLine), v.StartPos, v.EndPos)) { + if (IsInside(position, v.StartPos, v.EndPos)) { return v; } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs index dba45c21c1..9c6c64d9db 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; +using System.Text; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.Ast; @@ -34,6 +35,19 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } } + public override object VisitQueryExpression(QueryExpression queryExpression, object data) + { + IReturnType type = queryExpression.SelectOrGroupClause.AcceptVisitor(this, data) as IReturnType; + if (type != null) { + return new ConstructedReturnType( + new GetClassReturnType(resolver.ProjectContent, "System.Collections.Generic.IEnumerable", 1), + new IReturnType[] { type } + ); + } else { + return null; + } + } + public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { switch (binaryOperatorExpression.Op) { @@ -230,11 +244,11 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver if (identifierExpression == null) { return null; } - IClass c = resolver.SearchClass(identifierExpression.Identifier); + IClass c = resolver.SearchClass(identifierExpression.Identifier, identifierExpression.StartLocation); if (c != null) { return c.DefaultReturnType; } - return resolver.DynamicLookup(identifierExpression.Identifier); + return resolver.DynamicLookup(identifierExpression.Identifier, identifierExpression.StartLocation); } public override object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) @@ -325,12 +339,71 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { - return CreateReturnType(objectCreateExpression.CreateType); + if (objectCreateExpression.IsAnonymousType) { + return CreateAnonymousTypeClass(objectCreateExpression.ObjectInitializer).DefaultReturnType; + } else { + return CreateReturnType(objectCreateExpression.CreateType); + } + } + + DefaultClass CreateAnonymousTypeClass(CollectionInitializerExpression initializer) + { + List fieldTypes = new List(); + List fieldNames = new List(); + + foreach (Expression expr in initializer.CreateExpressions) { + if (expr is AssignmentExpression) { + // use right part only + fieldTypes.Add( ((AssignmentExpression)expr).Right.AcceptVisitor(this, null) as IReturnType ); + } else { + fieldTypes.Add( expr.AcceptVisitor(this, null) as IReturnType ); + } + + fieldNames.Add(GetAnonymousTypeFieldName(expr)); + } + + StringBuilder nameBuilder = new StringBuilder(); + nameBuilder.Append('{'); + for (int i = 0; i < fieldTypes.Count; i++) { + if (i > 0) nameBuilder.Append(", "); + nameBuilder.Append(fieldNames[i]); + nameBuilder.Append(" : "); + if (fieldTypes[i] != null) { + nameBuilder.Append(fieldTypes[i].DotNetName); + } + } + nameBuilder.Append('}'); + + DefaultClass c = new DefaultClass(new DefaultCompilationUnit(resolver.ProjectContent), nameBuilder.ToString()); + c.Modifiers = ModifierEnum.Internal | ModifierEnum.Synthetic | ModifierEnum.Sealed; + for (int i = 0; i < fieldTypes.Count; i++) { + c.Fields.Add(new DefaultField(fieldTypes[i], fieldNames[i], ModifierEnum.Public | ModifierEnum.Synthetic, DomRegion.Empty, c)); + } + return c; + } + + static string GetAnonymousTypeFieldName(Expression expr) + { + if (expr is FieldReferenceExpression) { + return ((FieldReferenceExpression)expr).FieldName; + } + if (expr is AssignmentExpression) { + expr = ((AssignmentExpression)expr).Left; // use left side if it is an IdentifierExpression + } + if (expr is IdentifierExpression) { + return ((IdentifierExpression)expr).Identifier; + } else { + return "?"; + } } public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { - return CreateReturnType(arrayCreateExpression.CreateType); + if (arrayCreateExpression.IsImplicitlyTyped) { + return arrayCreateExpression.ArrayInitializer.AcceptVisitor(this, data); + } else { + return CreateReturnType(arrayCreateExpression.CreateType); + } } public override object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) @@ -352,10 +425,17 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver return amrt; } - public override object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data) + public override object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data) { - // no calls allowed !!! - return null; + // used for implicitly typed arrays + if (collectionInitializerExpression.CreateExpressions.Count == 0) + return null; + IReturnType combinedRT = collectionInitializerExpression.CreateExpressions[0].AcceptVisitor(this, data) as IReturnType; + for (int i = 1; i < collectionInitializerExpression.CreateExpressions.Count; i++) { + IReturnType rt = collectionInitializerExpression.CreateExpressions[i].AcceptVisitor(this, data) as IReturnType; + combinedRT = MemberLookupHelper.GetCommonType(resolver.ProjectContent, combinedRT, rt); + } + return new ArrayReturnType(resolver.ProjectContent, combinedRT, 1); } IReturnType CreateReturnType(TypeReference reference) diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ResolveResult.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ResolveResult.cs index 7f14247786..644ef9afdb 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ResolveResult.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ResolveResult.cs @@ -164,7 +164,7 @@ namespace ICSharpCode.SharpDevelop.Dom } } // now add the extension method if it fits the type - if (MemberLookupHelper.ConversionExists(resolvedType, ext.Parameters[0].ReturnType)) { + if (MemberLookupHelper.IsApplicable(resolvedType, ext.Parameters[0].ReturnType)) { IMethod method = ext as IMethod; if (method != null && method.TypeParameters.Count > 0) { IReturnType[] typeArguments = new IReturnType[method.TypeParameters.Count]; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetAmbience.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetAmbience.cs index c991c705c3..9d0641f4e1 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetAmbience.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetAmbience.cs @@ -372,7 +372,11 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet public override string Convert(IMethod m) { StringBuilder builder = new StringBuilder(); - builder.Append(Convert(m.Modifiers)); + if (ShowModifiers && m.IsExtensionMethod) { + builder.Append(" "); + } + + builder.Append(Convert(m.Modifiers)); // show visibility if (ShowModifiers) { builder.Append(GetModifier(m)); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/XmlDoc.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/XmlDoc.cs index c0d5bc2060..4d26c89b7d 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/XmlDoc.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/XmlDoc.cs @@ -239,7 +239,7 @@ namespace ICSharpCode.SharpDevelop.Dom public static XmlDoc Load(string fileName, string cachePath) { - LoggingService.Debug("Loading XmlDoc for " + fileName); + //LoggingService.Debug("Loading XmlDoc for " + fileName); Directory.CreateDirectory(cachePath); string cacheName = cachePath + "/" + Path.GetFileNameWithoutExtension(fileName) + "." + fileName.GetHashCode().ToString("x") + ".dat"; @@ -247,7 +247,7 @@ namespace ICSharpCode.SharpDevelop.Dom if (File.Exists(cacheName)) { doc = new XmlDoc(); if (doc.LoadFromBinary(cacheName, File.GetLastWriteTimeUtc(fileName))) { - LoggingService.Debug("XmlDoc: Load from cache successful"); + //LoggingService.Debug("XmlDoc: Load from cache successful"); return doc; } else { doc.Dispose(); @@ -262,17 +262,17 @@ namespace ICSharpCode.SharpDevelop.Dom doc = Load(xmlReader); } } catch (XmlException ex) { - LoggingService.Warn("Error loading XmlDoc", ex); + LoggingService.Warn("Error loading XmlDoc " + fileName, ex); return new XmlDoc(); } if (doc.xmlDescription.Count > cacheLength * 2) { - LoggingService.Debug("XmlDoc: Creating cache"); + LoggingService.Debug("XmlDoc: Creating cache for " + fileName); DateTime date = File.GetLastWriteTimeUtc(fileName); try { doc.Save(cacheName, date); } catch (Exception ex) { - LoggingService.Error("Cannot write to cache file", ex); + LoggingService.Error("Cannot write to cache file " + cacheName, ex); return doc; } doc.Dispose(); diff --git a/src/SharpDevelop.Tests.sln b/src/SharpDevelop.Tests.sln index 233ac3f945..dda8002bfa 100644 --- a/src/SharpDevelop.Tests.sln +++ b/src/SharpDevelop.Tests.sln @@ -1,6 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 9.00 -# SharpDevelop 2.1.0.2027 +# Visual Studio 2005 +# SharpDevelop 2.1.0.2166 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{14A277EE-7DF1-4529-B639-7D1EF334C1C5}" ProjectSection(SolutionItems) = postProject EndProjectSection