Search in sources :

Example 6 with PhasedUnit

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon-compiler by ceylon.

the class CeylonEnter method typeCheck.

private void typeCheck() {
    final java.util.List<PhasedUnit> listOfUnits = phasedUnits.getPhasedUnits();
    // Delegate to an external typechecker (e.g. the IDE build)
    compilerDelegate.typeCheck(listOfUnits);
    if (sp != null) {
        sp.clearLine();
        sp.log("Preparation phase");
    }
    int size = listOfUnits.size();
    int i = 1;
    // This phase is proper to the Java backend 
    ForcedCaptureVisitor fcv = new ForcedCaptureVisitor();
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(1, i++, size, pu);
        Unit unit = pu.getUnit();
        final CompilationUnit compilationUnit = pu.getCompilationUnit();
        compilationUnit.visit(fcv);
        for (Declaration d : unit.getDeclarations()) {
            if (d instanceof TypedDeclaration && !(d instanceof Setter) && // skip already captured members
            !d.isCaptured()) {
                compilationUnit.visit(new MethodOrValueReferenceVisitor((TypedDeclaration) d));
            }
        }
    }
    UnsupportedVisitor uv = new UnsupportedVisitor();
    JvmMissingNativeVisitor mnv = new JvmMissingNativeVisitor(modelLoader);
    BoxingDeclarationVisitor boxingDeclarationVisitor = new CompilerBoxingDeclarationVisitor(gen);
    BoxingVisitor boxingVisitor = new CompilerBoxingVisitor(gen);
    DeferredVisitor deferredVisitor = new DeferredVisitor();
    AnnotationModelVisitor amv = new AnnotationModelVisitor(gen);
    DefiniteAssignmentVisitor dav = new DefiniteAssignmentVisitor();
    TypeParameterCaptureVisitor tpCaptureVisitor = new TypeParameterCaptureVisitor();
    InterfaceVisitor localInterfaceVisitor = new InterfaceVisitor();
    // Extra phases for the compiler
    // boxing visitor depends on boxing decl
    i = 1;
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(2, i++, size, pu);
        pu.getCompilationUnit().visit(uv);
    }
    i = 1;
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(3, i++, size, pu);
        pu.getCompilationUnit().visit(boxingDeclarationVisitor);
    }
    i = 1;
    // the others can run at the same time
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(4, i++, size, pu);
        CompilationUnit compilationUnit = pu.getCompilationUnit();
        compilationUnit.visit(mnv);
        compilationUnit.visit(boxingVisitor);
        compilationUnit.visit(deferredVisitor);
        compilationUnit.visit(amv);
        compilationUnit.visit(dav);
        compilationUnit.visit(tpCaptureVisitor);
        compilationUnit.visit(localInterfaceVisitor);
    }
    i = 1;
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(5, i++, size, pu);
        CompilationUnit compilationUnit = pu.getCompilationUnit();
        compilationUnit.visit(new WarningSuppressionVisitor<Warning>(Warning.class, pu.getSuppressedWarnings()));
    }
    collectTreeErrors(true, true);
}
Also used : CeylonCompilationUnit(com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) TypeParameterCaptureVisitor(com.redhat.ceylon.compiler.java.codegen.TypeParameterCaptureVisitor) Warning(com.redhat.ceylon.compiler.typechecker.analyzer.Warning) UsageWarning(com.redhat.ceylon.compiler.typechecker.analyzer.UsageWarning) AnnotationModelVisitor(com.redhat.ceylon.compiler.java.codegen.AnnotationModelVisitor) UnsupportedVisitor(com.redhat.ceylon.compiler.java.codegen.UnsupportedVisitor) CompilerBoxingDeclarationVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingDeclarationVisitor) CeylonCompilationUnit(com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) Unit(com.redhat.ceylon.model.typechecker.model.Unit) JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) CeylonPhasedUnit(com.redhat.ceylon.compiler.java.tools.CeylonPhasedUnit) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) DefiniteAssignmentVisitor(com.redhat.ceylon.compiler.java.codegen.DefiniteAssignmentVisitor) InterfaceVisitor(com.redhat.ceylon.compiler.java.codegen.InterfaceVisitor) CeylonPhasedUnit(com.redhat.ceylon.compiler.java.tools.CeylonPhasedUnit) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) JvmMissingNativeVisitor(com.redhat.ceylon.compiler.java.codegen.JvmMissingNativeVisitor) DeferredVisitor(com.redhat.ceylon.compiler.java.codegen.DeferredVisitor) CompilerBoxingVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingVisitor) Setter(com.redhat.ceylon.model.typechecker.model.Setter) CompilerBoxingVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingVisitor) BoxingVisitor(com.redhat.ceylon.compiler.java.codegen.BoxingVisitor) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) BoxingDeclarationVisitor(com.redhat.ceylon.compiler.java.codegen.BoxingDeclarationVisitor) CompilerBoxingDeclarationVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingDeclarationVisitor)

Example 7 with PhasedUnit

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon-compiler by ceylon.

the class CeylonDocTool method copySourceFiles.

private void copySourceFiles() throws FileNotFoundException, IOException {
    for (PhasedUnit pu : phasedUnits) {
        Package pkg = pu.getUnit().getPackage();
        if (!shouldInclude(pkg)) {
            continue;
        }
        File file = new File(getFolder(pu.getPackage()), pu.getUnitFile().getName() + ".html");
        File dir = file.getParentFile();
        if (!dir.exists() && !dir.mkdirs()) {
            throw new IOException(CeylondMessages.msg("error.couldNotCreateDirectory", file));
        }
        Writer writer = openWriter(file);
        try {
            Markup markup = new Markup(writer);
            markup.write("<!DOCTYPE html>");
            markup.open("html xmlns='http://www.w3.org/1999/xhtml'");
            markup.open("head");
            markup.tag("meta charset='UTF-8'");
            markup.around("title", pu.getUnit().getFilename());
            markup.tag("link href='" + getResourceUrl(pkg, "favicon.ico") + "' rel='shortcut icon'");
            markup.tag("link href='" + getResourceUrl(pkg, "ceylon.css") + "' rel='stylesheet' type='text/css'");
            markup.tag("link href='" + getResourceUrl(pkg, "ceylondoc.css") + "' rel='stylesheet' type='text/css'");
            markup.tag("link href='http://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'");
            markup.open("script type='text/javascript'");
            markup.write("var resourceBaseUrl = '" + getResourceUrl(pkg, "") + "'");
            markup.close("script");
            markup.around("script src='" + getResourceUrl(pkg, "jquery-1.8.2.min.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "rainbow.min.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "rainbow.linenumbers.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "ceylon.js") + "' type='text/javascript'");
            markup.around("script src='" + getResourceUrl(pkg, "ceylondoc.js") + "' type='text/javascript'");
            markup.close("head");
            markup.open("body", "pre data-language='ceylon' style='font-family: Inconsolata, Monaco, Courier, monospace'");
            // XXX source char encoding
            BufferedReader input = new BufferedReader(new InputStreamReader(pu.getUnitFile().getInputStream()));
            try {
                String line = input.readLine();
                while (line != null) {
                    markup.text(line, "\n");
                    line = input.readLine();
                }
            } finally {
                input.close();
            }
            markup.close("pre", "body", "html");
        } finally {
            writer.close();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Package(com.redhat.ceylon.model.typechecker.model.Package) IOException(java.io.IOException) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Example 8 with PhasedUnit

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon-compiler by ceylon.

the class CeylonDocTool method warningMissingThrows.

protected void warningMissingThrows(Declaration d) {
    if (ignoreMissingThrows) {
        return;
    }
    final Scope scope = d.getScope();
    final PhasedUnit unit = getUnit(d);
    final Node node = getNode(d);
    if (scope == null || unit == null || unit.getUnit() == null || node == null || !(d instanceof FunctionOrValue)) {
        return;
    }
    List<Type> documentedExceptions = new ArrayList<Type>();
    for (Annotation annotation : d.getAnnotations()) {
        if (annotation.getName().equals("throws")) {
            String exceptionName = annotation.getPositionalArguments().get(0);
            Declaration exceptionDecl = scope.getMemberOrParameter(unit.getUnit(), exceptionName, null, false);
            if (exceptionDecl instanceof TypeDeclaration) {
                documentedExceptions.add(((TypeDeclaration) exceptionDecl).getType());
            }
        }
    }
    final List<Type> thrownExceptions = new ArrayList<Type>();
    node.visitChildren(new Visitor() {

        @Override
        public void visit(Tree.Throw that) {
            Expression expression = that.getExpression();
            if (expression != null) {
                thrownExceptions.add(expression.getTypeModel());
            } else {
                thrownExceptions.add(unit.getUnit().getExceptionType());
            }
        }

        @Override
        public void visit(Tree.Declaration that) {
        // the end of searching
        }
    });
    for (Type thrownException : thrownExceptions) {
        boolean isDocumented = false;
        for (Type documentedException : documentedExceptions) {
            if (thrownException.isSubtypeOf(documentedException)) {
                isDocumented = true;
                break;
            }
        }
        if (!isDocumented) {
            log.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
        }
    }
}
Also used : Visitor(com.redhat.ceylon.compiler.typechecker.tree.Visitor) SourceDeclarationVisitor(com.redhat.ceylon.compiler.java.loader.SourceDeclarationVisitor) Node(com.redhat.ceylon.compiler.typechecker.tree.Node) ArrayList(java.util.ArrayList) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) NothingType(com.redhat.ceylon.model.typechecker.model.NothingType) Type(com.redhat.ceylon.model.typechecker.model.Type) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Expression(com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 9 with PhasedUnit

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon-compiler by ceylon.

the class CeylonDocTool method initTypeCheckedUnits.

private void initTypeCheckedUnits(TypeChecker typeChecker) {
    for (PhasedUnit unit : typeChecker.getPhasedUnits().getPhasedUnits()) {
        // obtain the unit container path
        final String pkgName = Util.getUnitPackageName(unit);
        unit.getCompilationUnit().visit(new SourceDeclarationVisitor() {

            @Override
            public void loadFromSource(com.redhat.ceylon.compiler.typechecker.tree.Tree.Declaration decl) {
                compiledClasses.add(Util.getQuotedFQN(pkgName, decl));
            }

            @Override
            public void loadFromSource(ModuleDescriptor that) {
            // don't think we care about these
            }

            @Override
            public void loadFromSource(PackageDescriptor that) {
            // don't think we care about these
            }
        });
    }
}
Also used : ModuleDescriptor(com.redhat.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) SourceDeclarationVisitor(com.redhat.ceylon.compiler.java.loader.SourceDeclarationVisitor) PackageDescriptor(com.redhat.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Example 10 with PhasedUnit

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon-compiler by ceylon.

the class CeylonDocTool method buildNodesMaps.

private void buildNodesMaps() {
    for (final PhasedUnit pu : phasedUnits) {
        CompilationUnit cu = pu.getCompilationUnit();
        Walker.walkCompilationUnit(new Visitor() {

            public void visit(Tree.Declaration that) {
                modelUnitMap.put(that.getDeclarationModel(), pu);
                modelNodeMap.put(that.getDeclarationModel(), that);
                super.visit(that);
            }

            public void visit(Tree.ObjectDefinition that) {
                if (that.getDeclarationModel() != null && that.getDeclarationModel().getTypeDeclaration() != null) {
                    TypeDeclaration typeDecl = that.getDeclarationModel().getTypeDeclaration();
                    modelUnitMap.put(typeDecl, pu);
                    modelNodeMap.put(typeDecl, that);
                }
                super.visit(that);
            }

            public void visit(Tree.PackageDescriptor that) {
                if (that.getImportPath() != null && that.getImportPath().getModel() != null) {
                    Referenceable model = that.getImportPath().getModel();
                    modelUnitMap.put(model, pu);
                    modelNodeMap.put(model, that);
                }
                super.visit(that);
            }

            public void visit(Tree.ModuleDescriptor that) {
                if (that.getImportPath() != null && that.getImportPath().getModel() != null) {
                    Referenceable model = that.getImportPath().getModel();
                    modelUnitMap.put(model, pu);
                    modelNodeMap.put(model, that);
                }
                super.visit(that);
            }

            public void visit(Tree.SpecifierStatement that) {
                modelUnitMap.put(that.getDeclaration(), pu);
                modelNodeMap.put(that.getDeclaration(), that);
                super.visit(that);
            }

            public void visit(Tree.Parameter param) {
                parameterUnitMap.put(param.getParameterModel(), pu);
                parameterNodeMap.put(param.getParameterModel(), param);
                super.visit(param);
            }
        }, cu);
    }
}
Also used : CompilationUnit(com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) ModuleDescriptor(com.redhat.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) Visitor(com.redhat.ceylon.compiler.typechecker.tree.Visitor) SourceDeclarationVisitor(com.redhat.ceylon.compiler.java.loader.SourceDeclarationVisitor) Referenceable(com.redhat.ceylon.model.typechecker.model.Referenceable) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) PackageDescriptor(com.redhat.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Aggregations

PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)16 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)8 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)5 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)5 CeylonCompilationUnit (com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit)4 Package (com.redhat.ceylon.model.typechecker.model.Package)4 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)4 IOException (java.io.IOException)4 SourceDeclarationVisitor (com.redhat.ceylon.compiler.java.loader.SourceDeclarationVisitor)3 Node (com.redhat.ceylon.compiler.typechecker.tree.Node)3 CompilationUnit (com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit)3 ModuleDescriptor (com.redhat.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor)3 Visitor (com.redhat.ceylon.compiler.typechecker.tree.Visitor)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 RuntimeModelLoader (com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader)2 PhasedUnits (com.redhat.ceylon.compiler.typechecker.context.PhasedUnits)2 PackageDescriptor (com.redhat.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor)2 AbstractModelLoader (com.redhat.ceylon.model.loader.AbstractModelLoader)2