Package org.openquark.cal.compiler

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


            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

        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

        } 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

                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

                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

    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

        }

        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

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

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

TOP

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

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.