public override object Visit(InvocationExpression invocationExpression, object data) { if (invocationExpression.TargetObject is FieldReferenceOrInvocationExpression) { FieldReferenceOrInvocationExpression field = (FieldReferenceOrInvocationExpression)invocationExpression.TargetObject; IReturnType type = field.TargetObject.AcceptVisitor(this, data) as IReturnType; ArrayList methods = resolver.SearchMethod(type, field.FieldName); resolver.ShowStatic = false; if (methods.Count <= 0) { return null; } // TODO: Find the right method return ((IMethod)methods[0]).ReturnType; } else if (invocationExpression.TargetObject is IdentifierExpression) { string id = ((IdentifierExpression)invocationExpression.TargetObject).Identifier; if (resolver.CallingClass == null) { return null; } IReturnType type = new ReturnType(resolver.CallingClass.FullyQualifiedName); ArrayList methods = resolver.SearchMethod(type, id); resolver.ShowStatic = false; if (methods.Count <= 0) { return null; } // TODO: Find the right method return ((IMethod)methods[0]).ReturnType; } // invocationExpression is delegate call IReturnType t = invocationExpression.AcceptChildren(this, data) as IReturnType; if (t == null) { return null; } IClass c = resolver.SearchType(t.FullyQualifiedName, resolver.CallingClass, resolver.CompilationUnit); if (c.ClassType == ClassType.Delegate) { ArrayList methods = resolver.SearchMethod(t, "invoke"); if (methods.Count <= 0) { return null; } return ((IMethod)methods[0]).ReturnType; } return null; }
public override object Visit(InvocationExpression invocationExpression, object data) { Expression target = invocationExpression.TargetObject; CodeExpression targetExpr; string methodName = null; if (target == null) { targetExpr = new CodeThisReferenceExpression(); } else if (target is FieldReferenceOrInvocationExpression) { FieldReferenceOrInvocationExpression fRef = (FieldReferenceOrInvocationExpression)target; targetExpr = (CodeExpression)fRef.TargetObject.AcceptVisitor(this, data); if (fRef.TargetObject is FieldReferenceOrInvocationExpression) { FieldReferenceOrInvocationExpression fRef2 = (FieldReferenceOrInvocationExpression)fRef.TargetObject; if (fRef2.FieldName != null && Char.IsUpper(fRef2.FieldName[0])) { // an exception is thrown if it doesn't end in an indentifier exception // for example for : this.MyObject.MyMethod() leads to an exception, which // is correct in this case ... I know this is really HACKY :) try { CodeExpression tExpr = ConvertToIdentifier(fRef2); if (tExpr != null) { targetExpr = tExpr; } } catch (Exception) {} } } methodName = fRef.FieldName; // HACK for : Microsoft.VisualBasic.ChrW(NUMBER) //Console.WriteLine(methodName); if (methodName == "ChrW") { //Console.WriteLine("Return CAST EXPRESSION" + GetExpressionList(invocationExpression.Parameters)[0]); return new CodeCastExpression("System.Char", GetExpressionList(invocationExpression.Parameters)[0]); } } else { targetExpr = (CodeExpression)target.AcceptVisitor(this, data); } return new CodeMethodInvokeExpression(targetExpr, methodName, GetExpressionList(invocationExpression.Parameters)); }
void EmbeddedStatement( #line 2071 "VBNET.ATG" out Statement statement) { #line 2073 "VBNET.ATG" Statement embeddedStatement = null; statement = null; Expression expr = null; string name = String.Empty; ArrayList p = null; switch (la.kind) { case 95: { lexer.NextToken(); #line 2079 "VBNET.ATG" ExitType exitType = ExitType.None; switch (la.kind) { case 169: { lexer.NextToken(); #line 2081 "VBNET.ATG" exitType = ExitType.Sub; break; } case 101: { lexer.NextToken(); #line 2083 "VBNET.ATG" exitType = ExitType.Function; break; } case 148: { lexer.NextToken(); #line 2085 "VBNET.ATG" exitType = ExitType.Property; break; } case 84: { lexer.NextToken(); #line 2087 "VBNET.ATG" exitType = ExitType.Do; break; } case 99: { lexer.NextToken(); #line 2089 "VBNET.ATG" exitType = ExitType.For; break; } case 176: { lexer.NextToken(); #line 2091 "VBNET.ATG" exitType = ExitType.Try; break; } case 183: { lexer.NextToken(); #line 2093 "VBNET.ATG" exitType = ExitType.While; break; } case 157: { lexer.NextToken(); #line 2095 "VBNET.ATG" exitType = ExitType.Select; break; } default: SynErr(229); break; } #line 2097 "VBNET.ATG" statement = new ExitStatement(exitType); break; } case 176: { TryStatement( #line 2098 "VBNET.ATG" out statement); break; } case 173: { lexer.NextToken(); if (StartOf(18)) { Expr( #line 2100 "VBNET.ATG" out expr); } #line 2100 "VBNET.ATG" statement = new ThrowStatement(expr); break; } case 156: { lexer.NextToken(); if (StartOf(18)) { Expr( #line 2102 "VBNET.ATG" out expr); } #line 2102 "VBNET.ATG" statement = new ReturnStatement(expr); break; } case 170: { lexer.NextToken(); Expr( #line 2104 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2104 "VBNET.ATG" out embeddedStatement); Expect(89); Expect(170); #line 2105 "VBNET.ATG" statement = new LockStatement(expr, embeddedStatement); break; } case 151: { lexer.NextToken(); Identifier(); #line 2107 "VBNET.ATG" name = t.val; if (la.kind == 25) { lexer.NextToken(); if (StartOf(17)) { ArgumentList( #line 2108 "VBNET.ATG" out p); } Expect(26); } #line 2109 "VBNET.ATG" statement = new RaiseEventStatement(name, p); break; } case 184: { WithStatement( #line 2111 "VBNET.ATG" out statement); break; } case 43: { lexer.NextToken(); #line 2113 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2114 "VBNET.ATG" out expr); Expect(12); Expr( #line 2114 "VBNET.ATG" out handlerExpr); #line 2116 "VBNET.ATG" statement = new AddHandlerStatement(expr, handlerExpr); break; } case 154: { lexer.NextToken(); #line 2119 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2120 "VBNET.ATG" out expr); Expect(12); Expr( #line 2120 "VBNET.ATG" out handlerExpr); #line 2122 "VBNET.ATG" statement = new RemoveHandlerStatement(expr, handlerExpr); break; } case 183: { lexer.NextToken(); Expr( #line 2125 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2126 "VBNET.ATG" out embeddedStatement); Expect(89); Expect(183); #line 2128 "VBNET.ATG" statement = new WhileStatement(expr, embeddedStatement); break; } case 84: { lexer.NextToken(); #line 2133 "VBNET.ATG" ConditionType conditionType = ConditionType.None; if (la.kind == 179 || la.kind == 183) { WhileOrUntil( #line 2136 "VBNET.ATG" out conditionType); Expr( #line 2136 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2137 "VBNET.ATG" out embeddedStatement); Expect(119); #line 2140 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.Start); } else if (la.kind == 1 || la.kind == 13) { EndOfStmt(); Block( #line 2144 "VBNET.ATG" out embeddedStatement); Expect(119); if (la.kind == 179 || la.kind == 183) { WhileOrUntil( #line 2145 "VBNET.ATG" out conditionType); Expr( #line 2145 "VBNET.ATG" out expr); } #line 2147 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); } else SynErr(230); break; } case 99: { lexer.NextToken(); #line 2152 "VBNET.ATG" Expression group = null; LoopControlVariableExpression loopControlExpr = null; if (la.kind == 86) { lexer.NextToken(); LoopControlVariable( #line 2157 "VBNET.ATG" out loopControlExpr); Expect(110); Expr( #line 2158 "VBNET.ATG" out group); EndOfStmt(); Block( #line 2159 "VBNET.ATG" out embeddedStatement); Expect(129); if (StartOf(18)) { Expr( #line 2160 "VBNET.ATG" out expr); } #line 2162 "VBNET.ATG" statement = new ForeachStatement(loopControlExpr, group, embeddedStatement, expr); } else if (StartOf(9)) { #line 2166 "VBNET.ATG" Expression start = null; Expression end = null; Expression step = null; Expression nextExpr = null; ArrayList nextExpressions = null; LoopControlVariable( #line 2172 "VBNET.ATG" out loopControlExpr); Expect(11); Expr( #line 2173 "VBNET.ATG" out start); Expect(174); Expr( #line 2173 "VBNET.ATG" out end); if (la.kind == 164) { lexer.NextToken(); Expr( #line 2173 "VBNET.ATG" out step); } EndOfStmt(); Block( #line 2174 "VBNET.ATG" out embeddedStatement); Expect(129); if (StartOf(18)) { Expr( #line 2177 "VBNET.ATG" out nextExpr); #line 2177 "VBNET.ATG" nextExpressions = new ArrayList(); nextExpressions.Add(nextExpr); while (la.kind == 12) { lexer.NextToken(); Expr( #line 2178 "VBNET.ATG" out nextExpr); #line 2178 "VBNET.ATG" nextExpressions.Add(nextExpr); } } #line 2181 "VBNET.ATG" statement = new ForStatement(loopControlExpr, start, end, step, embeddedStatement, nextExpressions); } else SynErr(231); break; } case 93: { lexer.NextToken(); Expr( #line 2185 "VBNET.ATG" out expr); #line 2185 "VBNET.ATG" statement = new ErrorStatement(expr); break; } case 153: { lexer.NextToken(); #line 2187 "VBNET.ATG" Expression clause = null; if (la.kind == 146) { lexer.NextToken(); } Expr( #line 2188 "VBNET.ATG" out clause); #line 2190 "VBNET.ATG" ArrayList clauses = new ArrayList(); clauses.Add(clause); /*ReDimStatement reDimStatement = new ReDimStatement(clauses);*/ while (la.kind == 12) { lexer.NextToken(); Expr( #line 2194 "VBNET.ATG" out clause); #line 2194 "VBNET.ATG" clauses.Add(clause); } break; } case 92: { lexer.NextToken(); Expr( #line 2197 "VBNET.ATG" out expr); #line 2199 "VBNET.ATG" ArrayList arrays = new ArrayList(); arrays.Add(expr); EraseStatement eraseStatement = new EraseStatement(arrays); while (la.kind == 12) { lexer.NextToken(); Expr( #line 2204 "VBNET.ATG" out expr); #line 2204 "VBNET.ATG" arrays.Add(expr); } #line 2205 "VBNET.ATG" statement = eraseStatement; break; } case 165: { lexer.NextToken(); #line 2207 "VBNET.ATG" statement = new StopStatement(); break; } case 107: { lexer.NextToken(); Expr( #line 2209 "VBNET.ATG" out expr); if (la.kind == 172) { lexer.NextToken(); } if ( #line 2211 "VBNET.ATG" IsEndStmtAhead()) { Expect(89); #line 2211 "VBNET.ATG" statement = new IfStatement(expr, new EndStatement()); } else if (la.kind == 1 || la.kind == 13) { EndOfStmt(); Block( #line 2214 "VBNET.ATG" out embeddedStatement); #line 2216 "VBNET.ATG" ArrayList elseIfSections = new ArrayList(); IfStatement ifStatement = new IfStatement(expr, embeddedStatement); while (la.kind == 88 || #line 2221 "VBNET.ATG" IsElseIf()) { if ( #line 2221 "VBNET.ATG" IsElseIf()) { Expect(87); Expect(107); } else { lexer.NextToken(); } #line 2224 "VBNET.ATG" Expression condition = null; Statement block = null; Expr( #line 2225 "VBNET.ATG" out condition); if (la.kind == 172) { lexer.NextToken(); } EndOfStmt(); Block( #line 2226 "VBNET.ATG" out block); #line 2228 "VBNET.ATG" ElseIfSection elseIfSection = new ElseIfSection(condition, block); elseIfSections.Add(elseIfSection); } if (la.kind == 87) { lexer.NextToken(); EndOfStmt(); Block( #line 2234 "VBNET.ATG" out embeddedStatement); #line 2236 "VBNET.ATG" ifStatement.EmbeddedElseStatement = embeddedStatement; } Expect(89); Expect(107); #line 2240 "VBNET.ATG" ifStatement.ElseIfStatements = elseIfSections; statement = ifStatement; } else if (StartOf(27)) { EmbeddedStatement( #line 2244 "VBNET.ATG" out embeddedStatement); #line 2246 "VBNET.ATG" SimpleIfStatement ifStatement = new SimpleIfStatement(expr); ArrayList statements = new ArrayList(); statements.Add(embeddedStatement); ifStatement.Statements = statements; while (la.kind == 13) { lexer.NextToken(); EmbeddedStatement( #line 2251 "VBNET.ATG" out embeddedStatement); #line 2251 "VBNET.ATG" statements.Add(embeddedStatement); } if (la.kind == 87) { lexer.NextToken(); if (StartOf(27)) { EmbeddedStatement( #line 2253 "VBNET.ATG" out embeddedStatement); } #line 2255 "VBNET.ATG" ArrayList elseStatements = new ArrayList(); elseStatements.Add(embeddedStatement); ifStatement.ElseStatements = elseStatements; while (la.kind == 13) { lexer.NextToken(); EmbeddedStatement( #line 2260 "VBNET.ATG" out embeddedStatement); #line 2261 "VBNET.ATG" elseStatements.Add(embeddedStatement); } } #line 2264 "VBNET.ATG" statement = ifStatement; } else SynErr(232); break; } case 157: { lexer.NextToken(); if (la.kind == 58) { lexer.NextToken(); } Expr( #line 2267 "VBNET.ATG" out expr); EndOfStmt(); #line 2269 "VBNET.ATG" ArrayList selectSections = new ArrayList(); Statement block = null; while (la.kind == 58) { #line 2273 "VBNET.ATG" ArrayList caseClauses = null; lexer.NextToken(); CaseClauses( #line 2274 "VBNET.ATG" out caseClauses); if ( #line 2274 "VBNET.ATG" IsNotStatementSeparator()) { lexer.NextToken(); } EndOfStmt(); #line 2276 "VBNET.ATG" SelectSection selectSection = new SelectSection(); selectSection.CaseClauses = caseClauses; compilationUnit.BlockStart(selectSection); Block( #line 2280 "VBNET.ATG" out block); #line 2282 "VBNET.ATG" selectSection.EmbeddedStatement = block; compilationUnit.BlockEnd(); selectSections.Add(selectSection); } #line 2287 "VBNET.ATG" statement = new SelectStatement(expr, selectSections); Expect(89); Expect(157); break; } case 136: { #line 2289 "VBNET.ATG" OnErrorStatement onErrorStatement = null; OnErrorStatement( #line 2290 "VBNET.ATG" out onErrorStatement); #line 2290 "VBNET.ATG" statement = onErrorStatement; break; } case 105: { #line 2291 "VBNET.ATG" GoToStatement goToStatement = null; GoToStatement( #line 2292 "VBNET.ATG" out goToStatement); #line 2292 "VBNET.ATG" statement = goToStatement; break; } case 155: { #line 2293 "VBNET.ATG" ResumeStatement resumeStatement = null; ResumeStatement( #line 2294 "VBNET.ATG" out resumeStatement); #line 2294 "VBNET.ATG" statement = resumeStatement; break; } case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 14: case 15: case 16: case 25: case 44: case 52: case 53: case 55: case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 67: case 69: case 70: case 71: case 73: case 74: case 75: case 76: case 77: case 78: case 83: case 85: case 97: case 103: case 112: case 118: case 120: case 125: case 126: case 128: case 131: case 161: case 162: case 167: case 171: case 175: case 177: { #line 2297 "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; UnaryExpr( #line 2303 "VBNET.ATG" out expr); if (StartOf(14)) { AssignmentOperator( #line 2305 "VBNET.ATG" out op); Expr( #line 2305 "VBNET.ATG" out val); #line 2305 "VBNET.ATG" expr = new AssignmentExpression(expr, op, val); } else if (la.kind == 1 || la.kind == 13 || la.kind == 87) { #line 2306 "VBNET.ATG" if (mustBeAssignment) Error("error in assignment."); } else SynErr(233); #line 2309 "VBNET.ATG" // a field reference expression that stands alone is a // invocation expression without parantheses and arguments if(expr is FieldReferenceOrInvocationExpression) { expr = new InvocationExpression(expr, new ArrayList()); } statement = new StatementExpression(expr); break; } case 57: { lexer.NextToken(); UnaryExpr( #line 2316 "VBNET.ATG" out expr); #line 2316 "VBNET.ATG" statement = new StatementExpression(expr); break; } default: SynErr(234); break; } }
void SimpleExpr( #line 1493 "VBNET.ATG" out Expression pexpr) { #line 1495 "VBNET.ATG" Expression expr; TypeReference type = null; string name = String.Empty; pexpr = null; if (StartOf(20)) { switch (la.kind) { case 3: { lexer.NextToken(); #line 1503 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 4: { lexer.NextToken(); #line 1504 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 7: { lexer.NextToken(); #line 1505 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 6: { lexer.NextToken(); #line 1506 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 5: { lexer.NextToken(); #line 1507 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 9: { lexer.NextToken(); #line 1508 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 8: { lexer.NextToken(); #line 1509 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 175: { lexer.NextToken(); #line 1511 "VBNET.ATG" pexpr = new PrimitiveExpression(true, "true"); break; } case 97: { lexer.NextToken(); #line 1512 "VBNET.ATG" pexpr = new PrimitiveExpression(false, "false"); break; } case 131: { lexer.NextToken(); #line 1513 "VBNET.ATG" pexpr = new PrimitiveExpression(null, "null"); break; } case 25: { lexer.NextToken(); Expr( #line 1514 "VBNET.ATG" out expr); Expect(26); #line 1514 "VBNET.ATG" pexpr = new ParenthesizedExpression(expr); break; } case 2: case 52: case 71: case 171: { Identifier(); #line 1515 "VBNET.ATG" pexpr = new IdentifierExpression(t.val); break; } case 53: case 55: case 66: case 77: case 78: case 85: case 112: case 118: case 161: case 162: case 167: { #line 1516 "VBNET.ATG" string val = String.Empty; PrimitiveTypeName( #line 1516 "VBNET.ATG" out val); Expect(10); Identifier(); #line 1517 "VBNET.ATG" pexpr = new FieldReferenceOrInvocationExpression(new TypeReferenceExpression(val), t.val); break; } case 120: { lexer.NextToken(); #line 1518 "VBNET.ATG" pexpr = new ThisReferenceExpression(); break; } case 125: case 126: { #line 1519 "VBNET.ATG" Expression retExpr = null; if (la.kind == 125) { lexer.NextToken(); #line 1520 "VBNET.ATG" retExpr = new BaseReferenceExpression(); } else if (la.kind == 126) { lexer.NextToken(); #line 1521 "VBNET.ATG" retExpr = new ClassReferenceExpression(); } else SynErr(217); Expect(10); IdentifierOrKeyword( #line 1523 "VBNET.ATG" out name); #line 1523 "VBNET.ATG" pexpr = new FieldReferenceOrInvocationExpression(retExpr, name); break; } case 128: { ObjectCreateExpression( #line 1524 "VBNET.ATG" out expr); #line 1524 "VBNET.ATG" pexpr = expr; break; } case 76: case 83: { if (la.kind == 83) { lexer.NextToken(); } else if (la.kind == 76) { lexer.NextToken(); } else SynErr(218); Expect(25); Expr( #line 1525 "VBNET.ATG" out expr); Expect(12); TypeName( #line 1525 "VBNET.ATG" out type); Expect(26); #line 1525 "VBNET.ATG" pexpr = new CastExpression(type, expr); break; } case 60: case 61: case 62: case 63: case 64: case 65: case 67: case 69: case 70: case 73: case 74: case 75: { CastTarget( #line 1526 "VBNET.ATG" out type); Expect(25); Expr( #line 1526 "VBNET.ATG" out expr); Expect(26); #line 1526 "VBNET.ATG" pexpr = new CastExpression(type, expr, true); break; } case 44: { lexer.NextToken(); Expr( #line 1527 "VBNET.ATG" out expr); #line 1527 "VBNET.ATG" pexpr = new AddressOfExpression(expr); break; } case 103: { lexer.NextToken(); Expect(25); TypeName( #line 1528 "VBNET.ATG" out type); Expect(26); #line 1528 "VBNET.ATG" pexpr = new GetTypeExpression(type); break; } case 177: { lexer.NextToken(); SimpleExpr( #line 1529 "VBNET.ATG" out expr); Expect(114); TypeName( #line 1529 "VBNET.ATG" out type); #line 1529 "VBNET.ATG" pexpr = new TypeOfExpression(expr, type); break; } } while (la.kind == 10 || la.kind == 25) { if (la.kind == 10) { lexer.NextToken(); IdentifierOrKeyword( #line 1532 "VBNET.ATG" out name); #line 1532 "VBNET.ATG" pexpr = new FieldReferenceOrInvocationExpression(pexpr, name); } else { lexer.NextToken(); #line 1533 "VBNET.ATG" ArrayList parameters = new ArrayList(); if (StartOf(21)) { #line 1535 "VBNET.ATG" expr = null; if (StartOf(18)) { Argument( #line 1535 "VBNET.ATG" out expr); } #line 1535 "VBNET.ATG" parameters.Add(expr); while (la.kind == 12) { lexer.NextToken(); #line 1537 "VBNET.ATG" expr = null; if (StartOf(18)) { Argument( #line 1538 "VBNET.ATG" out expr); } #line 1538 "VBNET.ATG" parameters.Add(expr); } } Expect(26); #line 1541 "VBNET.ATG" pexpr = new InvocationExpression(pexpr, parameters); } } } else if (la.kind == 10) { lexer.NextToken(); IdentifierOrKeyword( #line 1545 "VBNET.ATG" out name); #line 1545 "VBNET.ATG" pexpr = new FieldReferenceOrInvocationExpression(pexpr, name); while (la.kind == 10 || la.kind == 25) { if (la.kind == 10) { lexer.NextToken(); IdentifierOrKeyword( #line 1547 "VBNET.ATG" out name); #line 1547 "VBNET.ATG" pexpr = new FieldReferenceOrInvocationExpression(pexpr, name); } else { lexer.NextToken(); #line 1548 "VBNET.ATG" ArrayList parameters = new ArrayList(); if (StartOf(21)) { #line 1550 "VBNET.ATG" expr = null; if (StartOf(18)) { Argument( #line 1550 "VBNET.ATG" out expr); } #line 1550 "VBNET.ATG" parameters.Add(expr); while (la.kind == 12) { lexer.NextToken(); #line 1552 "VBNET.ATG" expr = null; if (StartOf(18)) { Argument( #line 1553 "VBNET.ATG" out expr); } #line 1553 "VBNET.ATG" parameters.Add(expr); } } Expect(26); #line 1556 "VBNET.ATG" pexpr = new InvocationExpression(pexpr, parameters); } } } else SynErr(219); }
public object Visit(InvocationExpression invocationExpression, object data) { DebugOutput(invocationExpression); return String.Concat(invocationExpression.TargetObject.AcceptVisitor(this, data), GetParameters(invocationExpression.Parameters) ); }
public virtual object Visit(InvocationExpression invocationExpression, object data) { if (invocationExpression.TargetObject == null) { return data; } return invocationExpression.TargetObject.AcceptVisitor(this, data); }