Пример #1
0
                public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
                {
                        if (!is_resolved)
                                Resolve (code_gen, classdef);

                        if (addon != null) {
                                addon.Resolve (code_gen);
                                event_def.AddAddon (AsMethodDef (addon.PeapiMethod, "addon"));
                        }

                        if (fire != null) {
                                fire.Resolve (code_gen);
                                event_def.AddFire (AsMethodDef (fire.PeapiMethod, "fire"));
                        }

                        if (other_list != null) {
				foreach (MethodRef otherm in other_list) {
	                                otherm.Resolve (code_gen);
        	                        event_def.AddOther (AsMethodDef (otherm.PeapiMethod, "other"));
				}
                        }

                        if (removeon != null) {
                                removeon.Resolve (code_gen);
                                event_def.AddRemoveOn (AsMethodDef (removeon.PeapiMethod, "removeon"));
                        }
                }
Пример #2
0
 public PrimitiveTypeRef (PEAPI.PrimitiveType type, string full_name, ArrayList conv_list, string sig_mod)
         : base (full_name, conv_list, sig_mod)
 {
         this.type = type;
         if (SigMod == null)
                 SigMod = String.Empty;
 }
Пример #3
0
                public PEAPI.Property Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
                {
                        if (is_resolved)
                                return prop_def;

                        PEAPI.Type[] type_list = new PEAPI.Type[arg_list.Count];

                        for (int i=0; i<type_list.Length; i++) {
                                BaseTypeRef arg_type = (BaseTypeRef) arg_list[i];
                                arg_type.Resolve (code_gen);
                                type_list[i] = arg_type.PeapiType;
                        }

                        type.Resolve (code_gen);
                        prop_def = classdef.AddProperty (name, type.PeapiType, type_list);

                        if ((attr & FeatureAttr.Rtspecialname) != 0)
                                prop_def.SetRTSpecialName ();

                        if ((attr & FeatureAttr.Specialname) != 0)
                                prop_def.SetSpecialName ();

                        prop_def.SetInstance ((attr & FeatureAttr.Instance) != 0);

                        if (customattr_list != null)
                                foreach (CustomAttr customattr in customattr_list)
                                        customattr.AddTo (code_gen, prop_def);


                        is_resolved = true;

                        return prop_def;
                }
Пример #4
0
 private PEAPI.MethodDef AsMethodDef (PEAPI.Method method, string type)
 {
         PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
         if (methoddef == null)
                 Report.Error (type + " method of property " + name + " not found");
         return methoddef;
 }
Пример #5
0
                public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
                {
                        System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding ();
                        foreach (DictionaryEntry entry in permissionset_table) {
                                PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key;
                                SSPermissionSet ps = (SSPermissionSet) entry.Value;

                                code_gen.PEFile.AddDeclSecurity (sec_action,
                                        ue.GetBytes (ps.ToXml ().ToString ()), 
                                         elem);
                        }

                        if (permissionset20_table == null)
                                return;

                        foreach (DictionaryEntry entry in permissionset20_table) {
                                PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key;
                                MIPermissionSet ps = (MIPermissionSet) entry.Value;

                                code_gen.PEFile.AddDeclSecurity (sec_action,
                                        ps.Resolve (code_gen), 
                                        elem);
                        }

                }
Пример #6
0
 public GenericParamRef (PEAPI.GenParam gen_param, string full_name, ArrayList conv_list)
         : base (full_name, false, conv_list, "")
 {
         this.type = gen_param;
         this.param = gen_param;
         is_added = false;
 }
Пример #7
0
 public ParamDef (PEAPI.ParamAttr attr, string name,
                 BaseTypeRef typeref) {
         this.attr = attr;
         this.name = name;
         this.typeref = typeref;
         is_defined = false;
         defval = null;
 }
Пример #8
0
 public PeapiTypeRef (PEAPI.Type peapi_type)
 {
         this.peapi_type = peapi_type;
         is_pinned = false;
         is_array = false;
         is_ref = false;
         use_type_spec = false;
 }
Пример #9
0
                public CalliInstr (PEAPI.CallConv call_conv, BaseTypeRef ret_type,
				   BaseTypeRef[] param, Location loc)
			: base (loc)
                {
                        this.call_conv = call_conv;
                        this.ret_type = ret_type;
                        this.param = param;
                }
Пример #10
0
                public override void Emit (CodeGen code_gen, MethodDef meth,
					   PEAPI.CILInstructions cil)
                {
                        if (operand != null)
                                cil.ldstr (operand);
                        else
                                cil.ldstr (b_operand);
                }
Пример #11
0
 protected override BaseMethodRef CreateMethodRef (BaseTypeRef ret_type,
         PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
 {
         if (SigMod == null | SigMod == "")
                 return new MethodRef (this, call_conv, ret_type, name, param, gen_param_count);
         else
                 return new TypeSpecMethodRef (this, call_conv, ret_type, name, param, gen_param_count);
 }
Пример #12
0
		private void Resolve (CodeGen code_gen, PEAPI.GenericParameter gp)
		{
			ResolveConstraints (code_gen, gp);
			if (customattrList == null)
				return;

			foreach (CustomAttr customattr in customattrList)
				customattr.AddTo (code_gen, gp);
		}
Пример #13
0
                public MethodInstr (PEAPI.MethodOp op, BaseMethodRef operand, Location loc)
			: base (loc)
                {
                        this.op = op;
                        this.operand = operand;

                        if (op == PEAPI.MethodOp.newobj || op == PEAPI.MethodOp.callvirt)
                                operand.CallConv |= PEAPI.CallConv.Instance;
                }
Пример #14
0
                public void Resolve (CodeGen code_gen, PEAPI.Module module)
                {
                        this.module = module;

                        if (customattr_list == null)
                                return;

                        foreach (CustomAttr customattr in customattr_list)
                                customattr.AddTo (code_gen, module);
                }
Пример #15
0
                public void AddPermission (PEAPI.SecurityAction sec_action, IPermission perm)
                {
                        SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action];
                        if (ps == null) {
                                ps = new SSPermissionSet (PermissionState.None);        
                                permissionset_table [sec_action] = ps;
                        }

                        ps.AddPermission (perm);
                }
Пример #16
0
                public MethodPointerTypeRef (PEAPI.CallConv callconv, BaseTypeRef ret, ArrayList param_list, ArrayList conv_list, string sig_mod)
                        : base (String.Empty, conv_list, sig_mod)
                {
                        this.callconv = callconv;
                        this.ret = ret;
                        this.param_list = param_list;

                        // We just need these to not break the interface
                        full_name = BuildTypeName ();
                        //sig_mod = String.Empty;
                }
Пример #17
0
                public void AddPermissionSet (PEAPI.SecurityAction sec_action, SSPermissionSet perm_set)
                {
                        SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action];
                        if (ps == null) {
                                permissionset_table [sec_action] = perm_set;
                                return;
                        }

                        foreach (IPermission iper in perm_set)
                                ps.AddPermission (iper);
                }
Пример #18
0
                public override void Emit (CodeGen code_gen, MethodDef meth,
					   PEAPI.CILInstructions cil)
                {
                        PEAPI.CILLabel from = block.GetFromLabel (code_gen, meth);
                        PEAPI.CILLabel to = block.GetToLabel (code_gen, meth);
                        PEAPI.TryBlock try_block = new PEAPI.TryBlock (from, to);

                        foreach (ISehClause clause in clause_list)
                                try_block.AddHandler (clause.Resolve (code_gen, meth));
			
                        cil.AddTryBlock (try_block);
                }
Пример #19
0
		public GenericParameter (string id, PEAPI.GenericParamAttributes attr, ArrayList constraints)
		{
			this.id = id;
			this.attr = attr;
			num = -1;
			constraintsList = null;
			customattrList = null;
				
			if (constraints != null)
				foreach (BaseTypeRef typeref in constraints)
					AddConstraint (typeref);
		}
Пример #20
0
 public BaseMethodRef (BaseTypeRef owner, PEAPI.CallConv call_conv,
         BaseTypeRef ret_type, string name, BaseTypeRef[] param, int gen_param_count)
 {
         this.owner = owner;
         this.call_conv = call_conv;
         this.ret_type = ret_type;
         this.name = name;
         this.param = param;
         this.gen_param_count = gen_param_count;
         if (gen_param_count > 0)
                 CallConv |= PEAPI.CallConv.Generic;
         is_resolved = false;
 }
Пример #21
0
                public override BaseMethodRef GetMethodRef (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
                                string name, BaseTypeRef[] param, int gen_param_count)
                {
                        /* Use FullName also here, as we are caching in a static hashtable */
                        string key = FullName + MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, true);
                        TypeSpecMethodRef mr = s_method_table [key] as TypeSpecMethodRef;
                        if (mr != null)
                                return mr;

			//FIXME: generic methodref for primitive type?
                        mr = new TypeSpecMethodRef (this, call_conv, ret_type, name, param, gen_param_count);
                        s_method_table [key] = mr;
                        return mr;
                }
Пример #22
0
                public override void Emit (CodeGen code_gen, MethodDef meth,
					   PEAPI.CILInstructions cil)
                {
                        switch (op) {
                        case MiscInstr.ldc_r8:
                                cil.ldc_r8 (d_operand);
                                break;
                        case MiscInstr.ldc_r4:
                                cil.ldc_r4 ((float) d_operand);
                                break;
                        case MiscInstr.ldc_i8:
                                cil.ldc_i8 (l_operand);
                                break;
                        }
                }
Пример #23
0
                public FieldDef (PEAPI.FieldAttr attr, string name,
                                BaseTypeRef type)
                {
                        this.attr = attr;
                        this.name = name;
                        this.type = type;

                        offset_set = false;
//                        datavalue_set = false;
                        value_set = false;

                        at_data_id = null;

                        is_resolved = false;
                }
Пример #24
0
                public void AddPermissionSet (PEAPI.SecurityAction sec_action, MIPermissionSet perm_set)
                {
                        PermissionSet ps = null;

                        if (permissionset20_table == null)
                                permissionset20_table = new Hashtable ();
                        else
                                ps = (MIPermissionSet) permissionset20_table [sec_action];

                        if (ps == null) {
                                permissionset20_table [sec_action] = perm_set;
                                return;
                        }

                        foreach (Permission perm in perm_set.Permissions)
                                ps.AddPermission (perm);
                }
Пример #25
0
                public override void Emit (CodeGen code_gen, MethodDef meth,
					   PEAPI.CILInstructions cil)
                {
                        if (field_ref != null) {
                                field_ref.Resolve (code_gen);
                                cil.FieldInst (PEAPI.FieldOp.ldtoken,
                                                field_ref.PeapiField);
                        } else if (method_ref != null) {
                                method_ref.Resolve (code_gen);
                                cil.MethInst (PEAPI.MethodOp.ldtoken,
                                                method_ref.PeapiMethod);
                        } else if (type_ref != null) {
                                type_ref.Resolve (code_gen);
                                cil.TypeInst (PEAPI.TypeOp.ldtoken,
                                                type_ref.PeapiType);
                        }
                }
Пример #26
0
                public TypeDef (PEAPI.TypeAttr attr, string name_space, string name,
                                BaseClassRef parent, ArrayList impl_list, Location location, GenericParameters gen_params, TypeDef outer)
                {
                        this.attr = attr;
                        this.parent = parent;
                        this.impl_list = impl_list;
                        this.gen_params = gen_params;
                        this.outer = outer;
                        this.location = location;

                        field_table = new Hashtable ();
                        field_list = new ArrayList ();

                        method_table = new Hashtable ();
                        method_list = new ArrayList ();

                        size = -1;
                        pack = -1;

                        is_defined = false;
                        is_intransit = false;

                        is_value_class = false;
                        is_enum_class = false;

                        ResolveGenParams ();

                        int lastdot = name.LastIndexOf ('.');
                        /* Namespace . name split should not be done for nested classes */
                        if (lastdot >= 0 && outer == null) {
                                if (name_space == null || name_space == "")
                                        this.name_space = name.Substring (0, lastdot);
                                else
                                        this.name_space = name_space + "." + name.Substring (0, lastdot);
                                this.name = name.Substring (lastdot + 1);
                        } else {
                                this.name_space = name_space;
                                this.name = name;
                        }

                        //Fixup attributes
                        if (IsInterface)
                                this.attr |= PEAPI.TypeAttr.Abstract;
                }
Пример #27
0
                public virtual BaseMethodRef GetMethodRef (BaseTypeRef ret_type,
                        PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
                {
                        BaseMethodRef mr = null;

                        /* Note: FullName not reqd as this is cached per object */
                        string key = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, true);
                        if (method_table == null)
                                method_table = new Hashtable ();
                        else
                                mr = (BaseMethodRef) method_table [key];

                        if (mr == null) {
                                mr = CreateMethodRef (ret_type, call_conv, name, param, gen_param_count);
                                method_table [key] = mr;
                        }

                        return mr;
                }
Пример #28
0
                public MethodDef (CodeGen codegen, PEAPI.MethAttr meth_attr,
				  PEAPI.CallConv call_conv, PEAPI.ImplAttr impl_attr,
				  string name, BaseTypeRef ret_type, ArrayList param_list,
				  Location start, GenericParameters gen_params, TypeDef type_def)
                {
                        this.codegen = codegen;
                        this.meth_attr = meth_attr;
                        this.call_conv = call_conv;
                        this.impl_attr = impl_attr;
                        this.name = name;
                        this.param_list = param_list;
                        this.type_def = type_def;
                        this.gen_params = gen_params;
                        this.ret_param = new ParamDef (PEAPI.ParamAttr.Default, "", ret_type);
                        this.start = (Location) start.Clone ();

                        inst_list = new ArrayList ();
                        label_table = new Hashtable ();
                        labelref_table = new Hashtable ();
                        label_list = new ArrayList ();
                        local_list = new ArrayList ();
                        named_local_tables = new ArrayList ();
                        named_local_tables.Add (new Hashtable ());
                        current_scope_depth = 0;

                        entry_point = false;
                        zero_init = false;
                        init_locals = false;
                        max_stack = -1;
                        pinvoke_info = false;

                        is_defined = false;
                        is_resolved = false;
                        ResolveGenParams ();
                        CreateSignature ();

			codegen.BeginMethodDef (this);

			if (codegen.SymbolWriter != null)
				source = codegen.SymbolWriter.BeginMethod (this, start);
                }
Пример #29
0
                public override void Emit (CodeGen code_gen, MethodDef meth,
					   PEAPI.CILInstructions cil)
                {
                        int count = 0;
                        PEAPI.CILLabel[] label_array;

                        if (label_list != null) {
                                label_array = new PEAPI.CILLabel[label_list.Count];
                                foreach (object lab in label_list) {
                                        if (lab is LabelInfo) {
                                                label_array[count++] = ((LabelInfo)lab).Label;
                                        } else {                                                
                                                throw new InternalErrorException ("offsets in switch statements.");
                                        }
                                }
                        } else {
                                label_array = new PEAPI.CILLabel [0];
                        }

                        cil.Switch (label_array);
                }
Пример #30
0
                public PEAPI.Event Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
                {
                        if (is_resolved)
                                return event_def;

                        type.Resolve (code_gen);
                        event_def = classdef.AddEvent (name, type.PeapiType);

                        if ((attr & FeatureAttr.Rtspecialname) != 0)
                                event_def.SetRTSpecialName ();

                        if ((attr & FeatureAttr.Specialname) != 0)
                                event_def.SetSpecialName ();
                        
                        if (customattr_list != null)
                                foreach (CustomAttr customattr in customattr_list)
                                        customattr.AddTo (code_gen, event_def);

                        is_resolved = true;

                        return event_def;
                }