Ejemplo n.º 1
0
        InterField IResolver.Resolve(FieldReference fldRef, List <InterGenericArgument> genericArgs)
        {
            InterType  declType = ((IResolver)this).Resolve(fldRef.DeclaringType, genericArgs);
            InterField result   = declType.Fields.Where(F => F.Name == fldRef.Name).FirstOrDefault();

            if (result == null)
            {
                InterField mapped = null;

                result = new InterField(fldRef, genericArgs, this, F => mapped = F);
                if (mapped != null)
                {
                    return(mapped);
                }

                Messages.Verbose("Adding field {0} to compile...", result.ToString());
                declType.Fields.Add(result);
            }

            return(result);
        }
Ejemplo n.º 2
0
 public override string ToString()
 {
     return((Type == FieldAccessorType.Setter ? "set " : "get ") + Field.ToString());
 }
Ejemplo n.º 3
0
        private Java.Field CompileField(InterField field)
        {
            Messages.Verbose("    Compiling field {0}...", field.ToString());
            Java.Field result = new Java.Field();

            if (field.IsPublic)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Public;
            }
            else if (field.IsProtected)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Protected;
            }
            else
            {
                result.AccessFlags |= Java.FieldAccessFlags.Private;
            }

            if (field.IsStatic)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Static;
            }

            //if it will be readonly, we will get error in CopyTo method of ValueType
            if (((field.IsReadonly) || (field.IsLiteral)) && (!field.DeclaringType.IsValueType))
            {
                result.AccessFlags |= Java.FieldAccessFlags.Final;
            }
            if (field.IsVolatile)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Volatile;
            }

            result.Name       = FieldNameToJava(field.Name);
            result.Descriptor = GetFieldDescriptor(field.FieldType);

            if ((field.IsStatic) && (field.IsThreadLocal))
            {
                result.Descriptor = "L" + TypeNameToJava(ClassNames.JavaLangThreadLocal.ClassName) + ";";
            }

            if (field.Constatnt != null)
            {
                Java.Constant constVal = null;

                if (field.Constatnt is byte)
                {
                    constVal = new Java.Constants.Integer((byte)field.Constatnt);
                }
                else if (field.Constatnt is sbyte)
                {
                    constVal = new Java.Constants.Integer((sbyte)field.Constatnt);
                }
                else if (field.Constatnt is short)
                {
                    constVal = new Java.Constants.Integer((short)field.Constatnt);
                }
                else if (field.Constatnt is ushort)
                {
                    constVal = new Java.Constants.Integer((ushort)field.Constatnt);
                }
                else if (field.Constatnt is int)
                {
                    constVal = new Java.Constants.Integer((int)field.Constatnt);
                }
                else if (field.Constatnt is uint)
                {
                    constVal = new Java.Constants.Integer(unchecked ((int)((uint)field.Constatnt)));
                }
                else if (field.Constatnt is char)
                {
                    constVal = new Java.Constants.Integer((char)field.Constatnt);
                }
                else if (field.Constatnt is bool)
                {
                    constVal = new Java.Constants.Integer((bool)field.Constatnt ? 1 : 0);
                }
                else if (field.Constatnt is long)
                {
                    constVal = new Java.Constants.Long((long)field.Constatnt);
                }
                else if (field.Constatnt is ulong)
                {
                    constVal = new Java.Constants.Long(unchecked ((long)((ulong)field.Constatnt)));
                }
                else if (field.Constatnt is float)
                {
                    constVal = new Java.Constants.Float((float)field.Constatnt);
                }
                else if (field.Constatnt is double)
                {
                    constVal = new Java.Constants.Double((double)field.Constatnt);
                }
                else if (field.Constatnt is string)
                {
                    constVal = new Java.Constants.String((string)field.Constatnt);
                }

                if (constVal != null)
                {
                    result.Attributes.Add(new Java.Attributes.ConstantValue(constVal));
                }
            }

            return(result);
        }