Examples of MessageLogger


Examples of org.openquark.cal.compiler.MessageLogger

        /// Create and compile a workspace through a BasicCALServices
        //
       
        WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
       
        MessageLogger msgLogger = new MessageLogger();
       
        StatusListener.StatusListenerAdapter statusListener = new StatusListener.StatusListenerAdapter() {
            /**
             * {@inheritDoc}
             */
            @Override
            public void setModuleStatus(StatusListener.Status.Module moduleStatus, ModuleName moduleName) {
                if (moduleStatus == StatusListener.SM_GENCODE) {
                    logger.fine("Compiling " + moduleName);
                }
            }
        };
       
        logger.info("Compiling CAL workspace...");
        calServices.compileWorkspace(statusListener, msgLogger);
       
        if (msgLogger.getNErrors() == 0) {
            logger.info("Compilation successful");
           
            ////
            /// We only run the CarBuilder if everything compiled properly without errors
            //
           
            CarBuilder.Monitor monitor = new CarBuilder.Monitor() {
                public boolean isCanceled() {
                    return false;
                }
                public void operationStarted(int nCars, int nTotalModules) {}
                public void showMessages(String[] messages) {
                    for (final String element : messages) {
                        logger.info(element);
                    }
                }
                public void carBuildingStarted(String carName, int nModules) {
                    logger.info("Creating the Car file " + carName);
                }
                public void processingModule(String carName, ModuleName moduleName) {
                    logger.info("Adding module " + moduleName + " to the Car...");
                }
                public void carBuildingDone(String carName) {
                    logger.info("Done creating the Car file " + carName);
                }
                public void operationDone() {
                    logger.info("All done");
                }
            };
           
            ///
            // Command line syntax:
            //
            // [-notVerbose] [-keepsource] [-nocws | -nosuffix] [-s] [-excludeCarsInDirs ... --] [-excludeCarJarsInDirs ... --] [-jar] outputDirectory [carSpecName1 carSpecName2...]
            // OR
            // [-notVerbose] [-keepsource] [-nocws | -nosuffix] [-s] [-excludeCarsInDirs ... --] [-excludeCarJarsInDirs ... --] [-jar] -d outputDirectory
           
            boolean verboseMode = true; // default: verbose
            if (arguments.getArgument().equals("-notVerbose")) {
                verboseMode = false;
                arguments.consumeArgument();
            }
           
            boolean shouldBuildSourcelessModules = true; // default: generate sourceless modules
            if (arguments.getArgument().equals("-keepsource")) {
                shouldBuildSourcelessModules = false;
                arguments.consumeArgument();
            }
           
            boolean shouldGenerateCorrespWorspaceDecl = true; // default: generated the cws files
            boolean noCarSuffixInWorkspaceDeclName = false;   // default: generated cws files end with .car.cws
           
            if (arguments.getArgument().equals("-nocws")) {
                shouldGenerateCorrespWorspaceDecl = false;
                arguments.consumeArgument();
            } else if (arguments.getArgument().equals("-nosuffix")) {
                noCarSuffixInWorkspaceDeclName = true;
                arguments.consumeArgument();
            }
           
            boolean shouldSkipModulesAlreadyInCars = false; // default: do not skip modules already in Cars
            if (arguments.getArgument().equals("-s")) {
                shouldSkipModulesAlreadyInCars = true;
                arguments.consumeArgument();
            }
           
            Set<String> carsToExclude = new HashSet<String>(additionalCarsToExclude);
            if (arguments.getArgument().equals("-excludeCarsInDirs")) {
                arguments.consumeArgument();
               
                while (!arguments.getArgument().equals("--")) {
                    File directory = new File(arguments.getAndConsumeArgument(), "Car");
                   
                    File[] files = directory.listFiles();
                    if (files == null) {
                        logger.warning("Folder does not exist: " + directory);
                    } else {
                        for (final File element : files) {
                            carsToExclude.add(element.getName());
                        }
                    }
                }
                arguments.consumeArgument(); // consume the -- delimiter
            }
           
            if (arguments.getArgument().equals("-excludeCarJarsInDirs")) {
                arguments.consumeArgument();
               
                while (!arguments.getArgument().equals("--")) {
                    File directory = new File(arguments.getAndConsumeArgument());
                   
                    File[] files = directory.listFiles();
                    if (files == null) {
                        logger.warning("Folder does not exist: " + directory);
                    } else {
                        for (final File element : files) {
                            String fileName = element.getName();
                            if (fileName.endsWith(CarBuilder.DOT_CAR_DOT_JAR)) {
                                String carName = fileName.substring(0, fileName.length() - 4); // chop ".jar" off the end
                                carsToExclude.add(carName);
                            }
                        }
                    }
                }
                arguments.consumeArgument(); // consume the -- delimiter
            }
           
            boolean shouldGenerateCarJarSuffix = false; // default: generate Cars and not Car-jars.
            if (arguments.getArgument().equals("-jar")) {
                shouldGenerateCarJarSuffix = true;
                arguments.consumeArgument();
            }
           
            if (verboseMode) {
                System.out.println();
                System.out.println(workspaceManager.getDebugInfo());
                System.out.println();
            }
           
            CarBuilder.BuilderOptions options = new CarBuilder.BuilderOptions(
                shouldSkipModulesAlreadyInCars,
                shouldGenerateCorrespWorspaceDecl,
                noCarSuffixInWorkspaceDeclName,
                shouldBuildSourcelessModules,
                carsToExclude,
                shouldGenerateCarJarSuffix);
               
            if (arguments.getArgument().equals("-d")) {
                // the user wants one Car per workspace declaration file
               
                arguments.consumeArgument();
               
                final String outputDir = arguments.getAndConsumeArgument();
               
                arguments.noMoreArgumentsAllowed();
               
                final File outputDirectory = new File(outputDir);
               
                try {
                    String[] carsBuilt = CarBuilder.buildOneCarPerWorkspaceDeclaration(workspaceManager, monitor, outputDirectory, options);
                    return carsBuilt;
                   
                } catch (IOException e) {
                    logger.info("Error occurred generating the Car files: " + e.getMessage());
                    throw new OperationFailedException();
                }
               
               
            } else {
                // the user wants just one Car for all modules in the workspace
                if (!carsToExclude.equals(additionalCarsToExclude)) {
                    logger.info("The option -excludeCarsInDirs does not apply for building just one Car. Ignoring...");
                }
               
                final String carName = CarBuilder.makeCarNameFromSourceWorkspaceDeclName(workspaceDeclarationName);
                   
                final String outputDir = arguments.getAndConsumeArgument();
               
                final File outputDirectory = new File(outputDir);
               
                CarBuilder.Configuration config =
                    CarBuilder.Configuration.makeConfigOptionallySkippingModulesAlreadyInCars(workspaceManager, options);
               
                for (Iterator<String> it = arguments.getRemainingArgumentsIterator(); it.hasNext(); ) {
                    String carSpecName = it.next();
                    File specFile = new File(carSpecName);
                    config.addFileBasedCarSpec(specFile.getName(), specFile);
                }
               
                config.setMonitor(monitor);
               
                try {
                    boolean notCanceled = CarBuilder.buildCar(config, outputDirectory, carName, options);
                    if (notCanceled) {
                        return new String[] {carName};
                    }
                   
                } catch (IOException e) {
                    logger.info("Error occurred generating the Car file: " + e.getMessage());
                    throw new OperationFailedException();
                }
            }
           
        } else {
            logger.severe("Compilation failed:");
            List<CompilerMessage> messages = msgLogger.getCompilerMessages();
            for (int i = 0, n = messages.size(); i < n; i++) {
                logger.info("  " + messages.get(i).toString());
            }
           
            throw new OperationFailedException();
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

                }
            }
        });

       
        CompilerMessageLogger ml = new MessageLogger();
       
        // 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());
        }
       
        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);
            workspaceManager.compile(ml, dirtyOnly, null, options);
        }
       
        long compileTime = System.currentTimeMillis() - startCompile;
       
        boolean compilationSucceeded;
        if (ml.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
            // Errors
            jfitLogger.severe("Compilation unsuccessful because of errors:");
            compilationSucceeded = false;
        } else {
            // Compilation successful
            jfitLogger.fine("Compilation successful");
            compilationSucceeded = true;
        }
       
        // Write out compiler messages
        java.util.List<CompilerMessage> errs = ml.getCompilerMessages();
        int errsSize = errs.size();
        for (int i = 0; i < errsSize; i++) {
            CompilerMessage err = errs.get(i);
            jfitLogger.info("  " + err.toString());
        }
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

                HashSet<EntryPointSpec> required = new HashSet<EntryPointSpec>();

                required.addAll(cache.keySet());
                required.addAll(entryPointSpecs);

                CompilerMessageLogger compilerLogger = new MessageLogger();
                      
                List<EntryPointSpec> requiredList = new ArrayList<EntryPointSpec>(required);
                //compile the entry points
                List<EntryPoint> entryPoints
                = programModelManager.getCompiler().getEntryPoints(requiredList, moduleName, compilerLogger);

                if (compilerLogger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
                    StringBuffer sb = new StringBuffer();
                    sb.append("Failed to generate entry points for module '");
                    sb.append(moduleName);
                    sb.append(General.SYSTEM_EOL);
                    for(CompilerMessage msg : compilerLogger.getCompilerMessages()) {
                        sb.append(msg);
                        sb.append(General.SYSTEM_EOL);
                    }

                    //all of the cached entry points are invalid now.
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

     * @param typeChecker TypeChecker the type checker to use to generate the type
     * @return TypeExpr a new TypeExpr for the target sc.
     */
    protected static final TypeExpr getNewTargetTypeExpr(Target target, ModuleName moduleName, TypeChecker typeChecker) {
        AdjunctSource scDefinition = target.getTargetDef(null, typeChecker.getTypeCheckInfo(moduleName).getModuleTypeInfo());
        CompilerMessageLogger logger = new MessageLogger ();
        return typeChecker.checkFunction(scDefinition, moduleName, logger);
    }
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

        }
        // Get supercombinator defined at the current target and its name
        ModuleTypeInfo currentModuleTypeInfo = getWorkspaceManager().getWorkspace().getMetaModule(getTargetModule()).getTypeInfo();
        AdjunctSource scDef = target.getTargetDef(null, currentModuleTypeInfo);

        CompilerMessageLogger logger = new MessageLogger ();
        TypeExpr targetTypeExpr = getTypeChecker().checkFunction(scDef, targetModule, logger);
       
        if (targetTypeExpr == null) {
            VALUENODE_LOGGER.log(Level.SEVERE, "Error determining gem execution type.  Text: \n" + scDef);
            throw new ProgramCompileException(CompilerMessage.Severity.ERROR, logger.getFirstError());
        }

        // Determine the overall output TypeExpr of the target.
        int numArgs = inputPolicies.length;
        TypeExpr[] targetTypePieces = targetTypeExpr.getTypePieces(numArgs);
                                           
        TypeExpr outputTypeExpr;
        try {
                              
            TypeExpr[] specializedTargetTypePieces =
                TypeExpr.patternMatchPieces(argTypes, targetTypePieces, currentModuleTypeInfo);
            outputTypeExpr = specializedTargetTypePieces[numArgs];  
                                   
        } catch (TypeException e) {
            // What to do?  You really don't want to be throwing an uncaught exception here.
            VALUENODE_LOGGER.log(Level.WARNING, "Error determining gem execution output type.");
            e.printStackTrace();
            outputTypeExpr = targetTypePieces[numArgs];
        }
       
        TypeExpr declaredType = outputTypeExpr;
        for (int i = numArgs - 1; i >= 0 ; i--) {
            declaredType = TypeExpr.makeFunType(argTypes[i], declaredType);
        }

        // Update the scDef with the type declaration.
        scDef = target.getTargetDef(declaredType, currentModuleTypeInfo);

        outputValueNode = valueNodeBuilderHelper.getValueNodeForTypeExpr(outputTypeExpr);
        if (outputValueNode == null) {
            // Unable to create an output value node for type: {declaredType}
            throw new ProgramCompileException(CompilerMessage.Severity.ERROR,
                    new CompilerMessage(new MessageKind.Error.UnableToCreateOutputValueNode(declaredType.toString())));
        }
       
        OutputPolicy outputPolicy = null;
        outputPolicy = outputValueNode.getOutputPolicy();
        if (outputPolicy == null) {
            // Unable to retrieve an output policy for type: {declaredType}
            throw new ProgramCompileException(CompilerMessage.Severity.ERROR,
                    new CompilerMessage(new MessageKind.Error.UnableToRetrieveAnOutputPolicy(declaredType.toString())));
        }

        if (getShowConsoleInfo()) {
            System.out.println("Executing:\n" + scDef);
        }
       
        // Compile the definition, indicating that this is an adjunct
        QualifiedName targetName = QualifiedName.make(getTargetModule(), getTarget().getTargetName(currentModuleTypeInfo));
        entryPoint = getWorkspaceManager().getCompiler().getEntryPoint(scDef, EntryPointSpec.make(targetName, inputPolicies, outputPolicy), targetName.getModuleName(), logger);
        if (entryPoint == null) {       
            throw new ProgramCompileException(CompilerMessage.Severity.ERROR, logger.getFirstError());
        }
    }
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

            return;
        }
       
        // Okay, the basics check out.
        System.out.print("Renaming " + oldNameString + " to " + newNameString + "...");
        CompilerMessageLogger messageLogger = new MessageLogger();
        Refactorer refactorer = new Refactorer.Rename(getWorkspaceManager().getWorkspace().asModuleContainer(), getWorkspaceManager().getTypeChecker(), oldName, newName, category);

        refactorer.setStatusListener(new Refactorer.StatusListener() {
            public void willUseResource(ModuleSourceDefinition resource) {
                System.out.print(".");
            }
            public void doneUsingResource(ModuleSourceDefinition resource) {
            }
        });

        refactorer.calculateModifications(messageLogger);

        if(messageLogger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
            System.out.println("");
            dumpCompilerMessages(messageLogger);
            return;
        }

        refactorer.apply(messageLogger);
        System.out.println("");

        if(messageLogger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
            dumpCompilerMessages(messageLogger);
            return;
        }

        if(!compileWorkspace(false, true, false)) {
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

        Refactorer refactorer = new Refactorer.PrettyPrint(
                getWorkspaceManager().getWorkspace().asModuleContainer(),
                moduleName, startLine, 0, endLine, 0, functionNames);

        CompilerMessageLogger messageLogger = new MessageLogger();

        refactorer.calculateModifications(messageLogger);

        if (messageLogger.getNErrors() == 0) {
            // apply the changes, unless we encountered errors while calculating them
            refactorer.apply(messageLogger);
        }

        if (messageLogger.getNErrors() > 0) {
            dumpCompilerMessages(messageLogger);
            return;
        }

        iceLogger.log(Level.INFO, "Pretty printing done.");
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

        } else {
            iceLogger.log(Level.INFO, "unrecognized refactoring type '" + args[0] + "'");
            return;
        }
       
        CompilerMessageLogger messageLogger = new MessageLogger();
       
        refactorer.calculateModifications(messageLogger);

        if (messageLogger.getNErrors() == 0) {
            // apply the changes, unless we encountered errors while calculating them
            refactorer.apply(messageLogger);
        }
           
        if (messageLogger.getNErrors() > 0) {
            dumpCompilerMessages(messageLogger);
            return;
        }

        // Output statistics, if any
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

                int nextSpace = args.indexOf(' ');
                String typeClassName = args.substring(0, nextSpace);
                String instanceTypeString = args.substring(nextSpace).trim();
               
                QualifiedName qualifiedTypeClassName = resolveTypeClassName(typeClassName);
                CompilerMessageLogger logger = new MessageLogger();
                TypeExpr instanceTypeExpr = getTypeChecker().getTypeFromString(instanceTypeString, targetModule, logger);
               
                if (logger.getNErrors() > 0) {
                    dumpCompilerMessages(logger);
                } else if (qualifiedTypeClassName != null) {
                    ClassInstanceIdentifier id;
                    if (instanceTypeExpr instanceof RecordType) {
                       
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

                nextSpace = args.indexOf(' ');
                String typeClassName = args.substring(0, nextSpace);
                String instanceTypeString = args.substring(nextSpace).trim();
               
                QualifiedName qualifiedTypeClassName = resolveTypeClassName(typeClassName);
                CompilerMessageLogger logger = new MessageLogger();
                TypeExpr instanceTypeExpr = getTypeChecker().getTypeFromString(instanceTypeString, targetModule, logger);
               
                if (logger.getNErrors() > 0) {
                    dumpCompilerMessages(logger);
                } else if (qualifiedTypeClassName != null) {
                    ClassInstanceIdentifier id;
                    if (instanceTypeExpr instanceof RecordType) {
                       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.