コード例 #1
0
        public static ParameterSymbol Create(
            MethodSymbol?container,
            TypeWithAnnotations type,
            int ordinal,
            RefKind refKind,
            string name            = "",
            DeclarationScope scope = DeclarationScope.Unscoped,
            ImmutableArray <CustomModifier> refCustomModifiers          = default,
            SourceComplexParameterSymbolBase?baseParameterForAttributes = null)
        {
            if (refCustomModifiers.IsDefaultOrEmpty && baseParameterForAttributes is null)
            {
                return(new SynthesizedParameterSymbol(container, type, ordinal, refKind, scope, name));
            }

            return(new SynthesizedComplexParameterSymbol(
                       container,
                       type,
                       ordinal,
                       refKind,
                       scope,
                       name,
                       refCustomModifiers.NullToEmpty(),
                       baseParameterForAttributes));
        }
コード例 #2
0
ファイル: AnonymousTypeField.cs プロジェクト: lameox/roslyn
 public AnonymousTypeField(string name, Location location, TypeWithAnnotations typeWithAnnotations, RefKind refKind, DeclarationScope scope)
 {
     this.Name                = name;
     this.Location            = location;
     this.TypeWithAnnotations = typeWithAnnotations;
     this.RefKind             = refKind;
     this.Scope               = scope;
 }
コード例 #3
0
 private SynthesizedParameterSymbol(
     MethodSymbol?container,
     TypeWithAnnotations type,
     int ordinal,
     RefKind refKind,
     DeclarationScope scope,
     string name)
     : base(container, type, ordinal, refKind, scope, name)
 {
 }
コード例 #4
0
 public SourceSimpleParameterSymbol(
     Symbol owner,
     TypeWithAnnotations parameterType,
     int ordinal,
     RefKind refKind,
     DeclarationScope scope,
     string name,
     ImmutableArray <Location> locations)
     : base(owner, parameterType, ordinal, refKind, scope, name, locations)
 {
 }
コード例 #5
0
 public LambdaParameterSymbol(
     LambdaSymbol owner,
     SyntaxList <AttributeListSyntax> attributeLists,
     TypeWithAnnotations parameterType,
     int ordinal,
     RefKind refKind,
     DeclarationScope scope,
     string name,
     bool isDiscard,
     ImmutableArray <Location> locations)
     : base(owner, ordinal, parameterType, refKind, name, locations, syntaxRef: null, isParams: false, isExtensionMethodThis: false, scope)
 {
     _attributeLists = attributeLists;
     IsDiscard       = isDiscard;
 }
コード例 #6
0
ファイル: SourceLocalSymbol.cs プロジェクト: lameox/roslyn
        private SourceLocalSymbol(
            Symbol containingSymbol,
            Binder scopeBinder,
            bool allowRefKind,
            TypeSyntax typeSyntax,
            SyntaxToken identifierToken,
            LocalDeclarationKind declarationKind,
            bool hasScopedModifier)
        {
            Debug.Assert(identifierToken.Kind() != SyntaxKind.None);
            Debug.Assert(declarationKind != LocalDeclarationKind.None);
            Debug.Assert(scopeBinder != null);
            Debug.Assert(containingSymbol.DeclaringCompilation == scopeBinder.Compilation);

            this._scopeBinder      = scopeBinder;
            this._containingSymbol = containingSymbol;
            this._identifierToken  = identifierToken;

            if (allowRefKind && typeSyntax is RefTypeSyntax refTypeSyntax)
            {
                this._typeSyntax = refTypeSyntax.Type;
                this._refKind    = refTypeSyntax.ReadOnlyKeyword.Kind() == SyntaxKind.ReadOnlyKeyword ?
                                   RefKind.RefReadOnly :
                                   RefKind.Ref;
                this._scope = refTypeSyntax.ScopedKeyword.Kind() == SyntaxKind.ScopedKeyword ?
                              DeclarationScope.ValueScoped :
                              (hasScopedModifier ? DeclarationScope.RefScoped : DeclarationScope.Unscoped);
            }
            else
            {
                this._typeSyntax = typeSyntax;
                this._refKind    = RefKind.None;
                this._scope      = hasScopedModifier ? DeclarationScope.ValueScoped : DeclarationScope.Unscoped;
            }

            this._declarationKind = declarationKind;

            // create this eagerly as it will always be needed for the EnsureSingleDefinition
            _locations = ImmutableArray.Create <Location>(identifierToken.GetLocation());

            _refEscapeScope = this._refKind == RefKind.None ?
                              scopeBinder.LocalScopeDepth :
                              Binder.ExternalScope;           // default to returnable, unless there is initializer

            // we do not know the type yet.
            // assume this is returnable in case we never get to know our type.
            _valEscapeScope = Binder.ExternalScope;
        }
コード例 #7
0
        public SynthesizedComplexParameterSymbol(
            MethodSymbol?container,
            TypeWithAnnotations type,
            int ordinal,
            RefKind refKind,
            DeclarationScope scope,
            string name,
            ImmutableArray <CustomModifier> refCustomModifiers,
            SourceComplexParameterSymbolBase?baseParameterForAttributes)
            : base(container, type, ordinal, refKind, scope, name)
        {
            Debug.Assert(!refCustomModifiers.IsDefault);
            Debug.Assert(!refCustomModifiers.IsEmpty || baseParameterForAttributes is object);

            _refCustomModifiers         = refCustomModifiers;
            _baseParameterForAttributes = baseParameterForAttributes;
        }
コード例 #8
0
        public SynthesizedParameterSymbolBase(
            MethodSymbol?container,
            TypeWithAnnotations type,
            int ordinal,
            RefKind refKind,
            DeclarationScope scope,
            string name)
        {
            Debug.Assert(type.HasType);
            Debug.Assert(name != null);
            Debug.Assert(ordinal >= 0);

            _container = container;
            _type      = type;
            _ordinal   = ordinal;
            _refKind   = refKind;
            _scope     = scope;
            _name      = name;
        }
コード例 #9
0
        protected SourceParameterSymbol(
            Symbol owner,
            TypeWithAnnotations parameterType,
            int ordinal,
            RefKind refKind,
            DeclarationScope scope,
            string name,
            ImmutableArray <Location> locations)
            : base(owner, ordinal)
        {
#if DEBUG
            foreach (var location in locations)
            {
                Debug.Assert(location != null);
            }
#endif
            Debug.Assert((owner.Kind == SymbolKind.Method) || (owner.Kind == SymbolKind.Property));
            this.parameterType = parameterType;
            _refKind           = refKind;
            _scope             = scope;
            _name      = name;
            _locations = locations;
        }
コード例 #10
0
            public override void VisitParameterList(ParameterListSyntax node)
            {
                var saveCurrentScope = currentScope;
                DeclarationScope parametersScope = null;

                switch (node.Parent.Kind)
                {
                    case SyntaxKind.ClassDeclaration:
                        if (((ClassDeclarationSyntax)node.Parent).ParameterList == node)
                        {
                            parametersScope = primaryConstructorParametersScopes[(ClassDeclarationSyntax)node.Parent];
                            currentScope = parametersScope;
                        }
                        break;
                    case SyntaxKind.StructDeclaration:
                        if (((StructDeclarationSyntax)node.Parent).ParameterList == node)
                        {
                            parametersScope = primaryConstructorParametersScopes[(StructDeclarationSyntax)node.Parent];
                            currentScope = parametersScope;
                        }
                        break;
                }

                base.VisitParameterList(node);

                if (parametersScope != null)
                {
                    Debug.Assert(currentScope == parametersScope);
                    Debug.Assert(currentScope.Parent == saveCurrentScope);
                    currentScope = saveCurrentScope;
                }
                else
                {
                    Debug.Assert(currentScope == saveCurrentScope);
                }
            }
コード例 #11
0
            public override void VisitPrimaryConstructorBody(PrimaryConstructorBodySyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = primaryConstructorInitializerScope;

                base.VisitPrimaryConstructorBody(node);

                Debug.Assert(currentScope == primaryConstructorInitializerScope);
                currentScope = saveCurrentScope;
            }
コード例 #12
0
            public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
            {
                VisitAttributes(node.AttributeLists);

                var saveCurrentScope = currentScope;
                var parametersScope = new DeclarationScope(saveCurrentScope);
                currentScope = parametersScope;

                Visit(node.ParameterList);

                Debug.Assert(currentScope == parametersScope);
                currentScope = new DeclarationScope(parametersScope);

                Visit(node.Initializer);

                if (node.Modifiers.Any(SyntaxKind.StaticKeyword))
                {
                    Debug.Assert(currentScope.Parent == parametersScope);
                    currentScope = parametersScope;

                    Visit(node.Body);
                }
                else
                {
                    Visit(node.Body);

                    Debug.Assert(currentScope.Parent == parametersScope);
                    currentScope = parametersScope;
                }

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #13
0
            public override void VisitParameter(ParameterSyntax node)
            {
                Debug.Assert(currentScope != null);

                if (node.Identifier.CSharpKind() != SyntaxKind.ArgListKeyword)
                {
                    builder.Add(new SemanticModelInfo(currentScope, node));
                }

                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope.Parent);

                Visit(node.Default);

                Debug.Assert(currentScope.Parent == saveCurrentScope.Parent);
                currentScope = saveCurrentScope;
            }
コード例 #14
0
            public override void VisitSelectClause(SelectClauseSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                Visit(node.Expression);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #15
0
            public override void VisitWhereClause(WhereClauseSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                Visit(node.Condition);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #16
0
            public override void VisitForEachStatement(ForEachStatementSyntax node)
            {
                var saveCurrentScope = currentScope;

                currentScope = new DeclarationScope(currentScope);

                var nestedScope = new DeclarationScope(currentScope);

                builder.Add(new SemanticModelInfo(nestedScope, node));

                Visit(node.Expression);

                currentScope = nestedScope;

                VisitPossibleEmbeddedStatement(node.Statement);

                Debug.Assert(currentScope.Parent.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #17
0
 public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
 {
     var saveCurrentScope = currentScope;
     currentScope = new DeclarationScope(currentScope);
     base.VisitArrowExpressionClause(node);
     Debug.Assert(currentScope.Parent == saveCurrentScope);
     currentScope = saveCurrentScope;
 }
コード例 #18
0
 public override void VisitBlock(BlockSyntax node)
 {
     var saveCurrentScope = currentScope;
     currentScope = new DeclarationScope(currentScope);
     base.VisitBlock(node);
     Debug.Assert(currentScope.Parent == saveCurrentScope);
     currentScope = saveCurrentScope;
 }
コード例 #19
0
            public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
            {
                Debug.Assert(currentScope == null);

                VisitAttributes(node.AttributeLists);

                if (node.AccessorList != null)
                {
                    VisitAccessorList(node.AccessorList);
                }

                Visit(node.ExpressionBody);

                DeclarationScope initScope = node.Modifiers.Any(SyntaxKind.StaticKeyword) ? staticInitScope : instanceInitScope;

                currentScope = initScope ?? new DeclarationScope(null);
                Visit(node.Initializer);
                currentScope = null;
            }
コード例 #20
0
            public override void VisitEventFieldDeclaration(EventFieldDeclarationSyntax node)
            {
                Debug.Assert(currentScope == null);
                DeclarationScope initScope = node.Modifiers.Any(SyntaxKind.StaticKeyword) ? staticInitScope : instanceInitScope;

                foreach (VariableDeclaratorSyntax declarator in node.Declaration.Variables)
                {
                    currentScope = initScope ?? new DeclarationScope(null);
                    Visit(declarator.Initializer);
                    currentScope = null;
                }
            }
コード例 #21
0
            public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
            {
                Debug.Assert(currentScope == null);
                DeclarationScope saveStaticInitScope = staticInitScope;
                DeclarationScope saveInstanceInitScope = instanceInitScope;

                staticInitScope = new DeclarationScope(null);
                instanceInitScope = new DeclarationScope(null);

                base.VisitInterfaceDeclaration(node);

                staticInitScope = saveStaticInitScope;
                instanceInitScope = saveInstanceInitScope;
                Debug.Assert(currentScope == null);
            }
コード例 #22
0
 public SemanticModelInfo(DeclarationScope declScope, CSharpSyntaxNode node)
 {
     this.DeclScope = declScope;
     this.Node = node;
 }
コード例 #23
0
            public override void VisitEnumDeclaration(EnumDeclarationSyntax node)
            {
                Debug.Assert(currentScope == null);
                DeclarationScope saveStaticInitScope = staticInitScope;
                DeclarationScope saveInstanceInitScope = instanceInitScope;

                staticInitScope = null;
                instanceInitScope = null;

                base.VisitEnumDeclaration(node);

                staticInitScope = saveStaticInitScope;
                instanceInitScope = saveInstanceInitScope;
                Debug.Assert(currentScope == null);
            }
コード例 #24
0
            public override void VisitFixedStatement(FixedStatementSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                foreach (VariableDeclaratorSyntax declarator in node.Declaration.Variables)
                {
                    builder.Add(new SemanticModelInfo(currentScope, declarator));
                    Visit(declarator.Initializer);
                }

                VisitPossibleEmbeddedStatement(node.Statement);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #25
0
 public DeclarationScope(DeclarationScope parent)
 {
     this.Parent = parent;
 }
コード例 #26
0
            public override void VisitSwitchStatement(SwitchStatementSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                Visit(node.Expression);

                currentScope = new DeclarationScope(currentScope);

                foreach (SwitchSectionSyntax section in node.Sections)
                {
                    Visit(section);
                }

                Debug.Assert(currentScope.Parent.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #27
0
            public override void VisitGroupClause(GroupClauseSyntax node)
            {
                var saveCurrentScope = currentScope;

                currentScope = new DeclarationScope(saveCurrentScope);
                Visit(node.GroupExpression);

                currentScope = new DeclarationScope(saveCurrentScope);
                Visit(node.ByExpression);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #28
0
            public override void VisitIfStatement(IfStatementSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                Visit(node.Condition);

                VisitPossibleEmbeddedStatement(node.Statement);
                Visit(node.Else);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #29
0
            public override void VisitAttributeArgument(AttributeArgumentSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(saveCurrentScope);

                Visit(node.Expression);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #30
0
            public override void VisitCatchClause(CatchClauseSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                var declarationOpt = node.Declaration;
                if ((declarationOpt != null) && (declarationOpt.Identifier.CSharpKind() != SyntaxKind.None))
                {
                    builder.Add(new SemanticModelInfo(currentScope, declarationOpt));
                }

                Visit(node.Filter);
                Visit(node.Block);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #31
0
            public override void VisitBaseClassWithArguments(BaseClassWithArgumentsSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = primaryConstructorInitializerScope;

                Visit(node.ArgumentList);

                Debug.Assert(currentScope == primaryConstructorInitializerScope);
                currentScope = saveCurrentScope;
            }
コード例 #32
0
            private void VisitPossibleEmbeddedStatement(StatementSyntax statement)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                Visit(statement);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #33
0
            public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
            {
                VisitAttributes(node.AttributeLists);

                var saveCurrentScope = currentScope;
                var parametersScope = new DeclarationScope(saveCurrentScope);
                currentScope = parametersScope;

                Visit(node.ParameterList);

                Debug.Assert(currentScope == parametersScope);
                currentScope = new DeclarationScope(parametersScope);

                Visit(node.Body);

                // TODO: Should visit expression body here.

                Debug.Assert(currentScope.Parent == parametersScope);
                Debug.Assert(currentScope.Parent.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #34
0
ファイル: PEParameterSymbol.cs プロジェクト: lameox/roslyn
            public PackedFlags(RefKind refKind, bool attributesAreComplete, bool hasNameInMetadata, DeclarationScope scope)
            {
                int refKindBits           = ((int)refKind & RefKindMask) << RefKindOffset;
                int attributeBits         = attributesAreComplete ? AllWellKnownAttributesCompleteNoData : 0;
                int hasNameInMetadataBits = hasNameInMetadata ? HasNameInMetadataBit : 0;
                int scopeBits             = ((int)scope & ScopeMask) << ScopeOffset;

                _bits = refKindBits | attributeBits | hasNameInMetadataBits | scopeBits;
            }
コード例 #35
0
        public static SourceParameterSymbol Create(
            Binder context,
            Symbol owner,
            TypeWithAnnotations parameterType,
            ParameterSyntax syntax,
            RefKind refKind,
            SyntaxToken identifier,
            int ordinal,
            bool isParams,
            bool isExtensionMethodThis,
            bool addRefReadOnlyModifier,
            DeclarationScope scope,
            BindingDiagnosticBag declarationDiagnostics)
        {
            Debug.Assert(!(owner is LambdaSymbol)); // therefore we don't need to deal with discard parameters

            var name      = identifier.ValueText;
            var locations = ImmutableArray.Create <Location>(new SourceLocation(identifier));

            if (isParams)
            {
                // touch the constructor in order to generate proper use-site diagnostics
                Binder.ReportUseSiteDiagnosticForSynthesizedAttribute(context.Compilation,
                                                                      WellKnownMember.System_ParamArrayAttribute__ctor,
                                                                      declarationDiagnostics,
                                                                      identifier.Parent.GetLocation());
            }

            ImmutableArray <CustomModifier> inModifiers = ParameterHelpers.ConditionallyCreateInModifiers(refKind, addRefReadOnlyModifier, context, declarationDiagnostics, syntax);

            Debug.Assert(!inModifiers.IsDefault);

            if (!inModifiers.IsDefaultOrEmpty)
            {
                return(new SourceComplexParameterSymbolWithCustomModifiersPrecedingRef(
                           owner,
                           ordinal,
                           parameterType,
                           refKind,
                           inModifiers,
                           name,
                           locations,
                           syntax.GetReference(),
                           isParams,
                           isExtensionMethodThis,
                           scope));
            }

            if (!isParams &&
                !isExtensionMethodThis &&
                (syntax.Default == null) &&
                (syntax.AttributeLists.Count == 0) &&
                !owner.IsPartialMethod())
            {
                return(new SourceSimpleParameterSymbol(owner, parameterType, ordinal, refKind, scope, name, locations));
            }

            return(new SourceComplexParameterSymbol(
                       owner,
                       ordinal,
                       parameterType,
                       refKind,
                       name,
                       locations,
                       syntax.GetReference(),
                       isParams,
                       isExtensionMethodThis,
                       scope));
        }
コード例 #36
0
            public override void VisitFromClause(FromClauseSyntax node)
            {
                var saveCurrentScope = currentScope;

                // Visit Expression in the current scope only for a "from" clause that starts a query, it (the expression) doesn't become a body of a lambda.
                var parent = node.Parent;

                if (parent != null && (parent.Kind != SyntaxKind.QueryExpression || ((QueryExpressionSyntax)parent).FromClause != node))
                {
                    currentScope = new DeclarationScope(currentScope);
                }

                Visit(node.Expression);

                currentScope = saveCurrentScope;
            }
コード例 #37
0
            private DeclarationScope GetPrimaryConstructorParametersScopeForInitializers(TypeDeclarationSyntax node, ParameterListSyntax parameterList, out DeclarationScope primaryConstructorParametersScope)
            {
                DeclarationScope primaryConstructorParametersScopeForInitializers;

                if (!primaryConstructorParametersScopesForInitializers.TryGetValue(node.Identifier.ValueText, out primaryConstructorParametersScopeForInitializers))
                {
                    primaryConstructorParametersScopeForInitializers = new DeclarationScope(null);
                    primaryConstructorParametersScopesForInitializers.Add(node.Identifier.ValueText, primaryConstructorParametersScopeForInitializers);
                }

                if (parameterList != null)
                {
                    if (primaryConstructorParametersScopesForInitializersIsUsed.Add(node.Identifier.ValueText))
                    {
                        primaryConstructorParametersScope = primaryConstructorParametersScopeForInitializers;
                    }
                    else
                    {
                        primaryConstructorParametersScope = new DeclarationScope(null);
                    }

                    primaryConstructorParametersScopes.Add(node, primaryConstructorParametersScope);
                }
                else
                {
                    primaryConstructorParametersScope = null;
                }

                return primaryConstructorParametersScopeForInitializers;
            }
コード例 #38
0
            public override void VisitJoinClause(JoinClauseSyntax node)
            {
                Visit(node.InExpression);

                var saveCurrentScope = currentScope;

                currentScope = new DeclarationScope(saveCurrentScope);
                Visit(node.LeftExpression);

                currentScope = new DeclarationScope(saveCurrentScope);
                Visit(node.RightExpression);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #39
0
            public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                Visit(node.Block);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #40
0
            public override void VisitStructDeclaration(StructDeclarationSyntax node)
            {
                Debug.Assert(currentScope == null);
                DeclarationScope saveStaticInitScope = staticInitScope;
                DeclarationScope saveInstanceInitScope = instanceInitScope;
                DeclarationScope savePrimaryConstructorInitializerScope = primaryConstructorInitializerScope;

                staticInitScope = new DeclarationScope(null);

                DeclarationScope primaryConstructorParametersScope;
                instanceInitScope = new DeclarationScope(GetPrimaryConstructorParametersScopeForInitializers(node, node.ParameterList, out primaryConstructorParametersScope));

                if (primaryConstructorParametersScope == instanceInitScope.Parent)
                {
                    primaryConstructorInitializerScope = new DeclarationScope(instanceInitScope);
                }
                else
                {
                    primaryConstructorInitializerScope = new DeclarationScope(primaryConstructorParametersScope);
                }

                base.VisitStructDeclaration(node);

                staticInitScope = saveStaticInitScope;
                instanceInitScope = saveInstanceInitScope;
                primaryConstructorInitializerScope = savePrimaryConstructorInitializerScope;
                Debug.Assert(currentScope == null);
            }
コード例 #41
0
            public override void VisitParenthesizedLambdaExpression(ParenthesizedLambdaExpressionSyntax node)
            {
                var saveCurrentScope = currentScope;
                var parametersScope = new DeclarationScope(saveCurrentScope);
                currentScope = parametersScope;

                Visit(node.ParameterList);

                Debug.Assert(currentScope == parametersScope);
                currentScope = new DeclarationScope(parametersScope);

                Visit(node.Body);

                Debug.Assert(currentScope.Parent == parametersScope);
                Debug.Assert(currentScope.Parent.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
コード例 #42
0
ファイル: PEParameterSymbol.cs プロジェクト: lameox/roslyn
        private PEParameterSymbol(
            PEModuleSymbol moduleSymbol,
            Symbol containingSymbol,
            int ordinal,
            bool isByRef,
            TypeWithAnnotations typeWithAnnotations,
            ParameterHandle handle,
            Symbol nullableContext,
            int countOfCustomModifiers,
            out bool isBad)
        {
            Debug.Assert((object)moduleSymbol != null);
            Debug.Assert((object)containingSymbol != null);
            Debug.Assert(ordinal >= 0);
            Debug.Assert(typeWithAnnotations.HasType);

            isBad             = false;
            _moduleSymbol     = moduleSymbol;
            _containingSymbol = containingSymbol;
            _ordinal          = (ushort)ordinal;

            _handle = handle;

            RefKind          refKind = RefKind.None;
            DeclarationScope scope   = DeclarationScope.Unscoped;

            if (handle.IsNil)
            {
                refKind = isByRef ? RefKind.Ref : RefKind.None;
                byte?value = nullableContext.GetNullableContextValue();
                if (value.HasValue)
                {
                    typeWithAnnotations = NullableTypeDecoder.TransformType(typeWithAnnotations, value.GetValueOrDefault(), default);
                }
                _lazyCustomAttributes = ImmutableArray <CSharpAttributeData> .Empty;
                _lazyHiddenAttributes = ImmutableArray <CSharpAttributeData> .Empty;
                _lazyDefaultValue     = ConstantValue.NotAvailable;
                _lazyIsParams         = ThreeState.False;
            }
            else
            {
                try
                {
                    moduleSymbol.Module.GetParamPropsOrThrow(handle, out _name, out _flags);
                }
                catch (BadImageFormatException)
                {
                    isBad = true;
                }

                if (isByRef)
                {
                    ParameterAttributes inOutFlags = _flags & (ParameterAttributes.Out | ParameterAttributes.In);

                    if (inOutFlags == ParameterAttributes.Out)
                    {
                        refKind = RefKind.Out;
                        scope   = DeclarationScope.RefScoped;
                    }
                    else if (moduleSymbol.Module.HasIsReadOnlyAttribute(handle))
                    {
                        refKind = RefKind.In;
                    }
                    else
                    {
                        refKind = RefKind.Ref;
                    }
                }

                var typeSymbol = DynamicTypeDecoder.TransformType(typeWithAnnotations.Type, countOfCustomModifiers, handle, moduleSymbol, refKind);
                typeSymbol          = NativeIntegerTypeDecoder.TransformType(typeSymbol, handle, moduleSymbol, containingSymbol.ContainingType);
                typeWithAnnotations = typeWithAnnotations.WithTypeAndModifiers(typeSymbol, typeWithAnnotations.CustomModifiers);
                // Decode nullable before tuple types to avoid converting between
                // NamedTypeSymbol and TupleTypeSymbol unnecessarily.

                // The containing type is passed to NullableTypeDecoder.TransformType to determine access
                // for property parameters because the property does not have explicit accessibility in metadata.
                var accessSymbol = containingSymbol.Kind == SymbolKind.Property ? containingSymbol.ContainingSymbol : containingSymbol;
                typeWithAnnotations = NullableTypeDecoder.TransformType(typeWithAnnotations, handle, moduleSymbol, accessSymbol: accessSymbol, nullableContext: nullableContext);
                typeWithAnnotations = TupleTypeDecoder.DecodeTupleTypesIfApplicable(typeWithAnnotations, handle, moduleSymbol);

                if (_moduleSymbol.Module.HasLifetimeAnnotationAttribute(_handle, out var pair))
                {
                    var scopeOpt = GetScope(refKind, typeWithAnnotations.Type, pair.IsRefScoped, pair.IsValueScoped);
                    if (scopeOpt is null)
                    {
                        isBad = true;
                    }
                    else
                    {
                        scope = scopeOpt.GetValueOrDefault();
                    }
                }
            }

            _typeWithAnnotations = typeWithAnnotations;

            bool hasNameInMetadata = !string.IsNullOrEmpty(_name);

            if (!hasNameInMetadata)
            {
                // As was done historically, if the parameter doesn't have a name, we give it the name "value".
                _name = "value";
            }

            _packedFlags = new PackedFlags(refKind, attributesAreComplete: handle.IsNil, hasNameInMetadata: hasNameInMetadata, scope);

            Debug.Assert(refKind == this.RefKind);
            Debug.Assert(hasNameInMetadata == this.HasNameInMetadata);
            Debug.Assert(_name is not null);
        }