Esempio n. 1
0
 // create a SemanticModel for:
 // (a) A true field initializer (field = value) of a named type (incl. Enums) OR
 // (b) A parameter default value
 private InitializerSemanticModel(CSharpSyntaxNode syntax,
                                  Symbol symbol,
                                  Binder rootBinder,
                                  SyntaxTreeSemanticModel containingSemanticModelOpt = null,
                                  SyntaxTreeSemanticModel parentSemanticModelOpt     = null,
                                  int speculatedPosition = 0) :
     base(syntax, symbol, rootBinder, containingSemanticModelOpt, parentSemanticModelOpt, speculatedPosition)
 {
     Debug.Assert(!(syntax is ConstructorInitializerSyntax));
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a speculative SemanticModel for an initializer node (field initializer, constructor initializer, or parameter default value)
        /// that did not appear in the original source code.
        /// </summary>
        internal static InitializerSemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, Symbol owner, CSharpSyntaxNode syntax, Binder rootBinder, int position)
        {
            Debug.Assert(parentSemanticModel != null);
            Debug.Assert(syntax != null);
            Debug.Assert(syntax.IsKind(SyntaxKind.EqualsValueClause));
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            return(new InitializerSemanticModel(syntax, owner, rootBinder, parentSemanticModelOpt: parentSemanticModel, speculatedPosition: position));
        }
        private static SpeculativeSyntaxTreeSemanticModel CreateCore(SyntaxTreeSemanticModel parentSemanticModel, CSharpSyntaxNode root, Binder rootBinder, int position, SpeculativeBindingOption bindingOption)
        {
            Debug.Assert(parentSemanticModel is SyntaxTreeSemanticModel);
            Debug.Assert(root != null);
            Debug.Assert(root is TypeSyntax || root is CrefSyntax);
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            var speculativeModel = new SpeculativeSyntaxTreeSemanticModel(parentSemanticModel, root, rootBinder, position, bindingOption);

            return(speculativeModel);
        }
Esempio n. 4
0
 private AttributeSemanticModel(
     AttributeSyntax syntax,
     NamedTypeSymbol attributeType,
     AliasSymbol aliasOpt,
     Binder rootBinder,
     SyntaxTreeSemanticModel containingSemanticModelOpt = null,
     SyntaxTreeSemanticModel parentSemanticModelOpt     = null,
     int speculatedPosition = 0)
     : base(syntax, attributeType, new ExecutableCodeBinder(syntax, rootBinder.ContainingMember(), rootBinder), containingSemanticModelOpt, parentSemanticModelOpt, speculatedPosition)
 {
     Debug.Assert(syntax != null);
     _aliasOpt = aliasOpt;
 }
        /// <summary>
        /// Creates a SemanticModel for the method.
        /// </summary>
        internal static MethodBodySemanticModel Create(SyntaxTreeSemanticModel containingSemanticModel, MethodSymbol owner, ExecutableCodeBinder executableCodeBinder,
                                                       CSharpSyntaxNode syntax, BoundNode boundNode = null)
        {
            Debug.Assert(containingSemanticModel != null);
            var result = new MethodBodySemanticModel(owner, executableCodeBinder, syntax, containingSemanticModel);

            if (boundNode != null)
            {
                result.UnguardedAddBoundTreeForStandaloneSyntax(syntax, boundNode);
            }

            return(result);
        }
Esempio n. 6
0
        internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, EqualsValueClauseSyntax initializer, out SemanticModel speculativeModel)
        {
            var binder = this.GetEnclosingBinder(position);

            if (binder == null)
            {
                speculativeModel = null;
                return(false);
            }

            binder           = new ExecutableCodeBinder(initializer, binder.ContainingMemberOrLambda, binder);
            speculativeModel = CreateSpeculative(parentModel, this.MemberSymbol, initializer, binder, position);
            return(true);
        }
 private MethodBodySemanticModel(
     Symbol owner,
     Binder rootBinder,
     CSharpSyntaxNode syntax,
     SyntaxTreeSemanticModel containingSemanticModelOpt = null,
     SyntaxTreeSemanticModel parentSemanticModelOpt     = null,
     int speculatedPosition = 0)
     : base(syntax, owner, rootBinder, containingSemanticModelOpt, parentSemanticModelOpt, speculatedPosition)
 {
     Debug.Assert((object)owner != null);
     Debug.Assert(owner.Kind == SymbolKind.Method);
     Debug.Assert(syntax != null);
     Debug.Assert(syntax.Kind() != SyntaxKind.CompilationUnit);
 }
        internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ConstructorInitializerSyntax constructorInitializer, out SemanticModel speculativeModel)
        {
            if ((MemberSymbol as MethodSymbol)?.MethodKind == MethodKind.Constructor)
            {
                var binder = this.GetEnclosingBinder(position);
                if (binder != null)
                {
                    var methodSymbol = (MethodSymbol)this.MemberSymbol;
                    binder           = new ExecutableCodeBinder(constructorInitializer, methodSymbol, binder);
                    speculativeModel = CreateSpeculative(parentModel, methodSymbol, constructorInitializer, binder, position);
                    return(true);
                }
            }

            speculativeModel = null;
            return(false);
        }
        internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, StatementSyntax statement, out SemanticModel speculativeModel)
        {
            position = CheckAndAdjustPosition(position);

            var binder = this.GetEnclosingBinder(position);

            if (binder == null)
            {
                speculativeModel = null;
                return(false);
            }

            var methodSymbol = (MethodSymbol)this.MemberSymbol;

            binder           = new ExecutableCodeBinder(statement, methodSymbol, binder);
            speculativeModel = CreateSpeculative(parentModel, methodSymbol, statement, binder, position);
            return(true);
        }
Esempio n. 10
0
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ArrowExpressionClauseSyntax expressionBody, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return(false);
 }
Esempio n. 11
0
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, EqualsValueClauseSyntax initializer, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return(false);
 }
Esempio n. 12
0
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ConstructorInitializerSyntax constructorInitializer, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return(false);
 }
 /// <summary>
 /// Creates a speculative SemanticModel for a TypeSyntax node at a position within an existing MemberSemanticModel.
 /// </summary>
 public SpeculativeMemberSemanticModel(SyntaxTreeSemanticModel parentSemanticModel, Symbol owner, TypeSyntax root, Binder rootBinder, int position)
     : base(root, owner, rootBinder, containingSemanticModelOpt: null, parentSemanticModelOpt: parentSemanticModel, speculatedPosition: position)
 {
 }
Esempio n. 14
0
 /// <summary>
 /// Creates a SemanticModel for a parameter default value.
 /// </summary>
 internal static InitializerSemanticModel Create(SyntaxTreeSemanticModel containingSemanticModel, ParameterSyntax syntax, ParameterSymbol parameterSymbol, Binder rootBinder)
 {
     Debug.Assert(containingSemanticModel != null);
     return(new InitializerSemanticModel(syntax, parameterSymbol, rootBinder, containingSemanticModel));
 }
Esempio n. 15
0
 /// <summary>
 /// Creates a SemanticModel for an autoprop initializer of a named type
 /// </summary>
 internal static InitializerSemanticModel Create(SyntaxTreeSemanticModel containingSemanticModel, CSharpSyntaxNode syntax, PropertySymbol propertySymbol, Binder rootBinder)
 {
     Debug.Assert(containingSemanticModel != null);
     Debug.Assert(syntax.IsKind(SyntaxKind.PropertyDeclaration));
     return(new InitializerSemanticModel(syntax, propertySymbol, rootBinder, containingSemanticModel));
 }
Esempio n. 16
0
 internal override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, BaseMethodDeclarationSyntax method, out SemanticModel speculativeModel)
 {
     // CONSIDER: Do we want to ensure that speculated method and the original method have identical signatures?
     return(GetSpeculativeSemanticModelForMethodBody(parentModel, position, method.Body, out speculativeModel));
 }
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ConstructorInitializerSyntax constructorInitializer, out SemanticModel speculativeModel)
 {
     throw ExceptionUtilities.Unreachable;
 }
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, EqualsValueClauseSyntax initializer, out SemanticModel speculativeModel)
 {
     throw ExceptionUtilities.Unreachable;
 }
 public static SpeculativeSyntaxTreeSemanticModel Create(SyntaxTreeSemanticModel parentSemanticModel, CrefSyntax root, Binder rootBinder, int position)
 {
     return(CreateCore(parentSemanticModel, root, rootBinder, position, bindingOption: SpeculativeBindingOption.BindAsTypeOrNamespace));
 }
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ArrowExpressionClauseSyntax expressionBody, out SemanticModel speculativeModel)
 {
     throw ExceptionUtilities.Unreachable;
 }
Esempio n. 21
0
 internal override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, AccessorDeclarationSyntax accessor, out SemanticModel speculativeModel)
 {
     return(GetSpeculativeSemanticModelForMethodBody(parentModel, position, accessor.Body, out speculativeModel));
 }
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, StatementSyntax statement, out SemanticModel speculativeModel)
 {
     throw ExceptionUtilities.Unreachable;
 }
Esempio n. 23
0
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, StatementSyntax statement, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return(false);
 }
Esempio n. 24
0
 /// <summary>
 /// Creates a SemanticModel for a true field initializer (field = value) of a named type (incl. Enums).
 /// </summary>
 internal static InitializerSemanticModel Create(SyntaxTreeSemanticModel containingSemanticModel, CSharpSyntaxNode syntax, FieldSymbol fieldSymbol, Binder rootBinder)
 {
     Debug.Assert(containingSemanticModel != null);
     Debug.Assert(syntax.IsKind(SyntaxKind.VariableDeclaration) || syntax.IsKind(SyntaxKind.EnumMemberDeclaration));
     return(new InitializerSemanticModel(syntax, fieldSymbol, rootBinder, containingSemanticModel));
 }
Esempio n. 25
0
 internal override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, AccessorDeclarationSyntax accessor, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return(false);
 }
 internal override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, AccessorDeclarationSyntax accessor, out SemanticModel speculativeModel)
 {
     throw ExceptionUtilities.Unreachable;
 }
Esempio n. 27
0
 /// <summary>
 /// Creates an AttributeSemanticModel that allows asking semantic questions about an attribute node.
 /// </summary>
 public static AttributeSemanticModel Create(SyntaxTreeSemanticModel containingSemanticModel, AttributeSyntax syntax, NamedTypeSymbol attributeType, AliasSymbol aliasOpt, Binder rootBinder)
 {
     return(new AttributeSemanticModel(syntax, attributeType, aliasOpt, rootBinder, containingSemanticModel));
 }
 public static SpeculativeSyntaxTreeSemanticModel Create(SyntaxTreeSemanticModel parentSemanticModel, TypeSyntax root, Binder rootBinder, int position, SpeculativeBindingOption bindingOption)
 {
     return(CreateCore(parentSemanticModel, root, rootBinder, position, bindingOption));
 }