本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundExpression类的典型用法代码示例。如果您正苦于以下问题:C# BoundExpression类的具体用法?C# BoundExpression怎么用?C# BoundExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundExpression类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了BoundExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static DecisionTree Create(BoundExpression expression, TypeSymbol type, Symbol enclosingSymbol)
{
Debug.Assert(expression.Type == type);
LocalSymbol temp = null;
if (expression.ConstantValue == null)
{
// Unless it is a constant, the decision tree acts on a copy of the input expression.
// We create a temp to represent that copy. Lowering will assign into this temp.
temp = new SynthesizedLocal(enclosingSymbol as MethodSymbol, type, SynthesizedLocalKind.PatternMatchingTemp, expression.Syntax, false, RefKind.None);
expression = new BoundLocal(expression.Syntax, temp, null, type);
}
if (expression.Type.CanBeAssignedNull())
{
// We need the ByType decision tree to separate null from non-null values.
// Note that, for the purpose of the decision tree (and subsumption), we
// ignore the fact that the input may be a constant, and therefore always
// or never null.
return new ByType(expression, type, temp);
}
else
{
// If it is a (e.g. builtin) value type, we can switch on its (constant) values.
// If it isn't a builtin, in practice we will only use the Default part of the
// ByValue.
return new ByValue(expression, type, temp);
}
}
示例2: ClassifyConversionFromExpression
public Conversion ClassifyConversionFromExpression(BoundExpression sourceExpression, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert(sourceExpression != null);
Debug.Assert((object)destination != null);
return ClassifyConversionFromExpression(sourceExpression, sourceExpression.Type, destination, ref useSiteDiagnostics);
}
示例3: LowerDecisionTree
/// <summary>
/// Lower the given decision tree into the given statement builder.
/// </summary>
public void LowerDecisionTree(BoundExpression expression, DecisionTree decisionTree, ArrayBuilder<BoundStatement> loweredDecisionTree)
{
var oldLoweredDecisionTree = this._loweredDecisionTree;
this._loweredDecisionTree = loweredDecisionTree;
LowerDecisionTree(expression, decisionTree);
this._loweredDecisionTree = oldLoweredDecisionTree;
}
示例4: SelectField
private BoundExpression SelectField(SimpleNameSyntax node, BoundExpression receiver, string name, DiagnosticBag diagnostics)
{
var receiverType = receiver.Type as NamedTypeSymbol;
if ((object)receiverType == null || !receiverType.IsAnonymousType)
{
// We only construct transparent query variables using anonymous types, so if we're trying to navigate through
// some other type, we must have some hinky query API where the types don't match up as expected.
// We should report this as an error of some sort.
// TODO: DevDiv #737822 - reword error message and add test.
var info = new CSDiagnosticInfo(ErrorCode.ERR_UnsupportedTransparentIdentifierAccess, name, receiver.ExpressionSymbol ?? receiverType);
Error(diagnostics, info, node);
return new BoundBadExpression(
node,
LookupResultKind.Empty,
ImmutableArray.Create<Symbol>(receiver.ExpressionSymbol),
ImmutableArray.Create<BoundNode>(receiver),
new ExtendedErrorTypeSymbol(this.Compilation, "", 0, info));
}
LookupResult lookupResult = LookupResult.GetInstance();
LookupOptions options = LookupOptions.MustBeInstance;
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
LookupMembersWithFallback(lookupResult, receiver.Type, name, 0, ref useSiteDiagnostics, basesBeingResolved: null, options: options);
diagnostics.Add(node, useSiteDiagnostics);
var result = BindMemberOfType(node, node, name, 0, receiver, default(SeparatedSyntaxList<TypeSyntax>), default(ImmutableArray<TypeSymbol>), lookupResult, BoundMethodGroupFlags.None, diagnostics);
result.WasCompilerGenerated = true;
lookupResult.Free();
return result;
}
示例5: BinderWithConditionalReceiver
internal BinderWithConditionalReceiver(Binder next, BoundExpression receiverExpression)
: base(next)
{
Debug.Assert(receiverExpression != null);
_receiverExpression = receiverExpression;
}
示例6: VisitUnusedExpression
private BoundExpression VisitUnusedExpression(BoundExpression expression)
{
if (expression.HasErrors)
{
return expression;
}
switch (expression.Kind)
{
case BoundKind.AssignmentOperator:
// Avoid extra temporary by indicating the expression value is not used.
var assignmentOperator = (BoundAssignmentOperator)expression;
return VisitAssignmentOperator(assignmentOperator, used: false);
case BoundKind.CompoundAssignmentOperator:
var compoundAssignmentOperator = (BoundCompoundAssignmentOperator)expression;
return VisitCompoundAssignmentOperator(compoundAssignmentOperator, false);
case BoundKind.Call:
var call = (BoundCall)expression;
if (call.Method.CallsAreOmitted(call.SyntaxTree))
{
return null;
}
break;
case BoundKind.DynamicInvocation:
// TODO (tomat): circumvents logic in VisitExpression...
return VisitDynamicInvocation((BoundDynamicInvocation)expression, resultDiscarded: true);
}
return VisitExpression(expression);
}
示例7: MakeFieldAccess
private BoundExpression MakeFieldAccess(
CSharpSyntaxNode syntax,
BoundExpression rewrittenReceiver,
FieldSymbol fieldSymbol,
ConstantValue constantValueOpt,
LookupResultKind resultKind,
TypeSymbol type,
BoundFieldAccess oldNodeOpt = null)
{
if (fieldSymbol.IsTupleField)
{
return MakeTupleFieldAccess(syntax, fieldSymbol, rewrittenReceiver, constantValueOpt, resultKind);
}
BoundExpression result = oldNodeOpt != null ?
oldNodeOpt.Update(rewrittenReceiver, fieldSymbol, constantValueOpt, resultKind, type) :
new BoundFieldAccess(syntax, rewrittenReceiver, fieldSymbol, constantValueOpt, resultKind, type);
if (fieldSymbol.IsFixed)
{
// a reference to a fixed buffer is translated into its address
result = new BoundConversion(syntax,
new BoundAddressOfOperator(syntax, result, syntax != null && SyntaxFacts.IsFixedStatementExpression(syntax), type, false),
new Conversion(ConversionKind.PointerToPointer), false, false, default(ConstantValue), type, false);
}
return result;
}
示例8: MakeIsDeclarationPattern
private BoundExpression MakeIsDeclarationPattern(BoundDeclarationPattern loweredPattern, BoundExpression loweredInput)
{
Debug.Assert(((object)loweredPattern.Variable == null && loweredPattern.VariableAccess.Kind == BoundKind.DiscardedExpression) ||
loweredPattern.Variable.GetTypeOrReturnType() == loweredPattern.DeclaredType.Type);
if (loweredPattern.IsVar)
{
var result = _factory.Literal(true);
if (loweredPattern.VariableAccess.Kind == BoundKind.DiscardedExpression)
{
return result;
}
Debug.Assert((object)loweredPattern.Variable != null && loweredInput.Type == loweredPattern.Variable.GetTypeOrReturnType());
var assignment = _factory.AssignmentExpression(loweredPattern.VariableAccess, loweredInput);
return _factory.MakeSequence(assignment, result);
}
if (loweredPattern.VariableAccess.Kind == BoundKind.DiscardedExpression)
{
LocalSymbol temp;
BoundLocal discard = _factory.MakeTempForDiscard((BoundDiscardedExpression)loweredPattern.VariableAccess, out temp);
return _factory.Sequence(ImmutableArray.Create(temp),
sideEffects: ImmutableArray<BoundExpression>.Empty,
result: MakeIsDeclarationPattern(loweredPattern.Syntax, loweredInput, discard, requiresNullTest: true));
}
return MakeIsDeclarationPattern(loweredPattern.Syntax, loweredInput, loweredPattern.VariableAccess, requiresNullTest: true);
}
示例9: MakePropertyGetAccess
private BoundExpression MakePropertyGetAccess(
SyntaxNode syntax,
BoundExpression rewrittenReceiver,
PropertySymbol property,
ImmutableArray<BoundExpression> rewrittenArguments,
MethodSymbol getMethodOpt = null,
BoundPropertyAccess oldNodeOpt = null)
{
if (_inExpressionLambda && rewrittenArguments.IsEmpty)
{
return oldNodeOpt != null ?
oldNodeOpt.Update(rewrittenReceiver, property, LookupResultKind.Viable, property.Type) :
new BoundPropertyAccess(syntax, rewrittenReceiver, property, LookupResultKind.Viable, property.Type);
}
else
{
var getMethod = getMethodOpt ?? property.GetOwnOrInheritedGetMethod();
Debug.Assert((object)getMethod != null);
Debug.Assert(getMethod.ParameterCount == rewrittenArguments.Length);
Debug.Assert(((object)getMethodOpt == null) || ReferenceEquals(getMethod, getMethodOpt));
return BoundCall.Synthesized(
syntax,
rewrittenReceiver,
getMethod,
rewrittenArguments);
}
}
示例10: SpillExpressionsWithReceiver
/// <summary>
/// Spill an expression list with a receiver (e.g. array access, method call), where at least one of the
/// receiver or the arguments contains an await expression.
/// </summary>
private Tuple<BoundExpression, ReadOnlyArray<BoundExpression>> SpillExpressionsWithReceiver(
BoundExpression receiverOpt,
ReadOnlyArray<BoundExpression> expressions,
SpillBuilder spillBuilder,
ReadOnlyArray<RefKind> refKindsOpt)
{
if (receiverOpt == null)
{
return Tuple.Create(default(BoundExpression), SpillExpressionList(spillBuilder, expressions));
}
// We have a non-null receiver, and an expression of the form:
// receiver[index1, index2, ..., indexN]
// or:
// receiver(arg1, arg2, ... argN)
// Build a list containing the receiver and all expressions (in that order)
var allExpressions = ReadOnlyArray<BoundExpression>.CreateFrom(receiverOpt).Concat(expressions);
var allRefKinds = (refKindsOpt != null)
? ReadOnlyArray<RefKind>.CreateFrom(RefKind.None).Concat(refKindsOpt)
: ReadOnlyArray<RefKind>.Empty;
// Spill the expressions (and possibly the receiver):
var allSpilledExpressions = SpillExpressionList(spillBuilder, allExpressions, allRefKinds);
var spilledReceiver = allSpilledExpressions.First();
var spilledArguments = allSpilledExpressions.RemoveFirst();
return Tuple.Create(spilledReceiver, spilledArguments);
}
示例11: AddSpillsForRef
/// <summary>
/// If a ref variable is to be spilled, sometimes that causes us to need to spill
/// the thing the ref variable was initialized with. For example, if the variable
/// was initialized with "structVariable.field", then the struct variable needs to
/// be spilled. This method adds to the spill set things that need to be spilled
/// based on the given refInitializer expression.
/// </summary>
private void AddSpillsForRef(BoundExpression refInitializer, IEnumerable<CSharpSyntaxNode> locations)
{
while (true)
{
if (refInitializer == null) return;
switch (refInitializer.Kind)
{
case BoundKind.Local:
var local = (BoundLocal)refInitializer;
if (!variablesCaptured.ContainsKey(local.LocalSymbol))
{
foreach (var loc in locations) variablesCaptured.Add(local.LocalSymbol, loc);
if (local.LocalSymbol.RefKind != RefKind.None)
{
refInitializer = refLocalInitializers[local.LocalSymbol];
continue;
}
}
return;
case BoundKind.FieldAccess:
var field = (BoundFieldAccess)refInitializer;
if (!field.FieldSymbol.IsStatic && field.FieldSymbol.ContainingType.IsValueType)
{
refInitializer = field.ReceiverOpt;
continue;
}
return;
default:
return;
}
}
}
示例12: AddCollectionInitializers
// Rewrite collection initializer add method calls:
// 2) new List<int> { 1 };
// ~
private void AddCollectionInitializers(ref ArrayBuilder<BoundExpression> dynamicSiteInitializers, ArrayBuilder<BoundExpression> result, BoundExpression rewrittenReceiver, ImmutableArray<BoundExpression> initializers)
{
Debug.Assert(rewrittenReceiver != null || _inExpressionLambda);
foreach (var initializer in initializers)
{
// In general bound initializers may contain bad expressions or element initializers.
// We don't lower them if they contain errors, so it's safe to assume an element initializer.
BoundExpression rewrittenInitializer;
if (initializer.Kind == BoundKind.CollectionElementInitializer)
{
rewrittenInitializer = MakeCollectionInitializer(rewrittenReceiver, (BoundCollectionElementInitializer)initializer);
}
else
{
Debug.Assert(!_inExpressionLambda);
Debug.Assert(initializer.Kind == BoundKind.DynamicCollectionElementInitializer);
rewrittenInitializer = MakeDynamicCollectionInitializer(rewrittenReceiver, (BoundDynamicCollectionElementInitializer)initializer);
}
// the call to Add may be omitted
if (rewrittenInitializer != null)
{
result.Add(rewrittenInitializer);
}
}
}
示例13: RewriteConditionalOperator
private static BoundExpression RewriteConditionalOperator(
CSharpSyntaxNode syntax,
BoundExpression rewrittenCondition,
BoundExpression rewrittenConsequence,
BoundExpression rewrittenAlternative,
ConstantValue constantValueOpt,
TypeSymbol rewrittenType)
{
// NOTE: This optimization assumes that a constant has no side effects. In the future we
// might wish to represent nodes that are known to the optimizer as having constant
// values as a sequence of side effects and a constant value; in that case the result
// of this should be a sequence containing the side effect and the consequence or alternative.
ConstantValue conditionConstantValue = rewrittenCondition.ConstantValue;
if (conditionConstantValue == ConstantValue.True)
{
return rewrittenConsequence;
}
else if (conditionConstantValue == ConstantValue.False)
{
return rewrittenAlternative;
}
else
{
return new BoundConditionalOperator(
syntax,
rewrittenCondition,
rewrittenConsequence,
rewrittenAlternative,
constantValueOpt,
rewrittenType);
}
}
示例14: SubsumptionDiagnosticBuilder
internal SubsumptionDiagnosticBuilder(Symbol enclosingSymbol,
Conversions conversions,
BoundExpression expression)
: base(enclosingSymbol, conversions)
{
_subsumptionTree = DecisionTree.Create(expression, expression.Type, enclosingSymbol);
}
示例15: Update
internal BoundSpillSequence2 Update(BoundExpression value)
{
var result = new BoundSpillSequence2(value);
result.locals = this.locals;
result.statements = this.statements;
return result;
}