Exemplo n.º 1
0
        public PEAPI.FieldDef Resolve(CodeGen code_gen)
        {
            if (is_resolved)
            {
                return(field_def);
            }

            type.Resolve(code_gen);
            field_def = code_gen.PEFile.AddField(attr, name, type.PeapiType);

            is_resolved = true;

            return(field_def);
        }
        public override void Emit(CodeGen code_gen, MethodDef meth,
                                  PEAPI.CILInstructions cil)
        {
            PEAPI.Type[]   param_array;
            PEAPI.CalliSig callisig;

            if (param != null)
            {
                param_array = new PEAPI.Type[param.Length];
                int count = 0;
                foreach (BaseTypeRef typeref in param)
                {
                    typeref.Resolve(code_gen);
                    param_array[count++] = typeref.PeapiType;
                }
            }
            else
            {
                param_array = new PEAPI.Type[0];
            }

            ret_type.Resolve(code_gen);
            callisig = new PEAPI.CalliSig(call_conv,
                                          ret_type.PeapiType, param_array);

            cil.calli(callisig);
        }
Exemplo n.º 3
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);
        }
        public void Resolve(CodeGen code_gen)
        {
            if (is_resolved)
            {
                return;
            }

            owner.Resolve(code_gen);

            if (owner.UseTypeSpec)
            {
                PEAPI.Type owner_ref = owner.PeapiType;
                code_gen.PEFile.AddFieldToTypeSpec(owner_ref, name,
                                                   type.PeapiType);
            }
            else
            {
                PEAPI.ClassRef owner_ref;
                owner_ref = (PEAPI.ClassRef)owner.PeapiType;
                type.Resolve(code_gen);
                peapi_field = owner_ref.AddField(name, type.PeapiType);
            }

            is_resolved = true;
        }
        public void Define(CodeGen code_gen)
        {
            if (is_defined)
            {
                return;
            }

            typeref.Resolve(code_gen);

            peapi_param = new PEAPI.Param(attr,
                                          name, typeref.PeapiType);
            if (defval != null)
            {
                peapi_param.AddDefaultValue(defval);
            }

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

            if (native_type != null)
            {
                peapi_param.AddMarshallInfo(native_type);
            }

            is_defined = true;
        }
Exemplo n.º 6
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);
        }
        public override void Resolve(CodeGen code_gen)
        {
            if (is_resolved)
            {
                return;
            }

            PEAPI.Type [] arg_array;
            PEAPI.Type [] opt_array;
            bool          is_vararg = false;

            if (param_list != null)
            {
                ArrayList opt_list = new ArrayList();
                ArrayList arg_list = new ArrayList();
                bool      in_opt   = false;
                int       max      = param_list.Count;

                for (int i = 0; i < max; i++)
                {
                    ParamDef param = (ParamDef)param_list [i];

                    if (param.IsSentinel())
                    {
                        is_vararg = true;
                        in_opt    = true;
                        param.Type.Resolve(code_gen);
                    }
                    else if (in_opt)
                    {
                        param.Type.Resolve(code_gen);
                        opt_list.Add(param.Type.PeapiType);
                    }
                    else
                    {
                        param.Type.Resolve(code_gen);
                        arg_list.Add(param.Type.PeapiType);
                    }
                }

                arg_array = (PEAPI.Type [])arg_list.ToArray(typeof(PEAPI.Type));
                opt_array = (PEAPI.Type [])opt_list.ToArray(typeof(PEAPI.Type));
            }
            else
            {
                arg_array = new PEAPI.Type [0];
                opt_array = new PEAPI.Type [0];
            }

            ret.Resolve(code_gen);

            type = new PEAPI.MethPtrType(callconv, ret.PeapiType, arg_array, is_vararg, opt_array);
            type = Modify(code_gen, type);

            is_resolved = true;
        }
        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);
        }
        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;
        }
Exemplo n.º 10
0
        PEAPI.Type GetType(CodeGen code_gen, PEAPI.CustomModifier modifier, BaseTypeRef klass)
        {
            klass.Resolve(code_gen);
            var bcr = klass as BaseClassRef;

            if (bcr != null)
            {
                return(new PEAPI.CustomModifiedType(peapi_type, modifier, bcr.PeapiClass));
            }

            var pt = klass as PrimitiveTypeRef;

            return(new PEAPI.CustomModifiedType(peapi_type, modifier, code_gen.PEFile.AddPrimitiveType((PEAPI.PrimitiveType)pt.PeapiType)));

            throw new NotSupportedException(klass.GetType().ToString());
        }
        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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
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);
     }
 }
Exemplo n.º 15
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);
                }
            }
        }
Exemplo n.º 16
0
 public override void Emit(CodeGen code_gen, MethodDef meth,
                           PEAPI.CILInstructions cil)
 {
     operand.Resolve(code_gen);
     cil.TypeInst(op, operand.PeapiType);
 }
Exemplo n.º 17
0
                PEAPI.Type GetType (CodeGen code_gen, PEAPI.CustomModifier modifier, BaseTypeRef klass)
                {
                        klass.Resolve (code_gen);
                        var bcr = klass as BaseClassRef;
                        if (bcr != null)
                                return new PEAPI.CustomModifiedType (peapi_type, modifier, bcr.PeapiClass);

                        var pt = klass as PrimitiveTypeRef;
                                return new PEAPI.CustomModifiedType (peapi_type, modifier, code_gen.PEFile.AddPrimitiveType ((PEAPI.PrimitiveType) pt.PeapiType));

                        throw new NotSupportedException (klass.GetType ().ToString ());
                }