本文整理汇总了C#中ResolveContext.Set方法的典型用法代码示例。如果您正苦于以下问题:C# ResolveContext.Set方法的具体用法?C# ResolveContext.Set怎么用?C# ResolveContext.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResolveContext
的用法示例。
在下文中一共展示了ResolveContext.Set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: DoResolve
protected override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Value;
// FIXME: Hack
var caller_builder = (Constructor) ec.MemberContext;
//
// Spec mandates that constructor initializer will not have `this' access
//
using (ec.Set (ResolveContext.Options.BaseInitializer)) {
if (argument_list != null) {
bool dynamic;
argument_list.Resolve (ec, out dynamic);
if (dynamic) {
ec.Report.Error (1975, loc,
"The constructor call cannot be dynamically dispatched within constructor initializer");
return null;
}
}
type = ec.CurrentType;
if (this is ConstructorBaseInitializer) {
if (ec.CurrentType.BaseType == null)
return this;
type = ec.CurrentType.BaseType;
if (ec.CurrentType.IsStruct) {
ec.Report.Error (522, loc,
"`{0}': Struct constructors cannot call base constructors", caller_builder.GetSignatureForError ());
return this;
}
} else {
//
// It is legal to have "this" initializers that take no arguments
// in structs, they are just no-ops.
//
// struct D { public D (int a) : this () {}
//
if (ec.CurrentType.IsStruct && argument_list == null)
return this;
}
base_ctor = ConstructorLookup (ec, type, ref argument_list, loc);
}
if (base_ctor != null && base_ctor.MemberDefinition == caller_builder.Spec.MemberDefinition) {
ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself",
caller_builder.GetSignatureForError ());
}
return this;
}
示例3: 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;
if (Block.IsAsync) {
ec.Report.Error (1989, loc, "Async lambda expressions cannot be converted to expression trees");
}
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 {
am = body.Compatible (ec);
}
} catch (CompletionResult) {
throw;
} catch (FatalException) {
throw;
} catch (Exception e) {
throw new InternalErrorException (e, loc);
}
if (!ec.IsInProbingMode) {
compatibles.Add (type, am ?? EmptyExpression.Null);
}
return am;
}
示例4: ImplicitStandardConversionExists
//
// Returns true if the body of lambda expression can be implicitly
// converted to the delegate of type `delegate_type'
//
public bool ImplicitStandardConversionExists (ResolveContext ec, TypeSpec delegate_type)
{
using (ec.With (ResolveContext.Options.InferReturnType, false)) {
using (ec.Set (ResolveContext.Options.ProbingMode)) {
var prev = ec.Report.SetPrinter (TypeInferenceReportPrinter ?? new NullReportPrinter ());
var res = Compatible (ec, delegate_type) != null;
ec.Report.SetPrinter (prev);
return res;
}
}
}
示例5: InferReturnType
public TypeSpec InferReturnType (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegate_type)
{
Expression expr;
AnonymousExpression am;
if (compatibles.TryGetValue (delegate_type, out expr)) {
am = expr as AnonymousExpression;
return am == null ? null : am.ReturnType;
}
using (ec.Set (ResolveContext.Options.ProbingMode | ResolveContext.Options.InferReturnType)) {
ReportPrinter prev;
if (TypeInferenceReportPrinter != null) {
prev = ec.Report.SetPrinter (TypeInferenceReportPrinter);
} else {
prev = null;
}
var body = CompatibleMethodBody (ec, tic, null, delegate_type);
if (body != null) {
am = body.Compatible (ec, body);
} else {
am = null;
}
if (TypeInferenceReportPrinter != null) {
ec.Report.SetPrinter (prev);
}
}
if (am == null)
return null;
// compatibles.Add (delegate_type, am);
return am.ReturnType;
}