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 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);
        }
Beispiel #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;
                }
Beispiel #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;
                }
Beispiel #5
0
        protected PEAPI.Type Modify(CodeGen code_gen, PEAPI.Type type)
        {
            PeapiTypeRef peapi_type = new PeapiTypeRef(type);
            int          count      = conversion_list.Count;

            for (int i = 0; i < count; i++)
            {
                switch ((ConversionMethod)conversion_list[i])
                {
                case ConversionMethod.MakeArray:
                    peapi_type.MakeArray();
                    break;

                case ConversionMethod.MakeBoundArray:
                    peapi_type.MakeBoundArray((ArrayList)conversion_list[++i]);
                    break;

                case ConversionMethod.MakeManagedPointer:
                    peapi_type.MakeManagedPointer();
                    break;

                case ConversionMethod.MakeUnmanagedPointer:
                    peapi_type.MakeUnmanagedPointer();
                    break;

                case ConversionMethod.MakeCustomModified:
                    peapi_type.MakeCustomModified(code_gen, (PEAPI.CustomModifier)conversion_list[++i],
                                                  (BaseClassRef)conversion_list[++i]);
                    break;
                }
            }

            return(peapi_type.PeapiType);
        }
Beispiel #6
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;
 }
Beispiel #7
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;
 }
        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 override void Resolve(CodeGen code_gen)
        {
            if (is_resolved)
            {
                return;
            }

            if ((call_conv & PEAPI.CallConv.Vararg) != 0)
            {
                ResolveVararg(code_gen);
                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);

            if (owner.UseTypeSpec)
            {
                PEAPI.Type owner_ref = owner.PeapiType;
                peapi_method = code_gen.PEFile.AddMethodToTypeSpec(owner_ref, write_name,
                                                                   ret_type.PeapiType, param_list, gen_param_count);
            }
            else
            {
                PEAPI.ClassRef owner_ref;
                owner_ref    = (PEAPI.ClassRef)owner.PeapiType;
                peapi_method = owner_ref.AddMethod(write_name,
                                                   ret_type.PeapiType, param_list, gen_param_count);
            }

            peapi_method.AddCallConv(call_conv);

            is_resolved = true;
        }
Beispiel #10
0
        public void Resolve(CodeGen code_gen)
        {
            if (is_resolved)
            {
                return;
            }

            type_ref.Resolve(code_gen);

            type = new PEAPI.GenericTypeInst(type_ref.PeapiType, gen_args.Resolve(code_gen));

            is_resolved = true;
        }
Beispiel #11
0
        public void MakeUnmanagedPointer()
        {
            PEAPI.Type type;
            use_type_spec = true;

            Pair p = new Pair(peapi_type, "*");

            type = type_table [p] as PEAPI.Type;
            if (type == null)
            {
                type           = new PEAPI.UnmanagedPointer(peapi_type);
                type_table [p] = type;
            }
            peapi_type = type;
        }
Beispiel #12
0
        public void MakeCustomModified(CodeGen code_gen, PEAPI.CustomModifier modifier,
                                       BaseTypeRef klass)
        {
            PEAPI.Type type;

            use_type_spec = true;

            Pair p = new Pair(peapi_type, modifier.ToString());

            type = type_table [p] as PEAPI.Type;
            if (type == null)
            {
                type           = GetType(code_gen, modifier, klass);
                type_table [p] = type;
            }
            peapi_type = type;
        }
Beispiel #13
0
        public void MakeArray()
        {
            PEAPI.Type type;

            use_type_spec = true;
            is_array      = true;

            Pair p = new Pair(peapi_type, "[]");

            type = type_table [p] as PEAPI.Type;
            if (type == null)
            {
                type           = new PEAPI.ZeroBasedArray(peapi_type);
                type_table [p] = type;
            }
            peapi_type = type;
        }
        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);
        }
Beispiel #15
0
                public override void Resolve (CodeGen code_gen)
                {
			if (is_resolved)
				return;

                        if ((call_conv & PEAPI.CallConv.Vararg) != 0) {
                                ResolveVararg (code_gen);
                                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);

                        if (owner.UseTypeSpec) {
                                PEAPI.Type owner_ref = owner.PeapiType;
                                peapi_method = code_gen.PEFile.AddMethodToTypeSpec (owner_ref, write_name,
                                                ret_type.PeapiType, param_list, gen_param_count);
                        } else {
                                PEAPI.ClassRef owner_ref;
                                owner_ref = (PEAPI.ClassRef) owner.PeapiType;
                                peapi_method = owner_ref.AddMethod (write_name,
                                                ret_type.PeapiType, param_list, gen_param_count);
                        }

                        peapi_method.AddCallConv (call_conv);

			is_resolved = true;
                }
Beispiel #16
0
                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);
                }
Beispiel #17
0
		public void Resolve (CodeGen code_gen)
		{
			if (is_resolved)
				return;

			type_ref.Resolve (code_gen);

			type = new PEAPI.GenericTypeInst (type_ref.PeapiType, gen_args.Resolve (code_gen));

			is_resolved = true;
		}
Beispiel #18
0
                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;
                }
Beispiel #19
0
 public Pair (PEAPI.Type type, string sig)
 {
         this.type = type;
         this.sig = sig;
 }
Beispiel #20
0
        public void MakeBoundArray(ArrayList bound_list)
        {
            use_type_spec = true;
            is_array      = true;

            int dimen = bound_list.Count;

            int[]  lower_array = new int[dimen];
            int[]  size_array = new int[dimen];
            int [] lobounds = null;
            int [] sizes = null;
            int    num_lower, num_sizes;
            string sigmod = "";

            PEAPI.Type type;
            Pair       p;

            sigmod += "[";
            for (int i = 0; i < bound_list.Count; i++)
            {
                DictionaryEntry e = (DictionaryEntry)bound_list [i];
                if (e.Key != TypeRef.Ellipsis)
                {
                    sigmod += e.Key;
                }
                sigmod += "...";
                if (e.Value != TypeRef.Ellipsis)
                {
                    sigmod += e.Value;
                }
                if (i + 1 < bound_list.Count)
                {
                    sigmod += ", ";
                }
            }
            sigmod += "]";

            p    = new Pair(peapi_type, sigmod);
            type = type_table [p] as PEAPI.Type;
            if (type != null)
            {
                peapi_type = type;
                return;
            }

            num_sizes = num_lower = 0;
            // TODO: There should probably be an error reported if
            // something like [3...,3...5] is done
            for (int i = 0; i < dimen; i++)
            {
                if (bound_list [i] == null)
                {
                    continue;
                }

                DictionaryEntry bound = (DictionaryEntry)bound_list [i];

                if (bound.Key != TypeRef.Ellipsis)
                {
                    /* Lower bound specified */
                    lower_array [i] = (int)bound.Key;
                    num_lower       = i + 1;
                }
                if (bound.Value != TypeRef.Ellipsis)
                {
                    size_array [i] = (int)bound.Value;
                    if (bound.Key != TypeRef.Ellipsis)
                    {
                        /* .Value is Upper bound eg [1...5] */
                        size_array [i] -= lower_array [i] - 1;
                    }
                    num_sizes = i + 1;
                }
            }

            if (num_lower > 0)
            {
                lobounds = new int [num_lower];
                Array.Copy(lower_array, lobounds, num_lower);
            }

            if (num_sizes > 0)
            {
                sizes = new int [num_sizes];
                Array.Copy(size_array, sizes, num_sizes);
            }

            peapi_type = new PEAPI.BoundArray(peapi_type,
                                              (uint)dimen, lobounds, sizes);
            type_table [p] = peapi_type;
        }
Beispiel #21
0
                public void MakeUnmanagedPointer ()
                {
                        PEAPI.Type type;
                        use_type_spec = true;

                        Pair p = new Pair (peapi_type, "*");
                        type = type_table [p] as PEAPI.Type;
                        if (type == null) {
                                type = new PEAPI.UnmanagedPointer (peapi_type);
                                type_table [p] = type;
                        }
                        peapi_type = type;
                }
		public PermissionMember (MemberTypes member_type, PEAPI.Type type, string name, object value)
		{
			this.member_type = member_type;
			this.type = type;
			this.name = name;
			this.value = value;
		}
Beispiel #23
0
                public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier,
                                BaseTypeRef klass)
                {
			PEAPI.Type type;

                        use_type_spec = true;
                        
                        Pair p = new Pair (peapi_type, modifier.ToString ());
                        type = type_table [p] as PEAPI.Type;
                        if (type == null) {
                                type = GetType (code_gen, modifier, klass);
                                type_table [p] = type;
                        }
                        peapi_type = type;
                }
Beispiel #24
0
                public void MakeBoundArray (ArrayList bound_list)
                {
                        use_type_spec = true;
                        is_array = true;

                        int dimen = bound_list.Count;
                        int[] lower_array = new int[dimen];
                        int[] size_array = new int[dimen];
                        int [] lobounds = null;
                        int [] sizes = null;
                        int num_lower, num_sizes;
                        string sigmod = "";
                        PEAPI.Type type;
                        Pair p;

                        sigmod += "[";
                        for (int i=0; i<bound_list.Count; i++) {
                                DictionaryEntry e = (DictionaryEntry) bound_list [i];
                                if (e.Key != TypeRef.Ellipsis)
                                        sigmod += e.Key;
                                sigmod += "...";
                                if (e.Value != TypeRef.Ellipsis)
                                        sigmod += e.Value;
                                if (i + 1 < bound_list.Count)
                                        sigmod += ", ";
                        }
                        sigmod += "]";

                        p = new Pair (peapi_type, sigmod);
                        type = type_table [p] as PEAPI.Type;
                        if (type != null) {
                                peapi_type = type;
                                return;
                        }

                        num_sizes = num_lower = 0;
                        // TODO: There should probably be an error reported if
                        // something like [3...,3...5] is done
                        for (int i=0; i<dimen; i++) {
                                if (bound_list [i] == null)
                                        continue;
                                        
                                DictionaryEntry bound = (DictionaryEntry) bound_list [i];
                                
                                if (bound.Key != TypeRef.Ellipsis) {
                                        /* Lower bound specified */
                                        lower_array [i] = (int) bound.Key;
                                        num_lower = i + 1;
                                }
                                if (bound.Value != TypeRef.Ellipsis) {
                                        size_array [i] = (int) bound.Value;
                                        if (bound.Key != TypeRef.Ellipsis)
                                                /* .Value is Upper bound eg [1...5] */
                                                size_array [i] -= lower_array [i] - 1;
                                        num_sizes = i + 1;
                                }
                        }

                        if (num_lower > 0) {
                                lobounds = new int [num_lower];
                                Array.Copy (lower_array, lobounds, num_lower);
                        }

                        if (num_sizes > 0) {
                                sizes = new int [num_sizes];
                                Array.Copy (size_array, sizes, num_sizes);
                        }

                        peapi_type = new PEAPI.BoundArray (peapi_type,
                                                (uint) dimen, lobounds, sizes);
                        type_table [p] = peapi_type;
                }
Beispiel #25
0
                public void MakeArray ()
                {
                        PEAPI.Type type;

                        use_type_spec = true;
                        is_array = true;

                        Pair p = new Pair (peapi_type, "[]");
                        type = type_table [p] as PEAPI.Type;
                        if (type == null) {
                                type = new PEAPI.ZeroBasedArray (peapi_type);
                                type_table [p] = type;
                        }
                        peapi_type = type;
                }
        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;
        }
Beispiel #27
0
 public Pair(PEAPI.Type type, string sig)
 {
     this.type = type;
     this.sig  = sig;
 }
		public Permission (PEAPI.Type type, string name)
		{
			this.type = type;
			this.name = name;
		}
Beispiel #29
0
 public Triplet(PEAPI.Type type, string sig, string typeMod)
     : base(type, sig)
 {
     this.typeMod = typeMod;
 }