Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.QualifiedName


     * @return a QualifiedName for the resolved type class, or null if the name cannot be resolved.
     */
    private QualifiedName resolveTypeClassName(String name) {
        ModuleTypeInfo moduleTypeInfo = getWorkspaceManager().getModuleTypeInfo(targetModule);
       
        QualifiedName resolvedName = CodeAnalyser.resolveEntityNameAccordingToImportUsingClauses(name, Category.TYPE_CLASS, moduleTypeInfo);
       
        if (resolvedName != null) {
            return resolvedName;
        } else {
            return qualifyTypeClass(name);
View Full Code Here


           
            String functionName = firstWord;
           
            // Determine if function name is a valid CAL function or data constructor.
            try {
                QualifiedName qn = resolveQualifiedNameInProgram(QualifiedName.makeFromCompoundName(functionName));
                if (qn == null) {
                    return;
                }
                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) {
                    logInfo(qn + " is not a valid function name.");
                    return;
                }
                   
            } catch (IllegalArgumentException e) {
View Full Code Here

            } else {
                // :trace Module.function
                String functionName = firstWordRaw;
                try {
                    // Check that the function name is valid.
                    QualifiedName qn = resolveQualifiedNameInProgram(QualifiedName.makeFromCompoundName(functionName));
                    if (qn == null) {
                        return;
                    }
                    functionName = qn.getQualifiedName();
                   
                    try {
                        if(getWorkspaceManager().getMachineFunction(qn) == null) {
                            logInfo(qn.getQualifiedName() + " is not a valid function.");
                            return;
                        }
                    } catch (ProgramException e) {
                        logInfo(qn.getQualifiedName() + " is not a valid function.");
                        return;
                    }
                } catch (IllegalArgumentException e) {
                    logInfo(functionName + " is not a valid compound name.");
                    return;
View Full Code Here

     */
    public void testCorrectLoaderChosen() {
       
        ModuleName adjunctModuleName = CALPlatformTestModuleNames.M1;
        String adjunctUnqualifiedName = "testAdjunct";
        QualifiedName qualifiedAdjunctName = QualifiedName.make(adjunctModuleName, adjunctUnqualifiedName);
        QualifiedName qualifiedDependeeFunctionName = QualifiedName.make(adjunctModuleName, "callNot");
        QualifiedName qualifiedPreludeDependeeName = CAL_Prelude.Functions.not;
       
        // Create the adjunct source.
        SourceModel.Expr funcArg = SourceModel.Expr.makeBooleanValue(false);
        SourceModel.Expr funcExpr = SourceModel.Expr.makeGemCall(qualifiedDependeeFunctionName, funcArg);
       
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public FilePath getResourcePath(ResourceName resourceName) {
        QualifiedName designName = checkDesignName(resourceName);
        String fileName = FileSystemResourceHelper.getFileSystemName(designName.getQualifiedName() + "." + DESIGN_FILE_EXTENSION);
        String moduleNameString = FileSystemResourceHelper.getFileSystemName(designName.getModuleName().toSourceText());
        return baseDesignFolder.extendFolder(moduleNameString).extendFile(fileName);
    }
View Full Code Here

     * @return the corresponding resource name.
     */
    private ResourceName getResourceNameFromFileName(String fileName) {
        String unencodedFileName = FileSystemResourceHelper.stripFileExtension(fileName, DESIGN_FILE_EXTENSION, true);
        if (unencodedFileName != null) {
            QualifiedName qualifiedName = QualifiedName.makeFromCompoundName(unencodedFileName);
            return new ResourceName(CALFeatureName.getFunctionFeatureName(qualifiedName));
        } else {
            return null;
        }
    }
View Full Code Here

//        if (clazz.isArray()) {
//            Class componentType = clazz.getComponentType();
//            return TypeExprDefn.List.make(getTypeExprForClass(componentType, generationInfo));
//        }
       
        QualifiedName typeConsName = generationInfo.getForeignTypeName(javaClass);
       
        // For the unit, make a Unit type.
        if (typeConsName.equals(CAL_Prelude.TypeConstructors.Unit)) {
            return TypeExprDefn.Unit.make();
        }
       
        // Just a regular type cons.
       
        // If in the current module, we can use in unqualified form.
        ModuleName typeConsModuleName = typeConsName.getModuleName();
        if (typeConsModuleName.equals(generationInfo.getCurrentModuleName())) {
            return TypeExprDefn.TypeCons.make(null, typeConsName.getUnqualifiedName());
       
       
        } else if (typeConsModuleName.equals(CAL_Prelude.MODULE_NAME)) {
            // If in the Prelude, may also be able to use the unqualified form, but this means we need to add to the using clause.
            // We cannot use in an unqualifed way if a type with the same unqualifed name exists in the current module.
            String unqualifiedTypeName = typeConsName.getUnqualifiedName();
           
            if (generationInfo.addTypeToPreludeUsingSet(unqualifiedTypeName)) {
                return TypeExprDefn.TypeCons.make(null, unqualifiedTypeName);
            }
        }           
View Full Code Here

                // Iterate over the type constructors in the module.
                int nTypeConstructors = moduleTypeInfo.getNTypeConstructors();
                for (int j = 0; j < nTypeConstructors; j++) {
                    TypeConstructor typeCons = moduleTypeInfo.getNthTypeConstructor(j);
                   
                    QualifiedName calName = typeCons.getName();
                    
                    //Prelude.Unit and Prelude.Boolean are special cases in that they are algebraic types that however correspond
                    //to foreign types for the purposes of declaring foreign functions.
                   
                    if (calName.equals(CAL_Prelude.TypeConstructors.Unit)) {
                        classToTypeConsNameMap.put(void.class, calName);
                        continue;
                    }
                    if (calName.equals(CAL_Prelude.TypeConstructors.Boolean)) {
                        classToTypeConsNameMap.put(boolean.class, calName);
                        continue;
                    }
                   
                    // Check if the type is foreign.
                    ForeignTypeInfo fti = typeCons.getForeignTypeInfo();
                   
                    if (fti != null && fti.getImplementationVisibility() == Scope.PUBLIC) {
                        Class<?> foreignType = fti.getForeignType();
                       
                        // In cases where a single class maps to multiple type constructors,
                        //   we choose the type in the module which is "closest" to the Prelude.
                        // For now, this distance is approximated by the number of imports in the module.
                        // TODOEL: Later, we can figure out the size of the import graph.
                        QualifiedName existingMappedName = classToTypeConsNameMap.get(foreignType);
                        if (existingMappedName == null) {
                            // Add a new mapping.
                            classToTypeConsNameMap.put(foreignType, calName);
                            continue;
                        }
                        // a mapping already exists.
                        ModuleTypeInfo existingMappingModuleTypeInfo = workspace.getMetaModule(existingMappedName.getModuleName()).getTypeInfo();
                        if (existingMappingModuleTypeInfo == null) {
                            // Existing mapping's type info not compiled.
                            continue;
                        }
                        int existingMappingNImports = existingMappingModuleTypeInfo.getNImportedModules();
View Full Code Here

         * @return the new generated name.
         */
        String getTypeConsName(Class<?> foreignClass) {

            {
                QualifiedName previouslyCalculatedName = classToTypeConsNameMap.get(foreignClass);
                if (previouslyCalculatedName != null) {
                    return previouslyCalculatedName.getUnqualifiedName();
                }
            }
           
            String baseName = makeTypeConsName(foreignClass, -1);
           
            // Disambiguate.
            int index = 2;
            String typeConsName = baseName;
            while (!existingUnqualifiedTypeConsNamesSet.add(typeConsName)) {
                typeConsName = baseName + index;
                index++;
            }
           
            // Add a mapping for the generated name.
            QualifiedName qualifiedTypeConsName = QualifiedName.make(currentModuleName, typeConsName);
            classToTypeConsNameMap.put(foreignClass, qualifiedTypeConsName);
           
            return typeConsName;
        }
View Full Code Here

                        typeConsName = baseName + index;
                        index++;
                    }
                   
                    // Only one class with this base name.
                    QualifiedName qualifiedTypeConsName = QualifiedName.make(currentModuleName, baseName);
                    classToTypeConsNameMap.put(conflictingClass, qualifiedTypeConsName);
                   
                } else {
                    // More than one class with the same base name.
                    // Iterate over the classes in the set, figuring out how many qualifications are necessary to disambiguate.
                    // Names are qualified in reverse order.
                    // eg. for org.openquark.gems.client.jfit.ForeignImportGenerator,
                    //   base name       : ForeignImportGenerator
                    //   1 qualification : jfit.ForeignImportGenerator
                    //   2 qualifications: client.jfit.ForeignImportGenerator
                    //   etc.
                   
                    int numQualifications = 1;
                    while (numQualifications > 0) {
                        // (Set of String) names of classes, with the given number of qualifications.
                        Set<String> namesWithQualification = new HashSet<String>();
                       
                        boolean foundConflict = false;
                       
                        for (final Class<?> conflictingClass : classSet) {
                            String nameWithQualification = makeTypeConsName(conflictingClass, numQualifications);
                           
                            if (nameWithQualification == null) {
                                // Not enough qualifications exist in the name.
                                // foundConflict is false, so we will break out of the while.. loop.
                                numQualifications = -1;
                                break;
                            }
                           
                            if (!namesWithQualification.add(nameWithQualification)) {
                                // This number of qualifications is not enough to disambiguate with respect to the other classes.
                                foundConflict = true;
                                break;
                            } else {
                                // Didn't find a conflict.  Try the next name.
                            }
                        }
                        if (foundConflict) {
                            // Try more qualifications.
                            numQualifications++;
                        } else {
                            // Found a sufficient number of qualifications.
                            break;
                        }
                    }

                    // Now populate the classToTypeConsNameMap
                    for (final Class<?> conflictingClass : classSet) {
                        String nameWithQualification = makeTypeConsName(conflictingClass, numQualifications);
                       
                        // Disambiguate.
                        int index = 2;
                        String typeConsName = nameWithQualification;
                        while (!existingUnqualifiedTypeConsNamesSet.add(typeConsName)) {
                            typeConsName = baseName + index;
                            index++;
                        }
                       
                        // Add a mapping for the generated name.
                        QualifiedName qualifiedTypeConsName = QualifiedName.make(currentModuleName, typeConsName);
                        classToTypeConsNameMap.put(conflictingClass, qualifiedTypeConsName);
                    }
                }
            }
        }
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.