Package org.openquark.cal.compiler.SourceModel

Examples of org.openquark.cal.compiler.SourceModel.ModuleDefn


        private boolean isFormattingValid(ModuleDefn moduleDefn, String formatted) {
            CompilerMessageLogger mlogger= new MessageLogger();
            ArrayList<SourceEmbellishment> embellishments = new ArrayList<SourceEmbellishment>();
           
            //verify the formatted source can parsed
            ModuleDefn moduleDefnTest = SourceModelUtilities.TextParsing.parseModuleDefnIntoSourceModel(formatted, false, mlogger, embellishments);
            if (moduleDefnTest == null) {
                return false;
            }

            if (!General.toPlatformLineSeparators(moduleDefn.toString()).equals(General.toPlatformLineSeparators(moduleDefnTest.toString()))) {
                //the original and formatted code are not equal
                return false;
            }

            return true;
View Full Code Here


                      
            String oldSource = super.readModuleText(moduleName, messageLogger); //super.moduleContainer.getModuleSource(moduleName);
           
            CompilerMessageLogger mlogger= new MessageLogger();
            ArrayList<SourceEmbellishment> embellishments = new ArrayList<SourceEmbellishment>();
            ModuleDefn moduleDefn = SourceModelUtilities.TextParsing.parseModuleDefnIntoSourceModel(oldSource, false, mlogger, embellishments);
                      
            if (moduleDefn == null) {
                MessageKind messageKind = new MessageKind.Fatal.DebugMessage("PrettyPrint failed: Unable to parse source module.");
                messageLogger.logMessage(new CompilerMessage(messageKind));
                return null;
View Full Code Here

                SourceModel.Import.make(CAL_Prelude.MODULE_NAME, null, null, generationInfo.getPreludeUsingTypes(), preludeUsingTypeClasses),
                SourceModel.Import.make(CAL_Debug.MODULE_NAME, null, null, null, debugUsingTypeClasses)
        };
       
        // Create the source model for the module.
        ModuleDefn moduleDefn = SourceModel.ModuleDefn.make(moduleComment, moduleName, imports, topLevelSourceElements);
       
        // Add imports
        moduleDefn = ImportAugmenter.augmentWithImports(moduleDefn);
       
        return moduleDefn;
View Full Code Here

     * Automatically figure out what the required classes and functions are, generate them, output to a file.
     * Does nothing if there was a problem with the command-line options.
     */
    private void fitToFile(File outputFolder) {
       
        ModuleDefn defn = autoFit();
        if (defn == null) {
            jfitLogger.info("");
            jfitLogger.info("Generation failed.");
            return;
        }
       
        String sourceText = defn.toSourceText();
       
        String[] moduleNameQualifier = defn.getModuleName().getQualifier().getComponents();
        String unqualifiedModuleName = defn.getModuleName().getUnqualifiedModuleName();
       
        File fileFolder = outputFolder;
        for (final String component : moduleNameQualifier) {
            if (fileFolder == null) {
                fileFolder = new File(component);
            } else {
                fileFolder = new File(fileFolder, component);
            }
        }
       
        if (fileFolder != null) {
            if (!FileSystemHelper.ensureDirectoryExists(fileFolder)) {
                jfitLogger.severe("The folder \'" + fileFolder.getPath() + "\' does not exist, and could not be created.");
                return;
            }
        }
       
        String fileName = unqualifiedModuleName + "." + CALSourcePathMapper.INSTANCE.getFileExtension();
        File outputFile = fileFolder == null ? new File(fileName) : new File(fileFolder, fileName);
       
        jfitLogger.info("Writing file: " + outputFile.getAbsolutePath() + "..");
       
        boolean wroteFile;
       
        Writer writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(outputFile));
            writer.write(sourceText);
            wroteFile = true;
           
        } catch (IOException e) {
            jfitLogger.log(Level.SEVERE, "Error writing file: " + outputFile.getPath(), e);
            wroteFile = false;

        } finally {
            if (writer != null) {
                try {
                    writer.flush();
                    writer.close();
                } catch (IOException e) {
                    // Not much we can do about this.
                }
            }
        }
       
        if (wroteFile) {
            int nGeneratedFunctions = 0;
            int nGeneratedTypes = 0;
           
            int nTopLevelDefns = defn.getNTopLevelDefns();
            for (int i = 0; i < nTopLevelDefns; i++) {
                TopLevelSourceElement nthTopLevelDefn = defn.getNthTopLevelDefn(i);
               
                if (nthTopLevelDefn instanceof SourceModel.FunctionDefn.Foreign) {
                    nGeneratedFunctions++;
               
                } else if (nthTopLevelDefn instanceof SourceModel.TypeConstructorDefn.ForeignType) {
View Full Code Here

        // Instantiate the fit options.
        JFit.Options options = JFit.Options.makeOptions(moduleName, inputFiles, inputDirs, null, patterns, generationScope, excludeMethods, generatorLogger);
       
        // Create the fitter and fit.
        JFit jfit = new JFit(options, perspective.getWorkspace(), generatorLogger);
        final ModuleDefn defn = jfit.autoFit();         // null if an error occurred.

        // Deal with warnings/errors.
        Status capturedStatus = statusHandler.getStatus();
        if (capturedStatus.getSeverity().compareTo(Status.Severity.WARNING) >= 0) {
            String title = GeneratorMessages.getString("JFIMF_JavaForeignImportTitle");
View Full Code Here

        modifications = new SourceModifier();
       
        CompilerMessageLogger mlogger= new MessageLogger();

        embellishments.clear();
        ModuleDefn moduleDefn = SourceModelUtilities.TextParsing.parseModuleDefnIntoSourceModel(source, false, mlogger, embellishments);
                  
        if (moduleDefn == null) {
            //unable to parse module
            return null;
        }
       
        if (rangeToFormat == null && functionNames.isEmpty()) {
            //format the whole file
            String formatted = SourceModelCodeFormatter.formatCode(
                    moduleDefn,
                    SourceModelCodeFormatter.DEFAULT_OPTIONS,
                    embellishments
            );

            modifications.addSourceModification(
                    new SourceModification.ReplaceText(source, formatted, new SourcePosition(1, 1, moduleDefn.getModuleName().toString())));
   
        } else {           
            //visit module elements and format those in range
            moduleDefn.accept(this, null);
        }
        return modifications;
    }
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.SourceModel.ModuleDefn

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.