Example #1
0
        private static string GetNameForField(X86.IL.FieldInfo inf)
        {
            // First we need to separate out the
            // actual name of field from the type of the field.
            int loc = inf.Id.IndexOf(' ');

            if (loc >= 0)
            {
                string fName = inf.Id.Substring(loc, inf.Id.Length - loc);
                return(inf.DeclaringType.AssemblyQualifiedName + fName);
            }

            return(inf.Id);
        }
Example #2
0
File: ILOp.cs Project: Orvid/Cosmos
    private static void DoGetFieldsInfo(Type aType, List<X86.IL.FieldInfo> aFields, bool includeStatic) {
      var xCurList = new Dictionary<string, X86.IL.FieldInfo>();
      var xBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
      if (includeStatic)
      {
        xBindingFlags |= BindingFlags.Static;
      }
      var xFields = (from item in aType.GetFields(xBindingFlags)
                     orderby item.Name, item.DeclaringType.ToString()
                     select item).ToArray();
      for (int i = 0; i < xFields.Length; i++) {
        var xField = xFields[i];
        // todo: should be possible to have GetFields only return fields from a given type, thus removing need of next statement
        if (xField.DeclaringType != aType) {
          continue;
        }

        string xId = xField.GetFullName();

        var xInfo = new X86.IL.FieldInfo(xId, SizeOfType(xField.FieldType), aType, xField.FieldType);
        xInfo.IsStatic = xField.IsStatic;
        xInfo.Field = xField;

        var xFieldOffsetAttrib = xField.GetCustomAttributes(typeof(FieldOffsetAttribute), true).FirstOrDefault() as FieldOffsetAttribute;
        if (xFieldOffsetAttrib != null) {
          xInfo.Offset = (uint)xFieldOffsetAttrib.Value;
        }

        aFields.Add(xInfo);
        xCurList.Add(xId, xInfo);
      }

      // now check plugs
      IDictionary<string, PlugFieldAttribute> xPlugFields;
      if (mPlugManager.PlugFields.TryGetValue(aType, out xPlugFields)) {
        foreach (var xPlugField in xPlugFields) {
          X86.IL.FieldInfo xPluggedField = null;
          if (xCurList.TryGetValue(xPlugField.Key, out xPluggedField)) {
            // plugfield modifies an already existing field

            // TODO: improve.
            if (xPlugField.Value.IsExternalValue) {
              xPluggedField.IsExternalValue = true;
              xPluggedField.FieldType = xPluggedField.FieldType.MakePointerType();
              xPluggedField.Size = 4;
            }
          } else {
            xPluggedField = new X86.IL.FieldInfo(xPlugField.Value.FieldId, SizeOfType(xPlugField.Value.FieldType), aType, xPlugField.Value.FieldType);
            aFields.Add(xPluggedField);
          }
        }
      }

      if (aType.BaseType != null) {
        DoGetFieldsInfo(aType.BaseType, aFields, includeStatic);
      }
    }
Example #3
0
        private static void DoGetFieldsInfo(Type aType, List <X86.IL.FieldInfo> aFields)
        {
            var xCurList = new Dictionary <string, X86.IL.FieldInfo>();
            var xFields  = (from item in aType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                            orderby item.Name, item.DeclaringType.ToString()
                            select item).ToArray();

            for (int i = 0; i < xFields.Length; i++)
            {
                var xField = xFields[i];
                // todo: should be possible to have GetFields only return fields from a given type, thus removing need of next statement
                if (xField.DeclaringType != aType)
                {
                    continue;
                }

                string xId;
                if (!xField.IsStatic)
                {
                    xId = xField.GetFullName();
                }
                else
                {
                    xId = DataMember.GetStaticFieldName(xField);
                }

                var xInfo = new X86.IL.FieldInfo(xId, SizeOfType(xField.FieldType), aType, xField.FieldType);
                xInfo.IsStatic = xField.IsStatic;

                var xFieldOffsetAttrib = xField.GetCustomAttributes(typeof(FieldOffsetAttribute), true).FirstOrDefault() as FieldOffsetAttribute;
                if (xFieldOffsetAttrib != null)
                {
                    xInfo.Offset = (uint)xFieldOffsetAttrib.Value;
                }

                aFields.Add(xInfo);
                xCurList.Add(xId, xInfo);
            }

            // now check plugs
            IDictionary <string, PlugFieldAttribute> xPlugFields;

            if (mPlugManager.PlugFields.TryGetValue(aType, out xPlugFields))
            {
                foreach (var xPlugField in xPlugFields)
                {
                    X86.IL.FieldInfo xPluggedField = null;
                    if (xCurList.TryGetValue(xPlugField.Key, out xPluggedField))
                    {
                        // plugfield modifies an already existing field

                        // TODO: improve.
                        if (xPlugField.Value.IsExternalValue)
                        {
                            xPluggedField.IsExternalValue = true;
                            xPluggedField.FieldType       = xPluggedField.FieldType.MakePointerType();
                            xPluggedField.Size            = 4;
                        }
                    }
                    else
                    {
                        xPluggedField = new X86.IL.FieldInfo(xPlugField.Value.FieldId, SizeOfType(xPlugField.Value.FieldType), aType, xPlugField.Value.FieldType);
                        aFields.Add(xPluggedField);
                    }
                }
            }

            if (aType.BaseType != null)
            {
                DoGetFieldsInfo(aType.BaseType, aFields);
            }
        }