Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.TypeConsApp


                // we can simply use the field accessor.  Otherwise we need to apply output to
                // resulting value.
                TypeExpr fieldTypeExpr = dcFieldTypeExprs[i];
                updateInputableImports(fieldTypeExpr);
                String dcFieldTypeConsName = "";
                TypeConsApp typeConsApp = fieldTypeExpr.rootTypeConsApp();
                if (typeConsApp != null) {
                    TypeConstructor tc = typeConsApp.getRoot();
                    dcFieldTypeConsName = tc.getName().toString();
                }

                String constructorArgTypeConsName = ((TypeExprDefn.TypeCons)argTypes[i]).getTypeConsName().toString();
View Full Code Here


     */
    @Override
    public ValueNode transmuteValueNode(ValueNodeBuilderHelper valueNodeBuilderHelper, ValueNodeTransformer valueNodeTransformer, TypeExpr newTypeExpr) {

        QualifiedName typeConsName = getTypeExpr().rootTypeConsApp().getName();
        TypeConsApp newTypeConsApp = newTypeExpr.rootTypeConsApp();

        // If we don't need to change type constructors, then we just basically copy the value.
        if (newTypeConsApp != null && typeConsName.equals(newTypeConsApp.getName())) {

            List<ValueNode> componentList = getChildrenList();
            List<ValueNode> newComponentList = new ArrayList<ValueNode>(componentList.size());
   
            // Go thru the component ValueNodes and transmute them.
View Full Code Here

         */
        @Override
        public DataConstructorValueNode getNodeInstance(Object value, DataConstructor dataConstructor, TypeExpr typeExpr) {
           
            // Check for handleability.
            TypeConsApp typeConsApp = typeExpr.rootTypeConsApp();
            if (typeConsApp == null || typeConsApp.isFunctionType()) {
                return null;
            }
           
            // Check visibility of the type.. (should we do this?)
            Perspective perspective = getValueNodeBuilderHelper().getPerspective();
            if (perspective.getTypeConstructor(typeConsApp.getName()) == null) {
                return null;
            }
           
            if (dataConstructor == null) {
                // No data constructor provided - we have to pick one, and create a default value.
               
                // If the perspective's working module has changed, the typeExprToNodeMap is no longer valid.
                if (perspective.getWorkingModule() != workingModule) {
                    workingModule = perspective.getWorkingModule();
                    typeExprToNodeMap.clear();
                }
               
                // TODOEL: ~HACK - we use the string-ified value as a key because we want it equals() in the map.
                String typeExprString = typeExpr.toString();
           
                // First, check if we've previously created a value node for this expression.
                if (typeExprToNodeMap.containsKey(typeExprString)) {

                    // We've already found a value node for this type, so just return it.
                    // If we're currently in the process of finding a value node for it, then this
                    // will end up returning null. That's ok since it indicates to the caller that
                    // there is a cycle.
                    DataConstructorValueNode valueNode = typeExprToNodeMap.get(typeExprString);
                    return valueNode != null ? valueNode.copyValueNode(typeExpr) : null;
               
                } else {
                    // Add a signal that we are building a value node for this type.
                    typeExprToNodeMap.put(typeExprString, null);
                }
               
                // Iterate over the visible data constructors.
                DataConstructor[] dataConsArray = perspective.getDataConstructorsForType(typeConsApp.getName());
               
                if (dataConsArray != null) {

                    for (final DataConstructor element : dataConsArray) {

View Full Code Here

                updateInputableImports(fieldTypeExpr);
               
                TypeExprDefn fieldTypeForGetter = getTypeExprDefn(new JavaTypeName[]{fieldType});
                String fieldTypeForGetterTypeConsName = ((TypeExprDefn.TypeCons)fieldTypeForGetter).getTypeConsName().toString();
                String dcFieldTypeConsName = "";
                TypeConsApp typeConsApp = fieldTypeExpr.rootTypeConsApp();
                if (typeConsApp != null) {
                    TypeConstructor tc = typeConsApp.getRoot();
                    dcFieldTypeConsName = tc.getName().toString();
                }
               
                if (!fieldTypeForGetterTypeConsName.equals(dcFieldTypeConsName)) {
                    // apply input and usafe coerce.
View Full Code Here

           
            return codomain;
        }
       
        private final void updateInputableImports (TypeExpr typeExpr) {
            TypeConsApp tca = typeExpr.rootTypeConsApp();
            if (tca != null) {
                for (int i = 0, n = tca.getNArgs(); i < n; ++i) {
                    updateInputableImports(tca.getArg(i));
                }
            }
           
            if (typeExpr.isListType()) {
                if (typeExpr.rootTypeConsApp() == null) {
                    ((TypeApp)typeExpr).getOperandType();
                }
            } else if (typeExpr.isTupleType()) {
                RecordType rt = (RecordType)typeExpr;
                Map<FieldName, TypeExpr> hasFieldsMap = rt.getHasFieldsMap();
                for (Iterator<TypeExpr> it = hasFieldsMap.values().iterator(); it.hasNext();) {
                    updateInputableImports(it.next());
                }
            } else if (!typeExpr.isFunctionType()) {
                if (tca != null) {
                    TypeConstructor tc = tca.getRoot();
                    // Ignore functions
                    ModuleTypeInfo m = findModuleWithClassInstance(CAL_Prelude.TypeClasses.Inputable, tc.getName());
                    if (m != null) {
                        inputableImports.add(m.getModuleName());
                    } else if (!tc.getName().getModuleName().equals(module.getModuleName())){
View Full Code Here

            for (int i = 0, n = module.getNClassInstances(); i < n; ++i) {
                ClassInstance ci = module.getNthClassInstance(i);
                if (ci.getTypeClass().getName().equals(className)) {
                    // Check the instance type
                    TypeExpr instanceTypeExpr = ci.getType();
                    TypeConsApp tca = instanceTypeExpr.rootTypeConsApp();
                    if (tca != null) {
                        if (tca.getRoot().getName().equals(typeConstructorName)) {
                            return module;
                        }
                    }
                }
            }
View Full Code Here

     * @param typeExprParam the type expression of this value node. Must be a foreign type.
     */
    public ForeignValueNode(Object foreignValue, TypeExpr typeExprParam) {
        super(foreignValue, typeExprParam);
       
        TypeConsApp typeConsApp = typeExprParam.rootTypeConsApp();
        if (typeConsApp == null || !typeConsApp.usesForeignType()) {
            throw new IllegalArgumentException("type expression is not a foreign type: " + typeExprParam);
        }
    }
View Full Code Here

         */
        @Override
        public ForeignValueNode getNodeInstance(Object value, DataConstructor dataConstructor, TypeExpr typeExpr) {
           
            // Check for handleability.
            TypeConsApp typeConsApp = typeExpr.rootTypeConsApp();
            TypeConstructor typeCons = typeConsApp != null ? getPerspective().getTypeConstructor(typeConsApp.getName())
                                                                    : null;
           
            if (typeCons == null || typeCons.getForeignTypeInfo() == null) {
                return null;
            }
View Full Code Here

     * @param analyzeTypeExpr
     */
    private static TypeExpr getElementTypeExpr(TypeExpr analyzeTypeExpr) {

        // It doesn't matter the componentNumber (Elements of a list are homogeneous).
        TypeConsApp typeConsApp = analyzeTypeExpr.rootTypeConsApp();
               
        return typeConsApp.getArg(0);
    }
View Full Code Here

    static private boolean canTypeBeUnboxed (TypeExpr typeExpr) throws UnableToResolveForeignEntityException {
        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) {
                ForeignTypeInfo fti = typeConsApp.getForeignTypeInfo();
                Class<?> foreignClass = fti.getForeignType();
                if(foreignClass.isPrimitive() && foreignClass != void.class) {
                    return true;
                }
               
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.