本文整理汇总了C#中Mono.CSharp.ResolveContext.GetThis方法的典型用法代码示例。如果您正苦于以下问题:C# ResolveContext.GetThis方法的具体用法?C# ResolveContext.GetThis怎么用?C# ResolveContext.GetThis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.ResolveContext
的用法示例。
在下文中一共展示了ResolveContext.GetThis方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoResolve
protected override Expression DoResolve(ResolveContext ec)
{
eclass = ExprClass.Value;
// FIXME: Hack
var caller_builder = (Constructor) ec.MemberContext;
if (argument_list != null) {
bool dynamic;
//
// Spec mandates that constructor initializer will not have `this' access
//
using (ec.Set (ResolveContext.Options.BaseInitializer)) {
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 (TypeManager.IsStruct (ec.CurrentType) && argument_list == null)
return this;
}
base_constructor_group = MemberLookupFinal (
ec, null, type, ConstructorBuilder.ConstructorName, 0, MemberKind.Constructor,
BindingRestriction.AccessibleOnly | BindingRestriction.DeclaredOnly,
loc) as MethodGroupExpr;
if (base_constructor_group == null)
return this;
base_constructor_group = base_constructor_group.OverloadResolve (
ec, ref argument_list, false, loc);
if (base_constructor_group == null)
return this;
if (!ec.IsStatic)
base_constructor_group.InstanceExpression = ec.GetThis (loc);
var base_ctor = base_constructor_group.BestCandidate;
// TODO MemberCache: Does it work for inflated types ?
if (base_ctor == caller_builder.Spec){
ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself",
caller_builder.GetSignatureForError ());
}
return this;
}
示例2: DoSimpleNameResolve
//.........这里部分代码省略.........
}
if (e == null) {
/*
if (almost_matched == null && almost_matched_members.Count > 0) {
almost_matched_type = ec.CurrentType;
almost_matched = new List<MemberSpec> (almost_matched_members);
}
*/
e = ResolveAsTypeStep (ec, true);
}
if (e == null) {
if (current_block != null) {
IKnownVariable ikv = current_block.Explicit.GetKnownVariable (Name);
if (ikv != null) {
LocalInfo li = ikv as LocalInfo;
// Supress CS0219 warning
if (li != null)
li.Used = true;
Error_VariableIsUsedBeforeItIsDeclared (ec.Report, Name);
return null;
}
}
if (RootContext.EvalMode){
FieldInfo fi = Evaluator.LookupField (Name);
if (fi != null)
return new FieldExpr (Import.CreateField (fi, null), loc).Resolve (ec);
}
/*
if (almost_matched != null)
almost_matched_members = almost_matched;
if (almost_matched_type == null)
almost_matched_type = ec.CurrentType;
*/
string type_name = ec.MemberContext.CurrentType == null ? null : ec.MemberContext.CurrentType.Name;
return Error_MemberLookupFailed (ec, ec.CurrentType, null, ec.CurrentType, Name, arity,
type_name, MemberKind.All, BindingRestriction.AccessibleOnly);
}
if (e is MemberExpr) {
MemberExpr me = (MemberExpr) e;
Expression left;
if (me.IsInstance) {
if (ec.IsStatic || ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer | ResolveContext.Options.ConstantScope)) {
//
// Note that an MemberExpr can be both IsInstance and IsStatic.
// An unresolved MethodGroupExpr can contain both kinds of methods
// and each predicate is true if the MethodGroupExpr contains
// at least one of that kind of method.
//
/*
if (!me.IsStatic &&
(!intermediate || !IdenticalNameAndTypeName (ec, me, loc))) {
Error_ObjectRefRequired (ec, loc, me.GetSignatureForError ());
return null;
}
*/
//
// Pass the buck to MemberAccess and Invocation.
//
left = EmptyExpression.Null;
} else {
left = ec.GetThis (loc);
}
} else {
left = new TypeExpression (ec.CurrentType, loc);
}
me = me.ResolveMemberAccess (ec, left, loc, null);
if (me == null)
return null;
if (HasTypeArguments) {
if (!targs.Resolve (ec))
return null;
me.SetTypeArguments (ec, targs);
}
if (!me.IsStatic && (me.InstanceExpression != null && me.InstanceExpression != EmptyExpression.Null) &&
TypeManager.IsNestedFamilyAccessible (me.InstanceExpression.Type, me.DeclaringType) &&
me.InstanceExpression.Type != me.DeclaringType &&
!TypeManager.IsFamilyAccessible (me.InstanceExpression.Type, me.DeclaringType) &&
(!intermediate || !IdenticalNameAndTypeName (ec, e, loc))) {
ec.Report.Error (38, loc, "Cannot access a nonstatic member of outer type `{0}' via nested type `{1}'",
TypeManager.CSharpName (me.DeclaringType), TypeManager.CSharpName (me.InstanceExpression.Type));
return null;
}
return (right_side != null)
? me.DoResolveLValue (ec, right_side)
: me.Resolve (ec);
}
return e;
}
示例3: CommonResolve
protected override void CommonResolve (ResolveContext ec)
{
instance_expr = ec.GetThis (loc);
current_type = ec.CurrentType.BaseType;
indexer_type = current_type;
}
示例4: DoResolveInstanceExpression
void DoResolveInstanceExpression (ResolveContext ec)
{
//
// Argument is another delegate
//
if (delegate_instance_expression != null)
return;
if (method_group.IsStatic) {
delegate_instance_expression = null;
return;
}
Expression instance = method_group.InstanceExpression;
if (instance != null && instance != EmptyExpression.Null) {
delegate_instance_expression = instance;
Type instance_type = delegate_instance_expression.Type;
if (TypeManager.IsValueType (instance_type) || TypeManager.IsGenericParameter (instance_type)) {
delegate_instance_expression = new BoxedCast (
delegate_instance_expression, TypeManager.object_type);
}
} else {
delegate_instance_expression = ec.GetThis (loc);
}
}
示例5: DoResolve
public override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Value;
// TODO: ec.GetSignatureForError ()
ConstructorBuilder caller_builder = ((Constructor) ec.MemberContext).ConstructorBuilder;
if (argument_list != null) {
bool dynamic;
//
// Spec mandates that constructor initializer will not have `this' access
//
using (ec.Set (ResolveContext.Options.BaseInitializer)) {
argument_list.Resolve (ec, out dynamic);
}
if (dynamic) {
SimpleName ctor = new SimpleName (ConstructorBuilder.ConstructorName, loc);
return new DynamicInvocation (ctor, argument_list, loc).Resolve (ec) as ExpressionStatement;
}
}
type = ec.CurrentType;
if (this is ConstructorBaseInitializer) {
if (ec.CurrentType.BaseType == null)
return this;
type = ec.CurrentType.BaseType;
if (TypeManager.IsStruct (ec.CurrentType)) {
ec.Report.Error (522, loc,
"`{0}': Struct constructors cannot call base constructors", TypeManager.CSharpSignature (caller_builder));
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 (TypeManager.IsStruct (ec.CurrentType) && argument_list == null)
return this;
}
base_constructor_group = MemberLookupFinal (
ec, null, type, ConstructorBuilder.ConstructorName, MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
loc) as MethodGroupExpr;
if (base_constructor_group == null)
return this;
base_constructor_group = base_constructor_group.OverloadResolve (
ec, ref argument_list, false, loc);
if (base_constructor_group == null)
return this;
if (!ec.IsStatic)
base_constructor_group.InstanceExpression = ec.GetThis (loc);
ConstructorInfo base_ctor = (ConstructorInfo)base_constructor_group;
if (base_ctor == caller_builder){
ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself", TypeManager.CSharpSignature (caller_builder));
}
return this;
}