Search in sources :

Example 1 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class ClassOrPackageDoc method getParameterDefaultValue.

private String getParameterDefaultValue(Parameter param) throws IOException {
    String defaultValue = null;
    if (param.isDefaulted()) {
        PhasedUnit pu = tool.getParameterUnit(param);
        Node paramNode = tool.getParameterNode(param);
        if (pu != null && paramNode instanceof Tree.Parameter) {
            Tree.SpecifierOrInitializerExpression defArg = getDefaultArgument((Tree.Parameter) paramNode);
            if (defArg != null) {
                defaultValue = getSourceCode(pu, defArg.getExpression());
                if (defaultValue != null) {
                    defaultValue = defaultValue.trim();
                }
            }
        }
    }
    return defaultValue;
}
Also used : Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 2 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class ClassOrPackageDoc method getParametersAssertions.

private Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> getParametersAssertions(final Declaration decl) {
    final Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> parametersAssertions = new LinkedHashMap<Parameter, Map<Tree.Assertion, List<Tree.Condition>>>();
    if (((Functional) decl).getParameterLists().isEmpty()) {
        return parametersAssertions;
    }
    Node node = tool.getNode(decl);
    PhasedUnit pu = tool.getUnit(decl);
    if (node == null || pu == null) {
        return parametersAssertions;
    }
    Tree.Body body = null;
    if (node instanceof Tree.MethodDefinition) {
        body = ((Tree.MethodDefinition) node).getBlock();
    } else if (node instanceof Tree.ClassDefinition) {
        body = ((Tree.ClassDefinition) node).getClassBody();
    }
    if (body == null) {
        return parametersAssertions;
    }
    final Map<String, Parameter> parametersNames = new HashMap<String, Parameter>();
    for (ParameterList parameterList : ((Functional) decl).getParameterLists()) {
        for (Parameter parameter : parameterList.getParameters()) {
            parametersNames.put(parameter.getName(), parameter);
        }
    }
    body.visitChildren(new Visitor() {

        private boolean stop = false;

        private Tree.Assertion assertion = null;

        private Set<Parameter> referencedParameters = new HashSet<Parameter>();

        @Override
        public void visit(Tree.Assertion that) {
            assertion = that;
            super.visit(that);
            assertion = null;
        }

        @Override
        public void visit(Tree.Condition that) {
            referencedParameters.clear();
            super.visit(that);
            if (assertion != null && !referencedParameters.isEmpty()) {
                for (Parameter referencedParameter : referencedParameters) {
                    Map<Tree.Assertion, List<Tree.Condition>> parameterAssertions = parametersAssertions.get(referencedParameter);
                    if (parameterAssertions == null) {
                        parameterAssertions = new LinkedHashMap<Tree.Assertion, List<Tree.Condition>>();
                        parametersAssertions.put(referencedParameter, parameterAssertions);
                    }
                    List<Tree.Condition> parameterConditions = parameterAssertions.get(assertion);
                    if (parameterConditions == null) {
                        parameterConditions = new ArrayList<Tree.Condition>();
                        parameterAssertions.put(assertion, parameterConditions);
                    }
                    parameterConditions.add(that);
                }
            }
        }

        @Override
        public void visit(Tree.BaseMemberExpression that) {
            if (assertion != null) {
                Declaration d = that.getDeclaration();
                Scope realScope = org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope(d.getScope());
                if (parametersNames.containsKey(d.getName()) && realScope == decl) {
                    referencedParameters.add(parametersNames.get(d.getName()));
                }
            }
            super.visit(that);
        }

        @Override
        public void visit(Tree.Statement that) {
            if (assertion == null) {
                stop = true;
            }
            super.visit(that);
        }

        @Override
        public void visitAny(Node that) {
            if (!stop) {
                super.visitAny(that);
            }
        }
    });
    return parametersAssertions;
}
Also used : Visitor(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) List(java.util.List) Util.findBottomMostRefinedDeclaration(org.eclipse.ceylon.ceylondoc.Util.findBottomMostRefinedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) HashSet(java.util.HashSet) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class TypeChecker method executePhases.

protected void executePhases(List<PhasedUnit> listOfUnits) {
    for (PhasedUnit pu : listOfUnits) {
        pu.validateTree();
        pu.scanDeclarations();
    }
    for (PhasedUnit pu : listOfUnits) {
        pu.scanTypeDeclarations();
    }
    for (PhasedUnit pu : listOfUnits) {
        pu.validateRefinement();
    }
    for (PhasedUnit pu : listOfUnits) {
        pu.analyseTypes();
    }
    for (PhasedUnit pu : listOfUnits) {
        pu.analyseFlow();
    }
    for (PhasedUnit pu : listOfUnits) {
        pu.analyseUsage();
    }
}
Also used : PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 4 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class TypeChecker method executePhases.

private void executePhases(PhasedUnits phasedUnits, boolean forceSilence) {
    List<PhasedUnit> listOfUnits = phasedUnits.getPhasedUnits();
    phasedUnits.getModuleManager().prepareForTypeChecking();
    phasedUnits.visitModules();
    phasedUnits.getModuleManager().modulesVisited();
    // By now le language module version should be known
    // (as local) or we should use the default one.
    Module languageModule = context.getModules().getLanguageModule();
    if (languageModule.getVersion() == null) {
        languageModule.setVersion(LANGUAGE_MODULE_VERSION);
    }
    ModuleValidator moduleValidator = new ModuleValidator(context, phasedUnits);
    if (verifyDependencies) {
        moduleValidator.verifyModuleDependencyTree();
    }
    phasedUnitsOfDependencies = moduleValidator.getPhasedUnitsOfDependencies();
    executePhases(listOfUnits);
    if (!forceSilence) {
        for (PhasedUnit pu : listOfUnits) {
            if (verbose) {
                pu.display();
            }
            pu.generateStatistics(statsVisitor);
            pu.runAssertions(assertionVisitor);
        }
        if (verbose || statistics) {
            statsVisitor.print();
        }
        assertionVisitor.print(verbose);
    }
}
Also used : Module(org.eclipse.ceylon.model.typechecker.model.Module) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) ModuleValidator(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleValidator)

Example 5 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class MainForJsTest method main.

public static void main(String[] args) throws Exception {
    String distRepo = "../dist/dist/repo";
    final Options opts = new Options().addRepo(distRepo).outRepo("build/test/proto");
    System.out.println("Typechecking Ceylon test code...");
    JsModuleManagerFactory.setVerbose(true);
    TypeCheckerBuilder tcb = new TypeCheckerBuilder().verbose(false).moduleManagerFactory(new JsModuleManagerFactory(null)).usageWarnings(false);
    final ArrayList<File> excludes = new ArrayList<>();
    final ArrayList<File> resfiles = new ArrayList<>();
    final ArrayList<File> resdirs = new ArrayList<>();
    for (String dir : args) {
        final File d = new File(dir.charAt(1) == ':' ? dir.substring(2) : dir);
        if (dir.startsWith("X:")) {
            excludes.add(d);
        } else if (dir.startsWith("R:")) {
            resdirs.add(d);
        } else if (dir.startsWith("r:")) {
            resfiles.add(d);
        } else if (dir.startsWith("c:")) {
            opts.cwd(d);
        } else {
            tcb.addSrcDirectory(d);
            opts.addSrcDir(d);
        }
    }
    final RepositoryManager repoman = CeylonUtils.repoManager().cwd(opts.getCwd()).systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
    tcb.setRepositoryManager(repoman);
    final TypeChecker typeChecker = tcb.getTypeChecker();
    for (File x : excludes) {
        String ap = x.getPath();
        // Fix for Windows
        if ('/' != File.separatorChar) {
            ap = ap.replace(File.separatorChar, '/');
        }
        for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
            if (pu.getUnit().getFullPath().startsWith(ap)) {
                typeChecker.getPhasedUnits().removePhasedUnitForRelativePath(pu.getPathRelativeToSrcDir());
            }
        }
    }
    TypeCache.doWithoutCaching(new Runnable() {

        @Override
        public void run() {
            typeChecker.process();
        }
    });
    if (typeChecker.getErrors() > 0) {
        System.exit(1);
    }
    System.out.println("Compiling in prototype style");
    opts.resourceDirs(resdirs);
    JsCompiler jsc = new JsCompiler(typeChecker, opts).stopOnErrors(true);
    ArrayList<File> sources = new ArrayList<>();
    for (String dir : args) {
        // The arg is src/test/ceylon for example
        addFilesToList(new File(dir), sources);
    }
    Collections.sort(sources);
    jsc.setSourceFiles(sources);
    jsc.setResourceFiles(resfiles);
    PrintWriter writer = new PrintWriter(System.out);
    if (!jsc.generate()) {
        jsc.printErrorsAndCount(writer);
    }
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) ArrayList(java.util.ArrayList) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) File(java.io.File) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) PrintWriter(java.io.PrintWriter)

Aggregations

PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)28 File (java.io.File)9 Package (org.eclipse.ceylon.model.typechecker.model.Package)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 HashMap (java.util.HashMap)4 CeylonCompilationUnit (org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit)4 MetamodelVisitor (org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor)4 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)4 Node (org.eclipse.ceylon.compiler.typechecker.tree.Node)4 Visitor (org.eclipse.ceylon.compiler.typechecker.tree.Visitor)4 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)4 Module (org.eclipse.ceylon.model.typechecker.model.Module)4 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 Map (java.util.Map)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3