Example #1
0
        internal static List <ClassDefinition> Hierarchicalize(List <ClassDefinition> container)
        {
            var result = new List <ClassDefinition>();
            var dex    = new DexLookup(container, false);

            foreach (var cdef in container)
            {
                int idx = cdef.Fullname.LastIndexOf(DexConsts.InnerClassMarker);

                if (idx == -1)
                {
                    result.Add(cdef);
                }
                else
                {
                    string ownerFullName = cdef.Fullname.Substring(0, idx);
                    var    owner         = dex.GetClass(ownerFullName);
                    if (owner != null)
                    {
                        owner.AddInnerClass(cdef);
                        cdef.Owner = owner;
                    }
                    else
                    {
                        DLog.Error(DContext.CompilerCodeGenerator, "owner not found for inner class {0}", cdef.Fullname);
                        result.Add(cdef);
                    }
                }
            }
            return(result);
        }
        private void Initialize(string dexFilename, string mapfile, Func<AssemblyDefinition, string> filenameFromAssembly)
        {
            try
            {
                var readDex = Task.Factory.StartNew(() => DexLib.Dex.Read(dexFilename));
                var readMap = Task.Factory.StartNew(() => new MapFileLookup(new MapFile(mapfile)));

                Task.WaitAll(readMap, readDex);
                var dex = readDex.Result;
                var map = readMap.Result;
                
                _modifiedDetector = new AssemblyModifiedDetector(filenameFromAssembly, map);

                foreach (var type in map.TypeEntries)
                {
                    if(type.ScopeId == null)
                        continue;
                    
                    var typeScopeId = GetTypeScopeId(type);
                    
                    // redirect the generated class if neccessary.
                    var dexType = type.Id == 0 ? map.GeneratedType : type;

                    foreach (var method in type.Methods)
                    {
                        if (type.ScopeId == null)
                            continue;
                        
                        var scopeKey = Tuple.Create(typeScopeId, method.ScopeId);
                        _methodsByScopeId[scopeKey] = Tuple.Create(dexType, method);
                    }
                }

                _dexLookup = new DexLookup(dex);

                _dex = dex;
                _map = map;
            }
            catch (Exception ex)
            {
                IsEnabled = false;
                DLog.Warning(DContext.CompilerCodeGenerator, "Unable to initialize compiler cache: {0}", ex.Message);
            }            
        }
Example #3
0
        internal static List<ClassDefinition> Hierarchicalize(List<ClassDefinition> container)
        {
            var result = new List<ClassDefinition>();
            var dex = new DexLookup(container, false);

            foreach (var cdef in container)
            {
                int idx = cdef.Fullname.LastIndexOf(DexConsts.InnerClassMarker);

                if (idx == -1)
                {
                    result.Add(cdef);
                }
                else
                {
                    string ownerFullName = cdef.Fullname.Substring(0, idx);
                    var owner = dex.GetClass(ownerFullName);
                    if (owner != null)
                    {
                        owner.AddInnerClass(cdef);
                        cdef.Owner = owner;
                    }
                    else
                    {
                        DLog.Error(DContext.CompilerCodeGenerator, "owner not found for inner class {0}", cdef.Fullname);
                        result.Add(cdef);
                    }
                }
            }
            return result;
        }