本文整理汇总了C#中Mono.CSharp.ResolveContext.HasSet方法的典型用法代码示例。如果您正苦于以下问题:C# ResolveContext.HasSet方法的具体用法?C# ResolveContext.HasSet怎么用?C# ResolveContext.HasSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.ResolveContext
的用法示例。
在下文中一共展示了ResolveContext.HasSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compatible
public bool Compatible (ResolveContext ec)
{
// TODO: Implement clone
BlockContext aec = new BlockContext (ec.MemberContext, Block, ReturnType);
aec.CurrentAnonymousMethod = this;
IDisposable aec_dispose = null;
ResolveContext.Options flags = 0;
if (ec.HasSet (ResolveContext.Options.InferReturnType)) {
flags |= ResolveContext.Options.InferReturnType;
aec.ReturnTypeInference = new TypeInferenceContext ();
}
if (ec.IsInProbingMode)
flags |= ResolveContext.Options.ProbingMode;
if (ec.HasSet (ResolveContext.Options.FieldInitializerScope))
flags |= ResolveContext.Options.FieldInitializerScope;
if (ec.IsUnsafe)
flags |= ResolveContext.Options.UnsafeScope;
if (ec.HasSet (ResolveContext.Options.CheckedScope))
flags |= ResolveContext.Options.CheckedScope;
// HACK: Flag with 0 cannot be set
if (flags != 0)
aec_dispose = aec.Set (flags);
bool res = Block.Resolve (ec.CurrentBranching, aec, Block.Parameters, null);
if (aec.HasReturnLabel)
return_label = aec.ReturnLabel;
if (ec.HasSet (ResolveContext.Options.InferReturnType)) {
aec.ReturnTypeInference.FixAllTypes (ec);
ReturnType = aec.ReturnTypeInference.InferredTypeArguments [0];
}
if (aec_dispose != null) {
aec_dispose.Dispose ();
}
return res;
}
示例2: BlockContext
public BlockContext (ResolveContext rc, ExplicitBlock block, TypeSpec returnType)
: this (rc.MemberContext, block, returnType)
{
if (rc.IsUnsafe)
flags |= ResolveContext.Options.UnsafeScope;
if (rc.HasSet (ResolveContext.Options.CheckedScope))
flags |= ResolveContext.Options.CheckedScope;
}
示例3: DoResolve
protected override Expression DoResolve (ResolveContext ec)
{
if (ec.HasSet (ResolveContext.Options.ConstantScope)) {
ec.Report.Error (1706, loc, "Anonymous methods and lambda expressions cannot be used in the current context");
return null;
}
//
// Set class type, set type
//
eclass = ExprClass.Value;
//
// This hack means `The type is not accessible
// anywhere', we depend on special conversion
// rules.
//
type = InternalType.AnonymousMethod;
if (!DoResolveParameters (ec))
return null;
#if !STATIC
// FIXME: The emitted code isn't very careful about reachability
// so, ensure we have a 'ret' at the end
BlockContext bc = ec as BlockContext;
if (bc != null && bc.CurrentBranching != null && bc.CurrentBranching.CurrentUsageVector.IsUnreachable)
bc.NeedReturnLabel ();
#endif
return this;
}
示例4: Compatible
public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae)
{
if (block.Resolved)
return this;
// TODO: Implement clone
BlockContext aec = new BlockContext (ec, block, ReturnType);
aec.CurrentAnonymousMethod = ae;
var am = this as AnonymousMethodBody;
if (ec.HasSet (ResolveContext.Options.InferReturnType) && am != null) {
am.ReturnTypeInference = new TypeInferenceContext ();
}
var bc = ec as BlockContext;
if (bc != null) {
aec.AssignmentInfoOffset = bc.AssignmentInfoOffset;
aec.EnclosingLoop = bc.EnclosingLoop;
aec.EnclosingLoopOrSwitch = bc.EnclosingLoopOrSwitch;
aec.Switch = bc.Switch;
}
var errors = ec.Report.Errors;
bool res = Block.Resolve (aec);
if (res && errors == ec.Report.Errors) {
MarkReachable (new Reachability ());
if (!CheckReachableExit (ec.Report)) {
return null;
}
if (bc != null)
bc.AssignmentInfoOffset = aec.AssignmentInfoOffset;
}
if (am != null && am.ReturnTypeInference != null) {
am.ReturnTypeInference.FixAllTypes (ec);
ReturnType = am.ReturnTypeInference.InferredTypeArguments [0];
am.ReturnTypeInference = null;
//
// If e is synchronous the inferred return type is T
// If e is asynchronous and the body of F is either an expression classified as nothing
// or a statement block where no return statements have expressions, the inferred return type is Task
// If e is async and has an inferred result type T, the inferred return type is Task<T>
//
if (block.IsAsync && ReturnType != null) {
ReturnType = ReturnType.Kind == MemberKind.Void ?
ec.Module.PredefinedTypes.Task.TypeSpec :
ec.Module.PredefinedTypes.TaskGeneric.TypeSpec.MakeGenericType (ec, new [] { ReturnType });
}
}
if (res && errors != ec.Report.Errors)
return null;
return res ? this : null;
}
示例5: CreateCallSiteBinder
public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args)
{
Arguments binder_args = new Arguments (4);
MemberAccess sle = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc);
var flags = ec.HasSet (ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0;
binder_args.Add (new Argument (new BinderFlags (flags, this)));
binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), name, loc)));
binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc)));
return new Invocation (GetBinder ("UnaryOperation", loc), binder_args);
}
示例6: DoResolve
protected override Expression DoResolve (ResolveContext rc)
{
if (rc.HasSet (ResolveContext.Options.ConstantScope)) {
rc.Report.Error (1706, loc, "Anonymous methods and lambda expressions cannot be used in the current context");
return null;
}
//
// Update top-level block generated duting parsing with actual top-level block
//
if (rc.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer) && rc.CurrentMemberDefinition.Parent.PartialContainer.PrimaryConstructorParameters != null) {
var tb = rc.ConstructorBlock.ParametersBlock.TopBlock;
if (Block.TopBlock != tb) {
Block b = Block;
while (b.Parent != Block.TopBlock && b != Block.TopBlock)
b = b.Parent;
b.Parent = tb;
tb.IncludeBlock (Block, Block.TopBlock);
b.ParametersBlock.TopBlock = tb;
}
}
eclass = ExprClass.Value;
//
// This hack means `The type is not accessible
// anywhere', we depend on special conversion
// rules.
//
type = InternalType.AnonymousMethod;
if (!DoResolveParameters (rc))
return null;
return this;
}
示例7: DoResolve
protected override Expression DoResolve (ResolveContext ec)
{
constructor_method = Delegate.GetConstructor (type);
var invoke_method = Delegate.GetInvokeMethod (type);
if (!ec.HasSet (ResolveContext.Options.ConditionalAccessReceiver)) {
if (method_group.HasConditionalAccess ()) {
conditional_access_receiver = true;
ec.Set (ResolveContext.Options.ConditionalAccessReceiver);
}
}
Arguments arguments = CreateDelegateMethodArguments (ec, invoke_method.Parameters, invoke_method.Parameters.Types, loc);
method_group = method_group.OverloadResolve (ec, ref arguments, this, OverloadResolver.Restrictions.CovariantDelegate);
if (conditional_access_receiver)
ec.With (ResolveContext.Options.ConditionalAccessReceiver, false);
if (method_group == null)
return null;
var delegate_method = method_group.BestCandidate;
if (delegate_method.DeclaringType.IsNullableType) {
ec.Report.Error (1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type",
delegate_method.GetSignatureForError ());
return null;
}
if (!AllowSpecialMethodsInvocation)
Invocation.IsSpecialMethodInvocation (ec, delegate_method, loc);
ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr;
if (emg != null) {
method_group.InstanceExpression = emg.ExtensionExpression;
TypeSpec e_type = emg.ExtensionExpression.Type;
if (TypeSpec.IsValueType (e_type)) {
ec.Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates",
delegate_method.GetSignatureForError (), e_type.GetSignatureForError ());
}
}
TypeSpec rt = method_group.BestCandidateReturnType;
if (rt.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
rt = ec.BuiltinTypes.Object;
if (!Delegate.IsTypeCovariant (ec, rt, invoke_method.ReturnType)) {
Expression ret_expr = new TypeExpression (delegate_method.ReturnType, loc);
Error_ConversionFailed (ec, delegate_method, ret_expr);
}
if (method_group.IsConditionallyExcluded) {
ec.Report.SymbolRelatedToPreviousError (delegate_method);
MethodOrOperator m = delegate_method.MemberDefinition as MethodOrOperator;
if (m != null && m.IsPartialDefinition) {
ec.Report.Error (762, loc, "Cannot create delegate from partial method declaration `{0}'",
delegate_method.GetSignatureForError ());
} else {
ec.Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute",
TypeManager.CSharpSignature (delegate_method));
}
}
var expr = method_group.InstanceExpression;
if (expr != null && (expr.Type.IsGenericParameter || !TypeSpec.IsReferenceType (expr.Type)))
method_group.InstanceExpression = new BoxedCast (expr, ec.BuiltinTypes.Object);
eclass = ExprClass.Value;
return this;
}
示例8: DoResolve
Expression DoResolve(ResolveContext ec, bool lvalue_instance, bool out_access)
{
if (!IsStatic){
if (InstanceExpression == null){
//
// This can happen when referencing an instance field using
// a fully qualified type expression: TypeName.InstanceField = xxx
//
SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return null;
}
// Resolve the field's instance expression while flow analysis is turned
// off: when accessing a field "a.b", we must check whether the field
// "a.b" is initialized, not whether the whole struct "a" is initialized.
if (lvalue_instance) {
using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
Expression right_side =
out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
if (InstanceExpression != EmptyExpression.Null)
InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side);
}
} else {
if (InstanceExpression != EmptyExpression.Null) {
using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
InstanceExpression = InstanceExpression.Resolve (ec, ResolveFlags.VariableOrValue);
}
}
}
if (InstanceExpression == null)
return null;
using (ec.Set (ResolveContext.Options.OmitStructFlowAnalysis)) {
InstanceExpression.CheckMarshalByRefAccess (ec);
}
}
if (!ec.IsObsolete) {
ObsoleteAttribute oa = spec.GetAttributeObsolete ();
if (oa != null)
AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (spec), loc, ec.Report);
}
var fb = spec as FixedFieldSpec;
IVariableReference var = InstanceExpression as IVariableReference;
if (fb != null) {
IFixedExpression fe = InstanceExpression as IFixedExpression;
if (!ec.HasSet (ResolveContext.Options.FixedInitializerScope) && (fe == null || !fe.IsFixed)) {
ec.Report.Error (1666, loc, "You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement");
}
if (InstanceExpression.eclass != ExprClass.Variable) {
ec.Report.SymbolRelatedToPreviousError (spec);
ec.Report.Error (1708, loc, "`{0}': Fixed size buffers can only be accessed through locals or fields",
TypeManager.GetFullNameSignature (spec));
} else if (var != null && var.IsHoisted) {
AnonymousMethodExpression.Error_AddressOfCapturedVar (ec, var, loc);
}
return new FixedBufferPtr (this, fb.ElementType, loc).Resolve (ec);
}
eclass = ExprClass.Variable;
// If the instance expression is a local variable or parameter.
if (var == null || var.VariableInfo == null)
return this;
VariableInfo vi = var.VariableInfo;
if (!vi.IsFieldAssigned (ec, Name, loc))
return null;
variable_info = vi.GetSubStruct (Name);
return this;
}
示例9: Error_ObjectRefRequired
public static void Error_ObjectRefRequired(ResolveContext ec, Location l, string name)
{
if (ec.HasSet (ResolveContext.Options.FieldInitializerScope))
ec.Report.Error (236, l,
"A field initializer cannot reference the nonstatic field, method, or property `{0}'",
name);
else
ec.Report.Error (120, l,
"An object reference is required to access non-static member `{0}'",
name);
}
示例10: DoResolveLValue
public override Expression DoResolveLValue(ResolveContext ec, Expression right_side)
{
IVariableReference var = InstanceExpression as IVariableReference;
if (var != null && var.VariableInfo != null)
var.VariableInfo.SetFieldAssigned (ec, Name);
bool lvalue_instance = !spec.IsStatic && TypeManager.IsValueType (spec.DeclaringType);
bool out_access = right_side == EmptyExpression.OutAccess.Instance || right_side == EmptyExpression.LValueMemberOutAccess;
Expression e = DoResolve (ec, lvalue_instance, out_access);
if (e == null)
return null;
spec.MemberDefinition.SetIsAssigned ();
if ((right_side == EmptyExpression.UnaryAddress || right_side == EmptyExpression.OutAccess.Instance) &&
(spec.Modifiers & Modifiers.VOLATILE) != 0) {
ec.Report.Warning (420, 1, loc,
"`{0}': A volatile field references will not be treated as volatile",
spec.GetSignatureForError ());
}
if (spec.IsReadOnly) {
// InitOnly fields can only be assigned in constructors or initializers
if (!ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.ConstructorScope))
return Report_AssignToReadonly (ec, right_side);
if (ec.HasSet (ResolveContext.Options.ConstructorScope)) {
// InitOnly fields cannot be assigned-to in a different constructor from their declaring type
if (!TypeManager.IsEqual (ec.CurrentMemberDefinition.Parent.Definition, DeclaringType.GetDefinition ()))
return Report_AssignToReadonly (ec, right_side);
// static InitOnly fields cannot be assigned-to in an instance constructor
if (IsStatic && !ec.IsStatic)
return Report_AssignToReadonly (ec, right_side);
// instance constructors can't modify InitOnly fields of other instances of the same type
if (!IsStatic && !(InstanceExpression is This))
return Report_AssignToReadonly (ec, right_side);
}
}
if (right_side == EmptyExpression.OutAccess.Instance &&
!IsStatic && !(InstanceExpression is This) && TypeManager.mbr_type != null && TypeManager.IsSubclassOf (DeclaringType, TypeManager.mbr_type)) {
ec.Report.SymbolRelatedToPreviousError (DeclaringType);
ec.Report.Warning (197, 1, loc,
"Passing `{0}' as ref or out or taking its address may cause a runtime exception because it is a field of a marshal-by-reference class",
GetSignatureForError ());
}
eclass = ExprClass.Variable;
return this;
}
示例11: ResolveMemberAccess
public override MemberExpr ResolveMemberAccess(ResolveContext ec, Expression left, Location loc,
SimpleName original)
{
//
// If the event is local to this class, we transform ourselves into a FieldExpr
//
if (spec.DeclaringType == ec.CurrentType ||
TypeManager.IsNestedChildOf(ec.CurrentType, spec.DeclaringType)) {
// TODO: Breaks dynamic binder as currect context fields are imported and not compiled
EventField mi = spec.MemberDefinition as EventField;
if (mi != null && mi.HasBackingField) {
mi.SetIsUsed ();
if (!ec.IsObsolete)
mi.CheckObsoleteness (loc);
if ((mi.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0 && !ec.HasSet (ResolveContext.Options.CompoundAssignmentScope))
Error_AssignmentEventOnly (ec);
FieldExpr ml = new FieldExpr (mi.BackingField, loc);
InstanceExpression = null;
return ml.ResolveMemberAccess (ec, left, loc, original);
}
}
if (left is This && !ec.HasSet (ResolveContext.Options.CompoundAssignmentScope))
Error_AssignmentEventOnly (ec);
return base.ResolveMemberAccess (ec, left, loc, original);
}
示例12: CreateCallSiteBinder
public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
{
Arguments binder_args = new Arguments (4);
MemberAccess ns;
if (ec.Module.PredefinedTypes.IsPlayScriptAotMode) {
ns = new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "PlayScript", loc);
} else {
ns = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc);
}
var flags = ec.HasSet (ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0;
binder_args.Add (new Argument (new BinderFlags (flags, this)));
binder_args.Add (new Argument (new MemberAccess (new MemberAccess (ns, "ExpressionType", loc), name, loc)));
binder_args.Add (new Argument (new TypeOf (ec.CurrentType, loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation (args.CreateDynamicBinderArguments (ec), loc)));
return new Invocation (GetBinder ("UnaryOperation", loc), binder_args);
}
示例13: CreateCallSiteBinder
public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
{
Arguments binder_args = new Arguments (4);
MemberAccess ns;
if (ec.Module.PredefinedTypes.IsPlayScriptAotMode) {
ns = new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "PlayScript", loc);
} else {
ns = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc);
}
CSharpBinderFlags flags = 0;
if (ec.HasSet (ResolveContext.Options.CheckedScope))
flags = CSharpBinderFlags.CheckedContext;
if ((oper & Binary.Operator.LogicalMask) != 0)
flags |= CSharpBinderFlags.BinaryOperationLogical;
binder_args.Add (new Argument (new EnumConstant (new IntLiteral (ec.BuiltinTypes, (int) flags, loc), ec.Module.PredefinedTypes.GetBinderFlags(ec).Resolve ())));
binder_args.Add (new Argument (new MemberAccess (new MemberAccess (ns, "ExpressionType", loc), this.name, loc)));
binder_args.Add (new Argument (new TypeOf (ec.CurrentType, loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation (args.CreateDynamicBinderArguments (ec), loc)));
return new Invocation (new MemberAccess (new TypeExpression (ec.Module.PredefinedTypes.GetBinder(ec).TypeSpec, loc), "BinaryOperation", loc), binder_args);
}
示例14: Compatible
//
// Returns AnonymousMethod container if this anonymous method
// expression can be implicitly converted to the delegate type `delegate_type'
//
public Expression Compatible (ResolveContext ec, TypeSpec type)
{
Expression am;
if (compatibles.TryGetValue (type, out am))
return am;
TypeSpec delegate_type = CompatibleChecks (ec, type);
if (delegate_type == null)
return null;
//
// At this point its the first time we know the return type that is
// needed for the anonymous method. We create the method here.
//
var invoke_mb = Delegate.GetInvokeMethod (delegate_type);
TypeSpec return_type = invoke_mb.ReturnType;
//
// Second: the return type of the delegate must be compatible with
// the anonymous type. Instead of doing a pass to examine the block
// we satisfy the rule by setting the return type on the EmitContext
// to be the delegate type return type.
//
var body = CompatibleMethodBody (ec, null, return_type, delegate_type);
if (body == null)
return null;
bool etree_conversion = delegate_type != type;
try {
if (etree_conversion) {
if (ec.HasSet (ResolveContext.Options.ExpressionTreeConversion)) {
//
// Nested expression tree lambda use same scope as parent
// lambda, this also means no variable capturing between this
// and parent scope
//
am = body.Compatible (ec, ec.CurrentAnonymousMethod);
//
// Quote nested expression tree
//
if (am != null)
am = new Quote (am);
} else {
int errors = ec.Report.Errors;
using (ec.Set (ResolveContext.Options.ExpressionTreeConversion)) {
am = body.Compatible (ec);
}
//
// Rewrite expressions into expression tree when targeting Expression<T>
//
if (am != null && errors == ec.Report.Errors)
am = CreateExpressionTree (ec, delegate_type);
}
} else {
if (Block.IsAsync) {
var rt = body.ReturnType;
if (rt.Kind != MemberKind.Void &&
rt != ec.Module.PredefinedTypes.Task.TypeSpec &&
!rt.IsGenericTask) {
ec.Report.Error (4010, loc, "Cannot convert async {0} to delegate type `{1}'",
GetSignatureForError (), type.GetSignatureForError ());
}
AsyncInitializer.Create (ec, body.Block, body.Parameters, ec.CurrentMemberDefinition.Parent, rt, loc);
}
am = body.Compatible (ec);
}
} catch (CompletionResult) {
throw;
} catch (Exception e) {
throw new InternalErrorException (e, loc);
}
if (!ec.IsInProbingMode) {
compatibles.Add (type, am ?? EmptyExpression.Null);
}
return am;
}
示例15: CreateExpressionTree
public override Expression CreateExpressionTree(ResolveContext ec)
{
Arguments args = new Arguments (2);
args.Add (new Argument (child.CreateExpressionTree (ec)));
args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
if (type.IsPointer || child.Type.IsPointer)
Error_PointerInsideExpressionTree (ec);
return CreateExpressionFactoryCall (ec, ec.HasSet (ResolveContext.Options.CheckedScope) ? "ConvertChecked" : "Convert", args);
}