internal static UnifiedSet <UnifiedArgument> AcceptVisitorAsArgs <T, TResult>( this IEnumerable <Expression> args, IAstVisitor <T, TResult> visitor, T data) { var uArgs = UnifiedSet <UnifiedArgument> .Create(); foreach (var arg in args) { var value = arg.AcceptVisitor(visitor, data); var uArg = value as UnifiedArgument; if (uArg != null) { uArgs.Add(uArg); } else { var uExpr = value as UnifiedExpression; if (uExpr != null) { uArgs.Add( UnifiedArgument.Create( uExpr, /*label*/ null, /*mod*/ null)); } } } return(uArgs); }
public UnifiedType WrapArray(UnifiedArgument argument = null) { return new UnifiedArrayType { Type = this, // argumentがnullの場合でもコレクションの要素にしたいため Arguments = Enumerable.Repeat(argument, 1).ToSet(), }; }
public UnifiedElement VisitNamedArgumentExpression( NamedArgumentExpression expr, object data) { var name = UnifiedVariableIdentifier.Create(expr.Name); var value = expr.Expression.TryAcceptForExpression(this); return(UnifiedArgument.Create(value: value, target: name)); }
public UnifiedElement VisitDirectionExpression( DirectionExpression expr, object data) { var mods = LookupModifier(expr.FieldDirection).ToSet(); var value = expr.Expression.TryAcceptForExpression(this); return(UnifiedArgument.Create(value, null, mods)); }
public override bool Visit(UnifiedArgument element, VisitorArgument arg) { // Javaはメソッド呼び出しにModifiersがないが element.Modifiers.TryAccept(this, arg); element.Target.TryAccept(this, arg, "", " = "); element.Value.TryAccept(this, arg); return(false); }
public override bool Visit(UnifiedArgument element, VisitorArgument arg) { Writer.Write("/*"); element.Modifiers.TryAccept(this, arg); Writer.Write("*/"); element.Value.TryAccept(this, arg); return(false); }
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() )); }
// Expressions public static UnifiedSet <UnifiedArgument> CreateArgumentExpressionList( XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "argument_expression_list"); /* * argument_expression_list * : assignment_expression (',' assignment_expression)* */ var arguments = node.Elements("assignment_expression"). Select(CreateAssignmentExpression). Select(e => UnifiedArgument.Create(e)); return(UnifiedSet <UnifiedArgument> .Create(arguments)); }
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 override bool Visit(UnifiedArgument element, VisitorArgument arg) { // Javaはメソッド呼び出しにModifiersがないが element.Modifiers.TryAccept(this, arg); element.Target.TryAccept(this, arg, "", " = "); element.Value.TryAccept(this, arg); return 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); }
//実引数 public override bool Visit(UnifiedArgument element, VisitorArgument arg) { element.Value.TryAccept(this, arg); return false; }
// 実引数(UnifiedArgument) public override bool Visit(UnifiedArgument element, VisitorArgument arg) { // element.Target.TryAccept(this, arg, "", " = "); // TODO Targetが何か確認 element.Value.TryAccept(this, arg); return false; }
public override bool Visit(UnifiedArgument element, VisitorArgument arg) { Writer.Write("/*"); element.Modifiers.TryAccept(this, arg); Writer.Write("*/"); element.Value.TryAccept(this, arg); return false; }
//実引数 public override bool Visit(UnifiedArgument element, VisitorArgument arg) { element.Value.TryAccept(this, arg); return(false); }