Exemple #1
0
        /// <summary>
        /// Compile all types and members
        /// </summary>
        public void Compile()
        {
#if DEBUG
            //System.Diagnostics.Debugger.Launch();
#endif

            // Detect Free Apps Key
            var allAttributes = assemblies.SelectMany(x => x.CustomAttributes);
            var attr          = allAttributes.FirstOrDefault(x => x.AttributeType.Name == AttributeConstants.FreeAppsKeyAttributeName && x.AttributeType.Namespace == AttributeConstants.Dot42AttributeNamespace);
            freeAppsKey = (attr != null) ? (string)attr.ConstructorArguments[0].Value : null;

            // Detect all types to include in the compilation
            var        reachableContext   = new ReachableContext(this, assemblies.Select(x => x.Name), rootClassNames);
            const bool includeAllJavaCode = false;
            foreach (var assembly in assemblies)
            {
                reachableContext.MarkRoots(assembly, includeAllJavaCode);
            }
            foreach (var assembly in references.Where(IsLibraryProject))
            {
                reachableContext.MarkRoots(assembly, includeAllJavaCode);
            }
            reachableContext.Complete();

            // Convert IL to java compatible constructs.
            ILConversion.ILToJava.Convert(reachableContext);

            // Convert all types
            var classBuilders = reachableContext.ClassBuilders.OrderBy(x => x.SortPriority).ThenBy(x => x.FullName).ToList();
            classBuilders.ForEach(x => x.Create(targetPackage));
            classBuilders.ForEach(x => x.Implement(targetPackage));
            classBuilders.ForEach(x => x.FixUp(targetPackage));
            classBuilders.ForEach(x => x.GenerateCode(targetPackage));
            classBuilders.ForEach(x => x.CreateAnnotations(targetPackage));

            // Compile all methods
            targetPackage.CompileToTarget(generateDebugInfo, mapFile);

            // Add structure annotations
            targetPackage.AfterCompileMethods();

            // Verify
            targetPackage.VerifyBeforeSave(freeAppsKey);

            // Optimize map file
            classBuilders.ForEach(x => x.RecordMapping(mapFile));
            mapFile.Optimize();
        }
Exemple #2
0
        /// <summary>
        /// Compile all types and members
        /// </summary>
        public void Compile()
        {
#if DEBUG
            //System.Diagnostics.Debugger.Launch();
#endif

            // Detect Free Apps Key 
            var allAttributes = assemblies.SelectMany(x => x.CustomAttributes);
            var attr = allAttributes.FirstOrDefault(x => x.AttributeType.Name == AttributeConstants.FreeAppsKeyAttributeName && x.AttributeType.Namespace == AttributeConstants.Dot42AttributeNamespace);
            freeAppsKey = (attr != null) ? (string)attr.ConstructorArguments[0].Value : null;

            // Detect all types to include in the compilation
            var reachableContext = new ReachableContext(this, assemblies.Select(x => x.Name), rootClassNames);
            const bool includeAllJavaCode = false;
            foreach (var assembly in assemblies)
            {
                reachableContext.MarkRoots(assembly, includeAllJavaCode);
            }
            foreach (var assembly in references.Where(IsLibraryProject))
            {
                reachableContext.MarkRoots(assembly, includeAllJavaCode);                
            }
            reachableContext.Complete();

            // Convert IL to java compatible constructs.
            ILConversion.ILToJava.Convert(reachableContext);

            // Convert all types
            var classBuilders = reachableContext.ClassBuilders.OrderBy(x => x.SortPriority).ThenBy(x => x.FullName).ToList();
            classBuilders.ForEach(x => x.Create(targetPackage));
            classBuilders.ForEach(x => x.Implement(targetPackage));
            classBuilders.ForEach(x => x.FixUp(targetPackage));
            classBuilders.ForEach(x => x.GenerateCode(targetPackage));
            classBuilders.ForEach(x => x.CreateAnnotations(targetPackage));

            // Compile all methods
            targetPackage.CompileToTarget(generateDebugInfo, mapFile);

            // Add structure annotations
            targetPackage.AfterCompileMethods();

            // Verify
            targetPackage.VerifyBeforeSave(freeAppsKey);

            // Optimize map file
            classBuilders.ForEach(x => x.RecordMapping(mapFile));
            mapFile.Optimize();
        }
Exemple #3
0
        /// <summary>
        /// Compile all types and members
        /// </summary>
        public void Compile()
        {
#if DEBUG
            //System.Diagnostics.Debugger.Launch();
#endif

            // Detect Free Apps Key 
            var allAttributes = assemblies.SelectMany(x => x.CustomAttributes);
            var attr = allAttributes.FirstOrDefault(x => x.AttributeType.Name == AttributeConstants.FreeAppsKeyAttributeName && x.AttributeType.Namespace == AttributeConstants.Dot42AttributeNamespace);
            freeAppsKey = (attr != null) ? (string)attr.ConstructorArguments[0].Value : null;

            // Detect all types to include in the compilation
            var reachableContext = new ReachableContext(this, assemblies.Select(x => x.Name), rootClassNames);
            const bool includeAllJavaCode = false;

            using (Profile("for marking roots"))
            {
                assemblies.Concat(references.Where(IsLibraryProject))
                          .ToList()
                          .AsParallel()
                          .ForAll(assembly => reachableContext.MarkRoots(assembly, includeAllJavaCode));

                reachableContext.MarkPatternIncludes(assemblies.Concat(references).ToList());
            }

            using (Profile("for finding reachables"))
                reachableContext.Complete();

            // Convert IL to java compatible constructs.
            using (Profile("for IL conversion"))
                ILConversion.ILToJava.Convert(reachableContext);

            // Convert all types
            var classBuilders = reachableContext.ClassBuilders.OrderBy(x => x.SortPriority)
                                                              .ThenBy(x => x.FullName)
                                                              .ToList();
            using (Profile("for creating/implementing/fixup"))
            {
                classBuilders.ForEachWithExceptionMessage(x => x.Create(targetPackage));

                classBuilders.ForEachWithExceptionMessage(x => x.Implement(targetPackage));
                classBuilders.ForEachWithExceptionMessage(x => x.FixUp(targetPackage));

                // update sort priority which might have changed after XType creation.
                classBuilders = classBuilders.OrderBy(x => x.SortPriority)
                                             .ThenBy(x => x.FullName)
                                             .ToList();
            }

            if (StopCompilationBeforeGeneratingCode)
                return;

            List<Exception> errors = new List<Exception>() ;

            using (Profile("for generating code"))
            {
                if (StopAtFirstError)
                    classBuilders.ForEachWithExceptionMessage(x => x.GenerateCode(targetPackage, StopAtFirstError));
                else
                {
                    foreach (var classBuilder in classBuilders)
                    {
                        try
                        {
                            classBuilder.GenerateCode(targetPackage, StopAtFirstError);
                        }
                        catch (AggregateException ex)
                        {
                            errors.Add(new Exception("Error while compiling class " + classBuilder.FullName + ": " 
                                                    + string.Join("; ", ex.Flatten().InnerExceptions.Select(e=>e.Message)), 
                                                    ex));
                        }
                        catch (Exception ex)
                        {
                            errors.Add(new Exception("Error while compiling " + classBuilder.FullName + ": " + ex.Message, ex));
                        }
                    }
                }
            }

            classBuilders.ForEachWithExceptionMessage(x => x.CreateAnnotations(targetPackage));

            if (AddAssemblyTypesAnnotations())
                AssemblyTypesBuilder.CreateAssemblyTypes(this, (Target.Dex.DexTargetPackage)targetPackage, reachableContext.ReachableTypes);

            if (AddFrameworkPropertyAnnotations())
                DexImportClassBuilder.FinalizeFrameworkPropertyAnnotations(this, (Target.Dex.DexTargetPackage)targetPackage);

            // Compile all methods
            using (Profile("for compiling to target"))
                targetPackage.CompileToTarget(generateDebugInfo, mapFile);

            // Add structure annotations
            targetPackage.AfterCompileMethods();

            // Verify
            targetPackage.VerifyBeforeSave(freeAppsKey);


            // Create MapFile, but don't optimize jet.
            optimizedMapFile = false;
            RecordScopeMapping(reachableContext);
            classBuilders.ForEachWithExceptionMessage(x => x.RecordMapping(mapFile));

            if (errors.Count > 0)
                throw new AggregateException(errors);
        }
Exemple #4
0
        /// <summary>
        /// Compile all types and members
        /// </summary>
        public void Compile()
        {
#if DEBUG
            //System.Diagnostics.Debugger.Launch();
#endif

            // Detect Free Apps Key
            var allAttributes = assemblies.SelectMany(x => x.CustomAttributes);
            var attr          = allAttributes.FirstOrDefault(x => x.AttributeType.Name == AttributeConstants.FreeAppsKeyAttributeName && x.AttributeType.Namespace == AttributeConstants.Dot42AttributeNamespace);
            freeAppsKey = (attr != null) ? (string)attr.ConstructorArguments[0].Value : null;

            // Detect all types to include in the compilation
            var        reachableContext   = new ReachableContext(this, assemblies.Select(x => x.Name), rootClassNames);
            const bool includeAllJavaCode = false;

            using (Profile("for marking roots"))
            {
                assemblies.Concat(references.Where(IsLibraryProject))
                .ToList()
                .AsParallel()
                .ForAll(assembly => reachableContext.MarkRoots(assembly, includeAllJavaCode));

                reachableContext.MarkPatternIncludes(assemblies.Concat(references).ToList());
            }

            using (Profile("for finding reachables"))
                reachableContext.Complete();

            // Convert IL to java compatible constructs.
            using (Profile("for IL conversion"))
                ILConversion.ILToJava.Convert(reachableContext);

            // Convert all types
            var classBuilders = reachableContext.ClassBuilders.OrderBy(x => x.SortPriority)
                                .ThenBy(x => x.FullName)
                                .ToList();
            using (Profile("for creating/implementing/fixup"))
            {
                classBuilders.ForEachWithExceptionMessage(x => x.Create(targetPackage));

                classBuilders.ForEachWithExceptionMessage(x => x.Implement(targetPackage));
                classBuilders.ForEachWithExceptionMessage(x => x.FixUp(targetPackage));

                // update sort priority which might have changed after XType creation.
                classBuilders = classBuilders.OrderBy(x => x.SortPriority)
                                .ThenBy(x => x.FullName)
                                .ToList();
            }

            if (StopCompilationBeforeGeneratingCode)
            {
                return;
            }

            List <Exception> errors = new List <Exception>();

            using (Profile("for generating code"))
            {
                if (StopAtFirstError)
                {
                    classBuilders.ForEachWithExceptionMessage(x => x.GenerateCode(targetPackage, StopAtFirstError));
                }
                else
                {
                    foreach (var classBuilder in classBuilders)
                    {
                        try
                        {
                            classBuilder.GenerateCode(targetPackage, StopAtFirstError);
                        }
                        catch (AggregateException ex)
                        {
                            errors.Add(new Exception("Error while compiling class " + classBuilder.FullName + ": "
                                                     + string.Join("; ", ex.Flatten().InnerExceptions.Select(e => e.Message)),
                                                     ex));
                        }
                        catch (Exception ex)
                        {
                            errors.Add(new Exception("Error while compiling " + classBuilder.FullName + ": " + ex.Message, ex));
                        }
                    }
                }
            }

            using (Profile("for creating annotations"))
            {
                classBuilders.ForEachWithExceptionMessage(x => x.CreateAnnotations(targetPackage));

                if (AddAssemblyTypesAnnotations())
                {
                    AssemblyTypesBuilder.CreateAssemblyTypes(this, (Target.Dex.DexTargetPackage)targetPackage,
                                                             reachableContext.ReachableTypes);
                }

                if (AddFrameworkPropertyAnnotations())
                {
                    DexImportClassBuilder.FinalizeFrameworkPropertyAnnotations(this,
                                                                               (Target.Dex.DexTargetPackage)targetPackage);
                }
            }

            // Compile all methods
            using (Profile("for compiling to target"))
                targetPackage.CompileToTarget(generateDebugInfo, mapFile);

            // Add structure annotations
            targetPackage.AfterCompileMethods();

            // Verify
            targetPackage.VerifyBeforeSave(freeAppsKey);


            // Create MapFile, but don't optimize jet.
            optimizedMapFile = false;
            RecordScopeMapping(reachableContext);
            classBuilders.ForEachWithExceptionMessage(x => x.RecordMapping(mapFile));

            if (errors.Count > 0)
            {
                throw new AggregateException(errors);
            }
        }