本文整理汇总了C#中Mono.CSharp.TypeExpression类的典型用法代码示例。如果您正苦于以下问题:C# TypeExpression类的具体用法?C# TypeExpression怎么用?C# TypeExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeExpression类属于Mono.CSharp命名空间,在下文中一共展示了TypeExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Enum
public Enum(NamespaceContainer ns, DeclSpace parent, TypeExpression type,
Modifiers mod_flags, MemberName name, Attributes attrs)
: base(ns, parent, name, attrs, MemberKind.Enum)
{
underlying_type_expr = type;
var accmods = IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE;
ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod_flags, accmods, Location, Report);
spec = new EnumSpec (null, this, null, null, ModFlags);
}
开发者ID:tapenjoyGame,项目名称:ILSpy,代码行数:9,代码来源:enum.cs
示例2: Define
/// <summary>
/// Defines the constant in the @parent
/// </summary>
public override bool Define ()
{
if (!base.Define ())
return false;
if (!member_type.IsConstantCompatible) {
Error_InvalidConstantType (member_type, Location, Report);
}
FieldAttributes field_attr = FieldAttributes.Static | ModifiersExtensions.FieldAttr (ModFlags);
// Decimals cannot be emitted into the constant blob. So, convert to 'readonly'.
if (member_type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
field_attr |= FieldAttributes.InitOnly;
} else {
field_attr |= FieldAttributes.Literal;
}
FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType.GetMetaInfo (), field_attr);
spec = new ConstSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags, initializer);
Parent.MemberCache.AddMember (spec);
if ((field_attr & FieldAttributes.InitOnly) != 0)
Parent.PartialContainer.RegisterFieldForInitialization (this,
new FieldInitializer (this, initializer, Location));
if (declarators != null) {
foreach (var d in declarators) {
var t = new TypeExpression (d.Type, TypeExpression.Location);
var c = new Const (Parent, t, ModFlags & ~Modifiers.STATIC, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
c.initializer = d.Initializer;
if (d.Initializer is ConstInitializer)
((ConstInitializer)d.Initializer).Field = c;
((ConstInitializer) c.initializer).Name = d.Name.Value;
c.Define ();
Parent.PartialContainer.Members.Add (c);
}
}
return true;
}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:44,代码来源:const.cs
示例3: AddCapturedVariable
public Field AddCapturedVariable (string name, TypeSpec type)
{
CheckMembersDefined ();
FullNamedExpression field_type = new TypeExpression (type, Location);
if (!spec.IsGenericOrParentIsGeneric)
return AddCompilerGeneratedField (name, field_type);
const Modifiers mod = Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED;
Field f = new HoistedField (this, field_type, mod, name, null, Location);
AddField (f);
return f;
}
开发者ID:rabink,项目名称:mono,代码行数:13,代码来源:anonymous.cs
示例4: DoDefineMembers
protected override bool DoDefineMembers ()
{
if (!base.DoDefineMembers ())
return false;
Location loc = Location;
var equals_parameters = ParametersCompiled.CreateFullyResolved (
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), Compiler.BuiltinTypes.Object);
Method equals = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc),
equals_parameters, null);
equals_parameters[0].Resolve (equals, 0);
Method tostring = new Method (this, new TypeExpression (Compiler.BuiltinTypes.String, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc);
TypeExpr current_type;
if (CurrentTypeParameters != null) {
var targs = new TypeArguments ();
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
targs.Add (new TypeParameterExpr (CurrentTypeParameters[i], Location));
}
current_type = new GenericTypeExpr (Definition, targs, loc);
} else {
current_type = new TypeExpression (Definition, loc);
}
var li_other = LocalVariable.CreateCompilerGenerated (CurrentType, equals_block, loc);
equals_block.AddStatement (new BlockVariableDeclaration (new TypeExpression (li_other.Type, loc), li_other));
var other_variable = new LocalVariableReference (li_other, loc);
MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc);
Expression rs_equals = null;
Expression string_concat = new StringConstant (Compiler.BuiltinTypes, "{", loc);
Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc);
for (int i = 0; i < parameters.Count; ++i) {
var p = parameters [i];
var f = (Field) Members [i * 2];
MemberAccess equality_comparer = new MemberAccess (new MemberAccess (
system_collections_generic, "EqualityComparer",
new TypeArguments (new SimpleName (CurrentTypeParameters [i].Name, loc)), loc),
"Default", loc);
Arguments arguments_equal = new Arguments (2);
arguments_equal.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
arguments_equal.Add (new Argument (new MemberAccess (other_variable, f.Name)));
Expression field_equal = new Invocation (new MemberAccess (equality_comparer,
"Equals", loc), arguments_equal);
Arguments arguments_hashcode = new Arguments (1);
arguments_hashcode.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer,
"GetHashCode", loc), arguments_hashcode);
IntConstant FNV_prime = new IntConstant (Compiler.BuiltinTypes, 16777619, loc);
rs_hashcode = new Binary (Binary.Operator.Multiply,
new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode),
FNV_prime);
Expression field_to_string = new Conditional (new BooleanExpression (new Binary (Binary.Operator.Inequality,
new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc))),
new Invocation (new MemberAccess (
new MemberAccess (new This (f.Location), f.Name), "ToString"), null),
new StringConstant (Compiler.BuiltinTypes, string.Empty, loc), loc);
if (rs_equals == null) {
rs_equals = field_equal;
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new Binary (Binary.Operator.Addition,
new StringConstant (Compiler.BuiltinTypes, " " + p.Name + " = ", loc),
field_to_string));
continue;
}
//
// Implementation of ToString () body using string concatenation
//
string_concat = new Binary (Binary.Operator.Addition,
new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (Compiler.BuiltinTypes, ", " + p.Name + " = ", loc)),
field_to_string);
rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal);
}
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
//.........这里部分代码省略.........
开发者ID:rabink,项目名称:mono,代码行数:101,代码来源:anonymous.cs
示例5: Define
public override bool Define ()
{
if (!base.Define ())
return false;
MetaType[] required_modifier = null;
if ((ModFlags & Modifiers.VOLATILE) != 0) {
var mod = Module.PredefinedTypes.IsVolatile.Resolve ();
if (mod != null)
required_modifier = new MetaType[] { mod.GetMetaInfo () };
}
FieldBuilder = Parent.TypeBuilder.DefineField (
Name, member_type.GetMetaInfo (), required_modifier, null, ModifiersExtensions.FieldAttr (ModFlags));
spec = new FieldSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags);
//
// Don't cache inaccessible fields except for struct where we
// need them for definitive assignment checks
//
if ((ModFlags & Modifiers.BACKING_FIELD) == 0 || Parent.Kind == MemberKind.Struct) {
Parent.MemberCache.AddMember (spec);
}
if (initializer != null) {
((TypeContainer) Parent).RegisterFieldForInitialization (this,
new FieldInitializer (spec, initializer, this));
}
if (declarators != null) {
var t = new TypeExpression (MemberType, TypeExpression.Location);
int index = Parent.PartialContainer.Fields.IndexOf (this);
foreach (var d in declarators) {
var f = new Field (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null)
f.initializer = d.Initializer;
Parent.PartialContainer.Fields.Insert (++index, f);
}
}
return true;
}
开发者ID:agallero,项目名称:mono,代码行数:44,代码来源:field.cs
示例6: LookupNamespaceOrType
//
// Public function used to locate types.
//
// Returns: Type or null if they type can not be found.
//
public override FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
{
FullNamedExpression e;
if (arity == 0 && Cache.TryGetValue (name, out e) && mode != LookupMode.IgnoreAccessibility)
return e;
e = null;
if (arity == 0) {
var tp = CurrentTypeParameters;
if (tp != null) {
TypeParameter tparam = tp.Find (name);
if (tparam != null)
e = new TypeParameterExpr (tparam, Location.Null);
}
}
if (e == null) {
TypeSpec t = LookupNestedTypeInHierarchy (name, arity);
if (t != null && (t.IsAccessible (this) || mode == LookupMode.IgnoreAccessibility))
e = new TypeExpression (t, Location.Null);
else {
var errors = Compiler.Report.Errors;
e = Parent.LookupNamespaceOrType (name, arity, mode, loc);
// TODO: LookupNamespaceOrType does more than just lookup. The result
// cannot be cached or the error reporting won't happen
if (errors != Compiler.Report.Errors)
return e;
}
}
// TODO MemberCache: How to cache arity stuff ?
if (arity == 0 && mode == LookupMode.Normal)
Cache[name] = e;
return e;
}
开发者ID:razzfazz,项目名称:mono,代码行数:44,代码来源:class.cs
示例7: Visit
public override object Visit (TypeExpression typeExpression)
{
var result = new FullTypeName ();
if (typeExpression.Type != null) {
result.AddChild (new Identifier (typeExpression.Type.Name, Convert (typeExpression.Location)));
}
// if (!string.IsNullOrEmpty (typeExpression.)) {
// result.AddChild (new Identifier (typeExpression.Namespace + "." + typeExpression.Name, Convert (typeExpression.Location)));
// } else {
// result.AddChild (new Identifier (typeExpression.Name, Convert (typeExpression.Location)));
// }
return result;
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:13,代码来源:CSharpParser.cs
示例8: CreateSiteType
TypeExpr CreateSiteType(CompilerContext ctx, Arguments arguments, int dyn_args_count, bool is_statement)
{
int default_args = is_statement ? 1 : 2;
bool has_ref_out_argument = false;
FullNamedExpression[] targs = new FullNamedExpression[dyn_args_count + default_args];
targs [0] = new TypeExpression (TypeManager.call_site_type, loc);
for (int i = 0; i < dyn_args_count; ++i) {
TypeSpec arg_type;
Argument a = arguments [i];
if (a.Type == TypeManager.null_type)
arg_type = TypeManager.object_type;
else
arg_type = a.Type;
if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
has_ref_out_argument = true;
targs [i + 1] = new TypeExpression (arg_type, loc);
}
TypeExpr del_type = null;
if (!has_ref_out_argument) {
string d_name = is_statement ? "Action" : "Func";
TypeSpec t = TypeManager.CoreLookupType (ctx, "System", d_name, dyn_args_count + default_args, MemberKind.Delegate, false);
if (t != null) {
if (!is_statement)
targs [targs.Length - 1] = new TypeExpression (type, loc);
del_type = new GenericTypeExpr (t, new TypeArguments (targs), loc);
}
}
//
// Create custom delegate when no appropriate predefined one is found
//
if (del_type == null) {
TypeSpec rt = is_statement ? TypeManager.void_type : type;
Parameter[] p = new Parameter [dyn_args_count + 1];
p[0] = new Parameter (targs [0], "p0", Parameter.Modifier.NONE, null, loc);
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);
TypeContainer parent = CreateSiteContainer ();
Delegate d = new Delegate (parent.NamespaceEntry, parent, new TypeExpression (rt, loc),
Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
new MemberName ("Container" + container_counter++.ToString ("X")),
new ParametersCompiled (ctx, p), null);
d.CreateType ();
d.DefineType ();
d.Define ();
d.Emit ();
parent.AddDelegate (d);
del_type = new TypeExpression (d.Definition, loc);
}
TypeExpr site_type = new GenericTypeExpr (TypeManager.generic_call_site_type, new TypeArguments (del_type), loc);
return site_type;
}
开发者ID:speier,项目名称:shake,代码行数:63,代码来源:dynamic.cs
示例9: case_792
void case_792()
#line 5340 "cs-parser.jay"
{
Expression.Error_VoidInvalidInTheContext (GetLocation (yyVals[0+yyTop]), report);
yyVal = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[0+yyTop]));
}
开发者ID:segaman,项目名称:NRefactory,代码行数:6,代码来源:cs-parser.cs
示例10: case_376
void case_376()
#line 3076 "cs-parser.jay"
{
report.Error (1536, GetLocation (yyVals[0+yyTop]), "Invalid parameter type `void'");
yyVal = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[0+yyTop]));
}
开发者ID:segaman,项目名称:NRefactory,代码行数:6,代码来源:cs-parser.cs
示例11: case_240
void case_240()
#line 2104 "cs-parser.jay"
{
report.Error (590, GetLocation (yyVals[0+yyTop]), "User-defined operators cannot return void");
yyVal = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[0+yyTop]));
}
开发者ID:segaman,项目名称:NRefactory,代码行数:6,代码来源:cs-parser.cs
示例12: yyparse
//.........这里部分代码省略.........
case 357:
case_357();
break;
case 358:
case_358();
break;
case 359:
case_359();
break;
case 360:
case_360();
break;
case 361:
case_361();
break;
case 363:
case_363();
break;
case 364:
case_364();
break;
case 365:
case_365();
break;
case 366:
case_366();
break;
case 367:
case_367();
break;
case 369:
#line 3042 "cs-parser.jay"
{
yyVal = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[0+yyTop]));
}
break;
case 370:
#line 3049 "cs-parser.jay"
{
lexer.parsing_generic_declaration = true;
}
break;
case 372:
case_372();
break;
case 374:
case_374();
break;
case 376:
case_376();
break;
case 378:
#line 3087 "cs-parser.jay"
{
yyVal = new ComposedCast ((FullNamedExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
}
break;
case 379:
case_379();
break;
case 380:
#line 3106 "cs-parser.jay"
{
yyVal = new ComposedCast ((ATypeNameExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
}
break;
开发者ID:segaman,项目名称:NRefactory,代码行数:67,代码来源:cs-parser.cs
示例13: Define
public override bool Define()
{
if (!base.Define ())
return false;
if (declarators != null) {
var t = new TypeExpression (MemberType, TypeExpression.Location);
int index = Parent.PartialContainer.Events.IndexOf (this);
foreach (var d in declarators) {
var ef = new EventField (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null)
ef.initializer = d.Initializer;
Parent.PartialContainer.Events.Insert (++index, ef);
}
}
if (!HasBackingField) {
SetIsUsed ();
return true;
}
if (Add.IsInterfaceImplementation)
SetIsUsed ();
backing_field = new Field (Parent,
new TypeExpression (MemberType, Location),
Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
MemberName, null);
Parent.PartialContainer.AddField (backing_field);
backing_field.Initializer = Initializer;
backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED;
// Call define because we passed fields definition
backing_field.Define ();
// Set backing field for event fields
spec.BackingField = backing_field.Spec;
return true;
}
开发者ID:afaerber,项目名称:mono,代码行数:43,代码来源:property.cs
示例14: AddCapturedThisField
public void AddCapturedThisField (EmitContext ec)
{
TypeExpr type_expr = new TypeExpression (ec.CurrentType, Location);
Field f = AddCompilerGeneratedField ("<>f__this", type_expr);
f.Define ();
hoisted_this = new HoistedThis (this, f);
// Inflated type instance has to be updated manually
if (Instance.Type is InflatedTypeSpec) {
var inflator = new TypeParameterInflator (this, Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
Instance.Type.MemberCache.AddMember (f.Spec.InflateMember (inflator));
inflator = new TypeParameterInflator (this, f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
f.Parent.CurrentType.MemberCache.AddMember (f.Spec.InflateMember (inflator));
}
}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:16,代码来源:anonymous.cs
示例15: LookupType
public TypeExpr LookupType (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
{
if (types == null)
return null;
TypeExpr te;
if (arity == 0 && cached_types.TryGetValue (name, out te))
return te;
IList<TypeSpec> found;
if (!types.TryGetValue (name, out found))
return null;
TypeSpec best = null;
foreach (var ts in found) {
if (ts.Arity == arity) {
if (best == null) {
if ((ts.Modifiers & Modifiers.INTERNAL) != 0 && !ts.MemberDefinition.IsInternalAsPublic (ctx.Module.DeclaringAssembly) && mode != LookupMode.IgnoreAccessibility)
continue;
best = ts;
continue;
}
if (best.MemberDefinition.IsImported && ts.MemberDefinition.IsImported) {
if (mode == LookupMode.Normal) {
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
ctx.Module.Compiler.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", ts.GetSignatureForError ());
}
break;
}
if (best.MemberDefinition.IsImported)
best = ts;
if ((best.Modifiers & Modifiers.INTERNAL) != 0 && !best.MemberDefinition.IsInternalAsPublic (ctx.Module.DeclaringAssembly))
continue;
if (mode != LookupMode.Normal)
continue;
if (ts.MemberDefinition.IsImported) {
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
}
ctx.Module.Compiler.Report.Warning (436, 2, loc,
"The type `{0}' conflicts with the imported type of same name'. Ignoring the imported type definition",
best.GetSignatureForError ());
}
//
// Lookup for the best candidate with the closest arity match
//
if (arity < 0) {
if (best == null) {
best = ts;
} else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best.Arity + arity)) {
best = ts;
}
}
}
if (best == null)
return null;
te = new TypeExpression (best, Location.Null);
// TODO MemberCache: Cache more
if (arity == 0 && mode == LookupMode.Normal)
cached_types.Add (name, te);
return te;
}
开发者ID:geoparsYoti,项目名称:mono,代码行数:75,代码来源:namespace.cs
示例16: Resolve
public override bool Resolve(BlockContext ec)
{
TypeExpression storey_type_expr = new TypeExpression (host.Definition, loc);
List<Expression> init = null;
if (host.hoisted_this != null) {
init = new List<Expression> (host.hoisted_params == null ? 1 : host.HoistedParameters.Count + 1);
HoistedThis ht = host.hoisted_this;
FieldExpr from = new FieldExpr (ht.Field, loc);
from.InstanceExpression = CompilerGeneratedThis.Instance;
init.Add (new ElementInitializer (ht.Field.Name, from, loc));
}
if (host.hoisted_params != null) {
if (init == null)
init = new List<Expression> (host.HoistedParameters.Count);
for (int i = 0; i < host.hoisted_params.Count; ++i) {
HoistedParameter hp = (HoistedParameter) host.hoisted_params [i];
HoistedParameter hp_cp = (HoistedParameter) host.hoisted_params_copy [i];
FieldExpr from = new FieldExpr (hp_cp.Field, loc);
from.InstanceExpression = CompilerGeneratedThis.Instance;
init.Add (new ElementInitializer (hp.Field.Name, from, loc));
}
}
if (init != null) {
new_storey = new NewInitialize (storey_type_expr, null,
new CollectionOrObjectInitializers (init, loc), loc);
} else {
new_storey = new New (storey_type_expr, null, loc);
}
new_storey = new_storey.Resolve (ec);
if (new_storey != null)
new_storey = Convert.ImplicitConversionRequired (ec, new_storey, host_method.MemberType, loc);
if (TypeManager.int_interlocked_compare_exchange == null) {
TypeSpec t = TypeManager.CoreLookupType (ec.Compiler, "System.Threading", "Interlocked", MemberKind.Class, true);
if (t != null) {
var p = ParametersCompiled.CreateFullyResolved (
new[] {
new ParameterData (null, Parameter.Modifier.REF),
new ParameterData (null, Parameter.Modifier.NONE),
new ParameterData (null, Parameter.Modifier.NONE)
},
new[] {
TypeManager.int32_type, TypeManager.int32_type, TypeManager.int32_type
}
);
var f = new MemberFilter ("CompareExchange", 0, MemberKind.Method, p, TypeManager.int32_type);
TypeManager.int_interlocked_compare_exchange = TypeManager.GetPredefinedMethod (t, f, loc);
}
}
ec.CurrentBranching.CurrentUsageVector.Goto ();
return true;
}
开发者ID:speier,项目名称:shake,代码行数:59,代码来源:iterators.cs
示例17: Visit
public override object Visit(TypeExpression typeExpression)
{
return new TypeReferenceExpression(new PrimitiveType(keywordTable [(int)typeExpression.Type.BuiltinType], Convert(typeExpression.Location)));
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:4,代码来源:CSharpParser.cs
示例18: EmitCall
protected void EmitCall (EmitContext ec, Expression binder, Arguments arguments, bool isStatement)
{
//
// This method generates all internal infrastructure for a dynamic call. The
// reason why it's quite complicated is the mixture of dynamic and anonymous
// methods. Dynamic itself requires a temporary class (ContainerX) and anonymous
// methods can generate temporary storey as well (AnonStorey). Handling MVAR
// type parameters rewrite is non-trivial in such case as there are various
// combinations possible therefore the mutator is not straightforward. Secondly
// we need to keep both MVAR(possibly VAR for anon storey) and type VAR to emit
// correct Site field type and its access from EmitContext.
//
int dyn_args_count = arguments == null ? 0 : arguments.Count;
int default_args = isStatement ? 1 : 2;
var module = ec.Module;
bool has_ref_out_argument = false;
var targs = new TypeExpression[dyn_args_count + default_args];
targs[0] = new TypeExpression (module.PredefinedTypes.CallSite.TypeSpec, loc);
TypeExpression[] targs_for_instance = null;
TypeParameterMutator mutator;
var site_container = ec.CreateDynamicSite ();
if (context_mvars != null) {
TypeParameters tparam;
TypeContainer sc = site_container;
do {
tparam = sc.CurrentTypeParameters;
sc = sc.Parent;
} while (tparam == null);
mutator = new TypeParameterMutator (context_mvars, tparam);
if (!ec.IsAnonymousStoreyMutateRequired) {
targs_for_instance = new TypeExpression[targs.Length];
targs_for_instance[0] = targs[0];
}
} else {
mutator = null;
}
for (int i = 0; i < dyn_args_count; ++i) {
Argument a = arguments[i];
if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
has_ref_out_argument = true;
var t = a.Type;
// Convert any internal type like dynamic or null to object
if (t.Kind == MemberKind.InternalCompilerType)
t = ec.BuiltinTypes.Object;
if (targs_for_instance != null)
targs_for_instance[i + 1] = new TypeExpression (t, loc);
if (mutator != null)
t = t.Mutate (mutator);
targs[i + 1] = new TypeExpression (t, loc);
}
TypeExpr del_type = null;
TypeExpr del_type_instance_access = null;
if (!has_ref_out_argument) {
string d_name = isStatement ? "Action" : "Func";
TypeSpec te = null;
Namespace type_ns = module.GlobalRootNamespace.GetNamespace ("System", true);
if (type_ns != null) {
te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, LookupMode.Normal, loc);
}
if (te != null) {
if (!isStatement) {
var t = type;
if (t.Kind == MemberKind.InternalCompilerType)
t = ec.BuiltinTypes.Object;
if (targs_for_instance != null)
targs_for_instance[targs_for_instance.Length - 1] = new TypeExpression (t, loc);
if (mutator != null)
t = t.Mutate (mutator);
targs[targs.Length - 1] = new TypeExpression (t, loc);
}
del_type = new GenericTypeExpr (te, new TypeArguments (targs), loc);
if (targs_for_instance != null)
del_type_instance_access = new GenericTypeExpr (te, new TypeArguments (targs_for_instance), loc);
else
del_type_instance_access = del_type;
}
}
//
// Create custom delegate when no appropriate predefined delegate has been found
//.........这里部分代码省略.........
开发者ID:caomw,项目名称:mono,代码行数:101,代码来源:dynamic.cs
示例19: Define
public override bool Define()
{
var mod_flags_src = ModFlags;
if (!base.Define ())
return false;
if (declarators != null) {
if ((mod_flags_src & Modifiers.DEFAULT_ACCESS_MODIFER) != 0)
mod_flags_src &= ~(Modifiers.AccessibilityMask | Modifiers.DEFAULT_ACCESS_MODIFER);
var t = new TypeExpression (MemberType, TypeExpression.Location);
foreach (var d in declarators) {
var ef = new EventField (Parent, t, mod_flags_src, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null)
ef.initializer = d.Initializer;
ef.Define ();
Parent.PartialContainer.Members.Add (ef);
}
}
if (!HasBackingField) {
SetIsUsed ();
return true;
}
if (Add.IsInterfaceImplementation)
SetIsUsed ();
backing_field = new Field (Parent,
new TypeExpression (MemberType, Location),
Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
MemberName, null);
Parent.PartialContainer.Members.Add (backing_field);
backing_field.Initializer = Initializer;
backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED;
// Call define because we passed fields definition
backing_field.Define ();
// Set backing field for event fields
spec.BackingField = backing_field.Spec;
return true;
}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:48,代码来源:property.cs
示例20: DoDefineMembers
protected override bool DoDefineMembers ()
{
var builtin_types = Compiler.BuiltinTypes;
var ctor_parameters = ParametersCompiled.CreateFullyResolved (
new [] {
new Parameter (new TypeExpression (builtin_types.Object, Location), "object", Parameter.Modifier.NONE, null, Location),
new Parameter (new TypeExpression (builtin_types.IntPtr, Location), "method", Parameter.Modifier.NONE, null, Location)
},
new [] {
builtin_types.Object,
builtin_types.IntPtr
}
);
Constructor = new Constructor (this, Constructor.ConstructorName,
Modifiers.PUBLIC, null, ctor_parameters, Location);
Constructor.Define ();
//
// Here the various methods like Invoke, BeginInvoke etc are defined
//
// First, call the `out of band' special method for
// defining recursively any types we need:
//
var p = parameters;
if (!p.Resolve (this))
return false;
//
// Invoke method
//
// Check accessibility
foreach (var partype in p.Types) {
if (!IsAccessibleAs (partype)) {
Report.SymbolRelatedToPreviousError (partype);
Report.Error (59, Location,
"Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'",
partype.GetSignatureForError (), GetSignatureForError ());
}
}
var ret_type = ReturnType.ResolveAsType (this);
if (ret_type == null)
return false;
//
// We don't have to check any others because they are all
// guaranteed to be accessible - they are standard types.
//
if (!IsAccessibleAs (ret_type)) {
Report.SymbolRelatedToPreviousError (ret_type);
Report.Error (58, Location,
"Inconsistent accessibility: return type `" +
ret_type.GetSignatureForError () + "' is less " +
"accessible than delegate `" + GetSignatureForError () + "'");
return false;
}
CheckProtectedModifier ();
if (Compiler.Settings.StdLib && ret_type.IsSpecialRuntimeType) {
Method.Error1599 (Location, ret_type, Report);
return false;
}
VarianceDecl.CheckTypeVariance (ret_type, Variance.Covariant, this);
var resolved_rt = new TypeExpression (ret_type, Location);
InvokeBuilder = new Method (this, resolved_rt, MethodModifiers, new MemberName (InvokeMethodName), p, null);
InvokeBuilder.Define ();
//
// Don't emit async method for compiler generated delegates (e.g. dynamic site containers)
//
if (!IsCompilerGenerated) {
DefineAsyncMethods (resolved_rt);
}
return true;
}
开发者ID:psni,项目名称:mono,代码行数:83,代码来源:delegate.cs
注:本文中的Mono.CSharp.TypeExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论