Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.TypeConsApp


    static boolean canTypeBeUnboxed (TypeExpr typeExpr) throws CodeGenerationException {
        if (typeExpr == null) {
            return false;
        }

        TypeConsApp typeConsApp = typeExpr.rootTypeConsApp();
        if (typeConsApp != null && typeConsApp.getNArgs() == 0) {

            if (typeConsApp.isNonParametricType(CAL_Prelude.TypeConstructors.Boolean)) {
                return true;
            }

            if (typeConsApp.getForeignTypeInfo() != null && !isCalValueClass(SCJavaDefn.getForeignType(typeConsApp.getForeignTypeInfo()))) {
                return true;
            }

            if (LECCMachineConfiguration.TREAT_ENUMS_AS_INTS) {
                if (isEnumDataType (typeConsApp)) {
View Full Code Here


     *
     * @param typeExpr
     * @return true if the given type is an enumeration, according to the above definition.
     */
    static boolean isEnumDataType (TypeExpr typeExpr) {
        TypeConsApp typeConsApp = typeExpr.rootTypeConsApp();
        if (typeConsApp == null) {
            return false;
        }

        return TypeExpr.isEnumType(typeConsApp.getRoot());
    }
View Full Code Here

    /**
     * @param typeExpr
     * @return true if the data type is self referential
     */
    static private boolean isSelfReferentialDataType (TypeExpr typeExpr) {
        TypeConsApp typeConsApp = typeExpr.rootTypeConsApp();
        if (typeConsApp == null) {
            return false;
        }

        TypeConstructor typeCons = typeConsApp.getRoot();

        for (int i = 0, n = typeCons.getNDataConstructors(); i < n; ++i) {
            DataConstructor dc = typeCons.getNthDataConstructor(i);
            TypeExpr[] fieldTypes = SCJavaDefn.getFieldTypesForDC(dc);
            for (int j = 0, k = fieldTypes.length; j < k; ++j) {
                TypeExpr fieldType = fieldTypes[j];
                TypeConsApp fieldTc = fieldType.rootTypeConsApp();
                if (fieldTc != null &&
                    (typeConsApp.sameType(fieldTc) || fieldTc.getRoot().equals(typeCons))) {
                    return true;
                }
            }
        }

View Full Code Here

     * @param typeExpr
     * @return a JavaTypeName
     */
    static JavaTypeName typeExprToTypeName (TypeExpr typeExpr) throws CodeGenerationException {
        if (typeExpr != null) {
            TypeConsApp typeConsApp = typeExpr.rootTypeConsApp();
            if (typeConsApp != null) {

                if (typeConsApp.isNonParametricType(CAL_Prelude.TypeConstructors.Boolean)) {
                    return JavaTypeName.BOOLEAN;
                }

                if(typeConsApp.getForeignTypeInfo() != null) {
                    ForeignTypeInfo fti = typeConsApp.getForeignTypeInfo();
                    return JavaTypeName.make (SCJavaDefn.getForeignType(fti));
                }

                if (LECCMachineConfiguration.TREAT_ENUMS_AS_INTS) {
                    if (isEnumDataType (typeConsApp)) {
View Full Code Here

    static JavaExpression boxExpression (TypeExpr boxType, JavaExpression e) throws CodeGenerationException {
        if (boxType == null || e == null) {
            throw new CodeGenerationException ("Attempt to box null type. ");
        }

        TypeConsApp typeConsApp = boxType.rootTypeConsApp();

        if (typeConsApp != null) {

            if (typeConsApp.isNonParametricType(CAL_Prelude.TypeConstructors.Boolean)) {
                return boxExpression (JavaTypeName.BOOLEAN, e);
            }

            if (typeConsApp.getForeignTypeInfo() != null) {
                return boxExpression (JavaTypeName.make(SCJavaDefn.getForeignType(typeConsApp.getForeignTypeInfo())), e);
            }

            if (LECCMachineConfiguration.TREAT_ENUMS_AS_INTS) {
                if (SCJavaDefn.isEnumDataType (typeConsApp)) {
                    return boxExpression (JavaTypeName.INT, e);
View Full Code Here

                ClassInstance ci = module.getNthClassInstance(j);
                if (ci.getTypeClass().getName().equals(CAL_Prelude.TypeClasses.Inputable) ||
                    ci.getTypeClass().getName().equals(CAL_Prelude.TypeClasses.Outputable)) {
                    // Check the instance type
                    TypeExpr instanceTypeExpr = ci.getType();
                    TypeConsApp tca = instanceTypeExpr.rootTypeConsApp();
                    if (tca != null) {
                        if (tca.getRoot().getName().equals(tc.getName())) {
                            alreadyInputableOutputable = true;
                        }
                    }
                }
            }
View Full Code Here

        if (typeExpr != null) {
            if (typeExpr instanceof RecordType) {
                return JavaTypeName.make(java.util.List.class);
            }
           
            TypeConsApp typeConsApp = typeExpr.rootTypeConsApp();
            if (typeConsApp != null) {
           
                if (typeConsApp.isNonParametricType(CAL_Prelude.TypeConstructors.Boolean)) {
                    return JavaTypeName.BOOLEAN;
                }
                   
                if(typeConsApp.getForeignTypeInfo() != null) {
                    ForeignTypeInfo fti = typeConsApp.getForeignTypeInfo();
                    return JavaTypeName.make (fti.getForeignType());
                }

                TypeConstructor typeConstructor = typeConsApp.getRoot();

                JavaTypeName typeName = (JavaTypeName)typeToClassMappings.get(typeConstructor.getName());
                if (typeName != null) {
                    return typeName;
                }
View Full Code Here

               
                return "<html><body><b>Prelude Record</b></body></html>";
               
            } else if (listEntryData instanceof TypeConsApp) {
           
                TypeConsApp typeConsApp = (TypeConsApp) listEntryData;
                QualifiedName typeConsName = typeConsApp.getName();
               
                TypeConstructor typeCons = valueEditorManager.getPerspective().getTypeConstructor(typeConsName);
                return ToolTipHelpers.getEntityToolTip(typeCons, getNamingPolicy(), valueEditorManager.getWorkspace(), invoker);
               
            } else {
View Full Code Here

    }
   
    @Override
    public String getColumnName(int col) {
       
        TypeConsApp listTypeConsApp = ((TypeConsApp) getListValueNode().getTypeExpr());
       
        if (!consolidatedColumns && isListRecord()) {
           
            // Special case: if this is a list of records, use record field names as column names
            List<FieldName> fieldNames = listTypeConsApp.getArg(0).rootRecordType().getHasFieldNames();
           
            if (fieldNames.size() == 0) {
                return ValueEditorMessages.getString("VE_NoFieldsColumnName");
               
            } else {
View Full Code Here

     * @param col column index of element to retrieve type for
     * @return TypeExpr
     */
    @Override
    public TypeExpr getElementType (int col) {
        TypeConsApp listTypeConsApp = ((TypeConsApp) getListValueNode().getTypeExpr());
      
        if (!consolidatedColumns && isListRecord()) {
           
            //this handles the case of lists of tuples as well as lists of general records
           
            // Special case: in the case of a list of records, index the record fields alphabetically
            List<FieldName> fieldNames = listTypeConsApp.getArg(0).rootRecordType().getHasFieldNames();
           
            if (fieldNames.isEmpty()) {
                // Special case: record has no fields. The type of this column is the record type
                return ((TypeConsApp) getListValueNode().getTypeExpr()).getArg(0).rootRecordType();
            }
           
            return listTypeConsApp.getArg(0).rootRecordType().getHasFieldType(fieldNames.get(col));
           
        } else {
            return listTypeConsApp.getArg(col);
        }      
    }
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.TypeConsApp

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.