public UnifiedElement VisitAssignmentExpression( AssignmentExpression assign, object data) { var op = LookupAssignOperator(assign.Operator); var left = assign.Left.TryAcceptForExpression(this); var right = assign.Right.TryAcceptForExpression(this); return(UnifiedBinaryExpression.Create(left, op, right)); }
private static UnifiedExpression CreateMatch3(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "match3"); return(UnifiedBinaryExpression.Create( CreateExpresion(node.FirstElement()), UnifiedBinaryOperator.Create( "=~", UnifiedBinaryOperatorKind.RegexEqual), CreateExpresion(node.LastElement()))); }
public UnifiedElement VisitAsExpression( AsExpression asExpr, object data) { var op = UnifiedBinaryOperator.Create( "as", UnifiedBinaryOperatorKind.As); var value = asExpr.Expression.TryAcceptForExpression(this); var type = LookupType(asExpr.Type); return(UnifiedBinaryExpression.Create(value, op, type)); }
private static UnifiedExpression CreateOpAsgnAnd(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "op_asgn_and"); // 優先順位の違いはASTの深さ(&& / and) return(UnifiedBinaryExpression.Create( CreateExpresion(node.FirstElement()), UnifiedBinaryOperator.Create( "&&=", UnifiedBinaryOperatorKind.AndAlsoAssign), CreateExpresion(node.LastElement()))); }
public void compares_same_expressions_containing_null() { var o2 = UnifiedBinaryExpression.Create( UnifiedVariableIdentifier.Create("n"), null, UnifiedInt32Literal.Create(1)); var o1 = o2; Assert.That( StructuralEqualityComparer.StructuralEquals(o1, o2), Is.True); }
private static UnifiedExpression CreateOpAsgnOr(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "op_asgn_or"); // 優先順位の違いはASTの深さ(|| / or) return(UnifiedBinaryExpression.Create( CreateExpresion(node.FirstElement()), UnifiedBinaryOperator.Create( "||=", UnifiedBinaryOperatorKind.OrElseAssign), CreateExpresion(node.LastElement()))); }
public override bool Visit( UnifiedBinaryExpression element, VisitorArgument arg) { var paren = GetRequiredParen(element); Writer.Write(paren.Item1); element.LeftHandSide.TryAccept(this, arg.Set(Paren)); Writer.Write(" "); element.Operator.TryAccept(this, arg); Writer.Write(" "); element.RightHandSide.TryAccept(this, arg.Set(Paren)); Writer.Write(paren.Item2); return false; }
public void compares_same_expressions() { var o2 = UnifiedBinaryExpression.Create( UnifiedVariableIdentifier.Create("n"), UnifiedBinaryOperator.Create( "-", UnifiedBinaryOperatorKind.Subtract), UnifiedInt32Literal.Create(1)); var o1 = o2; Assert.That( StructuralEqualityComparer.StructuralEquals(o1, o2), Is.True); }
public override bool Visit( UnifiedBinaryExpression element, VisitorArgument arg) { var paren = GetRequiredParen(element); Writer.Write(paren.Item1); element.LeftHandSide.TryAccept(this, arg.Set(Paren)); Writer.Write(" "); element.Operator.TryAccept(this, arg); Writer.Write(" "); element.RightHandSide.TryAccept(this, arg.Set(Paren)); Writer.Write(paren.Item2); return(false); }
private static UnifiedExpression CreateOpAsgn1(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "op_asgn1"); var expression = UnifiedIndexer.Create( CreateExpresion(node.FirstElement()), CreateArglist(node.NthElement(1))); return(UnifiedBinaryExpression.Create( expression, Sign2BinaryOperator[node.NthElement(2).Value + "="].DeepCopy (), CreateExpresion(node.LastElement()))); }
public static UnifiedBinaryExpression CreateAsgn(XElement node) { Contract.Requires(node != null); Contract.Requires( node.Name() == "lasgn" || node.Name() == "masgn" || node.Name() == "iasgn" || node.Name() == "gasgn" || node.Name() == "cvdecl" || node.Name() == "cdecl"); return(UnifiedBinaryExpression.Create( CreateExpresion(node.FirstElement()), UnifiedBinaryOperator.Create( "=", UnifiedBinaryOperatorKind.Assign), CreateExpresion(node.LastElement()))); }
/// <summary> /// 指定したXMLノードから左結合のBinaryExpressionを作成します. /// </summary> /// <param name="node"> </param> /// <param name="firstCreateExpression"> </param> /// <param name="otherCreateExpression"> </param> /// <param name="op2Kind"> </param> /// <returns> </returns> public static UnifiedExpression CreateBinaryExpression( XElement node, Func <XElement, UnifiedExpression> firstCreateExpression, Func <XElement, UnifiedExpression> otherCreateExpression, IDictionary <string, UnifiedBinaryOperator> op2Kind) { var nodes = node.Elements().OddIndexElements(); return(nodes.AggregateApartFirst( firstCreateExpression, (e, n) => UnifiedBinaryExpression.Create( e, op2Kind[n.PreviousElement().Value].DeepCopy(), otherCreateExpression(n)))); }
public void compares_different_expressions_containing_null() { var o1 = UnifiedBinaryExpression.Create( UnifiedVariableIdentifier.Create("n"), null, UnifiedInt32Literal.Create(1)); var o2 = UnifiedBinaryExpression.Create( UnifiedVariableIdentifier.Create("n"), UnifiedBinaryOperator.Create( null, UnifiedBinaryOperatorKind.Add), UnifiedInt32Literal.Create(1)); Assert.That( StructuralEqualityComparer.StructuralEquals(o1, o2), Is.False); }
private static UnifiedExpression CreateOpAsgn2(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "op_asgn2"); var propName = node.NthElement(1).Value; var expression = UnifiedProperty.Create( ".", CreateExpresion(node.FirstElement()), UnifiedVariableIdentifier.Create( propName.Substring(0, propName.Length - 1))); return(UnifiedBinaryExpression.Create( expression, Sign2BinaryOperator[node.NthElement(2).Value + "="].DeepCopy (), CreateExpresion(node.LastElement()))); }
// 指定された2項式を括弧でくくる必要があるかどうかを判定します protected bool GetRequiredParen(UnifiedBinaryExpression exp) { var parent = exp.Parent; var parentExp = parent as UnifiedBinaryExpression; // 2項式がネストしている場合 if (parentExp != null) { if (exp.Operator.Kind == parentExp.Operator.Kind) { // 左結合の演算子である場合、自分が親の左オペランドである場合には括弧は必要でない // e.g. exp -> 1+2, parent -> (1+2)+3, parent.LeftHandSide -> 1+2 if (IsLeftAssociative(exp.Operator)) { var left = parentExp.LeftHandSide as UnifiedBinaryExpression; if (exp == left) { return(false); } } else if (IsRightAssociative(exp.Operator)) { // 右結合の演算子である場合、自分が親の右オペランドである場合には括弧は必要でない // e.g. exp -> b=c, parent -> a=(b=c), parent.RightHandSide -> b=c var right = parentExp.RightHandSide as UnifiedBinaryExpression; if (exp == right) { return(false); } } } return(true); } // 2項式以外とネストしている場合は親が以下の要素であれば括弧が必要となる return(parent is UnifiedFunctionDefinition || parent is UnifiedIndexer || parent is UnifiedProperty || parent is UnifiedCast || parent is UnifiedUnaryExpression || parent is UnifiedTernaryExpression); }
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 void compares_same_blocks() { var o1 = UnifiedBlock.Create( new UnifiedExpression[] { UnifiedBinaryExpression.Create( UnifiedVariableIdentifier.Create("n"), UnifiedBinaryOperator.Create( "=", UnifiedBinaryOperatorKind.Assign), UnifiedInt32Literal.Create(1)), UnifiedReturn.Create( UnifiedInt32Literal.Create(2)), }); var o2 = o1; Assert.That( StructuralEqualityComparer.StructuralEquals(o1, o2), Is.True); }
protected bool GetRequiredParen(UnifiedBinaryExpression exp) { var parent = exp.Parent; var parentExp = parent as UnifiedBinaryExpression; if (parentExp != null) { if (exp.Operator.Kind == parentExp.Operator.Kind) { if (IsLeftAssociative(exp.Operator)) { var left = parentExp.LeftHandSide as UnifiedBinaryExpression; if (exp == left) { return(false); } } else if (IsRightAssociative(exp.Operator)) { var right = parentExp.RightHandSide as UnifiedBinaryExpression; if (exp == right) { return(false); } } } return(true); } return(parent is UnifiedFunctionDefinition || parent is UnifiedIndexer || parent is UnifiedProperty || parent is UnifiedCast || parent is UnifiedUnaryExpression || parent is UnifiedTernaryExpression); }
protected bool GetRequiredParen(UnifiedBinaryExpression exp) { var parent = exp.Parent; var parentExp = parent as UnifiedBinaryExpression; if (parentExp != null) { if (exp.Operator.Kind == parentExp.Operator.Kind) { if (IsLeftAssociative(exp.Operator)) { var left = parentExp.LeftHandSide as UnifiedBinaryExpression; if (exp == left) { return false; } } else if (IsRightAssociative(exp.Operator)) { var right = parentExp.RightHandSide as UnifiedBinaryExpression; if (exp == right) { return false; } } } return true; } return parent is UnifiedFunctionDefinition || parent is UnifiedIndexer || parent is UnifiedProperty || parent is UnifiedCast || parent is UnifiedUnaryExpression || parent is UnifiedTernaryExpression; }
// 指定された2項式を括弧でくくる必要があるかどうかを判定します protected bool GetRequiredParen(UnifiedBinaryExpression exp) { var parent = exp.Parent; var parentExp = parent as UnifiedBinaryExpression; // 2項式がネストしている場合 if (parentExp != null) { if (exp.Operator.Kind == parentExp.Operator.Kind) { // 左結合の演算子である場合、自分が親の左オペランドである場合には括弧は必要でない // e.g. exp -> 1+2, parent -> (1+2)+3, parent.LeftHandSide -> 1+2 if (IsLeftAssociative(exp.Operator)) { var left = parentExp.LeftHandSide as UnifiedBinaryExpression; if (exp == left) { return false; } } else if (IsRightAssociative(exp.Operator)) { // 右結合の演算子である場合、自分が親の右オペランドである場合には括弧は必要でない // e.g. exp -> b=c, parent -> a=(b=c), parent.RightHandSide -> b=c var right = parentExp.RightHandSide as UnifiedBinaryExpression; if (exp == right) { return false; } } } return true; } // 2項式以外とネストしている場合は親が以下の要素であれば括弧が必要となる return parent is UnifiedFunctionDefinition || parent is UnifiedIndexer || parent is UnifiedProperty || parent is UnifiedCast || parent is UnifiedUnaryExpression || parent is UnifiedTernaryExpression; }