Package org.openquark.cal.internal.javamodel

Examples of org.openquark.cal.internal.javamodel.JavaMethod


                    }
                    JavaTypeName fieldType = (JavaTypeName)dcInfo.fieldTypeNames.get(fieldName);
                    String javaFieldName = (String)typeConstructorInfo.fieldJavaNames.get(fieldName);
                   
                    String accessorName = (String)typeConstructorInfo.fieldJavaAccessorMethodNames.get(fieldName);
                    JavaMethod getter = createMethod_getField(accessorName, javaFieldName, fieldType, true);
                   
                    dcClass.addMethod(getter);
                }
   
                dcClass.addMethod(createMethod_getDCOrdinal(dc.getOrdinal()));
View Full Code Here


            }
           
            private final JavaMethod createMethod_getDCOrdinal(int ordinal) {
               
                JavaMethod javaMethod = new JavaMethod(Modifier.PUBLIC, JavaTypeName.INT, GET_DC_ORDINAL_METHOD_NAME);
                // return dc ordinal.
                javaMethod.addStatement (new ReturnStatement(LiteralWrapper.make (new Integer (ordinal))));

                JavaDocComment jdc =
                    new JavaDocComment ("@return the ordinal of this instance of " + typeConstructorInfo.javaClassName);
                javaMethod.setJavaDocComment(jdc);

                return javaMethod;
            }
View Full Code Here

                return javaMethod;
            }
           
            private final JavaMethod createMethod_getDCName(String dcName) {
                int modifiers = Modifier.PUBLIC | Modifier.FINAL;
                JavaMethod javaMethod = new JavaMethod(modifiers, JavaTypeName.STRING, GET_DC_NAME_METHOD_NAME);
               
                javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make(dcName)));

                JavaDocComment jdc =
                    new JavaDocComment ("@return the name of the data constructor corresponding to this instance of " + typeConstructorInfo.javaClassName);
                javaMethod.setJavaDocComment(jdc);

                return javaMethod;
           
View Full Code Here

         * @return the getFieldNameByOrdinal() method.
         */
        private JavaMethod createDCFieldSelectionClass_method_getFieldNameByOrdinal () {

            int modifiers = Modifier.PROTECTED | Modifier.FINAL;
            JavaMethod javaMethod = new JavaMethod (modifiers, JavaTypeName.STRING, "ordinal", JavaTypeName.INT, false, "getFieldNameByOrdinal");
            SwitchStatement sw = new SwitchStatement (METHODVAR_ORDINAL);
            for (int i = 0, nFields = dc.getArity(); i < nFields; ++i) {
                String fieldName = dc.getNthFieldName(i).toString();
                sw.addCase(new SwitchStatement.IntCaseGroup(i, new ReturnStatement(LiteralWrapper.make(fieldName))));
            }

            javaMethod.addStatement(sw);

            JavaExpression exception =
                new JavaExpression.ClassInstanceCreationExpression(JavaTypeName.INDEX_OUT_OF_BOUNDS_EXCEPTION);
            JavaStatement s =
                new JavaStatement.ThrowStatement (exception);
            javaMethod.addStatement(s);
            return javaMethod;
        }
View Full Code Here

            return javaMethod;
        }

        private JavaMethod createDCFieldSelectionClass_method_getDCName () {
            int modifiers = Modifier.PROTECTED | Modifier.FINAL;
            JavaMethod javaMethod = new JavaMethod (modifiers, JavaTypeName.STRING, "getDCName");

            javaMethod.addStatement(new ReturnStatement (JavaExpression.LiteralWrapper.make (dc.getName().getQualifiedName())));
            return javaMethod;
        }
View Full Code Here

        private void createMethod_getArity() {
            int modifiers = Modifier.PUBLIC | Modifier.FINAL;
            JavaTypeName returnType = JavaTypeName.INT;

            // Add the method to the class.
            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, "getArity");
            javaClassRep.addMethod(javaMethod);

            // Add the body..
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make(Integer.valueOf(dc.getArity()))));

            //LiteralWrapper zeroWrapper = LiteralWrapper.make(JavaPrimitives.makeInteger(0));
//            if (arity == 0) {
                // return 0;
//                javaMethod.addStatement(new ReturnStatement(zeroWrapper));
View Full Code Here

        private void createMethod_getOrdinalValue() {
            int modifiers = Modifier.PUBLIC;
            JavaTypeName returnType = JavaTypeName.INT;

            // Add the method to the class.
            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, "getOrdinalValue");
            javaClassRep.addMethod(javaMethod);

            // Add the body..
            // return (ordinal);
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make(Integer.valueOf(dc.getOrdinal()))));
        }
View Full Code Here

        private void createMethod_make() {
            int modifiers = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
            JavaTypeName returnType = className;

            // Add the method to the class.
            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, "make");
            javaClassRep.addMethod(javaMethod);

            // Add the body..
            // The no argument version of make should only be called for an instance to
            // be used as a supercombinator so we can return the singleton instance.
            JavaField selfField = new JavaField.Static(className, instanceName, className);
            javaMethod.addStatement(new ReturnStatement(selfField));

        }
View Full Code Here

            final int modifiers = Modifier.PUBLIC | Modifier.FINAL;
            final JavaTypeName returnType = JavaTypeNames.RTVALUE;

            // Add the method to the class.
            final JavaMethod javaMethod = new JavaMethod(
                modifiers,
                returnType,
                new String [] {ROOT_NODE, SCJavaDefn.EXECUTION_CONTEXT_NAME},
                new JavaTypeName[]{JavaTypeNames.RTRESULT_FUNCTION, JavaTypeNames.RTEXECUTION_CONTEXT},
                new boolean[] {true, true},
                "f");
            javaClassRep.addMethod(javaMethod);

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

            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,
                                         "dcFunctionCalled",
                                         args,
                                         argTypes,
                                         JavaTypeName.VOID,
                                         MethodInvocation.InvocationType.VIRTUAL);
                javaMethod.addStatement(new ExpressionStatement(mi));
            }

            // Add the body..
            final int arity = dc.getArity();
            if (arity > 0) {
                // // Arguments
                javaMethod.addStatement(new LineComment("Arguments"));

                final boolean addEC = LECCMachineConfiguration.passExecContextToDataConstructors();

                final int nConstructorArgs = addEC ? (arity + 1) : arity;

                // Get arg names
                final JavaExpression[] arguments = new JavaExpression[nConstructorArgs];
                for (int i = 0; i < arity; i++) {
                    final String localVarName = "$arg" + i;
                    arguments[i] = new LocalVariable(localVarName, JavaTypeNames.RTVALUE);
                }


                // final RTValue $arg_i = initializer;
                for (int i = arity - 1; i >= 0; i--) {

                    final JavaExpression initializer;

                    if (i == arity - 1) {
                        //$rootNode.getArgValue();
                        initializer = SCJavaDefn.createInvocation(METHODVAR_ROOT_NODE, SCJavaDefn.GETARGVALUE);

                    } else if (i == arity - 2) {

                        if (arity > 2) {
                            //RTValue $currentRootNode;
                            javaMethod.addStatement(new LocalVariableDeclaration(LOCALVAR_CURRENT_ROOT_NODE));
                            //($currentRootNode = $rootNode.prevArg()).getArgValue();
                            initializer =
                                SCJavaDefn.createInvocation(
                                    new Assignment(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.createInvocation(METHODVAR_ROOT_NODE, SCJavaDefn.PREVARG)),
                                    SCJavaDefn.GETARGVALUE);
                        } else {
                            //$rootNode.prevArg().getArgValue();
                            initializer =
                                SCJavaDefn.createInvocation(
                                    SCJavaDefn.createInvocation(METHODVAR_ROOT_NODE, SCJavaDefn.PREVARG),
                                    SCJavaDefn.GETARGVALUE);
                        }

                    } else if (i == 0) {

                        //$currentRootNode.prevArg().getArgValue();
                        initializer =
                            SCJavaDefn.createInvocation(
                                SCJavaDefn.createInvocation(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.PREVARG),
                                SCJavaDefn.GETARGVALUE);

                    } else {

                        //($currentRootNode = $currentRootNode.prevArg()).getArgValue();
                        initializer =
                            SCJavaDefn.createInvocation(
                                new Assignment(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.createInvocation(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.PREVARG)),
                                SCJavaDefn.GETARGVALUE);
                    }

                    final LocalVariableDeclaration argDeclaration =
                        new LocalVariableDeclaration((LocalVariable)arguments[i], initializer, !fieldStrictness[i]);

                    javaMethod.addStatement(argDeclaration);
                }

                // Get arg types - all RTValues.
                final JavaTypeName[] argTypes = new JavaTypeName[nConstructorArgs];
                Arrays.fill(argTypes, JavaTypeNames.RTVALUE);

                if (addEC) {
                    arguments[arguments.length - 1] = SCJavaDefn.EXECUTION_CONTEXT_VAR;
                    argTypes[argTypes.length - 1] = JavaTypeNames.RTEXECUTION_CONTEXT;
                }

                for (int i = 0; i < dc.getArity(); ++i) {
                    if (fieldStrictness[i]) {
                        arguments[i]= new MethodInvocation.Instance (arguments[i],
                                                            "evaluate",
                                                            SCJavaDefn.EXECUTION_CONTEXT_VAR,
                                                            JavaTypeNames.RTEXECUTION_CONTEXT,
                                                            JavaTypeNames.RTVALUE,
                                                            MethodInvocation.InvocationType.VIRTUAL);

                        if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
                            argTypes[i] = SCJavaDefn.typeExprToTypeName(fieldTypes[i]);
                            arguments[i] = SCJavaDefn.unboxValue(SCJavaDefn.typeExprToTypeName(fieldTypes[i]), arguments[i]);
                        }
                    }
                }

                // return new ThisClass($arg0, $arg1, ...);
                final JavaExpression cice = new ClassInstanceCreationExpression(className, arguments, argTypes);

                javaMethod.addStatement(new ReturnStatement(cice));
            } else {
                // return new ThisClass();
                final JavaExpression cice = new ClassInstanceCreationExpression(className, JavaExpression.LiteralWrapper.NULL, JavaTypeNames.RTEXECUTION_CONTEXT);
                javaMethod.addStatement(new ReturnStatement(cice));
            }
        }
View Full Code Here

             argTypes[argTypes.length - 1] = JavaTypeNames.RTEXECUTION_CONTEXT;
              argNames[argNames.length - 1] = SCJavaDefn.EXECUTION_CONTEXT_NAME;

            // Add the method to the class.
            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, argNames, argTypes, null, "f" + dc.getArity() + "L");
            javaClassRep.addMethod(javaMethod);

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

            if (LECCMachineConfiguration.generateCallCounts()) {
                JavaExpression args[] = new JavaExpression[2];
                JavaTypeName ccArgTypes[] = new JavaTypeName[2];
                args[0] = LiteralWrapper.make(dc.getName().getModuleName().toSourceText());
                args[1] = LiteralWrapper.make(dc.getName().getUnqualifiedName());
                ccArgTypes[0] = ccArgTypes[1] = JavaTypeName.STRING;
                MethodInvocation mi =
                    new MethodInvocation.Instance(SCJavaDefn.EXECUTION_CONTEXT_VAR,
                                         "dcFunctionCalled",
                                         args,
                                         ccArgTypes,
                                         JavaTypeName.VOID,
                                         MethodInvocation.InvocationType.VIRTUAL);

                javaMethod.addStatement(new ExpressionStatement(mi));
            }

            boolean addEC = LECCMachineConfiguration.passExecContextToDataConstructors();
            int nConstructorArgs = dc.getArity();
            if (addEC) {
                nConstructorArgs++;
            }

            JavaExpression constructorArgs[] = new JavaExpression [nConstructorArgs];
            JavaTypeName constructorArgTypes[] = new JavaTypeName [nConstructorArgs];
            System.arraycopy(argTypes, 0, constructorArgTypes, 0, constructorArgTypes.length);

            if (addEC) {
                constructorArgs[constructorArgs.length - 1] = SCJavaDefn.EXECUTION_CONTEXT_VAR;
            }

            for (int i = 0; i < dc.getArity(); ++i) {
                constructorArgs[i] = new MethodVariable("member" + i);
                if (fieldStrictness[i]) {
                    constructorArgs[i] = new MethodInvocation.Instance (constructorArgs[i],
                                                    "evaluate",
                                                    SCJavaDefn.EXECUTION_CONTEXT_VAR,
                                                    JavaTypeNames.RTEXECUTION_CONTEXT,
                                                    JavaTypeNames.RTVALUE,
                                                    MethodInvocation.InvocationType.VIRTUAL);

                    if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
                        constructorArgs[i] = SCJavaDefn.unboxValue(SCJavaDefn.typeExprToTypeName(fieldTypes[i]), constructorArgs[i]);
                        constructorArgTypes[i] = SCJavaDefn.typeExprToTypeName(fieldTypes[i]);
                    }
                }
            }

            JavaExpression cc = new ClassInstanceCreationExpression (className, constructorArgs, constructorArgTypes);

            javaMethod.addStatement(new ReturnStatement(cc));
        }
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaMethod

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.