Package org.openquark.cal.internal.javamodel

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


         * This method returns the ordinal identifier of this data constructor.
         *      public int getOrdinalValue()  {return (ordinal);}
         */
        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);

View Full Code Here


         * Create the no-argument make() method
         *      public static final RTFunction make();
         */
        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);

View Full Code Here

         * @throws CodeGenerationException
         */
        private void createMethod_f() throws CodeGenerationException {

            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,
View Full Code Here

         * Create the fnL() method.
         * @throws CodeGenerationException
         */
        private void createMethod_fSaturatedLazy() throws CodeGenerationException {
            final int modifiers = Modifier.PUBLIC | Modifier.FINAL;
            final JavaTypeName returnType = JavaTypeNames.RTVALUE;

            final int nArgs = dc.getArity() + 1;

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

            // Figure out arg names.
            final String[] argNames = new String[nArgs];
            for (int i = 0; i < argNames.length; i++) {
                argNames[i] = "member" + i;
            }

             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;
            }
View Full Code Here

         * Create the isLogicalTrue() override method for the Prelude.False data constructor.
         *      public boolean isLogicalTrue() {return false;}
         */
        private void createMethod_isLogicalTrueOverrideFalse() {
            int modifiers = Modifier.PUBLIC;
            JavaTypeName returnType = JavaTypeName.BOOLEAN;

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

View Full Code Here

            if (commonFields.contains(dc.getNthFieldName(i))) {
                return;
            }

            int modifiers = Modifier.PUBLIC | Modifier.FINAL;
            JavaTypeName returnType = JavaTypeNames.RTVALUE;
            // Add the method to the class.
            String methodName = "get" + javaFieldNames[i];
            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, methodName);
            javaClassRep.addMethod(javaMethod);
View Full Code Here

                    // 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;
View Full Code Here

                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 {
                    javaFieldExpr = new JavaExpression.JavaField.Instance(null, javaFieldName, JavaTypeNames.RTVALUE);
                }
View Full Code Here

                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

            ////
            /// First generate the main classes (and their associated classes and resources)
            //
            for (final MainClassSpec spec : mainClassSpecs) {
               
                final JavaTypeName mainClassName = spec.getClassName();
                final QualifiedName entryPointName = spec.getEntryPointName();

                // Check the main class's configuration, and throw InvalidConfigurationException if there are problems
                checkMainClassConfiguration(entryPointName, workspaceManager);
               
                final ModuleName rootModule = entryPointName.getModuleName();

                ////
                /// Write out the main class and the generated classes required by the class.
                //
                final String mainClassRelativePath = mainClassName.getName().replace('.', '/') + ".class";
                final ZipEntry mainClassEntry = new ZipEntry(mainClassRelativePath);

                final byte[] mainClassBytecode;
                try {
                    final JavaClassRep mainClassRep = makeMainClass(mainClassName, entryPointName, workspaceManager);
                    mainClassBytecode = AsmJavaBytecodeGenerator.encodeClass(mainClassRep);
                   
                    // Write out the source for the class
                    final String javaFileRelativePath = mainClassName.getName().replace('.', '/') + ".java";
                    final ZipEntry javaFileEntry = new ZipEntry(javaFileRelativePath);
                    sourceGen.generateSource(javaFileEntry, mainClassRep);
                   
                    writeClassAndOtherRequiredClassesAndGatherResources(workspaceManager, jos, classesAlreadyAdded, sourcesAlreadyAdded, allRequredModules, rootModule, mainClassEntry, mainClassBytecode, sourceGen);
                   
                } catch (final JavaGenerationException e) {
                    // We should not have problems generating the main class - if there are any then it is an internal problem
                    throw new InternalProblemException(e);
                }
            }

            ////
            /// Then generate the library classes (and their associated classes and resources)
            //
            for (final LibraryClassSpec spec : libClassSpecs) {
               
                final JavaTypeName libClassName = spec.getClassName();
                final ModuleName libModuleName = spec.getModuleName();

                // Check the library class's configuration, and throw InvalidConfigurationException if there are problems
                checkLibraryClassConfiguration(libModuleName, workspaceManager);
               
                ////
                /// Write out the library class and the generated classes required by the class.
                //
                final String libClassRelativePath = libClassName.getName().replace('.', '/') + ".class";
                final ZipEntry libClassEntry = new ZipEntry(libClassRelativePath);

                final byte[] libClassBytecode;
                try {
                    final JavaClassRep libClassRep = makeLibraryClass(spec.getScope(), libClassName, libModuleName, workspaceManager, monitor);
                    libClassBytecode = AsmJavaBytecodeGenerator.encodeClass(libClassRep);
                   
                    // Write out the source for the class
                    final String javaFileRelativePath = libClassName.getName().replace('.', '/') + ".java";
                    final ZipEntry javaFileEntry = new ZipEntry(javaFileRelativePath);
                    sourceGen.generateSource(javaFileEntry, libClassRep);
                   
                    writeClassAndOtherRequiredClassesAndGatherResources(workspaceManager, jos, classesAlreadyAdded, sourcesAlreadyAdded, allRequredModules, libModuleName, libClassEntry, libClassBytecode, sourceGen);
                   
View Full Code Here

TOP

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

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.