private static UnifiedExpression CreateZsuper(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "zsuper"); // 引数を省略するとコンストラクタと同じ引数を渡す return(UnifiedCall.Create( UnifiedSuperIdentifier.Create("super"))); }
public UnifiedElement VisitInvocationExpression( InvocationExpression invoc, object data) { var target = invoc.Target.TryAcceptForExpression(this); var uArgs = invoc.Arguments.AcceptVisitorAsArgs(this, data); return(UnifiedCall.Create(target, uArgs)); }
private static IEnumerable <UnifiedExpression> CreateCallExpression(StaticCallExpression statement) { var args = from ph in statement.Phrases.OfType <ActualComplementPhrase>() let arg = CreatePhrase(ph.PrefixExpression) let sfx = ph.Particle.Text select UnifiedArgument.Create(arg, UnifiedIdentifier.CreateVariable(sfx)); yield return (UnifiedCall.Create( UnifiedIdentifier.CreateVariable(statement.MethodInfo.Name), args.ToSet())); }
private static UnifiedExpression CreateSuper(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "super"); // 引数を省略するとコンストラクタと同じ引数を渡す return(UnifiedCall.Create( UnifiedSuperIdentifier.Create("super"), node.Elements() .Select(CreateExpresion) .Select(e => UnifiedArgument.Create(e)) .ToSet() )); }
public static UnifiedCall CreateCall(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "call"); // TODO: 演算子への変換 var receiver = CreateExpresion(node.NthElement(0)); var secondNode = node.NthElement(1); return(UnifiedCall.Create( receiver != null ? UnifiedProperty.Create( ".", receiver, CreateExpresion(secondNode)) : CreateExpresion(secondNode), CreateArglist(node.NthElement(2)))); }
public void compares_different_calls() { var o1 = UnifiedCall.Create( UnifiedVariableIdentifier.Create("f"), UnifiedSet <UnifiedArgument> .Create( UnifiedArgument.Create( UnifiedVariableIdentifier.Create( "a"), null, null), UnifiedArgument.Create( UnifiedBinaryExpression.Create( UnifiedVariableIdentifier. Create("n"), UnifiedBinaryOperator.Create ( "-", UnifiedBinaryOperatorKind .Add), UnifiedInt32Literal.Create( 1) ), null, null))); var o2 = UnifiedCall.Create( UnifiedVariableIdentifier.Create("f"), UnifiedSet <UnifiedArgument> .Create( UnifiedArgument.Create( UnifiedVariableIdentifier.Create( "a"), null, null), UnifiedArgument.Create( UnifiedBinaryExpression.Create( UnifiedVariableIdentifier. Create("n2"), UnifiedBinaryOperator.Create ( "-", UnifiedBinaryOperatorKind .Add), UnifiedInt32Literal.Create( 1)), null, null))); Assert.That( StructuralEqualityComparer.StructuralEquals(o1, o2), Is.False); }
public static UnifiedExpression CreatePostfixExpression(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "postfix_expression"); /* * postfix_expression * : primary_expression * ( '[' expression ']' | '(' ')' | '(' argument_expression_list ')' | '.' IDENTIFIER | '->' IDENTIFIER | '++' | '--' | )* */ var result = CreatePrimaryExpression(node.Element("primary_expression")); var elements = node.Elements().Skip(1); //先頭以外のすべての要素を取得 var length = elements.Count(); for (var i = 0; i < length; i++) { switch (elements.ElementAt(i++).Value) { case "[": result = UnifiedIndexer.Create( result, UnifiedSet <UnifiedArgument> .Create( UnifiedArgument.Create( CreateExpression( elements.ElementAt(i++)). ElementAt(0)))); i++; // ']'読み飛ばし break; case "(": if (elements.ElementAt(i).Name == "argument_expression_list") { result = UnifiedCall.Create( result, CreateArgumentExpressionList( elements.ElementAt(i++))); } else { result = UnifiedCall.Create( result, UnifiedSet <UnifiedArgument> .Create()); } i++; // ')'読み飛ばし break; case ".": result = UnifiedProperty.Create( ".", result, UnifiedIdentifier.CreateVariable( elements.ElementAt(i++).Value)); break; case "->": result = UnifiedProperty.Create( "->", result, UnifiedIdentifier.CreateVariable( elements.ElementAt(i++).Value)); // TODO ポインタ型に展開してから処理するのか? break; case "++": result = UnifiedUnaryExpression.Create( result, UnifiedUnaryOperator.Create( "++", UnifiedUnaryOperatorKind.PostIncrementAssign)); break; case "--": result = UnifiedUnaryExpression.Create( result, UnifiedUnaryOperator.Create( "--", UnifiedUnaryOperatorKind.PostDecrementAssign)); break; default: throw new InvalidOperationException(); } } return(result); }