Exemple #1
0
 public EmbeddedProperty(
     PropertySymbolAdapter underlyingProperty,
     EmbeddedMethod getter,
     EmbeddedMethod setter
     ) : base(underlyingProperty, getter, setter)
 {
 }
        public SynthesizedImplementationMethod(
            MethodSymbol interfaceMethod,
            NamedTypeSymbol implementingType,
            string name = null,
            bool debuggerHidden = false,
            PropertySymbol associatedProperty = null,
            MethodSymbol asyncKickoffMethod = null)
        {
            //it does not make sense to add methods to substituted types
            Debug.Assert(implementingType.IsDefinition);

            this.name = name ?? ExplicitInterfaceHelpers.GetMemberName(interfaceMethod.Name, interfaceMethod.ContainingType, aliasQualifierOpt: null);
            this.interfaceMethod = interfaceMethod;
            this.implementingType = implementingType;
            this.debuggerHidden = debuggerHidden;
            this.associatedProperty = associatedProperty;
            this.explicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(interfaceMethod);
            this.asyncKickoffMethod = asyncKickoffMethod;

            // alpha-rename to get the implementation's type parameters
            var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty;
            typeMap.WithAlphaRename(interfaceMethod, this, out this.typeParameters);

            var substitutedInterfaceMethod = interfaceMethod.ConstructIfGeneric(this.typeParameters.Cast<TypeParameterSymbol, TypeSymbol>());
            this.returnType = substitutedInterfaceMethod.ReturnType;
            this.parameters = SynthesizedParameterSymbol.DeriveParameters(substitutedInterfaceMethod, this);
        }
        private BoundExpression MakePropertyGetAccess(
            SyntaxNode syntax,
            BoundExpression rewrittenReceiver,
            PropertySymbol property,
            ImmutableArray<BoundExpression> rewrittenArguments,
            MethodSymbol getMethodOpt = null,
            BoundPropertyAccess oldNodeOpt = null)
        {
            if (_inExpressionLambda && rewrittenArguments.IsEmpty)
            {
                return oldNodeOpt != null ?
                    oldNodeOpt.Update(rewrittenReceiver, property, LookupResultKind.Viable, property.Type) :
                    new BoundPropertyAccess(syntax, rewrittenReceiver, property, LookupResultKind.Viable, property.Type);
            }
            else
            {
                var getMethod = getMethodOpt ?? property.GetOwnOrInheritedGetMethod();

                Debug.Assert((object)getMethod != null);
                Debug.Assert(getMethod.ParameterCount == rewrittenArguments.Length);
                Debug.Assert(((object)getMethodOpt == null) || ReferenceEquals(getMethod, getMethodOpt));

                return BoundCall.Synthesized(
                    syntax,
                    rewrittenReceiver,
                    getMethod,
                    rewrittenArguments);
            }
        }
        public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
            NamedTypeSymbol containingType,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            string propertyName,
            ArrowExpressionClauseSyntax syntax,
            PropertySymbol explicitlyImplementedPropertyOpt,
            string aliasQualifierOpt,
            DiagnosticBag diagnostics)
        {
            string name;
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
            GetNameAndExplicitInterfaceImplementations(
                explicitlyImplementedPropertyOpt,
                propertyName,
                property.IsCompilationOutputWinMdObj(),
                aliasQualifierOpt,
                isGetMethod: true,
                name: out name,
                explicitInterfaceImplementations:
                out explicitInterfaceImplementations);

            return new SourcePropertyAccessorSymbol(
                containingType,
                name,
                property,
                propertyModifiers,
                explicitInterfaceImplementations,
                syntax.Expression.GetLocation(),
                syntax,
                diagnostics);
        }
        public SynthesizedImplementationMethod(
            MethodSymbol interfaceMethod,
            NamedTypeSymbol implementingType,
            string name = null,
            bool generateDebugInfo = true,
            PropertySymbol associatedProperty = null)
        {
            //it does not make sense to add methods to substituted types
            Debug.Assert(implementingType.IsDefinition);

            _name = name ?? ExplicitInterfaceHelpers.GetMemberName(interfaceMethod.Name, interfaceMethod.ContainingType, aliasQualifierOpt: null);
            _interfaceMethod = interfaceMethod;
            _implementingType = implementingType;
            _generateDebugInfo = generateDebugInfo;
            _associatedProperty = associatedProperty;
            _explicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(interfaceMethod);

            // alpha-rename to get the implementation's type parameters
            var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty;
            typeMap.WithAlphaRename(interfaceMethod, this, out _typeParameters);

            var substitutedInterfaceMethod = interfaceMethod.ConstructIfGeneric(_typeParameters.Cast<TypeParameterSymbol, TypeSymbol>());
            _returnType = substitutedInterfaceMethod.ReturnType;
            _parameters = SynthesizedParameterSymbol.DeriveParameters(substitutedInterfaceMethod, this);
        }
        public RetargetingPropertySymbol(RetargetingModuleSymbol retargetingModule, PropertySymbol underlyingProperty)
            : base(underlyingProperty)
        {
            Debug.Assert((object)retargetingModule != null);
            Debug.Assert(!(underlyingProperty is RetargetingPropertySymbol));

            _retargetingModule = retargetingModule;
        }
        public RetargetingPropertySymbol(RetargetingModuleSymbol retargetingModule, PropertySymbol underlyingProperty)
        {
            Debug.Assert((object)retargetingModule != null);
            Debug.Assert((object)underlyingProperty != null);
            Debug.Assert(!(underlyingProperty is RetargetingPropertySymbol));

            this.retargetingModule = retargetingModule;
            this.underlyingProperty = underlyingProperty;
        }
        public SynthesizedSealedPropertyAccessor(PropertySymbol property, MethodSymbol overriddenAccessor)
        {
            Debug.Assert((object)property != null);
            Debug.Assert(property.IsSealed);
            Debug.Assert((object)overriddenAccessor != null);

            _property = property;
            _overriddenAccessor = overriddenAccessor;
            _parameters = SynthesizedParameterSymbol.DeriveParameters(overriddenAccessor, this);
        }
 protected SynthesizedStateMachineMethod(
     string name,
     MethodSymbol interfaceMethod,
     StateMachineTypeSymbol stateMachineType,
     PropertySymbol associatedProperty,
     bool generateDebugInfo,
     bool hasMethodBodyDependency)
     : base(interfaceMethod, stateMachineType, name, generateDebugInfo, associatedProperty)
 {
     _hasMethodBodyDependency = hasMethodBodyDependency;
 }
 public override void VisitProperty(PropertySymbol symbol)
 {
     var sourceProperty = symbol as SourcePropertySymbol;
     if ((object)sourceProperty != null && sourceProperty.IsSealed)
     {
         var synthesizedAccessor = sourceProperty.SynthesizedSealedAccessorOpt;
         if ((object)synthesizedAccessor != null)
         {
             moduleBeingBuilt.AddCompilerGeneratedDefinition(sourceProperty.ContainingType, synthesizedAccessor);
         }
     }
 }
 public SynthesizedStateMachineMethod(
     string name,            
     MethodSymbol interfaceMethod,
     NamedTypeSymbol implementingType,
     MethodSymbol asyncKickoffMethod,
     PropertySymbol associatedProperty,
     bool debuggerHidden,
     bool hasMethodBodyDependency)
     : base(interfaceMethod, implementingType,  name, debuggerHidden, associatedProperty, asyncKickoffMethod)
 {
     this.hasMethodBodyDependency = hasMethodBodyDependency;
 }
        public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
            NamedTypeSymbol containingType,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            string propertyName,
            AccessorDeclarationSyntax syntax,
            PropertySymbol explicitlyImplementedPropertyOpt,
            string aliasQualifierOpt,
            bool isAutoPropertyAccessor,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(syntax.Kind == SyntaxKind.GetAccessorDeclaration || syntax.Kind == SyntaxKind.SetAccessorDeclaration);

            bool isGetMethod = (syntax.Kind == SyntaxKind.GetAccessorDeclaration);
            bool isWinMd = property.IsCompilationOutputWinMdObj();
            string name;
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
            if ((object)explicitlyImplementedPropertyOpt == null)
            {
                name = GetAccessorName(propertyName, isGetMethod, isWinMd);
                explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
            }
            else
            {
                MethodSymbol implementedAccessor = isGetMethod ? explicitlyImplementedPropertyOpt.GetMethod : explicitlyImplementedPropertyOpt.SetMethod;
                string accessorName = (object)implementedAccessor != null ? implementedAccessor.Name
                    : GetAccessorName(explicitlyImplementedPropertyOpt.MetadataName, isGetMethod, isWinMd); //Not name - could be indexer placeholder
                name = ExplicitInterfaceHelpers.GetMemberName(accessorName, explicitlyImplementedPropertyOpt.ContainingType, aliasQualifierOpt);
                explicitInterfaceImplementations =
                    (object)implementedAccessor == null ?
                        ImmutableArray<MethodSymbol>.Empty :
                        ImmutableArray.Create<MethodSymbol>(implementedAccessor);
            }

            var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
            return new SourcePropertyAccessorSymbol(
                containingType,
                name,
                property,
                propertyModifiers,
                explicitInterfaceImplementations,
                syntax.Keyword.GetLocation(),
                syntax,
                methodKind,
                isAutoPropertyAccessor,
                diagnostics);
        }
        private BoundExpression MakePropertyAccess(
            SyntaxNode syntax,
            BoundExpression rewrittenReceiverOpt,
            PropertySymbol propertySymbol,
            LookupResultKind resultKind,
            TypeSymbol type,
            bool isLeftOfAssignment,
            BoundPropertyAccess oldNodeOpt = null)
        {
            // check for System.Array.[Length|LongLength] on a single dimensional array,
            // we have a special node for such cases.
            if (rewrittenReceiverOpt != null && rewrittenReceiverOpt.Type.IsArray() && !isLeftOfAssignment)
            {
                var asArrayType = (ArrayTypeSymbol)rewrittenReceiverOpt.Type;
                if (asArrayType.IsSZArray)
                {
                    // NOTE: we are not interested in potential badness of Array.Length property.
                    // If it is bad reference compare will not succeed.
                    if (ReferenceEquals(propertySymbol, _compilation.GetSpecialTypeMember(SpecialMember.System_Array__Length)) ||
                        !_inExpressionLambda && ReferenceEquals(propertySymbol, _compilation.GetSpecialTypeMember(SpecialMember.System_Array__LongLength)))
                    {
                        return new BoundArrayLength(syntax, rewrittenReceiverOpt, type);
                    }
                }
            }

            if (isLeftOfAssignment && propertySymbol.RefKind == RefKind.None)
            {
                // This is a property set access. We return a BoundPropertyAccess node here.
                // This node will be rewritten with MakePropertyAssignment when rewriting the enclosing BoundAssignmentOperator.

                return oldNodeOpt != null ?
                    oldNodeOpt.Update(rewrittenReceiverOpt, propertySymbol, resultKind, type) :
                    new BoundPropertyAccess(syntax, rewrittenReceiverOpt, propertySymbol, resultKind, type);
            }
            else
            {
                // This is a property get access
                return MakePropertyGetAccess(syntax, rewrittenReceiverOpt, propertySymbol, oldNodeOpt);
            }
        }
 internal AsyncMethodBuilderMemberCollection(
     NamedTypeSymbol builderType,
     TypeSymbol resultType,
     MethodSymbol setException,
     MethodSymbol setResult,
     MethodSymbol awaitOnCompleted,
     MethodSymbol awaitUnsafeOnCompleted,
     MethodSymbol start,
     MethodSymbol setStateMachine,
     PropertySymbol task)
 {
     BuilderType = builderType;
     ResultType = resultType;
     SetException = setException;
     SetResult = setResult;
     AwaitOnCompleted = awaitOnCompleted;
     AwaitUnsafeOnCompleted = awaitUnsafeOnCompleted;
     Start = start;
     SetStateMachine = setStateMachine;
     Task = task;
 }
        public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
            NamedTypeSymbol containingType,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            string propertyName,
            AccessorDeclarationSyntax syntax,
            PropertySymbol explicitlyImplementedPropertyOpt,
            string aliasQualifierOpt,
            bool isAutoPropertyAccessor,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(syntax.Kind() == SyntaxKind.GetAccessorDeclaration || syntax.Kind() == SyntaxKind.SetAccessorDeclaration);

            bool isGetMethod = (syntax.Kind() == SyntaxKind.GetAccessorDeclaration);
            string name;
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
            GetNameAndExplicitInterfaceImplementations(
                explicitlyImplementedPropertyOpt,
                propertyName,
                property.IsCompilationOutputWinMdObj(),
                aliasQualifierOpt,
                isGetMethod,
                out name,
                out explicitInterfaceImplementations);

            var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
            return new SourcePropertyAccessorSymbol(
                containingType,
                name,
                property,
                propertyModifiers,
                explicitInterfaceImplementations,
                syntax.Keyword.GetLocation(),
                syntax,
                methodKind,
                isAutoPropertyAccessor,
                diagnostics);
        }
 public virtual void VisitProperty(PropertySymbol symbol)
 {
     DefaultVisit(symbol);
 }
        private PropertySymbol VisitPropertySymbol(PropertySymbol property)
        {
            if ((object)property == null)
            {
                return null;
            }

            if (!property.ContainingType.IsAnonymousType)
            {
                //  Property of a regular type
                return ((PropertySymbol)property.OriginalDefinition)
                    .AsMember((NamedTypeSymbol)TypeMap.SubstituteType(property.ContainingType).AsTypeSymbolOnly());
            }

            //  Method of an anonymous type
            var newType = (NamedTypeSymbol)TypeMap.SubstituteType(property.ContainingType).AsTypeSymbolOnly();
            if (ReferenceEquals(newType, property.ContainingType))
            {
                //  Anonymous type symbol was not rewritten
                return property;
            }

            //  get a new property by name
            foreach (var member in newType.GetMembers(property.Name))
            {
                if (member.Kind == SymbolKind.Property)
                {
                    return (PropertySymbol)member;
                }
            }

            throw ExceptionUtilities.Unreachable;
        }
        internal static bool AccessingAutopropertyFromConstructor(BoundExpression receiver, PropertySymbol propertySymbol, Symbol fromMember)
        {
            var sourceProperty = propertySymbol as SourcePropertySymbol;
            var propertyIsStatic = propertySymbol.IsStatic;

            return (object)sourceProperty != null &&
                    sourceProperty.IsAutoProperty &&
                    sourceProperty.ContainingType == fromMember.ContainingType &&
                    ((MethodSymbol)fromMember).MethodKind == (propertyIsStatic ? MethodKind.StaticConstructor
                                                                                : MethodKind.Constructor) &&
                   (propertyIsStatic || receiver.Kind == BoundKind.ThisReference);
        }
 public EmbeddedProperty(PropertySymbol underlyingProperty, EmbeddedMethod getter, EmbeddedMethod setter) :
     base(underlyingProperty, getter, setter)
 {
 }
Exemple #20
0
 public AnonymousTypeFieldSymbol(PropertySymbol property)
 {
     Debug.Assert((object)property != null);
     _property = property;
 }
        private static void CheckParameterizedProperty(PropertySymbol property, bool expectGetter, bool expectSetter, string propertyDisplayString, bool expectIndexer, bool suppressAssociatedPropertyCheck)
        {
            Assert.Equal(SymbolKind.Property, property.Kind);
            Assert.Equal(expectIndexer, property.IsIndexer);
            Assert.NotEqual(expectIndexer, property.MustCallMethodsDirectly);
            Assert.Equal(propertyDisplayString, property.ToTestDisplayString());

            if (expectGetter)
            {
                CheckAccessorShape(property.GetMethod, true, property, expectIndexer, suppressAssociatedPropertyCheck);
            }
            else
            {
                Assert.Null(property.GetMethod);
            }

            if (expectSetter)
            {
                CheckAccessorShape(property.SetMethod, false, property, expectIndexer, suppressAssociatedPropertyCheck);
            }
            else
            {
                Assert.Null(property.SetMethod);
            }
        }
 // Create AccessorSymbol for AccessorDeclarationSyntax
 private SourcePropertyAccessorSymbol CreateAccessorSymbol(AccessorDeclarationSyntax syntaxOpt,
     PropertySymbol explicitlyImplementedPropertyOpt, string aliasQualifierOpt, bool isAutoPropertyAccessor, DiagnosticBag diagnostics)
 {
     if (syntaxOpt == null)
     {
         return null;
     }
     return SourcePropertyAccessorSymbol.CreateAccessorSymbol(_containingType, this, _modifiers, _sourceName, syntaxOpt,
         explicitlyImplementedPropertyOpt, aliasQualifierOpt, isAutoPropertyAccessor, diagnostics);
 }
Exemple #23
0
 public static BoundIndexerAccess ErrorAccess(
     CSharpSyntaxNode node,
     BoundExpression receiverOpt,
     PropertySymbol indexer,
     ImmutableArray<BoundExpression> arguments,
     ImmutableArray<string> namedArguments,
     ImmutableArray<RefKind> refKinds,
     ImmutableArray<PropertySymbol> originalIndexers)
 {
     return new BoundIndexerAccess(
         node,
         receiverOpt,
         indexer,
         arguments,
         namedArguments,
         refKinds,
         expanded: false,
         argsToParamsOpt: default(ImmutableArray<int>),
         type: indexer.Type,
         hasErrors: true)
     {
         OriginalIndexersOpt = originalIndexers
     };
 }
        private static void GetNameAndExplicitInterfaceImplementations(
            PropertySymbol explicitlyImplementedPropertyOpt,
            string propertyName,
            bool isWinMd,
            string aliasQualifierOpt,
            bool isGetMethod,
            out string name,
            out ImmutableArray<MethodSymbol> explicitInterfaceImplementations)
        {
            if ((object)explicitlyImplementedPropertyOpt == null)
            {
                name = GetAccessorName(propertyName, isGetMethod, isWinMd);
                explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
            }
            else
            {
                MethodSymbol implementedAccessor = isGetMethod
                    ? explicitlyImplementedPropertyOpt.GetMethod
                    : explicitlyImplementedPropertyOpt.SetMethod;

                string accessorName = (object)implementedAccessor != null
                    ? implementedAccessor.Name
                    : GetAccessorName(explicitlyImplementedPropertyOpt.MetadataName,
                        isGetMethod, isWinMd); //Not name - could be indexer placeholder

                name = ExplicitInterfaceHelpers.GetMemberName(accessorName, explicitlyImplementedPropertyOpt.ContainingType, aliasQualifierOpt);
                explicitInterfaceImplementations = (object)implementedAccessor == null
                    ? ImmutableArray<MethodSymbol>.Empty
                    : ImmutableArray.Create<MethodSymbol>(implementedAccessor);
            }
        }
Exemple #25
0
        private static void CheckIndexer(PropertySymbol property, bool hasGet, bool hasSet, SpecialType expectedType, params SpecialType[] expectedParameterTypes)
        {
            Assert.NotNull(property);
            Assert.True(property.IsIndexer);

            Assert.Equal(property.Type.SpecialType, expectedType);
            CheckParameters(property.Parameters, expectedParameterTypes);

            var getter = property.GetMethod;
            if (hasGet)
            {
                Assert.NotNull(getter);
                Assert.Equal(getter.ReturnType.SpecialType, expectedType);
                CheckParameters(getter.Parameters, expectedParameterTypes);
            }
            else
            {
                Assert.Null(getter);
            }

            var setter = property.SetMethod;
            if (hasSet)
            {
                Assert.NotNull(setter);
                Assert.True(setter.ReturnsVoid);
                CheckParameters(setter.Parameters, expectedParameterTypes.Concat(new[] { expectedType }).ToArray());
            }
            else
            {
                Assert.Null(setter);
            }

            Assert.Equal(property.GetMethod != null, hasGet);
            Assert.Equal(property.SetMethod != null, hasSet);
        }
Exemple #26
0
        private static bool AccessingAutoPropertyFromConstructor(BoundExpression receiver, PropertySymbol propertySymbol, Symbol fromMember)
        {
            var sourceProperty = propertySymbol as SourcePropertySymbol;
            var propertyIsStatic = propertySymbol.IsStatic;

            return (object)sourceProperty != null &&
                    sourceProperty.IsAutoProperty &&
                    sourceProperty.ContainingType == fromMember.ContainingType &&
                    IsConstructorOrField(fromMember, isStatic: propertyIsStatic) &&
                    (propertyIsStatic || receiver.Kind == BoundKind.ThisReference);
        }
Exemple #27
0
 public WrappedPropertySymbol(PropertySymbol underlyingProperty)
 {
     Debug.Assert((object)underlyingProperty != null);
     _underlyingProperty = underlyingProperty;
 }
Exemple #28
0
 public SynthesizedRecordGetHashCode(SourceMemberContainerTypeSymbol containingType, PropertySymbol equalityContract, int memberOffset, DiagnosticBag diagnostics)
     : base(containingType, WellKnownMemberNames.ObjectGetHashCode, memberOffset, diagnostics)
 {
     _equalityContract = equalityContract;
 }
Exemple #29
0
 internal SubstitutedPropertySymbol(SubstitutedNamedTypeSymbol containingType, PropertySymbol originalDefinition)
     : base(originalDefinition)
 {
     _containingType = containingType;
 }
 private static void CheckIndexer(PropertySymbol indexer, bool expectGetter, bool expectSetter, string indexerDisplayString, bool suppressAssociatedPropertyCheck = false)
 {
     CheckParameterizedProperty(indexer, expectGetter, expectSetter, indexerDisplayString, true, suppressAssociatedPropertyCheck);
 }
 internal SubstitutedParameterSymbol(PropertySymbol containingSymbol, TypeMap map, ParameterSymbol originalParameter) :
     this((Symbol)containingSymbol, map, originalParameter)
 {
 }
 private static void CheckNonIndexer(PropertySymbol property, bool expectGetter, bool expectSetter, string propertyDisplayString)
 {
     CheckParameterizedProperty(property, expectGetter, expectSetter, propertyDisplayString, false, true);
 }
Exemple #33
0
 public SynthesizedRecordGetHashCode(NamedTypeSymbol containingType, PropertySymbol equalityContract, int memberOffset)
 {
     _memberOffset     = memberOffset;
     ContainingType    = containingType;
     _equalityContract = equalityContract;
 }
        private static void CheckAccessorShape(MethodSymbol accessor, bool accessorIsGetMethod, PropertySymbol property, bool propertyIsIndexer, bool suppressAssociatedPropertyCheck)
        {
            Assert.NotNull(accessor);
            if (propertyIsIndexer)
            {
                if (!suppressAssociatedPropertyCheck)
                {
                    Assert.Same(property, accessor.AssociatedSymbol);
                }
            }
            else
            {
                Assert.Null(accessor.AssociatedSymbol);
                Assert.Equal(MethodKind.Ordinary, accessor.MethodKind);
            }

            if (accessorIsGetMethod)
            {
                Assert.Equal(propertyIsIndexer ? MethodKind.PropertyGet : MethodKind.Ordinary, accessor.MethodKind);

                Assert.Equal(property.Type, accessor.ReturnType);
                Assert.Equal(property.ParameterCount, accessor.ParameterCount);
            }
            else
            {
                Assert.Equal(propertyIsIndexer ? MethodKind.PropertySet : MethodKind.Ordinary, accessor.MethodKind);

                Assert.Equal(SpecialType.System_Void, accessor.ReturnType.SpecialType);
                Assert.Equal(property.Type, accessor.Parameters.Last().Type);
                Assert.Equal(property.ParameterCount + 1, accessor.ParameterCount);
            }

            // NOTE: won't check last param of setter - that was handled above.
            for (int i = 0; i < property.ParameterCount; i++)
            {
                Assert.Equal(property.Parameters[i].Type, accessor.Parameters[i].Type);
            }

            Assert.Equal(property.IsAbstract, accessor.IsAbstract);
            Assert.Equal(property.IsOverride, @accessor.IsOverride);
            Assert.Equal(property.IsVirtual, @accessor.IsVirtual);
            Assert.Equal(property.IsSealed, @accessor.IsSealed);
            Assert.Equal(property.IsExtern, @accessor.IsExtern);
        }
 /// <summary>
 /// Helper method specifically for TestPropertyOverrideCombinations.
 /// </summary>
 /// <param name="property">Must have array type.</param>
 /// <param name="inType">True if a custom modifier is expected on the return type array element type.</param>
 /// <param name="onType">True if a custom modifier is expected on the return type.</param>
 private static void CheckPropertyCustomModifiers(PropertySymbol property, bool inType, bool onType)
 {
     CheckCustomModifier(inType, ((ArrayTypeSymbol)property.Type).CustomModifiers);
     CheckCustomModifier(onType, property.TypeCustomModifiers);
 }
        // Separate these checks out of FindExplicitlyImplementedProperty because they depend on the accessor symbols,
        // which depend on the explicitly implemented property
        private void CheckExplicitImplementationAccessor(MethodSymbol thisAccessor, MethodSymbol otherAccessor, PropertySymbol explicitlyImplementedProperty, DiagnosticBag diagnostics)
        {
            var thisHasAccessor = (object)thisAccessor != null;
            var otherHasAccessor = (object)otherAccessor != null;

            if (otherHasAccessor && !thisHasAccessor)
            {
                diagnostics.Add(ErrorCode.ERR_ExplicitPropertyMissingAccessor, this.Location, this, otherAccessor);
            }
            else if (!otherHasAccessor && thisHasAccessor)
            {
                diagnostics.Add(ErrorCode.ERR_ExplicitPropertyAddingAccessor, thisAccessor.Locations[0], thisAccessor, explicitlyImplementedProperty);
            }
        }
 /// <summary>
 /// Creates a SemanticModel for an autoprop initializer of a named type
 /// </summary>
 internal static InitializerSemanticModel Create(CSharpCompilation compilation, CSharpSyntaxNode syntax, PropertySymbol propertySymbol, Binder rootBinder)
 {
     Debug.Assert(syntax.IsKind(SyntaxKind.PropertyDeclaration));
     return new InitializerSemanticModel(compilation, syntax, propertySymbol, rootBinder);
 }
Exemple #38
0
 public TuplePropertySymbol(TupleTypeSymbol container, PropertySymbol underlyingProperty)
     : base(underlyingProperty)
 {
     _containingType = container;
 }
        public override IExpression VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            var             o        = this.semanticModel.GetSymbolInfo(node);
            IExpression     instance = null;
            BoundExpression be       = null;
            var             onLHS    = this.lhs;

            this.lhs = false; // only the right-most member is a l-value: all other member accesses are for r-value.
            var s = o.Symbol;

            if (s != null)
            {
                switch (s.Kind)
                {
                case CommonSymbolKind.Method:
                    R.MethodSymbol ms = (R.MethodSymbol)s;
                    instance = null;
                    if (!s.IsStatic)
                    {
                        instance = this.Visit(node.Expression);
                    }
                    var mr = this.mapper.Map(ms);
                    be = new BoundExpression()
                    {
                        Definition = mr,
                        Instance   = instance,
                        Locations  = Helper.SourceLocation(this.tree, node),
                        Type       = mr.Type,
                    };
                    return(be);

                case CommonSymbolKind.Field:
                    FieldSymbol fs = (FieldSymbol)s;
                    instance = null;
                    if (!fs.IsStatic)
                    {
                        instance = this.Visit(node.Expression);
                    }
                    var fr = this.mapper.Map(fs);
                    // Certain fields represent compile-time constants
                    // REVIEW: Is this the right place to do this?
                    // TODO: All the rest of the constants...
                    if (fr.ContainingType.InternedKey == this.host.PlatformType.SystemInt32.InternedKey)
                    {
                        if (fr.Name.Value.Equals("MinValue"))
                        {
                            return(new CompileTimeConstant()
                            {
                                Type = fr.Type, Value = Int32.MinValue,
                            });
                        }
                        else if (fr.Name.Value.Equals("MaxValue"))
                        {
                            return(new CompileTimeConstant()
                            {
                                Type = fr.Type, Value = Int32.MaxValue,
                            });
                        }
                    }

                    be = new BoundExpression()
                    {
                        Definition = fr,
                        Instance   = instance,
                        Locations  = Helper.SourceLocation(this.tree, node),
                        Type       = fr.Type,
                    };
                    return(be);

                case CommonSymbolKind.Property:
                    R.PropertySymbol ps = (R.PropertySymbol)s;
                    instance = null;
                    if (!ps.IsStatic)
                    {
                        instance = this.Visit(node.Expression);
                    }
                    var accessor = onLHS ? this.mapper.Map(ps.SetMethod) : this.mapper.Map(ps.GetMethod);
                    if (!onLHS && MemberHelper.GetMemberSignature(accessor, NameFormattingOptions.None).Contains("Length"))
                    {
                        return(new VectorLength()
                        {
                            Locations = Helper.SourceLocation(this.tree, node),
                            Type = accessor.Type,
                            Vector = instance,
                        });
                    }
                    return(new MethodCall()
                    {
                        MethodToCall = accessor,
                        IsStaticCall = ps.IsStatic,
                        Locations = Helper.SourceLocation(this.tree, node),
                        ThisArgument = instance,
                        Type = accessor.Type,
                    });

                default:
                    throw new InvalidDataException("VisitMemberAccessExpression: uknown definition kind: " + s.Kind);
                }
            }
            throw new InvalidDataException("VisitMemberAccessExpression couldn't find something to return");
        }