Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.CompilerMessageLogger


    private void runCAF (String cafName) {
        if (cafName == null || cafName.length () == 0) {
            return;
        }
       
        CompilerMessageLogger logger = new MessageLogger();
        EntryPoint entryPoint = getCompiler().getEntryPoint(
            EntryPointSpec.make(EntryPointImpl.makeEntryPointName (cafName)), targetModule, logger);
        if (entryPoint == null) {
            iceLogger.log(Level.INFO, "CAL: Compilation unsuccessful because of errors:");
            dumpCompilerMessages(logger);
View Full Code Here


        }
    }
   
    protected String qualifyCodeExpression (String expressionText) {
        // Qualify unqualified symbols in code, if unambiguous
        CompilerMessageLogger logger = new MessageLogger();
        CodeAnalyser analyser = new CodeAnalyser(getTypeChecker(), getWorkspaceManager().getModuleTypeInfo(targetModule), false, false);
        CodeAnalyser.QualificationResults qualificationResults = analyser.qualifyExpression(expressionText, null, null, logger, true);
        if (qualificationResults == null){
            outputStream.println("Attempt to qualify expression has failed because of errors: ");
            dumpCompilerMessages(logger);
View Full Code Here

        if (this.workspaceManager == null) {
            return null;
        }
       
        synchronized (this.workspaceManager) {
            CompilerMessageLogger ml = new MessageLogger ();
           
            // Compile it, indicating that this is an adjunct
            EntryPoint targetEntryPoint =
                getCompiler().getEntryPoint(
                    new AdjunctSource.FromText(scDef),
                    EntryPointSpec.make(QualifiedName.make(targetModule, targetName), new InputPolicy[]{}, OutputPolicy.DEFAULT_OUTPUT_POLICY),
                        targetModule,
                        ml);
                   
            if (targetEntryPoint == null) {       
                iceLogger.log(Level.INFO, "CAL: Compilation unsuccessful because of errors:");
                // Write out compiler messages
                List<CompilerMessage> compilerMessages = ml.getCompilerMessages();
                for (final CompilerMessage message : compilerMessages) {
                    iceLogger.log(Level.INFO, "  " + message.toString());
                }
                return null;
            }
View Full Code Here

        boolean calcClassSize =
            getMachineType() == MachineType.LECC &&
            repository != null && (forceCodeRegen || repository.isEmpty());
       
        synchronized (this.workspaceManager) {
            CompilerMessageLogger ml = new MessageLogger();
           
            if (initialize) {
                // Init and compile the workspace.
                Status initStatus = new Status("Init status.");
                workspaceManager.initWorkspace(streamProvider, initStatus);
               
                if (initStatus.getSeverity() != Status.Severity.OK) {
                    ml.logMessage(initStatus.asCompilerMessage());
                }
            }
           
            ModuleLoadListener moduleLoadListener = new ModuleLoadListener();
           
            long startCompile = System.currentTimeMillis();
           
            // If there are no errors go ahead and compile the workspace.
            if (ml.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) < 0) {
                WorkspaceManager.CompilationOptions options = new WorkspaceManager.CompilationOptions();
                options.setForceCodeRegeneration(forceCodeRegen);
                if (!forceCodeRegen && !dirtyOnly && !initialize) {
                    options.setIgnoreCompiledModuleInfo(true);
                }

                workspaceManager.compile(ml, dirtyOnly, moduleLoadListener, options);
            }
           
            long compileTime = System.currentTimeMillis() - startCompile;
           
            if (ml.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
                // Errors
                iceLogger.log(Level.INFO, "CAL: Compilation unsuccessful because of errors:");
                calcClassSize = false;
            } else {
                // Compilation successful
                iceLogger.log(Level.INFO, "CAL: Compilation successful");
            }
           
            // Write out compiler messages
            List<CompilerMessage> errs = ml.getCompilerMessages();
            for (final CompilerMessage err : errs) {
                iceLogger.log(Level.INFO, "  " + err.toString());
            }
           
            // DIAG
            iceLogger.log(Level.INFO, "CAL: Finished compiling in " + compileTime + "ms");
           
            if (!initialize) {
                changeToPreferredWorkingModule();
            }
           
            displayModulesLoadedStats(moduleLoadListener.getLoadedModuleNames());
           
            if (calcClassSize && getMachineType() == MachineType.LECC) {
                command_classFileSize(true, false);
            }

            // If we have initialized a new workspace we need to reset the run state.
            // i.e. we need to discard the current execution context, executor, etc.
            if (initialize) {
                resetRunState();
            }
           
           
            return (ml.getNErrors() == 0);
        }
    }
View Full Code Here

        final String WORKSPACE_FILE_NAME = "cal.benchmark.cws"
        List<EntryPoint> entryPoints;

        calServices = BasicCALServices.makeCompiled(WORKSPACE_FILE_NAME, new MessageLogger());

        CompilerMessageLogger messageLogger = new MessageLogger();       
        Compiler compiler = calServices.getCompiler();  

        ModuleName moduleName= ModuleName.make("Cal.Benchmarks.Shootout.ChameneosThreadBody");

        List<QualifiedName> functionalAgentNames = new ArrayList<QualifiedName>();
        functionalAgentNames.add(QualifiedName.make(moduleName, "chameneos"));
        functionalAgentNames.add(QualifiedName.make(moduleName, "makeEmptyRoom"));
        functionalAgentNames.add(QualifiedName.make(moduleName, "Red"));
        functionalAgentNames.add(QualifiedName.make(moduleName, "Yellow"));
        functionalAgentNames.add(QualifiedName.make(moduleName, "Blue"));

        CALExecutor executor = calServices.getWorkspaceManager().makeExecutorWithNewContextAndDefaultProperties();

        entryPoints = compiler.getEntryPoints(EntryPointSpec.buildListFromQualifiedNames(functionalAgentNames),
            moduleName, messageLogger);
       
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
            System.exit(1);
        }

        stopWatch.stop();
        System.err.println("Startup took: " + stopWatch);
View Full Code Here

       
        stopWatch.start();
       
        calServices = BasicCALServices.makeCompiled(WORKSPACE_FILE_NAME, new MessageLogger());
       
        CompilerMessageLogger messageLogger = new MessageLogger();       
        Compiler compiler = calServices.getCompiler();  
       
        ModuleName moduleName= ModuleName.make("Cal.Benchmarks.Shootout.MessageThreadBody");
       
        threadBody = compiler.getEntryPoint(
            EntryPointSpec.make(QualifiedName.make("Cal.Benchmarks.Shootout.MessageThreadBody", "threadBody")),
            moduleName, messageLogger);
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }

        stopWatch.stop();
        System.err.println("startup took: " + stopWatch);
       
View Full Code Here

        if (module == null) {
            throw new IllegalArgumentException("g.CodeGenerator.generateSCCode() cannot have a null module.");
        }

        CompilerMessageLogger generateLogger = new MessageLogger();
       
        try {

            informStatusListeners(StatusListener.SM_GENCODE, module.getName());
            currentModule = module;

            for (final MachineFunction mf : module.getFunctions()) {
               
                GMachineFunction gmf = (GMachineFunction)mf;
               
                if (gmf.isCodeGenerated()) {
                    continue;
                }
                if (gmf.getAliasOf() != null || gmf.getLiteralValue() != null) {
                    gmf.setCodeGenerated(true);
                    continue;
                }

                try {
                    generateSCCode (gmf);
                } catch (CodeGenerationException e) {
                    try {
                        // Note: The code generation could potentially have failed because a foreign type or a foreign function's corresponding Java entity
                        // could not be resolved. (In this case the CodeGenerationException would be wrapping an UnableToResolveForeignEntityException)
                       
                        final Throwable cause = e.getCause();
                        if (cause instanceof UnableToResolveForeignEntityException) {
                            generateLogger.logMessage(((UnableToResolveForeignEntityException)cause).getCompilerMessage());
                        }
                       
                        // Code generation aborted. Error generating code for: {cl.getQualifiedName()}
                        generateLogger.logMessage(new CompilerMessage(new MessageKind.Error.CodeGenerationAborted(gmf.getQualifiedName().getQualifiedName()), e));
                    } catch (CompilerMessage.AbortCompilation e2) {/* Ignore exceptions generated by the act of logging. */}
                    return generateLogger.getMaxSeverity();
                }
            }


            fixupPushGlobals (module);

        } catch (Exception e) {
            try {
                if (generateLogger.getNErrors() > 0) {
                    //if an error occurred previously, we continue to compile the program to try to report additional
                    //meaningful compilation errors. However, this can produce spurious exceptions related to the fact
                    //that the program state does not satisfy preconditions because of the initial error(s). We don't
                    //report the spurious exception as an internal coding error.
                    generateLogger.logMessage(new CompilerMessage(new MessageKind.Fatal.UnableToRecoverFromCodeGenErrors(module.getName())));
                } else {                              
                    generateLogger.logMessage(new CompilerMessage(new MessageKind.Fatal.CodeGenerationAbortedDueToInternalCodingError(module.getName()), e));
                }                                                                           
            } catch (CompilerMessage.AbortCompilation ace) {
                /* Ignore exceptions generated by the act of logging. */
            }
        } catch (Error e) {
            try {
                generateLogger.logMessage(new CompilerMessage(new MessageKind.Error.CodeGenerationAbortedWithException(module.getName(), e)));
            } catch (CompilerMessage.AbortCompilation ace) {
                /* Ignore exceptions generated by the act of logging. */
            }
        } finally {
            if (logger != null) {
                // Log messages to the passed-in logger.
                try {
                    logger.logMessages(generateLogger);
                } catch (CompilerMessage.AbortCompilation e) {
                    /* Ignore exceptions generated by the act of logging. */
                }
            }
        }

        return generateLogger.getMaxSeverity();
    }
View Full Code Here

        //compute the necessary imports
        if (imports == null) {
            newModule = SourceModelUtilities.ImportAugmenter.augmentWithImports(newModule);
        }
       
        CompilerMessageLogger logger = new MessageLogger();
       
        //add the module to the workspace
        CompilerMessage.Severity errorLevel = addNewModule(new SourceModelModuleSource(newModule), logger);
       
        if (errorLevel.compareTo(CompilerMessage.Severity.ERROR) >= 0) {
View Full Code Here

    /**
     * Compile the workspace.
     * @return whether the workspace compiled successfully.
     */
    private boolean compileWorkspace() {
        CompilerMessageLogger ml = new MessageLogger();

        calLogger.fine("Compiling workspace..");
       
        // Init and compile the workspace.
        Status initStatus = new Status("Init status.");
        workspaceManager.initWorkspace(getStreamProvider(), false, initStatus);

        if (initStatus.getSeverity() != Status.Severity.OK) {
            ml.logMessage(initStatus.asCompilerMessage());
        }

        long startCompile = System.currentTimeMillis();

        // If there are no errors go ahead and compile the workspace.
        if (ml.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) < 0) {
            workspaceManager.compile(ml, true, null);
        }

        long compileTime = System.currentTimeMillis() - startCompile;

        // Write out compiler messages
        writeOutCompileResult(ml);

        int nModules = workspaceManager.getModuleNamesInProgram().length;
        calLogger.fine("CAL: Finished compiling " + nModules + " modules in " + compileTime + "ms\n");

        return ml.getNErrors() == 0;
    }
View Full Code Here

         * CALServicesHelper constructor.
         */
        public CALServicesHelper() throws BusinessObjectsException {
            boolean compilationSuccessful = false;
           
            CompilerMessageLogger messageLogger = new MessageLogger();
           
            BasicCALServices newCalServices = null;
            try {
                newCalServices = BasicCALServices.make (WORKSPACE_FILE_PROPERTY,
                        DEFAULT_WORKSPACE_FILE, DEFAULT_WORKSPACE_CLIENT_ID);
               
                if (newCalServices != null) {
                    // If there's a local cache, the workspace will use it, rather than the modules in the repo
                    // ...so if the cache is out of date, now's the time to synch
                    compilationSuccessful = newCalServices.compileWorkspace(null, messageLogger);
                }
            }
            catch (Throwable t) {
                t.printStackTrace();
               
                newCalServices = null;
            }
           
            if ((newCalServices == null) || !compilationSuccessful){
                String message = "";
                if (messageLogger.getNErrors() > 0) {
                    StringBuffer msg = new StringBuffer("Failed to compile workspace:");
                    for (final CompilerMessage cm : messageLogger.getCompilerMessages()) {
                        msg.append("\n");
                        msg.append(cm);
                    }
   
                    message = msg.toString();
View Full Code Here

TOP

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

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.