Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.QualifiedName


            for (int i = 0; i < nParentClasses; i++) {
                if (i > 0) {
                    currentPage.addText(CALFragments.COMMA_AND_SPACE);
                }
               
                QualifiedName parentClassName = typeClass.getNthParentClass(i).getName();
               
                if (shouldGenerateHyperlinks) {
                    generateTypeClassReference(parentClassName);
                } else {
                    currentPage.addText(getAppropriatelyQualifiedName(parentClassName.getModuleName(), parentClassName.getUnqualifiedName()));
                }
               
                currentPage.addText("&nbsp;" + CALFragments.STANDARD_TYPE_VAR);
            }
           
View Full Code Here


     */
    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.
        //
        visitor.generateConstraintsFromSignature(typeSig, null);
       
        /// Then generate the instance type class name.
        //
        if (shouldGenerateHyperlinks) {
            generateTypeClassReference(typeClassName);
        } else {
            currentPage.addText(getAppropriatelyQualifiedName(typeClassName.getModuleName(), typeClassName.getUnqualifiedName()));
        }
       
        currentPage.addText(" ");
       
        /// Finally, generate the remaining type expression portion of the instance type, parenthesized as needed
View Full Code Here

        /**
         * {@inheritDoc}
         */
        @Override
        final void generateFunctionOrClassMethodReference(final HTMLBuilder builder, final ScopedEntityReference reference) {
            final QualifiedName qualifiedName = reference.getName();
           
            CALFeatureName featureName;
            if (isClassMethodName(qualifiedName)) {
                featureName = CALFeatureName.getClassMethodFeatureName(qualifiedName);
            } else {
View Full Code Here

        }
       
        private void generateMultiClassIO (
            List<TopLevelSourceElement> topLevelDefnsList) throws UnableToResolveForeignEntityException {
           
            QualifiedName typeConstructorName = typeConstructorInfo.typeConstructor.getName();
           
            // Import the top level class as a foreign type.
            // ex. data foreign unsafe import jvm "org.olap.CubeType" public JCubeType;
            makeForeignClassDeclaration(topLevelDefnsList);
           
            for (int i = 0, n = typeConstructor.getNDataConstructors(); i < n; ++i) {
                DataConstructor dc = typeConstructor.getNthDataConstructor(i);
                makeForeignClassDeclaration(dc, topLevelDefnsList);
            }
           
            TypeExprDefn.TypeCons jClassTypeExpr =
                TypeExprDefn.TypeCons.make(Name.TypeCons.makeUnqualified(typeConstructorInfo.calForeignTypeName));
           
           
            // Import the constructors for each inner class (i.e. each data constructor)
            // Pull in the constructor for the Java class.
            for (int i = 0, n = javaClass.getNInnerClasses(); i < n; ++i) {
                JavaClassRep innerClass = javaClass.getInnerClass(i);
                assert (innerClass.getNConstructors() == 1);
                JavaConstructor constructor = innerClass.getConstructor(0);
                topLevelDefnsList.add(importJavaConstructor(constructor, true));
            }
           
            // Create accessors for fields in the top level class.
            for (FieldName fn : typeConstructorInfo.commonFieldNames) {
                Set<JavaTypeName> fieldTypes = typeConstructorInfo.allFieldTypeNames.get(fn);
               
                // There will only be one type for common fields.
                Iterator<JavaTypeName> types = fieldTypes.iterator();
                JavaTypeName fieldType = types.next();
               
                String foreignFieldTypeSting = typeConstructorInfo.calFieldForeignTypes.get(fn).get(fieldType);
               
                generateFieldAccessor (
                        typeConstructorInfo.calForeignTypeName,
                        fn,
                        fieldType,
                        foreignFieldTypeSting,
                        typeConstructor.getNthDataConstructor(0),
                        topLevelDefnsList);
            }
           
            // Create accessors for the fields in the inner classes.
            for (int i = 0, n = typeConstructor.getNDataConstructors(); i < n; ++i) {
                DataConstructor dc = typeConstructor.getNthDataConstructor(i);
                DataConstructorInfo dcInfo = (DataConstructorInfo)typeConstructorInfo.dataConstructorInfo.get(dc);
               
                for (FieldName fn : dcInfo.allFieldNames) {
                    if (typeConstructorInfo.commonFieldNames.contains(fn)) {
                        continue;
                    }
                   
                    JavaTypeName fieldType = (JavaTypeName)dcInfo.fieldTypeNames.get(fn);
                    String foreignFieldTypeSting = typeConstructorInfo.calFieldForeignTypes.get(fn).get(fieldType);
                    generateFieldAccessor (
                            dcInfo.calForeignTypeName,
                            fn,
                            fieldType,
                            foreignFieldTypeSting,
                            dc,
                            topLevelDefnsList);
                }
            }
           
            // Bring in the 'getDCOrdinal()' method of the Java class.
            String getDCOrdinalName = "j" + javaClass.getClassName().getUnqualifiedJavaSourceName() + "_getDCOrdinal";
            SourceModel.TypeSignature getDCOrdinalTypeSignature =
                TypeSignature.make(
                        TypeExprDefn.Function.make(
                                jClassTypeExpr,
                                INT_TYPE_EXPR_DEFN));
           
            SourceModel.CALDoc.Comment.Function getDCOrdinalComment;
            {
                SourceModel.CALDoc.TextSegment.Plain textSegment =
                    SourceModel.CALDoc.TextSegment.Plain.make(
                            "\nRetrieve the ordinal value from an instance of " + typeConstructorInfo.calForeignTypeName + ".\n" +
                            "The ordinal can be used to determine which data constructor the " + typeConstructorInfo.calForeignTypeName + "\n" +
                            "instance corresponds to.");
               
                SourceModel.CALDoc.TextBlock textBlock =
                    SourceModel.CALDoc.TextBlock.make(new SourceModel.CALDoc.TextSegment.TopLevel[]{textSegment});
                   
                getDCOrdinalComment =
                    SourceModel.CALDoc.Comment.Function.make(
                            textBlock,
                            null);
            }
           
            SourceModel.FunctionDefn getDCOrdinal =
                FunctionDefn.Foreign.make(
                        getDCOrdinalComment,
                        getDCOrdinalName,
                        Scope.PRIVATE,
                        true,
                        "method getDCOrdinal",
                        getDCOrdinalTypeSignature);
            topLevelDefnsList.add(getDCOrdinal);
           
            // Create input function.
            // inputCube :: JCube -> Cube;
            // inputCube jCube =
            //     case (jCube_getDCOrdinal JCube) of
            //     0 -> ...;
            //     1 -> ...;
            String inputFunctionName =
                "input" + typeConstructor.getName().getUnqualifiedName();
            String inputFunctionArgName = "j" + typeConstructorInfo.calForeignTypeName.substring(1);
            Expr.Var inputFunctionArg = Expr.Var.make(Name.Function.makeUnqualified(inputFunctionArgName));

            // Do the function type declaration.
            // JCube -> Cube
            TypeExprDefn inputFunctionType =
                TypeExprDefn.Function.make(
                        TypeExprDefn.TypeCons.make(Name.TypeCons.makeUnqualified(typeConstructorInfo.calForeignTypeName)),
                        TypeExprDefn.TypeCons.make(Name.TypeCons.makeUnqualified(typeConstructorName.getUnqualifiedName())));
           
            SourceModel.CALDoc.Comment.Function inputFunctionComment;
            {
                SourceModel.CALDoc.TextSegment.Plain textSegment =
                    SourceModel.CALDoc.TextSegment.Plain.make(
View Full Code Here

            DataConstructorInfo dcInfo = (DataConstructorInfo)typeConstructorInfo.dataConstructorInfo.get(dc);
           
            // Build up the values for each field in the data constructor.
            SourceModel.Expr dcApplicationExpressions[] = new SourceModel.Expr[dc.getArity() + 1];
           
            QualifiedName makeFunctionName = findMakeDCName(dc);
            if (makeFunctionName != null) {
                dcApplicationExpressions[0] = SourceModel.Expr.Var.make (Name.Function.make(makeFunctionName));
                logMessage(Level.INFO, "Using function " + makeFunctionName.getUnqualifiedName() + " instead of data constructor " + dc.getName().getUnqualifiedName());
            } else {
                dcApplicationExpressions[0] = SourceModel.Expr.DataCons.make(dc.getName());
            }
            TypeExpr[] dcFieldTypes = getFieldTypesForDC(dc);
View Full Code Here

                           
                            String name = var.toSourceText();
                           
                            if (QualifiedName.isValidCompoundName(name)) {
                               
                                QualifiedName functionName = QualifiedName.makeFromCompoundName(name);
                                GemEntity gemEntity = getWorkspaceManager().getWorkspace().getGemEntity(functionName);
                               
                                if (gemEntity != null) {
                                    return new GemEntityValueNode(gemEntity, resultType);
                                }
View Full Code Here

               
                /*
                 * count the instance methods
                 */
                for (int j = 0; j < nInstanceMethods; j++) {
                    QualifiedName instanceMethod = nthClassInstance.getInstanceMethod(j);
                    if (instanceMethod == null) {
                        totalDefaultInstanceMethods++;
                        defaultInstanceMethodEncountered = true;
                   
                    } else {
                        totalNonDefaultInstanceMethods++;
                       
                        if (instanceMethod.getUnqualifiedName().startsWith("$")) {
                           
                            if (instanceMethod.getUnqualifiedName().startsWith("$typeOf$")) {
                                encounteredTypeOfClassMethod = true;
                                totalNonDefaultGeneratedTypeOfInstanceMethods++;
                               
                                String unqualifiedInstanceMethodName = instanceMethod.getUnqualifiedName();
                                typeableConstructorNameSet.add(
                                        QualifiedName.make(moduleName, unqualifiedInstanceMethodName.substring(unqualifiedInstanceMethodName.lastIndexOf('$') + 1))
                                        );
                               
                            } else {
View Full Code Here

   
        } else if (unqualifiedName.length() == 0) {
            XMLPersistenceHelper.handleBadDocument(nameElement, "No unqualified name given.");
        }

        QualifiedName qualifiedName = null;
        try {
            qualifiedName = QualifiedName.make(ModuleName.make(moduleName), unqualifiedName);

        } catch (Exception e) {
            XMLPersistenceHelper.handleBadDocument(nameElement, "Invalid name:" + e.getMessage());
View Full Code Here

        }
       
        final Category category;
       
        String oldNameString;
        QualifiedName oldName;
       
        String newNameString;
        QualifiedName newName;
       
        if(args.length >= 3) {
            String categoryString = args[0];
            if(categoryString.equals("function") || categoryString.equals("method")) {
                category = Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD;
            } else if(categoryString.equals("dataCons") || categoryString.equals("dataConstructor")) {
                category = Category.DATA_CONSTRUCTOR;
            } else if(categoryString.equals("typeCons") || categoryString.equals("typeConstructor")) {
                category = Category.TYPE_CONSTRUCTOR;
            } else if(categoryString.equals("typeClass")) {
                category = Category.TYPE_CLASS;
            } else if(categoryString.equals("module")) {
                category = Category.MODULE_NAME;
            } else {
                iceLogger.log(Level.INFO, "Error: Unrecognized category '" + categoryString + "'");
                return;
            }
       
            oldNameString = args[1];
            newNameString = args[2];
            if(category == Category.MODULE_NAME) {
               
                ModuleName oldNameAsModuleName = ModuleName.maybeMake(oldNameString);
                if(oldNameAsModuleName == null) {
                    iceLogger.log(Level.INFO, "Error: " + oldNameString + " is not a valid module name");
                    return;
                }
               
                oldName = QualifiedName.make(oldNameAsModuleName, Refactorer.Rename.UNQUALIFIED_NAME_FOR_MODULE_RENAMING);
           
            } else if(QualifiedName.isValidCompoundName(oldNameString)) {
                oldName = QualifiedName.makeFromCompoundName(oldNameString);
           
            } else {
                iceLogger.log(Level.INFO, "Error: " + oldNameString + " is not a valid qualified name");
                return;
            }
       
        } else {
           
            oldNameString = args[0];
            newNameString = args[1];

            ModuleName oldNameAsModuleName = ModuleName.maybeMake(oldNameString);
            // the null check for oldNameAsModuleName comes a bit later (a few lines down)
           
            QualifiedName oldNameAsQualifiedName;
            if (QualifiedName.isValidCompoundName(oldNameString)) {
                oldNameAsQualifiedName = QualifiedName.makeFromCompoundName(oldNameString);
            } else {
                oldNameAsQualifiedName = null;
            }
           
            List<Category> entityCategories = new ArrayList<Category>();
            if (oldNameAsModuleName != null && getWorkspaceManager().getModuleTypeInfo(oldNameAsModuleName) != null) {
                entityCategories.add(Category.MODULE_NAME);
            }
           
            if (oldNameAsQualifiedName != null) {
                ModuleName moduleName = oldNameAsQualifiedName.getModuleName();
                String unqualifiedName = oldNameAsQualifiedName.getUnqualifiedName();
               
                ModuleTypeInfo moduleTypeInfo = getWorkspaceManager().getModuleTypeInfo(moduleName);
                if(moduleTypeInfo != null) {

                    if(moduleTypeInfo.getFunctionOrClassMethod(unqualifiedName) != null) {
View Full Code Here

     * @param functionOrClassMethodName
     */
    private void command_docFunctionOrClassMethod(String functionOrClassMethodName) {
        if (this.workspaceManager != null) {
            synchronized (this.workspaceManager) {
                QualifiedName qualifiedFunctionName = resolveFunctionOrClassMethodName(functionOrClassMethodName);
                if (qualifiedFunctionName != null) {
                    ModuleName moduleName = qualifiedFunctionName.getModuleName();
                    ModuleTypeInfo typeInfo = workspaceManager.getModuleTypeInfo(moduleName);
                    if (typeInfo == null) {
                        iceLogger.log(Level.INFO, "The module " + moduleName + " does not exist.");
                    } else {
                        String functionName = qualifiedFunctionName.getUnqualifiedName();
                        FunctionalAgent function = typeInfo.getFunctionOrClassMethod(functionName);
                        if (function == null) {
                            iceLogger.log(Level.INFO, "The function " + qualifiedFunctionName + " does not exist.");
                        } else {                           
                            ScopedEntityNamingPolicy scopedEntityNamingPolicy = new ScopedEntityNamingPolicy.UnqualifiedUnlessAmbiguous(typeInfo);
View Full Code Here

TOP

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

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.