コード例 #1
0
ファイル: RefExpression.cs プロジェクト: belav/csharpier
 public static Doc Print(RefExpressionSyntax node)
 {
     return(Doc.Concat(
                Token.PrintWithSuffix(node.RefKeyword, " "),
                Node.Print(node.Expression)
                ));
 }
コード例 #2
0
 private Doc PrintRefExpressionSyntax(RefExpressionSyntax node)
 {
     // TODO 1 should all " " turn into spaceIfNoPreviousComment? Maybe we just make a type for space and make it do that?
     return(Concat(
                this.PrintSyntaxToken(node.RefKeyword, " "),
                this.Print(node.Expression)
                ));
 }
コード例 #3
0
        public override void VisitRefExpression(RefExpressionSyntax node)
        {
            if (!PreVisit(node))
            {
                return;
            }

            node.Expression?.Accept(this);

            base.VisitRefExpression(node);

            PostVisit(node);
        }
コード例 #4
0
        public override void VisitRefExpression(RefExpressionSyntax node)
        {
            ExpressionSyntax expression = node.Expression;

            if (expression != null)
            {
                VisitAssignedExpression(expression);
            }
            else
            {
                base.VisitRefExpression(node);
            }
        }
コード例 #5
0
ファイル: Expression.cs プロジェクト: binarybird/Cascade
        public override Evaluation VisitRefExpression(RefExpressionSyntax node)
        {
            node.Expression?.Accept <Evaluation>(this);

            return(base.VisitRefExpression(node));
        }
コード例 #6
0
 public override void VisitRefExpression(RefExpressionSyntax node)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
ファイル: FuncGenerator.cs プロジェクト: jake-bladt/Fuzzlyn
        private StatementSyntax GenAssignmentStatement()
        {
            LValueInfo lvalue = null;

            if (!Random.FlipCoin(Options.AssignToNewVarProb))
            {
                lvalue = GenExistingLValue(null, int.MinValue);
            }

            if (lvalue == null)
            {
                FuzzType newType = Types.PickType(Options.LocalIsByRefProb);
                // Determine if we should create a new local. We do this with a certain probabilty,
                // or always if the new type is a by-ref type (we cannot have static by-refs).
                if (newType is RefType || Random.FlipCoin(Options.NewVarIsLocalProb))
                {
                    VariableIdentifier variable;
                    string             varName = $"var{_varCounter++}";
                    ExpressionSyntax   rhs;
                    if (newType is RefType newRt)
                    {
                        LValueInfo rhsLV = GenLValue(newRt.InnerType, int.MinValue);
                        variable = new VariableIdentifier(newType, varName, rhsLV.RefEscapeScope);
                        rhs      = RefExpression(rhsLV.Expression);
                    }
                    else
                    {
                        rhs      = GenExpression(newType);
                        variable = new VariableIdentifier(newType, varName, -(_scope.Count - 1));
                    }

                    LocalDeclarationStatementSyntax decl =
                        LocalDeclarationStatement(
                            VariableDeclaration(
                                variable.Type.GenReferenceTo(),
                                SingletonSeparatedList(
                                    VariableDeclarator(variable.Name)
                                    .WithInitializer(
                                        EqualsValueClause(rhs)))));

                    _scope.Last().Variables.Add(variable);

                    return(decl);
                }

                StaticField newStatic = Statics.GenerateNewField(newType);
                lvalue = new LValueInfo(IdentifierName(newStatic.Var.Name), newType, int.MaxValue);
            }

            // Determine if we should generate a ref-reassignment. In that case we cannot do anything
            // clever, like generate compound assignments.
            FuzzType rhsType = lvalue.Type;

            if (lvalue.Type is RefType rt)
            {
                if (Random.FlipCoin(Options.AssignGenRefReassignProb))
                {
                    RefExpressionSyntax refRhs = RefExpression(GenLValue(rt.InnerType, lvalue.RefEscapeScope).Expression);
                    return
                        (ExpressionStatement(
                             AssignmentExpression(
                                 SyntaxKind.SimpleAssignmentExpression,
                                 lvalue.Expression,
                                 refRhs)));
                }

                // We have a ref-type, but are not generating a ref-reassign, so lift the type and make a normal assignment.
                rhsType = rt.InnerType;
            }

            SyntaxKind assignmentKind = SyntaxKind.SimpleAssignmentExpression;

            // Determine if we should generate compound assignment.
            if (rhsType.AllowedAdditionalAssignmentKinds.Length > 0 && Random.FlipCoin(Options.CompoundAssignmentProb))
            {
                assignmentKind = Random.NextElement(rhsType.AllowedAdditionalAssignmentKinds);
            }

            // Early our for simple cases.
            if (assignmentKind == SyntaxKind.PreIncrementExpression ||
                assignmentKind == SyntaxKind.PreDecrementExpression)
            {
                return(ExpressionStatement(PrefixUnaryExpression(assignmentKind, lvalue.Expression)));
            }

            if (assignmentKind == SyntaxKind.PostIncrementExpression ||
                assignmentKind == SyntaxKind.PostDecrementExpression)
            {
                return(ExpressionStatement(PostfixUnaryExpression(assignmentKind, lvalue.Expression)));
            }

            // Right operand of shifts are always ints.
            if (assignmentKind == SyntaxKind.LeftShiftAssignmentExpression ||
                assignmentKind == SyntaxKind.RightShiftAssignmentExpression)
            {
                rhsType = Types.GetPrimitiveType(SyntaxKind.IntKeyword);
            }

            ExpressionSyntax right = GenExpression(rhsType);

            // For modulo and division we don't want to throw divide-by-zero exceptions,
            // so always or right-hand-side with 1.
            if (assignmentKind == SyntaxKind.ModuloAssignmentExpression ||
                assignmentKind == SyntaxKind.DivideAssignmentExpression)
            {
                right =
                    CastExpression(
                        rhsType.GenReferenceTo(),
                        ParenthesizedExpression(
                            BinaryExpression(
                                SyntaxKind.BitwiseOrExpression,
                                ParenthesizeIfNecessary(right),
                                LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1)))));
            }

            return(ExpressionStatement(AssignmentExpression(assignmentKind, lvalue.Expression, right)));
        }
コード例 #8
0
 /// <inheritdoc />
 public override Expression VisitRefExpression(RefExpressionSyntax node)
 {
     return(node.Expression.Accept(this));
 }
コード例 #9
0
 public TameRefExpressionSyntax(RefExpressionSyntax node)
 {
     Node = node;
     AddChildren();
 }
コード例 #10
0
 public override void VisitRefExpression(RefExpressionSyntax node)
 {
     this.VisitExpression(node);
 }
コード例 #11
0
 public override void VisitRefExpression(RefExpressionSyntax node)
 {
     LogUnsupportedSyntax(node);
 }
コード例 #12
0
 public override void VisitRefExpression(RefExpressionSyntax node)
 {
 }
コード例 #13
0
        public override void VisitRefExpression(RefExpressionSyntax node)
        {
            node.Expression?.Accept(this);

            base.VisitRefExpression(node);
        }
コード例 #14
0
 //
 // Summary:
 //     Called when the visitor visits a RefExpressionSyntax node.
 public virtual void VisitRefExpression(RefExpressionSyntax node);