use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class InheritanceVisitor method checkCaseType.
void checkCaseType(TypeDeclaration type, Tree.StaticType ct, TypeDeclaration caseTypeDec) {
if (caseTypeDec instanceof ClassOrInterface && ct instanceof Tree.SimpleType && caseTypeDec.isParameterized()) {
Tree.SimpleType t = (Tree.SimpleType) ct;
Tree.TypeArgumentList tal = t.getTypeArgumentList();
List<Tree.Type> args = tal == null ? Collections.<Tree.Type>emptyList() : tal.getTypes();
List<TypeParameter> typeParameters = caseTypeDec.getTypeParameters();
Set<TypeParameter> used = new HashSet<TypeParameter>();
for (int i = 0; i < typeParameters.size(); i++) {
TypeParameter typeParameter = typeParameters.get(i);
Type argType;
Node node;
String typeArg;
if (i < args.size()) {
Tree.Type arg = args.get(i);
argType = arg.getTypeModel();
node = arg;
typeArg = "type argument";
} else {
argType = typeParameter.getDefaultTypeArgument();
node = tal;
typeArg = "default type argument '" + argType.asString(node.getUnit()) + "' of '" + typeParameter.getName() + "' ";
}
if (argType != null) {
TypeDeclaration argTypeDec = argType.getDeclaration();
if (argType.isTypeParameter()) {
TypeParameter tp = (TypeParameter) argTypeDec;
if (!tp.getDeclaration().equals(type)) {
node.addError(typeArg + "is not a type parameter of the enumerated type: '" + tp.getName() + "' is not a type parameter of '" + type.getName() + "'");
} else if (!used.add(tp)) {
node.addError("type parameter of the enumerated type is used twice as a type argument: '" + argTypeDec.getName());
}
} else if (typeParameter.isCovariant()) {
checkAssignable(typeParameter.getType(), argType, node, typeArg + " is not an upper bound of the type parameter '" + typeParameter.getName() + "' ");
} else if (typeParameter.isContravariant()) {
checkAssignable(argType, typeParameter.getType(), node, typeArg + " is not a lower bound of the type parameter '" + typeParameter.getName() + "' ");
} else {
node.addError(typeArg + "is not a type parameter of the enumerated type: '" + argTypeDec.getName() + "'");
}
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ModuleValidator method verifyNative.
private void verifyNative(Module module) {
for (ImportModule imp : moduleManagerUtil.retrieveModuleImportNodes(module)) {
Module importedModule;
Node node;
if (imp.getImportPath() != null) {
node = imp.getImportPath();
importedModule = (Module) imp.getImportPath().getModel();
} else {
node = imp.getQuotedLiteral();
importedModule = moduleManagerUtil.getModuleForNode(node);
if (importedModule == null)
continue;
}
Backends bs = getNativeBackend(imp.getAnnotationList(), imp.getUnit());
if (bs.none()) {
if (importedModule.isNative() && !module.isNative()) {
node.addError(new ModuleSourceMapper.ModuleDependencyAnalysisError(node, "native import for cross-platform module" + " (mark either the module or the import as native)", 20000));
}
} else if (importedModule.isNative() && !bs.supports(importedModule.getNativeBackends())) {
node.addError(new ModuleSourceMapper.ModuleDependencyAnalysisError(node, "native backend name conflicts with imported module: '\"" + bs + "\"' is not '\"" + importedModule.getNativeBackends().names() + "\"'"));
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ErrorCollectingVisitor method printErrors.
public int printErrors(Writer out, DiagnosticListener diagnosticListener, boolean printWarnings, boolean printCount) throws IOException {
int warnings = 0;
int count = 0;
List<PositionedMessage> errors = (!recogErrors.isEmpty()) ? recogErrors : analErrors;
for (PositionedMessage pm : errors) {
Message err = pm.message;
if (err instanceof UsageWarning) {
if (!printWarnings || ((UsageWarning) err).isSuppressed()) {
continue;
}
}
Node node = TreeUtil.getIdentifyingNode(pm.node);
int line = err.getLine();
int position = -1;
if (err instanceof AnalysisMessage) {
if (node != null && node.getToken() != null)
position = node.getToken().getCharPositionInLine();
} else if (err instanceof RecognitionError) {
position = ((RecognitionError) err).getCharacterInLine();
}
String fileName = (node.getUnit() != null) ? node.getUnit().getFullPath() : "unknown";
out.write(OSUtil.color(fileName, OSUtil.Color.blue));
out.write(":");
out.write(String.format("%d", line));
out.write(": ");
if (err instanceof UsageWarning) {
out.write(OSUtil.color("warning", OSUtil.Color.yellow));
warnings++;
} else {
out.write(OSUtil.color("error", OSUtil.Color.red));
count++;
}
out.write(": ");
out.write(err.getMessage());
out.write(System.lineSeparator());
String ln = getErrorSourceLine(pm);
if (ln != null) {
out.write(ln);
out.write(System.lineSeparator());
out.write(getErrorMarkerLine(position));
out.write(System.lineSeparator());
}
if (diagnosticListener != null) {
File file = null;
boolean warning = err instanceof UsageWarning;
if (node.getUnit() != null && node.getUnit().getFullPath() != null)
file = new File(node.getUnit().getFullPath()).getAbsoluteFile();
if (position != -1)
// make it 1-based
position++;
if (warning)
diagnosticListener.warning(file, line, position, err.getMessage());
else
diagnosticListener.error(file, line, position, err.getMessage());
}
}
if (printCount) {
if (count > 0)
out.write(String.format("%d %s%n", count, count == 1 ? "error" : "errors"));
if (warnings > 0)
out.write(String.format("%d %s%n", warnings, warnings == 1 ? "warning" : "warnings"));
}
out.flush();
return count;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.AttributeArgument that) {
Tree.SpecifierExpression se = that.getSpecifierExpression();
Tree.Type type = that.getType();
Value val = that.getDeclarationModel();
if (se == null) {
Declaration od = beginReturnDeclaration(val);
Tree.Type rt = beginReturnScope(type);
super.visit(that);
endReturnScope(rt, val);
endReturnDeclaration(od);
} else {
super.visit(that);
inferType(that, se);
if (type != null) {
Type t = type.getTypeModel();
if (!isTypeUnknown(t)) {
checkType(t, val, se, 2100);
}
}
}
if (type instanceof Tree.LocalModifier) {
if (isTypeUnknown(type.getTypeModel())) {
if (se == null || !hasError(se)) {
Node node = type.getToken() == null ? that : type;
node.addError("argument type could not be inferred");
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.SwitchExpression that) {
Node ose = switchStatementOrExpression;
Node oie = ifStatementOrExpression;
switchStatementOrExpression = that;
ifStatementOrExpression = null;
super.visit(that);
Tree.SwitchCaseList switchCaseList = that.getSwitchCaseList();
Tree.SwitchClause switchClause = that.getSwitchClause();
checkSwitch(switchClause, switchCaseList);
if (switchCaseList != null) {
List<Type> list = new ArrayList<Type>();
for (Tree.CaseClause cc : that.getSwitchCaseList().getCaseClauses()) {
Tree.Expression e = cc.getExpression();
if (e != null) {
Type t = e.getTypeModel();
if (t != null) {
addToUnion(list, t);
}
}
}
Tree.ElseClause elseClause = that.getSwitchCaseList().getElseClause();
if (elseClause != null) {
Tree.Expression e = elseClause.getExpression();
if (e != null) {
Type t = e.getTypeModel();
if (t != null) {
addToUnion(list, t);
}
}
}
that.setTypeModel(union(list, unit));
}
switchStatementOrExpression = ose;
ifStatementOrExpression = oie;
}
Aggregations