// *****************************************************************************
        // public methods
        // *****************************************************************************
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer tb = ExprProcessor.ListToJava(varDefinitions, indent, tracer);

            tb.Append(ExprProcessor.ListToJava(exprents, indent, tracer));
            return(tb);
        }
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf       = new TextBuffer();
            bool       islabeled = IsLabeled();

            buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer));
            if (islabeled)
            {
                buf.AppendIndent(indent++).Append("label").Append(this.id.ToString()).Append(": {"
                                                                                             ).AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
            }
            bool notempty = false;

            for (int i = 0; i < stats.Count; i++)
            {
                Statement st = stats[i];
                if (i > 0 && notempty)
                {
                    buf.AppendLineSeparator();
                    tracer.IncrementCurrentSourceLine();
                }
                TextBuffer str = ExprProcessor.JmpWrapper(st, indent, false, tracer);
                buf.Append(str);
                notempty = !str.ContainsOnlyWhitespaces();
            }
            if (islabeled)
            {
                buf.AppendIndent(indent - 1).Append("}").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
            }
            return(buf);
        }
Beispiel #3
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);
        }
        private TextBuffer WrapOperandString(Exprent expr, bool eq, int indent, BytecodeMappingTracer
                                             tracer)
        {
            int  myprec      = GetPrecedence();
            int  exprprec    = expr.GetPrecedence();
            bool parentheses = exprprec > myprec;

            if (!parentheses && eq)
            {
                parentheses = (exprprec == myprec);
                if (parentheses)
                {
                    if (expr.type == Exprent.Exprent_Function && ((FunctionExprent)expr).GetFuncType(
                            ) == funcType)
                    {
                        parentheses = !Associativity.Contains(funcType);
                    }
                }
            }
            TextBuffer res = expr.ToJava(indent, tracer);

            if (parentheses)
            {
                res.Enclose("(", ")");
            }
            return(res);
        }
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            SwitchHelper.Simplify(this);
            TextBuffer buf = new TextBuffer();

            buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer));
            buf.Append(first.ToJava(indent, tracer));
            if (IsLabeled())
            {
                buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator
                    ();
                tracer.IncrementCurrentSourceLine();
            }
            buf.AppendIndent(indent).Append(headexprent[0].ToJava(indent, tracer)).Append(" {"
                                                                                          ).AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            VarType switch_type = headexprent[0].GetExprType();

            for (int i = 0; i < caseStatements.Count; i++)
            {
                Statement       stat   = caseStatements[i];
                List <StatEdge> edges  = caseEdges[i];
                List <Exprent>  values = caseValues[i];
                for (int j = 0; j < edges.Count; j++)
                {
                    if (edges[j] == default_edge)
                    {
                        buf.AppendIndent(indent).Append("default:").AppendLineSeparator();
                    }
                    else
                    {
                        buf.AppendIndent(indent).Append("case ");
                        Exprent value = values[j];
                        if (value is ConstExprent)
                        {
                            value = value.Copy();
                            ((ConstExprent)value).SetConstType(switch_type);
                        }
                        if (value is FieldExprent && ((FieldExprent)value).IsStatic())
                        {
                            // enum values
                            buf.Append(((FieldExprent)value).GetName());
                        }
                        else
                        {
                            buf.Append(value.ToJava(indent, tracer));
                        }
                        buf.Append(":").AppendLineSeparator();
                    }
                    tracer.IncrementCurrentSourceLine();
                }
                buf.Append(ExprProcessor.JmpWrapper(stat, indent + 1, false, tracer));
            }
            buf.AppendIndent(indent).Append("}").AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            return(buf);
        }
Beispiel #6
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());
     }
 }
Beispiel #7
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            string     new_line_separator = DecompilerContext.GetNewLineSeparator();
            TextBuffer buf = new TextBuffer();

            buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer));
            bool labeled = IsLabeled();

            if (labeled)
            {
                buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator
                    ();
                tracer.IncrementCurrentSourceLine();
            }
            List <StatEdge> lstSuccs = first.GetSuccessorEdges(Statedge_Direct_All);

            if (first.type == Type_Trycatch && (first.varDefinitions.Count == 0) && isFinally__ &&
                !labeled && !first.IsLabeled() && ((lstSuccs.Count == 0) || !lstSuccs[0].@explicit
                                                   ))
            {
                TextBuffer content = ExprProcessor.JmpWrapper(first, indent, true, tracer);
                content.SetLength(content.Length() - new_line_separator.Length);
                tracer.IncrementCurrentSourceLine(-1);
                buf.Append(content);
            }
            else
            {
                buf.AppendIndent(indent).Append("try {").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                buf.Append(ExprProcessor.JmpWrapper(first, indent + 1, true, tracer));
                buf.AppendIndent(indent).Append("}");
            }
            buf.Append(isFinally__ ? " finally" : " catch (" + vars[0].ToJava(indent, tracer)
                       + ")").Append(" {").AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            if (monitor != null)
            {
                buf.AppendIndent(indent + 1).Append("if (").Append(monitor.ToJava(indent, tracer)
                                                                   ).Append(") {").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
            }
            buf.Append(ExprProcessor.JmpWrapper(handler, indent + 1 + (monitor != null ? 1 :
                                                                       0), true, tracer));
            if (monitor != null)
            {
                buf.AppendIndent(indent + 1).Append("}").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
            }
            buf.AppendIndent(indent).Append("}").AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            return(buf);
        }
Beispiel #8
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);
        }
Beispiel #9
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 "));
     }
 }
        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);
                }
            }
        }
        // *****************************************************************************
        // public methods
        // *****************************************************************************
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf = new TextBuffer();

            if (IsLabeled())
            {
                buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator
                    ();
            }
            buf.AppendIndent(indent).Append("abstract statement {").AppendLineSeparator();
            foreach (Statement stat in stats)
            {
                buf.Append(stat.ToJava(indent + 1, tracer));
            }
            buf.AppendIndent(indent).Append("}");
            return(buf);
        }
Beispiel #12
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(']'));
        }
Beispiel #13
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);
        }
        // *****************************************************************************
        // public methods
        // *****************************************************************************
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf = new TextBuffer();

            buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer));
            buf.Append(first.ToJava(indent, tracer));
            if (IsLabeled())
            {
                buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator
                    ();
                tracer.IncrementCurrentSourceLine();
            }
            buf.AppendIndent(indent).Append(headexprent[0].ToJava(indent, tracer)).Append(" {"
                                                                                          ).AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            buf.Append(ExprProcessor.JmpWrapper(body, indent + 1, true, tracer));
            buf.AppendIndent(indent).Append("}").AppendLineSeparator();
            MapMonitorExitInstr(tracer);
            tracer.IncrementCurrentSourceLine();
            return(buf);
        }
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buffer = new TextBuffer();

            buffer.AppendIndent(indent);
            buffer.Append('@');
            buffer.Append(DecompilerContext.GetImportCollector().GetShortName(ExprProcessor.BuildJavaClassName
                                                                                  (className)));
            int type = GetAnnotationType();

            if (type != Annotation_Marker)
            {
                buffer.Append('(');
                bool oneLiner = type == Annotation_Single_Element || indent < 0;
                for (int i = 0; i < parNames.Count; i++)
                {
                    if (!oneLiner)
                    {
                        buffer.AppendLineSeparator().AppendIndent(indent + 1);
                    }
                    if (type != Annotation_Single_Element)
                    {
                        buffer.Append(parNames[i]);
                        buffer.Append(" = ");
                    }
                    buffer.Append(parValues[i].ToJava(0, tracer));
                    if (i < parNames.Count - 1)
                    {
                        buffer.Append(',');
                    }
                }
                if (!oneLiner)
                {
                    buffer.AppendLineSeparator().AppendIndent(indent);
                }
                buffer.Append(')');
            }
            return(buffer);
        }
Beispiel #16
0
 private static string GetQualifiedNewInstance(string classname, List <Exprent> lstParams
                                               , int indent, BytecodeMappingTracer tracer)
 {
     ClassesProcessor.ClassNode node = DecompilerContext.GetClassProcessor().GetMapRootClasses
                                           ().GetOrNull(classname);
     if (node != null && node.type != ClassesProcessor.ClassNode.Class_Root && node.type
         != ClassesProcessor.ClassNode.Class_Local && (node.access & ICodeConstants.Acc_Static
                                                       ) == 0)
     {
         if (!(lstParams.Count == 0))
         {
             Exprent enclosing      = lstParams[0];
             bool    isQualifiedNew = false;
             if (enclosing.type == Exprent.Exprent_Var)
             {
                 VarExprent  varEnclosing  = (VarExprent)enclosing;
                 StructClass current_class = ((ClassesProcessor.ClassNode)DecompilerContext.GetProperty
                                                  (DecompilerContext.Current_Class_Node)).classStruct;
                 string this_classname = varEnclosing.GetProcessor().GetThisVars().GetOrNull(new VarVersionPair
                                                                                                 (varEnclosing));
                 if (!current_class.qualifiedName.Equals(this_classname))
                 {
                     isQualifiedNew = true;
                 }
             }
             else
             {
                 isQualifiedNew = true;
             }
             if (isQualifiedNew)
             {
                 return(enclosing.ToJava(indent, tracer).ToString());
             }
         }
     }
     return(null);
 }
Beispiel #17
0
        // precedence of new
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf = new TextBuffer();

            if (anonymous)
            {
                ClassesProcessor.ClassNode child = DecompilerContext.GetClassProcessor().GetMapRootClasses
                                                       ().GetOrNull(newType.value);
                // IDEA-204310 - avoid backtracking later on for lambdas (causes spurious imports)
                if (!enumConst && (!lambda || DecompilerContext.GetOption(IFernflowerPreferences
                                                                          .Lambda_To_Anonymous_Class)))
                {
                    string enclosing = null;
                    if (!lambda && constructor != null)
                    {
                        enclosing = GetQualifiedNewInstance(child.anonymousClassType.value, constructor.GetLstParameters
                                                                (), indent, tracer);
                        if (enclosing != null)
                        {
                            buf.Append(enclosing).Append('.');
                        }
                    }
                    buf.Append("new ");
                    string typename = ExprProcessor.GetCastTypeName(child.anonymousClassType);
                    if (enclosing != null)
                    {
                        ClassesProcessor.ClassNode anonymousNode = DecompilerContext.GetClassProcessor().
                                                                   GetMapRootClasses().GetOrNull(child.anonymousClassType.value);
                        if (anonymousNode != null)
                        {
                            typename = anonymousNode.simpleName;
                        }
                        else
                        {
                            typename = Sharpen.Runtime.Substring(typename, typename.LastIndexOf('.') + 1);
                        }
                    }
                    GenericClassDescriptor descriptor = ClassWriter.GetGenericClassDescriptor(child.classStruct
                                                                                              );
                    if (descriptor != null)
                    {
                        if ((descriptor.superinterfaces.Count == 0))
                        {
                            buf.Append(GenericMain.GetGenericCastTypeName(descriptor.superclass));
                        }
                        else
                        {
                            if (descriptor.superinterfaces.Count > 1 && !lambda)
                            {
                                DecompilerContext.GetLogger().WriteMessage("Inconsistent anonymous class signature: "
                                                                           + child.classStruct.qualifiedName, IFernflowerLogger.Severity.Warn);
                            }
                            buf.Append(GenericMain.GetGenericCastTypeName(descriptor.superinterfaces[0]));
                        }
                    }
                    else
                    {
                        buf.Append(typename);
                    }
                }
                buf.Append('(');
                if (!lambda && constructor != null)
                {
                    List <Exprent>        parameters = constructor.GetLstParameters();
                    List <VarVersionPair> mask       = child.GetWrapper().GetMethodWrapper(ICodeConstants.Init_Name
                                                                                           , constructor.GetStringDescriptor()).synthParameters;
                    if (mask == null)
                    {
                        InvocationExprent superCall = child.superInvocation;
                        mask = ExprUtil.GetSyntheticParametersMask(superCall.GetClassname(), superCall.GetStringDescriptor
                                                                       (), parameters.Count);
                    }
                    int  start      = enumConst ? 2 : 0;
                    bool firstParam = true;
                    for (int i = start; i < parameters.Count; i++)
                    {
                        if (mask == null || mask[i] == null)
                        {
                            if (!firstParam)
                            {
                                buf.Append(", ");
                            }
                            ExprProcessor.GetCastedExprent(parameters[i], constructor.GetDescriptor().@params
                                                           [i], buf, indent, true, tracer);
                            firstParam = false;
                        }
                    }
                }
                buf.Append(')');
                if (enumConst && buf.Length() == 2)
                {
                    buf.SetLength(0);
                }
                if (lambda)
                {
                    if (!DecompilerContext.GetOption(IFernflowerPreferences.Lambda_To_Anonymous_Class
                                                     ))
                    {
                        buf.SetLength(0);
                    }
                    // remove the usual 'new <class>()', it will be replaced with lambda style '() ->'
                    Exprent    methodObject = constructor == null ? null : constructor.GetInstance();
                    TextBuffer clsBuf       = new TextBuffer();
                    new ClassWriter().ClassLambdaToJava(child, clsBuf, methodObject, indent, tracer);
                    buf.Append(clsBuf);
                    tracer.IncrementCurrentSourceLine(clsBuf.CountLines());
                }
                else
                {
                    TextBuffer clsBuf = new TextBuffer();
                    new ClassWriter().ClassToJava(child, clsBuf, indent, tracer);
                    buf.Append(clsBuf);
                    tracer.IncrementCurrentSourceLine(clsBuf.CountLines());
                }
            }
            else if (directArrayInit)
            {
                VarType leftType = newType.DecreaseArrayDim();
                buf.Append('{');
                for (int i = 0; i < lstArrayElements.Count; i++)
                {
                    if (i > 0)
                    {
                        buf.Append(", ");
                    }
                    ExprProcessor.GetCastedExprent(lstArrayElements[i], leftType, buf, indent, false,
                                                   tracer);
                }
                buf.Append('}');
            }
            else if (newType.arrayDim == 0)
            {
                if (!enumConst)
                {
                    string enclosing = null;
                    if (constructor != null)
                    {
                        enclosing = GetQualifiedNewInstance(newType.value, constructor.GetLstParameters()
                                                            , indent, tracer);
                        if (enclosing != null)
                        {
                            buf.Append(enclosing).Append('.');
                        }
                    }
                    buf.Append("new ");
                    string typename = ExprProcessor.GetTypeName(newType);
                    if (enclosing != null)
                    {
                        ClassesProcessor.ClassNode newNode = DecompilerContext.GetClassProcessor().GetMapRootClasses
                                                                 ().GetOrNull(newType.value);
                        if (newNode != null)
                        {
                            typename = newNode.simpleName;
                        }
                        else
                        {
                            typename = Sharpen.Runtime.Substring(typename, typename.LastIndexOf('.') + 1);
                        }
                    }
                    buf.Append(typename);
                }
                if (constructor != null)
                {
                    List <Exprent>        parameters = constructor.GetLstParameters();
                    List <VarVersionPair> mask       = ExprUtil.GetSyntheticParametersMask(constructor.GetClassname
                                                                                               (), constructor.GetStringDescriptor(), parameters.Count);
                    int start = enumConst ? 2 : 0;
                    if (!enumConst || start < parameters.Count)
                    {
                        buf.Append('(');
                        bool firstParam = true;
                        for (int i = start; i < parameters.Count; i++)
                        {
                            if (mask == null || mask[i] == null)
                            {
                                Exprent expr     = parameters[i];
                                VarType leftType = constructor.GetDescriptor().@params[i];
                                if (i == parameters.Count - 1 && expr.GetExprType() == VarType.Vartype_Null && ProbablySyntheticParameter
                                        (leftType.value))
                                {
                                    break;
                                }
                                // skip last parameter of synthetic constructor call
                                if (!firstParam)
                                {
                                    buf.Append(", ");
                                }
                                ExprProcessor.GetCastedExprent(expr, leftType, buf, indent, true, false, true, true
                                                               , tracer);
                                firstParam = false;
                            }
                        }
                        buf.Append(')');
                    }
                }
            }
            else if (isVarArgParam)
            {
                // just print the array elements
                VarType leftType = newType.DecreaseArrayDim();
                for (int i = 0; i < lstArrayElements.Count; i++)
                {
                    if (i > 0)
                    {
                        buf.Append(", ");
                    }
                    // new String[][]{{"abc"}, {"DEF"}} => new String[]{"abc"}, new String[]{"DEF"}
                    Exprent element = lstArrayElements[i];
                    if (element.type == Exprent_New)
                    {
                        ((NewExprent)element).SetDirectArrayInit(false);
                    }
                    ExprProcessor.GetCastedExprent(element, leftType, buf, indent, false, tracer);
                }
                // if there is just one element of Object[] type it needs to be casted to resolve ambiguity
                if (lstArrayElements.Count == 1)
                {
                    VarType elementType = lstArrayElements[0].GetExprType();
                    if (elementType.type == ICodeConstants.Type_Object && elementType.value.Equals("java/lang/Object"
                                                                                                   ) && elementType.arrayDim >= 1)
                    {
                        buf.Prepend("(Object)");
                    }
                }
            }
            else
            {
                buf.Append("new ").Append(ExprProcessor.GetTypeName(newType));
                if ((lstArrayElements.Count == 0))
                {
                    for (int i = 0; i < newType.arrayDim; i++)
                    {
                        buf.Append('[');
                        if (i < lstDims.Count)
                        {
                            buf.Append(lstDims[i].ToJava(indent, tracer));
                        }
                        buf.Append(']');
                    }
                }
                else
                {
                    for (int i = 0; i < newType.arrayDim; i++)
                    {
                        buf.Append("[]");
                    }
                    VarType leftType = newType.DecreaseArrayDim();
                    buf.Append('{');
                    for (int i = 0; i < lstArrayElements.Count; i++)
                    {
                        if (i > 0)
                        {
                            buf.Append(", ");
                        }
                        ExprProcessor.GetCastedExprent(lstArrayElements[i], leftType, buf, indent, false,
                                                       tracer);
                    }
                    buf.Append('}');
                }
            }
            return(buf);
        }
Beispiel #18
0
 public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     return(ExprProcessor.ListToJava(varDefinitions, indent, tracer).Append(first.ToJava
                                                                                (indent, tracer)));
 }
Beispiel #19
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);
        }
Beispiel #20
0
 public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     tracer.AddMapping(bytecode);
     return(value.ToJava(indent, tracer).Enclose("switch(", ")"));
 }
Beispiel #21
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);
        }
Beispiel #22
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            TextBuffer buf = new TextBuffer();

            buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer));
            buf.Append(first.ToJava(indent, tracer));
            if (IsLabeled())
            {
                buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator
                    ();
                tracer.IncrementCurrentSourceLine();
            }
            buf.AppendIndent(indent).Append(headexprent[0].ToJava(indent, tracer)).Append(" {"
                                                                                          ).AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            if (ifstat == null)
            {
                bool semicolon = false;
                if (ifedge.@explicit)
                {
                    semicolon = true;
                    if (ifedge.GetType() == StatEdge.Type_Break)
                    {
                        // break
                        buf.AppendIndent(indent + 1).Append("break");
                    }
                    else
                    {
                        // continue
                        buf.AppendIndent(indent + 1).Append("continue");
                    }
                    if (ifedge.labeled)
                    {
                        buf.Append(" label").Append(ifedge.closure.id.ToString());
                    }
                }
                if (semicolon)
                {
                    buf.Append(";").AppendLineSeparator();
                    tracer.IncrementCurrentSourceLine();
                }
            }
            else
            {
                buf.Append(ExprProcessor.JmpWrapper(ifstat, indent + 1, true, tracer));
            }
            bool elseif = false;

            if (elsestat != null)
            {
                if (elsestat.type == Statement.Type_If && (elsestat.varDefinitions.Count == 0) &&
                    (elsestat.GetFirst().GetExprents().Count == 0) && !elsestat.IsLabeled() && ((elsestat
                                                                                                 .GetSuccessorEdges(Statedge_Direct_All).Count == 0) || !elsestat.GetSuccessorEdges
                                                                                                    (Statedge_Direct_All)[0].@explicit))
                {
                    // else if
                    buf.AppendIndent(indent).Append("} else ");
                    TextBuffer content = ExprProcessor.JmpWrapper(elsestat, indent, false, tracer);
                    content.SetStart(TextUtil.GetIndentString(indent).Length);
                    buf.Append(content);
                    elseif = true;
                }
                else
                {
                    BytecodeMappingTracer else_tracer = new BytecodeMappingTracer(tracer.GetCurrentSourceLine
                                                                                      () + 1);
                    TextBuffer content = ExprProcessor.JmpWrapper(elsestat, indent + 1, false, else_tracer
                                                                  );
                    if (content.Length() > 0)
                    {
                        buf.AppendIndent(indent).Append("} else {").AppendLineSeparator();
                        tracer.SetCurrentSourceLine(else_tracer.GetCurrentSourceLine());
                        tracer.AddTracer(else_tracer);
                        buf.Append(content);
                    }
                }
            }
            if (!elseif)
            {
                buf.AppendIndent(indent).Append("}").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
            }
            return(buf);
        }
        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);
        }
Beispiel #24
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");
        }
        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);
        }
Beispiel #26
0
 public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     tracer.AddMapping(bytecode);
     return(condition.ToJava(indent, tracer).Enclose("if (", ")"));
 }
Beispiel #27
0
 public virtual TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
 {
     throw new Exception("not implemented");
 }
Beispiel #28
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();
            }
            switch (looptype)
            {
            case Loop_Do:
            {
                buf.AppendIndent(indent).Append("while(true) {").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                buf.Append(ExprProcessor.JmpWrapper(first, indent + 1, false, tracer));
                buf.AppendIndent(indent).Append("}").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                break;
            }

            case Loop_Dowhile:
            {
                buf.AppendIndent(indent).Append("do {").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                buf.Append(ExprProcessor.JmpWrapper(first, indent + 1, false, tracer));
                buf.AppendIndent(indent).Append("} while(").Append(conditionExprent[0].ToJava(indent
                                                                                              , tracer)).Append(");").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                break;
            }

            case Loop_While:
            {
                buf.AppendIndent(indent).Append("while(").Append(conditionExprent[0].ToJava(indent
                                                                                            , tracer)).Append(") {").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                buf.Append(ExprProcessor.JmpWrapper(first, indent + 1, false, tracer));
                buf.AppendIndent(indent).Append("}").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                break;
            }

            case Loop_For:
            {
                buf.AppendIndent(indent).Append("for(");
                if (initExprent[0] != null)
                {
                    buf.Append(initExprent[0].ToJava(indent, tracer));
                }
                buf.Append("; ").Append(conditionExprent[0].ToJava(indent, tracer)).Append("; ").
                Append(incExprent[0].ToJava(indent, tracer)).Append(") {").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                buf.Append(ExprProcessor.JmpWrapper(first, indent + 1, false, tracer));
                buf.AppendIndent(indent).Append("}").AppendLineSeparator();
                tracer.IncrementCurrentSourceLine();
                break;
            }
            }
            return(buf);
        }