Exemplo n.º 1
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buffer = new TextBuffer();

            tracer.AddMapping(bytecode);
            if (classDef)
            {
                ClassesProcessor.ClassNode child = DecompilerContext.GetClassProcessor().GetMapRootClasses
                                                       ().GetOrNull(varType.value);
                new ClassWriter().ClassToJava(child, buffer, indent, tracer);
                tracer.IncrementCurrentSourceLine(buffer.CountLines());
            }
            else
            {
                VarVersionPair varVersion = GetVarVersionPair();
                string         name       = null;
                if (processor != null)
                {
                    name = processor.GetVarName(varVersion);
                }
                if (definition)
                {
                    if (processor != null && processor.GetVarFinal(varVersion) == VarTypeProcessor.Var_Explicit_Final)
                    {
                        buffer.Append("final ");
                    }
                    AppendDefinitionType(buffer);
                    buffer.Append(" ");
                }
                buffer.Append(name == null ? ("var" + index + (this.version == 0 ? string.Empty :
                                                               "_" + this.version)) : name);
            }
            return(buffer);
        }
Exemplo n.º 2
0
 public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     tracer.AddMapping(bytecode);
     if (monType == Monitor_Enter)
     {
         return(value.ToJava(indent, tracer).Enclose("synchronized(", ")"));
     }
     else
     {
         return(new TextBuffer());
     }
 }
Exemplo n.º 3
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf = new TextBuffer();

            buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer));
            if (IsLabeled())
            {
                buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator
                    ();
                tracer.IncrementCurrentSourceLine();
            }
            buf.AppendIndent(indent).Append("try {").AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            buf.Append(ExprProcessor.JmpWrapper(first, indent + 1, true, tracer));
            buf.AppendIndent(indent).Append("}");
            for (int i = 1; i < stats.Count; i++)
            {
                Statement stat = stats[i];
                // map first instruction storing the exception to the catch statement
                BasicBlock block = stat.GetBasichead().GetBlock();
                if (!block.GetSeq().IsEmpty() && block.GetInstruction(0).opcode == ICodeConstants
                    .opc_astore)
                {
                    int offset = block.GetOldOffset(0);
                    if (offset > -1)
                    {
                        tracer.AddMapping(offset);
                    }
                }
                buf.Append(" catch (");
                List <string> exception_types = exctstrings[i - 1];
                if (exception_types.Count > 1)
                {
                    // multi-catch, Java 7 style
                    for (int exc_index = 1; exc_index < exception_types.Count; ++exc_index)
                    {
                        VarType exc_type = new VarType(ICodeConstants.Type_Object, 0, exception_types[exc_index
                                                       ]);
                        string exc_type_name = ExprProcessor.GetCastTypeName(exc_type);
                        buf.Append(exc_type_name).Append(" | ");
                    }
                }
                buf.Append(vars[i - 1].ToJava(indent, tracer));
                buf.Append(") {").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                buf.Append(ExprProcessor.JmpWrapper(stat, indent + 1, false, tracer)).AppendIndent
                    (indent).Append("}");
            }
            buf.AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            return(buf);
        }
Exemplo n.º 4
0
 public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     tracer.AddMapping(bytecode);
     if (exitType == Exit_Return)
     {
         TextBuffer buffer = new TextBuffer("return");
         if (retType.type != ICodeConstants.Type_Void)
         {
             buffer.Append(' ');
             ExprProcessor.GetCastedExprent(value, retType, buffer, indent, false, tracer);
         }
         return(buffer);
     }
     else
     {
         MethodWrapper method = (MethodWrapper)DecompilerContext.GetProperty(DecompilerContext
                                                                             .Current_Method_Wrapper);
         ClassesProcessor.ClassNode node = ((ClassesProcessor.ClassNode)DecompilerContext.
                                            GetProperty(DecompilerContext.Current_Class_Node));
         if (method != null && node != null)
         {
             StructExceptionsAttribute attr = method.methodStruct.GetAttribute(StructGeneralAttribute
                                                                               .Attribute_Exceptions);
             if (attr != null)
             {
                 string classname = null;
                 for (int i = 0; i < attr.GetThrowsExceptions().Count; i++)
                 {
                     string exClassName = attr.GetExcClassname(i, node.classStruct.GetPool());
                     if ("java/lang/Throwable".Equals(exClassName))
                     {
                         classname = exClassName;
                         break;
                     }
                     else if ("java/lang/Exception".Equals(exClassName))
                     {
                         classname = exClassName;
                     }
                 }
                 if (classname != null)
                 {
                     VarType    exType = new VarType(classname, true);
                     TextBuffer buffer = new TextBuffer("throw ");
                     ExprProcessor.GetCastedExprent(value, exType, buffer, indent, false, tracer);
                     return(buffer);
                 }
             }
         }
         return(value.ToJava(indent, tracer).Prepend("throw "));
     }
 }
Exemplo n.º 5
0
        private void MapMonitorExitInstr(BytecodeMappingTracer tracer)
        {
            BasicBlock block = body.GetBasichead().GetBlock();

            if (!block.GetSeq().IsEmpty() && block.GetLastInstruction().opcode == ICodeConstants
                .opc_monitorexit)
            {
                int offset = block.GetOldOffset(block.Size() - 1);
                if (offset > -1)
                {
                    tracer.AddMapping(offset);
                }
            }
        }
Exemplo n.º 6
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer res = array.ToJava(indent, tracer);

            if (array.GetPrecedence() > GetPrecedence())
            {
                // array precedence equals 0
                res.Enclose("(", ")");
            }
            VarType arrType = array.GetExprType();

            if (arrType.arrayDim == 0)
            {
                VarType objArr = VarType.Vartype_Object.ResizeArrayDim(1);
                // type family does not change
                res.Enclose("((" + ExprProcessor.GetCastTypeName(objArr) + ")", ")");
            }
            tracer.AddMapping(bytecode);
            return(res.Append('[').Append(index.ToJava(indent, tracer)).Append(']'));
        }
Exemplo n.º 7
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buffer = new TextBuffer();

            buffer.Append("assert ");
            tracer.AddMapping(bytecode);
            if (parameters[0] == null)
            {
                buffer.Append("false");
            }
            else
            {
                buffer.Append(parameters[0].ToJava(indent, tracer));
            }
            if (parameters.Count > 1)
            {
                buffer.Append(" : ");
                buffer.Append(parameters[1].ToJava(indent, tracer));
            }
            return(buffer);
        }
Exemplo n.º 8
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf = new TextBuffer();

            if (isStatic__)
            {
                ClassesProcessor.ClassNode node = (ClassesProcessor.ClassNode)DecompilerContext.GetProperty
                                                      (DecompilerContext.Current_Class_Node);
                if (node == null || !classname.Equals(node.classStruct.qualifiedName) || IsAmbiguous
                        ())
                {
                    buf.Append(DecompilerContext.GetImportCollector().GetShortNameInClassContext(ExprProcessor
                                                                                                 .BuildJavaClassName(classname)));
                    buf.Append(".");
                }
            }
            else
            {
                string super_qualifier = null;
                if (instance != null && instance.type == Exprent.Exprent_Var)
                {
                    VarExprent     instVar       = (VarExprent)instance;
                    VarVersionPair pair          = new VarVersionPair(instVar);
                    MethodWrapper  currentMethod = (MethodWrapper)DecompilerContext.GetProperty(DecompilerContext
                                                                                                .Current_Method_Wrapper);
                    if (currentMethod != null)
                    {
                        // FIXME: remove
                        string this_classname = currentMethod.varproc.GetThisVars().GetOrNull(pair);
                        if (this_classname != null)
                        {
                            if (!classname.Equals(this_classname))
                            {
                                // TODO: direct comparison to the super class?
                                super_qualifier = this_classname;
                            }
                        }
                    }
                }
                if (super_qualifier != null)
                {
                    TextUtil.WriteQualifiedSuper(buf, super_qualifier);
                }
                else
                {
                    TextBuffer buff   = new TextBuffer();
                    bool       casted = ExprProcessor.GetCastedExprent(instance, new VarType(ICodeConstants
                                                                                             .Type_Object, 0, classname), buff, indent, true, tracer);
                    string res = buff.ToString();
                    if (casted || instance.GetPrecedence() > GetPrecedence())
                    {
                        res = "(" + res + ")";
                    }
                    buf.Append(res);
                }
                if (buf.ToString().Equals(VarExprent.Var_Nameless_Enclosure))
                {
                    // FIXME: workaround for field access of an anonymous enclosing class. Find a better way.
                    buf.SetLength(0);
                }
                else
                {
                    buf.Append(".");
                }
            }
            buf.Append(name);
            tracer.AddMapping(bytecode);
            return(buf);
        }
Exemplo n.º 9
0
 public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     tracer.AddMapping(bytecode);
     return(value.ToJava(indent, tracer).Enclose("switch(", ")"));
 }
Exemplo n.º 10
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            VarType leftType         = left.GetExprType();
            VarType rightType        = right.GetExprType();
            bool    fieldInClassInit = false;
            bool    hiddenField      = false;

            if (left.type == Exprent.Exprent_Field)
            {
                // first assignment to a final field. Field name without "this" in front of it
                FieldExprent field = (FieldExprent)left;
                ClassesProcessor.ClassNode node = ((ClassesProcessor.ClassNode)DecompilerContext.
                                                   GetProperty(DecompilerContext.Current_Class_Node));
                if (node != null)
                {
                    StructField fd = node.classStruct.GetField(field.GetName(), field.GetDescriptor()
                                                               .descriptorString);
                    if (fd != null)
                    {
                        if (field.IsStatic() && fd.HasModifier(ICodeConstants.Acc_Final))
                        {
                            fieldInClassInit = true;
                        }
                        if (node.GetWrapper() != null && node.GetWrapper().GetHiddenMembers().Contains(InterpreterUtil
                                                                                                       .MakeUniqueKey(fd.GetName(), fd.GetDescriptor())))
                        {
                            hiddenField = true;
                        }
                    }
                }
            }
            if (hiddenField)
            {
                return(new TextBuffer());
            }
            TextBuffer buffer = new TextBuffer();

            if (fieldInClassInit)
            {
                buffer.Append(((FieldExprent)left).GetName());
            }
            else
            {
                buffer.Append(left.ToJava(indent, tracer));
            }
            if (right.type == Exprent_Const)
            {
                ((ConstExprent)right).AdjustConstType(leftType);
            }
            TextBuffer res = right.ToJava(indent, tracer);

            if (condType == Condition_None && !leftType.IsSuperset(rightType) && (rightType.Equals
                                                                                      (VarType.Vartype_Object) || leftType.type != ICodeConstants.Type_Object))
            {
                if (right.GetPrecedence() >= FunctionExprent.GetPrecedence(FunctionExprent.Function_Cast
                                                                           ))
                {
                    res.Enclose("(", ")");
                }
                res.Prepend("(" + ExprProcessor.GetCastTypeName(leftType) + ")");
            }
            buffer.Append(condType == Condition_None ? " = " : Operators[condType]).Append(res
                                                                                           );
            tracer.AddMapping(bytecode);
            return(buffer);
        }
Exemplo n.º 11
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            tracer.AddMapping(bytecode);
            if (funcType <= Function_Ushr)
            {
                return(WrapOperandString(lstOperands[0], false, indent, tracer).Append(Operators[
                                                                                           funcType]).Append(WrapOperandString(lstOperands[1], true, indent, tracer)));
            }
            // try to determine more accurate type for 'char' literals
            if (funcType >= Function_Eq)
            {
                if (funcType <= Function_Le)
                {
                    Exprent left  = lstOperands[0];
                    Exprent right = lstOperands[1];
                    if (right.type == Exprent_Const)
                    {
                        ((ConstExprent)right).AdjustConstType(left.GetExprType());
                    }
                    else if (left.type == Exprent_Const)
                    {
                        ((ConstExprent)left).AdjustConstType(right.GetExprType());
                    }
                }
                return(WrapOperandString(lstOperands[0], false, indent, tracer).Append(Operators[
                                                                                           funcType - Function_Eq + 11]).Append(WrapOperandString(lstOperands[1], true, indent
                                                                                                                                                  , tracer)));
            }
            switch (funcType)
            {
            case Function_Bit_Not:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("~"));
            }

            case Function_Bool_Not:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("!"));
            }

            case Function_Neg:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("-"));
            }

            case Function_Cast:
            {
                return(lstOperands[1].ToJava(indent, tracer).Enclose("(", ")").Append(WrapOperandString
                                                                                          (lstOperands[0], true, indent, tracer)));
            }

            case Function_Array_Length:
            {
                Exprent    arr = lstOperands[0];
                TextBuffer res = WrapOperandString(arr, false, indent, tracer);
                if (arr.GetExprType().arrayDim == 0)
                {
                    VarType objArr = VarType.Vartype_Object.ResizeArrayDim(1);
                    // type family does not change
                    res.Enclose("((" + ExprProcessor.GetCastTypeName(objArr) + ")", ")");
                }
                return(res.Append(".length"));
            }

            case Function_Iif:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Append(" ? ").Append
                           (WrapOperandString(lstOperands[1], true, indent, tracer)).Append(" : ").Append(WrapOperandString
                                                                                                              (lstOperands[2], true, indent, tracer)));
            }

            case Function_Ipp:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Append("++"));
            }

            case Function_Ppi:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("++"));
            }

            case Function_Imm:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Append("--"));
            }

            case Function_Mmi:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("--"));
            }

            case Function_Instanceof:
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Append(" instanceof "
                                                                                      ).Append(WrapOperandString(lstOperands[1], true, indent, tracer)));
            }

            case Function_Lcmp:
            {
                // shouldn't appear in the final code
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("__lcmp__("
                                                                                       ).Append(", ").Append(WrapOperandString(lstOperands[1], true, indent, tracer)).Append
                           (")"));
            }

            case Function_Fcmpl:
            {
                // shouldn't appear in the final code
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("__fcmpl__("
                                                                                       ).Append(", ").Append(WrapOperandString(lstOperands[1], true, indent, tracer)).Append
                           (")"));
            }

            case Function_Fcmpg:
            {
                // shouldn't appear in the final code
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("__fcmpg__("
                                                                                       ).Append(", ").Append(WrapOperandString(lstOperands[1], true, indent, tracer)).Append
                           (")"));
            }

            case Function_Dcmpl:
            {
                // shouldn't appear in the final code
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("__dcmpl__("
                                                                                       ).Append(", ").Append(WrapOperandString(lstOperands[1], true, indent, tracer)).Append
                           (")"));
            }

            case Function_Dcmpg:
            {
                // shouldn't appear in the final code
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("__dcmpg__("
                                                                                       ).Append(", ").Append(WrapOperandString(lstOperands[1], true, indent, tracer)).Append
                           (")"));
            }
            }
            if (funcType <= Function_I2s)
            {
                return(WrapOperandString(lstOperands[0], true, indent, tracer).Prepend("(" + ExprProcessor
                                                                                       .GetTypeName(Types[funcType - Function_I2l]) + ")"));
            }
            //		return "<unknown function>";
            throw new Exception("invalid function");
        }
Exemplo n.º 12
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            bool literal = DecompilerContext.GetOption(IFernflowerPreferences.Literals_As_Is
                                                       );
            bool ascii = DecompilerContext.GetOption(IFernflowerPreferences.Ascii_String_Characters
                                                     );

            tracer.AddMapping(bytecode);
            if (constType.type != ICodeConstants.Type_Null && value == null)
            {
                return(new TextBuffer(ExprProcessor.GetCastTypeName(constType)));
            }
            switch (constType.type)
            {
            case ICodeConstants.Type_Boolean:
            {
                return(new TextBuffer(((int)value != 0).ToString()));
            }

            case ICodeConstants.Type_Char:
            {
                int    val = (int)value;
                string ret = Char_Escapes.GetOrNull(val);
                if (ret == null)
                {
                    char c = (char)val;
                    if (IsPrintableAscii(c) || !ascii && TextUtil.IsPrintableUnicode(c))
                    {
                        ret = c.ToString();
                    }
                    else
                    {
                        ret = TextUtil.CharToUnicodeLiteral(c);
                    }
                }
                return(new TextBuffer(ret).Enclose("'", "'"));
            }

            case ICodeConstants.Type_Byte:
            case ICodeConstants.Type_Bytechar:
            case ICodeConstants.Type_Short:
            case ICodeConstants.Type_Shortchar:
            case ICodeConstants.Type_Int:
            {
                int intVal = (int)value;
                if (!literal)
                {
                    if (intVal == int.MaxValue)
                    {
                        return(new FieldExprent("MAX_VALUE", "java/lang/Integer", true, null, FieldDescriptor
                                                .Integer_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (intVal == int.MinValue)
                    {
                        return(new FieldExprent("MIN_VALUE", "java/lang/Integer", true, null, FieldDescriptor
                                                .Integer_Descriptor, bytecode).ToJava(0, tracer));
                    }
                }
                return(new TextBuffer(value.ToString()));
            }

            case ICodeConstants.Type_Long:
            {
                long longVal = (long)value;
                if (!literal)
                {
                    if (longVal == long.MaxValue)
                    {
                        return(new FieldExprent("MAX_VALUE", "java/lang/Long", true, null, FieldDescriptor
                                                .Long_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (longVal == long.MinValue)
                    {
                        return(new FieldExprent("MIN_VALUE", "java/lang/Long", true, null, FieldDescriptor
                                                .Long_Descriptor, bytecode).ToJava(0, tracer));
                    }
                }
                return(new TextBuffer(value.ToString()).Append('L'));
            }

            case ICodeConstants.Type_Float:
            {
                float floatVal = (float)value;
                if (!literal)
                {
                    if (float.IsNaN(floatVal))
                    {
                        return(new FieldExprent("NaN", "java/lang/Float", true, null, FieldDescriptor.Float_Descriptor
                                                , bytecode).ToJava(0, tracer));
                    }
                    else if (floatVal == float.PositiveInfinity)
                    {
                        return(new FieldExprent("POSITIVE_INFINITY", "java/lang/Float", true, null, FieldDescriptor
                                                .Float_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (floatVal == float.NegativeInfinity)
                    {
                        return(new FieldExprent("NEGATIVE_INFINITY", "java/lang/Float", true, null, FieldDescriptor
                                                .Float_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (floatVal == float.MaxValue)
                    {
                        return(new FieldExprent("MAX_VALUE", "java/lang/Float", true, null, FieldDescriptor
                                                .Float_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (floatVal == float.MinValue)
                    {
                        return(new FieldExprent("MIN_VALUE", "java/lang/Float", true, null, FieldDescriptor
                                                .Float_Descriptor, bytecode).ToJava(0, tracer));
                    }
                }
                else if (float.IsNaN(floatVal))
                {
                    return(new TextBuffer("0.0F / 0.0"));
                }
                else if (floatVal == float.PositiveInfinity)
                {
                    return(new TextBuffer("1.0F / 0.0"));
                }
                else if (floatVal == float.NegativeInfinity)
                {
                    return(new TextBuffer("-1.0F / 0.0"));
                }
                return(new TextBuffer(value.ToString()).Append('F'));
            }

            case ICodeConstants.Type_Double:
            {
                double doubleVal = (double)value;
                if (!literal)
                {
                    if (double.IsNaN(doubleVal))
                    {
                        return(new FieldExprent("NaN", "java/lang/Double", true, null, FieldDescriptor.Double_Descriptor
                                                , bytecode).ToJava(0, tracer));
                    }
                    else if (doubleVal == double.PositiveInfinity)
                    {
                        return(new FieldExprent("POSITIVE_INFINITY", "java/lang/Double", true, null, FieldDescriptor
                                                .Double_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (doubleVal == double.NegativeInfinity)
                    {
                        return(new FieldExprent("NEGATIVE_INFINITY", "java/lang/Double", true, null, FieldDescriptor
                                                .Double_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (doubleVal == double.MaxValue)
                    {
                        return(new FieldExprent("MAX_VALUE", "java/lang/Double", true, null, FieldDescriptor
                                                .Double_Descriptor, bytecode).ToJava(0, tracer));
                    }
                    else if (doubleVal == double.MinValue)
                    {
                        return(new FieldExprent("MIN_VALUE", "java/lang/Double", true, null, FieldDescriptor
                                                .Double_Descriptor, bytecode).ToJava(0, tracer));
                    }
                }
                else if (double.IsNaN(doubleVal))
                {
                    return(new TextBuffer("0.0D / 0.0"));
                }
                else if (doubleVal == double.PositiveInfinity)
                {
                    return(new TextBuffer("1.0D / 0.0"));
                }
                else if (doubleVal == double.NegativeInfinity)
                {
                    return(new TextBuffer("-1.0D / 0.0"));
                }
                return(new TextBuffer(value.ToString()).Append('D'));
            }

            case ICodeConstants.Type_Null:
            {
                return(new TextBuffer("null"));
            }

            case ICodeConstants.Type_Object:
            {
                if (constType.Equals(VarType.Vartype_String))
                {
                    return(new TextBuffer(ConvertStringToJava(value.ToString(), ascii)).Enclose("\"",
                                                                                                "\""));
                }
                else if (constType.Equals(VarType.Vartype_Class))
                {
                    string  stringVal = value.ToString();
                    VarType type      = new VarType(stringVal, !stringVal.StartsWith("["));
                    return(new TextBuffer(ExprProcessor.GetCastTypeName(type)).Append(".class"));
                }
                break;
            }
            }
            throw new Exception("invalid constant type: " + constType);
        }
Exemplo n.º 13
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf             = new TextBuffer();
            string     super_qualifier = null;
            bool       isInstanceThis  = false;

            tracer.AddMapping(bytecode);
            if (instance is InvocationExprent)
            {
                ((InvocationExprent)instance).MarkUsingBoxingResult();
            }
            if (isStatic__)
            {
                if (IsBoxingCall() && canIgnoreBoxing)
                {
                    // process general "boxing" calls, e.g. 'Object[] data = { true }' or 'Byte b = 123'
                    // here 'byte' and 'short' values do not need an explicit narrowing type cast
                    ExprProcessor.GetCastedExprent(lstParameters[0], descriptor.@params[0], buf, indent
                                                   , false, false, false, false, tracer);
                    return(buf);
                }
                ClassesProcessor.ClassNode node = (ClassesProcessor.ClassNode)DecompilerContext.GetProperty
                                                      (DecompilerContext.Current_Class_Node);
                if (node == null || !classname.Equals(node.classStruct.qualifiedName))
                {
                    buf.Append(DecompilerContext.GetImportCollector().GetShortNameInClassContext(ExprProcessor
                                                                                                 .BuildJavaClassName(classname)));
                }
            }
            else
            {
                if (instance != null && instance.type == Exprent.Exprent_Var)
                {
                    VarExprent     instVar = (VarExprent)instance;
                    VarVersionPair varPair = new VarVersionPair(instVar);
                    VarProcessor   varProc = instVar.GetProcessor();
                    if (varProc == null)
                    {
                        MethodWrapper currentMethod = (MethodWrapper)DecompilerContext.GetProperty(DecompilerContext
                                                                                                   .Current_Method_Wrapper);
                        if (currentMethod != null)
                        {
                            varProc = currentMethod.varproc;
                        }
                    }
                    string this_classname = null;
                    if (varProc != null)
                    {
                        this_classname = varProc.GetThisVars().GetOrNull(varPair);
                    }
                    if (this_classname != null)
                    {
                        isInstanceThis = true;
                        if (invocationTyp == Invoke_Special)
                        {
                            if (!classname.Equals(this_classname))
                            {
                                // TODO: direct comparison to the super class?
                                StructClass cl          = DecompilerContext.GetStructContext().GetClass(classname);
                                bool        isInterface = cl != null && cl.HasModifier(ICodeConstants.Acc_Interface);
                                super_qualifier = !isInterface ? this_classname : classname;
                            }
                        }
                    }
                }
                if (functype == Typ_General)
                {
                    if (super_qualifier != null)
                    {
                        TextUtil.WriteQualifiedSuper(buf, super_qualifier);
                    }
                    else if (instance != null)
                    {
                        TextBuffer res = instance.ToJava(indent, tracer);
                        if (IsUnboxingCall())
                        {
                            // we don't print the unboxing call - no need to bother with the instance wrapping / casting
                            buf.Append(res);
                            return(buf);
                        }
                        VarType rightType = instance.GetExprType();
                        VarType leftType  = new VarType(ICodeConstants.Type_Object, 0, classname);
                        if (rightType.Equals(VarType.Vartype_Object) && !leftType.Equals(rightType))
                        {
                            buf.Append("((").Append(ExprProcessor.GetCastTypeName(leftType)).Append(")");
                            if (instance.GetPrecedence() >= FunctionExprent.GetPrecedence(FunctionExprent.Function_Cast
                                                                                          ))
                            {
                                res.Enclose("(", ")");
                            }
                            buf.Append(res).Append(")");
                        }
                        else if (instance.GetPrecedence() > GetPrecedence())
                        {
                            buf.Append("(").Append(res).Append(")");
                        }
                        else
                        {
                            buf.Append(res);
                        }
                    }
                }
            }
            switch (functype)
            {
            case Typ_General:
            {
                if (VarExprent.Var_Nameless_Enclosure.Equals(buf.ToString()))
                {
                    buf = new TextBuffer();
                }
                if (buf.Length() > 0)
                {
                    buf.Append(".");
                }
                buf.Append(name);
                if (invocationTyp == Invoke_Dynamic)
                {
                    buf.Append("<invokedynamic>");
                }
                buf.Append("(");
                break;
            }

            case Typ_Clinit:
            {
                throw new Exception("Explicit invocation of " + ICodeConstants.Clinit_Name);
            }

            case Typ_Init:
            {
                if (super_qualifier != null)
                {
                    buf.Append("super(");
                }
                else if (isInstanceThis)
                {
                    buf.Append("this(");
                }
                else if (instance != null)
                {
                    buf.Append(instance.ToJava(indent, tracer)).Append(".<init>(");
                }
                else
                {
                    throw new Exception("Unrecognized invocation of " + ICodeConstants.Init_Name);
                }
                break;
            }
            }
            List <VarVersionPair> mask = null;
            bool isEnum = false;

            if (functype == Typ_Init)
            {
                ClassesProcessor.ClassNode newNode = DecompilerContext.GetClassProcessor().GetMapRootClasses
                                                         ().GetOrNull(classname);
                if (newNode != null)
                {
                    mask = ExprUtil.GetSyntheticParametersMask(newNode, stringDescriptor, lstParameters
                                                               .Count);
                    isEnum = newNode.classStruct.HasModifier(ICodeConstants.Acc_Enum) && DecompilerContext
                             .GetOption(IFernflowerPreferences.Decompile_Enum);
                }
            }
            BitSet setAmbiguousParameters = GetAmbiguousParameters();

            // omit 'new Type[] {}' for the last parameter of a vararg method call
            if (lstParameters.Count == [email protected] && IsVarArgCall())
            {
                Exprent lastParam = lstParameters[lstParameters.Count - 1];
                if (lastParam.type == Exprent_New && lastParam.GetExprType().arrayDim >= 1)
                {
                    ((NewExprent)lastParam).SetVarArgParam(true);
                }
            }
            bool firstParameter = true;
            int  start          = isEnum ? 2 : 0;

            for (int i = start; i < lstParameters.Count; i++)
            {
                if (mask == null || mask[i] == null)
                {
                    TextBuffer buff      = new TextBuffer();
                    bool       ambiguous = setAmbiguousParameters.Get(i);
                    // 'byte' and 'short' literals need an explicit narrowing type cast when used as a parameter
                    ExprProcessor.GetCastedExprent(lstParameters[i], descriptor.@params[i], buff, indent
                                                   , true, ambiguous, true, true, tracer);
                    // the last "new Object[0]" in the vararg call is not printed
                    if (buff.Length() > 0)
                    {
                        if (!firstParameter)
                        {
                            buf.Append(", ");
                        }
                        buf.Append(buff);
                    }
                    firstParameter = false;
                }
            }
            buf.Append(')');
            return(buf);
        }
Exemplo n.º 14
0
 public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     tracer.AddMapping(bytecode);
     return(condition.ToJava(indent, tracer).Enclose("if (", ")"));
 }