use of com.redhat.ceylon.compiler.typechecker.analyzer.Warning in project ceylon-compiler by ceylon.
the class LanguageCompiler method ceylonParse.
private JCCompilationUnit ceylonParse(JavaFileObject filename, CharSequence readSource) {
if (ceylonEnter.hasRun())
throw new RunTwiceException("Trying to load new source file after CeylonEnter has been called: " + filename);
try {
ModuleManager moduleManager = phasedUnits.getModuleManager();
ModuleSourceMapper moduleSourceMapper = phasedUnits.getModuleSourceMapper();
File sourceFile = new File(filename.getName());
// FIXME: temporary solution
VirtualFile file = vfs.getFromFile(sourceFile);
VirtualFile srcDir = vfs.getFromFile(getSrcDir(sourceFile));
String source = readSource.toString();
char[] chars = source.toCharArray();
LineMap map = Position.makeLineMap(chars, chars.length, false);
PhasedUnit phasedUnit = null;
PhasedUnit externalPhasedUnit = compilerDelegate.getExternalSourcePhasedUnit(srcDir, file);
String suppressWarnings = options.get(OptionName.CEYLONSUPPRESSWARNINGS);
final EnumSet<Warning> suppressedWarnings;
if (suppressWarnings != null) {
if (suppressWarnings.trim().isEmpty()) {
suppressedWarnings = EnumSet.allOf(Warning.class);
} else {
suppressedWarnings = EnumSet.noneOf(Warning.class);
for (String name : suppressWarnings.trim().split(" *, *")) {
suppressedWarnings.add(Warning.valueOf(name));
}
}
} else {
suppressedWarnings = EnumSet.noneOf(Warning.class);
}
if (externalPhasedUnit != null) {
phasedUnit = new CeylonPhasedUnit(externalPhasedUnit, filename, map);
phasedUnit.setSuppressedWarnings(suppressedWarnings);
phasedUnits.addPhasedUnit(externalPhasedUnit.getUnitFile(), phasedUnit);
gen.setMap(map);
String pkgName = phasedUnit.getPackage().getQualifiedNameString();
if ("".equals(pkgName)) {
pkgName = null;
}
return gen.makeJCCompilationUnitPlaceholder(phasedUnit.getCompilationUnit(), filename, pkgName, phasedUnit);
}
if (phasedUnit == null) {
ANTLRStringStream input = new NewlineFixingStringStream(source);
CeylonLexer lexer = new CeylonLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
CeylonParser parser = new CeylonParser(tokens);
CompilationUnit cu = parser.compilationUnit();
java.util.List<LexError> lexerErrors = lexer.getErrors();
for (LexError le : lexerErrors) {
printError(le, le.getMessage(), "ceylon.lexer", map);
}
java.util.List<ParseError> parserErrors = parser.getErrors();
for (ParseError pe : parserErrors) {
printError(pe, pe.getMessage(), "ceylon.parser", map);
}
// if we continue and it's not a descriptor, we don't care about errors
if ((options.get(OptionName.CEYLONCONTINUE) != null && !ModuleManager.MODULE_FILE.equals(sourceFile.getName()) && !ModuleManager.PACKAGE_FILE.equals(sourceFile.getName())) || // otherwise we care about errors
(lexerErrors.size() == 0 && parserErrors.size() == 0)) {
// FIXME: this is bad in many ways
String pkgName = getPackage(filename);
// make a Package with no module yet, we will resolve them later
/*
* Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
*/
com.redhat.ceylon.model.typechecker.model.Package p = modelLoader.findOrCreateModulelessPackage(pkgName == null ? "" : pkgName);
phasedUnit = new CeylonPhasedUnit(file, srcDir, cu, p, moduleManager, moduleSourceMapper, ceylonContext, filename, map);
phasedUnit.setSuppressedWarnings(suppressedWarnings);
phasedUnits.addPhasedUnit(file, phasedUnit);
gen.setMap(map);
return gen.makeJCCompilationUnitPlaceholder(cu, filename, pkgName, phasedUnit);
}
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
JCCompilationUnit result = make.TopLevel(List.<JCAnnotation>nil(), null, List.<JCTree>of(make.Erroneous()));
result.sourcefile = filename;
return result;
}
use of com.redhat.ceylon.compiler.typechecker.analyzer.Warning 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);
}
Aggregations