protected override ImmutableArray<LocalSymbol> BuildLocals() { var locals = ArrayBuilder<LocalSymbol>.GetInstance(); var declarationOpt = _syntax.Declaration; if ((declarationOpt != null) && (declarationOpt.Identifier.Kind() != SyntaxKind.None)) { locals.Add( SourceLocalSymbol.MakeLocal( this.ContainingMemberOrLambda, this, false, declarationOpt.Type, declarationOpt.Identifier, LocalDeclarationKind.CatchVariable ) ); } if (_syntax.Filter != null) { ExpressionVariableFinder.FindExpressionVariables( this, locals, _syntax.Filter.FilterExpression ); } return locals.ToImmutableAndFree(); }
public override void VisitArgument(ArgumentSyntax node) { if (node.Expression != null) { base.VisitArgument(node); return; } var contextKind = node.Parent. // ArgumentListSyntax Parent. // invocation/constructor initializer Kind(); switch (contextKind) { case SyntaxKind.InvocationExpression: case SyntaxKind.ObjectCreationExpression: case SyntaxKind.ThisConstructorInitializer: case SyntaxKind.BaseConstructorInitializer: break; default: // It looks like we are deling with a syntax tree that has a shape that could never be // produced by the LanguageParser, including all error conditions. // Out Variable declarations can only appear in an argument list of the syntax nodes mentioned above. throw ExceptionUtilities.UnexpectedValue(contextKind); } _localsBuilder.Add(SourceLocalSymbol.MakeLocal(_binder.ContainingMemberOrLambda, _binder, RefKind.None, node.Type, node.Identifier, LocalDeclarationKind.RegularVariable)); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { SourceLocalSymbol local = null; var declarationOpt = syntax.Declaration; if ((declarationOpt != null) && (declarationOpt.Identifier.CSharpKind() != SyntaxKind.None)) { local = SourceLocalSymbol.MakeLocal(this.ContainingMemberOrLambda, this, declarationOpt.Type, declarationOpt.Identifier, null, LocalDeclarationKind.Catch); } if (syntax.Filter != null) { var walker = new BuildLocalsFromDeclarationsWalker(this); walker.Visit(syntax.Filter); if (walker.Locals != null) { if ((object)local != null) { walker.Locals.Insert(0, local); } return(walker.Locals.ToImmutableAndFree()); } } if ((object)local != null) { return(ImmutableArray.Create <LocalSymbol>(local)); } return(ImmutableArray <LocalSymbol> .Empty); }
protected override ImmutableArray <LocalSymbol> BuildLocals() { var builder = ArrayBuilder <LocalSymbol> .GetInstance(); builder.AddRange(_aliases); var declaration = _syntax as LocalDeclarationStatementSyntax; if (declaration != null) { var kind = declaration.IsConst ? LocalDeclarationKind.Constant : LocalDeclarationKind.RegularVariable; foreach (var variable in declaration.Declaration.Variables) { var local = SourceLocalSymbol.MakeLocal( _containingMethod, this, declaration.RefKeyword.Kind() == SyntaxKind.RefKeyword? RefKind.Ref: RefKind.None, declaration.Declaration.Type, variable.Identifier, kind, variable.Initializer); builder.Add(local); } } return(builder.ToImmutableAndFree()); }
protected SourceLocalSymbol MakeLocal(VariableDeclarationSyntax declaration, VariableDeclaratorSyntax declarator, LocalDeclarationKind kind) { SourceLocalSymbol localSymbol; if (declarator.Initializer == null) { localSymbol = SourceLocalSymbol.MakeLocal( this.ContainingMemberOrLambda, this, declaration.Type, declarator.Identifier, kind); } else { localSymbol = SourceLocalSymbol.MakeLocalWithInitializer( this.ContainingMemberOrLambda, this, declaration.Type, declarator.Identifier, declarator.Initializer, kind); } return(localSymbol); }
internal void CollectLocalsFromDeconstruction(VariableDesignationSyntax designation, TypeSyntax closestTypeSyntax, LocalDeclarationKind kind, ArrayBuilder <LocalSymbol> locals) { switch (designation.Kind()) { case SyntaxKind.SingleVariableDesignation: { var single = (SingleVariableDesignationSyntax)designation; SourceLocalSymbol localSymbol = SourceLocalSymbol.MakeDeconstructionLocal( this.ContainingMemberOrLambda, this, closestTypeSyntax, single.Identifier, kind); locals.Add(localSymbol); break; } case SyntaxKind.ParenthesizedVariableDesignation: { var tuple = (ParenthesizedVariableDesignationSyntax)designation; foreach (var d in tuple.Variables) { CollectLocalsFromDeconstruction(d, closestTypeSyntax, kind, locals); } break; } default: throw ExceptionUtilities.UnexpectedValue(designation.Kind()); } }
protected SourceLocalSymbol MakeLocal(VariableDeclarationSyntax declaration, VariableDeclaratorSyntax declarator, LocalDeclarationKind kind) { return(SourceLocalSymbol.MakeLocal( this.ContainingMemberOrLambda, this, declaration.Type, declarator.Identifier, kind, declarator.Initializer)); }
protected override ImmutableArray <LocalSymbol> BuildLocals() { var iterationVariable = SourceLocalSymbol.MakeForeachLocal( (MethodSymbol)this.ContainingMemberOrLambda, this, this.syntax.Type, this.syntax.Identifier, this.syntax.Expression); return(ImmutableArray.Create <LocalSymbol>(iterationVariable)); }
protected override ImmutableArray <LocalSymbol> BuildLocals() { var iterationVariable = SourceLocalSymbol.MakeForeachLocal( this.Owner, this, this.syntax.Type, this.syntax.Identifier, this.syntax.Expression); return(ImmutableArray.Create <LocalSymbol>(iterationVariable)); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { var declarationOpt = syntax.Declaration; if ((declarationOpt != null) && (declarationOpt.Identifier.CSharpKind() != SyntaxKind.None)) { var local = SourceLocalSymbol.MakeLocal(this.Owner, this, declarationOpt.Type, declarationOpt.Identifier, null, LocalDeclarationKind.Catch); return(ImmutableArray.Create <LocalSymbol>(local)); } return(ImmutableArray <LocalSymbol> .Empty); }
protected SourceLocalSymbol MakeLocal(VariableDeclarationSyntax declaration, LocalDeclarationKind kind, Binder initializerBinderOpt = null) { return(SourceLocalSymbol.MakeLocal( this.ContainingMemberOrLambda, this, declaration.Type.GetRefKind(), declaration.Type, declaration.Identifier, kind, declaration.Initializer, initializerBinderOpt)); }
public override void VisitDeclarationPattern(DeclarationPatternSyntax node) { _localsBuilder.Add(SourceLocalSymbol.MakeLocalSymbolWithEnclosingContext( _scopeBinder.ContainingMemberOrLambda, scopeBinder: _scopeBinder, nodeBinder: _enclosingBinder, typeSyntax: node.Type, identifierToken: node.Identifier, kind: LocalDeclarationKind.PatternVariable, nodeToBind: _nodeToBind, forbiddenZone: null)); base.VisitDeclarationPattern(node); }
protected SourceLocalSymbol MakeLocal(VariableDeclarationSyntax declaration, VariableDeclaratorSyntax declarator, LocalDeclarationKind kind, bool hasScopedModifier, Binder initializerBinderOpt = null) { return(SourceLocalSymbol.MakeLocal( this.ContainingMemberOrLambda, this, true, declaration.Type, declarator.Identifier, kind, declarator.Initializer, hasScopedModifier, initializerBinderOpt)); }
/// <summary> /// In embedded statements, returns a BoundLocal when the type was explicit. /// In global statements, returns a BoundFieldAccess when the type was explicit. /// Otherwise returns a DeconstructionVariablePendingInference when the type is implicit. /// </summary> private BoundExpression BindDeconstructionVariable( TypeSymbol declType, TypeSyntax typeSyntax, SingleVariableDesignationSyntax designation, DiagnosticBag diagnostics) { SourceLocalSymbol localSymbol = LookupLocal(designation.Identifier); // is this a local? if ((object)localSymbol != null) { // Check for variable declaration errors. // Use the binder that owns the scope for the local because this (the current) binder // might own nested scope. var hasErrors = localSymbol.ScopeBinder.ValidateDeclarationNameConflictsInScope(localSymbol, diagnostics); if ((object)declType != null) { CheckRestrictedTypeInAsync(this.ContainingMemberOrLambda, declType, diagnostics, typeSyntax); return(new BoundLocal(designation, localSymbol, constantValueOpt: null, type: declType, hasErrors: hasErrors)); } return(new DeconstructionVariablePendingInference(designation, localSymbol, receiverOpt: null)); } // Is this a field? GlobalExpressionVariable field = LookupDeclaredField(designation); if ((object)field == null) { // We should have the right binder in the chain, cannot continue otherwise. throw ExceptionUtilities.Unreachable; } BoundThisReference receiver = ThisReference(designation, this.ContainingType, hasErrors: false, wasCompilerGenerated: true); if ((object)declType != null) { TypeSymbol fieldType = field.GetFieldType(this.FieldsBeingBound); Debug.Assert(declType == fieldType); return(new BoundFieldAccess(designation, receiver, field, constantValueOpt: null, resultKind: LookupResultKind.Viable, type: fieldType)); } return(new DeconstructionVariablePendingInference(designation, field, receiver)); }
public override void VisitDeclarationExpression(DeclarationExpressionSyntax node) { var argumentSyntax = (ArgumentSyntax)node?.Parent; var argumentListSyntax = (BaseArgumentListSyntax)argumentSyntax?.Parent; _localsBuilder.Add(SourceLocalSymbol.MakeLocalSymbolWithEnclosingContext( containingSymbol: _scopeBinder.ContainingMemberOrLambda, scopeBinder: _scopeBinder, nodeBinder: _enclosingBinder, typeSyntax: node.Type(), identifierToken: node.Identifier(), kind: LocalDeclarationKind.RegularVariable, nodeToBind: _nodeToBind, forbiddenZone: argumentListSyntax)); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { if (syntax.Declaration != null) { var locals = new ArrayBuilder <LocalSymbol>(syntax.Declaration.Variables.Count); foreach (VariableDeclaratorSyntax declarator in syntax.Declaration.Variables) { locals.Add(SourceLocalSymbol.MakeLocal(this.Owner, this, syntax.Declaration.Type, declarator.Identifier, declarator.Initializer, LocalDeclarationKind.Using)); } return(locals.ToImmutable()); } return(ImmutableArray <LocalSymbol> .Empty); }
public override void VisitDeclarationExpression(DeclarationExpressionSyntax node) { Debug.Assert(scopeSegmentRoot != null); if (Locals == null) { Locals = ArrayBuilder <LocalSymbol> .GetInstance(); } SourceLocalSymbol localSymbol; if (node.Variable.Initializer == null) { if (node.Type.IsVar) { localSymbol = SourceLocalSymbol.MakePossibleOutVarLocalWithoutInitializer( Binder.ContainingMemberOrLambda, Binder, node.Type, node.Variable.Identifier, scopeSegmentRoot, LocalDeclarationKind.RegularVariable); } else { localSymbol = SourceLocalSymbol.MakeLocal( Binder.ContainingMemberOrLambda, Binder, node.Type, node.Variable.Identifier, LocalDeclarationKind.RegularVariable); } } else { localSymbol = SourceLocalSymbol.MakeLocalWithInitializer( Binder.ContainingMemberOrLambda, Binder, node.Type, node.Variable.Identifier, node.Variable.Initializer, LocalDeclarationKind.RegularVariable); } Locals.Add(localSymbol); Visit(node.Variable.Initializer); }
public override void VisitVariableDeclaration(VariableDeclarationSyntax node) { if (Locals == null) { Locals = ArrayBuilder <LocalSymbol> .GetInstance(); } LocalDeclarationKind kind; switch (node.Parent.CSharpKind()) { case SyntaxKind.LocalDeclarationStatement: var localDecl = (LocalDeclarationStatementSyntax)node.Parent; kind = localDecl.IsConst ? LocalDeclarationKind.Constant : localDecl.IsFixed ? LocalDeclarationKind.Fixed : LocalDeclarationKind.Variable; break; case SyntaxKind.ForStatement: kind = LocalDeclarationKind.For; break; case SyntaxKind.UsingStatement: kind = LocalDeclarationKind.Using; break; case SyntaxKind.FixedStatement: kind = LocalDeclarationKind.Fixed; break; default: throw ExceptionUtilities.Unreachable; } foreach (var vdecl in node.Variables) { var localSymbol = SourceLocalSymbol.MakeLocal( Binder.ContainingMemberOrLambda, Binder, node.Type, vdecl.Identifier, vdecl.Initializer, kind); Locals.Add(localSymbol); Visit(vdecl.Initializer); } }
protected ImmutableArray <LocalSymbol> BuildLocals(SyntaxList <StatementSyntax> statements) { ArrayBuilder <LocalSymbol> locals = null; foreach (var statement in statements) { var innerStatement = statement; // drill into any LabeledStatements -- atomic LabelStatements have been bound into // wrapped LabeledStatements by this point while (innerStatement.Kind == SyntaxKind.LabeledStatement) { innerStatement = ((LabeledStatementSyntax)innerStatement).Statement; } if (innerStatement.Kind == SyntaxKind.LocalDeclarationStatement) { var decl = (LocalDeclarationStatementSyntax)innerStatement; if (locals == null) { locals = ArrayBuilder <LocalSymbol> .GetInstance(); } foreach (var vdecl in decl.Declaration.Variables) { var localSymbol = SourceLocalSymbol.MakeLocal( this.Owner, this, decl.Declaration.Type, vdecl.Identifier, vdecl.Initializer, decl.IsConst ? LocalDeclarationKind.Constant : decl.IsFixed ? LocalDeclarationKind.Fixed : LocalDeclarationKind.Variable); locals.Add(localSymbol); } } } if (locals != null) { return(locals.ToImmutableAndFree()); } return(ImmutableArray <LocalSymbol> .Empty); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { SourceLocalSymbol local = null; var declarationOpt = syntax.Declaration; if ((declarationOpt != null) && (declarationOpt.Identifier.CSharpKind() != SyntaxKind.None)) { local = SourceLocalSymbol.MakeLocal(this.ContainingMemberOrLambda, this, declarationOpt.Type, declarationOpt.Identifier, LocalDeclarationKind.CatchVariable); } if ((object)local != null) { return(ImmutableArray.Create <LocalSymbol>(local)); } return(ImmutableArray <LocalSymbol> .Empty); }
public override void VisitDeclarationExpression(DeclarationExpressionSyntax node) { if (Locals == null) { Locals = ArrayBuilder <LocalSymbol> .GetInstance(); } var localSymbol = SourceLocalSymbol.MakeLocal( Binder.ContainingMemberOrLambda, Binder, node.Type, node.Variable.Identifier, node.Variable.Initializer, LocalDeclarationKind.Variable); Locals.Add(localSymbol); Visit(node.Variable.Initializer); }
// When a VariableDeclaration is used in a deconstruction, there are two cases: // - deconstruction is set, type may be set (for "var"), and no declarators. For instance, `var (x, ...)` or `(int x, ...)`. // - deconstruction is null, type may be set, and there is one declarator holding the identifier. For instance, `int x` or `x`. internal void CollectLocalsFromDeconstruction(VariableDeclarationSyntax declaration, TypeSyntax closestTypeSyntax, LocalDeclarationKind kind, ArrayBuilder <LocalSymbol> locals) { if (declaration.IsDeconstructionDeclaration) { foreach (var variable in declaration.Deconstruction.Variables) { CollectLocalsFromDeconstruction(variable, variable.Type ?? closestTypeSyntax, kind, locals); } } else { Debug.Assert(declaration.Variables.Count == 1); VariableDeclaratorSyntax declarator = declaration.Variables[0]; SourceLocalSymbol localSymbol = SourceLocalSymbol.MakeDeconstructionLocal( this.ContainingMemberOrLambda, this, closestTypeSyntax, declarator.Identifier, kind); locals.Add(localSymbol); } }
public override void VisitDeclarationExpression(DeclarationExpressionSyntax node) { var context = node?.Parent // ArgumentSyntax ?.Parent // ArgumentListSyntax ?.Parent; // invocation/constructor initializer switch (context?.Kind()) { case SyntaxKind.InvocationExpression: case SyntaxKind.ObjectCreationExpression: case SyntaxKind.ThisConstructorInitializer: case SyntaxKind.BaseConstructorInitializer: var local = SourceLocalSymbol.MakeOutVariable(_scopeBinder.ContainingMemberOrLambda, _scopeBinder, _enclosingBinderOpt, node.Type(), node.Identifier(), context); _localsBuilder.Add(local); break; default: // It looks like we are deling with a syntax tree that has a shape that could never be // produced by the LanguageParser, including all error conditions. // Out Variable declarations can only appear in an argument list of the syntax nodes mentioned above. throw ExceptionUtilities.UnexpectedValue(context?.Kind()); } }
override protected ReadOnlyArray <LocalSymbol> BuildLocals() { var declaration = this.syntax.Declaration; if (declaration == null) { return(ReadOnlyArray <LocalSymbol> .Empty); } var locals = ArrayBuilder <LocalSymbol> .GetInstance(); foreach (var variable in declaration.Variables) { var localSymbol = SourceLocalSymbol.MakeLocal( this.Owner, this, declaration.Type, variable.Identifier, variable.Initializer, LocalDeclarationKind.For); locals.Add(localSymbol); } return(locals.ToReadOnlyAndFree()); }
internal BoundLocal(SourceLocalSymbol symbol) : base(VariableKind.LocalVariable) { _symbol = symbol; }
internal BoundStaticLocal(SourceLocalSymbol symbol, BoundExpression initializer) : base(symbol) { _initialier = initializer; }
public override void VisitDeclarationPattern(DeclarationPatternSyntax node) { _localsBuilder.Add(SourceLocalSymbol.MakeLocal(_binder.ContainingMemberOrLambda, _binder, RefKind.None, node.Type, node.Identifier, LocalDeclarationKind.PatternVariable)); base.VisitDeclarationPattern(node); }
internal BoundLocal(SourceLocalSymbol symbol) : base(symbol.LocalKind) { _symbol = symbol; }
internal BoundLocal(SourceLocalSymbol symbol, VariableKind kind = VariableKind.LocalVariable) : base(kind) { Debug.Assert(kind == VariableKind.LocalVariable || kind == VariableKind.LocalTemporalVariable); _symbol = symbol; }
private BoundPattern BindDeclarationPattern( DeclarationPatternSyntax node, TypeSymbol operandType, bool hasErrors, DiagnosticBag diagnostics) { Debug.Assert(operandType != (object)null); var typeSyntax = node.Type; bool isVar; AliasSymbol aliasOpt; TypeSymbol declType = BindTypeOrVarKeyword(typeSyntax, diagnostics, out isVar, out aliasOpt); if (isVar) { declType = operandType; } if (declType == (object)null) { Debug.Assert(hasErrors); declType = this.CreateErrorType("var"); } var boundDeclType = new BoundTypeExpression(typeSyntax, aliasOpt, inferredType: isVar, type: declType); if (IsOperatorErrors(node, operandType, boundDeclType, diagnostics)) { hasErrors = true; } else { hasErrors |= CheckValidPatternType(typeSyntax, operandType, declType, isVar: isVar, patternTypeWasInSource: true, diagnostics: diagnostics); } switch (node.Designation.Kind()) { case SyntaxKind.SingleVariableDesignation: break; case SyntaxKind.DiscardDesignation: return(new BoundDeclarationPattern(node, null, boundDeclType, isVar, hasErrors)); default: throw ExceptionUtilities.UnexpectedValue(node.Designation.Kind()); } var designation = (SingleVariableDesignationSyntax)node.Designation; var identifier = designation.Identifier; SourceLocalSymbol localSymbol = this.LookupLocal(identifier); if (localSymbol != (object)null) { if ((InConstructorInitializer || InFieldInitializer) && ContainingMemberOrLambda.ContainingSymbol.Kind == SymbolKind.NamedType) { CheckFeatureAvailability(node, MessageID.IDS_FeatureExpressionVariablesInQueriesAndInitializers, diagnostics); } localSymbol.SetType(declType); // Check for variable declaration errors. hasErrors |= localSymbol.ScopeBinder.ValidateDeclarationNameConflictsInScope(localSymbol, diagnostics); if (!hasErrors) { hasErrors = CheckRestrictedTypeInAsync(this.ContainingMemberOrLambda, declType, diagnostics, typeSyntax); } return(new BoundDeclarationPattern(node, localSymbol, boundDeclType, isVar, hasErrors)); } else { // We should have the right binder in the chain for a script or interactive, so we use the field for the pattern. Debug.Assert(node.SyntaxTree.Options.Kind != SourceCodeKind.Regular); GlobalExpressionVariable expressionVariableField = LookupDeclaredField(designation); DiagnosticBag tempDiagnostics = DiagnosticBag.GetInstance(); expressionVariableField.SetType(declType, tempDiagnostics); tempDiagnostics.Free(); BoundExpression receiver = SynthesizeReceiver(node, expressionVariableField, diagnostics); var variableAccess = new BoundFieldAccess(node, receiver, expressionVariableField, null, hasErrors); return(new BoundDeclarationPattern(node, expressionVariableField, variableAccess, boundDeclType, isVar, hasErrors)); } }