/// <summary>
 /// Create a dex method definition from this method.
 /// </summary>
 public DexLib.MethodDefinition GetDexMethod(DexLib.ClassDefinition owner, DexTargetPackage targetPackage)
 {
     if (dexMethod == null)
     {
         var prototype = new DexLib.Prototype(ReturnType.GetReference(targetPackage),
                                              parameters.Select(x => new DexLib.Parameter(x.ParameterType.GetReference(targetPackage), x.Name)).ToArray());
         var mdef = new DexLib.MethodDefinition(owner, name, prototype);
         if (IsAbstract)
         {
             mdef.IsAbstract = true;
         }
         if (IsVirtual)
         {
             mdef.IsVirtual = true;
         }
         if (IsStatic)
         {
             mdef.IsStatic = true;
         }
         if (IsPrivate)
         {
             mdef.IsPrivate = true;
         }
         else if (IsProtected)
         {
             mdef.IsProtected = true;
         }
         else
         {
             mdef.IsPublic = true;
         }
         if (IsConstructor)
         {
             mdef.Name          = IsStatic ? "<clinit>" : "<init>";
             mdef.IsConstructor = true;
         }
         dexMethod = mdef;
         targetPackage.NameConverter.Record(this, dexMethod);
     }
     return(dexMethod);
 }
Пример #2
0
 /// <summary>
 /// Record the given method mapping
 /// </summary>
 internal void Record(XMethodDefinition xMethod, DexLib.MethodDefinition dMethod)
 {
     xMethodMap.Add(xMethod, dMethod);
 }
Пример #3
0
        /// <summary>
        /// Create a method body for the given method.
        /// </summary>
        internal static MethodBody TranslateToRL(AssemblyCompiler compiler, DexTargetPackage targetPackage, MethodSource source, DexLib.MethodDefinition dmethod, out CompiledMethod compiledMethod)
        {
            try
            {
#if DEBUG
                //Debugger.Launch();
                if ((source.Method != null) && (source.Method.Name == "test6"))
                {
                    //Debugger.Launch();
                }
#endif

                // Create Ast
                var optimizedAst = CreateOptimizedAst(compiler, source);

                // Generate RL code
                var rlBody      = new MethodBody(source);
                var rlGenerator = new AstCompilerVisitor(compiler, source, targetPackage, dmethod, rlBody);
                optimizedAst.Accept(rlGenerator, null);

                // Should we add return_void?
                if (source.ReturnsVoid)
                {
                    var instructions = rlBody.Instructions;
                    if ((instructions.Count == 0) || (instructions.Last().Code != RCode.Return_void))
                    {
                        instructions.Add(new RL.Instruction(RCode.Return_void)
                        {
                            SequencePoint = source.GetLastSourceLine()
                        });
                    }
                }

                // Record results
                compiledMethod = targetPackage.Record(source, rlBody, rlGenerator.Frame);

                return(rlBody);
            }
            catch (Exception ex)
            {
                // Forward exception with more information
                var msg = string.Format("Error while compiling {0} in {1}: {2}", source.FullName, source.DeclaringTypeFullName, ex.Message);
                throw new CompilerException(msg, ex);
            }
        }