Package joust.utils.tree.functiontemplates

Examples of joust.utils.tree.functiontemplates.FunctionTemplate


            scanUnfixableMethod(that);
            return;
        }

        // Is the call a static one?
        FunctionTemplate template = functionTemplates.get(calledMethod);
        if (template.isStatic) {
            log.debug("Static!");
            // If you're inside an assignment, then this one needs to be added to the list for that assignee.
            if (currentAssignmentTarget != null) {
                log.info("Attaching to: {}", currentAssignmentTarget);
View Full Code Here


        functionTemplates.put(findMethod("abs", langMath, true, symtab.doubleType), getAbs(symtab.doubleType));

        // Math.toDegrees
        AJCExpressionTree toDegrees = treeMaker.Binary(Tag.MUL, param(0, symtab.doubleType), treeMaker.Literal(57.2957795131D));
        toDegrees.setType(symtab.doubleType);
        functionTemplates.put(findMethod("toDegrees", langMath, true, symtab.doubleType), new FunctionTemplate(toDegrees, true, symtab.doubleType));

        // Math.toRadians
        AJCExpressionTree toRadians = treeMaker.Binary(Tag.MUL, param(0, symtab.doubleType), treeMaker.Literal(0.0174532925D));
        toDegrees.setType(symtab.doubleType);
        functionTemplates.put(findMethod("toRadians", langMath, true, symtab.doubleType), new FunctionTemplate(toRadians, true, symtab.doubleType));

        ClassSymbol langString = reader.enterClass(names.fromString("java.lang.String"));
        // String.valueOf
        AJCExpressionTree valueOfBoolean = treeMaker.Conditional(param(0, symtab.booleanType), treeMaker.Literal("true"), treeMaker.Literal("false"));
        functionTemplates.put(findMethod("valueOf", langString, true, symtab.booleanType), new FunctionTemplate(valueOfBoolean, true, symtab.booleanType));

        // String.toString()...
        functionTemplates.put(findMethod("toString", langString, false), new FunctionTemplate(param(0, symtab.stringType), false, symtab.stringType));
    }
View Full Code Here

                param(0, t),
                param(1, t)
            );
        mathMin.setType(t);

        return new FunctionTemplate(mathMin, true, t, t);
    }
View Full Code Here

                        treeMaker.Unary(Tag.NEG, param(0, t)),
                    param(0, t)
            );
        abs.setType(t);

        return new FunctionTemplate(abs, true, t);
    }
View Full Code Here

        if (!mayEdit) {
            return;
        }

        MethodSymbol targetSym = that.getTargetSymbol();
        FunctionTemplate template = functionTemplates.get(targetSym);

        // No template available.
        if (template == null) {
            return;
        }

        mayEdit = false;
        mHasMadeAChange = true;

        AJCForest.getInstance().increment("Calls to " + targetSym.owner + "." + targetSym.name + " Inlined: ");
        FunctionTemplateInstance instance;
        if (template.isStatic) {
            instance = template.instantiateWithTemps(enclosingMethod, that.args.toArray(new AJCExpressionTree[that.args.size()]));
        } else {
            AJCExpressionTree[] args = new AJCExpressionTree[that.args.size()+1];
            if (that.meth instanceof AJCFieldAccess) {
                // TODO: Urgh.
                args[0] = (AJCExpressionTree) ((AJCFieldAccess) that.meth).selected;
            }

            int i = 1;
            for (AJCExpressionTree arg : that.args) {
                args[i] = arg;
                i++;
            }

            instance = template.instantiateWithTemps(enclosingMethod, args);
        }

        List<AJCStatement> startupCopy = List.nil();
        if (!instance.startup.isEmpty()) {
            for (AJCStatement st : instance.startup) {
View Full Code Here

        if (newSym == null) {
            throw new IllegalStateException("Attempt to convert usages of a boxed symbol before converting the declaration.");
        }

        MethodSymbol calledMethod = that.getTargetSymbol();
        FunctionTemplate template = functionTemplates.get(calledMethod);

        if (template == null) {
            return null;
        }

        if (template.isStatic) {
            AJCExpressionTree replacement = template.instantiate(
                    that.args.toArray(
                            new AJCExpressionTree[that.args.size()]
                    )
            );

            log.info("Replacing {} with {}", that, replacement);
            return replacement;
        } else {
            // For nonstatics, the first argument to the template is the callee.
            List<AJCExpressionTree> newArgs = that.args;
            newArgs = newArgs.prepend(treeMaker.Ident(newSym));

            AJCExpressionTree replacement = template.instantiate(
                    newArgs.toArray(
                            new AJCExpressionTree[newArgs.size()]
                    )
            );
View Full Code Here

        Scope intMembers = IntegerClass.members();

        // Byte
        putCommonMethods(symtab.byteType, ByteClass, true);
        putToStringShortByte(symtab.byteType, ByteClass, IntegerClass);
        functionTemplates.put(findMethod("hashCode", ByteClass), new FunctionTemplate(byteHashCode, false, symtab.byteType));

        unboxedValueFunctions.put(symtab.byteType, findMethod("byteValue", ByteClass));

        // Short
        putCommonMethods(symtab.shortType, ShortClass, true);
        putToStringShortByte(symtab.shortType, ShortClass, IntegerClass);
        functionTemplates.put(findMethod("hashCode", ShortClass), new FunctionTemplate(shortHashCode, false, symtab.shortType));

        unboxedValueFunctions.put(symtab.shortType, findMethod("shortValue", ShortClass));

        // Integer
        putCommonMethods(symtab.intType, IntegerClass, true);
        putToString(symtab.intType, IntegerClass);
        functionTemplates.put(findMethod("hashCode", IntegerClass), new FunctionTemplate(intHashCode, false, symtab.intType));

        unboxedValueFunctions.put(symtab.intType, findMethod("intValue", IntegerClass));

        // Long
        putCommonMethods(symtab.longType, LongClass, true);
        putToString(symtab.longType, LongClass);
        functionTemplates.put(findMethod("hashCode", LongClass), new FunctionTemplate(longHashCode, false, symtab.longType));

        unboxedValueFunctions.put(symtab.longType, findMethod("longValue", LongClass));

        // Float
        putCommonMethods(symtab.floatType, FloatClass, false);
        putToString(symtab.floatType, FloatClass);

        unboxedValueFunctions.put(symtab.floatType, findMethod("floatValue", FloatClass));

        // Double
        putCommonMethods(symtab.doubleType, DoubleClass, false);
        putToString(symtab.doubleType, DoubleClass);

        unboxedValueFunctions.put(symtab.doubleType, findMethod("doubleValue", DoubleClass));

        // Boolean
        functionTemplates.put(findMethod("hashCode", BooleanClass), new FunctionTemplate(boolHashCode,false,  symtab.booleanType));
        functionTemplates.put(findMethod("toString", BooleanClass), new FunctionTemplate(boolToString, false, symtab.booleanType));
        functionTemplates.put(findMethod("booleanValue", BooleanClass), new FunctionTemplate(booleanValue, false, symtab.booleanType));
    }
View Full Code Here

        // Find the static toString method.
        AJCFieldAccess<MethodSymbol> methodRef = treeMaker.Select(treeMaker.Ident(clazz), toStringSym);

        AJCCall toString = treeMaker.Call(methodRef, List.<AJCExpressionTree>of(param(0, t)));

        functionTemplates.put(toStringSym, new FunctionTemplate(toString, false, t));
    }
View Full Code Here

        MethodSymbol intToStringSym = findMethod("toString", intClazz, true, symtab.intType);
        AJCFieldAccess<MethodSymbol> methodRef = treeMaker.Select(treeMaker.Ident(intClazz), intToStringSym);

        AJCCall toString = treeMaker.Call(methodRef, List.<AJCExpressionTree>of(cast));

        functionTemplates.put(findMethod("toString", clazz), new FunctionTemplate(toString, false, t));
    }
View Full Code Here

            AJCExpressionTree compare = treeMaker.Binary(JCTree.Tag.MINUS, param(0, t), param(1, t));

            // Can only be applied if the target object is also being unboxed.
            AJCExpressionTree equals = treeMaker.Binary(JCTree.Tag.EQ, param(0, t), param(1, t));

            FunctionTemplate equalsTemplate = new FunctionTemplate(equals, false, t, t);
            FunctionTemplate compareTemplate = new FunctionTemplate(compare, false, t, t);

            functionTemplates.put(findMethod("equals", clazz, symtab.objectType), equalsTemplate);
            functionTemplates.put(findMethod("compareTo", clazz, clazz.type), compareTemplate);

            functionTemplatesNeedingArgCheck.add(equalsTemplate);
            functionTemplatesNeedingArgCheck.add(compareTemplate);
        }

        functionTemplates.put(findMethod("byteValue", clazz), new FunctionTemplate(byteValue, false, t));
        functionTemplates.put(findMethod("shortValue", clazz), new FunctionTemplate(shortValue, false, t));
        functionTemplates.put(findMethod("intValue", clazz), new FunctionTemplate(intValue, false, t));
        functionTemplates.put(findMethod("longValue", clazz), new FunctionTemplate(longValue, false, t));
        functionTemplates.put(findMethod("floatValue", clazz), new FunctionTemplate(floatValue, false, t));
        functionTemplates.put(findMethod("doubleValue", clazz), new FunctionTemplate(doubleValue, false, t));
        functionTemplates.put(findMethod("valueOf", clazz, true, t), new FunctionTemplate(valueOf, true, t));
    }
View Full Code Here

TOP

Related Classes of joust.utils.tree.functiontemplates.FunctionTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.