Package org.openquark.cal.internal.javamodel

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


                }

                // Add inner classes for the data constructors.
                for (final DataConstructor dc : dataConsList) {
                    if (dc.getArity() > 0 || !createdTagDC) {
                        JavaClassRep dataConsClassRep = (new DataConsDefinitionBuilder(dc, className, commonFieldNames, module)).generateDataConsDefinition();
                        javaClassRep.addInnerClass(dataConsClassRep);
                    }
                }
            }
View Full Code Here


            JavaTypeName superClassTypeName = JavaTypeNames.RTCONS;

            // No interfaces are implemented
            JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;

            this.javaClassRep = new JavaClassRep(className, superClassTypeName, classModifiers, interfaces);

            // If there is more than one zero arity data constructor in this data type
            // we create a derived class called TagDC which holds an int tag field to
            // indicate which data constructor it corresponds to.  We than create a single instance
            // of this class for each of the zero arity data constructors.  This avoids
View Full Code Here

            // No interfaces are implemented
            JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;

            // Now instantiate the java class representation.
            JavaTypeName tagDCTypeName = CALToJavaNames.createTypeNameForTagDCFromType(typeConstructor, module);
            JavaClassRep tagDCClassRep = new JavaClassRep(tagDCTypeName, className, classModifiers, interfaces);

            // Add the body of the class.

            // private final int tag;
            JavaFieldDeclaration tagField = new JavaFieldDeclaration (Modifier.PRIVATE | Modifier.FINAL, JavaTypeName.INT, "tag", null);
            tagDCClassRep.addFieldDeclaration(tagField);

            // public TagDC(int tagVal) {this.tag = tagVal;}
            JavaConstructor javaConstructor = new JavaConstructor(Modifier.PUBLIC, new String[]{"tagVal"}, new JavaTypeName[]{JavaTypeName.INT}, "TagDC");
            tagDCClassRep.addConstructor(javaConstructor);
            Assignment tagAssign = new Assignment (new JavaField.Instance(null, "tag", JavaTypeName.INT), METHODVAR_TAGVAL);
            javaConstructor.addStatement(new ExpressionStatement(tagAssign));



            // public final int getArity() {return 0;}
            int modifiers = Modifier.PUBLIC | Modifier.FINAL;
            JavaTypeName returnType = JavaTypeName.INT;
            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, "getArity");
            tagDCClassRep.addMethod(javaMethod);
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make(Integer.valueOf(0))));

            // public final int getOrdinalValue(){return tag;}
            modifiers = Modifier.PUBLIC | Modifier.FINAL;
            returnType = JavaTypeName.INT;
            javaMethod = new JavaMethod(modifiers, returnType, "getOrdinalValue");
            tagDCClassRep.addMethod(javaMethod);
            javaMethod.addStatement(new ReturnStatement(new JavaField.Instance(null, "tag", JavaTypeName.INT)));

            // public final String getModuleName() ...
            modifiers = Modifier.PUBLIC | Modifier.FINAL;
            returnType = JavaTypeName.STRING;
            javaMethod = new JavaMethod(modifiers, returnType, "getModuleName");
            tagDCClassRep.addMethod(javaMethod);
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make (typeConstructor.getName().getModuleName().toSourceText())));

            // public final String getUnqualifiedName() ...
            modifiers = Modifier.PUBLIC | Modifier.FINAL;
            returnType = JavaTypeName.STRING;
            javaMethod = new JavaMethod(modifiers, returnType, "getUnqualifiedName");
            tagDCClassRep.addMethod(javaMethod);
            SwitchStatement sw = new SwitchStatement (new JavaField.Instance(null, "tag", JavaTypeName.INT));
            for (int i = 0, nDCs = dataConsList.size(); i < nDCs; ++i) {
                DataConstructor dc = dataConsList.get (i);
                sw.addCase(new SwitchStatement.IntCaseGroup(dc.getOrdinal(), new ReturnStatement (LiteralWrapper.make(dc.getName().getUnqualifiedName()))));
            }
            javaMethod.addStatement (sw);
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make ("Unknown data constructor")));

            // public final String getQualfiedName() ...
            modifiers = Modifier.PUBLIC | Modifier.FINAL;
            returnType = JavaTypeName.STRING;
            javaMethod = new JavaMethod(modifiers, returnType, "getQualifiedName");
            tagDCClassRep.addMethod(javaMethod);
            sw = new SwitchStatement (new JavaField.Instance(null, "tag", JavaTypeName.INT));
            for (int i = 0, nDCs = dataConsList.size(); i < nDCs; ++i) {
                DataConstructor dc = dataConsList.get (i);
                sw.addCase(new SwitchStatement.IntCaseGroup(dc.getOrdinal(), new ReturnStatement (LiteralWrapper.make(dc.getName().getQualifiedName()))));
            }
View Full Code Here

                // No interfaces are implemented
                JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;

                // Now instantiate the java class representation.
                this.javaClassRep = new JavaClassRep(className, superClassTypeName, classModifiers, interfaces);

                SCJavaDefn.SharedValues sharedValues = new SCJavaDefn.SharedValues();

                // Build up a list of SCJavaDefn instances, once for each CAL function.
                // We call genS_SC_Boxed() to force the population of the SharedValues
View Full Code Here

            JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;

            JavaTypeName strictAppTypeName = CALToJavaNames.createStrictInnerTypeNameFromSC(mf.getQualifiedName(), module);

            // Now instantiate the java class representation.
            JavaClassRep strictAppClassRep = new JavaClassRep(strictAppTypeName, superClassTypeName, classModifiers, interfaces);

            //add the function field, which is a reference to the function singleton.
            JavaFieldDeclaration functionFieldDec = new JavaFieldDeclaration (Modifier.PRIVATE | Modifier.FINAL, className, "function", null);
            strictAppClassRep.addFieldDeclaration(functionFieldDec);
            JavaField functionField = new JavaField.Instance (null, "function", className);

            // This class has a member field for each argument to the SC.
            JavaField[] functionArgumentMemberFields = new JavaField [mf.getArity()];
            for (int i = 0; i < mf.getArity(); ++i) {
                JavaFieldDeclaration fieldDec;
                JavaField field;
                String fieldName = CALToJavaNames.fixupVarName(mf.getParameterNames()[i]);
                if (mf.getParameterStrictness()[i] && SCJavaDefn.canTypeBeUnboxed(mf.getParameterTypes()[i])) {
                    fieldDec = new JavaFieldDeclaration (Modifier.PRIVATE, SCJavaDefn.typeExprToTypeName(mf.getParameterTypes()[i]), fieldName, null);
                    field = new JavaField.Instance (null, fieldName, SCJavaDefn.typeExprToTypeName(mf.getParameterTypes()[i]));
                } else {
                    fieldDec = new JavaFieldDeclaration (Modifier.PRIVATE, JavaTypeNames.RTVALUE, fieldName, null);
                    field = new JavaField.Instance (null, fieldName, JavaTypeNames.RTVALUE);
                }
                strictAppClassRep.addFieldDeclaration(fieldDec);
                functionArgumentMemberFields[i] = field;
            }

            // Add the constructor
            strictAppClassRep.addConstructor(createStrictAppClass_constructor(mf, functionField, functionArgumentMemberFields));

            // Add the reduce method.
            strictAppClassRep.addMethod(createStrictAppClass_method_reduce(mf, functionField, strictAppTypeName, functionArgumentMemberFields));

            // Add the clearMembers() method.
            JavaMethod clearMembers = new JavaMethod (Modifier.PUBLIC | Modifier.FINAL, JavaTypeName.VOID, "clearMembers");
            //the line "function = null;" should not be added to clearMembers. function is a reference to a singleton
            //so that clearing it doesn't actually free any memory. However, not clearing it means that the the method
            //debug_getNodeStartText works as desired even in the case when result == null and clearMembers() has been called.
            //clearMembers.addStatement(new ExpressionStatement(new Assignment(functionField, LiteralWrapper.NULL)));
            for (int i = 0; i < functionArgumentMemberFields.length; ++i) {
                if (!mf.getParameterStrictness()[i] || !SCJavaDefn.canTypeBeUnboxed(mf.getParameterTypes()[i])) {
                    Assignment a = new Assignment(functionArgumentMemberFields[i], LiteralWrapper.NULL);
                    clearMembers.addStatement(new ExpressionStatement(a));
                }
            }
            strictAppClassRep.addMethod (clearMembers);

            createAppClass_debugMethods(strictAppClassRep, functionArgumentMemberFields);

            // We need to mark this class as containing assertions.
            // This is done manually because we don't always
            // generate the inner classes at the same time
            // as the containing class.
            strictAppClassRep.setContainsAssertions();

            return strictAppClassRep;
        }
View Full Code Here

            JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;

            JavaTypeName lazyAppTypeName = CALToJavaNames.createLazyInnerTypeNameFromSC(mf.getQualifiedName(), module);

            // Now instantiate the java class representation.
            JavaClassRep lazyAppClassRep = new JavaClassRep(lazyAppTypeName, superClassTypeName, classModifiers, interfaces);

            //add the function field, which is a reference to the function singleton.
            JavaFieldDeclaration functionFieldDec = new JavaFieldDeclaration (Modifier.PRIVATE | Modifier.FINAL, className, "function", null);
            lazyAppClassRep.addFieldDeclaration(functionFieldDec);
            JavaField functionField = new JavaField.Instance (null, "function", className);

            // This class has a member field for each argument to the SC.
            JavaField[] functionArgumentMemberFields = new JavaField [mf.getArity()];
            for (int i = 0; i < mf.getArity(); ++i) {
                JavaFieldDeclaration fieldDec;
                JavaField field;
                String fieldName = CALToJavaNames.fixupVarName(mf.getParameterNames()[i]);
                fieldDec = new JavaFieldDeclaration (Modifier.PRIVATE, JavaTypeNames.RTVALUE, fieldName, null);
                field = new JavaField.Instance (null, fieldName, JavaTypeNames.RTVALUE);
                lazyAppClassRep.addFieldDeclaration(fieldDec);
                functionArgumentMemberFields[i] = field;
            }

            // Add the constructor.
            lazyAppClassRep.addConstructor(createLazyAppClass_constructor(mf, functionField, functionArgumentMemberFields));

            // Add the reduce method.
            lazyAppClassRep.addMethod(createLazyAppClass_method_reduce(mf, functionField, lazyAppTypeName, functionArgumentMemberFields));

            // Add the clearMembers() method.
            JavaMethod clearMembers = new JavaMethod (Modifier.PUBLIC | Modifier.FINAL, JavaTypeName.VOID, "clearMembers");
            //the line "function = null;" should not be added to clearMembers. function is a reference to a singleton
            //so that clearing it doesn't actually free any memory. However, not clearing it means that the the method
            //debug_getNodeStartText works as desired even in the case when result == null and clearMembers() has been called.
            //clearMembers.addStatement(new ExpressionStatement(new Assignment(functionField, LiteralWrapper.NULL)));
            for (int i = 0; i < functionArgumentMemberFields.length; ++i) {
                Assignment a = new Assignment(functionArgumentMemberFields[i], LiteralWrapper.NULL);
                clearMembers.addStatement(new ExpressionStatement(a));
            }
            lazyAppClassRep.addMethod (clearMembers);

            createAppClass_debugMethods(lazyAppClassRep, functionArgumentMemberFields);

            // We need to mark this class as containing assertions.
            // This is done manually because we don't always
            // generate the inner classes at the same time
            // as the containing class.
            lazyAppClassRep.setContainsAssertions();

            return lazyAppClassRep;
        }
View Full Code Here

    @Override
    void createFunction(FunctionGroupInfo functionGroupInfo, boolean forceWrite, CompilerMessageLogger logger)
            throws CodeGenerationException {
        if (forceWrite) {
            // Get the sc definition.
            JavaClassRep classRep = JavaDefinitionBuilder.getSCDefinition(functionGroupInfo, module, getCodeGenerationStats());
           
            // Generate and write classes.
            writeClassWithInnerClasses(classRep, logger);
           
            informStatusListeners(StatusListener.SM_ENTITY_GENERATED_FILE_WRITTEN, functionGroupInfo.getFunctionGroupName());
View Full Code Here

    void createTypeDefinition(TypeConstructor typeConstructor,
            boolean forceWrite, CompilerMessageLogger logger) throws CodeGenerationException {
        // Write out the bytecode for the type constructor and associated data constructors.
        if (forceWrite) {
            // Get the data type definition.
            JavaClassRep classRep = JavaDefinitionBuilder.getDataTypeDefinition(typeConstructor, module, getCodeGenerationStats());
           
            // Generate and write classes.
            writeClassWithInnerClasses(classRep, logger);
           
            for (int j = 0; j <= typeConstructor.getNDataConstructors(); ++j) {
View Full Code Here

        try {
            byte[] bytecode = AsmJavaBytecodeGenerator.encodeClass(classRep);
            writeClass(classRep, bytecode, logger);
           
            for (int i = 0, nInnerClasses = classRep.getNInnerClasses(); i < nInnerClasses; ++i) {
                JavaClassRep innerClassRep = classRep.getInnerClass(i);
                writeClassWithInnerClasses(innerClassRep, logger);
            }       
        } catch (JavaGenerationException e) {
            throw new CodeGenerationException(e.getLocalizedMessage(), e);
        }
View Full Code Here

     * @param unqualifiedClassName the name of the class representing the entity.
     * @return the class data, or null if the name is not the name of a class representing an entity generated in this module.
     * @throws CodeGenerationException
     */
    static byte[] generateClassData(LECCModule module, String unqualifiedClassName) throws CodeGenerationException {
        JavaClassRep classRep = JavaDefinitionBuilder.getClassRep(module, unqualifiedClassName);
        if (classRep == null) {
            return null;
        }
        try {
            byte[] bytecode = AsmJavaBytecodeGenerator.encodeClass(classRep);
            if (DEBUG_GENERATED_BYTECODE) {
                debugGeneratedBytecode(classRep.getClassName(), bytecode);
            }
           
            return bytecode;
        } catch (JavaGenerationException e) {
            throw new CodeGenerationException(e.getLocalizedMessage(), e);
View Full Code Here

TOP

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

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.