Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.TypeExpr


     * @param metadata the metadata that may be generated.
     * @param docComment the CALDoc comment to be generated.
     * @param descriptionStyleClass the style class to use for the description.
     */
    private void generateFunctionalAgentOverview(FunctionalAgent entity, String label, FunctionalAgentMetadata metadata, CALDocComment docComment, StyleClass descriptionStyleClass) {
        TypeExpr typeExpr = entity.getTypeExpr();
       
        /// Generate the cell for the scope
        //
        currentPage
            .openTag(HTML.Tag.TR, classAttribute(getScopeStyleClass(entity.getScope())))
            .openTag(HTML.Tag.TD, classAttribute(StyleClassConstants.OVERVIEW_TABLE_SCOPE_COLUMN).concat(HTMLBuilder.AttributeList.make(HTML.Attribute.VALIGN, "baseline")))
            .addTaggedText(HTML.Tag.SPAN, classAttribute(StyleClassConstants.SCOPE), entity.getScope().toString())
            .closeTag(HTML.Tag.TD)
            .openTag(HTML.Tag.TD, HTMLBuilder.AttributeList.make(HTML.Attribute.VALIGN, "baseline"))
            .openTag(HTML.Tag.DL)
            .openTag(HTML.Tag.DT)
            .openTag(HTML.Tag.SPAN, classAttribute(StyleClassConstants.NAME_AND_TYPE))
            .openTag(HTML.Tag.SPAN, classAttribute(StyleClassConstants.OVERVIEW_REFERENCE));

        /// Generate the entity name, hyperlinked
        //
        generateLocalReference(label, entity.getName().getUnqualifiedName(), entity.getName().getQualifiedName());
       
        /// Generate the type signature, hyperlinked
        //
        generateTypeSignature(typeExpr.toSourceModel(true, ScopedEntityNamingPolicy.FULLY_QUALIFIED));
       
        currentPage
            .closeTag(HTML.Tag.SPAN)
            .closeTag(HTML.Tag.SPAN);
           
View Full Code Here


     * @param metadata the metadata that may be generated.
     * @param docComment the CALDoc comment to be generated.
     * @param descriptionStyleClass the style class to use for the description.
     */
    private void generateUsageIndexEntry(FunctionalAgent entity, String label, FunctionalAgentMetadata metadata, CALDocComment docComment, StyleClass descriptionStyleClass) {
        TypeExpr typeExpr = entity.getTypeExpr();
       
        /// Generate the cell for the scope
        //
        currentPage
            .openTag(HTML.Tag.TR, classAttribute(getScopeStyleClass(entity.getScope())))
            .openTag(HTML.Tag.TD, classAttribute(StyleClassConstants.OVERVIEW_TABLE_SCOPE_COLUMN).concat(HTMLBuilder.AttributeList.make(HTML.Attribute.VALIGN, "baseline")))
            .addTaggedText(HTML.Tag.SPAN, classAttribute(StyleClassConstants.SCOPE), entity.getScope().toString())
            .closeTag(HTML.Tag.TD)
            .openTag(HTML.Tag.TD, HTMLBuilder.AttributeList.make(HTML.Attribute.VALIGN, "baseline"))
            .openTag(HTML.Tag.DL)
            .openTag(HTML.Tag.DT)
            .openTag(HTML.Tag.SPAN, classAttribute(StyleClassConstants.NAME_AND_TYPE))
            .openTag(HTML.Tag.SPAN, classAttribute(StyleClassConstants.OVERVIEW_REFERENCE));

        /// Generate the entity name, hyperlinked
        //
        String relativePathToModulesSubdirectory = "../" + MODULES_SUBDIRECTORY;
        generateNonLocalReference(currentPage, relativePathToModulesSubdirectory, entity.getName().getModuleName(), label, entity.getName().getUnqualifiedName(), entity.getName().getQualifiedName());
       
        /// Generate the type signature, hyperlinked
        //
        generateTypeSignature(typeExpr.toSourceModel(true, ScopedEntityNamingPolicy.FULLY_QUALIFIED), new TypeSignatureHTMLGeneratorUsingNonLocalReferences(relativePathToModulesSubdirectory));
       
        currentPage
            .closeTag(HTML.Tag.SPAN)
            .closeTag(HTML.Tag.SPAN)
            .closeTag(HTML.Tag.DT)
View Full Code Here

     * @param classInstance the class instance whose name is to be generated.
     * @param shouldGenerateHyperlinks whether hyperlinks should be generated.
     */
    private void generateClassInstanceDeclarationName(ClassInstance classInstance, boolean shouldGenerateHyperlinks) {
        TypeClass typeClass = classInstance.getTypeClass();
        TypeExpr instanceType = classInstance.getType();
       
        QualifiedName typeClassName = typeClass.getName();      
       
        SourceModel.TypeSignature typeSig = instanceType.toSourceModel(true, ScopedEntityNamingPolicy.FULLY_QUALIFIED);
        SourceModel.TypeExprDefn typeExprDefn = typeSig.getTypeExprDefn();
       
        TypeSignatureHTMLGenerator visitor = new TypeSignatureHTMLGenerator(shouldGenerateHyperlinks);
       
        /// First generate the constraints from the instance type signature - they form the constraints on the instance.
View Full Code Here

    /*
     * @implementation this method is exposed via package scope to allow reuse by the CALDocToTooltipHTMLUtilities
     */
    void generateFunctionalAgentDoc(String unqualifiedName, FunctionalAgent entity, String label, FunctionalAgentMetadata metadata, CALDocComment docComment, int indexInList, boolean shouldDisplayReturnBlock) {
        Scope scope = entity.getScope();
        TypeExpr typeExpr = entity.getTypeExpr();
        ArgumentMetadata[] argMetadataArray = metadata.getArguments();
       
        generateFunctionalAgentOrInstanceMethodDocHeading(scope, unqualifiedName, entity, typeExpr, label, argMetadataArray, docComment, indexInList, false);
       
        generateFunctionalAgentOrInstanceMethodDocBody(scope, entity, typeExpr, metadata, argMetadataArray, docComment, docComment, docComment, shouldDisplayReturnBlock);
View Full Code Here

       
        Scope scope = null;
        String unqualifiedName = methodName;
        FunctionalAgent entityWithArgumentNames = classMethod;
        CALDocComment classMethodCALDocComment = classMethod.getCALDocComment();
        TypeExpr typeExpr = classInstance.getInstanceMethodType(methodName);
        ArgumentMetadata[] argMetadataArray = metadata.getArguments();
        String label = labelMaker.getLabel(classInstance, methodName);
       
        /// If there are no @arg blocks for the instance method's CALDoc comment, or there is no CALDoc comment for the method at
        /// all, use the CALDoc comment for the class method
        //
        final CALDocComment docCommentForArguments;
        if (docComment != null && docComment.getNArgBlocks() > 0) {
            docCommentForArguments = docComment;
        } else {
            docCommentForArguments = classMethodCALDocComment;
        }
       
        /// If there is no @return block for the instance method's CALDoc comment, or there is no CALDoc comment for the method at
        /// all, use the CALDoc comment for the class method - but only if the class method's arity matches the instance method's arity.
        //
        final CALDocComment docCommentForReturnValue;
        if (docComment != null && docComment.getReturnBlock() != null) {
            docCommentForReturnValue = docComment;
           
        } else if (classMethod.getTypeExpr().getArity() == typeExpr.getArity()) {
           
            // we only default to the class method's comment if the arities match
            // for example: the QuickCheck.Arbitrary instance for the function type a->b has an instance method:
            //    generateInstance :: (Arbitrary a, Arbitrary b) => GenParams -> a -> b
            // but the class method has the type:
View Full Code Here

     * @param destTypeExpr
     * @return ValueNode
     */
    public ValueNode transform(ValueNodeBuilderHelper valueNodeBuilderHelper, ValueNode sourceVN, TypeExpr destTypeExpr) {

        TypeExpr sourceTypeExpr = sourceVN.getTypeExpr();
       
        // check if we're "transforming" to the same type
        if (sourceTypeExpr.sameType(destTypeExpr)) {
            return sourceVN.copyValueNode(destTypeExpr);
        }

        Object newValue = null;

        Class<? extends ValueNode> handlerClass = valueNodeBuilderHelper.getValueNodeClass(destTypeExpr);
       
        PreludeTypeConstants typeConstants = valueNodeBuilderHelper.getPreludeTypeConstants();

        if (handlerClass.equals(ListOfCharValueNode.class) || destTypeExpr.sameType(typeConstants.getStringType())) {

            if (sourceVN instanceof ListValueNode && sourceVN.getTypeExpr().sameType(typeConstants.getCharListType())) {
                // Converting a List to a List of Char: we convert each of the list values

                ListValueNode listValueNode = (ListValueNode)sourceVN;

                StringBuilder sb = new StringBuilder();
                int nElements = listValueNode.getNElements();
                for (int i = 0; i < nElements; i++) {
                    sb.append(listValueNode.getValueAt(i).getCALValue());
                }

                newValue = sb.toString();

            } else {
                newValue = sourceVN.getTextValue();
            }

        } else if (destTypeExpr.sameType(typeConstants.getCharType())) {
           
            // Just take the first character of the text value (if any)
            String textValue = sourceVN.getTextValue();
            if (textValue.length() != 0) {
                newValue = Character.valueOf(textValue.charAt(0));
            }
        }

        if (sourceVN instanceof LiteralValueNode && !sourceVN.getTypeExpr().sameType(typeConstants.getStringType())) {

            LiteralValueNode sourceLiteralVN = (LiteralValueNode) sourceVN;

            if (sourceTypeExpr.sameType(typeConstants.getDoubleType()) &&
                destTypeExpr.sameType(typeConstants.getIntType())) {

                newValue = Integer.valueOf((int) Math.round(sourceLiteralVN.getDoubleValue().doubleValue()));

            } else if (sourceTypeExpr.sameType(typeConstants.getIntType()) &&
                       destTypeExpr.sameType(typeConstants.getDoubleType())) {

                newValue = Double.valueOf(sourceLiteralVN.getIntegerValue().intValue());
            }

View Full Code Here

   
        setTarget(target, targetModule);
   
        // The target:
        // Note that if we can't get a target type then we return null.
        TypeExpr targetGemTypeExpr = getNewTargetTypeExpr();
        if (targetGemTypeExpr == null) {
            return null;
        }
                
        int nArgs = argValues.length;
        TypeExpr[] targetTypePieces = targetGemTypeExpr.getTypePieces(nArgs);

        // Use the arguments to specialize the target type.
        TypeExpr valueNodeArgTypes[] = new TypeExpr[nArgs];
        for (int i = 0; i < nArgs; i++) {
            valueNodeArgTypes[i] = argValues[i].getTypeExpr();
        }
       
        ModuleTypeInfo currentModuleTypeInfo = getWorkspaceManager().getWorkspace().getMetaModule(targetModule).getTypeInfo();
        TypeExpr[] specializedTargetTypePieces;
        try {       
            specializedTargetTypePieces = TypeExpr.patternMatchPieces(valueNodeArgTypes, targetTypePieces, currentModuleTypeInfo);
        } catch (TypeException te){
            // What to do?
            GemCutter.CLIENT_LOGGER.log(Level.SEVERE, "Could not determine gem execution output type.");
            return null;           
        }      

        // The result:
        TypeExpr resultType = specializedTargetTypePieces[nArgs];

        if (resultType.isFunctionType()) {
           
            // todoFW: HACK! Handle loading function values better.
            // The function value will be the last item in the text inside brackets.
            // Stip the brackets and get the text which should give us the qualified name
            // of the function.
View Full Code Here

     * @param targetModule the module in which the target exists.
     * @return boolean whether the target's output type can be handled.  Note that this will be in the absence
     * of any arguments being provided.
     */
    private boolean canHandleTargetOutput(Target target, ModuleName targetModule) {
        TypeExpr outputTypeExpr = getNewTargetTypeExpr(target, targetModule, getTypeChecker());
        return ValueNodeBuilderHelper.canHandleOutput(outputTypeExpr);
    }
View Full Code Here

     * @param caldoc the CALDoc comment of the entity. Can be null.
     * @param envEntity the FunctionalAgent being documented. Can be null if the comment is not for an FunctionalAgent.
     * @return the argument names from the CALDoc comment.
     */
    public static String[] getArgumentNamesFromCALDocComment(final CALDocComment caldoc, final FunctionalAgent envEntity) {
        final TypeExpr typeExpr = envEntity == null ? null : envEntity.getTypeExpr();
        return getArgumentNamesFromCALDocComment(caldoc, envEntity, typeExpr);
    }
View Full Code Here

     * @param envEntity the FunctionalAgent being documented. Can be null if the comment is not for an FunctionalAgent.
     * @param argNames the names of arguments to use. Can be null if the default mechanism for obtaining argument names is to be used.
     * @return a plain text representation for the comment.
     */
    public static String getJavadocFromCALDocComment(final CALDocComment caldoc, final boolean isClassComment, final FunctionalAgent envEntity, final String[] argNames) {
        TypeExpr typeExpr;
        if (envEntity == null) {
            typeExpr = null;
        } else {
            typeExpr = envEntity.getTypeExpr();
        }
View Full Code Here

TOP

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

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.