Descriptor for a field defined in a class of an assembly/module
Наследование: Field
Пример #1
0
 /*-------------------- Constructors ---------------------------------*/
 internal FieldRVA(FieldDef field, DataConstant data)
 {
     this.field = field;
     this.data = data;
     tabIx = MDTable.FieldRVA;
 }
Пример #2
0
 internal override sealed void Resolve(PEReader buff)
 {
     field = (FieldDef)buff.GetElement(MDTable.Field,fieldIx);
     field.AddDataValue(buff.GetDataConstant(rva,field.GetFieldType()));
 }
Пример #3
0
 /*-------------------- Constructors ---------------------------------*/
 internal FieldLayout(FieldDef field, uint offset)
 {
     this.field = field;
     this.offset = offset;
     tabIx = MDTable.FieldLayout;
 }
Пример #4
0
 internal override sealed void Resolve(PEReader buff)
 {
     field = (FieldDef)buff.GetElement(MDTable.Field,fieldIx);
     field.SetOffset(offset);
 }
Пример #5
0
 internal static void Read(PEReader buff, TableRow[] fields)
 {
     for (int i=0; i < fields.Length; i++)
         fields[i] = new FieldDef(buff);
 }
Пример #6
0
 /// <summary>
 /// Add a field to this class
 /// </summary>
 /// <param name="f">Descriptor for the field to be added</param>
 public void AddField(FieldDef f)
 {
     FieldDef field = (FieldDef)FindField(f.Name());
     if (field != null)
         throw new DescriptorException("Field " + field.NameString());
     f.SetParent(this);
     fields.Add(f);
 }
Пример #7
0
 /// <summary>
 /// Add a field to this class
 /// </summary>
 /// <param name="name">field name</param>
 /// <param name="fType">field type</param>
 /// <returns>a descriptor for this new field</returns>
 public FieldDef AddField(string name, Type fType)
 {
     FieldDef field = (FieldDef)FindField(name);
     if (field != null)
         throw new DescriptorException("Field " + field.NameString());
     field = new FieldDef(name,fType,this);
     fields.Add(field);
     return field;
 }
Пример #8
0
 /// <summary>
 /// Add a "global" field to this module
 /// </summary>
 /// <param name="fld">The field to be added</param>
 public void AddField(FieldDef fld)
 {
     defaultClass.AddField(fld);
 }
        internal override void GenCode0(CodeGenContext context)
        {
            bool scope_created, super_created;

            CodeGenContext newContext = new CodeGenContext(context);

            // scope and super must be evaluated in surrounding scope and passed to Init method
            ISimple scope = PushScope(context, out scope_created);
            ISimple super = PushSuper(context, out super_created);

            string basename = ID.ToDotNetName(name.vid);

            // BBTAG: try and get the superclass
            
            PERWAPI.Class superClass = Runtime.ObjectRef;
            bool superClassFound = false;
            PERWAPI.Method superClassConstructor0 = null;
            PERWAPI.Method superClassConstructor1 = Runtime.Object.ctor;

            if (this is CLASS)
            {
                superClass = ((CLASS)this).GetSuperClassRef(newContext);
                if (superClass != null)
                {
                    superClassFound = true;
                    superClassConstructor0 = superClass.GetMethodDesc(".ctor", new Type[0]);

                    if (superClassConstructor0 is MethodDef)
                        superClassConstructor0 = ((MethodDef)superClassConstructor0).MakeRefOf();

                    superClassConstructor1 = superClass.GetMethodDesc(".ctor", new Type[] { Runtime.ClassRef });

                    if (superClassConstructor1 is MethodDef)
                        superClassConstructor1 = ((MethodDef)superClassConstructor1).MakeRefOf();
                }
                else
                    superClass = Runtime.ObjectRef;
            }

            //public class MyClass: Object {

            // check if this class has already been created in a referenced DLL
            // FIXME: this won't work for nested classes
            PERWAPI.Class classRef = ClassSkeleton.FindPERWAPIClass(null, name, context.peFiles);
            bool defineInteropClass = (classRef == null);
            // if it seems like an extension of a ruby builtin class, don't generate an interop class
            // FIXME: this won't work for nested classes
            if (Ruby.Runtime.BuiltinClasses.IsBuiltinClass(basename))
            {
                Compiler.InteropWarning(basename + " is a Ruby built-in class, interop class not generated");
                defineInteropClass = false;
            }

            //ClassDef interopClass = newContext.CreateNestedClass(CurrentInteropClass(), basename, Runtime.ObjectRef); // BBTAG
            ClassDef interopClass = null;
            if (defineInteropClass)
            {
                if (superClass is PERWAPI.ClassDef)
                    interopClass = newContext.CreateNestedClass(CurrentInteropClass(), basename, ((PERWAPI.ClassDef)superClass).MakeRefOf()); // BBTAG
                else
                    interopClass = newContext.CreateNestedClass(CurrentInteropClass(), basename, superClass); // BBTAG
                interopClasses.Push(interopClass);
                classRef = interopClass;
            }
            //context.classes[classname] = interopClass;

            // BBTAG: create skeleton for this class
            
            ClassSkeleton skeleton;

            if (context.currentSkeleton.nestedClasses.ContainsKey(basename))
                skeleton = context.currentSkeleton.nestedClasses[basename];
            else
                skeleton = new ClassSkeleton(basename, classRef);
            skeleton.lexicalParent = context.currentSkeleton;
            newContext.currentSkeleton = skeleton;
            skeleton.lexicalParent.nestedClasses[basename] = skeleton;

            if (!superClassFound && this is AST.CLASS && ((AST.CLASS)this).super_class != null && defineInteropClass)
            {
                // do not add to post pass list if supertype is a built-in Ruby class
                //List<string> qualifiedSuperClass = ClassSkeleton.ConstNodeToClassList(((AST.CLASS)this).super_class);
                //if (!(qualifiedSuperClass.Count == 1 && Ruby.Runtime.BuiltinClasses.IsBuiltinClass(qualifiedSuperClass[0])))
                newContext.postPassList.Add(new ClassSkeletonPostPass(skeleton, interopClass, ((AST.CLASS)this).super_class));
            }
          
            //    public static Class classname;
            int seqNo = 0;
            internal_name = basename;
            while (FileClass().GetField(internal_name) != null)
                internal_name = basename + (seqNo++);

            // Define singleton in file class so that it gets initialized by .cctor
            singletonField = FileClass().AddField(PERWAPI.FieldAttr.PublicStatic, internal_name, Runtime.ClassRef);
            newContext.CurrentRubyClass = singletonField;

            //    public MyClass() : base(singleton) { };
            CodeGenContext class_constructor = null; 
            if (defineInteropClass)
            {
                if (interopClass.GetMethod(".ctor", new Type[0]) == null)
                {
                    CodeGenContext class_constructor0 = newContext.CreateConstructor(interopClass);
                    class_constructor0.ldarg(0);
                    if (superClassConstructor0 != null)
                        class_constructor0.call(superClassConstructor0);
                    else
                    {
                        class_constructor0.ldsfld(singletonField);
                        class_constructor0.call(superClassConstructor1);
                    }
                    class_constructor0.ret();
                    class_constructor0.Close();
                }


                //    public MyClass(Class klass) : base(klass) { };
                MethodDef ctor = interopClass.GetMethod(".ctor", new Type[] { Runtime.ClassRef });
                //CodeGenContext class_constructor;
                if (ctor == null)
                {
                    class_constructor = newContext.CreateConstructor(interopClass, new Param(ParamAttr.Default, "klass", Runtime.ClassRef));
                    class_constructor.ldarg(0);
                    class_constructor.ldarg("klass");
                    class_constructor.call(superClassConstructor1);
                    class_constructor.ret();
                    class_constructor.Close();
                }
                else
                {
                    class_constructor = new CodeGenContext();
                    class_constructor.Method = ctor;
                }
            }

            //    internal static void Init_fullname(object scope, object super, object recv, Frame caller) {
            CodeGenContext Init = newContext.CreateMethod(FileClass(), MethAttr.PublicStatic, "Init_" + internal_name, PrimitiveType.Object,
                    new Param(ParamAttr.Default, "scope", PrimitiveType.Object),
                    new Param(ParamAttr.Default, "super", PrimitiveType.Object),
                    new Param(ParamAttr.Default, "recv", PrimitiveType.Object),
                    new Param(ParamAttr.Default, "caller", Runtime.FrameRef));

            skeleton.initMethod = Init.Method;

            Init.startMethod(this.location);

            AddScopeLocals(Init);

            // singleton = scope.define_???(...)
            DefineClass(Init, singletonField);

            // recv = singleton;
            Init.ldsfld(singletonField);
            Init.starg("recv");

            // Fixme: should be conditional
            // singleton.define_allocator(allocator);
            if (defineInteropClass)
            {
                FieldDef allocator = DefineAllocator(newContext, class_constructor.Method);
                if (allocator != null)
                {
                    Init.ldsfld(singletonField);
                    Init.ldsfld(allocator);
                    Init.call(Runtime.Class.define_alloc_func);
                }
            }

            AddScopeBody(Init);

            Init.ReleaseLocal(0, true);

            Init.Close();

            if (defineInteropClass)
                interopClasses.Pop();

            // --------------------- Return to old Context ----------------------------


            context.newLine(location);
            // Init(scope, super, recv, caller);
            scope.GenSimple(context);
            super.GenSimple(context);
            context.ldarg("recv");
            context.ldloc(0);
            context.call(Init.Method);

            context.ReleaseLocal(super, super_created);
            context.ReleaseLocal(scope, scope_created);
        }