public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { base.VisitLocalVariableDeclaration(localVariableDeclaration, data); if ((localVariableDeclaration.Modifier & Modifiers.Static) == Modifiers.Static) { INode parent = localVariableDeclaration.Parent; while (parent != null && !IsTypeLevel(parent)) { parent = parent.Parent; } if (parent != null) { INode type = parent.Parent; if (type != null) { int pos = type.Children.IndexOf(parent); if (pos >= 0) { FieldDeclaration field = new FieldDeclaration(null); field.TypeReference = localVariableDeclaration.TypeReference; field.Modifier = Modifiers.Static; field.Fields = localVariableDeclaration.Variables; new PrefixFieldsVisitor(field.Fields, "static_" + GetTypeLevelEntityName(parent) + "_").Run(parent); type.Children.Insert(pos + 1, field); RemoveCurrentNode(); } } } } return null; }
public static VariableDeclaration add_Variable(this BlockStatement blockDeclaration, string name, Expression expression, TypeReference typeReference) { var variableDeclaration = new VariableDeclaration(name, expression) {TypeReference = typeReference}; var localVariableDeclaration = new LocalVariableDeclaration(variableDeclaration); blockDeclaration.append(localVariableDeclaration); return variableDeclaration; }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if (localVariableDeclaration.TypeReference.IsArrayType) { if (localVariableDeclaration.Variables.Count > 0) { var decl = localVariableDeclaration.Variables[0] as VariableDeclaration; if (decl != null) { if (decl.Initializer is CollectionInitializerExpression) { UnlockWith(localVariableDeclaration); } else if (decl.Initializer is ArrayCreateExpression) { ArrayCreateExpression decl2 = decl.Initializer as ArrayCreateExpression; if (decl2.ArrayInitializer is CollectionInitializerExpression && decl2.ArrayInitializer.CreateExpressions.Count > 0) { UnlockWith(decl2.ArrayInitializer); } } } } } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object VisitLocalVariableDeclaration(ICSharpCode.NRefactory.Ast.LocalVariableDeclaration localVariableDeclaration, object data) { bool containsAll = true; foreach (VariableDeclaration v in localVariableDeclaration.Variables) { if (Contains(v)) { localVariableDeclaration.Parent.Children.Add(new ExpressionStatement( new AssignmentExpression(new IdentifierExpression(v.Name), AssignmentOperatorType.Assign, v.Initializer))); } else { containsAll = false; } } if (containsAll) { this.RemoveCurrentNode(); } return(base.VisitLocalVariableDeclaration(localVariableDeclaration, data)); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { //Tim= not so happy about hardocing this RankSpecifier, not sure when this specifier contains more than 1 element if (localVariableDeclaration.TypeReference.IsArrayType && localVariableDeclaration.TypeReference.RankSpecifier[0]>=1) UnlockWith(localVariableDeclaration); return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if ((localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const) { UnlockWith(localVariableDeclaration); } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object VisitLocalVariableDeclaration(ICSharpCode.NRefactory.Ast.LocalVariableDeclaration localVariableDeclaration, object data) { object result = base.VisitLocalVariableDeclaration(localVariableDeclaration, data); if (localVariableDeclaration.Variables.Count == 0) { RemoveCurrentNode(); } return(result); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if (localVariableDeclaration.TypeReference.ToString().Equals("Thread") || localVariableDeclaration.TypeReference.ToString().Equals("Threading.Thread")) { UnlockWith(localVariableDeclaration); } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { foreach (var vd in localVariableDeclaration.Variables) { if (RenameTable.ContainsKey(vd.Name)) { vd.Name = RenameTable[vd.Name]; } } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
string GetVariableNameFromVariableDeclaration(LocalVariableDeclaration declaration) { if (declaration == null) return null; if (declaration.Variables.Count != 1) return null; VariableDeclaration varDecl = declaration.Variables[0]; if (!varDecl.Initializer.IsNull && // don't offer action for "var a = new Foo()" !(varDecl.Initializer is ObjectCreateExpression)) return varDecl.Name; return null; }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if (localVariableDeclaration.TypeReference.Type.Contains("System.Double") || localVariableDeclaration.TypeReference.Type.Contains("System.Float") || localVariableDeclaration.TypeReference.Type.Contains("System.Decimal")) { foreach (VariableDeclaration variableDeclaration in localVariableDeclaration.Variables) { _doublefloatvariables.Add(variableDeclaration.Name); } } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if (localVariableDeclaration.TypeReference.Type.Equals("Thread") || localVariableDeclaration.TypeReference.Type.Equals("Threading.Thread") || localVariableDeclaration.TypeReference.Type.Equals("System.Threading.Thread")) { foreach (VariableDeclaration variableDeclaration in localVariableDeclaration.Variables) { threadVars.Add(variableDeclaration.Name); } } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object TrackedVisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { string variableName = GetVariableName(arrayCreateExpression); List<Expression> initializerList = arrayCreateExpression.ArrayInitializer.CreateExpressions; Expression replacedExpression = arrayCreateExpression; if (initializerList.Count > 0 && initializerList[0] is CollectionInitializerExpression && data is InsertionBlockData) { ArrayCreateExpression replacedArrayCreateExpression = arrayCreateExpression; replacedArrayCreateExpression.ArrayInitializer = null; replacedArrayCreateExpression.Arguments.Add(new PrimitiveExpression(initializerList.Count, initializerList.Count.ToString())); string arrayTypeName = arrayCreateExpression.CreateType.Type + "s"; Position position = Position.After; if (variableName == null) { variableName = arrayTypeName; position = Position.Before; } List<Statement> initStatements = GetArrayInitStatements(replacedArrayCreateExpression, variableName, initializerList); InsertionBlockData insertionBlockData = (InsertionBlockData) data; insertionBlockData.Block = (BlockStatement) AstUtil.GetParentOfType(replacedArrayCreateExpression, typeof(BlockStatement)); insertionBlockData.BlockChildIndex = GetBlockChildIndex(replacedArrayCreateExpression, position); insertionBlockData.Statements = initStatements; if (variableName == arrayTypeName) { IdentifierExpression identifierExpression = new IdentifierExpression(variableName); replacedExpression = identifierExpression; VariableDeclaration variableDeclaration = new VariableDeclaration(variableName, arrayCreateExpression); LocalVariableDeclaration localVariable = new LocalVariableDeclaration(variableDeclaration); localVariable.TypeReference = arrayCreateExpression.CreateType; initStatements.Insert(0, localVariable); } ReplaceCurrentNode(replacedExpression); } return base.TrackedVisitArrayCreateExpression(arrayCreateExpression, data); }
public override object VisitLocalVariableDeclaration(ICSharpCode.NRefactory.Ast.LocalVariableDeclaration localVariableDeclaration, object data) { if (localVariableDeclaration.TypeReference.ToString().Equals("System.Char")) { foreach (VariableDeclaration declaration in localVariableDeclaration.Variables) { if (declaration.Initializer is PrimitiveExpression) { PrimitiveExpression prim = (PrimitiveExpression)declaration.Initializer; var regex = new Regex("\\\\.{1}"); if (regex.IsMatch(prim.StringValue)) { UnlockWith(localVariableDeclaration); } } } } return(base.VisitLocalVariableDeclaration(localVariableDeclaration, data)); }
void LocalDeclarationStatement( #line 2724 "VBNET.ATG" out Statement statement) { #line 2726 "VBNET.ATG" ModifierList m = new ModifierList(); LocalVariableDeclaration localVariableDeclaration; bool dimfound = false; while (la.kind == 75 || la.kind == 92 || la.kind == 189) { if (la.kind == 75) { lexer.NextToken(); #line 2732 "VBNET.ATG" m.Add(Modifiers.Const, t.Location); } else if (la.kind == 189) { lexer.NextToken(); #line 2733 "VBNET.ATG" m.Add(Modifiers.Static, t.Location); } else { lexer.NextToken(); #line 2734 "VBNET.ATG" dimfound = true; } } #line 2737 "VBNET.ATG" if(dimfound && (m.Modifier & Modifiers.Const) != 0) { Error("Dim is not allowed on constants."); } if(m.isNone && dimfound == false) { Error("Const, Dim or Static expected"); } localVariableDeclaration = new LocalVariableDeclaration(m.Modifier); localVariableDeclaration.StartLocation = t.Location; VariableDeclarator( #line 2748 "VBNET.ATG" localVariableDeclaration.Variables); while (la.kind == 12) { lexer.NextToken(); VariableDeclarator( #line 2749 "VBNET.ATG" localVariableDeclaration.Variables); } #line 2751 "VBNET.ATG" statement = localVariableDeclaration; }
void EmbeddedStatement( #line 2755 "VBNET.ATG" out Statement statement) { #line 2757 "VBNET.ATG" Statement embeddedStatement = null; statement = null; Expression expr = null; string name = String.Empty; List<Expression> p = null; if (la.kind == 107) { lexer.NextToken(); #line 2763 "VBNET.ATG" ExitType exitType = ExitType.None; switch (la.kind) { case 195: { lexer.NextToken(); #line 2765 "VBNET.ATG" exitType = ExitType.Sub; break; } case 114: { lexer.NextToken(); #line 2767 "VBNET.ATG" exitType = ExitType.Function; break; } case 171: { lexer.NextToken(); #line 2769 "VBNET.ATG" exitType = ExitType.Property; break; } case 95: { lexer.NextToken(); #line 2771 "VBNET.ATG" exitType = ExitType.Do; break; } case 111: { lexer.NextToken(); #line 2773 "VBNET.ATG" exitType = ExitType.For; break; } case 203: { lexer.NextToken(); #line 2775 "VBNET.ATG" exitType = ExitType.Try; break; } case 216: { lexer.NextToken(); #line 2777 "VBNET.ATG" exitType = ExitType.While; break; } case 182: { lexer.NextToken(); #line 2779 "VBNET.ATG" exitType = ExitType.Select; break; } default: SynErr(273); break; } #line 2781 "VBNET.ATG" statement = new ExitStatement(exitType); } else if (la.kind == 203) { TryStatement( #line 2782 "VBNET.ATG" out statement); } else if (la.kind == 76) { lexer.NextToken(); #line 2783 "VBNET.ATG" ContinueType continueType = ContinueType.None; if (la.kind == 95 || la.kind == 111 || la.kind == 216) { if (la.kind == 95) { lexer.NextToken(); #line 2783 "VBNET.ATG" continueType = ContinueType.Do; } else if (la.kind == 111) { lexer.NextToken(); #line 2783 "VBNET.ATG" continueType = ContinueType.For; } else { lexer.NextToken(); #line 2783 "VBNET.ATG" continueType = ContinueType.While; } } #line 2783 "VBNET.ATG" statement = new ContinueStatement(continueType); } else if (la.kind == 200) { lexer.NextToken(); if (StartOf(29)) { Expr( #line 2785 "VBNET.ATG" out expr); } #line 2785 "VBNET.ATG" statement = new ThrowStatement(expr); } else if (la.kind == 180) { lexer.NextToken(); if (StartOf(29)) { Expr( #line 2787 "VBNET.ATG" out expr); } #line 2787 "VBNET.ATG" statement = new ReturnStatement(expr); } else if (la.kind == 196) { lexer.NextToken(); Expr( #line 2789 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2789 "VBNET.ATG" out embeddedStatement); Expect(100); Expect(196); #line 2790 "VBNET.ATG" statement = new LockStatement(expr, embeddedStatement); } else if (la.kind == 174) { lexer.NextToken(); Identifier(); #line 2792 "VBNET.ATG" name = t.val; if (la.kind == 25) { lexer.NextToken(); if (StartOf(37)) { ArgumentList( #line 2793 "VBNET.ATG" out p); } Expect(26); } #line 2795 "VBNET.ATG" statement = new RaiseEventStatement(name, p); } else if (la.kind == 218) { WithStatement( #line 2798 "VBNET.ATG" out statement); } else if (la.kind == 43) { lexer.NextToken(); #line 2800 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2801 "VBNET.ATG" out expr); Expect(12); Expr( #line 2801 "VBNET.ATG" out handlerExpr); #line 2803 "VBNET.ATG" statement = new AddHandlerStatement(expr, handlerExpr); } else if (la.kind == 178) { lexer.NextToken(); #line 2806 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2807 "VBNET.ATG" out expr); Expect(12); Expr( #line 2807 "VBNET.ATG" out handlerExpr); #line 2809 "VBNET.ATG" statement = new RemoveHandlerStatement(expr, handlerExpr); } else if (la.kind == 216) { lexer.NextToken(); Expr( #line 2812 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2813 "VBNET.ATG" out embeddedStatement); Expect(100); Expect(216); #line 2815 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); } else if (la.kind == 95) { lexer.NextToken(); #line 2820 "VBNET.ATG" ConditionType conditionType = ConditionType.None; if (la.kind == 209 || la.kind == 216) { WhileOrUntil( #line 2823 "VBNET.ATG" out conditionType); Expr( #line 2823 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2824 "VBNET.ATG" out embeddedStatement); Expect(138); #line 2827 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, ConditionPosition.Start); } else if (la.kind == 1 || la.kind == 11) { EndOfStmt(); Block( #line 2834 "VBNET.ATG" out embeddedStatement); Expect(138); if (la.kind == 209 || la.kind == 216) { WhileOrUntil( #line 2835 "VBNET.ATG" out conditionType); Expr( #line 2835 "VBNET.ATG" out expr); } #line 2837 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); } else SynErr(274); } else if (la.kind == 111) { lexer.NextToken(); #line 2842 "VBNET.ATG" Expression group = null; TypeReference typeReference; string typeName; Location startLocation = t.Location; if (la.kind == 97) { lexer.NextToken(); LoopControlVariable( #line 2849 "VBNET.ATG" out typeReference, out typeName); Expect(125); Expr( #line 2850 "VBNET.ATG" out group); EndOfStmt(); Block( #line 2851 "VBNET.ATG" out embeddedStatement); Expect(149); if (StartOf(29)) { Expr( #line 2852 "VBNET.ATG" out expr); } #line 2854 "VBNET.ATG" statement = new ForeachStatement(typeReference, typeName, group, embeddedStatement, expr); statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } else if (StartOf(38)) { #line 2865 "VBNET.ATG" Expression start = null; Expression end = null; Expression step = null; Expression variableExpr = null; Expression nextExpr = null; List<Expression> nextExpressions = null; if ( #line 2872 "VBNET.ATG" IsLoopVariableDeclaration()) { LoopControlVariable( #line 2873 "VBNET.ATG" out typeReference, out typeName); } else { #line 2875 "VBNET.ATG" typeReference = null; typeName = null; SimpleExpr( #line 2876 "VBNET.ATG" out variableExpr); } Expect(10); Expr( #line 2878 "VBNET.ATG" out start); Expect(201); Expr( #line 2878 "VBNET.ATG" out end); if (la.kind == 190) { lexer.NextToken(); Expr( #line 2878 "VBNET.ATG" out step); } EndOfStmt(); Block( #line 2879 "VBNET.ATG" out embeddedStatement); Expect(149); if (StartOf(29)) { Expr( #line 2882 "VBNET.ATG" out nextExpr); #line 2884 "VBNET.ATG" nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); while (la.kind == 12) { lexer.NextToken(); Expr( #line 2887 "VBNET.ATG" out nextExpr); #line 2887 "VBNET.ATG" nextExpressions.Add(nextExpr); } } #line 2890 "VBNET.ATG" statement = new ForNextStatement { TypeReference = typeReference, VariableName = typeName, LoopVariableExpression = variableExpr, Start = start, End = end, Step = step, EmbeddedStatement = embeddedStatement, NextExpressions = nextExpressions }; } else SynErr(275); } else if (la.kind == 105) { lexer.NextToken(); Expr( #line 2903 "VBNET.ATG" out expr); #line 2903 "VBNET.ATG" statement = new ErrorStatement(expr); } else if (la.kind == 176) { lexer.NextToken(); #line 2905 "VBNET.ATG" bool isPreserve = false; if (la.kind == 169) { lexer.NextToken(); #line 2905 "VBNET.ATG" isPreserve = true; } ReDimClause( #line 2906 "VBNET.ATG" out expr); #line 2908 "VBNET.ATG" ReDimStatement reDimStatement = new ReDimStatement(isPreserve); statement = reDimStatement; SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); while (la.kind == 12) { lexer.NextToken(); ReDimClause( #line 2912 "VBNET.ATG" out expr); #line 2913 "VBNET.ATG" SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); } } else if (la.kind == 104) { lexer.NextToken(); Expr( #line 2917 "VBNET.ATG" out expr); #line 2919 "VBNET.ATG" EraseStatement eraseStatement = new EraseStatement(); if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr);} while (la.kind == 12) { lexer.NextToken(); Expr( #line 2922 "VBNET.ATG" out expr); #line 2922 "VBNET.ATG" if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr); } } #line 2923 "VBNET.ATG" statement = eraseStatement; } else if (la.kind == 191) { lexer.NextToken(); #line 2925 "VBNET.ATG" statement = new StopStatement(); } else if ( #line 2927 "VBNET.ATG" la.kind == Tokens.If) { Expect(122); #line 2928 "VBNET.ATG" Location ifStartLocation = t.Location; Expr( #line 2928 "VBNET.ATG" out expr); if (la.kind == 199) { lexer.NextToken(); } if (la.kind == 1 || la.kind == 11) { EndOfStmt(); Block( #line 2931 "VBNET.ATG" out embeddedStatement); #line 2933 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement); ifStatement.StartLocation = ifStartLocation; Location elseIfStart; while (la.kind == 99 || #line 2939 "VBNET.ATG" IsElseIf()) { if ( #line 2939 "VBNET.ATG" IsElseIf()) { Expect(98); #line 2939 "VBNET.ATG" elseIfStart = t.Location; Expect(122); } else { lexer.NextToken(); #line 2940 "VBNET.ATG" elseIfStart = t.Location; } #line 2942 "VBNET.ATG" Expression condition = null; Statement block = null; Expr( #line 2943 "VBNET.ATG" out condition); if (la.kind == 199) { lexer.NextToken(); } EndOfStmt(); Block( #line 2944 "VBNET.ATG" out block); #line 2946 "VBNET.ATG" ElseIfSection elseIfSection = new ElseIfSection(condition, block); elseIfSection.StartLocation = elseIfStart; elseIfSection.EndLocation = t.Location; elseIfSection.Parent = ifStatement; ifStatement.ElseIfSections.Add(elseIfSection); } if (la.kind == 98) { lexer.NextToken(); EndOfStmt(); Block( #line 2955 "VBNET.ATG" out embeddedStatement); #line 2957 "VBNET.ATG" ifStatement.FalseStatement.Add(embeddedStatement); } Expect(100); Expect(122); #line 2961 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else if (StartOf(39)) { #line 2966 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr); ifStatement.StartLocation = ifStartLocation; SingleLineStatementList( #line 2969 "VBNET.ATG" ifStatement.TrueStatement); if (la.kind == 98) { lexer.NextToken(); if (StartOf(39)) { SingleLineStatementList( #line 2972 "VBNET.ATG" ifStatement.FalseStatement); } } #line 2974 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else SynErr(276); } else if (la.kind == 182) { lexer.NextToken(); if (la.kind == 61) { lexer.NextToken(); } Expr( #line 2977 "VBNET.ATG" out expr); EndOfStmt(); #line 2978 "VBNET.ATG" List<SwitchSection> selectSections = new List<SwitchSection>(); Statement block = null; while (la.kind == 61) { #line 2982 "VBNET.ATG" List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; lexer.NextToken(); CaseClauses( #line 2983 "VBNET.ATG" out caseClauses); if ( #line 2983 "VBNET.ATG" IsNotStatementSeparator()) { lexer.NextToken(); } EndOfStmt(); #line 2985 "VBNET.ATG" SwitchSection selectSection = new SwitchSection(caseClauses); selectSection.StartLocation = caseLocation; Block( #line 2988 "VBNET.ATG" out block); #line 2990 "VBNET.ATG" selectSection.Children = block.Children; selectSection.EndLocation = t.EndLocation; selectSections.Add(selectSection); } #line 2996 "VBNET.ATG" statement = new SwitchStatement(expr, selectSections); Expect(100); Expect(182); } else if (la.kind == 157) { #line 2999 "VBNET.ATG" OnErrorStatement onErrorStatement = null; OnErrorStatement( #line 3000 "VBNET.ATG" out onErrorStatement); #line 3000 "VBNET.ATG" statement = onErrorStatement; } else if (la.kind == 119) { #line 3001 "VBNET.ATG" GotoStatement goToStatement = null; GotoStatement( #line 3002 "VBNET.ATG" out goToStatement); #line 3002 "VBNET.ATG" statement = goToStatement; } else if (la.kind == 179) { #line 3003 "VBNET.ATG" ResumeStatement resumeStatement = null; ResumeStatement( #line 3004 "VBNET.ATG" out resumeStatement); #line 3004 "VBNET.ATG" statement = resumeStatement; } else if (StartOf(38)) { #line 3007 "VBNET.ATG" Expression val = null; AssignmentOperatorType op; bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || la.kind == Tokens.Not || la.kind == Tokens.Times; SimpleExpr( #line 3013 "VBNET.ATG" out expr); if (StartOf(40)) { AssignmentOperator( #line 3015 "VBNET.ATG" out op); Expr( #line 3015 "VBNET.ATG" out val); #line 3015 "VBNET.ATG" expr = new AssignmentExpression(expr, op, val); } else if (la.kind == 1 || la.kind == 11 || la.kind == 98) { #line 3016 "VBNET.ATG" if (mustBeAssignment) Error("error in assignment."); } else SynErr(277); #line 3019 "VBNET.ATG" // a field reference expression that stands alone is a // invocation expression without parantheses and arguments if(expr is MemberReferenceExpression || expr is IdentifierExpression) { expr = new InvocationExpression(expr); } statement = new ExpressionStatement(expr); } else if (la.kind == 60) { lexer.NextToken(); SimpleExpr( #line 3026 "VBNET.ATG" out expr); #line 3026 "VBNET.ATG" statement = new ExpressionStatement(expr); } else if (la.kind == 211) { lexer.NextToken(); #line 3028 "VBNET.ATG" Statement block; if ( #line 3029 "VBNET.ATG" Peek(1).kind == Tokens.As) { #line 3030 "VBNET.ATG" LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); VariableDeclarator( #line 3031 "VBNET.ATG" resourceAquisition.Variables); while (la.kind == 12) { lexer.NextToken(); VariableDeclarator( #line 3033 "VBNET.ATG" resourceAquisition.Variables); } Block( #line 3035 "VBNET.ATG" out block); #line 3037 "VBNET.ATG" statement = new UsingStatement(resourceAquisition, block); } else if (StartOf(29)) { Expr( #line 3039 "VBNET.ATG" out expr); Block( #line 3040 "VBNET.ATG" out block); #line 3041 "VBNET.ATG" statement = new UsingStatement(new ExpressionStatement(expr), block); } else SynErr(278); Expect(100); Expect(211); } else if (StartOf(41)) { LocalDeclarationStatement( #line 3044 "VBNET.ATG" out statement); } else SynErr(279); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) { VariableDeclaration varDecl = (VariableDeclaration)localVariableDeclaration.Variables[i]; AddVariable(localVariableDeclaration.GetTypeForVariable(i), varDecl.Name, localVariableDeclaration.StartLocation, CurrentEndLocation, (localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const, false, varDecl.Initializer, null, false, localVariableDeclaration.SemicolonPosition); } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { return base.TrackedVisitLocalVariableDeclaration(localVariableDeclaration, localVariableDeclaration); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if (localVariableDeclaration.TypeReference.Type == "var") localVariableDeclaration.TypeReference = TypeReference.Null; return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { localVariableDeclarations.Add(localVariableDeclaration); return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { if (this.CheckNode(localVariableDeclaration)) { return null; } return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
public override List<Change> PerformChanges (RefactoringOptions options, object prop) { List<Change> result = new List<Change> (); ExtractMethodParameters param = (ExtractMethodParameters)prop; TextEditorData data = options.GetTextEditorData (); INRefactoryASTProvider provider = options.GetASTProvider (); IResolver resolver = options.GetResolver (); ICSharpCode.NRefactory.Ast.INode node = Analyze (options, param, false); if (param.VariablesToGenerate.Count > 0) { TextReplaceChange varGen = new TextReplaceChange (); varGen.Description = GettextCatalog.GetString ("Generate some temporary variables"); varGen.FileName = options.Document.FileName; LineSegment line = data.Document.GetLine (Math.Max (0, data.Document.OffsetToLineNumber (data.SelectionRange.Offset) - 1)); varGen.Offset = line.Offset + line.EditableLength; varGen.InsertedText = Environment.NewLine + options.GetWhitespaces (line.Offset); foreach (VariableDescriptor var in param.VariablesToGenerate) { TypeReference tr = options.ShortenTypeName (var.ReturnType).ConvertToTypeReference (); varGen.InsertedText += provider.OutputNode (options.Dom, new LocalVariableDeclaration (new VariableDeclaration (var.Name, null, tr))).Trim (); } result.Add (varGen); } InvocationExpression invocation = new InvocationExpression (new IdentifierExpression (param.Name)); foreach (VariableDescriptor var in param.Parameters) { if (!param.OneChangedVariable && param.ChangedVariables.Contains (var.Name)) { FieldDirection fieldDirection = FieldDirection.Ref; VariableDescriptor outsideVar = null; if (param.VariablesOutside.TryGetValue (var.Name, out outsideVar) && (var.GetsAssigned || param.VariablesToGenerate.Where (v => v.Name == var.Name).Any ())) { if (!outsideVar.GetsAssigned) fieldDirection = FieldDirection.Out; } invocation.Arguments.Add (new DirectionExpression (fieldDirection, new IdentifierExpression (var.Name))); } else { invocation.Arguments.Add (new IdentifierExpression (var.Name)); } } // string mimeType = DesktopService.GetMimeTypeForUri (options.Document.FileName); TypeReference returnType = new TypeReference ("System.Void", true); ICSharpCode.NRefactory.Ast.INode outputNode; if (param.OneChangedVariable) { string name = param.ChangedVariables.First (); returnType = options.ShortenTypeName (param.Variables.Find (v => v.Name == name).ReturnType).ConvertToTypeReference (); if (param.OutsideVariableList.Any (v => v.Name == name && !v.IsDefined)) { LocalVariableDeclaration varDecl = new LocalVariableDeclaration (returnType); varDecl.Variables.Add (new VariableDeclaration (name, invocation)); outputNode = varDecl; } else { outputNode = new ExpressionStatement (new AssignmentExpression (new IdentifierExpression (name), ICSharpCode.NRefactory.Ast.AssignmentOperatorType.Assign, invocation)); } } else { outputNode = node is BlockStatement ? (ICSharpCode.NRefactory.Ast.INode)new ExpressionStatement (invocation) : invocation; } TextReplaceChange replacement = new TextReplaceChange (); replacement.Description = string.Format (GettextCatalog.GetString ("Substitute selected statement(s) with call to {0}"), param.Name); replacement.FileName = options.Document.FileName; replacement.Offset = options.Document.Editor.SelectionRange.Offset; replacement.RemovedChars = options.Document.Editor.SelectionRange.Length; replacement.MoveCaretToReplace = true; LineSegment line1 = data.Document.GetLineByOffset (options.Document.Editor.SelectionRange.EndOffset); if (options.Document.Editor.SelectionRange.EndOffset == line1.Offset) { if (line1.Offset > 0) { LineSegment line2 = data.Document.GetLineByOffset (line1.Offset - 1); replacement.RemovedChars -= line2.DelimiterLength; } } replacement.InsertedText = options.GetWhitespaces (options.Document.Editor.SelectionRange.Offset) + provider.OutputNode (options.Dom, outputNode).Trim (); result.Add (replacement); TextReplaceChange insertNewMethod = new TextReplaceChange (); insertNewMethod.FileName = options.Document.FileName; insertNewMethod.Description = string.Format (GettextCatalog.GetString ("Create new method {0} from selected statement(s)"), param.Name); insertNewMethod.RemovedChars = param.InsertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : param.InsertionPoint.Location.Column; insertNewMethod.Offset = data.Document.LocationToOffset (param.InsertionPoint.Location) - insertNewMethod.RemovedChars; ExtractMethodAstTransformer transformer = new ExtractMethodAstTransformer (param.VariablesToGenerate); node.AcceptVisitor (transformer, null); if (!param.OneChangedVariable && node is Expression) { ResolveResult resolveResult = resolver.Resolve (new ExpressionResult ("(" + provider.OutputNode (options.Dom, node) + ")"), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column)); if (resolveResult.ResolvedType != null) returnType = options.ShortenTypeName (resolveResult.ResolvedType).ConvertToTypeReference (); } MethodDeclaration methodDecl = new MethodDeclaration (); methodDecl.Name = param.Name; methodDecl.Modifier = param.Modifiers; methodDecl.TypeReference = returnType; if (!param.ReferencesMember) methodDecl.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Static; if (node is BlockStatement) { methodDecl.Body = new BlockStatement (); methodDecl.Body.AddChild (new EmptyStatement ()); if (param.OneChangedVariable) methodDecl.Body.AddChild (new ReturnStatement (new IdentifierExpression (param.ChangedVariables.First ()))); } else if (node is Expression) { methodDecl.Body = new BlockStatement (); methodDecl.Body.AddChild (new ReturnStatement (node as Expression)); } foreach (VariableDescriptor var in param.VariablesToDefine) { BlockStatement block = methodDecl.Body; LocalVariableDeclaration varDecl = new LocalVariableDeclaration (options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ()); varDecl.Variables.Add (new VariableDeclaration (var.Name)); block.Children.Insert (0, varDecl); } foreach (VariableDescriptor var in param.Parameters) { TypeReference typeReference = options.ShortenTypeName (var.ReturnType).ConvertToTypeReference (); ParameterDeclarationExpression pde = new ParameterDeclarationExpression (typeReference, var.Name); if (!param.OneChangedVariable) { if (param.ChangedVariables.Contains (var.Name)) pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Ref; if (param.VariablesToGenerate.Where (v => v.Name == var.Name).Any ()) { pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Out; } VariableDescriptor outsideVar = null; if (var.GetsAssigned && param.VariablesOutside.TryGetValue (var.Name, out outsideVar)) { if (!outsideVar.GetsAssigned) pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Out; } } methodDecl.Parameters.Add (pde); } string indent = options.GetIndent (param.DeclaringMember); StringBuilder methodText = new StringBuilder (); switch (param.InsertionPoint.LineBefore) { case NewLineInsertion.Eol: methodText.AppendLine (); break; case NewLineInsertion.BlankLine: methodText.Append (indent); methodText.AppendLine (); break; } if (param.GenerateComment) { methodText.Append (indent); methodText.AppendLine ("/// <summary>"); methodText.Append (indent); methodText.AppendLine ("/// TODO: write a comment."); methodText.Append (indent); methodText.AppendLine ("/// </summary>"); Ambience ambience = AmbienceService.GetAmbienceForFile (options.Document.FileName); foreach (ParameterDeclarationExpression pde in methodDecl.Parameters) { methodText.Append (indent); methodText.Append ("/// <param name=\""); methodText.Append (pde.ParameterName); methodText.Append ("\"> A "); methodText.Append (ambience.GetString (pde.TypeReference.ConvertToReturnType (), OutputFlags.IncludeGenerics | OutputFlags.UseFullName)); methodText.Append (" </param>"); methodText.AppendLine (); } if (methodDecl.TypeReference.Type != "System.Void") { methodText.Append (indent); methodText.AppendLine ("/// <returns>"); methodText.Append (indent); methodText.Append ("/// A "); methodText.AppendLine (ambience.GetString (methodDecl.TypeReference.ConvertToReturnType (), OutputFlags.IncludeGenerics | OutputFlags.UseFullName)); methodText.Append (indent); methodText.AppendLine ("/// </returns>"); } } methodText.Append (indent); if (node is BlockStatement) { string text = provider.OutputNode (options.Dom, methodDecl, indent).Trim (); int emptyStatementMarker = text.LastIndexOf (';'); if (param.OneChangedVariable) emptyStatementMarker = text.LastIndexOf (';', emptyStatementMarker - 1); StringBuilder sb = new StringBuilder (); sb.Append (text.Substring (0, emptyStatementMarker)); sb.Append (AddIndent (param.Text, indent + "\t")); sb.Append (text.Substring (emptyStatementMarker + 1)); methodText.Append (sb.ToString ()); } else { methodText.Append (provider.OutputNode (options.Dom, methodDecl, options.GetIndent (param.DeclaringMember)).Trim ()); } switch (param.InsertionPoint.LineAfter) { case NewLineInsertion.Eol: methodText.AppendLine (); break; case NewLineInsertion.BlankLine: methodText.AppendLine (); methodText.AppendLine (); methodText.Append (indent); break; } insertNewMethod.InsertedText = methodText.ToString (); result.Add (insertNewMethod); return result; }
static Ast.INode TransformByteCode_Internal(MethodDefinition methodDef, ILExpression byteCode, List<Ast.Expression> args) { // throw new NotImplementedException(); OpCode opCode = byteCode.OpCode; object operand = byteCode.Operand; Ast.TypeReference operandAsTypeRef = operand is Cecil.TypeReference ? new Ast.TypeReference(((Cecil.TypeReference)operand).FullName) : null; ILExpression operandAsByteCode = operand as ILExpression; Ast.Expression arg1 = args.Count >= 1 ? args[0] : null; Ast.Expression arg2 = args.Count >= 2 ? args[1] : null; Ast.Expression arg3 = args.Count >= 3 ? args[2] : null; Ast.Statement branchCommand = null; if (byteCode.Operand is ILLabel) { branchCommand = new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name); } switch(opCode.Code) { #region Arithmetic case Code.Add: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2); case Code.Add_Ovf: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2); case Code.Add_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2); case Code.Div: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2); case Code.Div_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2); case Code.Mul: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2); case Code.Mul_Ovf: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2); case Code.Mul_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2); case Code.Rem: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2); case Code.Rem_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2); case Code.Sub: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2); case Code.Sub_Ovf: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2); case Code.Sub_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2); case Code.And: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.BitwiseAnd, arg2); case Code.Xor: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ExclusiveOr, arg2); case Code.Shl: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftLeft, arg2); case Code.Shr: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2); case Code.Shr_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2); case Code.Neg: return new Ast.UnaryOperatorExpression(arg1, UnaryOperatorType.Minus); case Code.Not: return new Ast.UnaryOperatorExpression(arg1, UnaryOperatorType.BitNot); #endregion #region Arrays case Code.Newarr: operandAsTypeRef.RankSpecifier = new int[] {0}; return new Ast.ArrayCreateExpression(operandAsTypeRef, new List<Expression>(new Expression[] {arg1})); case Code.Ldlen: return new Ast.MemberReferenceExpression(arg1, "Length"); case Code.Ldelem_I: case Code.Ldelem_I1: case Code.Ldelem_I2: case Code.Ldelem_I4: case Code.Ldelem_I8: case Code.Ldelem_U1: case Code.Ldelem_U2: case Code.Ldelem_U4: case Code.Ldelem_R4: case Code.Ldelem_R8: case Code.Ldelem_Ref: return new Ast.IndexerExpression(arg1, new List<Expression>(new Expression[] {arg2})); case Code.Ldelem_Any: throw new NotImplementedException(); case Code.Ldelema: return new Ast.IndexerExpression(arg1, new List<Expression>(new Expression[] {arg2})); case Code.Stelem_I: case Code.Stelem_I1: case Code.Stelem_I2: case Code.Stelem_I4: case Code.Stelem_I8: case Code.Stelem_R4: case Code.Stelem_R8: case Code.Stelem_Ref: return new Ast.AssignmentExpression(new Ast.IndexerExpression(arg1, new List<Expression>(new Expression[] {arg2})), AssignmentOperatorType.Assign, arg3); case Code.Stelem_Any: throw new NotImplementedException(); #endregion #region Branching case Code.Br: return branchCommand; case Code.Brfalse: return new Ast.IfElseStatement(new Ast.UnaryOperatorExpression(arg1, UnaryOperatorType.Not), branchCommand); case Code.Brtrue: return new Ast.IfElseStatement(arg1, branchCommand); case Code.Beq: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Equality, arg2), branchCommand); case Code.Bge: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThanOrEqual, arg2), branchCommand); case Code.Bge_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThanOrEqual, arg2), branchCommand); case Code.Bgt: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2), branchCommand); case Code.Bgt_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2), branchCommand); case Code.Ble: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThanOrEqual, arg2), branchCommand); case Code.Ble_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThanOrEqual, arg2), branchCommand); case Code.Blt: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2), branchCommand); case Code.Blt_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2), branchCommand); case Code.Bne_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.InEquality, arg2), branchCommand); #endregion #region Comparison case Code.Ceq: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Equality, ConvertIntToBool(arg2)); case Code.Cgt: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2); case Code.Cgt_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2); case Code.Clt: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2); case Code.Clt_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2); #endregion #region Conversions case Code.Conv_I: return new Ast.CastExpression(new Ast.TypeReference(typeof(int).FullName), arg1, CastType.Cast); // TODO case Code.Conv_I1: return new Ast.CastExpression(new Ast.TypeReference(typeof(SByte).FullName), arg1, CastType.Cast); case Code.Conv_I2: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int16).FullName), arg1, CastType.Cast); case Code.Conv_I4: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int32).FullName), arg1, CastType.Cast); case Code.Conv_I8: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int64).FullName), arg1, CastType.Cast); case Code.Conv_U: return new Ast.CastExpression(new Ast.TypeReference(typeof(uint).FullName), arg1, CastType.Cast); // TODO case Code.Conv_U1: return new Ast.CastExpression(new Ast.TypeReference(typeof(Byte).FullName), arg1, CastType.Cast); case Code.Conv_U2: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt16).FullName), arg1, CastType.Cast); case Code.Conv_U4: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt32).FullName), arg1, CastType.Cast); case Code.Conv_U8: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt64).FullName), arg1, CastType.Cast); case Code.Conv_R4: return new Ast.CastExpression(new Ast.TypeReference(typeof(float).FullName), arg1, CastType.Cast); case Code.Conv_R8: return new Ast.CastExpression(new Ast.TypeReference(typeof(double).FullName), arg1, CastType.Cast); case Code.Conv_R_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(double).FullName), arg1, CastType.Cast); // TODO case Code.Conv_Ovf_I: return new Ast.CastExpression(new Ast.TypeReference(typeof(int).FullName), arg1, CastType.Cast); // TODO case Code.Conv_Ovf_I1: return new Ast.CastExpression(new Ast.TypeReference(typeof(SByte).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_I2: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int16).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_I4: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int32).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_I8: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int64).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U: return new Ast.CastExpression(new Ast.TypeReference(typeof(uint).FullName), arg1, CastType.Cast); // TODO case Code.Conv_Ovf_U1: return new Ast.CastExpression(new Ast.TypeReference(typeof(Byte).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U2: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt16).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U4: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt32).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U8: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt64).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_I_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(int).FullName), arg1, CastType.Cast); // TODO case Code.Conv_Ovf_I1_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(SByte).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_I2_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int16).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_I4_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int32).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_I8_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(Int64).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(uint).FullName), arg1, CastType.Cast); // TODO case Code.Conv_Ovf_U1_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(Byte).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U2_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt16).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U4_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt32).FullName), arg1, CastType.Cast); case Code.Conv_Ovf_U8_Un: return new Ast.CastExpression(new Ast.TypeReference(typeof(UInt64).FullName), arg1, CastType.Cast); #endregion #region Indirect case Code.Ldind_I: throw new NotImplementedException(); case Code.Ldind_I1: throw new NotImplementedException(); case Code.Ldind_I2: throw new NotImplementedException(); case Code.Ldind_I4: throw new NotImplementedException(); case Code.Ldind_I8: throw new NotImplementedException(); case Code.Ldind_U1: throw new NotImplementedException(); case Code.Ldind_U2: throw new NotImplementedException(); case Code.Ldind_U4: throw new NotImplementedException(); case Code.Ldind_R4: throw new NotImplementedException(); case Code.Ldind_R8: throw new NotImplementedException(); case Code.Ldind_Ref: throw new NotImplementedException(); case Code.Stind_I: throw new NotImplementedException(); case Code.Stind_I1: throw new NotImplementedException(); case Code.Stind_I2: throw new NotImplementedException(); case Code.Stind_I4: throw new NotImplementedException(); case Code.Stind_I8: throw new NotImplementedException(); case Code.Stind_R4: throw new NotImplementedException(); case Code.Stind_R8: throw new NotImplementedException(); case Code.Stind_Ref: throw new NotImplementedException(); #endregion case Code.Arglist: throw new NotImplementedException(); case Code.Box: throw new NotImplementedException(); case Code.Break: throw new NotImplementedException(); case Code.Call: case Code.Callvirt: // TODO: Diferentiate vitual and non-vitual dispach Cecil.MethodReference cecilMethod = ((MethodReference)operand); Ast.Expression target; List<Ast.Expression> methodArgs = new List<Ast.Expression>(args); if (cecilMethod.HasThis) { target = methodArgs[0]; methodArgs.RemoveAt(0); } else { target = new Ast.IdentifierExpression(cecilMethod.DeclaringType.FullName); } // TODO: Constructors are ignored if (cecilMethod.Name == ".ctor") { return MakeComment("// Constructor"); } // TODO: Hack, detect properties properly if (cecilMethod.Name.StartsWith("get_")) { return new Ast.MemberReferenceExpression(target, cecilMethod.Name.Remove(0, 4)); } else if (cecilMethod.Name.StartsWith("set_")) { return new Ast.AssignmentExpression( new Ast.MemberReferenceExpression(target, cecilMethod.Name.Remove(0, 4)), AssignmentOperatorType.Assign, methodArgs[0] ); } // Multi-dimensional array acces // TODO: do properly if (cecilMethod.Name == "Get") { return new Ast.IndexerExpression(target, methodArgs); } else if (cecilMethod.Name == "Set") { Expression val = methodArgs[methodArgs.Count - 1]; methodArgs.RemoveAt(methodArgs.Count - 1); return new Ast.AssignmentExpression( new Ast.IndexerExpression(target, methodArgs), AssignmentOperatorType.Assign, Convert(val, ((Cecil.ArrayType)target.UserData["Type"]).ElementType) ); } // Default invocation return new Ast.InvocationExpression( new Ast.MemberReferenceExpression(target, cecilMethod.Name), methodArgs ); case Code.Calli: throw new NotImplementedException(); case Code.Castclass: return new Ast.CastExpression(operandAsTypeRef, arg1, CastType.Cast); case Code.Ckfinite: throw new NotImplementedException(); case Code.Constrained: throw new NotImplementedException(); case Code.Cpblk: throw new NotImplementedException(); case Code.Cpobj: throw new NotImplementedException(); case Code.Dup: return arg1; case Code.Endfilter: throw new NotImplementedException(); case Code.Endfinally: return null; case Code.Initblk: throw new NotImplementedException(); case Code.Initobj: throw new NotImplementedException(); case Code.Isinst: return new Ast.TypeOfIsExpression(arg1, new Ast.TypeReference(((Cecil.TypeReference)operand).FullName)); case Code.Jmp: throw new NotImplementedException(); case Code.Ldarg: if (methodDef.HasThis && ((ParameterDefinition)operand).Index < 0) { return new Ast.ThisReferenceExpression(); } else { return new Ast.IdentifierExpression(((ParameterDefinition)operand).Name); } case Code.Ldarga: throw new NotImplementedException(); case Code.Ldc_I4: case Code.Ldc_I8: case Code.Ldc_R4: case Code.Ldc_R8: return new Ast.PrimitiveExpression(operand, null); case Code.Ldfld: case Code.Ldsfld: { if (operand is FieldDefinition) { FieldDefinition field = (FieldDefinition) operand; if (field.IsStatic) { return new Ast.MemberReferenceExpression( new Ast.IdentifierExpression(field.DeclaringType.FullName), field.Name ); } else { return new Ast.MemberReferenceExpression(arg1, field.Name); } } else { // TODO: Static accesses return new Ast.MemberReferenceExpression(arg1, ((FieldReference)operand).Name); } } case Code.Stfld: case Code.Stsfld: { FieldDefinition field = (FieldDefinition) operand; if (field.IsStatic) { return new AssignmentExpression( new Ast.MemberReferenceExpression( new Ast.IdentifierExpression(field.DeclaringType.FullName), field.Name ), AssignmentOperatorType.Assign, arg1 ); } else { return new AssignmentExpression( new Ast.MemberReferenceExpression(arg1, field.Name), AssignmentOperatorType.Assign, arg2 ); } } case Code.Ldflda: case Code.Ldsflda: throw new NotImplementedException(); case Code.Ldftn: throw new NotImplementedException(); case Code.Ldloc: if (operand is ILStackVariable) { return new Ast.IdentifierExpression(((ILStackVariable)operand).Name); } else { return new Ast.IdentifierExpression(((VariableDefinition)operand).Name); } case Code.Ldloca: throw new NotImplementedException(); case Code.Ldnull: return new Ast.PrimitiveExpression(null, null); case Code.Ldobj: throw new NotImplementedException(); case Code.Ldstr: return new Ast.PrimitiveExpression(operand, null); case Code.Ldtoken: if (operand is Cecil.TypeReference) { return new Ast.MemberReferenceExpression( new Ast.TypeOfExpression(operandAsTypeRef), "TypeHandle" ); } else { throw new NotImplementedException(); } case Code.Ldvirtftn: throw new NotImplementedException(); case Code.Leave: return null; case Code.Localloc: throw new NotImplementedException(); case Code.Mkrefany: throw new NotImplementedException(); case Code.Newobj: Cecil.TypeReference declaringType = ((MethodReference)operand).DeclaringType; // TODO: Ensure that the corrent overloaded constructor is called if (declaringType is ArrayType) { return new Ast.ArrayCreateExpression( new Ast.TypeReference(((ArrayType)declaringType).ElementType.FullName, new int[] {}), new List<Expression>(args) ); } return new Ast.ObjectCreateExpression( new Ast.TypeReference(declaringType.FullName), new List<Expression>(args) ); case Code.No: throw new NotImplementedException(); case Code.Nop: return null; case Code.Or: throw new NotImplementedException(); case Code.Pop: return arg1; case Code.Readonly: throw new NotImplementedException(); case Code.Refanytype: throw new NotImplementedException(); case Code.Refanyval: throw new NotImplementedException(); case Code.Ret: { if (methodDef.ReturnType.FullName != Constants.Void) { arg1 = Convert(arg1, methodDef.ReturnType); return new Ast.ReturnStatement(arg1); } else { return new Ast.ReturnStatement(null); } } case Code.Rethrow: return new Ast.ThrowStatement(new IdentifierExpression("exception")); case Code.Sizeof: throw new NotImplementedException(); case Code.Starg: throw new NotImplementedException(); case Code.Stloc: { if (operand is ILStackVariable) { Ast.LocalVariableDeclaration astLocalVar = new Ast.LocalVariableDeclaration(new Ast.VariableDeclaration(((ILStackVariable)operand).Name, arg1)); astLocalVar.TypeReference = new Ast.TypeReference("var"); return astLocalVar; } VariableDefinition locVar = (VariableDefinition)operand; string name = locVar.Name; arg1 = Convert(arg1, locVar.VariableType); if (localVarDefined.ContainsKey(name)) { if (localVarDefined[name]) { return new Ast.AssignmentExpression(new Ast.IdentifierExpression(name), AssignmentOperatorType.Assign, arg1); } else { Ast.LocalVariableDeclaration astLocalVar = new Ast.LocalVariableDeclaration(new Ast.VariableDeclaration(name, arg1)); astLocalVar.TypeReference = new Ast.TypeReference(localVarTypes[name].FullName); localVarDefined[name] = true; return astLocalVar; } } else { return new Ast.AssignmentExpression(new Ast.IdentifierExpression(name), AssignmentOperatorType.Assign, arg1); } } case Code.Stobj: throw new NotImplementedException(); case Code.Switch: throw new NotImplementedException(); case Code.Tail: throw new NotImplementedException(); case Code.Throw: return new Ast.ThrowStatement(arg1); case Code.Unaligned: throw new NotImplementedException(); case Code.Unbox: throw new NotImplementedException(); case Code.Unbox_Any: throw new NotImplementedException(); case Code.Volatile: throw new NotImplementedException(); default: throw new Exception("Unknown OpCode: " + opCode); } }
public override object VisitLocalVariableDeclaration (LocalVariableDeclaration localVariableDeclaration, object data) { // Console.WriteLine ("LocalVariableDeclaration: " + localVariableDeclaration.StartLocation.ToString () + " - " + localVariableDeclaration.EndLocation.ToString ()); localVariableDeclaration.TypeReference.AcceptVisitor (this, data); foreach (VariableDeclaration o in localVariableDeclaration.Variables) { if (o.Name == ((IntegrateTemporaryVariableVisitorOptions)data).GetName ()) { IntegrateTemporaryVariableVisitorOptions options = (IntegrateTemporaryVariableVisitorOptions)data; options.Initializer = localVariableDeclaration.GetVariableDeclaration(((LocalVariable)options.Options.SelectedItem).Name).Initializer; if (localVariableDeclaration.Variables.Count == 1) { TextReplaceChange change = new TextReplaceChange (); change.Description = string.Format (GettextCatalog.GetString ("Deleting local variable declaration {0}"), options.GetName ()); change.FileName = options.Options.Document.FileName; change.Offset = options.Options.Document.Editor.Document.LocationToOffset (localVariableDeclaration.StartLocation.Line + ((LocalVariable)options.Options.SelectedItem).DeclaringMember.BodyRegion.Start.Line, localVariableDeclaration.StartLocation.Column); int end = options.Options.Document.Editor.Document.LocationToOffset (localVariableDeclaration.EndLocation.Line + ((LocalVariable)options.Options.SelectedItem).DeclaringMember.BodyRegion.Start.Line, localVariableDeclaration.EndLocation.Column); change.RemovedChars = end - change.Offset; change.InsertedText = ""; ((IntegrateTemporaryVariableVisitorOptions)data).Changes.Add (change); } else { TextReplaceChange change = new TextReplaceChange (); change.Description = string.Format (GettextCatalog.GetString ("Deleting local variable declaration {0}"), options.GetName ()); change.FileName = options.Options.Document.FileName; change.Offset = options.Options.Document.Editor.Document.LocationToOffset (localVariableDeclaration.StartLocation.Line + ((LocalVariable)options.Options.SelectedItem).DeclaringMember.BodyRegion.Start.Line, localVariableDeclaration.StartLocation.Column); int end = options.Options.Document.Editor.Document.LocationToOffset (localVariableDeclaration.EndLocation.Line + ((LocalVariable)options.Options.SelectedItem).DeclaringMember.BodyRegion.Start.Line, localVariableDeclaration.EndLocation.Column); change.RemovedChars = end - change.Offset; localVariableDeclaration.Variables.Remove (localVariableDeclaration.GetVariableDeclaration (options.GetName ())); INRefactoryASTProvider provider = options.Options.GetASTProvider (); change.InsertedText = options.Options.GetWhitespaces (change.Offset) + provider.OutputNode (options.Options.Dom, localVariableDeclaration); ((IntegrateTemporaryVariableVisitorOptions)data).Changes.Add (change); } } else { o.AcceptVisitor (this, data); } } return null; }
void EmbeddedStatement( //#line 3070 "VBNET.ATG" out Statement statement) { //#line 3072 "VBNET.ATG" Statement embeddedStatement = null; statement = null; Expression expr = null; string name = String.Empty; List<Expression> p = null; Location startLocation = la.Location; if (la.kind == 120) { lexer.NextToken(); //#line 3080 "VBNET.ATG" ExitType exitType = ExitType.None; switch (la.kind) { case 210: { lexer.NextToken(); //#line 3082 "VBNET.ATG" exitType = ExitType.Sub; break; } case 127: { lexer.NextToken(); //#line 3084 "VBNET.ATG" exitType = ExitType.Function; break; } case 186: { lexer.NextToken(); //#line 3086 "VBNET.ATG" exitType = ExitType.Property; break; } case 108: { lexer.NextToken(); //#line 3088 "VBNET.ATG" exitType = ExitType.Do; break; } case 124: { lexer.NextToken(); //#line 3090 "VBNET.ATG" exitType = ExitType.For; break; } case 218: { lexer.NextToken(); //#line 3092 "VBNET.ATG" exitType = ExitType.Try; break; } case 231: { lexer.NextToken(); //#line 3094 "VBNET.ATG" exitType = ExitType.While; break; } case 197: { lexer.NextToken(); //#line 3096 "VBNET.ATG" exitType = ExitType.Select; break; } default: SynErr(298); break; } //#line 3098 "VBNET.ATG" statement = new ExitStatement(exitType); } else if (la.kind == 218) { TryStatement( //#line 3099 "VBNET.ATG" out statement); } else if (la.kind == 89) { lexer.NextToken(); //#line 3100 "VBNET.ATG" ContinueType continueType = ContinueType.None; if (la.kind == 108 || la.kind == 124 || la.kind == 231) { if (la.kind == 108) { lexer.NextToken(); //#line 3100 "VBNET.ATG" continueType = ContinueType.Do; } else if (la.kind == 124) { lexer.NextToken(); //#line 3100 "VBNET.ATG" continueType = ContinueType.For; } else { lexer.NextToken(); //#line 3100 "VBNET.ATG" continueType = ContinueType.While; } } //#line 3100 "VBNET.ATG" statement = new ContinueStatement(continueType); } else if (la.kind == 215) { lexer.NextToken(); if (StartOf(24)) { Expr( //#line 3102 "VBNET.ATG" out expr); } //#line 3102 "VBNET.ATG" statement = new ThrowStatement(expr); } else if (la.kind == 195) { lexer.NextToken(); if (StartOf(24)) { Expr( //#line 3104 "VBNET.ATG" out expr); } //#line 3104 "VBNET.ATG" statement = new ReturnStatement(expr); } else if (la.kind == 211) { lexer.NextToken(); Expr( //#line 3106 "VBNET.ATG" out expr); EndOfStmt(); Block( //#line 3106 "VBNET.ATG" out embeddedStatement); Expect(113); Expect(211); //#line 3107 "VBNET.ATG" statement = new LockStatement(expr, embeddedStatement); } else if (la.kind == 189) { lexer.NextToken(); Identifier(); //#line 3109 "VBNET.ATG" name = t.val; if (la.kind == 37) { lexer.NextToken(); if (StartOf(43)) { ArgumentList( //#line 3110 "VBNET.ATG" out p); } Expect(38); } //#line 3112 "VBNET.ATG" statement = new RaiseEventStatement(name, p); } else if (la.kind == 233) { WithStatement( //#line 3115 "VBNET.ATG" out statement); } else if (la.kind == 56) { lexer.NextToken(); //#line 3117 "VBNET.ATG" Expression handlerExpr = null; Expr( //#line 3118 "VBNET.ATG" out expr); Expect(22); Expr( //#line 3118 "VBNET.ATG" out handlerExpr); //#line 3120 "VBNET.ATG" statement = new AddHandlerStatement(expr, handlerExpr); } else if (la.kind == 193) { lexer.NextToken(); //#line 3123 "VBNET.ATG" Expression handlerExpr = null; Expr( //#line 3124 "VBNET.ATG" out expr); Expect(22); Expr( //#line 3124 "VBNET.ATG" out handlerExpr); //#line 3126 "VBNET.ATG" statement = new RemoveHandlerStatement(expr, handlerExpr); } else if (la.kind == 231) { lexer.NextToken(); Expr( //#line 3129 "VBNET.ATG" out expr); EndOfStmt(); Block( //#line 3130 "VBNET.ATG" out embeddedStatement); Expect(113); Expect(231); //#line 3132 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); } else if (la.kind == 108) { lexer.NextToken(); //#line 3137 "VBNET.ATG" ConditionType conditionType = ConditionType.None; if (la.kind == 224 || la.kind == 231) { WhileOrUntil( //#line 3140 "VBNET.ATG" out conditionType); Expr( //#line 3140 "VBNET.ATG" out expr); EndOfStmt(); Block( //#line 3141 "VBNET.ATG" out embeddedStatement); Expect(152); //#line 3144 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, ConditionPosition.Start); } else if (la.kind == 1 || la.kind == 21) { EndOfStmt(); Block( //#line 3151 "VBNET.ATG" out embeddedStatement); Expect(152); if (la.kind == 224 || la.kind == 231) { WhileOrUntil( //#line 3152 "VBNET.ATG" out conditionType); Expr( //#line 3152 "VBNET.ATG" out expr); } //#line 3154 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); } else SynErr(299); } else if (la.kind == 124) { lexer.NextToken(); //#line 3159 "VBNET.ATG" Expression group = null; TypeReference typeReference; string typeName; if (la.kind == 110) { lexer.NextToken(); LoopControlVariable( //#line 3165 "VBNET.ATG" out typeReference, out typeName); Expect(138); Expr( //#line 3166 "VBNET.ATG" out group); EndOfStmt(); Block( //#line 3167 "VBNET.ATG" out embeddedStatement); Expect(163); if (StartOf(24)) { Expr( //#line 3168 "VBNET.ATG" out expr); } //#line 3170 "VBNET.ATG" statement = new ForeachStatement(typeReference, typeName, group, embeddedStatement, expr); statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } else if (StartOf(44)) { //#line 3181 "VBNET.ATG" Expression start = null; Expression end = null; Expression step = null; Expression variableExpr = null; Expression nextExpr = null; List<Expression> nextExpressions = null; if ( //#line 3188 "VBNET.ATG" IsLoopVariableDeclaration()) { LoopControlVariable( //#line 3189 "VBNET.ATG" out typeReference, out typeName); } else { //#line 3191 "VBNET.ATG" typeReference = null; typeName = null; SimpleExpr( //#line 3192 "VBNET.ATG" out variableExpr); } Expect(20); Expr( //#line 3194 "VBNET.ATG" out start); Expect(216); Expr( //#line 3194 "VBNET.ATG" out end); if (la.kind == 205) { lexer.NextToken(); Expr( //#line 3194 "VBNET.ATG" out step); } EndOfStmt(); Block( //#line 3195 "VBNET.ATG" out embeddedStatement); Expect(163); if (StartOf(24)) { Expr( //#line 3198 "VBNET.ATG" out nextExpr); //#line 3200 "VBNET.ATG" nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); while (la.kind == 22) { lexer.NextToken(); Expr( //#line 3203 "VBNET.ATG" out nextExpr); //#line 3203 "VBNET.ATG" nextExpressions.Add(nextExpr); } } //#line 3206 "VBNET.ATG" statement = new ForNextStatement { TypeReference = typeReference, VariableName = typeName, LoopVariableExpression = variableExpr, Start = start, End = end, Step = step, EmbeddedStatement = embeddedStatement, NextExpressions = nextExpressions }; } else SynErr(300); } else if (la.kind == 118) { lexer.NextToken(); Expr( //#line 3219 "VBNET.ATG" out expr); //#line 3219 "VBNET.ATG" statement = new ErrorStatement(expr); } else if (la.kind == 191) { lexer.NextToken(); //#line 3221 "VBNET.ATG" bool isPreserve = false; if (la.kind == 184) { lexer.NextToken(); //#line 3221 "VBNET.ATG" isPreserve = true; } ReDimClause( //#line 3222 "VBNET.ATG" out expr); //#line 3224 "VBNET.ATG" ReDimStatement reDimStatement = new ReDimStatement(isPreserve); statement = reDimStatement; SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); while (la.kind == 22) { lexer.NextToken(); ReDimClause( //#line 3228 "VBNET.ATG" out expr); //#line 3229 "VBNET.ATG" SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); } } else if (la.kind == 117) { lexer.NextToken(); Expr( //#line 3233 "VBNET.ATG" out expr); //#line 3235 "VBNET.ATG" EraseStatement eraseStatement = new EraseStatement(); if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr);} while (la.kind == 22) { lexer.NextToken(); Expr( //#line 3238 "VBNET.ATG" out expr); //#line 3238 "VBNET.ATG" if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr); } } //#line 3239 "VBNET.ATG" statement = eraseStatement; } else if (la.kind == 206) { lexer.NextToken(); //#line 3241 "VBNET.ATG" statement = new StopStatement(); } else if ( //#line 3243 "VBNET.ATG" la.kind == Tokens.If) { Expect(135); //#line 3244 "VBNET.ATG" Location ifStartLocation = t.Location; Expr( //#line 3244 "VBNET.ATG" out expr); if (la.kind == 214) { lexer.NextToken(); } if (la.kind == 1 || la.kind == 21) { EndOfStmt(); Block( //#line 3247 "VBNET.ATG" out embeddedStatement); //#line 3249 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement); ifStatement.StartLocation = ifStartLocation; Location elseIfStart; while (la.kind == 112 || //#line 3255 "VBNET.ATG" IsElseIf()) { if ( //#line 3255 "VBNET.ATG" IsElseIf()) { Expect(111); //#line 3255 "VBNET.ATG" elseIfStart = t.Location; Expect(135); } else { lexer.NextToken(); //#line 3256 "VBNET.ATG" elseIfStart = t.Location; } //#line 3258 "VBNET.ATG" Expression condition = null; Statement block = null; Expr( //#line 3259 "VBNET.ATG" out condition); if (la.kind == 214) { lexer.NextToken(); } EndOfStmt(); Block( //#line 3260 "VBNET.ATG" out block); //#line 3262 "VBNET.ATG" ElseIfSection elseIfSection = new ElseIfSection(condition, block); elseIfSection.StartLocation = elseIfStart; elseIfSection.EndLocation = t.Location; elseIfSection.Parent = ifStatement; ifStatement.ElseIfSections.Add(elseIfSection); } if (la.kind == 111) { lexer.NextToken(); if (la.kind == 1 || la.kind == 21) { EndOfStmt(); } Block( //#line 3271 "VBNET.ATG" out embeddedStatement); //#line 3273 "VBNET.ATG" ifStatement.FalseStatement.Add(embeddedStatement); } Expect(113); Expect(135); //#line 3277 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else if (StartOf(45)) { //#line 3282 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr); ifStatement.StartLocation = ifStartLocation; SingleLineStatementList( //#line 3285 "VBNET.ATG" ifStatement.TrueStatement); if (la.kind == 111) { lexer.NextToken(); if (StartOf(45)) { SingleLineStatementList( //#line 3288 "VBNET.ATG" ifStatement.FalseStatement); } } //#line 3290 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else SynErr(301); } else if (la.kind == 197) { lexer.NextToken(); if (la.kind == 74) { lexer.NextToken(); } Expr( //#line 3293 "VBNET.ATG" out expr); EndOfStmt(); //#line 3294 "VBNET.ATG" List<SwitchSection> selectSections = new List<SwitchSection>(); Statement block = null; while (la.kind == 74) { //#line 3298 "VBNET.ATG" List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; lexer.NextToken(); CaseClauses( //#line 3299 "VBNET.ATG" out caseClauses); if ( //#line 3299 "VBNET.ATG" IsNotStatementSeparator()) { lexer.NextToken(); } EndOfStmt(); //#line 3301 "VBNET.ATG" SwitchSection selectSection = new SwitchSection(caseClauses); selectSection.StartLocation = caseLocation; Block( //#line 3304 "VBNET.ATG" out block); //#line 3306 "VBNET.ATG" selectSection.Children = block.Children; selectSection.EndLocation = t.EndLocation; selectSections.Add(selectSection); } //#line 3312 "VBNET.ATG" statement = new SwitchStatement(expr, selectSections); Expect(113); Expect(197); } else if (la.kind == 171) { //#line 3315 "VBNET.ATG" OnErrorStatement onErrorStatement = null; OnErrorStatement( //#line 3316 "VBNET.ATG" out onErrorStatement); //#line 3316 "VBNET.ATG" statement = onErrorStatement; } else if (la.kind == 132) { //#line 3317 "VBNET.ATG" GotoStatement goToStatement = null; GotoStatement( //#line 3318 "VBNET.ATG" out goToStatement); //#line 3318 "VBNET.ATG" statement = goToStatement; } else if (la.kind == 194) { //#line 3319 "VBNET.ATG" ResumeStatement resumeStatement = null; ResumeStatement( //#line 3320 "VBNET.ATG" out resumeStatement); //#line 3320 "VBNET.ATG" statement = resumeStatement; } else if (StartOf(44)) { //#line 3323 "VBNET.ATG" Expression val = null; AssignmentOperatorType op; Location startLoc = la.Location; bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || la.kind == Tokens.Not || la.kind == Tokens.Times; SimpleExpr( //#line 3330 "VBNET.ATG" out expr); if (StartOf(46)) { AssignmentOperator( //#line 3332 "VBNET.ATG" out op); Expr( //#line 3332 "VBNET.ATG" out val); //#line 3334 "VBNET.ATG" expr = new AssignmentExpression(expr, op, val); expr.StartLocation = startLoc; expr.EndLocation = t.EndLocation; } else if (StartOf(47)) { //#line 3338 "VBNET.ATG" if (mustBeAssignment) Error("error in assignment."); } else SynErr(302); //#line 3341 "VBNET.ATG" // a field reference expression that stands alone is a // invocation expression without parantheses and arguments if(expr is MemberReferenceExpression || expr is IdentifierExpression) { Location endLocation = expr.EndLocation; expr = new InvocationExpression(expr); expr.StartLocation = startLoc; expr.EndLocation = endLocation; } statement = new ExpressionStatement(expr); } else if (la.kind == 73) { lexer.NextToken(); SimpleExpr( //#line 3351 "VBNET.ATG" out expr); //#line 3351 "VBNET.ATG" statement = new ExpressionStatement(expr); } else if (la.kind == 226) { lexer.NextToken(); //#line 3353 "VBNET.ATG" Statement block; if ( //#line 3354 "VBNET.ATG" Peek(1).kind == Tokens.As) { //#line 3355 "VBNET.ATG" LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); VariableDeclarator( //#line 3356 "VBNET.ATG" resourceAquisition.Variables); while (la.kind == 22) { lexer.NextToken(); VariableDeclarator( //#line 3358 "VBNET.ATG" resourceAquisition.Variables); } Block( //#line 3360 "VBNET.ATG" out block); //#line 3362 "VBNET.ATG" statement = new UsingStatement(resourceAquisition, block); } else if (StartOf(24)) { Expr( //#line 3364 "VBNET.ATG" out expr); Block( //#line 3365 "VBNET.ATG" out block); //#line 3366 "VBNET.ATG" statement = new UsingStatement(new ExpressionStatement(expr), block); } else SynErr(303); Expect(113); Expect(226); } else if (StartOf(48)) { LocalDeclarationStatement( //#line 3369 "VBNET.ATG" out statement); } else SynErr(304); //#line 3372 "VBNET.ATG" if (statement != null) { statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } }
public sealed override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { this.BeginVisit(localVariableDeclaration); object result = this.TrackedVisitLocalVariableDeclaration(localVariableDeclaration, data); this.EndVisit(localVariableDeclaration); return result; }
public virtual object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { throw new global::System.NotImplementedException("LocalVariableDeclaration"); }
public virtual object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); }
void EmbeddedStatement( #line 2297 "VBNET.ATG" out Statement statement) { #line 2299 "VBNET.ATG" Statement embeddedStatement = null; statement = null; Expression expr = null; string name = String.Empty; List<Expression> p = null; switch (la.kind) { case 94: { lexer.NextToken(); #line 2305 "VBNET.ATG" ExitType exitType = ExitType.None; switch (la.kind) { case 167: { lexer.NextToken(); #line 2307 "VBNET.ATG" exitType = ExitType.Sub; break; } case 100: { lexer.NextToken(); #line 2309 "VBNET.ATG" exitType = ExitType.Function; break; } case 146: { lexer.NextToken(); #line 2311 "VBNET.ATG" exitType = ExitType.Property; break; } case 83: { lexer.NextToken(); #line 2313 "VBNET.ATG" exitType = ExitType.Do; break; } case 98: { lexer.NextToken(); #line 2315 "VBNET.ATG" exitType = ExitType.For; break; } case 174: { lexer.NextToken(); #line 2317 "VBNET.ATG" exitType = ExitType.Try; break; } case 181: { lexer.NextToken(); #line 2319 "VBNET.ATG" exitType = ExitType.While; break; } case 155: { lexer.NextToken(); #line 2321 "VBNET.ATG" exitType = ExitType.Select; break; } default: SynErr(255); break; } #line 2323 "VBNET.ATG" statement = new ExitStatement(exitType); break; } case 174: { TryStatement( #line 2324 "VBNET.ATG" out statement); break; } case 187: { lexer.NextToken(); #line 2325 "VBNET.ATG" ContinueType continueType = ContinueType.None; if (la.kind == 83 || la.kind == 98 || la.kind == 181) { if (la.kind == 83) { lexer.NextToken(); #line 2325 "VBNET.ATG" continueType = ContinueType.Do; } else if (la.kind == 98) { lexer.NextToken(); #line 2325 "VBNET.ATG" continueType = ContinueType.For; } else { lexer.NextToken(); #line 2325 "VBNET.ATG" continueType = ContinueType.While; } } #line 2325 "VBNET.ATG" statement = new ContinueStatement(continueType); break; } case 171: { lexer.NextToken(); if (StartOf(27)) { Expr( #line 2327 "VBNET.ATG" out expr); } #line 2327 "VBNET.ATG" statement = new ThrowStatement(expr); break; } case 154: { lexer.NextToken(); if (StartOf(27)) { Expr( #line 2329 "VBNET.ATG" out expr); } #line 2329 "VBNET.ATG" statement = new ReturnStatement(expr); break; } case 168: { lexer.NextToken(); Expr( #line 2331 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2331 "VBNET.ATG" out embeddedStatement); Expect(88); Expect(168); #line 2332 "VBNET.ATG" statement = new LockStatement(expr, embeddedStatement); break; } case 149: { lexer.NextToken(); Identifier(); #line 2334 "VBNET.ATG" name = t.val; if (la.kind == 24) { lexer.NextToken(); if (StartOf(30)) { ArgumentList( #line 2335 "VBNET.ATG" out p); } Expect(25); } #line 2336 "VBNET.ATG" statement = new RaiseEventStatement(name, p); break; } case 182: { WithStatement( #line 2338 "VBNET.ATG" out statement); break; } case 42: { lexer.NextToken(); #line 2340 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2341 "VBNET.ATG" out expr); Expect(12); Expr( #line 2341 "VBNET.ATG" out handlerExpr); #line 2343 "VBNET.ATG" statement = new AddHandlerStatement(expr, handlerExpr); break; } case 152: { lexer.NextToken(); #line 2346 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2347 "VBNET.ATG" out expr); Expect(12); Expr( #line 2347 "VBNET.ATG" out handlerExpr); #line 2349 "VBNET.ATG" statement = new RemoveHandlerStatement(expr, handlerExpr); break; } case 181: { lexer.NextToken(); Expr( #line 2352 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2353 "VBNET.ATG" out embeddedStatement); Expect(88); Expect(181); #line 2355 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); break; } case 83: { lexer.NextToken(); #line 2360 "VBNET.ATG" ConditionType conditionType = ConditionType.None; if (la.kind == 177 || la.kind == 181) { WhileOrUntil( #line 2363 "VBNET.ATG" out conditionType); Expr( #line 2363 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2364 "VBNET.ATG" out embeddedStatement); Expect(118); #line 2367 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, ConditionPosition.Start); } else if (la.kind == 1 || la.kind == 13) { EndOfStmt(); Block( #line 2374 "VBNET.ATG" out embeddedStatement); Expect(118); if (la.kind == 177 || la.kind == 181) { WhileOrUntil( #line 2375 "VBNET.ATG" out conditionType); Expr( #line 2375 "VBNET.ATG" out expr); } #line 2377 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); } else SynErr(256); break; } case 98: { lexer.NextToken(); #line 2382 "VBNET.ATG" Expression group = null; TypeReference typeReference; string typeName; Location startLocation = t.Location; if (la.kind == 85) { lexer.NextToken(); LoopControlVariable( #line 2389 "VBNET.ATG" out typeReference, out typeName); Expect(109); Expr( #line 2390 "VBNET.ATG" out group); EndOfStmt(); Block( #line 2391 "VBNET.ATG" out embeddedStatement); Expect(128); if (StartOf(27)) { Expr( #line 2392 "VBNET.ATG" out expr); } #line 2394 "VBNET.ATG" statement = new ForeachStatement(typeReference, typeName, group, embeddedStatement, expr); statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } else if (StartOf(13)) { #line 2405 "VBNET.ATG" Expression start = null; Expression end = null; Expression step = null; Expression nextExpr = null;List<Expression> nextExpressions = null; LoopControlVariable( #line 2410 "VBNET.ATG" out typeReference, out typeName); Expect(11); Expr( #line 2411 "VBNET.ATG" out start); Expect(172); Expr( #line 2411 "VBNET.ATG" out end); if (la.kind == 162) { lexer.NextToken(); Expr( #line 2411 "VBNET.ATG" out step); } EndOfStmt(); Block( #line 2412 "VBNET.ATG" out embeddedStatement); Expect(128); if (StartOf(27)) { Expr( #line 2415 "VBNET.ATG" out nextExpr); #line 2415 "VBNET.ATG" nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); while (la.kind == 12) { lexer.NextToken(); Expr( #line 2416 "VBNET.ATG" out nextExpr); #line 2416 "VBNET.ATG" nextExpressions.Add(nextExpr); } } #line 2419 "VBNET.ATG" statement = new ForNextStatement(typeReference, typeName, start, end, step, embeddedStatement, nextExpressions); } else SynErr(257); break; } case 92: { lexer.NextToken(); Expr( #line 2423 "VBNET.ATG" out expr); #line 2423 "VBNET.ATG" statement = new ErrorStatement(expr); break; } case 151: { lexer.NextToken(); #line 2425 "VBNET.ATG" bool isPreserve = false; if (la.kind == 144) { lexer.NextToken(); #line 2425 "VBNET.ATG" isPreserve = true; } ReDimClause( #line 2426 "VBNET.ATG" out expr); #line 2428 "VBNET.ATG" ReDimStatement reDimStatement = new ReDimStatement(isPreserve); statement = reDimStatement; SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); while (la.kind == 12) { lexer.NextToken(); ReDimClause( #line 2432 "VBNET.ATG" out expr); #line 2433 "VBNET.ATG" SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); } break; } case 91: { lexer.NextToken(); Expr( #line 2437 "VBNET.ATG" out expr); #line 2438 "VBNET.ATG" List<Expression> arrays = new List<Expression>(); if (expr != null) { arrays.Add(expr);} EraseStatement eraseStatement = new EraseStatement(arrays); while (la.kind == 12) { lexer.NextToken(); Expr( #line 2443 "VBNET.ATG" out expr); #line 2443 "VBNET.ATG" if (expr != null) { arrays.Add(expr); } } #line 2444 "VBNET.ATG" statement = eraseStatement; break; } case 163: { lexer.NextToken(); #line 2446 "VBNET.ATG" statement = new StopStatement(); break; } case 106: { lexer.NextToken(); #line 2448 "VBNET.ATG" Location ifStartLocation = t.Location; Expr( #line 2448 "VBNET.ATG" out expr); if (la.kind == 170) { lexer.NextToken(); } if (la.kind == 1 || la.kind == 13) { EndOfStmt(); Block( #line 2451 "VBNET.ATG" out embeddedStatement); #line 2453 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement); ifStatement.StartLocation = ifStartLocation; Location elseIfStart; while (la.kind == 87 || #line 2459 "VBNET.ATG" IsElseIf()) { if ( #line 2459 "VBNET.ATG" IsElseIf()) { Expect(86); #line 2459 "VBNET.ATG" elseIfStart = t.Location; Expect(106); } else { lexer.NextToken(); #line 2460 "VBNET.ATG" elseIfStart = t.Location; } #line 2462 "VBNET.ATG" Expression condition = null; Statement block = null; Expr( #line 2463 "VBNET.ATG" out condition); if (la.kind == 170) { lexer.NextToken(); } EndOfStmt(); Block( #line 2464 "VBNET.ATG" out block); #line 2466 "VBNET.ATG" ElseIfSection elseIfSection = new ElseIfSection(condition, block); elseIfSection.StartLocation = elseIfStart; elseIfSection.EndLocation = t.Location; elseIfSection.Parent = ifStatement; ifStatement.ElseIfSections.Add(elseIfSection); } if (la.kind == 86) { lexer.NextToken(); EndOfStmt(); Block( #line 2475 "VBNET.ATG" out embeddedStatement); #line 2477 "VBNET.ATG" ifStatement.FalseStatement.Add(embeddedStatement); } Expect(88); Expect(106); #line 2481 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else if (StartOf(36)) { #line 2486 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr); ifStatement.StartLocation = ifStartLocation; SingleLineStatementList( #line 2489 "VBNET.ATG" ifStatement.TrueStatement); if (la.kind == 86) { lexer.NextToken(); if (StartOf(36)) { SingleLineStatementList( #line 2492 "VBNET.ATG" ifStatement.FalseStatement); } } #line 2494 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else SynErr(258); break; } case 155: { lexer.NextToken(); if (la.kind == 57) { lexer.NextToken(); } Expr( #line 2497 "VBNET.ATG" out expr); EndOfStmt(); #line 2498 "VBNET.ATG" List<SwitchSection> selectSections = new List<SwitchSection>(); Statement block = null; while (la.kind == 57) { #line 2502 "VBNET.ATG" List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; lexer.NextToken(); CaseClauses( #line 2503 "VBNET.ATG" out caseClauses); if ( #line 2503 "VBNET.ATG" IsNotStatementSeparator()) { lexer.NextToken(); } EndOfStmt(); #line 2505 "VBNET.ATG" SwitchSection selectSection = new SwitchSection(caseClauses); selectSection.StartLocation = caseLocation; Block( #line 2508 "VBNET.ATG" out block); #line 2510 "VBNET.ATG" selectSection.Children = block.Children; selectSection.EndLocation = t.EndLocation; selectSections.Add(selectSection); } #line 2515 "VBNET.ATG" statement = new SwitchStatement(expr, selectSections); Expect(88); Expect(155); break; } case 135: { #line 2517 "VBNET.ATG" OnErrorStatement onErrorStatement = null; OnErrorStatement( #line 2518 "VBNET.ATG" out onErrorStatement); #line 2518 "VBNET.ATG" statement = onErrorStatement; break; } case 104: { #line 2519 "VBNET.ATG" GotoStatement goToStatement = null; GotoStatement( #line 2520 "VBNET.ATG" out goToStatement); #line 2520 "VBNET.ATG" statement = goToStatement; break; } case 153: { #line 2521 "VBNET.ATG" ResumeStatement resumeStatement = null; ResumeStatement( #line 2522 "VBNET.ATG" out resumeStatement); #line 2522 "VBNET.ATG" statement = resumeStatement; break; } case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 24: case 43: case 47: case 49: case 50: case 51: case 52: case 54: case 59: case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 68: case 69: case 70: case 72: case 73: case 74: case 75: case 76: case 77: case 82: case 84: case 95: case 96: case 102: case 111: case 117: case 119: case 124: case 125: case 127: case 130: case 133: case 134: case 144: case 159: case 160: case 165: case 169: case 173: case 175: case 176: case 177: case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 205: { #line 2525 "VBNET.ATG" Expression val = null; AssignmentOperatorType op; bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || la.kind == Tokens.Not || la.kind == Tokens.Times; SimpleExpr( #line 2531 "VBNET.ATG" out expr); if (StartOf(37)) { AssignmentOperator( #line 2533 "VBNET.ATG" out op); Expr( #line 2533 "VBNET.ATG" out val); #line 2533 "VBNET.ATG" expr = new AssignmentExpression(expr, op, val); } else if (la.kind == 1 || la.kind == 13 || la.kind == 86) { #line 2534 "VBNET.ATG" if (mustBeAssignment) Error("error in assignment."); } else SynErr(259); #line 2537 "VBNET.ATG" // a field reference expression that stands alone is a // invocation expression without parantheses and arguments if(expr is MemberReferenceExpression || expr is IdentifierExpression) { expr = new InvocationExpression(expr); } statement = new ExpressionStatement(expr); break; } case 56: { lexer.NextToken(); SimpleExpr( #line 2544 "VBNET.ATG" out expr); #line 2544 "VBNET.ATG" statement = new ExpressionStatement(expr); break; } case 189: { lexer.NextToken(); #line 2546 "VBNET.ATG" Statement block; if ( #line 2547 "VBNET.ATG" Peek(1).kind == Tokens.As) { #line 2548 "VBNET.ATG" LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); VariableDeclarator( #line 2549 "VBNET.ATG" resourceAquisition.Variables); while (la.kind == 12) { lexer.NextToken(); VariableDeclarator( #line 2551 "VBNET.ATG" resourceAquisition.Variables); } Block( #line 2553 "VBNET.ATG" out block); #line 2554 "VBNET.ATG" statement = new UsingStatement(resourceAquisition, block); } else if (StartOf(27)) { Expr( #line 2555 "VBNET.ATG" out expr); Block( #line 2556 "VBNET.ATG" out block); #line 2557 "VBNET.ATG" statement = new UsingStatement(new ExpressionStatement(expr), block); } else SynErr(260); Expect(88); Expect(189); break; } default: SynErr(261); break; } }
public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { VariableDeclaration item = localVariableDeclaration.Variables[0]; if (!item.Initializer.IsNull) { this.AppendIndented(string.Concat(item.Name, " = ")); item.Initializer.AcceptVisitor(this, data); this.AppendLine(); } return null; }
protected override IEnumerable<string> GenerateCode (INRefactoryASTProvider astProvider, string indent, List<IBaseMember> includedMembers) { // Genereate Equals MethodDeclaration methodDeclaration = new MethodDeclaration (); methodDeclaration.Name = "Equals"; methodDeclaration.TypeReference = DomReturnType.Bool.ConvertToTypeReference (); methodDeclaration.Modifier = ICSharpCode.NRefactory.Ast.Modifiers.Public | ICSharpCode.NRefactory.Ast.Modifiers.Override; methodDeclaration.Body = new BlockStatement (); methodDeclaration.Parameters.Add (new ParameterDeclarationExpression (DomReturnType.Object.ConvertToTypeReference (), "obj")); IdentifierExpression paramId = new IdentifierExpression ("obj"); IfElseStatement ifStatement = new IfElseStatement (null); ifStatement.Condition = new BinaryOperatorExpression (paramId, BinaryOperatorType.Equality, new PrimitiveExpression (null)); ifStatement.TrueStatement.Add (new ReturnStatement (new PrimitiveExpression (false))); methodDeclaration.Body.AddChild (ifStatement); ifStatement = new IfElseStatement (null); List<Expression> arguments = new List<Expression> (); arguments.Add (new ThisReferenceExpression ()); arguments.Add (paramId); ifStatement.Condition = new InvocationExpression (new IdentifierExpression ("ReferenceEquals"), arguments); ifStatement.TrueStatement.Add (new ReturnStatement (new PrimitiveExpression (true))); methodDeclaration.Body.AddChild (ifStatement); ifStatement = new IfElseStatement (null); ifStatement.Condition = new BinaryOperatorExpression (new InvocationExpression (new MemberReferenceExpression (paramId, "GetType")), BinaryOperatorType.InEquality, new TypeOfExpression (new TypeReference (Options.EnclosingType.Name))); ifStatement.TrueStatement.Add (new ReturnStatement (new PrimitiveExpression (false))); methodDeclaration.Body.AddChild (ifStatement); LocalVariableDeclaration varDecl = new LocalVariableDeclaration (new DomReturnType (Options.EnclosingType).ConvertToTypeReference ()); varDecl.Variables.Add (new VariableDeclaration ("other", new CastExpression (varDecl.TypeReference, paramId, CastType.Cast))); methodDeclaration.Body.AddChild (varDecl); IdentifierExpression otherId = new IdentifierExpression ("other"); Expression binOp = null; foreach (IMember member in includedMembers) { Expression right = new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.Equality, new MemberReferenceExpression (otherId, member.Name)); if (binOp == null) { binOp = right; } else { binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.LogicalAnd, right); } } methodDeclaration.Body.AddChild (new ReturnStatement (binOp)); yield return astProvider.OutputNode (this.Options.Dom, methodDeclaration, indent); methodDeclaration = new MethodDeclaration (); methodDeclaration.Name = "GetHashCode"; methodDeclaration.TypeReference = DomReturnType.Int32.ConvertToTypeReference (); methodDeclaration.Modifier = ICSharpCode.NRefactory.Ast.Modifiers.Public | ICSharpCode.NRefactory.Ast.Modifiers.Override; methodDeclaration.Body = new BlockStatement (); binOp = null; foreach (IMember member in includedMembers) { Expression right; right = new InvocationExpression (new MemberReferenceExpression (new IdentifierExpression (member.Name), "GetHashCode")); IType type = Options.Dom.SearchType (Options.Document.ParsedDocument.CompilationUnit, member, member.ReturnType); if (type != null && type.ClassType != MonoDevelop.Projects.Dom.ClassType.Struct&& type.ClassType != MonoDevelop.Projects.Dom.ClassType.Enum) right = new ParenthesizedExpression (new ConditionalExpression (new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), right, new PrimitiveExpression (0))); if (binOp == null) { binOp = right; } else { binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.ExclusiveOr, right); } } BlockStatement uncheckedBlock = new BlockStatement (); uncheckedBlock.AddChild (new ReturnStatement (binOp)); methodDeclaration.Body.AddChild (new UncheckedStatement (uncheckedBlock)); yield return astProvider.OutputNode (this.Options.Dom, methodDeclaration, indent); }
void LocalDeclarationStatement( //#line 3039 "VBNET.ATG" out Statement statement) { //#line 3041 "VBNET.ATG" ModifierList m = new ModifierList(); LocalVariableDeclaration localVariableDeclaration; bool dimfound = false; while (la.kind == 88 || la.kind == 105 || la.kind == 204) { if (la.kind == 88) { lexer.NextToken(); //#line 3047 "VBNET.ATG" m.Add(Modifiers.Const, t.Location); } else if (la.kind == 204) { lexer.NextToken(); //#line 3048 "VBNET.ATG" m.Add(Modifiers.Static, t.Location); } else { lexer.NextToken(); //#line 3049 "VBNET.ATG" dimfound = true; } } //#line 3052 "VBNET.ATG" if(dimfound && (m.Modifier & Modifiers.Const) != 0) { Error("Dim is not allowed on constants."); } if(m.isNone && dimfound == false) { Error("Const, Dim or Static expected"); } localVariableDeclaration = new LocalVariableDeclaration(m.Modifier); localVariableDeclaration.StartLocation = t.Location; VariableDeclarator( //#line 3063 "VBNET.ATG" localVariableDeclaration.Variables); while (la.kind == 22) { lexer.NextToken(); VariableDeclarator( //#line 3064 "VBNET.ATG" localVariableDeclaration.Variables); } //#line 3066 "VBNET.ATG" statement = localVariableDeclaration; }
void LocalVariableDecl( #line 1501 "cs.ATG" out Statement stmt) { #line 1503 "cs.ATG" TypeReference type; VariableDeclaration var = null; LocalVariableDeclaration localVariableDeclaration; Location startPos = la.Location; Type( #line 1509 "cs.ATG" out type); #line 1509 "cs.ATG" localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = startPos; LocalVariableDeclarator( #line 1510 "cs.ATG" out var); #line 1510 "cs.ATG" SafeAdd(localVariableDeclaration, localVariableDeclaration.Variables, var); while (la.kind == 14) { lexer.NextToken(); LocalVariableDeclarator( #line 1511 "cs.ATG" out var); #line 1511 "cs.ATG" SafeAdd(localVariableDeclaration, localVariableDeclaration.Variables, var); } #line 1512 "cs.ATG" stmt = localVariableDeclaration; stmt.EndLocation = t.EndLocation; }