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;
}
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;
}
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();
}
}
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);
}
}
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);
}
}
Aggregations