Package org.openquark.cal.internal.javamodel

Examples of org.openquark.cal.internal.javamodel.JavaExpression$MethodInvocation$Static


            {
                //    if (isFunctionSingleton()) {
                //        throw new IndexOutOfBoundsException();
                //    }

                JavaExpression conditionExpr =
                    new MethodInvocation.Instance(null, "isFunctionSingleton", JavaTypeName.BOOLEAN, MethodInvocation.InvocationType.VIRTUAL);

                JavaStatement thenStatement =
                    new JavaStatement.ThrowStatement(
                        new JavaExpression.ClassInstanceCreationExpression(JavaTypeName.INDEX_OUT_OF_BOUNDS_EXCEPTION));

                JavaStatement.IfThenElseStatement ifThenStatement =
                    new JavaStatement.IfThenElseStatement (conditionExpr, thenStatement);

                method.addStatement(ifThenStatement);
            }

            SwitchStatement switchStatement =
                new SwitchStatement(childNVar);

            for (int i = 0; i < dcArity; ++i) {

                TypeExpr calFieldType = fieldTypes[i];
                String javaFieldName = javaFieldNames[i];

                JavaExpression javaFieldExpr;
                if (fieldStrictness[i] && SCJavaDefn.canTypeBeUnboxed(calFieldType)) {
                    JavaTypeName javaFieldType = SCJavaDefn.typeExprToTypeName(calFieldType);
                    javaFieldExpr = new JavaExpression.JavaField.Instance(null, javaFieldName, javaFieldType);
                    javaFieldExpr = SCJavaDefn.boxExpression(javaFieldType, javaFieldExpr);
                } else {
View Full Code Here


            // Add the throws declaration
            javaMethod.addThrows(JavaTypeName.CAL_EXECUTOR_EXCEPTION);

            // Add the method body.
            // Evaluate each child.
            JavaExpression rhs = METHODVAR_RHS;

            for (int i = dc.getArity() - 1; i >= 0; --i) {
                if (fieldStrictness[i] && !SCJavaDefn.typeExprToTypeName(fieldTypes[i]).equals(JavaTypeNames.RTVALUE)) {
                    // Strict primitive/foreign types don't need to have anything done.
                    continue;
                }

                // We want to build up an expression like:
                // deepSeq(field1 (deepSeq field2 (deepSeq field3 rhs)))
                // However, for non-strict fields we want to access them via the get_field accessor
                // to ensure the compacting of any indirection chains.
                JavaExpression deepSeqArgs[] = new JavaExpression [2];
                if (fieldStrictness[i]) {
                    deepSeqArgs[0] = new JavaField.Instance(null, javaFieldNames[i], JavaTypeNames.RTVALUE);
                } else {
                    deepSeqArgs[0] = new MethodInvocation.Instance(null, "get"+javaFieldNames[i], JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
                }
View Full Code Here

            if (LECCMachineConfiguration.generateStatistics()) {
                MethodInvocation mi = new MethodInvocation.Instance(SCJavaDefn.EXECUTION_CONTEXT_VAR, "incrementNDataTypeInstances", JavaTypeName.VOID, MethodInvocation.InvocationType.VIRTUAL);
                javaCons.addStatement(new ExpressionStatement(mi));
            }
            if (LECCMachineConfiguration.generateCallCounts()) {
                JavaExpression args[] = new JavaExpression[2];
                JavaTypeName argTypes[] = new JavaTypeName[2];
                args[0] = LiteralWrapper.make(dc.getName().getModuleName().toSourceText());
                args[1] = LiteralWrapper.make(dc.getName().getUnqualifiedName());
                argTypes[0] = argTypes[1] = JavaTypeName.STRING;
                MethodInvocation mi = new MethodInvocation.Instance(SCJavaDefn.EXECUTION_CONTEXT_VAR, "dcConstructorCalled", args, argTypes, JavaTypeName.VOID, MethodInvocation.InvocationType.VIRTUAL);
View Full Code Here

        public JavaExpression visitBinaryOperatorExpression(Binary binaryOperator,
                Void arg) {

            // Visit the second argument first, as we want to release the last reference to each
            // variable.
            JavaExpression arg1 = (JavaExpression)binaryOperator.getArgument(1).accept(this, arg);
            JavaExpression arg0 = (JavaExpression)binaryOperator.getArgument(0).accept(this, arg);
            return new Binary (
                    binaryOperator.getJavaOperator(),
                    arg0,
                    arg1);
        }
View Full Code Here

            // The branches of the conditional need to be handled separately, since they are mutually
            // exclusive.
            Map<String, JavaTypeName> variablesOfInterestBranch1 = new HashMap<String, JavaTypeName>(variablesOfInterest);
            VarReleaser vr = new VarReleaser(variablesOfInterestBranch1);
            JavaExpression arg1 = (JavaExpression)ternaryOperator.getArgument(1).accept(vr, arg);

            Map<String, JavaTypeName> variablesOfInterestBranch2 = new HashMap<String, JavaTypeName>(variablesOfInterest);
            vr = new VarReleaser(variablesOfInterestBranch2);
            JavaExpression arg2 = (JavaExpression)ternaryOperator.getArgument(2).accept(vr, arg);

            // Update the variables of interest.
            // If a variable was released in either branch it cannot be relesed previous
            // to the branching.  i.e. the variables of interest are the union of the
            // variables still in play from each branch.
            variablesOfInterest.clear();
            for(String varName : variablesOfInterestBranch1.keySet()) {
                if (variablesOfInterestBranch2.containsKey(varName)) {
                    variablesOfInterest.put(varName, variablesOfInterestBranch1.get(varName));
                }
            }

            JavaExpression arg0 = (JavaExpression)ternaryOperator.getArgument(0).accept(this, arg);
            return new Ternary (
                    arg0,
                    arg1,
                    arg2);
        }
View Full Code Here

         * @param mi
         * @return true if the method invocation is a call to 'evaluate' on a local.
         */
        private final JavaExpression.Nameable isEvaluateInvocation (MethodInvocation.Instance mi) {
            if (mi.getMethodName().equals("evaluate")) {
                JavaExpression target = mi.getInvocationTarget();

                if (target != null) {
                    if (target instanceof LocalName) {
                        return (LocalName)target;
                    } else if (target instanceof LocalVariable) {
View Full Code Here

         * @param varType
         * @return a call to RTValue.lastRef
         */
        private JavaExpression callLastRef(JavaExpression keep, JavaExpression.Nameable nullOut, JavaTypeName varType) {

            JavaExpression release =
                new MethodInvocation.Static(
                        JavaTypeNames.RTVALUE,
                        "lastRef",
                        new JavaExpression[]{keep, new Assignment(nullOut, LiteralWrapper.NULL)},
                        TWO_RTVALUES,
View Full Code Here

            // RTValue.lastRef(x.evaluate(...), x = null)
            // instead of:
            // RTValue.lastRef(x, x = null).evaluate(...);
            JavaExpression.Nameable evaluateTarget = isEvaluateInvocation(instanceInvocation);
            if (evaluateTarget != null ) {
                JavaExpression target = null;
                if (instanceInvocation.getInvocationTarget() != null) {
                    target = (JavaExpression)instanceInvocation.getInvocationTarget().accept(new JavaModelCopier<Void>(), arg);
                }

                String varName = null;
                if (evaluateTarget instanceof LocalName) {
                    varName =  ( ((LocalName)evaluateTarget).getName());
                } else if (evaluateTarget instanceof LocalVariable) {
                    varName = ( ((LocalVariable)evaluateTarget).getName());
                } else if (evaluateTarget instanceof MethodVariable) {
                    varName = ( ((MethodVariable)evaluateTarget).getName());
                } else {
                    throw new NullPointerException ("Unhandled sub type of Nameable in VarReleaser.visitInstanceMethodInvocation().");
                }

                JavaExpression newInvocation =
                    new MethodInvocation.Instance(
                        target,
                        instanceInvocation.getMethodName(),
                        instanceInvocation.getDeclaringClass(),
                        argValues,
                        argTypes,
                        instanceInvocation.getReturnType(),
                        instanceInvocation.getInvocationType());

                if (shouldRelease(varName)) {
                    JavaTypeName varType = variablesOfInterest.get(varName);
                    variablesOfInterest.remove(varName);
                    return callLastRef(newInvocation, evaluateTarget, varType);
                }

                return newInvocation;

            } else {
                JavaExpression target = null;
                if (instanceInvocation.getInvocationTarget() != null) {
                    target = (JavaExpression)instanceInvocation.getInvocationTarget().accept(this, arg);
                }

                JavaExpression newInvocation =
                    new MethodInvocation.Instance(
                        target,
                        instanceInvocation.getMethodName(),
                        instanceInvocation.getDeclaringClass(),
                        argValues,
View Full Code Here

                if (variablesOfInterestForElse.containsKey(varName)) {
                    variablesOfInterest.put(varName, variablesOfInterestForElse.get(varName));
                }
            }

            JavaExpression condition =
                (JavaExpression)ifThenElse.getCondition().accept (this, arg);

            if (newElse != null) {
                return new IfThenElseStatement(condition, newThen, newElse);
            }
View Full Code Here

        private void createFields_tagDCs () {
            JavaTypeName tagDCTypeName = CALToJavaNames.createTypeNameForTagDCFromType(typeConstructor, module);
            int fieldModifiers = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL;
            for (final DataConstructor dc : dataConsList) {
                if (dc.getArity() == 0) {
                    JavaExpression initializer = new ClassInstanceCreationExpression(tagDCTypeName, LiteralWrapper.make(Integer.valueOf(dc.getOrdinal())), JavaTypeName.INT);
                    String fieldName = CALToJavaNames.fixupVarName(dc.getName().getUnqualifiedName());
                    JavaFieldDeclaration fieldDec = new JavaFieldDeclaration(fieldModifiers, tagDCTypeName, fieldName, initializer);
                    javaClassRep.addFieldDeclaration(fieldDec);
                }
            }
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaExpression$MethodInvocation$Static

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.