Exemplo n.º 1
0
        /// <summary>
        /// Creates and populates a recursive pattern.
        /// </summary>
        /// <param name="cx">The extraction context.</param>
        /// <param name="syntax">The syntax node of the recursive pattern.</param>
        /// <param name="parent">The parent pattern/expression.</param>
        /// <param name="child">The child index of this pattern.</param>
        /// <param name="isTopLevel">If this pattern is in the top level of a case/is. In that case, the variable and type access are populated elsewhere.</param>
        public RecursivePattern(Context cx, RecursivePatternSyntax syntax, IExpressionParentEntity parent, int child) :
            base(new ExpressionInfo(cx, Type.Create(cx, null), cx.Create(syntax.GetLocation()), ExprKind.RECURSIVE_PATTERN, parent, child, false, null))
        {
            // Extract the type access
            if (syntax.Type is TypeSyntax t)
            {
                Expressions.TypeAccess.Create(cx, t, this, 1);
            }

            // Extract the local variable declaration
            if (syntax.Designation is VariableDesignationSyntax designation && cx.Model(syntax).GetDeclaredSymbol(designation) is ILocalSymbol symbol)
            {
                var type = Type.Create(cx, symbol.Type);

                VariableDeclaration.Create(cx, symbol, type, cx.Create(syntax.GetLocation()), cx.Create(designation.GetLocation()), false, this, 0);
            }

            if (syntax.PositionalPatternClause is PositionalPatternClauseSyntax posPc)
            {
                new PositionalPattern(cx, posPc, this, 2);
            }

            if (syntax.PropertyPatternClause is PropertyPatternClauseSyntax pc)
            {
                new PropertyPattern(cx, pc, this, 3);
            }
        }
Exemplo n.º 2
0
 private Doc PrintRecursivePatternSyntax(RecursivePatternSyntax node)
 {
     return(Concat(
                node.Type != null ? this.Print(node.Type) : Doc.Null,
                node.PositionalPatternClause != null
             ? Concat(
                    this.PrintSyntaxToken(
                        node.PositionalPatternClause.OpenParenToken
                        ),
                    this.PrintSeparatedSyntaxList(
                        node.PositionalPatternClause.Subpatterns,
                        subpatternNode => Concat(
                            subpatternNode.NameColon != null
                             ? this.PrintNameColonSyntax(
                                subpatternNode.NameColon
                                )
                             : string.Empty,
                            this.Print(subpatternNode.Pattern)
                            ),
                        " "
                        ),
                    this.PrintSyntaxToken(
                        node.PositionalPatternClause.CloseParenToken
                        )
                    )
             : string.Empty,
                node.PropertyPatternClause != null
             ? Concat(
                    " ",
                    this.PrintSyntaxToken(
                        node.PropertyPatternClause.OpenBraceToken,
                        " "
                        ),
                    this.PrintSeparatedSyntaxList(
                        node.PropertyPatternClause.Subpatterns,
                        subpatternNode => Concat(
                            subpatternNode.NameColon != null
                             ? this.PrintNameColonSyntax(
                                subpatternNode.NameColon
                                )
                             : Doc.Null,
                            this.Print(subpatternNode.Pattern)
                            ),
                        " "
                        ),
                    SpaceIfNoPreviousComment,
                    this.PrintSyntaxToken(
                        node.PropertyPatternClause.CloseBraceToken,
                        " "
                        )
                    )
             : string.Empty,
                node.Designation != null
             ? this.Print(node.Designation)
             : string.Empty
                ));
 }
Exemplo n.º 3
0
        public override void VisitRecursivePattern(RecursivePatternSyntax node)
        {
            TFieldOrLocalSymbol variable = MakePatternVariable(node, _nodeToBind);

            if ((object)variable != null)
            {
                _variablesBuilder.Add(variable);
            }

            base.VisitRecursivePattern(node);
        }
Exemplo n.º 4
0
 protected override Symbol MakePatternVariable(
     RecursivePatternSyntax node,
     SyntaxNode nodeToBind
     )
 {
     return(MakePatternVariable(
                node.Type,
                node.Designation as SingleVariableDesignationSyntax,
                nodeToBind
                ));
 }
Exemplo n.º 5
0
        public override void VisitRecursivePattern(RecursivePatternSyntax node)
        {
            Debug.Assert(node.Designation is null or SingleVariableDesignationSyntax or DiscardDesignationSyntax);
            TFieldOrLocalSymbol variable = MakePatternVariable(node.Type, node.Designation as SingleVariableDesignationSyntax, _nodeToBind);

            if ((object)variable != null)
            {
                _variablesBuilder.Add(variable);
            }

            base.VisitRecursivePattern(node);
        }
Exemplo n.º 6
0
 public static Doc Print(RecursivePatternSyntax node)
 {
     return(Doc.Concat(
                node.Type != null ? Doc.Concat(Node.Print(node.Type), " ") : Doc.Null,
                node.PositionalPatternClause != null
             ? Doc.Concat(
                    Token.Print(node.PositionalPatternClause.OpenParenToken),
                    SeparatedSyntaxList.Print(
                        node.PositionalPatternClause.Subpatterns,
                        subpatternNode =>
                        Doc.Concat(
                            subpatternNode.NameColon != null
                                     ? NameColon.Print(subpatternNode.NameColon)
                                     : string.Empty,
                            Node.Print(subpatternNode.Pattern)
                            ),
                        " "
                        ),
                    Token.Print(node.PositionalPatternClause.CloseParenToken)
                    )
             : string.Empty,
                node.PropertyPatternClause != null
             ? Doc.Concat(
                    Token.PrintWithSuffix(node.PropertyPatternClause.OpenBraceToken, " "),
                    SeparatedSyntaxList.Print(
                        node.PropertyPatternClause.Subpatterns,
                        subpatternNode =>
                        Doc.Concat(
                            subpatternNode.NameColon != null
                                     ? NameColon.Print(subpatternNode.NameColon)
                                     : Doc.Null,
                            Node.Print(subpatternNode.Pattern)
                            ),
                        " "
                        ),
                    node.PropertyPatternClause.Subpatterns.Any() ? " " : Doc.Null,
                    Token.Print(node.PropertyPatternClause.CloseBraceToken)
                    )
             : string.Empty,
                node.Designation != null
             ? Doc.Concat(" ", Node.Print(node.Designation))
             : string.Empty
                ));
 }
Exemplo n.º 7
0
 protected abstract TFieldOrLocalSymbol MakePatternVariable(RecursivePatternSyntax node, SyntaxNode nodeToBind);
    /// <inheritdoc/>
    public override SyntaxNode?VisitRecursivePattern(RecursivePatternSyntax node)
    {
        Diagnostics.Add(RecursivePattern, node);

        return(base.VisitRecursivePattern(node));
    }
Exemplo n.º 9
0
 public override void VisitRecursivePattern(RecursivePatternSyntax node)
 {
     Log(node, "Unsupported Syntax !");
 }
        /// <inheritdoc/>
        public override SyntaxNode?VisitRecursivePattern(RecursivePatternSyntax node)
        {
            Context.ReportDiagnostic(RecursivePattern, node);

            return(base.VisitRecursivePattern(node));
        }