Ejemplo n.º 1
0
        private BoundExpression MakeIsDeclarationPattern(BoundDeclarationPattern loweredPattern, BoundExpression loweredInput)
        {
            Debug.Assert(((object)loweredPattern.Variable == null && loweredPattern.VariableAccess.Kind == BoundKind.DiscardExpression) ||
                         loweredPattern.Variable.GetTypeOrReturnType() == loweredPattern.DeclaredType.Type);

            if (loweredPattern.IsVar)
            {
                var result = _factory.Literal(true);

                if (loweredPattern.VariableAccess.Kind == BoundKind.DiscardExpression)
                {
                    return(result);
                }

                Debug.Assert((object)loweredPattern.Variable != null && loweredInput.Type == loweredPattern.Variable.GetTypeOrReturnType());

                var assignment = _factory.AssignmentExpression(loweredPattern.VariableAccess, loweredInput);
                return(_factory.MakeSequence(assignment, result));
            }

            if (loweredPattern.VariableAccess.Kind == BoundKind.DiscardExpression)
            {
                LocalSymbol temp;
                BoundLocal  discard = _factory.MakeTempForDiscard((BoundDiscardExpression)loweredPattern.VariableAccess, out temp);

                return(_factory.Sequence(ImmutableArray.Create(temp),
                                         sideEffects: ImmutableArray <BoundExpression> .Empty,
                                         result: MakeIsDeclarationPattern(loweredPattern.Syntax, loweredInput, discard, requiresNullTest: true)));
            }

            return(MakeIsDeclarationPattern(loweredPattern.Syntax, loweredInput, loweredPattern.VariableAccess, requiresNullTest: true));
        }
Ejemplo n.º 2
0
        public override BoundNode VisitDeclarationPattern(BoundDeclarationPattern node)
        {
            if (IsInside)
            {
                _variablesDeclared.Add(node.LocalSymbol);
            }

            return(base.VisitDeclarationPattern(node));
        }
Ejemplo n.º 3
0
        private BoundExpression LowerDeclarationPattern(BoundDeclarationPattern pattern, BoundExpression input)
        {
            Debug.Assert(pattern.IsVar || pattern.LocalSymbol.Type == pattern.DeclaredType.Type);
            if (pattern.IsVar)
            {
                Debug.Assert(input.Type == pattern.LocalSymbol.Type);
                var assignment = _factory.AssignmentExpression(_factory.Local(pattern.LocalSymbol), input);
                var result     = _factory.Literal(true);
                return(_factory.MakeSequence(assignment, result));
            }

            return(MakeDeclarationPattern(pattern.Syntax, input, pattern.LocalSymbol, requiresNullTest: true));
        }
Ejemplo n.º 4
0
        private BoundExpression MakeIsDeclarationPattern(BoundDeclarationPattern loweredPattern, BoundExpression loweredInput)
        {
            Debug.Assert(loweredPattern.Variable.GetTypeOrReturnType() == loweredPattern.DeclaredType.Type);

            if (loweredPattern.IsVar)
            {
                Debug.Assert(loweredInput.Type == loweredPattern.Variable.GetTypeOrReturnType());
                var assignment = _factory.AssignmentExpression(loweredPattern.VariableAccess, loweredInput);
                var result     = _factory.Literal(true);
                return(_factory.MakeSequence(assignment, result));
            }

            return(MakeIsDeclarationPattern(loweredPattern.Syntax, loweredInput, loweredPattern.VariableAccess, requiresNullTest: true));
        }
Ejemplo n.º 5
0
        private BoundExpression LowerDeclarationPattern(BoundDeclarationPattern pattern, BoundExpression input)
        {
            Debug.Assert(pattern.Variable.GetTypeOrReturnType() == pattern.DeclaredType.Type);
            var variableAccess = VisitExpression(pattern.VariableAccess);

            if (pattern.IsVar)
            {
                Debug.Assert(input.Type == pattern.Variable.GetTypeOrReturnType());
                var assignment = _factory.AssignmentExpression(variableAccess, input);
                var result     = _factory.Literal(true);
                return(_factory.MakeSequence(assignment, result));
            }

            return(MakeDeclarationPattern(pattern.Syntax, input, variableAccess, requiresNullTest: true));
        }
Ejemplo n.º 6
0
 public override BoundNode VisitDeclarationPattern(BoundDeclarationPattern node)
 {
     Visit(node.VariableAccess);
     Visit(node.DeclaredType);
     return(null);
 }