本文整理汇总了C#中Mono.CSharp.GenericTypeExpr.ResolveAsTypeStep方法的典型用法代码示例。如果您正苦于以下问题:C# GenericTypeExpr.ResolveAsTypeStep方法的具体用法?C# GenericTypeExpr.ResolveAsTypeStep怎么用?C# GenericTypeExpr.ResolveAsTypeStep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.GenericTypeExpr
的用法示例。
在下文中一共展示了GenericTypeExpr.ResolveAsTypeStep方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveAsTypeStep
public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
FullNamedExpression fne = ec.GenericDeclContainer.LookupGeneric (Name, loc);
if (fne != null)
return fne.ResolveAsTypeStep (ec, silent);
int errors = Report.Errors;
fne = ec.DeclContainer.LookupNamespaceOrType (Name, loc, /*ignore_cs0104=*/ false);
if (fne != null) {
if (fne.Type == null)
return fne;
FullNamedExpression nested = ResolveNested (ec, fne.Type);
if (nested != null)
return nested.ResolveAsTypeStep (ec, false);
if (targs != null) {
GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
return ct.ResolveAsTypeStep (ec, false);
}
return fne;
}
if (silent || errors != Report.Errors)
return null;
Error_TypeOrNamespaceNotFound (ec);
return null;
}
示例2: ResolveAsTypeStep
public override FullNamedExpression ResolveAsTypeStep(IMemberContext ec, bool silent)
{
int errors = ec.Compiler.Report.Errors;
FullNamedExpression fne = ec.LookupNamespaceOrType (Name, Arity, loc, /*ignore_cs0104=*/ false);
if (fne != null) {
if (HasTypeArguments && fne.Type != null && TypeManager.IsGenericType (fne.Type)) {
GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
return ct.ResolveAsTypeStep (ec, false);
}
return fne;
}
if (!HasTypeArguments && Name == "dynamic" &&
RootContext.Version > LanguageVersion.V_3 &&
RootContext.MetadataCompatibilityVersion > MetadataVersion.v2) {
if (!PredefinedAttributes.Get.Dynamic.IsDefined) {
ec.Compiler.Report.Error (1980, Location,
"Dynamic keyword requires `{0}' to be defined. Are you missing System.Core.dll assembly reference?",
PredefinedAttributes.Get.Dynamic.GetSignatureForError ());
}
return new DynamicTypeExpr (loc);
}
if (silent || errors != ec.Compiler.Report.Errors)
return null;
Error_TypeOrNamespaceNotFound (ec);
return null;
}
示例3: EmitCall
//.........这里部分代码省略.........
for (int i = 1; i < dyn_args_count + 1; ++i) {
p[i] = new Parameter (targs[i], "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);
}
d = new Delegate (site.NamespaceEntry, site, new TypeExpression (rt, loc),
Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
new MemberName ("Container" + index.ToString ("X")),
new ParametersCompiled (p), null);
d.CreateType ();
d.DefineType ();
d.Define ();
d.Emit ();
site.AddDelegate (d);
del_type = new TypeExpression (d.CurrentType, loc);
if (targs_for_instance != null) {
del_type_instance_access = null;
} else {
del_type_instance_access = del_type;
}
} else {
d = null;
}
var site_type_decl = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments (del_type), loc);
var field = site_container.CreateCallSiteField (site_type_decl, loc);
if (field == null)
return;
if (del_type_instance_access == null) {
var dt = d.CurrentType.DeclaringType.MakeGenericType (module, context_mvars.Select (l => l.Type).ToArray ());
del_type_instance_access = new TypeExpression (MemberCache.GetMember (dt, d.CurrentType), loc);
}
FullNamedExpression instanceAccessExprType = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec,
new TypeArguments (del_type_instance_access), loc);
BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void);
instanceAccessExprType = instanceAccessExprType.ResolveAsTypeStep (bc, false);
if (instanceAccessExprType == null)
return;
bool inflate_using_mvar = context_mvars != null && ec.IsAnonymousStoreyMutateRequired;
TypeSpec gt;
if (inflate_using_mvar || context_mvars == null) {
gt = site_container.CurrentType;
} else {
gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Select (l => l.Type).ToArray ());
}
// When site container already exists the inflated version has to be
// updated manually to contain newly created field
if (gt is InflatedTypeSpec && site_container.Fields.Count > 1) {
var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes;
var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments);
gt.MemberCache.AddMember (field.InflateMember (inflator));
}
FieldExpr site_field_expr = new FieldExpr (MemberCache.GetMember (gt, field), loc);
SymbolWriter.OpenCompilerGeneratedBlock (ec);
Arguments args = new Arguments (1);
args.Add (new Argument (binder));
StatementExpression s = new StatementExpression (new SimpleAssign (site_field_expr, new Invocation (new MemberAccess (instanceAccessExprType, "Create"), args)));
if (s.Resolve (bc)) {
Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc), loc), s, loc);
init.Emit (ec);
}
args = new Arguments (1 + dyn_args_count);
args.Add (new Argument (site_field_expr));
if (arguments != null) {
int arg_pos = 1;
foreach (Argument a in arguments) {
if (a is NamedArgument) {
// Name is not valid in this context
args.Add (new Argument (a.Expr, a.ArgType));
} else {
args.Add (a);
}
if (inflate_using_mvar && a.Type != targs[arg_pos].Type)
a.Expr.Type = targs[arg_pos].Type;
++arg_pos;
}
}
Expression target = new DelegateInvocation (new MemberAccess (site_field_expr, "Target", loc).Resolve (bc), args, loc).Resolve (bc);
if (target != null)
target.Emit (ec);
SymbolWriter.CloseCompilerGeneratedBlock (ec);
}
示例4: ResolveNamespaceOrType
public FullNamedExpression ResolveNamespaceOrType (IMemberContext rc, bool silent)
{
FullNamedExpression expr_resolved = expr.ResolveAsTypeStep (rc, silent);
if (expr_resolved == null)
return null;
string LookupIdentifier = MemberName.MakeName (Name, targs);
Namespace ns = expr_resolved as Namespace;
if (ns != null) {
FullNamedExpression retval = ns.Lookup (rc.Compiler, LookupIdentifier, loc);
if (retval == null && !silent)
ns.Error_NamespaceDoesNotExist (loc, LookupIdentifier, rc.Compiler.Report);
else if (targs != null)
retval = new GenericTypeExpr (retval.Type, targs, loc).ResolveAsTypeStep (rc, silent);
return retval;
}
TypeExpr tnew_expr = expr_resolved.ResolveAsTypeTerminal (rc, false);
if (tnew_expr == null)
return null;
Type expr_type = tnew_expr.Type;
if (TypeManager.IsGenericParameter (expr_type)) {
rc.Compiler.Report.Error (704, loc, "A nested type cannot be specified through a type parameter `{0}'",
tnew_expr.GetSignatureForError ());
return null;
}
Expression member_lookup = MemberLookup (rc.Compiler,
rc.CurrentType, expr_type, expr_type, LookupIdentifier,
MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup == null) {
if (silent)
return null;
Error_IdentifierNotFound (rc, expr_resolved, LookupIdentifier);
return null;
}
TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (rc, false);
if (texpr == null)
return null;
TypeArguments the_args = targs;
Type declaring_type = texpr.Type.DeclaringType;
if (TypeManager.HasGenericArguments (declaring_type) && !TypeManager.IsGenericTypeDefinition (expr_type)) {
while (!TypeManager.IsEqual (TypeManager.DropGenericTypeArguments (expr_type), declaring_type)) {
expr_type = expr_type.BaseType;
}
TypeArguments new_args = new TypeArguments ();
foreach (Type decl in TypeManager.GetTypeArguments (expr_type))
new_args.Add (new TypeExpression (TypeManager.TypeToCoreType (decl), loc));
if (targs != null)
new_args.Add (targs);
the_args = new_args;
}
if (the_args != null) {
GenericTypeExpr ctype = new GenericTypeExpr (texpr.Type, the_args, loc);
return ctype.ResolveAsTypeStep (rc, false);
}
return texpr;
}
示例5: DoResolve
Expression DoResolve (ResolveContext ec, Expression right_side)
{
if (type != null)
throw new Exception ();
//
// Resolve the expression with flow analysis turned off, we'll do the definite
// assignment checks later. This is because we don't know yet what the expression
// will resolve to - it may resolve to a FieldExpr and in this case we must do the
// definite assignment check on the actual field and not on the whole struct.
//
SimpleName original = expr as SimpleName;
Expression expr_resolved = expr.Resolve (ec,
ResolveFlags.VariableOrValue | ResolveFlags.Type |
ResolveFlags.Intermediate | ResolveFlags.DisableStructFlowAnalysis);
if (expr_resolved == null)
return null;
string LookupIdentifier = MemberName.MakeName (Name, targs);
Namespace ns = expr_resolved as Namespace;
if (ns != null) {
FullNamedExpression retval = ns.Lookup (ec.Compiler, LookupIdentifier, loc);
if (retval == null)
ns.Error_NamespaceDoesNotExist (loc, LookupIdentifier, ec.Report);
else if (targs != null)
retval = new GenericTypeExpr (retval.Type, targs, loc).ResolveAsTypeStep (ec, false);
return retval;
}
Type expr_type = expr_resolved.Type;
if (TypeManager.IsDynamicType (expr_type)) {
Arguments args = new Arguments (2);
args.Add (new Argument (expr_resolved.Resolve (ec)));
if (right_side != null)
args.Add (new Argument (right_side));
return new DynamicMemberBinder (right_side != null, Name, args, loc).Resolve (ec);
}
if (expr_type.IsPointer || expr_type == TypeManager.void_type ||
expr_type == TypeManager.null_type || expr_type == InternalType.AnonymousMethod) {
Unary.Error_OperatorCannotBeApplied (ec, loc, ".", expr_type);
return null;
}
Constant c = expr_resolved as Constant;
if (c != null && c.GetValue () == null) {
ec.Report.Warning (1720, 1, loc, "Expression will always cause a `{0}'",
"System.NullReferenceException");
}
if (targs != null) {
if (!targs.Resolve (ec))
return null;
}
Expression member_lookup;
member_lookup = MemberLookup (ec.Compiler,
ec.CurrentType, expr_type, expr_type, Name, loc);
if (member_lookup == null && targs != null) {
member_lookup = MemberLookup (ec.Compiler,
ec.CurrentType, expr_type, expr_type, LookupIdentifier, loc);
}
if (member_lookup == null) {
ExprClass expr_eclass = expr_resolved.eclass;
//
// Extension methods are not allowed on all expression types
//
if (expr_eclass == ExprClass.Value || expr_eclass == ExprClass.Variable ||
expr_eclass == ExprClass.IndexerAccess || expr_eclass == ExprClass.PropertyAccess ||
expr_eclass == ExprClass.EventAccess) {
ExtensionMethodGroupExpr ex_method_lookup = ec.LookupExtensionMethod (expr_type, Name, loc);
if (ex_method_lookup != null) {
ex_method_lookup.ExtensionExpression = expr_resolved;
if (targs != null) {
ex_method_lookup.SetTypeArguments (ec, targs);
}
return ex_method_lookup.DoResolve (ec);
}
}
expr = expr_resolved;
member_lookup = Error_MemberLookupFailed (ec,
ec.CurrentType, expr_type, expr_type, Name, null,
AllMemberTypes, AllBindingFlags);
if (member_lookup == null)
return null;
}
TypeExpr texpr = member_lookup as TypeExpr;
//.........这里部分代码省略.........
示例6: CheckConstraint
protected bool CheckConstraint (IResolveContext ec, Type ptype, Expression expr,
Type ctype)
{
if (TypeManager.HasGenericArguments (ctype)) {
Type[] types = TypeManager.GetTypeArguments (ctype);
TypeArguments new_args = new TypeArguments ();
for (int i = 0; i < types.Length; i++) {
Type t = types [i];
if (t.IsGenericParameter) {
int pos = t.GenericParameterPosition;
t = atypes [pos];
}
new_args.Add (new TypeExpression (t, loc));
}
TypeExpr ct = new GenericTypeExpr (ctype, new_args, loc);
if (ct.ResolveAsTypeStep (ec, false) == null)
return false;
ctype = ct.Type;
} else if (ctype.IsGenericParameter) {
int pos = ctype.GenericParameterPosition;
if (ctype.DeclaringMethod == null) {
// FIXME: Implement
return true;
} else {
ctype = atypes [pos];
}
}
if (Convert.ImplicitStandardConversionExists (expr, ctype))
return true;
Report_SymbolRelatedToPreviousError ();
Report.SymbolRelatedToPreviousError (expr.Type);
if (TypeManager.IsNullableType (expr.Type) && ctype.IsInterface) {
Report.Error (313, loc,
"The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. " +
"The nullable type `{0}' never satisfies interface constraint of type `{3}'",
TypeManager.CSharpName (expr.Type), TypeManager.CSharpName (ptype),
GetSignatureForError (), TypeManager.CSharpName (ctype));
} else {
Report.Error (309, loc,
"The type `{0}' must be convertible to `{1}' in order to " +
"use it as parameter `{2}' in the generic type or method `{3}'",
TypeManager.CSharpName (expr.Type), TypeManager.CSharpName (ctype),
TypeManager.CSharpName (ptype), GetSignatureForError ());
}
return false;
}
示例7: ResolveAsTypeStep
public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent)
{
int errors = ec.Compiler.Report.Errors;
FullNamedExpression fne = ec.LookupNamespaceOrType (Name, loc, /*ignore_cs0104=*/ false);
if (fne != null) {
if (fne.Type == null)
return fne;
FullNamedExpression nested = ResolveNested (fne.Type);
if (nested != null)
return nested.ResolveAsTypeStep (ec, false);
if (targs != null) {
if (TypeManager.IsGenericType (fne.Type)) {
GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
return ct.ResolveAsTypeStep (ec, false);
}
Namespace.Error_TypeArgumentsCannotBeUsed (fne, loc);
}
return fne;
}
if (!HasTypeArguments && Name == "dynamic" && RootContext.Version > LanguageVersion.V_3)
return new DynamicTypeExpr (loc);
if (silent || errors != ec.Compiler.Report.Errors)
return null;
Error_TypeOrNamespaceNotFound (ec);
return null;
}