From 059e7e904f954f92de0b1a908510cbce9c8b54b2 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 21 May 2005 21:19:54 +0000 Subject: [PATCH] Added anonymous methods to c# parser. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@155 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/FormattingStrategy/Indentation.cs | 6 +- .../NRefactory/Project/NRefactory.csproj | 3 +- .../Src/Output/CSharp/CSharpOutputVisitor.cs | 78 +++-- .../Src/Output/VBNet/VBNetOutputVisitor.cs | 6 + .../Expressions/AnonymousMethodExpression.cs | 53 +++ .../Project/Src/Parser/CSharp/Parser.cs | 314 ++++++++++-------- .../Project/Src/Parser/CSharp/cs.ATG | 23 ++ .../Src/Parser/Visitors/AbstractASTVisitor.cs | 36 +- .../Src/Parser/Visitors/IASTVisitor.cs | 1 + .../NRefactory/Test/NRefactoryTests.csproj | 1 + .../Expressions/AnonymousMethodTests.cs | 45 +++ .../Src/Commands/ClassMemberMenuBuilder.cs | 9 +- .../Src/TextEditor/Bookmarks/Bookmark.cs | 7 +- .../Gui/Editor/TextEditorDisplayBinding.cs | 1 + src/Main/Base/Test/GenericResolverTests.cs | 72 ++++ 15 files changed, 471 insertions(+), 184 deletions(-) create mode 100644 src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/Expressions/AnonymousMethodExpression.cs create mode 100644 src/Libraries/NRefactory/Test/Parser/Expressions/AnonymousMethodTests.cs create mode 100644 src/Main/Base/Test/GenericResolverTests.cs diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/Indentation.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/Indentation.cs index 1e3a39b4c5..2c9e06e0b6 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/Indentation.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/Indentation.cs @@ -93,7 +93,7 @@ namespace CSharpBinding.FormattingStrategy StringBuilder indent = new StringBuilder(); if (line.Length == 0) { - // Special threatment for empty lines: + // Special treatment for empty lines: if (blockComment || (inString && verbatim)) return; indent.Append(block.InnerIndent); @@ -303,7 +303,7 @@ namespace CSharpBinding.FormattingStrategy if (IsSingleStatementKeyword(block.LastWord)) { block.OneLineBlock = true; } - } else if (block.LastWord == "else" && lastRealChar == 'e') { + } else if (lastRealChar == 'e' && block.LastWord == "else") { block.OneLineBlock = true; block.Continuation = false; } @@ -369,7 +369,7 @@ namespace CSharpBinding.FormattingStrategy if (!Char.IsWhiteSpace(line[line.Length - 1])) return false; // one space after an empty comment is allowed - if (line.EndsWith("// ")) + if (line.EndsWith("// ") || line.EndsWith("* ")) return false; doc.Text = line.TrimEnd(); diff --git a/src/Libraries/NRefactory/Project/NRefactory.csproj b/src/Libraries/NRefactory/Project/NRefactory.csproj index ff1ebca922..5dc0a776f8 100644 --- a/src/Libraries/NRefactory/Project/NRefactory.csproj +++ b/src/Libraries/NRefactory/Project/NRefactory.csproj @@ -4,7 +4,7 @@ AnyCPU 8.0.41115 2.0 - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} + {3a9ae6aa-bc07-4a2f-972c-581e3ae2f195} ICSharpCode.NRefactory ICSharpCode.NRefactory Library @@ -183,6 +183,7 @@ + diff --git a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs index 1ea6a0ed7f..e1e4e2b4b4 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { outputFormatter = new OutputFormatter(prettyPrintOptions); nodeTracker = new NodeTracker(this); - } + } #region ICSharpCode.NRefactory.Parser.IASTVisitor interface implementation public object Visit(INode node, object data) @@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return "void"; case "System.Object": return "object"; - + case "System.UInt64": return "ulong"; case "System.UInt32": @@ -110,7 +110,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return typeString; } - public object Visit(TypeReference typeReference, object data) + public object Visit(TypeReference typeReference, object data) { if (typeReference.Type == null || typeReference.Type.Length ==0) { outputFormatter.PrintIdentifier("void"); @@ -187,10 +187,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } outputFormatter.PrintToken(Tokens.CloseSquareBracket); outputFormatter.NewLine(); - return null; + return null; } - public object Visit(ICSharpCode.NRefactory.Parser.AST.Attribute attribute, object data) + public object Visit(ICSharpCode.NRefactory.Parser.AST.Attribute attribute, object data) { outputFormatter.PrintIdentifier(attribute.Name); outputFormatter.PrintToken(Tokens.OpenParenthesis); @@ -211,7 +211,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(NamedArgumentExpression namedArgumentExpression, object data) + public object Visit(NamedArgumentExpression namedArgumentExpression, object data) { outputFormatter.PrintIdentifier(namedArgumentExpression.Name); outputFormatter.Space(); @@ -283,7 +283,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public object Visit(TypeDeclaration typeDeclaration, object data) + public object Visit(TypeDeclaration typeDeclaration, object data) { VisitAttributes(typeDeclaration.Attributes, data); outputFormatter.Indent(); @@ -364,7 +364,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(DelegateDeclaration delegateDeclaration, object data) + public object Visit(DelegateDeclaration delegateDeclaration, object data) { VisitAttributes(delegateDeclaration.Attributes, data); OutputModifier(delegateDeclaration.Modifier); @@ -439,7 +439,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(PropertyGetRegion propertyGetRegion, object data) + public object Visit(PropertyGetRegion propertyGetRegion, object data) { this.VisitAttributes(propertyGetRegion.Attributes, data); outputFormatter.Indent(); @@ -486,7 +486,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(EventAddRegion eventAddRegion, object data) + public object Visit(EventAddRegion eventAddRegion, object data) { VisitAttributes(eventAddRegion.Attributes, data); outputFormatter.Indent(); @@ -645,7 +645,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter // } else { // Visit(operatorDeclaration.OpratorDeclarator.TypeReference, data); // } -// +// // outputFormatter.PrintToken(Tokens.OpenParenthesis); // Visit(operatorDeclaration.OpratorDeclarator.FirstParameterType, data); // outputFormatter.Space(); @@ -658,7 +658,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter // outputFormatter.PrintIdentifier(operatorDeclaration.OpratorDeclarator.SecondParameterName); // } // outputFormatter.PrintToken(Tokens.CloseParenthesis); -// +// // if (operatorDeclaration.Body.IsNull) { // outputFormatter.PrintToken(Tokens.Semicolon); // } else { @@ -816,21 +816,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(ReDimStatement reDimStatement, object data) + public object Visit(ReDimStatement reDimStatement, object data) { // TODO: implement me errors.Error(-1, -1, String.Format("ReDimStatement is unsupported")); return null; } -// public object Visit(ReDimClause reDimClause, object data) +// public object Visit(ReDimClause reDimClause, object data) // { // // TODO: implement me // errors.Error(-1, -1, String.Format("ReDimClause is unsupported")); // return null; // } - public object Visit(StatementExpression statementExpression, object data) + public object Visit(StatementExpression statementExpression, object data) { nodeTracker.TrackedVisit(statementExpression.Expression, data); outputFormatter.PrintToken(Tokens.Semicolon); @@ -998,7 +998,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(GotoStatement gotoStatement, object data) + public object Visit(GotoStatement gotoStatement, object data) { outputFormatter.PrintToken(Tokens.Goto); outputFormatter.Space(); @@ -1007,7 +1007,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(SwitchStatement switchStatement, object data) + public object Visit(SwitchStatement switchStatement, object data) { outputFormatter.PrintToken(Tokens.Switch); if (this.prettyPrintOptions.SwitchParentheses) { @@ -1045,14 +1045,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter // Check if a 'break' should be auto inserted. if (switchSection.Children.Count == 0 || !(switchSection.Children[switchSection.Children.Count - 1] is BreakStatement || - switchSection.Children[switchSection.Children.Count - 1] is ContinueStatement || + switchSection.Children[switchSection.Children.Count - 1] is ContinueStatement || switchSection.Children[switchSection.Children.Count - 1] is ReturnStatement)) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.Break); outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.NewLine(); } - + --outputFormatter.IndentationLevel; return null; } @@ -1253,7 +1253,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(TryCatchStatement tryCatchStatement, object data) + public object Visit(TryCatchStatement tryCatchStatement, object data) { outputFormatter.PrintToken(Tokens.Try); outputFormatter.Space(); @@ -1285,7 +1285,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(CatchClause catchClause, object data) + public object Visit(CatchClause catchClause, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.CloseCurlyBrace); @@ -1411,7 +1411,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(PrimitiveExpression primitiveExpression, object data) + public object Visit(PrimitiveExpression primitiveExpression, object data) { outputFormatter.PrintIdentifier(primitiveExpression.StringValue); return null; @@ -1430,7 +1430,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.Subtract: if (prettyPrintOptions.AroundAdditiveOperatorParentheses) { outputFormatter.Space(); @@ -1440,7 +1440,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.Multiply: if (prettyPrintOptions.AroundMultiplicativeOperatorParentheses) { outputFormatter.Space(); @@ -1450,7 +1450,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.Divide: if (prettyPrintOptions.AroundMultiplicativeOperatorParentheses) { outputFormatter.Space(); @@ -1460,7 +1460,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.Modulus: if (prettyPrintOptions.AroundMultiplicativeOperatorParentheses) { outputFormatter.Space(); @@ -1470,7 +1470,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.ShiftLeft: if (prettyPrintOptions.AroundShiftOperatorParentheses) { outputFormatter.Space(); @@ -1480,7 +1480,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.ShiftRight: if (prettyPrintOptions.AroundShiftOperatorParentheses) { outputFormatter.Space(); @@ -1491,7 +1491,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.BitwiseAnd: if (prettyPrintOptions.AroundBitwiseOperatorParentheses) { outputFormatter.Space(); @@ -1519,7 +1519,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.LogicalAnd: if (prettyPrintOptions.AroundLogicalOperatorParentheses) { outputFormatter.Space(); @@ -1538,13 +1538,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } break; - + case BinaryOperatorType.AS: outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); break; - + case BinaryOperatorType.IS: outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Is); @@ -1807,6 +1807,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } + public object Visit(AnonymousMethodExpression anonymousMethodExpression, object data) + { + outputFormatter.PrintToken(Tokens.Delegate); + + outputFormatter.PrintToken(Tokens.OpenParenthesis); + AppendCommaSeparatedList(anonymousMethodExpression.Parameters); + outputFormatter.PrintToken(Tokens.CloseParenthesis); + OutputBlock(anonymousMethodExpression.Body, this.prettyPrintOptions.MethodBraceStyle); + + return null; + } + public object Visit(CheckedExpression checkedExpression, object data) { outputFormatter.PrintToken(Tokens.Checked); @@ -1840,7 +1852,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(CastExpression castExpression, object data) + public object Visit(CastExpression castExpression, object data) { outputFormatter.PrintToken(Tokens.OpenParenthesis); nodeTracker.TrackedVisit(castExpression.CastTo, data); diff --git a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs index 69e7b26f70..f84a36d84e 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs @@ -1976,6 +1976,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } + public object Visit(AnonymousMethodExpression anonymousMethodExpression, object data) + { + errors.Error(-1, -1, String.Format("AnonymousMethodExpression is unsupported")); + return null; + } + public object Visit(CheckedExpression checkedExpression, object data) { errors.Error(-1, -1, String.Format("CheckedExpression is unsupported")); diff --git a/src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/Expressions/AnonymousMethodExpression.cs b/src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/Expressions/AnonymousMethodExpression.cs new file mode 100644 index 0000000000..7d43cb3afc --- /dev/null +++ b/src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/Expressions/AnonymousMethodExpression.cs @@ -0,0 +1,53 @@ +/* + * Created by SharpDevelop. + * User: Daniel Grunwald + * Date: 21.05.2005 + * Time: 21:44 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +using System; +using System.Collections; +using System.Diagnostics; + +namespace ICSharpCode.NRefactory.Parser.AST +{ + public class AnonymousMethodExpression : Expression + { + ArrayList parameters = new ArrayList(4); + + public ArrayList Parameters { + get { + return parameters; + } + set { + Debug.Assert(value != null); + parameters = value; + } + } + + BlockStatement body = BlockStatement.Null; + + public BlockStatement Body { + get { + return body; + } + set { + body = BlockStatement.CheckNull(value); + } + } + + public override object AcceptVisitor(IASTVisitor visitor, object data) + { + return visitor.Visit(this, data); + } + + public override string ToString() + { + return String.Format("[AnonymousMethodExpression: Parameters={0} Body={1}]", + GetCollectionString(Parameters), + Body); + } + } +} diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs index 3a207bd82b..5f29d636c1 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs @@ -1105,39 +1105,39 @@ templates); } void TypeParameterList( -#line 2128 "cs.ATG" +#line 2151 "cs.ATG" List templates) { -#line 2130 "cs.ATG" +#line 2153 "cs.ATG" AttributeSection section; ArrayList attributes = new ArrayList(); Expect(22); while (la.kind == 17) { AttributeSection( -#line 2134 "cs.ATG" +#line 2157 "cs.ATG" out section); -#line 2134 "cs.ATG" +#line 2157 "cs.ATG" attributes.Add(section); } Expect(1); -#line 2135 "cs.ATG" +#line 2158 "cs.ATG" templates.Add(new TemplateDefinition(t.val, attributes)); while (la.kind == 13) { lexer.NextToken(); while (la.kind == 17) { AttributeSection( -#line 2136 "cs.ATG" +#line 2159 "cs.ATG" out section); -#line 2136 "cs.ATG" +#line 2159 "cs.ATG" attributes.Add(section); } Expect(1); -#line 2137 "cs.ATG" +#line 2160 "cs.ATG" templates.Add(new TemplateDefinition(t.val, attributes)); } Expect(21); @@ -1171,25 +1171,25 @@ out qualident); } void TypeParameterConstraintsClause( -#line 2141 "cs.ATG" +#line 2164 "cs.ATG" List templates) { -#line 2142 "cs.ATG" +#line 2165 "cs.ATG" string name = ""; TypeReference type; Expect(1); -#line 2144 "cs.ATG" +#line 2167 "cs.ATG" if (t.val != "where") Error("where expected"); Expect(1); -#line 2145 "cs.ATG" +#line 2168 "cs.ATG" name = t.val; Expect(9); TypeParameterConstraintsClauseBase( -#line 2147 "cs.ATG" +#line 2170 "cs.ATG" out type); -#line 2148 "cs.ATG" +#line 2171 "cs.ATG" TemplateDefinition td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { @@ -1202,10 +1202,10 @@ out type); while (la.kind == 13) { lexer.NextToken(); TypeParameterConstraintsClauseBase( -#line 2157 "cs.ATG" +#line 2180 "cs.ATG" out type); -#line 2158 "cs.ATG" +#line 2181 "cs.ATG" td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { @@ -2581,20 +2581,20 @@ out type); } void TypeName( -#line 2110 "cs.ATG" +#line 2133 "cs.ATG" out string qualident, out List types) { -#line 2111 "cs.ATG" +#line 2134 "cs.ATG" List t; types = new List(); Qualident( -#line 2113 "cs.ATG" +#line 2136 "cs.ATG" out qualident); if (la.kind == 22) { TypeArgumentList( -#line 2114 "cs.ATG" +#line 2137 "cs.ATG" out t); -#line 2114 "cs.ATG" +#line 2137 "cs.ATG" types = t; } } @@ -4190,24 +4190,24 @@ out expr); } void ConditionalOrExpr( -#line 1988 "cs.ATG" +#line 2011 "cs.ATG" ref Expression outExpr) { -#line 1989 "cs.ATG" +#line 2012 "cs.ATG" Expression expr; ConditionalAndExpr( -#line 1991 "cs.ATG" +#line 2014 "cs.ATG" ref outExpr); while (la.kind == 25) { lexer.NextToken(); UnaryExpr( -#line 1991 "cs.ATG" +#line 2014 "cs.ATG" out expr); ConditionalAndExpr( -#line 1991 "cs.ATG" +#line 2014 "cs.ATG" ref expr); -#line 1991 "cs.ATG" +#line 2014 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); } } @@ -4631,6 +4631,16 @@ out expr); pexpr = new UncheckedExpression(expr); break; } + case 62: { + lexer.NextToken(); + AnonymousMethodExpr( +#line 1964 "cs.ATG" +out expr); + +#line 1964 "cs.ATG" + pexpr = expr; + break; + } default: SynErr(180); break; } while (StartOf(25)) { @@ -4638,353 +4648,395 @@ out expr); if (la.kind == 30) { lexer.NextToken(); -#line 1967 "cs.ATG" +#line 1968 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); } else if (la.kind == 31) { lexer.NextToken(); -#line 1968 "cs.ATG" +#line 1969 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); } else SynErr(181); } else if (la.kind == 46) { lexer.NextToken(); Expect(1); -#line 1971 "cs.ATG" +#line 1972 "cs.ATG" pexpr = new PointerReferenceExpression(pexpr, t.val); } else if (la.kind == 14) { lexer.NextToken(); Expect(1); -#line 1972 "cs.ATG" +#line 1973 "cs.ATG" pexpr = new FieldReferenceExpression(pexpr, t.val); } else if (la.kind == 19) { lexer.NextToken(); -#line 1974 "cs.ATG" +#line 1975 "cs.ATG" ArrayList parameters = new ArrayList(); if (StartOf(21)) { Argument( -#line 1975 "cs.ATG" +#line 1976 "cs.ATG" out expr); -#line 1975 "cs.ATG" +#line 1976 "cs.ATG" if (expr != null) {parameters.Add(expr);} while (la.kind == 13) { lexer.NextToken(); Argument( -#line 1976 "cs.ATG" +#line 1977 "cs.ATG" out expr); -#line 1976 "cs.ATG" +#line 1977 "cs.ATG" if (expr != null) {parameters.Add(expr);} } } Expect(20); -#line 1977 "cs.ATG" +#line 1978 "cs.ATG" pexpr = new InvocationExpression(pexpr, parameters); } else { -#line 1979 "cs.ATG" +#line 1980 "cs.ATG" if (isArrayCreation) Error("element access not allow on array creation"); ArrayList indices = new ArrayList(); lexer.NextToken(); Expr( -#line 1982 "cs.ATG" +#line 1983 "cs.ATG" out expr); -#line 1982 "cs.ATG" +#line 1983 "cs.ATG" if (expr != null) { indices.Add(expr); } while (la.kind == 13) { lexer.NextToken(); Expr( -#line 1983 "cs.ATG" +#line 1984 "cs.ATG" out expr); -#line 1983 "cs.ATG" +#line 1984 "cs.ATG" if (expr != null) { indices.Add(expr); } } Expect(18); -#line 1984 "cs.ATG" +#line 1985 "cs.ATG" pexpr = new IndexerExpression(pexpr, indices); } } } + void AnonymousMethodExpr( +#line 1989 "cs.ATG" +out Expression outExpr) { + +#line 1991 "cs.ATG" + AnonymousMethodExpression expr = new AnonymousMethodExpression(); + Statement stmt; + ArrayList p; + outExpr = expr; + + Expect(19); + if (StartOf(9)) { + FormalParameterList( +#line 1998 "cs.ATG" +out p); + +#line 1998 "cs.ATG" + expr.Parameters = p; + } + Expect(20); + +#line 2002 "cs.ATG" + if (compilationUnit != null) { + Block( +#line 2003 "cs.ATG" +out stmt); + +#line 2003 "cs.ATG" + expr.Body = (BlockStatement)stmt; + +#line 2004 "cs.ATG" + } else { + Expect(15); + +#line 2006 "cs.ATG" + lexer.SkipCurrentBlock(); + Expect(16); + +#line 2008 "cs.ATG" + } + } + void ConditionalAndExpr( -#line 1994 "cs.ATG" +#line 2017 "cs.ATG" ref Expression outExpr) { -#line 1995 "cs.ATG" +#line 2018 "cs.ATG" Expression expr; InclusiveOrExpr( -#line 1997 "cs.ATG" +#line 2020 "cs.ATG" ref outExpr); while (la.kind == 24) { lexer.NextToken(); UnaryExpr( -#line 1997 "cs.ATG" +#line 2020 "cs.ATG" out expr); InclusiveOrExpr( -#line 1997 "cs.ATG" +#line 2020 "cs.ATG" ref expr); -#line 1997 "cs.ATG" +#line 2020 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); } } void InclusiveOrExpr( -#line 2000 "cs.ATG" +#line 2023 "cs.ATG" ref Expression outExpr) { -#line 2001 "cs.ATG" +#line 2024 "cs.ATG" Expression expr; ExclusiveOrExpr( -#line 2003 "cs.ATG" +#line 2026 "cs.ATG" ref outExpr); while (la.kind == 28) { lexer.NextToken(); UnaryExpr( -#line 2003 "cs.ATG" +#line 2026 "cs.ATG" out expr); ExclusiveOrExpr( -#line 2003 "cs.ATG" +#line 2026 "cs.ATG" ref expr); -#line 2003 "cs.ATG" +#line 2026 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); } } void ExclusiveOrExpr( -#line 2006 "cs.ATG" +#line 2029 "cs.ATG" ref Expression outExpr) { -#line 2007 "cs.ATG" +#line 2030 "cs.ATG" Expression expr; AndExpr( -#line 2009 "cs.ATG" +#line 2032 "cs.ATG" ref outExpr); while (la.kind == 29) { lexer.NextToken(); UnaryExpr( -#line 2009 "cs.ATG" +#line 2032 "cs.ATG" out expr); AndExpr( -#line 2009 "cs.ATG" +#line 2032 "cs.ATG" ref expr); -#line 2009 "cs.ATG" +#line 2032 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); } } void AndExpr( -#line 2012 "cs.ATG" +#line 2035 "cs.ATG" ref Expression outExpr) { -#line 2013 "cs.ATG" +#line 2036 "cs.ATG" Expression expr; EqualityExpr( -#line 2015 "cs.ATG" +#line 2038 "cs.ATG" ref outExpr); while (la.kind == 27) { lexer.NextToken(); UnaryExpr( -#line 2015 "cs.ATG" +#line 2038 "cs.ATG" out expr); EqualityExpr( -#line 2015 "cs.ATG" +#line 2038 "cs.ATG" ref expr); -#line 2015 "cs.ATG" +#line 2038 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); } } void EqualityExpr( -#line 2018 "cs.ATG" +#line 2041 "cs.ATG" ref Expression outExpr) { -#line 2020 "cs.ATG" +#line 2043 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; RelationalExpr( -#line 2024 "cs.ATG" +#line 2047 "cs.ATG" ref outExpr); while (la.kind == 32 || la.kind == 33) { if (la.kind == 33) { lexer.NextToken(); -#line 2027 "cs.ATG" +#line 2050 "cs.ATG" op = BinaryOperatorType.InEquality; } else { lexer.NextToken(); -#line 2028 "cs.ATG" +#line 2051 "cs.ATG" op = BinaryOperatorType.Equality; } UnaryExpr( -#line 2030 "cs.ATG" +#line 2053 "cs.ATG" out expr); RelationalExpr( -#line 2030 "cs.ATG" +#line 2053 "cs.ATG" ref expr); -#line 2030 "cs.ATG" +#line 2053 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void RelationalExpr( -#line 2034 "cs.ATG" +#line 2057 "cs.ATG" ref Expression outExpr) { -#line 2036 "cs.ATG" +#line 2059 "cs.ATG" TypeReference type; Expression expr; BinaryOperatorType op = BinaryOperatorType.None; ShiftExpr( -#line 2041 "cs.ATG" +#line 2064 "cs.ATG" ref outExpr); while (StartOf(26)) { if (StartOf(27)) { if (la.kind == 22) { lexer.NextToken(); -#line 2044 "cs.ATG" +#line 2067 "cs.ATG" op = BinaryOperatorType.LessThan; } else if (la.kind == 21) { lexer.NextToken(); -#line 2045 "cs.ATG" +#line 2068 "cs.ATG" op = BinaryOperatorType.GreaterThan; } else if (la.kind == 35) { lexer.NextToken(); -#line 2046 "cs.ATG" +#line 2069 "cs.ATG" op = BinaryOperatorType.LessThanOrEqual; } else if (la.kind == 34) { lexer.NextToken(); -#line 2047 "cs.ATG" +#line 2070 "cs.ATG" op = BinaryOperatorType.GreaterThanOrEqual; } else SynErr(182); UnaryExpr( -#line 2049 "cs.ATG" +#line 2072 "cs.ATG" out expr); ShiftExpr( -#line 2049 "cs.ATG" +#line 2072 "cs.ATG" ref expr); -#line 2049 "cs.ATG" +#line 2072 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } else { if (la.kind == 83) { lexer.NextToken(); -#line 2052 "cs.ATG" +#line 2075 "cs.ATG" op = BinaryOperatorType.IS; } else if (la.kind == 48) { lexer.NextToken(); -#line 2053 "cs.ATG" +#line 2076 "cs.ATG" op = BinaryOperatorType.AS; } else SynErr(183); Type( -#line 2055 "cs.ATG" +#line 2078 "cs.ATG" out type); -#line 2055 "cs.ATG" +#line 2078 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, new TypeReferenceExpression(type)); } } } void ShiftExpr( -#line 2059 "cs.ATG" +#line 2082 "cs.ATG" ref Expression outExpr) { -#line 2061 "cs.ATG" +#line 2084 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; AdditiveExpr( -#line 2065 "cs.ATG" +#line 2088 "cs.ATG" ref outExpr); while (la.kind == 36 || -#line 2068 "cs.ATG" +#line 2091 "cs.ATG" IsShiftRight()) { if (la.kind == 36) { lexer.NextToken(); -#line 2067 "cs.ATG" +#line 2090 "cs.ATG" op = BinaryOperatorType.ShiftLeft; } else { Expect(21); Expect(21); -#line 2069 "cs.ATG" +#line 2092 "cs.ATG" op = BinaryOperatorType.ShiftRight; } UnaryExpr( -#line 2072 "cs.ATG" +#line 2095 "cs.ATG" out expr); AdditiveExpr( -#line 2072 "cs.ATG" +#line 2095 "cs.ATG" ref expr); -#line 2072 "cs.ATG" +#line 2095 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void AdditiveExpr( -#line 2076 "cs.ATG" +#line 2099 "cs.ATG" ref Expression outExpr) { -#line 2078 "cs.ATG" +#line 2101 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; MultiplicativeExpr( -#line 2082 "cs.ATG" +#line 2105 "cs.ATG" ref outExpr); while (la.kind == 4 || la.kind == 5) { if (la.kind == 4) { lexer.NextToken(); -#line 2085 "cs.ATG" +#line 2108 "cs.ATG" op = BinaryOperatorType.Add; } else { lexer.NextToken(); -#line 2086 "cs.ATG" +#line 2109 "cs.ATG" op = BinaryOperatorType.Subtract; } UnaryExpr( -#line 2088 "cs.ATG" +#line 2111 "cs.ATG" out expr); MultiplicativeExpr( -#line 2088 "cs.ATG" +#line 2111 "cs.ATG" ref expr); -#line 2088 "cs.ATG" +#line 2111 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void MultiplicativeExpr( -#line 2092 "cs.ATG" +#line 2115 "cs.ATG" ref Expression outExpr) { -#line 2094 "cs.ATG" +#line 2117 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; @@ -4992,84 +5044,84 @@ ref Expression outExpr) { if (la.kind == 6) { lexer.NextToken(); -#line 2100 "cs.ATG" +#line 2123 "cs.ATG" op = BinaryOperatorType.Multiply; } else if (la.kind == 7) { lexer.NextToken(); -#line 2101 "cs.ATG" +#line 2124 "cs.ATG" op = BinaryOperatorType.Divide; } else { lexer.NextToken(); -#line 2102 "cs.ATG" +#line 2125 "cs.ATG" op = BinaryOperatorType.Modulus; } UnaryExpr( -#line 2104 "cs.ATG" +#line 2127 "cs.ATG" out expr); -#line 2104 "cs.ATG" +#line 2127 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void TypeArgumentList( -#line 2117 "cs.ATG" +#line 2140 "cs.ATG" out List types) { -#line 2119 "cs.ATG" +#line 2142 "cs.ATG" types = new List(); TypeReference type = null; Expect(22); Type( -#line 2123 "cs.ATG" +#line 2146 "cs.ATG" out type); -#line 2123 "cs.ATG" +#line 2146 "cs.ATG" types.Add(type); while (la.kind == 13) { lexer.NextToken(); Type( -#line 2124 "cs.ATG" +#line 2147 "cs.ATG" out type); -#line 2124 "cs.ATG" +#line 2147 "cs.ATG" types.Add(type); } Expect(21); } void TypeParameterConstraintsClauseBase( -#line 2169 "cs.ATG" +#line 2192 "cs.ATG" out TypeReference type) { -#line 2170 "cs.ATG" +#line 2193 "cs.ATG" TypeReference t; type = null; if (la.kind == 107) { lexer.NextToken(); -#line 2172 "cs.ATG" +#line 2195 "cs.ATG" type = new TypeReference("struct"); } else if (la.kind == 57) { lexer.NextToken(); -#line 2173 "cs.ATG" +#line 2196 "cs.ATG" type = new TypeReference("struct"); } else if (la.kind == 87) { lexer.NextToken(); Expect(19); Expect(20); -#line 2174 "cs.ATG" +#line 2197 "cs.ATG" type = new TypeReference("struct"); } else if (StartOf(8)) { Type( -#line 2175 "cs.ATG" +#line 2198 "cs.ATG" out t); -#line 2175 "cs.ATG" +#line 2198 "cs.ATG" type = t; } else SynErr(184); } @@ -5324,7 +5376,7 @@ out t); {x,T,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,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,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,T,T,x, T,T,T,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,x,x,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,T,T,x, T,T,T,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,x,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,x, T,T,T,T, T,T,x,T, T,T,x,x, T,x,T,x, T,T,T,x, T,T,x,T, T,T,x,x, T,T,T,T, 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,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,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,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,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,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}, @@ -5340,10 +5392,10 @@ out 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, 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,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, 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,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,x,x,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,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,x,x,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,T,x, T,T,T,x, x,x,x,T, 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,x,x,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,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,x,x,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,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,x,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,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,x,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,T,x, T,T,T,x, x,x,x,T, 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,x,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,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,x,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,x,x,x, T,T,T,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,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,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}, diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG index 705cc32cd5..dd18a03582 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG @@ -1961,6 +1961,7 @@ PrimaryExpr | "sizeof" "(" Type ")" (. pexpr = new SizeOfExpression(type); .) | "checked" "(" Expr ")" (. pexpr = new CheckedExpression(expr); .) | "unchecked" "(" Expr ")" (. pexpr = new UncheckedExpression(expr); .) + | "delegate" AnonymousMethodExpr (. pexpr = expr; .) ) { ( @@ -1985,6 +1986,28 @@ PrimaryExpr } . +AnonymousMethodExpr +(. + AnonymousMethodExpression expr = new AnonymousMethodExpression(); + Statement stmt; + ArrayList p; + outExpr = expr; +.) += + "(" + [ FormalParameterList (. expr.Parameters = p; .) ] + ")" + /*--- 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; .) + (. } else { .) + "{" + (. lexer.SkipCurrentBlock(); .) + "}" + (. } .) +. + ConditionalOrExpr (. Expression expr; .) = diff --git a/src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs b/src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs index 5147c67a87..0a516227af 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs @@ -18,7 +18,6 @@ namespace ICSharpCode.NRefactory.Parser } } -#region ICSharpCode.NRefactory.Parser.IASTVisitor interface implementation public virtual object Visit(INode node, object data) { Console.WriteLine("Warning, INode visited!"); @@ -75,7 +74,7 @@ namespace ICSharpCode.NRefactory.Parser return namedArgumentExpression.Expression.AcceptVisitor(this, data); } -#region global scope + #region global scope public virtual object Visit(Using @using, object data) { Debug.Assert(@using != null); @@ -143,9 +142,9 @@ namespace ICSharpCode.NRefactory.Parser Debug.Assert(optionDeclaration != null); return data; } -#endregion + #endregion -#region type level + #region type level public virtual object Visit(FieldDeclaration fieldDeclaration, object data) { Debug.Assert(fieldDeclaration != null); @@ -420,9 +419,9 @@ namespace ICSharpCode.NRefactory.Parser } return data; } -#endregion + #endregion -#region statements + #region statements public virtual object Visit(BlockStatement blockStatement, object data) { Debug.Assert(blockStatement != null); @@ -835,10 +834,10 @@ namespace ICSharpCode.NRefactory.Parser forNextStatement.TypeReference.AcceptVisitor(this, data); return data; } - -#endregion -#region expressions + #endregion + + #region expressions public virtual object Visit(PrimitiveExpression primitiveExpression, object data) { Debug.Assert(primitiveExpression != null); @@ -1024,6 +1023,22 @@ namespace ICSharpCode.NRefactory.Parser return data; } + public object Visit(AnonymousMethodExpression anonymousMethodExpression, object data) + { + Debug.Assert(anonymousMethodExpression != null); + Debug.Assert(anonymousMethodExpression.Parameters != null); + Debug.Assert(anonymousMethodExpression.Body != null); + + foreach (ParameterDeclarationExpression p in anonymousMethodExpression.Parameters) { + p.AcceptVisitor(this, data); + } + blockStack.Push(anonymousMethodExpression.Body); + anonymousMethodExpression.Body.AcceptChildren(this, data); + blockStack.Pop(); + + return data; + } + public virtual object Visit(TypeOfIsExpression typeOfIsExpression, object data) { Debug.Assert(typeOfIsExpression != null); @@ -1100,7 +1115,6 @@ namespace ICSharpCode.NRefactory.Parser } return data; } -#endregion -#endregion + #endregion } } diff --git a/src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs b/src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs index d7be38e336..2c26ebea18 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs @@ -101,6 +101,7 @@ namespace ICSharpCode.NRefactory.Parser object Visit(TypeOfExpression typeOfExpression, object data); object Visit(TypeOfIsExpression typeOfIsExpression, object data); object Visit(AddressOfExpression addressOfExpression, object data); + object Visit(AnonymousMethodExpression anonymousMethodExpression, object data); object Visit(CheckedExpression checkedExpression, object data); object Visit(UncheckedExpression uncheckedExpression, object data); object Visit(PointerReferenceExpression pointerReferenceExpression, object data); diff --git a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj index eeb7979b86..5edc7f0d68 100644 --- a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj +++ b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj @@ -123,6 +123,7 @@ + diff --git a/src/Libraries/NRefactory/Test/Parser/Expressions/AnonymousMethodTests.cs b/src/Libraries/NRefactory/Test/Parser/Expressions/AnonymousMethodTests.cs new file mode 100644 index 0000000000..58c4ecb0ff --- /dev/null +++ b/src/Libraries/NRefactory/Test/Parser/Expressions/AnonymousMethodTests.cs @@ -0,0 +1,45 @@ +/* + * Created by SharpDevelop. + * User: Daniel Grunwald + * Date: 21.05.2005 + * Time: 21:33 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +using System; +using System.IO; +using NUnit.Framework; +using ICSharpCode.NRefactory.Parser; +using ICSharpCode.NRefactory.Parser.AST; + +namespace ICSharpCode.NRefactory.Tests.AST +{ + [TestFixture] + public class AnonymousMethodTests + { + AnonymousMethodExpression Parse(string program) + { + return (AnonymousMethodExpression)ParseUtilCSharp.ParseExpression(program, typeof(AnonymousMethodExpression)); + } + + [Test] + public void EmptyAnonymousMethod() + { + AnonymousMethodExpression ame = Parse("delegate() {}"); + Assert.AreEqual(0, ame.Parameters.Count); + Assert.AreEqual(0, ame.Body.Children.Count); + } + + [Test] + public void SimpleAnonymousMethod() + { + AnonymousMethodExpression ame = Parse("delegate(int a, int b) { return a + b; }"); + Assert.AreEqual(2, ame.Parameters.Count); + // blocks can't be added without compilation unit -> anonymous method body + // is always empty when using ParseExpression + //Assert.AreEqual(1, ame.Body.Children.Count); + //Assert.IsTrue(ame.Body.Children[0] is ReturnStatement); + } + } +} diff --git a/src/Main/Base/Project/Src/Commands/ClassMemberMenuBuilder.cs b/src/Main/Base/Project/Src/Commands/ClassMemberMenuBuilder.cs index d8a0b6e8f4..a49117e699 100644 --- a/src/Main/Base/Project/Src/Commands/ClassMemberMenuBuilder.cs +++ b/src/Main/Base/Project/Src/Commands/ClassMemberMenuBuilder.cs @@ -31,11 +31,14 @@ namespace ICSharpCode.SharpDevelop.Commands MenuCommand cmd; ClassMemberBookmark bookmark = (ClassMemberBookmark)owner; IMember member = bookmark.Member; + IMethod method = member as IMethod; List list = new List(); - cmd = new MenuCommand("&Rename", Rename); - cmd.Tag = member; - list.Add(cmd); + if (method == null || !method.IsConstructor) { + cmd = new MenuCommand("&Rename", Rename); + cmd.Tag = member; + list.Add(cmd); + } if (member.IsOverride) { cmd = new MenuCommand("Go to &base class", GoToBase); cmd.Tag = member; diff --git a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs index 62a169713f..de40f51607 100644 --- a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs +++ b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs @@ -53,8 +53,11 @@ namespace ICSharpCode.SharpDevelop.Bookmarks public void ChangeFilename(string newFileName) { fileName = newFileName; - foreach (SDBookmark mark in manager.Marks) { - mark.FileName = newFileName; + foreach (Bookmark mark in manager.Marks) { + SDBookmark sdMark = mark as SDBookmark; + if (sdMark != null) { + sdMark.FileName = newFileName; + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs index 8fcd8dd96b..eaa968497f 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs @@ -445,6 +445,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor { BookmarkManager bm = textAreaControl.Document.BookmarkManager; bm.RemoveMarks(new Predicate(IsClassMemberBookmark)); + if (parseInfo == null) return; foreach (IClass c in parseInfo.MostRecentCompilationUnit.Classes) { foreach (IMethod m in c.Methods) { if (m.Region == null || m.Region.BeginLine <= 0) continue; diff --git a/src/Main/Base/Test/GenericResolverTests.cs b/src/Main/Base/Test/GenericResolverTests.cs new file mode 100644 index 0000000000..9d6553ceed --- /dev/null +++ b/src/Main/Base/Test/GenericResolverTests.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections; +using System.IO; +using NUnit.Framework; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; + +namespace ICSharpCode.SharpDevelop.Tests +{ + [TestFixture] + public class GenericResolverTests + { + #region Test helper methods + NRefactoryResolverTests nrrt = new NRefactoryResolverTests(); + + ResolveResult Resolve(string program, string expression, int line) + { + return nrrt.Resolve(program, expression, line); + } + + ResolveResult ResolveVB(string program, string expression, int line) + { + return nrrt.ResolveVB(program, expression, line); + } + #endregion + + const string listProgram = @"using System.Collections.Generic; +class TestClass { + void Method() { + List list = new List(); + + } +} +"; + + [Test] + public void ListAddTest() + { + ResolveResult result = Resolve(listProgram, "list.Add(new A())", 5); + Assert.IsNotNull(result); + Assert.IsTrue(result is MemberResolveResult); + IMethod m = (IMethod)((MemberResolveResult)result).ResolvedMember; + Assert.AreEqual(1, m.Parameters.Count); + Assert.AreEqual("TestClass", m.Parameters[0].ReturnType.FullyQualifiedName); + } + + [Test] + public void ListAddRangeTest() + { + ResolveResult result = Resolve(listProgram, "list.AddRange(new A[0])", 5); + Assert.IsNotNull(result); + Assert.IsTrue(result is MemberResolveResult); + IMethod m = (IMethod)((MemberResolveResult)result).ResolvedMember; + Assert.AreEqual(1, m.Parameters.Count); + Assert.IsTrue(m.Parameters[0].ReturnType is SpecificReturnType); + Assert.AreEqual("System.Collections.Generic.IEnumerable", m.Parameters[0].ReturnType.FullyQualifiedName); + Assert.AreEqual("TestClass", ((SpecificReturnType)m.Parameters[0].ReturnType).TypeParameters[0].FullyQualifiedName); + } + + [Test] + public void ListToArrayTest() + { + ResolveResult result = Resolve(listProgram, "list.ToArray()", 5); + Assert.IsNotNull(result); + Assert.IsTrue(result is MemberResolveResult); + IMethod m = (IMethod)((MemberResolveResult)result).ResolvedMember; + Assert.AreEqual("TestClass", m.ReturnType.FullyQualifiedName); + Assert.AreEqual(1, m.ReturnType.ArrayDimensions); + } + } +}