Package org.openquark.cal.internal.javamodel.JavaExpression

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


            Block methodBodyBlock = new Block();
            int nReturnedFields = 0;

            // Check that this is an instance of the expected data constructor.
            MethodInvocation checkDC =
                new MethodInvocation.Instance(
                        null,
                        "checkDCOrdinalForFieldSelection",
                        new JavaExpression[]{new MethodVariable("dcOrdinal"), new MethodVariable("errorInfo")},
                        new JavaTypeName[]{JavaTypeName.INT, JavaTypeName.ERRORINFO},
                        JavaTypeName.VOID,
                        MethodInvocation.InvocationType.VIRTUAL);
            methodBodyBlock.addStatement(new ExpressionStatement(checkDC));

            SwitchStatement sw = new SwitchStatement(METHODVAR_FIELDINDEX);
            for (int i = 0; i < javaFieldNames.length; ++i) {
                if (forType != null) {
                    // If field is not strict or not primitive can't return unboxed form.
                    if (!fieldStrictness[i] || !SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
                        continue;
                    }

                    JavaTypeName ftn = SCJavaDefn.typeExprToTypeName(fieldTypes[i]);

                    if (!forType.equals(ftn)) {
                        // Check to see if we're doing return type 'Object' on a foreign type.
                        if (!forType.equals(JavaTypeName.OBJECT) || ftn instanceof JavaTypeName.Primitive) {
                            continue;
                        }
                    }
                }

                JavaExpression jf;
                if (fieldStrictness[i] && SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
                    jf = new JavaField.Instance (null, javaFieldNames[i], SCJavaDefn.typeExprToTypeName(fieldTypes[i]));
                    if (forType == null) {
                        jf = SCJavaDefn.boxExpression(fieldTypes[i], jf);
                    }
                } else {
                    // We have a non-strict field of type RTValue.  In order to reduce space usage
                    // we want to update the field value to be the result of the original suspension.
                    // We do this by using the field accessor function get_fieldName().
                    jf = new MethodInvocation.Instance(null, "get" + javaFieldNames[i], JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
                    if (forType != null) {
                        jf = SCJavaDefn.unboxValue(forType, jf);
                    }
                }

                SwitchStatement.IntCaseGroup iCase = new SwitchStatement.IntCaseGroup(i, new ReturnStatement (jf));
                sw.addCase(iCase);
                nReturnedFields++;

            }

            methodBodyBlock.addStatement (sw);

            MethodInvocation error =
                new MethodInvocation.Instance(
                        null,
                        "badFieldIndexInGetFieldByIndex",
                        METHODVAR_FIELDINDEX,
                        JavaTypeName.INT,
View Full Code Here


         * adds the appropriate code to augment the statistics.
         * @param javaCons
         */
        private void addStatsBlock(JavaConstructor javaCons) {
            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);
                javaCons.addStatement(new ExpressionStatement(mi));
            }

        }
View Full Code Here

            }

            // Check for a static invocation.
            if (returnValue instanceof MethodInvocation) {

                MethodInvocation mis = (MethodInvocation)returnValue;
                boolean isStatic = mis instanceof MethodInvocation.Static;
                final JavaTypeName invocationClass;
                if (isStatic) {
                    invocationClass = ((MethodInvocation.Static)mis).getInvocationClass();
                } else {
                    invocationClass = JavaTypeNames.RTVALUE;
                }


                // If this return value is a call to one of the error functions
                // we can treat it as returning an unboxed value since we know it
                // will actually throw an exception.  So we check if the returnValue
                // is an invocation of RTValue.badValue or RTValue.errorCall
                if (invocationClass.equals(JavaTypeNames.RTVALUE) &&
                    (mis.getMethodName().equals("errorCall") ||
                     mis.getMethodName().equals("badValue") ||
                     mis.getMethodName().equals("badSwitchIndex"))) {
                    // We need to create new MethodInvocation instances which will
                    // invoke the type specific version of 'errorCall'.
                    JavaTypeName[] argTypes;
                    JavaExpression[] argValues;

                    if (mis.getMethodName().equals("badSwitchIndex")) {
                        argTypes = new JavaTypeName[]{JavaTypeName.ERRORINFO};
                        argValues = new JavaExpression[]{mis.getArg(0)};
                    } else {
                        argTypes = new JavaTypeName[]{JavaTypeName.ERRORINFO, JavaTypeName.STRING};
                        argValues = new JavaExpression[2];
                        if (mis.getNArgs() == 1) {
                            argValues[0] = LiteralWrapper.NULL;
                            argValues[1] = mis.getArg(0);
                        } else {
                            argValues[0] = mis.getArg(0);
                            argValues[1] = mis.getArg(1);
                        }
                    }

                    boolean cast = false;
                    JavaTypeName callReturnType = resultTypeName;
                    String staticFunctionName = mis.getMethodName();
                    if (resultTypeName.equals(JavaTypeName.BOOLEAN)) {
                        staticFunctionName = staticFunctionName + "_boolean";
                    } else if (resultTypeName.equals(JavaTypeName.BYTE)) {
                        staticFunctionName = staticFunctionName + "_byte";
                    } else if (resultTypeName.equals(JavaTypeName.CHAR)) {
View Full Code Here

        recordSelectionBlock.addStatement(recordExprContextPair.getContextBlock());

        //the compiler ensures that evaluating recordExpr will result in a RTRecordValue.
        javaRecordExpr = new CastExpression(JavaTypeNames.RTRECORD_VALUE, javaRecordExpr);

        MethodInvocation getValueInvocation;
        if (fieldName instanceof FieldName.Textual) {
            getValueInvocation = new MethodInvocation.Instance(javaRecordExpr, "getTextualFieldValue",
                LiteralWrapper.make(fieldName.getCalSourceForm()), JavaTypeName.STRING,
                JavaTypeNames.RTVALUE, InvocationType.VIRTUAL);
        } else {
View Full Code Here

            jErrorInfo = getErrorInfo (errorInfo);
        } else {
            jErrorInfo = LiteralWrapper.NULL;
        }

        MethodInvocation mi =
            new MethodInvocation.Instance (null,
                                           "badSwitchIndex",
                                           jErrorInfo,
                                           JavaTypeName.ERRORINFO,
                                           JavaTypeNames.RTVALUE,
View Full Code Here

            jErrorInfo = getErrorInfo (errorInfo);
        } else {
            jErrorInfo = LiteralWrapper.NULL;
        }

        MethodInvocation mi =
            new MethodInvocation.Instance(null,
                "unhandledSwitchIndexForIntPattern",
                jErrorInfo,
                JavaTypeName.ERRORINFO,
                JavaTypeNames.RTVALUE,
View Full Code Here

            jErrorInfo = getErrorInfo (errorInfo);
        } else {
            jErrorInfo = LiteralWrapper.NULL;
        }

        MethodInvocation mi =
            new MethodInvocation.Instance(null,
                "unhandledSwitchIndexForCharPattern",
                jErrorInfo,
                JavaTypeName.ERRORINFO,
                JavaTypeNames.RTVALUE,
View Full Code Here

        // Preflight: must have >0 alts.
        if (alts.length <= 0) {
            // This can happen if a user creates a CAL Class that
            // has no instance methods.
            // We simply generate an error call.
            MethodInvocation errorCall =
                new MethodInvocation.Instance(null,
                                              "unhandledSwitchIndex",
                                              new JavaExpression[]{getErrorInfo(eswitch.getErrorInfo()), LiteralWrapper.make("any value")},
                                              new JavaTypeName[]{JavaTypeName.ERRORINFO, JavaTypeName.STRING},
                                              JavaTypeNames.RTVALUE,
View Full Code Here

            final String dataConsName = typeCons.getNthDataConstructor(tag).getName().getQualifiedName();

            altBody.addStatement (new JavaStatement.LineComment(dataConsName));

            // We generate a call to unhandledSwitchIndex with the data cons name appearing as a string literal.
            final MethodInvocation errorCall =
                new MethodInvocation.Instance(null,
                                              "unhandledSwitchIndex",
                                              new JavaExpression[]{getErrorInfo(eSwitch.getErrorInfo()), LiteralWrapper.make(dataConsName)},
                                              new JavaTypeName[]{JavaTypeName.ERRORINFO, JavaTypeName.STRING},
                                              JavaTypeNames.RTVALUE,
View Full Code Here

            args[args.length-1] = SCJavaDefn.EXECUTION_CONTEXT_VAR;
            JavaTypeName[] argTypes = new JavaTypeName[chain.length];
            Arrays.fill(argTypes, JavaTypeNames.RTVALUE);
            argTypes[argTypes.length-1] = JavaTypeNames.RTEXECUTION_CONTEXT;
            JavaExpression root = je[0];
            MethodInvocation fL = new MethodInvocation.Instance(root, "f" + (chain.length-1) + "L", args, argTypes, JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
            MethodInvocation eval = SCJavaDefn.createInvocation(fL, SCJavaDefn.EVALUATE, EXECUTION_CONTEXT_VAR);
            return new ExpressionContextPair(eval, newContext);
        }

        // Now we want to build the application chain. (As efficiently as possible).
        int nApplicationArguments = chain.length - 1;
View Full Code Here

TOP

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

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.