本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundFieldAccess类的典型用法代码示例。如果您正苦于以下问题:C# BoundFieldAccess类的具体用法?C# BoundFieldAccess怎么用?C# BoundFieldAccess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundFieldAccess类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了BoundFieldAccess类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: IsNonAgileFieldAccess
/// <remarks>
/// Based on OutputContext::IsNonAgileField.
/// </remarks>
internal static bool IsNonAgileFieldAccess(BoundFieldAccess fieldAccess, CSharpCompilation compilation)
{
// Warn if taking the address of a non-static field with a receiver other than this (possibly cast)
// and a type that descends from System.MarshalByRefObject.
if (IsInstanceFieldAccessWithNonThisReceiver(fieldAccess))
{
// NOTE: We're only trying to produce a warning, so there's no point in producing an
// error if the well-known type we need for the check is missing.
NamedTypeSymbol marshalByRefType = compilation.GetWellKnownType(WellKnownType.System_MarshalByRefObject);
TypeSymbol baseType = fieldAccess.FieldSymbol.ContainingType;
while ((object)baseType != null)
{
if (baseType == marshalByRefType)
{
return true;
}
// NOTE: We're only trying to produce a warning, so there's no point in producing a
// use site diagnostic if we can't walk up the base type hierarchy.
baseType = baseType.BaseTypeNoUseSiteDiagnostics;
}
}
return false;
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:29,代码来源:DiagnosticsPass_Warnings.cs
示例3: CheckFieldAsReceiver
/// <remarks>
/// This is for when we are dotting into a field.
/// Distinguish from <see cref="CheckFieldAddress"/>.
///
/// NOTE: dev11 also calls this on string initializers in fixed statements,
/// but never accomplishes anything since string is a reference type. This
/// is probably a bug, but fixing it would be a breaking change.
/// </remarks>
private void CheckFieldAsReceiver(BoundFieldAccess fieldAccess)
{
// From ExpressionBinder.cpp:
// Taking the address of a field is suspect if the type is marshalbyref.
// REVIEW ShonK: Is this really the best way to handle this? It'd be so much more
// bullet proof for ilgen to error when it spits out the ldflda....
FieldSymbol fieldSymbol = fieldAccess.FieldSymbol;
if (IsNonAgileFieldAccess(fieldAccess, _compilation) && !fieldSymbol.Type.IsReferenceType)
{
Error(ErrorCode.WRN_CallOnNonAgileField, fieldAccess, fieldSymbol);
}
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:22,代码来源:DiagnosticsPass_Warnings.cs
示例4: CheckFieldAddress
/// <remarks>
/// This is for when we are taking the address of a field.
/// Distinguish from <see cref="CheckFieldAsReceiver"/>.
/// </remarks>
private void CheckFieldAddress(BoundFieldAccess fieldAccess, Symbol consumerOpt)
{
FieldSymbol fieldSymbol = fieldAccess.FieldSymbol;
// We can safely suppress this warning when calling an Interlocked API
if (fieldSymbol.IsVolatile && ((object)consumerOpt == null || !IsInterlockedAPI(consumerOpt)))
{
Error(ErrorCode.WRN_VolatileByRef, fieldAccess, fieldSymbol);
}
if (IsNonAgileFieldAccess(fieldAccess, _compilation))
{
Error(ErrorCode.WRN_ByRefNonAgileField, fieldAccess, fieldSymbol);
}
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:19,代码来源:DiagnosticsPass_Warnings.cs
示例5: ConstructFieldLikeEventAccessorBody_Regular
/// <summary>
/// Generate a thread-safe accessor for a regular field-like event.
///
/// DelegateType tmp0 = _event; //backing field
/// DelegateType tmp1;
/// DelegateType tmp2;
/// do {
/// tmp1 = tmp0;
/// tmp2 = (DelegateType)Delegate.Combine(tmp1, value); //Remove for -=
/// tmp0 = Interlocked.CompareExchange<DelegateType>(ref _event, tmp2, tmp1);
/// } while ((object)tmp0 != (object)tmp1);
/// </summary>
internal static BoundBlock ConstructFieldLikeEventAccessorBody_Regular(SourceEventSymbol eventSymbol, bool isAddMethod, CSharpCompilation compilation, DiagnosticBag diagnostics)
{
CSharpSyntaxNode syntax = eventSymbol.CSharpSyntaxNode;
TypeSymbol delegateType = eventSymbol.Type;
MethodSymbol accessor = isAddMethod ? eventSymbol.AddMethod : eventSymbol.RemoveMethod;
ParameterSymbol thisParameter = accessor.ThisParameter;
TypeSymbol boolType = compilation.GetSpecialType(SpecialType.System_Boolean);
MethodSymbol updateMethod = (MethodSymbol)compilation.GetSpecialTypeMember(isAddMethod ? SpecialMember.System_Delegate__Combine : SpecialMember.System_Delegate__Remove);
MethodSymbol compareExchangeMethod = GetConstructedCompareExchangeMethod(delegateType, compilation, accessor.Locations[0], diagnostics);
if ((object)compareExchangeMethod == null)
{
return new BoundBlock(syntax,
locals: ImmutableArray<LocalSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(
new BoundReturnStatement(syntax,
expressionOpt: null)
{ WasCompilerGenerated = true }))
{ WasCompilerGenerated = true };
}
GeneratedLabelSymbol loopLabel = new GeneratedLabelSymbol("loop");
const int numTemps = 3;
LocalSymbol[] tmps = new LocalSymbol[numTemps];
BoundLocal[] boundTmps = new BoundLocal[numTemps];
for (int i = 0; i < numTemps; i++)
{
tmps[i] = new SynthesizedLocal(accessor, delegateType, SynthesizedLocalKind.LoweringTemp);
boundTmps[i] = new BoundLocal(syntax, tmps[i], null, delegateType);
}
BoundThisReference fieldReceiver = eventSymbol.IsStatic ?
null :
new BoundThisReference(syntax, thisParameter.Type) { WasCompilerGenerated = true };
BoundFieldAccess boundBackingField = new BoundFieldAccess(syntax,
receiver: fieldReceiver,
fieldSymbol: eventSymbol.AssociatedField,
constantValueOpt: null)
{ WasCompilerGenerated = true };
BoundParameter boundParameter = new BoundParameter(syntax,
parameterSymbol: accessor.Parameters[0])
{ WasCompilerGenerated = true };
// tmp0 = _event;
BoundStatement tmp0Init = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[0],
right: boundBackingField,
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// LOOP:
BoundStatement loopStart = new BoundLabelStatement(syntax,
label: loopLabel)
{ WasCompilerGenerated = true };
// tmp1 = tmp0;
BoundStatement tmp1Update = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[1],
right: boundTmps[0],
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// (DelegateType)Delegate.Combine(tmp1, value)
BoundExpression delegateUpdate = BoundConversion.SynthesizedNonUserDefined(syntax,
operand: BoundCall.Synthesized(syntax,
receiverOpt: null,
method: updateMethod,
arguments: ImmutableArray.Create<BoundExpression>(boundTmps[1], boundParameter)),
kind: ConversionKind.ExplicitReference,
type: delegateType);
// tmp2 = (DelegateType)Delegate.Combine(tmp1, value);
BoundStatement tmp2Update = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[2],
right: delegateUpdate,
type: delegateType)
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:MethodBodySynthesizer.cs
示例6: ConstructFieldLikeEventAccessorBody_WinRT
/// <summary>
/// Generate a thread-safe accessor for a WinRT field-like event.
///
/// Add:
/// return EventRegistrationTokenTable<Event>.GetOrCreateEventRegistrationTokenTable(ref _tokenTable).AddEventHandler(value);
///
/// Remove:
/// EventRegistrationTokenTable<Event>.GetOrCreateEventRegistrationTokenTable(ref _tokenTable).RemoveEventHandler(value);
/// </summary>
internal static BoundBlock ConstructFieldLikeEventAccessorBody_WinRT(SourceEventSymbol eventSymbol, bool isAddMethod, CSharpCompilation compilation, DiagnosticBag diagnostics)
{
CSharpSyntaxNode syntax = eventSymbol.CSharpSyntaxNode;
MethodSymbol accessor = isAddMethod ? eventSymbol.AddMethod : eventSymbol.RemoveMethod;
Debug.Assert((object)accessor != null);
FieldSymbol field = eventSymbol.AssociatedField;
Debug.Assert((object)field != null);
NamedTypeSymbol fieldType = (NamedTypeSymbol)field.Type;
Debug.Assert(fieldType.Name == "EventRegistrationTokenTable");
MethodSymbol getOrCreateMethod = (MethodSymbol)Binder.GetWellKnownTypeMember(
compilation,
WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T__GetOrCreateEventRegistrationTokenTable,
diagnostics,
syntax: syntax);
if ((object)getOrCreateMethod == null)
{
Debug.Assert(diagnostics.HasAnyErrors());
return null;
}
getOrCreateMethod = getOrCreateMethod.AsMember(fieldType);
WellKnownMember processHandlerMember = isAddMethod
? WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T__AddEventHandler
: WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T__RemoveEventHandler;
MethodSymbol processHandlerMethod = (MethodSymbol)Binder.GetWellKnownTypeMember(
compilation,
processHandlerMember,
diagnostics,
syntax: syntax);
if ((object)processHandlerMethod == null)
{
Debug.Assert(diagnostics.HasAnyErrors());
return null;
}
processHandlerMethod = processHandlerMethod.AsMember(fieldType);
// _tokenTable
BoundFieldAccess fieldAccess = new BoundFieldAccess(
syntax,
field.IsStatic ? null : new BoundThisReference(syntax, accessor.ThisParameter.Type),
field,
constantValueOpt: null)
{ WasCompilerGenerated = true };
// EventRegistrationTokenTable<Event>.GetOrCreateEventRegistrationTokenTable(ref _tokenTable)
BoundCall getOrCreateCall = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: getOrCreateMethod,
arguments: fieldAccess);
// value
BoundParameter parameterAccess = new BoundParameter(
syntax,
accessor.Parameters.Single());
// EventRegistrationTokenTable<Event>.GetOrCreateEventRegistrationTokenTable(ref _tokenTable).AddHandler(value) // or RemoveHandler
BoundCall processHandlerCall = BoundCall.Synthesized(
syntax,
receiverOpt: getOrCreateCall,
method: processHandlerMethod,
arguments: parameterAccess);
if (isAddMethod)
{
// {
// return EventRegistrationTokenTable<Event>.GetOrCreateEventRegistrationTokenTable(ref _tokenTable).AddHandler(value);
// }
BoundStatement returnStatement = BoundReturnStatement.Synthesized(syntax, processHandlerCall);
return BoundBlock.SynthesizedNoLocals(syntax, returnStatement);
}
else
{
// {
// EventRegistrationTokenTable<Event>.GetOrCreateEventRegistrationTokenTable(ref _tokenTable).RemoveHandler(value);
// return;
// }
BoundStatement callStatement = new BoundExpressionStatement(syntax, processHandlerCall);
BoundStatement returnStatement = new BoundReturnStatement(syntax, expressionOpt: null);
return BoundBlock.SynthesizedNoLocals(syntax, callStatement, returnStatement);
}
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:100,代码来源:MethodBodySynthesizer.cs
示例7: ConstructAutoPropertyAccessorBody
/// <summary>
/// Construct a body for an auto-property accessor (updating or returning the backing field).
/// </summary>
internal static BoundBlock ConstructAutoPropertyAccessorBody(SourceMethodSymbol accessor)
{
Debug.Assert(accessor.MethodKind == MethodKind.PropertyGet || accessor.MethodKind == MethodKind.PropertySet);
var property = (SourcePropertySymbol)accessor.AssociatedSymbol;
CSharpSyntaxNode syntax = property.CSharpSyntaxNode;
BoundExpression thisReference = null;
if (!accessor.IsStatic)
{
var thisSymbol = accessor.ThisParameter;
thisReference = new BoundThisReference(syntax, thisSymbol.Type) { WasCompilerGenerated = true };
}
var field = property.BackingField;
var fieldAccess = new BoundFieldAccess(syntax, thisReference, field, ConstantValue.NotAvailable) { WasCompilerGenerated = true };
BoundStatement statement;
if (accessor.MethodKind == MethodKind.PropertyGet)
{
statement = new BoundReturnStatement(syntax, fieldAccess) { WasCompilerGenerated = true };
}
else
{
Debug.Assert(accessor.MethodKind == MethodKind.PropertySet);
var parameter = accessor.Parameters[0];
statement = new BoundExpressionStatement(
syntax,
new BoundAssignmentOperator(
syntax,
fieldAccess,
new BoundParameter(syntax, parameter) { WasCompilerGenerated = true },
property.Type)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
}
statement = new BoundSequencePoint(accessor.SyntaxNode, statement) { WasCompilerGenerated = true };
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create<BoundStatement>(statement)) { WasCompilerGenerated = true };
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:43,代码来源:MethodBodySynthesizer.cs
示例8: VisitFieldAccess
public override BoundNode VisitFieldAccess(BoundFieldAccess node)
{
BoundExpression receiverOpt = (BoundExpression)this.Visit(node.ReceiverOpt);
TypeSymbol type = this.VisitType(node.Type);
if (receiverOpt == null || receiverOpt.Kind != BoundKind.SpillSequence)
{
return node.Update(receiverOpt, node.FieldSymbol, node.ConstantValueOpt, node.ResultKind, type);
}
var spill = (BoundSpillSequence)receiverOpt;
return RewriteSpillSequence(spill,
node.Update(
spill.Value,
node.FieldSymbol,
node.ConstantValueOpt,
node.ResultKind,
type));
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:19,代码来源:AwaitLoweringRewriterPass1_Unary.cs
示例9: VisitFieldAccess
private BoundExpression VisitFieldAccess(BoundFieldAccess node)
{
var receiver = node.FieldSymbol.IsStatic ? _bound.Null(ExpressionType) : Visit(node.ReceiverOpt);
return ExprFactory(
"Field",
receiver, _bound.FieldInfo(node.FieldSymbol));
}
开发者ID:MichalStrehovsky,项目名称:roslyn,代码行数:7,代码来源:ExpressionLambdaRewriter.cs
示例10: VisitFieldAccess
public override BoundNode VisitFieldAccess(BoundFieldAccess node)
{
if (node.ReceiverOpt != null && node.ReceiverOpt.Kind == BoundKind.ThisReference)
{
var thisSymbol = topLevelMethod.ThisParameter;
CaptureVariable(thisSymbol, node.Syntax);
}
return base.VisitFieldAccess(node);
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:10,代码来源:IteratorAndAsyncCaptureWalker.cs
示例11: MakeEventAccess
private BoundExpression MakeEventAccess(
SyntaxNode syntax,
BoundExpression rewrittenReceiver,
EventSymbol eventSymbol,
ConstantValue constantValueOpt,
LookupResultKind resultKind,
TypeSymbol type)
{
Debug.Assert(eventSymbol.HasAssociatedField);
FieldSymbol fieldSymbol = eventSymbol.AssociatedField;
Debug.Assert((object)fieldSymbol != null);
if (!eventSymbol.IsWindowsRuntimeEvent)
{
return MakeFieldAccess(syntax, rewrittenReceiver, fieldSymbol, constantValueOpt, resultKind, type);
}
NamedTypeSymbol fieldType = (NamedTypeSymbol)fieldSymbol.Type;
Debug.Assert(fieldType.Name == "EventRegistrationTokenTable");
// _tokenTable
BoundFieldAccess fieldAccess = new BoundFieldAccess(
syntax,
fieldSymbol.IsStatic ? null : rewrittenReceiver,
fieldSymbol,
constantValueOpt: null)
{ WasCompilerGenerated = true };
BoundExpression getOrCreateCall;
MethodSymbol getOrCreateMethod;
if (TryGetWellKnownTypeMember(syntax, WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T__GetOrCreateEventRegistrationTokenTable, out getOrCreateMethod))
{
getOrCreateMethod = getOrCreateMethod.AsMember(fieldType);
// EventRegistrationTokenTable<Event>.GetOrCreateEventRegistrationTokenTable(ref _tokenTable)
getOrCreateCall = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: getOrCreateMethod,
arg0: fieldAccess);
}
else
{
getOrCreateCall = new BoundBadExpression(syntax, LookupResultKind.NotInvocable, ImmutableArray<Symbol>.Empty, ImmutableArray.Create<BoundNode>(fieldAccess), ErrorTypeSymbol.UnknownResultType);
}
PropertySymbol invocationListProperty;
if (TryGetWellKnownTypeMember(syntax, WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T__InvocationList, out invocationListProperty))
{
MethodSymbol invocationListAccessor = invocationListProperty.GetMethod;
if ((object)invocationListAccessor == null)
{
string accessorName = SourcePropertyAccessorSymbol.GetAccessorName(invocationListProperty.Name,
getNotSet: true,
isWinMdOutput: invocationListProperty.IsCompilationOutputWinMdObj());
_diagnostics.Add(new CSDiagnosticInfo(ErrorCode.ERR_MissingPredefinedMember, invocationListProperty.ContainingType, accessorName), syntax.Location);
}
else
{
invocationListAccessor = invocationListAccessor.AsMember(fieldType);
return _factory.Call(getOrCreateCall, invocationListAccessor);
}
}
return new BoundBadExpression(syntax, LookupResultKind.NotInvocable, ImmutableArray<Symbol>.Empty, ImmutableArray.Create<BoundNode>(getOrCreateCall), ErrorTypeSymbol.UnknownResultType);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:69,代码来源:LocalRewriter_Event.cs
示例12: IsInstanceFieldAccessWithNonThisReceiver
private static bool IsInstanceFieldAccessWithNonThisReceiver(BoundFieldAccess fieldAccess)
{
BoundExpression receiver = fieldAccess.ReceiverOpt;
if (receiver == null || fieldAccess.FieldSymbol.IsStatic)
{
return false;
}
while (receiver.Kind == BoundKind.Conversion)
{
BoundConversion conversion = (BoundConversion)receiver;
if (conversion.ExplicitCastInCode) break;
receiver = conversion.Operand;
}
return receiver.Kind != BoundKind.ThisReference && receiver.Kind != BoundKind.BaseReference;
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:17,代码来源:DiagnosticsPass_Warnings.cs
示例13: TransformReferenceTypeFieldAccess
private BoundFieldAccess TransformReferenceTypeFieldAccess(BoundFieldAccess fieldAccess, BoundExpression receiver, ArrayBuilder<BoundExpression> stores, ArrayBuilder<LocalSymbol> temps)
{
Debug.Assert(receiver.Type.IsReferenceType);
Debug.Assert(receiver.Kind != BoundKind.TypeExpression);
BoundExpression rewrittenReceiver = VisitExpression(receiver);
if (rewrittenReceiver.Type.IsTypeParameter())
{
var memberContainingType = fieldAccess.FieldSymbol.ContainingType;
// From the verifier prospective type parameters do not contain fields or methods.
// the instance must be "boxed" to access the field
// It makes sense to box receiver before storing into a temp - no need to box twice.
rewrittenReceiver = BoxReceiver(rewrittenReceiver, memberContainingType);
}
BoundAssignmentOperator assignmentToTemp;
var receiverTemp = _factory.StoreToTemp(rewrittenReceiver, out assignmentToTemp);
stores.Add(assignmentToTemp);
temps.Add(receiverTemp.LocalSymbol);
return new BoundFieldAccess(fieldAccess.Syntax, receiverTemp, fieldAccess.FieldSymbol, null);
}
开发者ID:TyOverby,项目名称:roslyn,代码行数:22,代码来源:LocalRewriter_CompoundAssignmentOperator.cs
示例14: VisitFieldAccess
public override BoundNode VisitFieldAccess(BoundFieldAccess node)
{
BoundExpression rewrittenReceiver = VisitExpression(node.ReceiverOpt);
return MakeFieldAccess(node.Syntax, rewrittenReceiver, node.FieldSymbol, node.ConstantValue, node.ResultKind, node.Type, node);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:5,代码来源:LocalRewriter_Field.cs
示例15: GetDefaultParameterSpecial
private BoundExpression GetDefaultParameterSpecial(SyntaxNode syntax, ParameterSymbol parameter)
{
// We have a call to a method M([Optional] object x) which omits the argument. The value we generate
// for the argument depends on the presence or absence of other attributes. The rules are:
//
// * If the parameter is marked as [MarshalAs(Interface)], [MarshalAs(IUnknown)] or [MarshalAs(IDispatch)]
// then the argument is null.
// * Otherwise, if the parameter is marked as [IUnknownConstant] then the argument is
// new UnknownWrapper(null)
// * Otherwise, if the parameter is marked as [IDispatchConstant] then the argument is
// new DispatchWrapper(null)
// * Otherwise, the argument is Type.Missing.
BoundExpression defaultValue;
if (parameter.IsMarshalAsObject)
{
// default(object)
defaultValue = new BoundDefaultOperator(syntax, parameter.Type);
}
else if (parameter.IsIUnknownConstant)
{
// new UnknownWrapper(default(object))
var methodSymbol = (MethodSymbol)_compilation.GetWellKnownTypeMember(WellKnownMember.System_Runtime_InteropServices_UnknownWrapper__ctor);
var argument = new BoundDefaultOperator(syntax, parameter.Type);
defaultValue = new BoundObjectCreationExpression(syntax, methodSymbol, argument);
}
else if (parameter.IsIDispatchConstant)
{
// new DispatchWrapper(default(object))
var methodSymbol = (MethodSymbol)_compilation.GetWellKnownTypeMember(WellKnownMember.System_Runtime_InteropServices_DispatchWrapper__ctor);
var argument = new BoundDefaultOperator(syntax, parameter.Type);
defaultValue = new BoundObjectCreationExpression(syntax, methodSymbol, argument);
}
else
{
// Type.Missing
var fieldSymbol = (FieldSymbol)_compilation.GetWellKnownTypeMember(WellKnownMember.System_Type__Missing);
defaultValue = new BoundFieldAccess(syntax, null, fieldSymbol, ConstantValue.NotAvailable);
}
defaultValue = MakeConversionNode(defaultValue, parameter.Type, @checked: false);
return defaultValue;
}
开发者ID:jkotas,项目名称:roslyn,代码行数:45,代码来源:LocalRewriter_Call.cs
示例16: VisitFieldAccess
public override BoundNode VisitFieldAccess(BoundFieldAccess node)
{
CheckReceiverIfField(node.ReceiverOpt);
return base.VisitFieldAccess(node);
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:5,代码来源:DiagnosticsPass_Warnings.cs
示例17: VisitFieldAccess
public override BoundNode VisitFieldAccess(BoundFieldAccess node)
{
_syntaxWithReceiver = node.Syntax;
return base.VisitFieldAccess(node);
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:5,代码来源:LambdaRewriter.Analysis.cs
示例18: VisitFieldAccess
public override BoundNode VisitFieldAccess(BoundFieldAccess node)
{
BoundSpillSequence2 ss = null;
var receiver = VisitExpression(ref ss, node.ReceiverOpt);
return UpdateExpression(ss, node.Update(receiver, node.FieldSymbol, node.ConstantValueOpt, node.ResultKind, node.Type));
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:6,代码来源:AwaitLiftingRewriter.cs
示例19: BindNamedAttributeArgument
private BoundExpression BindNamedAttributeArgument(AttributeArgumentSyntax namedArgument, NamedTypeSymbol attributeType, DiagnosticBag diagnostics)
{
bool wasError;
LookupResultKind resultKind;
Symbol namedArgumentNameSymbol = BindNamedAttributeArgumentName(namedArgument, attributeType, diagnostics, out wasError, out resultKind);
ReportDiagnosticsIfObsolete(diagnostics, namedArgumentNameSymbol, namedArgument, hasBaseReceiver: false);
Debug.Assert(resultKind == LookupResultKind.Viable || wasError);
TypeSymbol namedArgumentType;
if (wasError)
{
namedArgumentType = CreateErrorType(); // don't generate cascaded errors.
}
else
{
namedArgumentType = BindNamedAttributeArgumentType(namedArgument, namedArgumentNameSymbol, attributeType, diagnostics);
}
// BindRValue just binds the expression without doing any validation (if its a valid expression for attribute argument).
// Validation is done later by AttributeExpressionVisitor
BoundExpression namedArgumentValue = this.BindValue(namedArgument.Expression, diagnostics, BindValueKind.RValue);
namedArgumentValue = GenerateConversionForAssignment(namedArgumentType, namedArgumentValue, diagnostics);
// TODO: should we create an entry even if there are binding errors?
var fieldSymbol = namedArgumentNameSymbol as FieldSymbol;
IdentifierNameSyntax nameSyntax = namedArgument.NameEquals.Name;
BoundExpression lvalue;
if ((object)fieldSymbol != null)
{
var containingAssembly = fieldSymbol.ContainingAssembly as SourceAssemblySymbol;
// We do not want to generate any unassigned field or unreferenced field diagnostics.
containingAssembly?.NoteFieldAccess(fieldSymbol, read: true, write: true);
lvalue = new BoundFieldAccess(nameSyntax, null, fieldSymbol, ConstantValue.NotAvailable, resultKind, fieldSymbol.Type);
}
else
{
var propertySymbol = namedArgumentNameSymbol as PropertySymbol;
if ((object)propertySymbol != null)
{
lvalue = new BoundPropertyAccess(nameSyntax, null, propertySymbol, resultKind, namedArgumentType);
}
else
{
lvalue = BadExpression(nameSyntax, resultKind);
}
}
return new BoundAssignmentOperator(namedArgument, lvalue, namedArgumentValue, namedArgumentType);
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:53,代码来源:Binder_Attributes.cs
示例20: MakeTupleFieldAccess
/// <summary>
/// Converts access to a tuple instance into access into the underlying ValueTuple(s).
///
/// For instance, tuple.Item8
/// produces fieldAccess(field=Item1, receiver=fieldAccess(field=Rest, receiver=ValueTuple for tuple))
/// </summary>
private BoundExpression MakeTupleFieldAccess(
CSharpSyntaxNode syntax,
FieldSymbol tupleField,
BoundExpression rewrittenReceiver,
ConstantValue constantValueOpt,
LookupResultKind resultKind,
TypeSymbol type)
{
var tupleType = tupleField.ContainingType;
NamedTypeSymbol currentLinkType = tupleType.TupleUnderlyingType;
FieldSymbol underlyingField = tupleField.TupleUnderlyingField;
if ((object)underlyingField == null)
{
// Use-site error must have been reported elsewhere.
return new BoundFieldAccess(syntax, rewrittenReceiver, tupleField, constantValueOpt, resultKind, type, hasErrors: true);
}
if (underlyingField.ContainingType != currentLinkType)
{
WellKnownMember wellKnownTupleRest = TupleTypeSymbol.GetTupleTypeMember(TupleTypeSymbol.RestPosition, TupleTypeSymbol.RestPosition);
var tupleRestField = (FieldSymbol)TupleTypeSymbol.GetWellKnownMemberInType(currentLinkType.OriginalDefinition, wellKnownTupleRest, _diagnostics, syntax);
if ((object)tupleRestField == null)
{
// error tolerance for cases when Rest is missing
return new BoundFieldAccess(syntax, rewrittenReceiver, tupleField, constantValueOpt, resultKind, type, hasErrors: true);
}
// make nested field accesses to Rest
do
{
FieldSymbol nestedFieldSymbol = tupleRestField.AsMember(currentLinkType);
currentLinkType = currentLinkType.TypeArgumentsNoUseSiteDiagnostics[TupleTypeSymbol.RestPosition - 1].TupleUnderlyingType;
rewrittenReceiver = new BoundFieldAccess(syntax, rewrittenReceiver, nestedFieldSymbol, ConstantValue.NotAvailable, LookupResultKind.Viable, currentLinkType);
}
while (underlyingField.ContainingType != currentLinkType);
}
// make a field access for the most local access
return new BoundFieldAccess(syntax, rewrittenReceiver, underlyingField, constantValueOpt, resultKind, type);
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:50,代码来源:LocalRewriter_Field.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.BoundFieldAccess类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论