Esempio n. 1
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);
                        }

                }
Esempio n. 2
0
                public PEAPI.Permission Resolve (CodeGen code_gen)
                {
                        string fname;

                        type_ref.Resolve (code_gen);

                        if (type_ref is ExternTypeRef) {
                                ExternAssembly ea = ((ExternTypeRef) type_ref).ExternRef as ExternAssembly;
                                if (ea == null)
                                        //FIXME: module.. ?
                                        throw new NotImplementedException ();

                                string name;
                                ExternTypeRef etr = type_ref as ExternTypeRef;
                                if (etr != null)
                                        name = etr.Name;
                                else
                                        name = type_ref.FullName;

                                fname = String.Format ("{0}, {1}", name, ea.AssemblyName.FullName);
                        } else {
                                fname = type_ref.FullName;
                        }

                        perm = new PEAPI.Permission (type_ref.PeapiType, fname);
                                        
                        foreach (PermissionMember member in members)
                                perm.AddMember (member.Resolve (code_gen));

                        return perm;
                }
Esempio n. 3
0
                public override void Resolve (CodeGen code_gen)
                {
                        if (is_resolved)
                                return;

                        PEAPI.Type[] param_list = new PEAPI.Type[param.Length];
                        string write_name;

                        ret_type.Resolve (code_gen);

                        int count = 0;
                        foreach (BaseTypeRef typeref in param) {
                                typeref.Resolve (code_gen);
                                param_list[count++] = typeref.PeapiType;
                        }

                        if (name == "<init>")
                                write_name = ".ctor";
                        else
                                write_name = name;

                        owner.Resolve (code_gen);
                        peapi_method = code_gen.PEFile.AddMethodToTypeSpec (owner.PeapiType, write_name,
                                        ret_type.PeapiType, param_list, gen_param_count);

                        peapi_method.AddCallConv (call_conv);

                        is_resolved = true;
                }
Esempio n. 4
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;
                }
Esempio n. 5
0
                public override void Resolve (CodeGen code_gen)
                {
			if (is_resolved)
				return;

                        if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
                                string sig = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, false);
                                peapi_method = code_gen.ResolveMethod (sig);
                        } else {
                                ArrayList opt_list = new ArrayList ();
                                bool in_opt = false;
                                foreach (BaseTypeRef type in param) {
                                        if (type is SentinelTypeRef) {
                                                in_opt = true;
                                        } else if (in_opt) {
                                                type.Resolve (code_gen);
                                                opt_list.Add (type.PeapiType);
                                        }
                                }

                                string sig_only_required_params = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, false);
                                string sig_with_optional_params = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, true);
                                peapi_method = code_gen.ResolveVarargMethod (sig_only_required_params, sig_with_optional_params, code_gen,
                                                (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
                        }

                        peapi_method.AddCallConv (call_conv);
			
			is_resolved = true;
                }
Esempio n. 6
0
                public override void Resolve (CodeGen code_gen)
                {
                        if (is_resolved)
                                return;

			owner.Resolve (code_gen);

                        TypeDef owner_def = code_gen.TypeManager[owner.FullName];
			if (owner_def == null)
				Report.Error ("Reference to undefined class '" + owner.FullName + "'");

                        if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
                                peapi_method = owner_def.ResolveMethod (ret_type, call_conv, name, 
                                        param, gen_param_count, code_gen);
                        } else {
                                ArrayList opt_list = new ArrayList ();
                                bool in_opt = false;
                                foreach (BaseTypeRef type in param) {
                                        if (type is SentinelTypeRef) {
                                                in_opt = true;
                                        } else if (in_opt) {
                                                type.Resolve (code_gen);
                                                opt_list.Add (type.PeapiType);
                                        }
                                }
                                peapi_method = owner_def.ResolveVarargMethod (
                                                ret_type, call_conv, name, param, gen_param_count,
                                                (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)),
                                                code_gen);
                        }

                        is_resolved = true;

                }
Esempio n. 7
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"));
                        }
                }
Esempio n. 8
0
                public PEAPI.HandlerBlock Resolve (CodeGen code_gen, MethodDef method)
                {
                        PEAPI.CILLabel from = handler_block.GetFromLabel (code_gen, method);
                        PEAPI.CILLabel to = handler_block.GetToLabel (code_gen, method);
                        PEAPI.Fault fault = new PEAPI.Fault (from, to);

                        return fault;
                }
Esempio n. 9
0
                public PEAPI.PermissionSet Resolve (CodeGen code_gen)
                {
                       ps = new PEAPI.PermissionSet (sec_action); 
                       foreach (Permission perm in permissions)
                               ps.AddPermission (perm.Resolve (code_gen));

                       return ps;
                }
Esempio n. 10
0
                public PEAPI.PermissionMember Resolve (CodeGen code_gen)
                {
                        type_ref.Resolve (code_gen);

                        member = new PEAPI.PermissionMember (member_type, type_ref.PeapiType, name, value);

                        return member;
                }
Esempio n. 11
0
                public PEAPI.HandlerBlock Resolve (CodeGen code_gen, MethodDef method)
                {
                        PEAPI.CILLabel from = handler_block.GetFromLabel (code_gen, method);
                        PEAPI.CILLabel to = handler_block.GetToLabel (code_gen, method);
                        PEAPI.Finally phinally = new PEAPI.Finally (from, to);

                        return phinally;
                }
Esempio n. 12
0
                public override void Emit (CodeGen code_gen, MethodDef meth,
					   PEAPI.CILInstructions cil)
                {
                        if (operand != null)
                                cil.ldstr (operand);
                        else
                                cil.ldstr (b_operand);
                }
Esempio n. 13
0
 public override void ResolveNoTypeSpec (CodeGen code_gen)
 {
         if (is_resolved)
                 return;
         
         type = Modify (code_gen, type);
         is_resolved = true;
 }
Esempio n. 14
0
                public void Resolve (CodeGen code_gen)
                {
			if (is_resolved)
				return;

                        peapi_field = code_gen.ResolveField (name, ret_type.FullName);

			is_resolved = true;
                }
Esempio n. 15
0
                public PEAPI.HandlerBlock Resolve (CodeGen code_gen, MethodDef method)
                {
                        PEAPI.CILLabel label = this_block.GetFromLabel (code_gen, method);
                        PEAPI.CILLabel from = handler_block.GetFromLabel (code_gen, method);
                        PEAPI.CILLabel to = handler_block.GetToLabel (code_gen, method);
                        PEAPI.Filter filter = new PEAPI.Filter (label, from, to);

                        return filter;
                }
Esempio n. 16
0
                public override void Resolve (CodeGen code_gen)
                {
                        ResolveNoTypeSpec (code_gen);
                        if (is_added)
                                return;

                        code_gen.PEFile.AddGenericClass ((PEAPI.GenericTypeInst) p_gen_inst);
                        is_added = true;
                }
Esempio n. 17
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);
		}
Esempio n. 18
0
                public void Resolve (CodeGen code_gen)
                {
			if (is_resolved)
				return;

                        TypeDef owner_def = code_gen.TypeManager[owner.FullName];
                        peapi_field = owner_def.ResolveField (name, ret_type, code_gen);

			is_resolved = true;
                }
Esempio n. 19
0
                public override void Resolve (CodeGen code_gen)
                {
                        if (is_resolved)
                                return;

                        // Perform all of the types modifications
                        type = Modify (code_gen, type);

                        is_resolved = true;
                }
Esempio n. 20
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);
                }
Esempio n. 21
0
                public override void Resolve (CodeGen code_gen)
                {
                        if (is_resolved)
                                return;

                        type = new PEAPI.Sentinel ();
                        type = Modify (code_gen, type);

                        is_resolved = true;
                }
Esempio n. 22
0
                public override void Resolve (CodeGen code_gen)
                {
                        if (is_resolved)
                                return;

                        meth.Resolve (code_gen);
                        peapi_method = code_gen.PEFile.AddMethodSpec (meth.PeapiMethod, sig.Resolve (code_gen));

                        is_resolved = true;
                }
Esempio n. 23
0
                public PEAPI.GenericMethodSig Resolve (CodeGen code_gen)
                {
                        if (is_resolved)
                                return sig;

                        sig = new PEAPI.GenericMethodSig (gen_args.Resolve (code_gen));
                        is_resolved = true;

                        return sig;
                }
Esempio n. 24
0
                protected void ResolveVararg (CodeGen code_gen)
                {
			if (is_resolved)
				return;

                        ArrayList param_list = new ArrayList ();
                        ArrayList opt_list = new ArrayList ();
                        bool in_opt = false;
                        string write_name;

                        ret_type.Resolve (code_gen);

                        foreach (BaseTypeRef typeref in param) {
                                if (in_opt) {
                                        typeref.Resolve (code_gen);
                                        opt_list.Add (typeref.PeapiType);
                                } else if (typeref is SentinelTypeRef) {
                                        in_opt = true;
                                } else {
                                        typeref.Resolve (code_gen);
                                        param_list.Add (typeref.PeapiType);
                                }
                        }

                        if (name == "<init>")
                                write_name = ".ctor";
                        else
                                write_name = name;

                        if (owner.IsArray)
                                Report.Error ("Vararg methods on arrays are not supported yet.");

                        owner.Resolve (code_gen);

                        if (owner.UseTypeSpec) {
                                PEAPI.Type owner_ref = owner.PeapiType;
                                peapi_method = code_gen.PEFile.AddVarArgMethodToTypeSpec (owner_ref,
                                                write_name, ret_type.PeapiType,
                                                (PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
                                                (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
                        } else {
                                PEAPI.ClassRef owner_ref;
                                owner_ref = (PEAPI.ClassRef) owner.PeapiType;
                                peapi_method = owner_ref.AddVarArgMethod (write_name,
                                                ret_type.PeapiType,
                                                (PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
                                                (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
                        }


                        peapi_method.AddCallConv (call_conv);
			
			is_resolved = true;
                }
Esempio n. 25
0
                public PEAPI.HandlerBlock Resolve (CodeGen code_gen, MethodDef method)
                {
                        PEAPI.CILLabel from = handler_block.GetFromLabel (code_gen, method);
                        PEAPI.CILLabel to = handler_block.GetToLabel (code_gen, method);
                        PEAPI.Catch katch;

                        type_ref.Resolve (code_gen);

                        katch = new PEAPI.Catch (type_ref.PeapiType, from, to);

                        return katch;
                }
Esempio n. 26
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);
                }
Esempio n. 27
0
                public override void ResolveNoTypeSpec (CodeGen code_gen)
                {
                        if (is_resolved)
                                return;

                        class_ref.Resolve (code_gen);
                        p_gen_inst = (PEAPI.GenericTypeInst) class_ref.ResolveInstance (code_gen, gen_args);

                        type = Modify (code_gen, p_gen_inst);

                        is_resolved = true;
                }
Esempio n. 28
0
                        public bool Run ()
                        {
                                if (il_file_list.Count == 0)
                                        Usage ();
                                if (output_file == null)
                                        output_file = CreateOutputFilename ();
                                try {
                                        codegen = new CodeGen (output_file, target == Target.Dll, debugging_info);
                                        foreach (string file_path in il_file_list) {
                                                Report.FilePath = file_path;
                                                ProcessFile (file_path);
                                        }
                                        if (scan_only)
                                                return true;

                                        if (Report.ErrorCount > 0)
                                                return false;

                                        if (target != Target.Dll && !codegen.HasEntryPoint)
                                                Report.Error ("No entry point found.");

					// if we have a key and aren't assembling a netmodule
					if ((keyname != null) && !codegen.IsThisAssembly (null)) {
						LoadKey ();
						// this overrides any attribute or .publickey directive in the source
						codegen.ThisAssembly.SetPublicKey (sn.PublicKey);
					}

                                        try {
                                                codegen.Write ();
                                        } catch {
                                                File.Delete (output_file);
                                                throw;
                                        }
                                } catch (ILAsmException e) {
                                        Error (e.ToString ());
                                        return false;
                                } catch (PEAPI.PEFileException pe) {
                                        Error ("Error : " + pe.Message);
                                        return false;
                                } 

                                try {
					if (sn != null) {
						Report.Message ("Signing assembly with the specified strongname keypair");
						return Sign (output_file);
					}
                                } catch {
                                        return false;
                                }

                                return true;
                        }
Esempio n. 29
0
                public void Resolve (CodeGen code_gen)
                {
			if (is_resolved)
				return;

                        owner.Resolve (code_gen);

                        type.Resolve (code_gen);
                        peapi_field = code_gen.PEFile.AddFieldToTypeSpec (owner.PeapiType, name, type.PeapiType);
		
			is_resolved = true;
                }
Esempio n. 30
0
File: Local.cs Progetto: nobled/mono
                public PEAPI.Local GetPeapiLocal (CodeGen code_gen)
                {
                        int ec = Report.ErrorCount;
                        BaseGenericTypeRef gtr = type as BaseGenericTypeRef;
                        if (gtr == null)
                                type.Resolve (code_gen);
                        else
                                gtr.ResolveNoTypeSpec (code_gen);

                        if (Report.ErrorCount > ec)
                                return null;

                        return new PEAPI.Local (name, type.PeapiType);
                }
Esempio n. 31
0
        public void Define(CodeGen code_gen)
        {
            if (is_defined)
            {
                return;
            }

            if (is_intransit)
            {
                // Circular definition
                Report.Error("Circular definition of class: " + FullName);
            }

            if (outer != null)
            {
                PEAPI.TypeAttr vis = attr & PEAPI.TypeAttr.VisibilityMask;

                if (vis == PEAPI.TypeAttr.Private || vis == PEAPI.TypeAttr.Public)
                {
                    /* Nested class, but attr not set accordingly. */
                    Report.Warning(location, String.Format("Nested class '{0}' has non-nested visibility, set to such.", NestedFullName));
                    attr  = attr ^ vis;
                    attr |= (vis == PEAPI.TypeAttr.Public ? PEAPI.TypeAttr.NestedPublic : PEAPI.TypeAttr.NestedPrivate);
                }
            }

            if (parent != null)
            {
                is_intransit = true;
                parent.Resolve(code_gen);

                is_intransit = false;
                if (parent.PeapiClass == null)
                {
                    Report.Error("this type can not be a base type: "
                                 + parent);
                }

                if (IsValueType(parent.PeapiClass.nameSpace, parent.PeapiClass.name))
                {
                    is_value_class = true;
                }
                else if (IsEnumType(parent.PeapiClass.nameSpace, parent.PeapiClass.name))
                {
                    is_enum_class  = true;
                    is_value_class = false;
                }

                if (!IsValueType(name_space, name) && !IsEnumType(name_space, name) &&
                    is_value_class && (attr & PEAPI.TypeAttr.Sealed) == 0)
                {
                    attr |= PEAPI.TypeAttr.Sealed;
                }

                if (outer != null)
                {
                    if (!outer.IsDefined)
                    {
                        outer.Define(code_gen);
                    }
                    classdef = outer.PeapiType.AddNestedClass(attr,
                                                              name_space, name, parent.PeapiClass);
                }
                else
                {
                    if (is_value_class || is_enum_class)
                    {
                        // Should probably confirm that the parent is System.ValueType
                        classdef = code_gen.PEFile.AddValueClass(attr,
                                                                 name_space, name, is_value_class ? PEAPI.ValueClass.ValueType : PEAPI.ValueClass.Enum);
                    }
                    else
                    {
                        classdef = code_gen.PEFile.AddClass(attr,
                                                            name_space, name, parent.PeapiClass);
                    }
                }
            }
            else
            {
                if (outer != null)
                {
                    if (!outer.IsDefined)
                    {
                        outer.Define(code_gen);
                    }
                    classdef = outer.PeapiType.AddNestedClass(attr,
                                                              name_space, name);
                }
                else
                {
                    if (is_value_class || is_enum_class)
                    {
                        classdef = code_gen.PEFile.AddValueClass(attr,
                                                                 name_space, name, is_value_class ? PEAPI.ValueClass.ValueType : PEAPI.ValueClass.Enum);
                    }
                    else
                    {
                        classdef = code_gen.PEFile.AddClass(attr,
                                                            name_space, name);
                    }
                }
                if (FullName == "System.Object" || NoAutoInherit)
                {
                    classdef.SpecialNoSuper();
                }
            }

            is_defined = true;

            if (size != -1 || pack != -1)
            {
                classdef.AddLayoutInfo((pack == -1) ? 1 : pack, (size == -1) ? 0 : size);
            }

            if (impl_list != null)
            {
                foreach (BaseClassRef impl in impl_list)
                {
                    impl.Resolve(code_gen);
                    classdef.AddImplementedInterface(impl.PeapiClass);
                }
            }

            if (gen_params != null)
            {
                gen_params.Resolve(code_gen, classdef);
            }

            is_intransit = false;

            code_gen.AddToDefineContentsList(this);
        }
Esempio n. 32
0
        private PEAPI.Method ResolveAsMethodRef(BaseTypeRef ret_type, PEAPI.CallConv call_conv,
                                                string name, BaseTypeRef [] param, int gen_param_count, CodeGen code_gen)
        {
            ExternTypeRef   type_ref  = code_gen.ThisModule.GetTypeRef(FullName, false);
            ExternMethodRef methodref = (ExternMethodRef)type_ref.GetMethodRef(ret_type, call_conv, name, param, gen_param_count);

            methodref.Resolve(code_gen);

            return(methodref.PeapiMethod);
        }
Esempio n. 33
0
 /* Only resolves, does not add it to the TypeSpec
  * table */
 public abstract void ResolveNoTypeSpec(CodeGen code_gen);
Esempio n. 34
0
        protected void WriteCode(CodeGen code_gen, PEAPI.MethodDef methoddef)
        {
            /// Add the custrom attributes to this method
            if (customattr_list != null)
            {
                foreach (CustomAttr customattr in customattr_list)
                {
                    customattr.AddTo(code_gen, methoddef);
                    if (customattr.IsSuppressUnmanaged(code_gen))
                    {
                        methoddef.AddMethAttribute(PEAPI.MethAttr.HasSecurity);
                    }
                }
            }

            /// Add declarative security to this method
            if (decl_sec != null)
            {
                decl_sec.AddTo(code_gen, methoddef);
                methoddef.AddMethAttribute(PEAPI.MethAttr.HasSecurity);
            }

            // Generic type parameters
            if (gen_params != null)
            {
                gen_params.Resolve(code_gen, methoddef);
            }

            if (type_def == null)
            {
                //Global method
                meth_attr &= ~PEAPI.MethAttr.Abstract;
                meth_attr |= PEAPI.MethAttr.Static;
            }
            else
            {
                if ((inst_list.Count > 0) && type_def.IsInterface && !IsStatic)
                {
                    Report.Error(start, "Method cannot have body if it is non-static declared in an interface");
                }

                if (IsAbstract)
                {
                    if (!type_def.IsAbstract)
                    {
                        Report.Error(start, String.Format("Abstract method '{0}' in non-abstract class '{1}'",
                                                          Name, type_def.FullName));
                    }
                    if (inst_list.Count > 0)
                    {
                        Report.Error(start, "Method cannot have body if it is abstract.");
                    }
                    return;
                }
            }

            if (entry_point)
            {
                methoddef.DeclareEntryPoint();
            }

            if (local_list.Count > 0)
            {
                int           ec          = Report.ErrorCount;
                PEAPI.Local[] local_array = new PEAPI.Local[local_list.Count];

                foreach (Local local in local_list)
                {
                    local_array[local.Slot] = local.GetPeapiLocal(code_gen);
                }

                if (Report.ErrorCount > ec)
                {
                    return;
                }

                if (zero_init)
                {
                    init_locals = true;
                }

                methoddef.AddLocals(local_array, init_locals);
            }

            /// Nothing seems to work if maxstack is not set,
            /// i need to find out if this NEEDs to be set
            /// and what its default value should be
            if (max_stack < 0)
            {
                max_stack = 8;
            }
            methoddef.SetMaxStack(max_stack);

            if (pinvoke_info)
            {
                methoddef.AddPInvokeInfo(pinvoke_mod.ModuleRef,
                                         (pinvoke_name != null ? pinvoke_name : name), pinvoke_attr);
            }

            if ((impl_attr & PEAPI.ImplAttr.Runtime) == PEAPI.ImplAttr.Runtime)
            {
                if (inst_list.Count > 0)
                {
                    Report.Error(start, String.Format("Method cannot have body if it is non-IL runtime-supplied, '{0}'",
                                                      FullName));
                }
            }
            else
            {
                if (((impl_attr & PEAPI.ImplAttr.Native) != 0) ||
                    ((impl_attr & PEAPI.ImplAttr.Unmanaged) != 0))
                {
                    Report.Error(start, String.Format("Cannot compile native/unmanaged method, '{0}'",
                                                      FullName));
                }
            }

            if (inst_list.Count > 0)
            {
                /* Has body */
                if ((impl_attr & PEAPI.ImplAttr.InternalCall) != 0)
                {
                    Report.Error(start, String.Format("Method cannot have body if it is an internal call, '{0}'",
                                                      FullName));
                }

                if (pinvoke_info)
                {
                    Report.Error(start, String.Format("Method cannot have body if it is pinvoke, '{0}'",
                                                      FullName));
                }
            }
            else
            {
                if (pinvoke_info ||
                    ((impl_attr & PEAPI.ImplAttr.Runtime) != 0) ||
                    ((impl_attr & PEAPI.ImplAttr.InternalCall) != 0))
                {
                    /* No body required */
                    return;
                }

                Report.Warning(start, "Method has no body, 'ret' emitted.");
                AddInstr(new SimpInstr(PEAPI.Op.ret, start));
            }

            PEAPI.CILInstructions cil = methoddef.CreateCodeBuffer();
            /// Create all the labels
            /// TODO: Most labels don't actually need to be created so we could
            /// probably only create the ones that need to be
            LabelInfo[] label_info = new LabelInfo[label_table.Count + label_list.Count];
            label_table.Values.CopyTo(label_info, 0);
            label_list.CopyTo(label_info, label_table.Count);
            int       previous_pos   = -1;
            LabelInfo previous_label = null;

            Array.Sort(label_info);

            foreach (LabelInfo label in label_info)
            {
                if (label.UseOffset)
                {
                    label.Define(new PEAPI.CILLabel(label.Offset, true));
                    continue;
                }
                if (label.Pos == previous_pos)
                {
                    label.Label = previous_label.Label;
                }
                else
                {
                    label.Define(cil.NewLabel());
                }

                previous_label = label;
                previous_pos   = label.Pos;
            }

            // Set all the label refs
            foreach (LabelInfo label in labelref_table.Values)
            {
                LabelInfo def = (LabelInfo)label_table[label.Name];
                if (def == null)
                {
                    Report.Error("Undefined Label:  " + label);
                    return;
                }
                label.Label = def.Label;
            }

            int label_pos      = 0;
            int next_label_pos = (label_info.Length > 0 ? label_info[0].Pos : -1);

            for (int i = 0; i < inst_list.Count; i++)
            {
                IInstr instr = (IInstr)inst_list[i];
                if (next_label_pos == i)
                {
                    cil.CodeLabel(label_info[label_pos].Label);
                    if (label_pos < label_info.Length)
                    {
                        while (next_label_pos == i && ++label_pos < label_info.Length)
                        {
                            if (label_info[label_pos].UseOffset)
                            {
                                cil.CodeLabel(label_info[label_pos].Label);
                            }
                            next_label_pos = label_info[label_pos].Pos;
                        }
                    }
                    if (label_pos >= label_info.Length)
                    {
                        next_label_pos = -1;
                    }
                }
                if (source != null)
                {
                    source.MarkLocation(instr.Location.line, cil.Offset);
                }
                instr.Emit(code_gen, this, cil);
            }

            if (source != null)
            {
                source.MarkLocation(source.EndLine, cil.Offset);
            }
        }
Esempio n. 35
0
 public PEAPI.MethodDef Resolve(CodeGen code_gen)
 {
     return(Resolve(code_gen, null));
 }
Esempio n. 36
0
 public void AddTo(CodeGen code_gen, PEAPI.MetaDataElement elem)
 {
     method_ref.Resolve(code_gen);
     code_gen.PEFile.AddCustomAttribute(method_ref.PeapiMethod, constant, elem);
 }
Esempio n. 37
0
 public override void Emit(CodeGen code_gen, MethodDef meth,
                           PEAPI.CILInstructions cil)
 {
     cil.Inst(op);
 }
Esempio n. 38
0
        public void DefineContents(CodeGen code_gen)
        {
            ArrayList fielddef_list = new ArrayList();

            foreach (FieldDef fielddef in field_list)
            {
                if (is_enum_class && fielddef.Name == "value__")
                {
                    fielddef.Attributes |= PEAPI.FieldAttr.SpecialName | PEAPI.FieldAttr.RTSpecialName;
                }

                fielddef.Define(code_gen, classdef);
                fielddef_list.Add(fielddef.PeapiFieldDef);
            }

            classdef.SetFieldOrder(fielddef_list);

            foreach (MethodDef methoddef in method_list)
            {
                methoddef.Define(code_gen);
            }

            if (event_list != null)
            {
                foreach (EventDef eventdef in event_list)
                {
                    eventdef.Define(code_gen, classdef);
                }
            }

            if (property_list != null)
            {
                foreach (PropertyDef propdef in property_list)
                {
                    propdef.Define(code_gen, classdef);
                }
            }

            if (customattr_list != null)
            {
                foreach (CustomAttr customattr in customattr_list)
                {
                    customattr.AddTo(code_gen, classdef);
                    if (customattr.IsSuppressUnmanaged(code_gen))
                    {
                        classdef.AddAttribute(PEAPI.TypeAttr.HasSecurity);
                    }
                }
            }

            /// Add declarative security to this class
            if (decl_sec != null)
            {
                decl_sec.AddTo(code_gen, classdef);
                classdef.AddAttribute(PEAPI.TypeAttr.HasSecurity);
            }

            if (override_list != null)
            {
                foreach (DictionaryEntry entry in override_list)
                {
                    MethodDef       body        = (MethodDef)entry.Key;
                    DictionaryEntry decl        = (DictionaryEntry)entry.Value;
                    BaseTypeRef     parent_type = (BaseTypeRef)decl.Key;
                    parent_type.Resolve(code_gen);
                    string        over_name = (string)decl.Value;
                    BaseMethodRef over_meth = parent_type.GetMethodRef(body.RetType,
                                                                       body.CallConv, over_name, body.ParamTypeList(), body.GenParamCount);
                    over_meth.Resolve(code_gen);
                    classdef.AddMethodOverride(over_meth.PeapiMethod,
                                               body.PeapiMethodDef);
                }
            }

            if (override_long_list != null)
            {
                foreach (DictionaryEntry entry in override_long_list)
                {
                    string        sig  = (string)entry.Key;
                    BaseMethodRef decl = (BaseMethodRef)entry.Value;
                    MethodDef     body = (MethodDef)method_table[sig];
                    decl.Resolve(code_gen);
                    classdef.AddMethodOverride(decl.PeapiMethod,
                                               body.PeapiMethodDef);
                }
            }
        }
Esempio n. 39
0
        public PEAPI.Method ResolveVarargMethod(BaseTypeRef ret_type, PEAPI.CallConv call_conv,
                                                string name, BaseTypeRef [] param, int gen_param_count, PEAPI.Type [] opt, CodeGen code_gen)
        {
            // Only MethodDef sig required to lookup in the method_table
            string    signature = MethodDef.CreateSignature(ret_type, call_conv, name, param, 0, false);
            MethodDef methoddef = (MethodDef)method_table[signature];

            if (methoddef != null)
            {
                methoddef.Resolve(code_gen, classdef);
                return(methoddef.GetVarargSig(
                           opt,
                           MethodDef.CreateSignature(ret_type, call_conv, name, param, 0, true)));
            }

            return(ResolveAsMethodRef(ret_type, call_conv, name, param, gen_param_count, code_gen));
        }
Esempio n. 40
0
 public override PEAPI.Type ResolveInstance(CodeGen code_gen, GenericArguments gen_args)
 {
     Report.Error("Invalid attempt to create '" + FullName + "''" + gen_args.ToString() + "'");
     return(null);
 }
 public abstract void Resolve(CodeGen code_gen);
Esempio n. 42
0
        public PEAPI.Method ResolveMethod(BaseTypeRef ret_type, PEAPI.CallConv call_conv,
                                          string name, BaseTypeRef [] param, int gen_param_count, CodeGen code_gen)
        {
            string    signature = MethodDef.CreateSignature(ret_type, call_conv, name, param, gen_param_count, false);
            MethodDef methoddef = (MethodDef)method_table[signature];

            if (methoddef != null)
            {
                return(methoddef.Resolve(code_gen, classdef));
            }
            return(ResolveAsMethodRef(ret_type, call_conv, name, param, gen_param_count, code_gen));
        }