Пример #1
0
        internal static TypeWrapper GetTypeWrapperFromObject(object o)
        {
            TypeWrapper ghostType = GhostTag.GetTag(o);

            if (ghostType != null)
            {
                return(ghostType);
            }
            Type t = o.GetType();

            if (t.IsPrimitive || (ClassLoaderWrapper.IsRemappedType(t) && !t.IsSealed))
            {
                return(DotNetTypeWrapper.GetWrapperFromDotNetType(t));
            }
            for (; ;)
            {
                TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(t);
                // if GetWrapperFromType returns null (or if tw.IsAbstract), that
                // must mean that the Type of the object is an implementation helper class
                // (e.g. an AtomicReferenceFieldUpdater or ThreadLocal instrinsic subclass)
                if (tw != null && (!tw.IsAbstract || tw.IsArray))
                {
                    return(tw);
                }
                t = t.BaseType;
            }
        }
Пример #2
0
            internal string GetTypeNameAndType(Type type, out bool isJavaType)
            {
                Module mod         = type.Module;
                int    moduleIndex = -1;

                for (int i = 0; i < modules.Length; i++)
                {
                    if (modules[i] == mod)
                    {
                        moduleIndex = i;
                        break;
                    }
                }
                if (isJavaModule[moduleIndex])
                {
                    isJavaType = true;
                    if (AttributeHelper.IsHideFromJava(type))
                    {
                        return(null);
                    }
                    return(CompiledTypeWrapper.GetName(type));
                }
                else
                {
                    isJavaType = false;
                    if (!DotNetTypeWrapper.IsAllowedOutside(type))
                    {
                        return(null);
                    }
                    return(DotNetTypeWrapper.GetName(type));
                }
            }
Пример #3
0
        private static string getClassNameFromType(Type type)
        {
            if (type == null)
            {
                return("<Module>");
            }
            if (ClassLoaderWrapper.IsRemappedType(type))
            {
                return(DotNetTypeWrapper.GetName(type));
            }
            TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(type);

            if (tw != null)
            {
                if (tw.IsPrimitive)
                {
                    return(DotNetTypeWrapper.GetName(type));
                }
#if !FIRST_PASS
                if (tw.IsUnsafeAnonymous)
                {
                    return(tw.ClassObject.getName());
                }
#endif
                return(tw.Name);
            }
            return(type.FullName);
        }
Пример #4
0
    private static int ProcessAssembly(Assembly assembly, bool continueOnError)
    {
        int rc = 0;

        foreach (Type t in assembly.GetTypes())
        {
            if (t.IsPublic &&
                !t.IsGenericTypeDefinition &&
                !AttributeHelper.IsHideFromJava(t) &&
                (!t.IsGenericType || !AttributeHelper.IsJavaModule(t.Module)))
            {
                TypeWrapper c;
                if (ClassLoaderWrapper.IsRemappedType(t) || t.IsPrimitive || t == Types.Void)
                {
                    c = DotNetTypeWrapper.GetWrapperFromDotNetType(t);
                }
                else
                {
                    c = ClassLoaderWrapper.GetWrapperFromType(t);
                }
                if (c != null)
                {
                    AddToExportList(c);
                }
            }
        }
        bool keepGoing;

        do
        {
            keepGoing = false;
            foreach (TypeWrapper c in new List <TypeWrapper>(todo.Values))
            {
                if (!done.ContainsKey(c.Name))
                {
                    keepGoing = true;
                    done.Add(c.Name, null);

                    try
                    {
                        ProcessClass(c);
                    }
                    catch (Exception x)
                    {
                        if (continueOnError)
                        {
                            rc = 1;
                            Console.WriteLine(x);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    WriteClass(c);
                }
            }
        } while(keepGoing);
        return(rc);
    }
Пример #5
0
            internal TypeWrapper CreateWrapperForAssemblyType(Type type)
            {
                Module mod         = type.Module;
                int    moduleIndex = -1;

                for (int i = 0; i < modules.Length; i++)
                {
                    if (modules[i] == mod)
                    {
                        moduleIndex = i;
                        break;
                    }
                }
                string name;

                if (isJavaModule[moduleIndex])
                {
                    name = CompiledTypeWrapper.GetName(type);
                }
                else
                {
                    name = DotNetTypeWrapper.GetName(type);
                }
                if (name == null)
                {
                    return(null);
                }
                if (isJavaModule[moduleIndex])
                {
                    if (AttributeHelper.IsHideFromJava(type))
                    {
                        return(null);
                    }
                    // since this type was compiled from Java source, we have to look for our
                    // attributes
                    return(CompiledTypeWrapper.newInstance(name, type));
                }
                else
                {
                    if (!DotNetTypeWrapper.IsAllowedOutside(type))
                    {
                        return(null);
                    }
                    // since this type was not compiled from Java source, we don't need to
                    // look for our attributes, but we do need to filter unrepresentable
                    // stuff (and transform some other stuff)
                    return(DotNetTypeWrapper.Create(type, name));
                }
            }
Пример #6
0
        private static string getClassNameFromType(Type type)
        {
            if (ClassLoaderWrapper.IsRemappedType(type))
            {
                return(DotNetTypeWrapper.GetName(type));
            }
            TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(type);

            if (tw != null)
            {
                if (tw.IsPrimitive)
                {
                    return(DotNetTypeWrapper.GetName(type));
                }
                return(tw.Name);
            }
            return(type.FullName);
        }
Пример #7
0
        public static jlClass getClassFromTypeHandle(RuntimeTypeHandle handle, int rank)
        {
            Type t = Type.GetTypeFromHandle(handle);

            if (t.IsPrimitive || ClassLoaderWrapper.IsRemappedType(t) || t == typeof(void))
            {
                return(DotNetTypeWrapper.GetWrapperFromDotNetType(t).MakeArrayType(rank).ClassObject);
            }
            if (!IsVisibleAsClass(t))
            {
                return(null);
            }
            TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(t);

            if (tw != null)
            {
                return(tw.MakeArrayType(rank).ClassObject);
            }
            return(null);
        }
Пример #8
0
            internal TypeWrapper CreateWrapperForAssemblyType(Type type)
            {
                bool   isJavaType;
                string name = GetTypeNameAndType(type, out isJavaType);

                if (name == null)
                {
                    return(null);
                }
                if (isJavaType)
                {
                    // since this type was compiled from Java source, we have to look for our
                    // attributes
                    return(CompiledTypeWrapper.newInstance(name, type));
                }
                else
                {
                    // since this type was not compiled from Java source, we don't need to
                    // look for our attributes, but we do need to filter unrepresentable
                    // stuff (and transform some other stuff)
                    return(DotNetTypeWrapper.Create(type, name));
                }
            }
Пример #9
0
 internal TypeWrapper DoLoad(string name)
 {
     for (int i = 0; i < modules.Length; i++)
     {
         if (isJavaModule[i])
         {
             Type type = GetJavaType(modules[i], name);
             if (type != null)
             {
                 // check the name to make sure that the canonical name was used
                 if (CompiledTypeWrapper.GetName(type) == name)
                 {
                     return(CompiledTypeWrapper.newInstance(name, type));
                 }
             }
         }
         else
         {
             // TODO should we catch ArgumentException and prohibit array, pointer and byref here?
             Type type = GetType(modules[i], DotNetTypeWrapper.DemangleTypeName(name));
             if (type != null && DotNetTypeWrapper.IsAllowedOutside(type))
             {
                 // check the name to make sure that the canonical name was used
                 if (DotNetTypeWrapper.GetName(type) == name)
                 {
                     return(DotNetTypeWrapper.Create(type, name));
                 }
             }
         }
     }
     if (hasDotNetModule)
     {
         // for fake types, we load the declaring outer type (the real one) and
         // let that generated the manufactured nested classes
         // (note that for generic outer types, we need to duplicate this in ClassLoaderWrapper.LoadGenericClass)
         TypeWrapper outer = null;
         if (name.EndsWith(DotNetTypeWrapper.DelegateInterfaceSuffix))
         {
             outer = DoLoad(name.Substring(0, name.Length - DotNetTypeWrapper.DelegateInterfaceSuffix.Length));
         }
         else if (name.EndsWith(DotNetTypeWrapper.AttributeAnnotationSuffix))
         {
             outer = DoLoad(name.Substring(0, name.Length - DotNetTypeWrapper.AttributeAnnotationSuffix.Length));
         }
         else if (name.EndsWith(DotNetTypeWrapper.AttributeAnnotationReturnValueSuffix))
         {
             outer = DoLoad(name.Substring(0, name.Length - DotNetTypeWrapper.AttributeAnnotationReturnValueSuffix.Length));
         }
         else if (name.EndsWith(DotNetTypeWrapper.AttributeAnnotationMultipleSuffix))
         {
             outer = DoLoad(name.Substring(0, name.Length - DotNetTypeWrapper.AttributeAnnotationMultipleSuffix.Length));
         }
         else if (name.EndsWith(DotNetTypeWrapper.EnumEnumSuffix))
         {
             outer = DoLoad(name.Substring(0, name.Length - DotNetTypeWrapper.EnumEnumSuffix.Length));
         }
         if (outer != null && outer.IsFakeTypeContainer)
         {
             foreach (TypeWrapper tw in outer.InnerClasses)
             {
                 if (tw.Name == name)
                 {
                     return(tw);
                 }
             }
         }
     }
     return(null);
 }
Пример #10
0
        internal TypeWrapper LoadGenericClass(string name)
        {
            // generic class name grammar:
            //
            // mangled(open_generic_type_name) "_$$$_" M(parameter_class_name) ( "_$$_" M(parameter_class_name) )* "_$$$$_"
            //
            // mangled() is the normal name mangling algorithm
            // M() is a replacement of "__" with "$$005F$$005F" followed by a replace of "." with "__"
            //
            int pos = name.IndexOf("_$$$_");

            if (pos <= 0 || !name.EndsWith("_$$$$_"))
            {
                return(null);
            }
            Type type = GetGenericTypeDefinition(DotNetTypeWrapper.DemangleTypeName(name.Substring(0, pos)));

            if (type == null)
            {
                return(null);
            }
            List <string> typeParamNames = new List <string>();

            pos += 5;
            int start = pos;
            int nest  = 0;

            for (;;)
            {
                pos = name.IndexOf("_$$", pos);
                if (pos == -1)
                {
                    return(null);
                }
                if (name.IndexOf("_$$_", pos, 4) == pos)
                {
                    if (nest == 0)
                    {
                        typeParamNames.Add(name.Substring(start, pos - start));
                        start = pos + 4;
                    }
                    pos += 4;
                }
                else if (name.IndexOf("_$$$_", pos, 5) == pos)
                {
                    nest++;
                    pos += 5;
                }
                else if (name.IndexOf("_$$$$_", pos, 6) == pos)
                {
                    if (nest == 0)
                    {
                        if (pos + 6 != name.Length)
                        {
                            return(null);
                        }
                        typeParamNames.Add(name.Substring(start, pos - start));
                        break;
                    }
                    nest--;
                    pos += 6;
                }
                else
                {
                    pos += 3;
                }
            }
            Type[] typeArguments = new Type[typeParamNames.Count];
            for (int i = 0; i < typeArguments.Length; i++)
            {
                string s = (string)typeParamNames[i];
                // only do the unmangling for non-generic types (because we don't want to convert
                // the double underscores in two adjacent _$$$_ or _$$$$_ markers)
                if (s.IndexOf("_$$$_") == -1)
                {
                    s = s.Replace("__", ".");
                    s = s.Replace("$$005F$$005F", "__");
                }
                int dims = 0;
                while (s.Length > dims && s[dims] == 'A')
                {
                    dims++;
                }
                if (s.Length == dims)
                {
                    return(null);
                }
                TypeWrapper tw = null;
                switch (s[dims])
                {
                case 'L':
                    tw = LoadClassByDottedNameFast(s.Substring(dims + 1));
                    tw.Finish();
                    break;

                case 'Z':
                    tw = PrimitiveTypeWrapper.BOOLEAN;
                    break;

                case 'B':
                    tw = PrimitiveTypeWrapper.BYTE;
                    break;

                case 'S':
                    tw = PrimitiveTypeWrapper.SHORT;
                    break;

                case 'C':
                    tw = PrimitiveTypeWrapper.CHAR;
                    break;

                case 'I':
                    tw = PrimitiveTypeWrapper.INT;
                    break;

                case 'F':
                    tw = PrimitiveTypeWrapper.FLOAT;
                    break;

                case 'J':
                    tw = PrimitiveTypeWrapper.LONG;
                    break;

                case 'D':
                    tw = PrimitiveTypeWrapper.DOUBLE;
                    break;
                }
                if (tw == null)
                {
                    return(null);
                }
                if (dims > 0)
                {
                    tw = tw.MakeArrayType(dims);
                }
                typeArguments[i] = tw.TypeAsSignatureType;
            }
            try
            {
                type = type.MakeGenericType(typeArguments);
            }
            catch (ArgumentException)
            {
                // one of the typeArguments failed to meet the constraints
                return(null);
            }
            TypeWrapper wrapper = GetWrapperFromType(type);

            if (wrapper != null && wrapper.Name != name)
            {
                // the name specified was not in canonical form
                return(null);
            }
            return(wrapper);
        }