Examples of MessageLogger


Examples of org.openquark.cal.compiler.MessageLogger

    private void command_find (String argString) {
        String[] args = argString.split(" ");
        String targetArg = args[args.length - 1];

        List<SearchResult> searchResults = null;
        MessageLogger searchLogger = new MessageLogger();
       
        long searchStart = System.currentTimeMillis();
        if(args.length <= 1 || args[0].equals("all")) {
            iceLogger.log(Level.INFO, "Searching workspace for all occurrences of " + targetArg + "...");
            searchResults = workspaceManager.getWorkspace().getSourceMetrics().findAllOccurrences(targetArg, searchLogger);
        } else if(args[0].equals("ref")) {
            iceLogger.log(Level.INFO, "Searching workspace for references to " + targetArg + "...");
            searchResults = workspaceManager.getWorkspace().getSourceMetrics().findReferences(targetArg, searchLogger);
        } else if(args[0].equals("instByClass")) {
            iceLogger.log(Level.INFO, "Searching workspace for instances of class " + targetArg + "...");
            searchResults = workspaceManager.getWorkspace().getSourceMetrics().findInstancesOfClass(targetArg, searchLogger);
        } else if(args[0].equals("instByType")) {
            iceLogger.log(Level.INFO, "Searching workspace for classes that type " + targetArg + " is an instance of...");
            searchResults = workspaceManager.getWorkspace().getSourceMetrics().findTypeInstances(targetArg, searchLogger);
        } else if(args[0].equals("defn")) {
            iceLogger.log(Level.INFO, "Searching workspace for definition of " + targetArg + "...");
            searchResults = workspaceManager.getWorkspace().getSourceMetrics().findDefinition(targetArg, searchLogger);
        } else if(args[0].equals("constructions")) {
            iceLogger.log(Level.INFO, "Searching workspace for constructions of " + targetArg + "...");
            searchResults = workspaceManager.getWorkspace().getSourceMetrics().findConstructions(targetArg, searchLogger);
        } else {
            iceLogger.log(Level.INFO, "unrecognized search type '" + args[0] + "'");
        }
       
        if(searchResults != null) {
            for(final SearchResult searchResult : searchResults) {
                if(searchResult != null) {
                   
                    if (searchResult instanceof SearchResult.Precise) {
                       
                        SearchResult.Precise preciseSearchResult = (SearchResult.Precise)searchResult;
                       
                        StringBuilder searchResultBuffer = new StringBuilder();
                        searchResultBuffer.append(preciseSearchResult.getSourceRange().getSourceName());
                        searchResultBuffer.append(": (line ");
                        searchResultBuffer.append(preciseSearchResult.getSourceRange().getStartLine());
                        searchResultBuffer.append(", column ");
                        searchResultBuffer.append(preciseSearchResult.getSourceRange().getStartColumn());
                        searchResultBuffer.append(") - ");
                        searchResultBuffer.append(preciseSearchResult.getName().toSourceText());
                       
                        int pointerPos = 0;
                        String contextLine = preciseSearchResult.getContextLine();
                        String trimmedContextLine = null;
                        if(contextLine != null) {
                            trimmedContextLine = contextLine.trim();
                            searchResultBuffer.append(" - ");
                            pointerPos = searchResultBuffer.length();
                            searchResultBuffer.append(trimmedContextLine);
                        }
                       
                        iceLogger.log(Level.INFO, searchResultBuffer.toString());
                        if(pointerPos != 0) {
                            StringBuilder pointerBuffer = new StringBuilder(pointerPos + 1);
                           
                            for(int i = 0; i < pointerPos; i++) {
                                pointerBuffer.append(' ');
                            }
                           
                            int printableStartIndex = countLeftWhitespace(contextLine);
                            for(int i = printableStartIndex; i < preciseSearchResult.getContextLineIndex() ; i++) {
                                if(contextLine.charAt(i) == '\t') {
                                    pointerBuffer.append('\t');
                                } else {
                                    pointerBuffer.append(' ');
                                }
                            }
                           
                            int currentPos = pointerBuffer.length() + 1;
                            for(int i = preciseSearchResult.getContextLineIndex(); i < preciseSearchResult.getContextLineEndIndex(); i++) {
                                int width = SourcePosition.columnWidth(currentPos, contextLine.charAt(i));
                               
                                for(int j = 0; j < width; j++) {
                                    pointerBuffer.append('^');
                                    currentPos++;
                                }
                            }
                            iceLogger.log(Level.INFO, pointerBuffer.toString());
                        }
                    } else if (searchResult instanceof SearchResult.Frequency) {
                        SearchResult.Frequency freqSearchResult = (SearchResult.Frequency)searchResult;
                        int frequency = freqSearchResult.getFrequency();
                        SearchResult.Frequency.Type resultType = freqSearchResult.getType();
                       
                        String optionalS = (frequency == 1 ? "" : "s");
                       
                        String resultTypeString;
                        if (resultType == SearchResult.Frequency.Type.FUNCTION_REFERENCES) {
                            resultTypeString = "reference" + optionalS + " to ";
                        } else if (resultType == SearchResult.Frequency.Type.INSTANCE_METHOD_REFERENCES) {
                            resultTypeString = "instance method" + optionalS + " referencing ";
                        } else if (resultType == SearchResult.Frequency.Type.CLASS_CONSTRAINTS) {
                            resultTypeString = "class constraint" + optionalS + " referencing ";
                        } else if (resultType == SearchResult.Frequency.Type.CLASSES) {
                            resultTypeString = "instance" + optionalS + " for the type ";
                        } else if (resultType == SearchResult.Frequency.Type.INSTANCES) {
                            resultTypeString = "instance" + optionalS + " for the class ";
                        } else if (resultType == SearchResult.Frequency.Type.DEFINITION) {
                            resultTypeString = "definition" + optionalS + " of ";
                        } else if (resultType == SearchResult.Frequency.Type.IMPORT) {
                            resultTypeString = "import statement" + optionalS + " referencing ";
                        } else {
                            throw new IllegalStateException("Unknown search result type: " + resultType);
                        }
                       
                        String searchResultString = freqSearchResult.getModuleName() + ": " + frequency + " " + resultTypeString + freqSearchResult.getName();
                       
                        iceLogger.log(Level.INFO, "(Sourceless result) " + searchResultString);
                    } else {
                        iceLogger.log(Level.INFO, "Unknown search result: " + searchResult);
                    }
                }
            }
           
            long searchTime = System.currentTimeMillis() - searchStart;
           
            int nHits = 0;
            for (int i = 0, n = searchResults.size(); i < n; i++) {
                SearchResult result = searchResults.get(i);
                if (result instanceof SearchResult.Frequency) {
                    nHits += ((SearchResult.Frequency)result).getFrequency();
                } else {
                    nHits++;
                }
            }
           
            if(nHits == 1) {
                iceLogger.log(Level.INFO, "1 hit found in " + searchTime + "ms");
            } else {
                iceLogger.log(Level.INFO, nHits + " hits found in " + searchTime + "ms");
            }
       
            if(searchLogger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
                iceLogger.log(Level.WARNING, "Search results may be incomplete due to errors during search:");
                dumpCompilerMessages(searchLogger);
            }
        }
    }
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

        }

        synchronized (this.workspaceManager) {
           
            // 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){
                iceLogger.log(Level.INFO, "Attempt to qualify expression has failed because of errors: ");
                dumpCompilerMessages(logger);
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

        }
    }
   
    private QualifiedName qualifyExpression(String nameAsText) {
        // 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(nameAsText, null, null, logger, true);
        if (qualificationResults == null){
            iceLogger.log(Level.INFO, "Attempt to qualify expression has failed because of errors: ");
            dumpCompilerMessages(logger);
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

        }
    }
   
    private QualifiedName qualifyType(String typeAsText) {
        // 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(CAL_Prelude.Functions.undefined.getQualifiedName() + "::" + typeAsText, null, null, logger, true);
        if (qualificationResults == null){
            iceLogger.log(Level.INFO, "Attempt to qualify expression has failed because of errors: ");
            dumpCompilerMessages(logger);
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

            return QualifiedName.make(targetModule, typeAsText);
        }
    }
   
    private QualifiedName qualifyTypeClass(String typeClassName) {
        CompilerMessageLogger logger = new MessageLogger();
        TypeExpr typeExpr = getTypeChecker().getTypeFromString(typeClassName + " a => a", targetModule, logger);
       
        if (logger.getNErrors() > 0) {
            dumpCompilerMessages(logger);
            return null;
        }
       
        String typeString = typeExpr.toString(ScopedEntityNamingPolicy.FULLY_QUALIFIED);
View Full Code Here

Examples of org.openquark.cal.compiler.MessageLogger

       
        //initialize th CAL workspace and get entry points for the CAL functions
        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

Examples of org.openquark.cal.compiler.MessageLogger

    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

Examples of org.openquark.cal.compiler.MessageLogger

        }
    }
   
    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

Examples of org.openquark.cal.compiler.MessageLogger

        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

Examples of org.openquark.cal.compiler.MessageLogger

        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
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.