本文整理汇总了C#中ICSharpCode.NRefactory.MonoCSharp.ResolveContext.HasSet方法的典型用法代码示例。如果您正苦于以下问题:C# ResolveContext.HasSet方法的具体用法?C# ResolveContext.HasSet怎么用?C# ResolveContext.HasSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.MonoCSharp.ResolveContext
的用法示例。
在下文中一共展示了ResolveContext.HasSet方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 (ec.CurrentType, loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation (args.CreateDynamicBinderArguments (ec), loc)));
return new Invocation (GetBinder ("UnaryOperation", loc), binder_args);
}
示例2: BinaryFold
/// <summary>
/// Constant expression folder for binary operations.
///
/// Returns null if the expression can not be folded.
/// </summary>
static public Constant BinaryFold (ResolveContext ec, Binary.Operator oper,
Constant left, Constant right, Location loc)
{
Constant result = null;
if (left is EmptyConstantCast)
return BinaryFold (ec, oper, ((EmptyConstantCast)left).child, right, loc);
if (left is SideEffectConstant) {
result = BinaryFold (ec, oper, ((SideEffectConstant) left).value, right, loc);
if (result == null)
return null;
return new SideEffectConstant (result, left, loc);
}
if (right is EmptyConstantCast)
return BinaryFold (ec, oper, left, ((EmptyConstantCast)right).child, loc);
if (right is SideEffectConstant) {
result = BinaryFold (ec, oper, left, ((SideEffectConstant) right).value, loc);
if (result == null)
return null;
return new SideEffectConstant (result, right, loc);
}
TypeSpec lt = left.Type;
TypeSpec rt = right.Type;
bool bool_res;
if (lt.BuiltinType == BuiltinTypeSpec.Type.Bool && lt == rt) {
bool lv = (bool) left.GetValue ();
bool rv = (bool) right.GetValue ();
switch (oper) {
case Binary.Operator.BitwiseAnd:
case Binary.Operator.LogicalAnd:
return new BoolConstant (ec.BuiltinTypes, lv && rv, left.Location);
case Binary.Operator.BitwiseOr:
case Binary.Operator.LogicalOr:
return new BoolConstant (ec.BuiltinTypes, lv || rv, left.Location);
case Binary.Operator.ExclusiveOr:
return new BoolConstant (ec.BuiltinTypes, lv ^ rv, left.Location);
case Binary.Operator.Equality:
return new BoolConstant (ec.BuiltinTypes, lv == rv, left.Location);
case Binary.Operator.Inequality:
return new BoolConstant (ec.BuiltinTypes, lv != rv, left.Location);
}
return null;
}
//
// During an enum evaluation, none of the rules are valid
// Not sure whether it is bug in csc or in documentation
//
if (ec.HasSet (ResolveContext.Options.EnumScope)){
if (left is EnumConstant)
left = ((EnumConstant) left).Child;
if (right is EnumConstant)
right = ((EnumConstant) right).Child;
} else if (left is EnumConstant && rt == lt) {
switch (oper){
///
/// E operator |(E x, E y);
/// E operator &(E x, E y);
/// E operator ^(E x, E y);
///
case Binary.Operator.BitwiseOr:
case Binary.Operator.BitwiseAnd:
case Binary.Operator.ExclusiveOr:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
if (result != null)
result = result.Reduce (ec, lt);
return result;
///
/// U operator -(E x, E y);
///
case Binary.Operator.Subtraction:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
if (result != null)
result = result.Reduce (ec, EnumSpec.GetUnderlyingType (lt));
return result;
///
/// bool operator ==(E x, E y);
/// bool operator !=(E x, E y);
/// bool operator <(E x, E y);
/// bool operator >(E x, E y);
/// bool operator <=(E x, E y);
/// bool operator >=(E x, E y);
///
case Binary.Operator.Equality:
case Binary.Operator.Inequality:
case Binary.Operator.LessThan:
case Binary.Operator.GreaterThan:
//.........这里部分代码省略.........
示例3: 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;
if (!rc.ConstantCheckState)
flags &= ~Options.ConstantCheckState;
if (rc.IsInProbingMode)
flags |= ResolveContext.Options.ProbingMode;
if (rc.HasSet (ResolveContext.Options.FieldInitializerScope))
flags |= ResolveContext.Options.FieldInitializerScope;
if (rc.HasSet (ResolveContext.Options.ExpressionTreeConversion))
flags |= ResolveContext.Options.ExpressionTreeConversion;
if (rc.HasSet (ResolveContext.Options.BaseInitializer))
flags |= ResolveContext.Options.BaseInitializer;
}
示例4: 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;
}
示例5: 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;
}
示例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)
{
right = right.Resolve (ec);
if (right == null)
return null;
MemberAccess ma = target as MemberAccess;
using (ec.Set (ResolveContext.Options.CompoundAssignmentScope)) {
target = target.Resolve (ec);
}
if (target == null)
return null;
if (target is MethodGroupExpr){
ec.Report.Error (1656, loc,
"Cannot assign to `{0}' because it is a `{1}'",
((MethodGroupExpr)target).Name, target.ExprClassName);
return null;
}
var event_expr = target as EventExpr;
if (event_expr != null) {
source = Convert.ImplicitConversionRequired (ec, right, target.Type, loc);
if (source == null)
return null;
Expression rside;
if (op == Binary.Operator.Addition)
rside = EmptyExpression.EventAddition;
else if (op == Binary.Operator.Subtraction)
rside = EmptyExpression.EventSubtraction;
else
rside = null;
target = target.ResolveLValue (ec, rside);
if (target == null)
return null;
eclass = ExprClass.Value;
type = event_expr.Operator.ReturnType;
return this;
}
//
// Only now we can decouple the original source/target
// into a tree, to guarantee that we do not have side
// effects.
//
if (left == null)
left = new TargetExpression (target);
source = new Binary (op, left, right, true);
if (target is DynamicMemberAssignable) {
Arguments targs = ((DynamicMemberAssignable) target).Arguments;
source = source.Resolve (ec);
Arguments args = new Arguments (targs.Count + 1);
args.AddRange (targs);
args.Add (new Argument (source));
var binder_flags = CSharpBinderFlags.ValueFromCompoundAssignment;
//
// Compound assignment does target conversion using additional method
// call, set checked context as the binary operation can overflow
//
if (ec.HasSet (ResolveContext.Options.CheckedScope))
binder_flags |= CSharpBinderFlags.CheckedContext;
if (target is DynamicMemberBinder) {
source = new DynamicMemberBinder (ma.Name, binder_flags, args, loc).Resolve (ec);
// Handles possible event addition/subtraction
if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction) {
args = new Arguments (targs.Count + 1);
args.AddRange (targs);
args.Add (new Argument (right));
string method_prefix = op == Binary.Operator.Addition ?
Event.AEventAccessor.AddPrefix : Event.AEventAccessor.RemovePrefix;
var invoke = DynamicInvocation.CreateSpecialNameInvoke (
new MemberAccess (right, method_prefix + ma.Name, loc), args, loc).Resolve (ec);
args = new Arguments (targs.Count);
args.AddRange (targs);
source = new DynamicEventCompoundAssign (ma.Name, args,
(ExpressionStatement) source, (ExpressionStatement) invoke, loc).Resolve (ec);
}
} else {
source = new DynamicIndexBinder (binder_flags, args, loc).Resolve (ec);
}
return source;
}
return base.DoResolve (ec);
}