本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.ExecutableCodeBinder类的典型用法代码示例。如果您正苦于以下问题:C# ExecutableCodeBinder类的具体用法?C# ExecutableCodeBinder怎么用?C# ExecutableCodeBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExecutableCodeBinder类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了ExecutableCodeBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSpeculativeSemanticModelForMethodBody
private bool GetSpeculativeSemanticModelForMethodBody(SyntaxTreeSemanticModel parentModel, int position, BlockSyntax body, out SemanticModel speculativeModel)
{
position = CheckAndAdjustPosition(position);
var methodSymbol = (MethodSymbol)this.MemberSymbol;
var executablebinder = new ExecutableCodeBinder(body, methodSymbol, this.rootBinder.Next); // Strip off ExecutableCodeBinder (see ctor).
var blockBinder = executablebinder.GetBinder(body).WithAdditionalFlags(BinderFlags.SemanticModel);
speculativeModel = CreateSpeculative(parentModel, methodSymbol, body, blockBinder, position);
return true;
}
示例2: TryGetSpeculativeSemanticModelCore
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);
// local declaration statements need to be wrapped in a block so the local gets seen
if (!statement.IsKind(SyntaxKind.Block))
{
binder = new BlockBinder(methodSymbol, binder, new SyntaxList<StatementSyntax>(statement));
}
speculativeModel = CreateSpeculative(parentModel, methodSymbol, statement, binder, position);
return true;
}
示例3: GetSpeculativeSemanticModelForMethodBody
private bool GetSpeculativeSemanticModelForMethodBody(SyntaxTreeSemanticModel parentModel, int position, BlockSyntax body, out SemanticModel speculativeModel)
{
position = CheckAndAdjustPosition(position);
var methodSymbol = (MethodSymbol)this.MemberSymbol;
// Strip off ExecutableCodeBinder (see ctor).
Binder binder = this.RootBinder;
do
{
if (binder is ExecutableCodeBinder)
{
binder = binder.Next;
break;
}
binder = binder.Next;
}
while (binder != null);
Debug.Assert(binder != null);
var executablebinder = new ExecutableCodeBinder(body, methodSymbol, binder ?? this.RootBinder);
var blockBinder = executablebinder.GetBinder(body).WithAdditionalFlags(GetSemanticModelBinderFlags());
speculativeModel = CreateSpeculative(parentModel, methodSymbol, body, blockBinder, position);
return true;
}
示例4: BindLambdaBody
protected abstract BoundBlock BindLambdaBody(LambdaSymbol lambdaSymbol, ExecutableCodeBinder binder, DiagnosticBag diagnostics);
示例5: GetAttribute
internal CSharpAttributeData GetAttribute(AttributeSyntax node, NamedTypeSymbol boundAttributeType, DiagnosticBag diagnostics)
{
var boundAttribute = new ExecutableCodeBinder(node, this.ContainingMemberOrLambda, this).BindAttribute(node, boundAttributeType, diagnostics);
return GetAttribute(boundAttribute, diagnostics);
}
示例6: BindScriptFieldInitializers
/// <summary>
/// In script C#, some field initializers are assignments to fields and others are global
/// statements. There are no restrictions on accessing instance members.
/// </summary>
private static void BindScriptFieldInitializers(CSharpCompilation compilation, MethodSymbol scriptCtor,
ImmutableArray<ImmutableArray<FieldInitializer>> initializers, ArrayBuilder<BoundInitializer> boundInitializers, DiagnosticBag diagnostics,
bool generateDebugInfo, out ConsList<Imports> firstDebugImports)
{
Debug.Assert((object)scriptCtor != null);
firstDebugImports = null;
for (int i = 0; i < initializers.Length; i++)
{
ImmutableArray<FieldInitializer> siblingInitializers = initializers[i];
// All sibling initializers share the same parent node and tree so we can reuse the binder
// factory across siblings. Unfortunately, we cannot reuse the binder itself, because
// individual fields might have their own binders (e.g. because of being declared unsafe).
BinderFactory binderFactory = null;
for (int j = 0; j < siblingInitializers.Length; j++)
{
var initializer = siblingInitializers[j];
var fieldSymbol = initializer.Field;
if ((object)fieldSymbol != null && fieldSymbol.IsConst)
{
// Constants do not need field initializers.
continue;
}
var syntaxRef = initializer.Syntax;
Debug.Assert(syntaxRef.SyntaxTree.Options.Kind != SourceCodeKind.Regular);
var initializerNode = (CSharpSyntaxNode)syntaxRef.GetSyntax();
if (binderFactory == null)
{
binderFactory = compilation.GetBinderFactory(syntaxRef.SyntaxTree);
}
Binder scriptClassBinder = binderFactory.GetBinder(initializerNode);
Debug.Assert(((ImplicitNamedTypeSymbol)scriptClassBinder.ContainingMemberOrLambda).IsScriptClass);
if (generateDebugInfo && firstDebugImports == null)
{
firstDebugImports = scriptClassBinder.ImportsList;
}
Binder parentBinder = new ExecutableCodeBinder((CSharpSyntaxNode)syntaxRef.SyntaxTree.GetRoot(), scriptCtor, scriptClassBinder);
BoundInitializer boundInitializer;
if ((object)fieldSymbol != null)
{
boundInitializer = BindFieldInitializer(
new LocalScopeBinder(parentBinder).WithAdditionalFlagsAndContainingMemberOrLambda(parentBinder.Flags | BinderFlags.FieldInitializer, fieldSymbol),
fieldSymbol,
(EqualsValueClauseSyntax)initializerNode,
diagnostics);
}
else if (initializerNode.Kind == SyntaxKind.LabeledStatement)
{
// TODO: labels in interactive
var boundStatement = new BoundBadStatement(initializerNode, ImmutableArray<BoundNode>.Empty, true);
boundInitializer = new BoundGlobalStatementInitializer(initializerNode, boundStatement);
}
else
{
var collisionDetector = new LocalScopeBinder(parentBinder);
boundInitializer = BindGlobalStatement(collisionDetector, (StatementSyntax)initializerNode, diagnostics,
isLast: i == initializers.Length - 1 && j == siblingInitializers.Length - 1);
}
boundInitializers.Add(boundInitializer);
}
}
}
示例7: BindScriptFieldInitializers
/// <summary>
/// In script C#, some field initializers are assignments to fields and others are global
/// statements. There are no restrictions on accessing instance members.
/// </summary>
private static void BindScriptFieldInitializers(
CSharpCompilation compilation,
SynthesizedInteractiveInitializerMethod scriptInitializer,
ImmutableArray<ImmutableArray<FieldOrPropertyInitializer>> initializers,
ArrayBuilder<BoundInitializer> boundInitializers,
DiagnosticBag diagnostics,
out ImportChain firstDebugImports)
{
firstDebugImports = null;
for (int i = 0; i < initializers.Length; i++)
{
ImmutableArray<FieldOrPropertyInitializer> siblingInitializers = initializers[i];
// All sibling initializers share the same parent node and tree so we can reuse the binder
// factory across siblings. Unfortunately, we cannot reuse the binder itself, because
// individual fields might have their own binders (e.g. because of being declared unsafe).
BinderFactory binderFactory = null;
// Label instances must be shared across all global statements.
ScriptLocalScopeBinder.Labels labels = null;
for (int j = 0; j < siblingInitializers.Length; j++)
{
var initializer = siblingInitializers[j];
var fieldSymbol = initializer.FieldOpt;
if ((object)fieldSymbol != null && fieldSymbol.IsConst)
{
// Constants do not need field initializers.
continue;
}
var syntaxRef = initializer.Syntax;
var syntaxTree = syntaxRef.SyntaxTree;
Debug.Assert(syntaxTree.Options.Kind != SourceCodeKind.Regular);
var syntax = (CSharpSyntaxNode)syntaxRef.GetSyntax();
var syntaxRoot = syntaxTree.GetCompilationUnitRoot();
if (binderFactory == null)
{
binderFactory = compilation.GetBinderFactory(syntaxTree);
labels = new ScriptLocalScopeBinder.Labels(scriptInitializer, syntaxRoot);
}
Binder scriptClassBinder = binderFactory.GetBinder(syntax);
Debug.Assert(((NamedTypeSymbol)scriptClassBinder.ContainingMemberOrLambda).IsScriptClass);
if (firstDebugImports == null)
{
firstDebugImports = scriptClassBinder.ImportChain;
}
Binder parentBinder = new ExecutableCodeBinder(
syntaxRoot,
scriptInitializer,
new ScriptLocalScopeBinder(labels, scriptClassBinder));
BoundInitializer boundInitializer;
if ((object)fieldSymbol != null)
{
boundInitializer = BindFieldInitializer(
parentBinder.WithAdditionalFlagsAndContainingMemberOrLambda(BinderFlags.FieldInitializer, fieldSymbol),
fieldSymbol,
(EqualsValueClauseSyntax)syntax,
diagnostics);
}
else
{
boundInitializer = BindGlobalStatement(
parentBinder,
scriptInitializer,
(StatementSyntax)syntax,
diagnostics,
isLast: i == initializers.Length - 1 && j == siblingInitializers.Length - 1);
}
boundInitializers.Add(boundInitializer);
}
}
}
示例8: GetEnclosingBinder
//.........这里部分代码省略.........
if (node == this.root)
{
return RootBinder;
}
ExpressionSyntax typeOfArgument = null;
CSharpSyntaxNode unexpectedAnonymousFunction = null;
// Keep track of which fix-up should be applied first. If we see a typeof expression inside an unexpected
// anonymous function, that the typeof binder should be innermost (i.e. should have the unexpected
// anonymous function binder as its Next).
// NOTE: only meaningful if typeOfArgument is non-null;
bool typeOfEncounteredBeforeUnexpectedAnonymousFunction = false;
Binder binder = null;
for (var current = node; binder == null; current = current.ParentOrStructuredTriviaParent)
{
Debug.Assert(current != null); // Why were we asked for an enclosing binder for a node outside our root?
StatementSyntax stmt = current as StatementSyntax;
if (stmt != null)
{
if (LookupPosition.IsInStatementScope(position, stmt))
{
binder = RootBinder.GetBinder(current);
if (binder != null)
{
binder = AdjustBinderForPositionWithinStatement(position, binder, stmt);
}
}
}
else if (current.Kind == SyntaxKind.CatchClause)
{
if (LookupPosition.IsInCatchBlockScope(position, (CatchClauseSyntax)current))
{
binder = RootBinder.GetBinder(current);
}
}
else if (current.Kind == SyntaxKind.CatchFilterClause)
{
if (LookupPosition.IsInCatchFilterScope(position, (CatchFilterClauseSyntax)current))
{
binder = RootBinder.GetBinder(current);
}
}
else if (current.IsAnonymousFunction())
{
if (LookupPosition.IsInAnonymousFunctionOrQuery(position, current))
{
binder = RootBinder.GetBinder(current);
// This should only happen in error scenarios. For example, C# does not allow array rank
// specifiers in types, (e.g. int[1] x;), but the syntax model does. In order to construct
// an appropriate binder chain for the anonymous method body, we need to construct an
// ExecutableCodeBinder.
if (binder == null && unexpectedAnonymousFunction == null)
{
unexpectedAnonymousFunction = current;
}
}
}
else if (current.Kind == SyntaxKind.TypeOfExpression && typeOfArgument == null)
{
typeOfArgument = ((TypeOfExpressionSyntax)current).Type;
typeOfEncounteredBeforeUnexpectedAnonymousFunction = unexpectedAnonymousFunction == null;
}
else
{
// If this ever breaks, make sure that all callers of
// CanHaveAssociatedLocalBinder are in sync.
Debug.Assert(!current.CanHaveAssociatedLocalBinder());
}
if (current == this.root)
{
break;
}
}
binder = binder ?? RootBinder;
Debug.Assert(binder != null);
if (typeOfArgument != null && !typeOfEncounteredBeforeUnexpectedAnonymousFunction)
{
binder = new TypeofBinder(typeOfArgument, binder);
}
if (unexpectedAnonymousFunction != null)
{
binder = new ExecutableCodeBinder(unexpectedAnonymousFunction, ErrorMethodSymbol.UnknownMethod, binder);
}
if (typeOfArgument != null && typeOfEncounteredBeforeUnexpectedAnonymousFunction)
{
binder = new TypeofBinder(typeOfArgument, binder);
}
return binder.WithAdditionalFlags(BinderFlags.SemanticModel);
}
示例9: Create
/// <summary>
/// Creates a SemanticModel for an ArrowExpressionClause, which includes
/// an ExecutableCodeBinder and a ScopedExpressionBinder.
/// </summary>
internal static MethodBodySemanticModel Create(CSharpCompilation compilation, MethodSymbol owner, Binder rootBinder, ArrowExpressionClauseSyntax syntax)
{
Binder binder = new ExecutableCodeBinder(syntax, owner, rootBinder);
return new MethodBodySemanticModel(compilation, owner, binder, syntax);
}
示例10: BindLambdaBody
protected override BoundBlock BindLambdaBody(LambdaSymbol lambdaSymbol, ExecutableCodeBinder lambdaBodyBinder, DiagnosticBag diagnostics)
{
return bodyResolver(lambdaSymbol, lambdaBodyBinder, diagnostics);
}
示例11: TryGetSpeculativeSemanticModelCore
private bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, CSharpSyntaxNode initializer, out SemanticModel speculativeModel)
{
Debug.Assert(initializer is EqualsValueClauseSyntax || initializer is ConstructorInitializerSyntax);
var binder = this.GetEnclosingBinder(position);
if (binder == null)
{
speculativeModel = null;
return false;
}
switch (initializer.Kind())
{
case SyntaxKind.EqualsValueClause:
binder = new ExecutableCodeBinder(initializer, binder.ContainingMemberOrLambda, binder);
break;
case SyntaxKind.ThisConstructorInitializer:
case SyntaxKind.BaseConstructorInitializer:
ArgumentListSyntax argList = ((ConstructorInitializerSyntax)initializer).ArgumentList;
if (argList != null)
{
binder = new ExecutableCodeBinder(argList, binder.ContainingMemberOrLambda, binder);
}
break;
}
speculativeModel = CreateSpeculative(parentModel, this.MemberSymbol, initializer, binder, position);
return true;
}
示例12: GetLambdaEnclosingBinder
/// <summary>
/// Performs the same function as GetEnclosingBinder, but is known to take place within a
/// specified lambda. Walks up the syntax hierarchy until a node with an associated binder
/// is found.
/// </summary>
/// <remarks>
/// CONSIDER: can this share code with MemberSemanticModel.GetEnclosingBinder?
///
/// Returned binder doesn't need to have <see cref="BinderFlags.SemanticModel"/> set - the caller will add it.
/// </remarks>
private static Binder GetLambdaEnclosingBinder(int position, CSharpSyntaxNode startingNode, CSharpSyntaxNode containingLambda, ExecutableCodeBinder lambdaBinder)
{
Debug.Assert(containingLambda.IsAnonymousFunction());
Debug.Assert(LookupPosition.IsInAnonymousFunctionOrQuery(position, containingLambda));
var current = startingNode;
while (current != containingLambda)
{
Debug.Assert(current != null);
StatementSyntax stmt = current as StatementSyntax;
if (stmt != null)
{
if (LookupPosition.IsInStatementScope(position, stmt))
{
Binder binder = lambdaBinder.GetBinder(current);
if (binder != null)
{
return binder;
}
}
}
else if (current.Kind == SyntaxKind.CatchClause)
{
if (LookupPosition.IsInCatchBlockScope(position, (CatchClauseSyntax)current))
{
Binder binder = lambdaBinder.GetBinder(current);
if (binder != null)
{
return binder;
}
}
}
else if (current.Kind == SyntaxKind.CatchFilterClause)
{
if (LookupPosition.IsInCatchFilterScope(position, (CatchFilterClauseSyntax)current))
{
Binder binder = lambdaBinder.GetBinder(current);
if (binder != null)
{
return binder;
}
}
}
else if (current.IsAnonymousFunction())
{
if (LookupPosition.IsInAnonymousFunctionOrQuery(position, current))
{
Binder binder = lambdaBinder.GetBinder(current);
if (binder != null)
{
return binder;
}
}
}
else
{
// If this ever breaks, make sure that all callers of
// CanHaveAssociatedLocalBinder are in sync.
Debug.Assert(!current.CanHaveAssociatedLocalBinder());
}
current = current.ParentOrStructuredTriviaParent;
}
return lambdaBinder;
}
示例13: BoundLambda
public BoundLambda(CSharpSyntaxNode syntax, BoundBlock body, ImmutableArray<Diagnostic> diagnostics, ExecutableCodeBinder binder, TypeSymbol type)
: this(syntax, (LambdaSymbol)binder.MemberSymbol, body, diagnostics, binder, type)
{
}
示例14: Create
/// <summary>
/// Creates an AttributeSemanticModel that allows asking semantic questions about an attribute node.
/// </summary>
public static AttributeSemanticModel Create(CSharpCompilation compilation, AttributeSyntax syntax, NamedTypeSymbol attributeType, AliasSymbol aliasOpt, Binder rootBinder)
{
var executableBinder = new ExecutableCodeBinder(syntax, attributeType, rootBinder);
return new AttributeSemanticModel(compilation, syntax, attributeType, aliasOpt, new LocalScopeBinder(executableBinder));
}
示例15: GetEnclosingBinder
//.........这里部分代码省略.........
position,
(typeOfExpression = (TypeOfExpressionSyntax)current).OpenParenToken,
typeOfExpression.CloseParenToken))
{
typeOfArgument = typeOfExpression.Type;
typeOfEncounteredBeforeUnexpectedAnonymousFunction = unexpectedAnonymousFunction == null;
}
else if (current.Kind() == SyntaxKind.SwitchSection)
{
if (LookupPosition.IsInSwitchSectionScope(position, (SwitchSectionSyntax)current))
{
binder = rootBinder.GetBinder(current);
}
}
else if (current.Kind() == SyntaxKind.ArgumentList)
{
var argList = (ArgumentListSyntax)current;
if (LookupPosition.IsBetweenTokens(position, argList.OpenParenToken, argList.CloseParenToken))
{
binder = rootBinder.GetBinder(current);
}
}
else if (current.Kind() == SyntaxKind.EqualsValueClause)
{
binder = rootBinder.GetBinder(current);
}
else if (current.Kind() == SyntaxKind.Attribute)
{
binder = rootBinder.GetBinder(current);
}
else if (current.Kind() == SyntaxKind.ArrowExpressionClause)
{
binder = rootBinder.GetBinder(current);
}
else if (current is ExpressionSyntax &&
((current.Parent as LambdaExpressionSyntax)?.Body == current ||
(current.Parent as SwitchStatementSyntax)?.Expression == current ||
(current.Parent as CommonForEachStatementSyntax)?.Expression == current))
{
binder = rootBinder.GetBinder(current);
}
else if (current is VariableComponentSyntax &&
(current.Parent as ForEachComponentStatementSyntax)?.VariableComponent == current)
{
binder = rootBinder.GetBinder(current.Parent);
}
else if (current is VariableComponentSyntax &&
(current.Parent is VariableComponentAssignmentSyntax) &&
(current.Parent.Parent as ForStatementSyntax)?.Deconstruction == current)
{
binder = rootBinder.GetBinder(current.Parent.Parent);
}
else if (current is VariableComponentSyntax &&
(current.Parent is VariableComponentAssignmentSyntax) &&
(current.Parent.Parent as DeconstructionDeclarationStatementSyntax)?.Assignment.VariableComponent == current)
{
binder = rootBinder.GetBinder(current.Parent.Parent);
}
else
{
// If this ever breaks, make sure that all callers of
// CanHaveAssociatedLocalBinder are in sync.
Debug.Assert(!current.CanHaveAssociatedLocalBinder());
}
if (current == root)
{
break;
}
}
binder = binder ?? rootBinder.GetBinder(root) ?? rootBinder;
Debug.Assert(binder != null);
if (typeOfArgument != null && !typeOfEncounteredBeforeUnexpectedAnonymousFunction)
{
binder = new TypeofBinder(typeOfArgument, binder);
}
if (unexpectedAnonymousFunction != null)
{
binder = new ExecutableCodeBinder(unexpectedAnonymousFunction,
new LambdaSymbol(binder.ContainingMemberOrLambda,
ImmutableArray<ParameterSymbol>.Empty,
RefKind.None,
ErrorTypeSymbol.UnknownResultType,
unexpectedAnonymousFunction.Kind() == SyntaxKind.AnonymousMethodExpression ? MessageID.IDS_AnonMethod : MessageID.IDS_Lambda,
unexpectedAnonymousFunction,
isSynthesized: false),
binder);
}
if (typeOfArgument != null && typeOfEncounteredBeforeUnexpectedAnonymousFunction)
{
binder = new TypeofBinder(typeOfArgument, binder);
}
return binder;
}