/// <summary> /// Make a local variable symbol whose type can be inferred (if necessary) by binding and enclosing construct. /// </summary> internal static LocalSymbol MakeLocalSymbolWithEnclosingContext( Symbol containingSymbol, Binder scopeBinder, Binder nodeBinder, TypeSyntax typeSyntax, SyntaxToken identifierToken, LocalDeclarationKind kind, SyntaxNode nodeToBind, SyntaxNode forbiddenZone) { Debug.Assert( nodeToBind.Kind() == SyntaxKind.CasePatternSwitchLabel || nodeToBind.Kind() == SyntaxKind.ThisConstructorInitializer || nodeToBind.Kind() == SyntaxKind.BaseConstructorInitializer || nodeToBind.Kind() == SyntaxKind.SwitchExpressionArm || nodeToBind.Kind() == SyntaxKind.ArgumentList && nodeToBind.Parent is ConstructorInitializerSyntax || nodeToBind.Kind() == SyntaxKind.VariableDeclaration && new[] { SyntaxKind.LocalDeclarationStatement, SyntaxKind.UsingStatement, SyntaxKind.FixedStatement }. Contains(nodeToBind.Ancestors().OfType <StatementSyntax>().First().Kind()) || nodeToBind is ExpressionSyntax); Debug.Assert(!(nodeToBind.Kind() == SyntaxKind.SwitchExpressionArm) || nodeBinder is SwitchExpressionArmBinder); return(typeSyntax.IsNullWithNoType() != false && kind != LocalDeclarationKind.DeclarationExpressionVariable ? new LocalSymbolWithEnclosingContext(containingSymbol, scopeBinder, nodeBinder, typeSyntax, identifierToken, kind, nodeToBind, forbiddenZone) : new SourceLocalSymbol(containingSymbol, scopeBinder, Compiler.RefKind.None, typeSyntax, identifierToken, kind)); }
/// <summary> /// Make a local variable symbol for an element of a deconstruction, /// which can be inferred (if necessary) by binding the enclosing statement. /// </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="nodeBinder"> /// Enclosing binder for the location where the local is declared. /// It should be used to bind something at that location. /// </param> /// <param name="closestTypeSyntax"></param> /// <param name="identifierToken"></param> /// <param name="kind"></param> /// <param name="deconstruction"></param> /// <returns></returns> public static SourceLocalSymbol MakeDeconstructionLocal( Symbol containingSymbol, Binder scopeBinder, Binder nodeBinder, TypeSyntax closestTypeSyntax, SyntaxToken identifierToken, LocalDeclarationKind kind, SyntaxNode deconstruction) { Debug.Assert(closestTypeSyntax != null); Debug.Assert(nodeBinder != null); return(closestTypeSyntax.IsNullWithNoType() ? new DeconstructionLocalSymbol(containingSymbol, scopeBinder, nodeBinder, closestTypeSyntax, identifierToken, kind, deconstruction) : new SourceLocalSymbol(containingSymbol, scopeBinder, RefKind.None, closestTypeSyntax, identifierToken, kind)); }
internal static GlobalExpressionVariable Create( SourceMemberContainerTypeSymbol containingType, DeclarationModifiers modifiers, TypeSyntax typeSyntax, string name, SyntaxNode syntax, Location location, FieldSymbol containingFieldOpt, SyntaxNode nodeToBind) { Debug.Assert(nodeToBind.Kind() == SyntaxKind.VariableDeclaration || nodeToBind is ExpressionSyntax); var syntaxReference = syntax.GetReference(); return((typeSyntax == null || typeSyntax.IsNullWithNoType()) ? new InferrableGlobalExpressionVariable(containingType, modifiers, typeSyntax, name, syntaxReference, location, containingFieldOpt, nodeToBind) : new GlobalExpressionVariable(containingType, modifiers, typeSyntax, name, syntaxReference, location)); }