Beispiel #1
0
 public static glsl.EqualsValueClauseSyntax Translate(this cs.EqualsValueClauseSyntax node)
 {
     return(new glsl.EqualsValueClauseSyntax().Update(
                node.EqualsToken,
                node.Value.Translate()
                ));
 }
        public static LocalDeclarationStatementSyntax Declaration(string type, string variableName, EqualsValueClauseSyntax equalsValue)
        {           
            return SyntaxFactory.LocalDeclarationStatement(
                            SyntaxFactory.VariableDeclaration(Identifier.Name(type))
                            .WithVariables(Declarator(variableName, equalsValue).AsList()))
                        .WithSemicolonToken(Token.SemiColon);

        }
 public static FieldDeclarationSyntax PrivateDeclation(string type, string variableName, EqualsValueClauseSyntax equalsValue)
 {
     return SyntaxFactory.FieldDeclaration(Declaration(SyntaxFactory.ParseTypeName(type),
                                               SyntaxFactory.VariableDeclarator(
                                                   Identifier.Token(variableName), 
                                                   null, 
                                                   equalsValue)))
                                                   .WithModifiers(Token.Private.AsList());
 }
Beispiel #4
0
 public static SourceLocalSymbol MakeLocal(
     MethodSymbol containingMethod,
     Binder binder,
     TypeSyntax typeSyntax,
     SyntaxToken identifierToken,
     EqualsValueClauseSyntax initializer,
     LocalDeclarationKind declarationKind)
 {
     Debug.Assert(declarationKind != LocalDeclarationKind.ForEach);
     return new SourceLocalSymbol(containingMethod, binder, typeSyntax, identifierToken, initializer, null, declarationKind);
 }
Beispiel #5
0
 public static SourceLocalSymbol MakeLocalWithInitializer(
     Symbol containingSymbol,
     Binder binder,
     TypeSyntax typeSyntax,
     SyntaxToken identifierToken,
     EqualsValueClauseSyntax initializer,
     LocalDeclarationKind declarationKind)
 {
     Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
     return new LocalWithInitializer(containingSymbol, binder, typeSyntax, identifierToken, initializer, declarationKind);
 }
Beispiel #6
0
        private CSSyntax.VariableDeclarationSyntax CreateVariableDeclaration(VariableDeclaratorSyntax vbDeclarator, bool preferExplicitType,
                                                                             bool requireExplicitTypeForAll, ITypeSymbol vbInitializerType, ITypeSymbol declaredSymbolType,
                                                                             CSSyntax.EqualsValueClauseSyntax equalsValueClauseSyntax, IMethodSymbol initSymbol, CSSyntax.VariableDeclaratorSyntax v)
        {
            var requireExplicitType = requireExplicitTypeForAll ||
                                      vbInitializerType != null && !Equals(declaredSymbolType, vbInitializerType);
            bool useVar     = equalsValueClauseSyntax != null && !preferExplicitType && !requireExplicitType;
            var  typeSyntax = initSymbol == null || !initSymbol.IsAnonymousFunction()
                ? GetTypeSyntax(declaredSymbolType, useVar)
                : GetFuncTypeSyntax(initSymbol);

            return(SyntaxFactory.VariableDeclaration(typeSyntax, SyntaxFactory.SingletonSeparatedList(v)));
        }
 public static PropertyDeclarationSyntax PropertyDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken)
 {
     return PropertyDeclaration(
         attributeLists,
         modifiers,
         refKeyword: default(SyntaxToken),
         type: type,
         explicitInterfaceSpecifier: explicitInterfaceSpecifier, 
         identifier: identifier, 
         accessorList: accessorList, 
         expressionBody: expressionBody, 
         initializer: initializer, 
         semicolonToken: semicolonToken);
 }
 private static BoundExpression BindFieldOrEnumInitializer(
     Binder binder,
     FieldSymbol fieldSymbol,
     EqualsValueClauseSyntax initializer,
     DiagnosticBag diagnostics)
 {
     var enumConstant = fieldSymbol as SourceEnumConstantSymbol;
     var collisionDetector = new LocalScopeBinder(binder);
     if ((object)enumConstant != null)
     {
         return collisionDetector.BindEnumConstantInitializer(enumConstant, initializer.Value, diagnostics);
     }
     else
     {
         return collisionDetector.BindVariableOrAutoPropInitializer(initializer, fieldSymbol.Type, diagnostics);
     }
 }
Beispiel #9
0
        private SourceLocalSymbol(
            MethodSymbol containingMethod,
            Binder binder,
            TypeSyntax typeSyntax,
            SyntaxToken identifierToken,
            EqualsValueClauseSyntax initializer,
            ExpressionSyntax collection,
            LocalDeclarationKind declarationKind)
        {
            Debug.Assert(identifierToken.CSharpKind() != SyntaxKind.None);
            Debug.Assert(declarationKind != LocalDeclarationKind.CompilerGenerated);

            this.binder = binder;
            this.containingMethod = containingMethod;
            this.identifierToken = identifierToken;
            this.typeSyntax = typeSyntax;
            this.initializer = initializer;
            this.collection = collection;
            this.declarationKind = declarationKind;

            // create this eagerly as it will always be needed for the EnsureSingleDefinition
            this.locations = ImmutableArray.Create<Location>(identifierToken.GetLocation());
        }
        public static ConstantValue EvaluateFieldConstant(
            SourceFieldSymbol symbol,
            EqualsValueClauseSyntax equalsValueNode,
            HashSet<SourceFieldSymbolWithSyntaxReference> dependencies,
            bool earlyDecodingWellKnownAttributes,
            DiagnosticBag diagnostics)
        {
            var compilation = symbol.DeclaringCompilation;
            var binderFactory = compilation.GetBinderFactory((SyntaxTree)symbol.Locations[0].SourceTree);
            var binder = binderFactory.GetBinder(equalsValueNode);
            if (earlyDecodingWellKnownAttributes)
            {
                binder = new EarlyWellKnownAttributeBinder(binder);
            }
            var inProgressBinder = new ConstantFieldsInProgressBinder(new ConstantFieldsInProgress(symbol, dependencies), binder);
            var boundValue = BindFieldOrEnumInitializer(inProgressBinder, symbol, equalsValueNode, diagnostics);
            var initValueNodeLocation = equalsValueNode.Value.Location;

            var value = GetAndValidateConstantValue(boundValue, symbol, symbol.Type, initValueNodeLocation, diagnostics);
            Debug.Assert(value != null);

            return value;
        }
Beispiel #11
0
        public static SourceLocalSymbol MakeLocal(
            Symbol containingSymbol,
            Binder binder,
            RefKind refKind,
            TypeSyntax typeSyntax,
            SyntaxToken identifierToken,
            LocalDeclarationKind declarationKind,
            EqualsValueClauseSyntax initializer = null)
        {
            Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
            if (initializer == null)
            {
                DeclarationExpressionSyntax declarationExpression;
                if (identifierToken.IsIdentifierOfOutVariableDeclaration(out declarationExpression))
                {
                    if (declarationExpression.Type().IsVar)
                    {
                        return new PossiblyImplicitlyTypedOutVarLocalSymbol(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind);
                    }
                }

                return new SourceLocalSymbol(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind);
            }

            return new LocalWithInitializer(containingSymbol, binder, refKind, typeSyntax, identifierToken, initializer, declarationKind);
        }
        private static BoundFieldInitializer BindFieldInitializer(Binder binder, FieldSymbol fieldSymbol, EqualsValueClauseSyntax equalsValueClauseNode,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(!fieldSymbol.IsMetadataConstant);

            var fieldsBeingBound = binder.FieldsBeingBound;

            var sourceField = fieldSymbol as SourceMemberFieldSymbol;
            bool isImplicitlyTypedField = (object)sourceField != null && sourceField.FieldTypeInferred(fieldsBeingBound);

            // If the type is implicitly typed, the initializer diagnostics have already been reported, so ignore them here:
            // CONSIDER (tomat): reusing the bound field initializers for implicitly typed fields.
            DiagnosticBag initializerDiagnostics;
            if (isImplicitlyTypedField)
            {
                initializerDiagnostics = DiagnosticBag.GetInstance();
            }
            else
            {
                initializerDiagnostics = diagnostics;
            }

            var collisionDetector = new LocalScopeBinder(binder);
            var boundInitValue = collisionDetector.BindVariableOrAutoPropInitializer(equalsValueClauseNode, fieldSymbol.GetFieldType(fieldsBeingBound), initializerDiagnostics);

            if (isImplicitlyTypedField)
            {
                initializerDiagnostics.Free();
            }

            return new BoundFieldInitializer(
                equalsValueClauseNode.Value, //we want the attached sequence point to indicate the value node
                fieldSymbol,
                boundInitValue);
        }
Beispiel #13
0
        // The location where the error is reported might not be the initializer.
        internal BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnostics, EqualsValueClauseSyntax initializer,
            CSharpSyntaxNode errorSyntax)
        {
            if (initializer == null)
            {
                if (!errorSyntax.HasErrors)
                {
                    Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableWithNoInitializer, errorSyntax);
                }

                return null;
            }

            if (initializer.Value.Kind() == SyntaxKind.ArrayInitializerExpression)
            {
                return BindUnexpectedArrayInitializer((InitializerExpressionSyntax)initializer.Value,
                    diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedArrayInitializer, errorSyntax);
            }

            BoundExpression expression = BindValue(initializer.Value, diagnostics, BindValueKind.RValue);

            // Certain expressions (null literals, method groups and anonymous functions) have no type of 
            // their own and therefore cannot be the initializer of an implicitly typed local.
            if (!expression.HasAnyErrors && !expression.HasExpressionType())
            {
                MessageID id = MessageID.IDS_NULL;
                if (expression.Kind == BoundKind.UnboundLambda)
                {
                    id = ((UnboundLambda)expression).MessageID;
                }
                else if (expression.Kind == BoundKind.MethodGroup)
                {
                    id = MessageID.IDS_MethodGroup;
                }
                else
                {
                    Debug.Assert(expression.IsLiteralNull(), "How did we successfully bind an expression without a type?");
                }

                // Cannot assign {0} to an implicitly-typed local variable
                Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, errorSyntax, id.Localize());
            }

            return expression;
        }
Beispiel #14
0
            public override void VisitEqualsValueClause(EqualsValueClauseSyntax node)
            {
                base.VisitEqualsValueClause(node);

                if (node.Parent != null && node.Parent.IsKind(SyntaxKind.PropertyDeclaration))
                {
                    var symbol = context.SemanticModel.GetDeclaredSymbol((PropertyDeclarationSyntax)node.Parent);
                    if (symbol != null)
                    {
                        CheckAssignment(symbol, node.Value);
                    }
                }
            }
Beispiel #15
0
        private SourceLocalSymbol LocateDeclaredVariableSymbol(SyntaxToken identifier, TypeSyntax typeSyntax, EqualsValueClauseSyntax equalsValue)
        {
            SourceLocalSymbol localSymbol = this.LookupLocal(identifier);

            // In error scenarios with misplaced code, it is possible we can't bind the local declaration.
            // This occurs through the semantic model.  In that case concoct a plausible result.
            if ((object)localSymbol == null)
            {
                localSymbol = SourceLocalSymbol.MakeLocal(
                    ContainingMemberOrLambda,
                    this,
                    false, // do not allow ref
                    typeSyntax,
                    identifier,
                    LocalDeclarationKind.RegularVariable,
                    equalsValue);
            }

            return localSymbol;
        }
Beispiel #16
0
        // The location where the error is reported might not be the initializer.
        protected BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnostics, EqualsValueClauseSyntax initializer, BindValueKind valueKind,
            CSharpSyntaxNode errorSyntax)
        {
            if (initializer == null)
            {
                if (!errorSyntax.HasErrors)
                {
                    Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableWithNoInitializer, errorSyntax);
                }

                return null;
            }

            if (initializer.Value.Kind() == SyntaxKind.ArrayInitializerExpression)
            {
                return BindUnexpectedArrayInitializer((InitializerExpressionSyntax)initializer.Value,
                    diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedArrayInitializer, errorSyntax);
            }

            BoundExpression expression = BindValue(initializer.Value, diagnostics, valueKind);

            // Certain expressions (null literals, method groups and anonymous functions) have no type of 
            // their own and therefore cannot be the initializer of an implicitly typed local.
            if (!expression.HasAnyErrors && !expression.HasExpressionType())
            {
                // Cannot assign {0} to an implicitly-typed local variable
                Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, errorSyntax, expression.Display);
            }

            return expression;
        }
Beispiel #17
0
            public LocalWithInitializer(
                Symbol containingSymbol,
                Binder binder,
                RefKind refKind,
                TypeSyntax typeSyntax,
                SyntaxToken identifierToken,
                EqualsValueClauseSyntax initializer,
                LocalDeclarationKind declarationKind) :
                    base(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind)
            {
                Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
                Debug.Assert(initializer != null);

                _initializer = initializer;

                // byval locals are always returnable
                // byref locals with initializers are assumed not returnable unless proven otherwise
                // NOTE: if we assumed returnable, then self-referring initializer could result in 
                //       a randomly changing returnability when initializer is bound concurrently.
                _returnable = refKind == RefKind.None;
            }
Beispiel #18
0
 internal BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnostics, RefKind refKind, EqualsValueClauseSyntax initializer,
     CSharpSyntaxNode errorSyntax)
 {
     BindValueKind valueKind;
     ExpressionSyntax value;
     IsInitializerRefKindValid(initializer, initializer, refKind, diagnostics, out valueKind, out value); // The return value isn't important here; we just want the diagnostics and the BindValueKind
     return BindInferredVariableInitializer(diagnostics, value, valueKind, errorSyntax);
 }
        private static bool EqualsValueClauseNotSuitableForVar(
            SyntaxToken identifier,
            TypeSyntax simpleName,
            EqualsValueClauseSyntax equalsValueClause,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            // var cannot be assigned null
            if (equalsValueClause.IsKind(SyntaxKind.NullLiteralExpression))
            {
                return true;
            }

            var type = semanticModel.GetTypeInfo(simpleName, cancellationToken).Type;

            // the variable cannot be initialized to a method group or an anonymous function
            if (type != null &&
                type.TypeKind == TypeKind.Delegate)
            {
                return true;
            }

            var initializerType = semanticModel.GetTypeInfo(equalsValueClause.Value, cancellationToken).Type;

            if (!type.Equals(initializerType))
            {
                return true;
            }

            // The assign expression in the initializer cannot be the same symbol as the i
            var possibleSameLocals = equalsValueClause.DescendantNodesAndSelf().Where(n => n.Kind() == SyntaxKind.IdentifierName && ((IdentifierNameSyntax)n).Identifier.ValueText.Equals(identifier.ValueText));
            var anyUse = possibleSameLocals.Any(n =>
            {
                var symbol = semanticModel.GetSymbolInfo(n, cancellationToken).Symbol;
                if (symbol != null && symbol.Kind == SymbolKind.Local)
                {
                    return true;
                }

                return false;
            });

            if (anyUse)
            {
                return true;
            }

            return false;
        }
 public override SyntaxNode VisitEqualsValueClause(EqualsValueClauseSyntax node)
 {
     this.VisitExpression(node.Value);
     return node;
 }
Beispiel #21
0
 internal abstract bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, EqualsValueClauseSyntax initializer, out SemanticModel speculativeModel);
Beispiel #22
0
 /// <summary>
 /// Get a SemanticModel object that is associated with an initializer that did not appear in
 /// this source code. This can be used to get detailed semantic information about sub-parts
 /// of a field initializer or default parameter value that did not appear in source code.
 /// </summary>
 /// <param name="position">A character position used to identify a declaration scope and accessibility. This
 /// character position must be within the FullSpan of the Root syntax node in this SemanticModel.
 /// </param>
 /// <param name="initializer">A syntax node that represents a parsed initializer. This initializer should not be
 /// present in the syntax tree associated with this object.</param>
 /// <param name="speculativeModel">A SemanticModel object that can be used to inquire about the semantic
 /// information associated with syntax nodes within <paramref name="initializer"/>.</param>
 /// <returns>Flag indicating whether a speculative semantic model was created.</returns>
 /// <exception cref="ArgumentException">Throws this exception if the <paramref name="initializer"/> node is contained any SyntaxTree in the current Compilation.</exception>
 /// <exception cref="ArgumentNullException">Throws this exception if <paramref name="initializer"/> is null.</exception>
 /// <exception cref="InvalidOperationException">Throws this exception if this model is a speculative semantic model, i.e. <see cref="SemanticModel.IsSpeculativeSemanticModel"/> is true.
 /// Chaining of speculative semantic model is not supported.</exception>
 public bool TryGetSpeculativeSemanticModel(int position, EqualsValueClauseSyntax initializer, out SemanticModel speculativeModel)
 {
     CheckModelAndSyntaxNodeToSpeculate(initializer);
     return TryGetSpeculativeSemanticModelCore((SyntaxTreeSemanticModel)this, position, initializer, out speculativeModel);
 }
            private IEnumerable<ITypeSymbol> InferTypeInEqualsValueClause(EqualsValueClauseSyntax equalsValue, SyntaxToken? previousToken = null)
            {
                // If we have a position, it has to be after the =
                if (previousToken.HasValue && previousToken.Value != equalsValue.EqualsToken)
                {
                    return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
                }

                if (equalsValue.IsParentKind(SyntaxKind.VariableDeclarator))
                {
                    return InferTypeInVariableDeclarator((VariableDeclaratorSyntax)equalsValue.Parent);
                }

                if (equalsValue.IsParentKind(SyntaxKind.Parameter))
                {
                    var parameter = this.semanticModel.GetDeclaredSymbol(equalsValue.Parent, cancellationToken) as IParameterSymbol;
                    if (parameter != null)
                    {
                        return SpecializedCollections.SingletonEnumerable(parameter.Type);
                    }
                }

                return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
            }
Beispiel #24
0
 /// <summary>
 /// Make a local variable symbol which can be inferred (if necessary) by binding its initializing expression.
 /// </summary>
 /// <param name="containingSymbol"></param>
 /// <param name="scopeBinder">
 /// Binder that owns the scope for the local, the one that returns it in its <see cref="Binder.Locals"/> array.
 /// </param>
 /// <param name="allowRefKind"></param>
 /// <param name="typeSyntax"></param>
 /// <param name="identifierToken"></param>
 /// <param name="declarationKind"></param>
 /// <param name="initializer"></param>
 /// <param name="initializerBinderOpt">
 /// Binder that should be used to bind initializer, if different from the <paramref name="scopeBinder"/>.
 /// </param>
 /// <returns></returns>
 public static SourceLocalSymbol MakeLocal(
     Symbol containingSymbol,
     Binder scopeBinder,
     bool allowRefKind,
     TypeSyntax typeSyntax,
     SyntaxToken identifierToken,
     LocalDeclarationKind declarationKind,
     EqualsValueClauseSyntax initializer = null,
     Binder initializerBinderOpt = null)
 {
     Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
     return (initializer != null)
         ? new LocalWithInitializer(containingSymbol, scopeBinder, typeSyntax, identifierToken, initializer, initializerBinderOpt ?? scopeBinder, declarationKind)
         : new SourceLocalSymbol(containingSymbol, scopeBinder, allowRefKind, typeSyntax, identifierToken, declarationKind);
 }
        internal sealed override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, EqualsValueClauseSyntax initializer, out SemanticModel speculativeModel)
        {
            position = CheckAndAdjustPosition(position);

            var model = this.GetMemberModel(position);
            if (model != null)
            {
                return model.TryGetSpeculativeSemanticModelCore(parentModel, position, initializer, out speculativeModel);
            }

            speculativeModel = null;
            return false;
        }
Beispiel #26
0
        protected static bool IsInitializerRefKindValid(
            EqualsValueClauseSyntax initializer,
            CSharpSyntaxNode node,
            RefKind variableRefKind,
            DiagnosticBag diagnostics,
            out BindValueKind valueKind)
        {
            if (variableRefKind == RefKind.None)
            {
                valueKind = BindValueKind.RValue;
                if (initializer != null && initializer.RefKeyword.Kind() != SyntaxKind.None)
                {
                    Error(diagnostics, ErrorCode.ERR_InitializeByValueVariableWithReference, node);
                    return false;
                }
            }
            else
            {
                valueKind = BindValueKind.RefOrOut;

                if (initializer == null)
                {
                    Error(diagnostics, ErrorCode.ERR_ByReferenceVariableMustBeInitialized, node);
                    return false;
                }
                else if (initializer.RefKeyword.Kind() == SyntaxKind.None)
                {
                    Error(diagnostics, ErrorCode.ERR_InitializeByReferenceVariableWithValue, node);
                    return false;
                }
            }

            return true;
        }
Beispiel #27
0
        public static SourceLocalSymbol MakeLocal(
            Symbol containingSymbol,
            Binder binder,
            RefKind refKind,
            TypeSyntax typeSyntax,
            SyntaxToken identifierToken,
            LocalDeclarationKind declarationKind,
            EqualsValueClauseSyntax initializer = null)
        {
            Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
            if (initializer == null)
            {
                ArgumentSyntax argument;
                if (ArgumentSyntax.IsIdentifierOfOutVariableDeclaration(identifierToken, out argument))
                {
                    if (argument.Type.IsVar)
                    {
                        return new PossibleOutVarLocalSymbol(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind);
                    }
                }

                return new SourceLocalSymbol(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind);
            }

            return new LocalWithInitializer(containingSymbol, binder, refKind, typeSyntax, identifierToken, initializer, declarationKind);
        }
        private BoundNode BindEqualsValue(Binder binder, EqualsValueClauseSyntax equalsValue, DiagnosticBag diagnostics)
        {
            switch (this.MemberSymbol.Kind)
            {
                case SymbolKind.Field:
                    {
                        var enumField = this.MemberSymbol as SourceEnumConstantSymbol;
                        if ((object)enumField != null)
                        {
                            return binder.BindEnumConstantInitializer(enumField, equalsValue.Value, diagnostics);
                        }

                        var fieldType = ((FieldSymbol)this.MemberSymbol).GetFieldType(binder.FieldsBeingBound);
                        return binder.BindVariableOrAutoPropInitializer(equalsValue, fieldType, diagnostics);
                    }

                case SymbolKind.Property:
                    {
                        var propertyType = ((PropertySymbol)this.MemberSymbol).Type;
                        return binder.BindVariableOrAutoPropInitializer(equalsValue, propertyType, diagnostics);
                    }

                case SymbolKind.Parameter:
                    {
                        BoundExpression unusedValueBeforeConversion; // not needed.
                        var parameter = (ParameterSymbol)this.MemberSymbol;
                        return binder.BindParameterDefaultValue(
                            equalsValue,
                            parameter.Type,
                            diagnostics,
                            out unusedValueBeforeConversion);
                    }

                default:
                    Debug.Assert(false, "Unexpected member symbol kind: " + this.MemberSymbol.Kind);
                    return null;
            }
        }
Beispiel #29
0
 public FieldInitializerInfo(FieldInitializer initializer, Binder binder, EqualsValueClauseSyntax equalsValue)
 {
     Initializer = initializer;
     Binder = binder;
     EqualsValue = equalsValue;
 }
Beispiel #30
0
        protected static bool IsInitializerRefKindValid(
            EqualsValueClauseSyntax initializer,
            CSharpSyntaxNode node,
            RefKind variableRefKind,
            DiagnosticBag diagnostics,
            out BindValueKind valueKind,
            out ExpressionSyntax value)
        {
            RefKind expressionRefKind = RefKind.None;
            value = initializer?.Value.SkipRef(out expressionRefKind);
            if (variableRefKind == RefKind.None)
            {
                valueKind = BindValueKind.RValue;
                if (expressionRefKind == RefKind.Ref)
                {
                    Error(diagnostics, ErrorCode.ERR_InitializeByValueVariableWithReference, node);
                    return false;
                }
            }
            else
            {
                valueKind = BindValueKind.RefOrOut;
                if (initializer == null)
                {
                    Error(diagnostics, ErrorCode.ERR_ByReferenceVariableMustBeInitialized, node);
                    return false;
                }
                else if (expressionRefKind != RefKind.Ref)
                {
                    Error(diagnostics, ErrorCode.ERR_InitializeByReferenceVariableWithValue, node);
                    return false;
                }
            }

            return true;
        }
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, EqualsValueClauseSyntax initializer, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return false;
 }
Beispiel #32
0
 public override void VisitEqualsValueClause(EqualsValueClauseSyntax node)
 {
     var valueBinder = new ExpressionVariableBinder(node, _enclosing);
     AddToMap(node, valueBinder);
     Visit(node.Value, valueBinder);
 }