Exemplo n.º 1
0
        private void InitializeFieldDescs()
        {
            var numStaticFields       = 0;
            var numThreadStaticFields = 0;
            var currentDeclaredField  = 0;

            var fieldDescs = new List <FieldDesc>();

            for (var i = 0; i < _typeDefinition.Fields.Count; i++)
            {
                var fieldDef = _typeDefinition.Fields[i];

                // We don't store static final primitive fields in the class layout
                if (fieldDef.IsLiteral)
                {
                    continue;
                }

                if (!fieldDef.IsPublic)
                {
                    HalfBakedClass.HasNonPublicFields = true;
                }

                if (fieldDef.IsStatic)
                {
                    if (false)
                    {
                        // TODO: ThreadStatic attr
                        // TODO: not implemented yet
                    }
                    else
                    {
                        fieldDescs.Add(new FieldDesc(fieldDef)
                        {
                            Offset = -1                                      /* FIELD_OFFSET_UNPLACED */
                        });
                        numStaticFields++;
                    }
                }
                else
                {
                    fieldDescs.Add(new FieldDesc(fieldDef)
                    {
                        Offset = -1                                      /* FIELD_OFFSET_UNPLACED */
                    });
                    currentDeclaredField++;
                }
            }

            HalfBakedClass.FieldDescList         = fieldDescs.ToArray();
            HalfBakedClass.NumInstanceFields     = HasParent ? ParentMethodTable.EEClass.NumInstanceFields + currentDeclaredField : 0;
            HalfBakedClass.NumStaticFields       = numStaticFields;
            HalfBakedClass.NumThreadStaticFields = numThreadStaticFields;

            // Cache Field descriptors
            _classLoader.RegisterFieldDescRange(HalfBakedClass.FieldDescList);
        }