本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundExpression类的典型用法代码示例。如果您正苦于以下问题:C# BoundExpression类的具体用法?C# BoundExpression怎么用?C# BoundExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundExpression类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了BoundExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:28,代码来源:DecisionTree.cs
示例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);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:Conversions.cs
示例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;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:10,代码来源:LocalRewriter_PatternSwitchStatement.cs
示例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;
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:30,代码来源:Binder.WithQueryLambdaParametersBinder.cs
示例5: BinderWithConditionalReceiver
internal BinderWithConditionalReceiver(Binder next, BoundExpression receiverExpression)
: base(next)
{
Debug.Assert(receiverExpression != null);
_receiverExpression = receiverExpression;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:7,代码来源:Binder_Flags.cs
示例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);
}
开发者ID:riversky,项目名称:roslyn,代码行数:33,代码来源:LocalRewriter_ExpressionStatement.cs
示例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;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:29,代码来源:LocalRewriter_Field.cs
示例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);
}
开发者ID:,项目名称:,代码行数:32,代码来源:
示例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);
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:29,代码来源:LocalRewriter_PropertyAccess.cs
示例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);
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:33,代码来源:AwaitLoweringRewriterPass1_ArgExpressions.cs
示例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;
}
}
}
开发者ID:riversky,项目名称:roslyn,代码行数:39,代码来源:IteratorAndAsyncCaptureWalker.cs
示例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);
}
}
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:32,代码来源:LocalRewriter_ObjectOrCollectionInitializerExpression.cs
示例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);
}
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:33,代码来源:LocalRewriter_ConditionalOperator.cs
示例14: SubsumptionDiagnosticBuilder
internal SubsumptionDiagnosticBuilder(Symbol enclosingSymbol,
Conversions conversions,
BoundExpression expression)
: base(enclosingSymbol, conversions)
{
_subsumptionTree = DecisionTree.Create(expression, expression.Type, enclosingSymbol);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:7,代码来源:SubsumptionDiagnosticBuilder.cs
示例15: Update
internal BoundSpillSequence2 Update(BoundExpression value)
{
var result = new BoundSpillSequence2(value);
result.locals = this.locals;
result.statements = this.statements;
return result;
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:AwaitLiftingRewriter.cs
示例16: LoweredDynamicOperation
public LoweredDynamicOperation(SyntheticBoundNodeFactory factory, BoundExpression siteInitialization, BoundExpression siteInvocation, TypeSymbol resultType)
{
this.Factory = factory;
this.resultType = resultType;
this.SiteInitialization = siteInitialization;
this.SiteInvocation = siteInvocation;
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:LoweredDynamicOperation.cs
示例17: CheckReceiverIfField
private void CheckReceiverIfField(BoundExpression receiverOpt)
{
if (receiverOpt != null && receiverOpt.Kind == BoundKind.FieldAccess)
{
CheckFieldAsReceiver((BoundFieldAccess)receiverOpt);
}
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:DiagnosticsPass_Warnings.cs
示例18: PopulateHelper
private void PopulateHelper(BoundExpression receiverOpt, LookupResultKind resultKind, DiagnosticInfo error)
{
VerifyClear();
this.Receiver = receiverOpt;
this.Error = error;
this.ResultKind = resultKind;
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:MethodGroup.cs
示例19: RewriteIfStatement
private static BoundStatement RewriteIfStatement(
CSharpSyntaxNode syntax,
ImmutableArray<LocalSymbol> locals,
BoundExpression rewrittenCondition,
BoundStatement rewrittenConsequence,
BoundStatement rewrittenAlternativeOpt,
bool hasErrors)
{
var afterif = new GeneratedLabelSymbol("afterif");
var builder = ArrayBuilder<BoundStatement>.GetInstance();
if (rewrittenAlternativeOpt == null)
{
// if (condition)
// consequence;
//
// becomes
//
// GotoIfFalse condition afterif;
// consequence;
// afterif:
builder.Add(new BoundConditionalGoto(rewrittenCondition.Syntax, rewrittenCondition, false, afterif));
builder.Add(rewrittenConsequence);
}
else
{
// if (condition)
// consequence;
// else
// alternative
//
// becomes
//
// GotoIfFalse condition alt;
// consequence
// goto afterif;
// alt:
// alternative;
// afterif:
var alt = new GeneratedLabelSymbol("alternative");
builder.Add(new BoundConditionalGoto(rewrittenCondition.Syntax, rewrittenCondition, false, alt));
builder.Add(rewrittenConsequence);
builder.Add(new BoundGotoStatement(syntax, afterif));
builder.Add(new BoundLabelStatement(syntax, alt));
builder.Add(rewrittenAlternativeOpt);
}
builder.Add(new BoundLabelStatement(syntax, afterif));
if (!locals.IsDefaultOrEmpty)
{
return new BoundBlock(syntax, locals, builder.ToImmutableAndFree(), hasErrors);
}
return new BoundStatementList(syntax, builder.ToImmutableAndFree(), hasErrors);
}
开发者ID:afrog33k,项目名称:csnative,代码行数:59,代码来源:LocalRewriter_IfStatement.cs
示例20: RewriteWhileStatement
private BoundStatement RewriteWhileStatement(
BoundLoopStatement loop,
BoundExpression rewrittenCondition,
BoundStatement rewrittenBody,
GeneratedLabelSymbol breakLabel,
GeneratedLabelSymbol continueLabel,
bool hasErrors)
{
Debug.Assert(loop.Kind == BoundKind.WhileStatement || loop.Kind == BoundKind.ForEachStatement);
// while (condition)
// body;
//
// becomes
//
// goto continue;
// start:
// {
// body
// continue:
// GotoIfTrue condition start;
// }
// break:
SyntaxNode syntax = loop.Syntax;
var startLabel = new GeneratedLabelSymbol("start");
BoundStatement ifConditionGotoStart = new BoundConditionalGoto(rewrittenCondition.Syntax, rewrittenCondition, true, startLabel);
BoundStatement gotoContinue = new BoundGotoStatement(syntax, continueLabel);
if (this.Instrument && !loop.WasCompilerGenerated)
{
switch (loop.Kind)
{
case BoundKind.WhileStatement:
ifConditionGotoStart = _instrumenter.InstrumentWhileStatementConditionalGotoStartOrBreak((BoundWhileStatement)loop, ifConditionGotoStart);
break;
case BoundKind.ForEachStatement:
ifConditionGotoStart = _instrumenter.InstrumentForEachStatementConditionalGotoStart((BoundForEachStatement)loop, ifConditionGotoStart);
break;
default:
throw ExceptionUtilities.UnexpectedValue(loop.Kind);
}
// mark the initial jump as hidden. We do it to tell that this is not a part of previous statement. This
// jump may be a target of another jump (for example if loops are nested) and that would give the
// impression that the previous statement is being re-executed.
gotoContinue = new BoundSequencePoint(null, gotoContinue);
}
return BoundStatementList.Synthesized(syntax, hasErrors,
gotoContinue,
new BoundLabelStatement(syntax, startLabel),
rewrittenBody,
new BoundLabelStatement(syntax, continueLabel),
ifConditionGotoStart,
new BoundLabelStatement(syntax, breakLabel));
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:59,代码来源:LocalRewriter_WhileStatement.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.BoundExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论