Examples of DataConstructor


Examples of org.openquark.cal.compiler.DataConstructor

   
                JavaTypeName[] constructorArgTypes = new JavaTypeName[]{JavaTypeName.INT, JavaTypeName.STRING};
               
                // For each data constructor create a constant int field for the ordinal.
                for (int i = 0, n = typeConstructor.getNDataConstructors(); i < n; ++i) {
                    DataConstructor dc = typeConstructor.getNthDataConstructor(i);
                    String ordinalFieldName = createEnumFieldName(dc.getName().getUnqualifiedName()) + "_ORDINAL";
                    JavaExpression initializer = LiteralWrapper.make(new Integer(dc.getOrdinal()));
                    JavaFieldDeclaration fieldDec =
                        new JavaFieldDeclaration (
                                Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL,
                                JavaTypeName.INT, ordinalFieldName, initializer);
                    dataTypeClass.addFieldDeclaration(fieldDec);
                   
                    JavaDocComment jdc =
                        new JavaDocComment ("Ordinal value corresponding to the " + dc.getName().getUnqualifiedName() + " data constructor.");
                    fieldDec.setJavaDoc(jdc);
                }
               
                // For each data constructor create a static field
                for (int i = 0, n = typeConstructor.getNDataConstructors(); i < n; ++i) {
                    DataConstructor dc = typeConstructor.getNthDataConstructor(i);
                   
                    String staticFieldName = createEnumFieldName(dc.getName().getUnqualifiedName());
                   
                    JavaExpression initializer =
                        new JavaExpression.ClassInstanceCreationExpression(
                                dataType_TypeName,
                                new JavaExpression[]{
                                        new JavaField.Static(
                                                dataType_TypeName,
                                                staticFieldName + "_ORDINAL",
                                                JavaTypeName.INT),
                                        LiteralWrapper.make(dc.getName().getUnqualifiedName())},
                                constructorArgTypes);
                   
                    JavaFieldDeclaration fieldDec =
                        new JavaFieldDeclaration (
                                Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL,
                                dataType_TypeName, staticFieldName, initializer);

                    JavaDocComment jdc =
                        new JavaDocComment ("This instance of " + typeConstructorInfo.javaClassName + " representing the " + dc.getName().getUnqualifiedName() + " data constructor.");
                    fieldDec.setJavaDoc(jdc);

                    dataTypeClass.addFieldDeclaration(fieldDec);
                }
               
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

                    ModuleTypeInfo typeInfo = workspaceManager.getModuleTypeInfo(moduleName);
                    if (typeInfo == null) {
                        iceLogger.log(Level.INFO, "The module " + moduleName + " does not exist.");
                    } else {
                        String dataConsName = qualifiedDataConsName.getUnqualifiedName();
                        DataConstructor dataCons = typeInfo.getDataConstructor(dataConsName);
                        if (dataCons == null) {
                            iceLogger.log(Level.INFO, "The data constructor " + qualifiedDataConsName + " does not exist.");
                        } else {
                            ScopedEntityNamingPolicy scopedEntityNamingPolicy = new ScopedEntityNamingPolicy.UnqualifiedUnlessAmbiguous(typeInfo);
                           
                            iceLogger.log(Level.INFO, qualifiedDataConsName + " :: " + dataCons.getTypeExpr().toString(scopedEntityNamingPolicy) + "\n");
                           
                            CALDocComment comment = dataCons.getCALDocComment();
                            if (comment != null) {
                                iceLogger.log(Level.INFO, "CALDoc for the " + qualifiedDataConsName + " data constructor:\n" + CALDocToTextUtilities.getTextFromCALDocComment(comment, dataCons, scopedEntityNamingPolicy));
                            } else {
                                iceLogger.log(Level.INFO, "There is no CALDoc for the " + qualifiedDataConsName + " data constructor.\n" + CALDocToTextUtilities.getTextForArgumentsAndReturnValue(null, dataCons, scopedEntityNamingPolicy));
                            }
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

                }
                functionName = qn.getQualifiedName();
               
                ModuleTypeInfo mt = getWorkspaceManager().getModuleTypeInfo(qn.getModuleName());
               
                DataConstructor dc = mt.getDataConstructor(qn.getUnqualifiedName());
                if (dc != null) {
                    if (dc.getArity() == 0) {
                        logInfo("Cannot set a breakpoint on a zero arity data constructor.");
                        return;
                    }
                } else 
                if (mt.getFunction(qn.getUnqualifiedName()) == null) {
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

        // the ordinal fields.
        Set<String> javaNames = new HashSet<String>();
        for (final String typeConstructorName : typeConstructorNames) {
            TypeConstructor typeCons = moduleTypeInfo.getTypeConstructor(typeConstructorName);
            for (int i = 0, n = typeCons.getNDataConstructors(); i < n; ++i) {
                DataConstructor dc = typeCons.getNthDataConstructor(i);
               
                // If we are showing public entities we only car about public data constructors.
                if (dc.getScope().isPublic() != publicEntities) {
                    continue;
                }

                // This is the name used to name the java function and the QualfiedName field
                // associated with this data constructor.
                String javaFuncName = fixupVarName(dc.getName().getUnqualifiedName());
                javaNames.add(javaFuncName);
            }
        }
       
        for (final String typeConstructorName : typeConstructorNames) {
            TypeConstructor typeCons = moduleTypeInfo.getTypeConstructor(typeConstructorName);
            boolean commentAdded = false;
            for (int i = 0, n = typeCons.getNDataConstructors(); i < n; ++i) {
                DataConstructor dc = typeCons.getNthDataConstructor(i);
               
                // If we are showing public entities we only car about public data constructors.
                if (dc.getScope().isPublic() != publicEntities) {
                    continue;
                }
               
                addClass = true;
               
                // If this is the first DC for the data type we want a non JavaDoc comment
                // indicating the data type.
                if (!commentAdded) {
                    MultiLineComment mlc = new MultiLineComment("DataConstructors for the " + typeCons.getName().getQualifiedName() + " data type.");
                    dataConstructorsClass.addComment(mlc);
                    commentAdded = true;
                }

                // Get the types of the data constructor fields.
                TypeExpr[] fieldTypes = getFieldTypesForDC(dc);
               
               
                String javaFuncName = fixupVarName(dc.getName().getUnqualifiedName());
               
                // Since data constructors are capitalized its possible to have a conflict between the name
                // of our field/helper function and the name of the containing class.
                if (javaFuncName.equals(this.bindingClassName)) {
                    javaFuncName = javaFuncName + "_";
                }
               
                // First generate a method that takes SourceModel.Expr instances for
                // each field value.
               
                // Build up the argument names and types.
                int nArgs = dc.getArity();
                JavaTypeName argTypes[] = new JavaTypeName[nArgs];
                Arrays.fill(argTypes, SOURCE_MODEL_EXPR_TYPE_NAME);
                String argNames[] = new String[nArgs];
                String origArgNames[] = new String[nArgs];
                for (int j = 0, k = argNames.length; j < k; ++j) {
                    argNames[j] = fixupVarName(dc.getArgumentName(j));
                    origArgNames[j] = dc.getArgumentName(j);
                }
               
                // Create the method.
                JavaMethod bindingFunction =
                    new JavaMethod(PUBLIC_STATIC_FINAL,
                                   SOURCE_MODEL_EXPR_TYPE_NAME,
                                   argNames,
                                   argTypes,
                                   null, javaFuncName);
                dataConstructorsClass.addMethod(bindingFunction);
               
                // Add JavaDoc for the method.
                JavaDocComment funcComment;
                CALDocComment cdc = dc.getCALDocComment();
                if (cdc != null) {
                    funcComment = new JavaDocComment(calDocCommentToJavaComment(cdc, dc, false, argNames));
                    funcComment = fixupJavaDoc(funcComment, origArgNames, argNames);
                } else {
                    funcComment = new JavaDocComment("Binding for DataConstructor: " + dc.getName().getQualifiedName() + ".");
                    for (int iName = 0; iName < argNames.length; ++iName) {
                        funcComment.addLine("@param " + argNames[iName]);
                    }
                    funcComment.addLine("@return the SourceModule.Expr representing an application of " + dc.getName().getQualifiedName());
                }
                bindingFunction.setJavaDocComment(funcComment);
               
                // Now we need to fill in the body.
               
                // Create an instance of SourceModel.Expr.DataCons for the data constructor.
                JavaField nameField = new JavaField.Static(dataConstructorsClassTypeName, javaFuncName, QUALIFIED_NAME_TYPE_NAME);
                JavaExpression sourceModelDataConsCreation =
                    new MethodInvocation.Static(
                            SOURCE_MODEL_EXPR_DATA_CONS_TYPE_NAME,
                            "make",
                            nameField,
                            QUALIFIED_NAME_TYPE_NAME,
                            SOURCE_MODEL_EXPR_DATA_CONS_TYPE_NAME);
               
                // Build up an @see tag for the function just created.
                String atSee = "@see #" + javaFuncName + "(";
                for (int iArg = 0; iArg < argNames.length; ++iArg) {
                    if (iArg == 0) {
                        atSee = atSee + argTypes[iArg].getFullJavaSourceName();
                    } else {
                        atSee = atSee + ", " + argTypes[iArg].getFullJavaSourceName();
                    }
                }
                atSee = atSee + ")";
               
                if (dc.getArity() == 0) {
                    // Simply return the Expr.DataCons.
                    bindingFunction.addStatement(new ReturnStatement(sourceModelDataConsCreation));
                } else {
                    // Need to build up an application.
                   
                    // Create an array of SourceModel.Expr where the first element is the
                    // SourceModel.Expr.DataCons instance and the following elements are
                    // the function arguments.
                    JavaExpression arrayElements[] = new JavaExpression[dc.getArity() + 1];
                    arrayElements[0] = sourceModelDataConsCreation;
                   
                    for (int j = 1; j <= argNames.length; ++j) {
                        arrayElements[j] = new JavaExpression.MethodVariable(argNames[j-1]);
                    }
                   
                    JavaExpression arrayCreation =
                        new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
                   
                    // Invoke SourceModle.Expr.Application.make()
                    MethodInvocation makeApply =
                        new MethodInvocation.Static(
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                                "make",
                                arrayCreation,
                                JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
                   
                    bindingFunction.addStatement(new ReturnStatement (makeApply));
               
                    // If any of the argument types correspond to a Java type.
                    // (eg. Prelude.Int, Prelude.Long, etc. we can generate a version
                    // of the binding function that takes these argument types.
                    boolean primArgs = false;
                    for (int j = 0, k = fieldTypes.length; j < k; ++j) {
                        if (canTypeBeUnboxed(fieldTypes[j])) {
                            primArgs = true;
                            // Update the type of the argument.
                            argTypes[j] = typeExprToTypeName(fieldTypes[j]);
                           
                            // The argument to Application.make needs to be updated.
                            // We need to wrap the raw value (i.e. int, boolean, etc.)
                            // in the appropriate SourceModel construct.
                            arrayElements[j+1] = wrapArgument(argNames[j], fieldTypes[j]);
                        }
                    }

                   
                    if (primArgs) {
                        bindingFunction =
                            new JavaMethod(PUBLIC_STATIC_FINAL,
                                           SOURCE_MODEL_EXPR_TYPE_NAME,
                                           argNames,
                                           argTypes,
                                           null, javaFuncName);
                        dataConstructorsClass.addMethod(bindingFunction);
                       
                        // For the comment for this method we want an @see referring to the previous method.
                       
                        JavaStatement.JavaDocComment comment = new JavaStatement.JavaDocComment(atSee);
                        for (int iArg = 0; iArg < argNames.length; ++iArg) {
                            comment.addLine("@param " + argNames[iArg]);
                        }                       
                        comment.addLine("@return " + SOURCE_MODEL_EXPR_TYPE_NAME.getFullJavaSourceName());
                        bindingFunction.setJavaDocComment(comment);
                       
                        arrayCreation =
                            new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
                       
                        makeApply =
                            new MethodInvocation.Static(
                                    SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                                    "make",
                                    arrayCreation,
                                    JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                                    SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
                       
                        bindingFunction.addStatement(new ReturnStatement (makeApply));
       
                    }
                   
                }
               
                // Create a field declaration for the QualifiedName field.
                JavaFieldDeclaration jfd =
                    makeQualifiedNameDeclaration(javaFuncName, dc.getName().getUnqualifiedName());
               
                // If there is CALDoc for the DC add it as JavaDoc.
                JavaDocComment comment = new JavaDocComment("Name binding for DataConstructor: " + dc.getName().getQualifiedName() + ".");
                comment.addLine(atSee);
               
                jfd.setJavaDoc(comment);
               
                dataConstructorsClass.addFieldDeclaration(jfd);               
            
                // Now add an int field which is the ordinal of the data constructor.
                String ordinalFieldName = javaFuncName + "_ordinal";
                while (javaNames.contains(ordinalFieldName)) {
                    ordinalFieldName = ordinalFieldName + "_";
                }
                JavaFieldDeclaration ordinalFieldDec =
                    new JavaFieldDeclaration(PUBLIC_STATIC_FINAL, JavaTypeName.INT, ordinalFieldName, JavaExpression.LiteralWrapper.make(Integer.valueOf(dc.getOrdinal())));
                javaNames.add(ordinalFieldName);
                JavaDocComment ordinalComment = new JavaDocComment("Ordinal of DataConstructor " + dc.getName().getQualifiedName() + ".");
                ordinalComment.addLine(atSee);
                ordinalFieldDec.setJavaDoc(ordinalComment);
               
                dataConstructorsClass.addFieldDeclaration(ordinalFieldDec);
            }
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

        /// Create a list of the data constructors to be documented, applying the user-specified filters along the way.
        //
        int nDataConstructors = typeConstructor.getNDataConstructors();
        List<DataConstructor> dataConstructorsList = new ArrayList<DataConstructor>(nDataConstructors);
        for (int i = 0; i < nDataConstructors; i++) {
            DataConstructor entity = typeConstructor.getNthDataConstructor(i);
            if (filter.shouldGenerateScopedEntity(entity)) {
                dataConstructorsList.add(entity);
            }
        }
       
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

        /// Create a list of the data constructors to be documented, applying the user-specified filters along the way.
        //
        int nDataConstructors = typeConstructor.getNDataConstructors();
        List<DataConstructor> dataConstructorsList = new ArrayList<DataConstructor>(nDataConstructors);
        for (int i = 0; i < nDataConstructors; i++) {
            DataConstructor entity = typeConstructor.getNthDataConstructor(i);
            if (filter.shouldGenerateScopedEntity(entity)) {
                dataConstructorsList.add(entity);
            }
        }

        ModuleName moduleName = typeConstructor.getName().getModuleName();

        ////
        /// Generate documentation for each data constructor of this type constructor, and add each to the main index
        /// and the argument type and return type indices.
        //
        List<IndexEntry> perModuleFunctionalAgentIndex = getPerModuleFunctionalAgentIndex(moduleName);
       
        int nDataConstructorsToGenerate = dataConstructorsList.size();
        beginDataConsDocList(nDataConstructorsToGenerate, calcMaxScopeOfScopedEntities(dataConstructorsList));
        for (int i = 0; i < nDataConstructorsToGenerate; i++) {
           
            DataConstructor dataConstructor = dataConstructorsList.get(i);
            QualifiedName name = dataConstructor.getName();
            perModuleFunctionalAgentIndex.add(new IndexEntry(name.getUnqualifiedName(), labelMaker.getLabel(dataConstructor), dataConstructor.getScope(), IndexEntry.Kind.FUNCTIONAL_AGENT));
           
            processEnvEntityForArgAndReturnTypeIndices(dataConstructor);
           
            generateDataConsDoc(dataConstructor, i);
        }
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

        // If this is a DataConstructor for an enumeration data type
        // we want to simply return as these are treates as int.
        Expression.PackCons packCons = e.asPackCons();
        if (packCons != null) {
            DataConstructor dc = packCons.getDataConstructor();
            if (TypeExpr.isEnumType(dc.getTypeConstructor())) {
                gmf.setCodeGenerated(true);
                return;
            }
        }
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

        // Is e a pack constructor?
        Expression.PackCons packCons = e.asPackCons();
        if (packCons != null) {

            // Generate the pack constructor code and return.
            DataConstructor dc = packCons.getDataConstructor();
            // If this is a supercombinator and we are instrumenting the code.
            if (System.getProperty("org.openquark.cal.machine.g.call_counts") != null) {
                body.code (new Instruction.I_Instrument (new Executor.CallCountInfo(currentMachineFunction.getQualifiedName (), "DataConstructor function form counts")));
            }

            // Force the evaluation of any strict arguments.
            if (dc.hasStrictArgs()) {
                for (int i = 0; i < dc.getArity(); ++i) {
                    if (dc.isArgStrict(i)) {
                        body.code(new Instruction.I_Push(i));
                        body.code(Instruction.I_Eval);
                        body.code(new Instruction.I_Pop(1));
                    }
                }
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

                MACHINE_LOGGER.log(Level.FINE, "    basic:");
            }

            ConstructorOpTuple  constructorOpExpressions = ConstructorOpTuple.isConstructorOp(e, false);

            DataConstructor dc = constructorOpExpressions.getDataConstructor ();

            Instruction instruction = Instruction.I_PackCons.makePackCons(dc);

            int nArgs = constructorOpExpressions.getNArguments ();

            if (nArgs < 0) {
                throw new CodeGenerationException ("Internal Coding Error: Invalid constructor operator arity");  
            }

            for (int i = 0; i < nArgs; ++i) {
                gp.code (schemeC (constructorOpExpressions.getArgument(nArgs - i - 1), p, d + i));
            }

            // Force the evaluation of any strict arguments.
            if (dc.hasStrictArgs()) {
                for (int i = 0; i < dc.getArity(); ++i) {
                    if (dc.isArgStrict(i)) {
                        gp.code(new Instruction.I_Push(i));
                        gp.code(Instruction.I_Eval);
                        gp.code(new Instruction.I_Pop(1));
                    }
                }
View Full Code Here

Examples of org.openquark.cal.compiler.DataConstructor

                MACHINE_LOGGER.log(Level.FINE, "    basic:");
            }

            ConstructorOpTuple  constructorOpExpressions = ConstructorOpTuple.isConstructorOp(e, false);

            DataConstructor dc = constructorOpExpressions.getDataConstructor ();

            Instruction instruction = Instruction.I_PackCons.makePackCons(dc);

            int nArgs = constructorOpExpressions.getNArguments ();

            if (nArgs < 0) {
                throw new CodeGenerationException ("Internal Coding Error: Invalid constructor operator arity");  
            }

            for (int i = 0; i < nArgs; ++i) {
                gp.code (schemeC (constructorOpExpressions.getArgument(nArgs - i - 1), p, d + i));
            }

            // Force the evaluation of any strict arguments.
            if (dc.hasStrictArgs()) {
                for (int i = 0; i < dc.getArity(); ++i) {
                    if (dc.isArgStrict(i)) {
                        gp.code(new Instruction.I_Push(i));
                        gp.code(Instruction.I_Eval);
                        gp.code(new Instruction.I_Pop(1));
                    }
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.