use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class ClassOperator method toStringBuilder.
@Override
public boolean toStringBuilder(StringBuilder builder) {
if (this.type.isPrimitive()) {
builder.append(this.type.getName().qualified);
return true;
}
IClass iClass = this.type.getTheClass();
if (iClass == null) {
return false;
}
if (iClass.isInterface()) {
builder.append("interface ");
} else {
builder.append("class ");
}
builder.append(iClass.getFullName());
return true;
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class AbstractConstructor method checkArguments.
@Override
public IType checkArguments(MarkerList markers, SourcePosition position, IContext context, IType type, ArgumentList arguments) {
final IClass theClass = this.enclosingClass;
if (!theClass.isTypeParametric()) {
for (int i = 0, count = this.parameters.size(); i < count; i++) {
arguments.checkValue(i, this.parameters.get(i), null, position, markers, context);
}
return type;
}
final IType classType = theClass.getThisType();
final GenericData genericData = new GenericData(theClass);
classType.inferTypes(type, genericData);
genericData.lockAvailable();
// Check Values and infer Types
for (int i = 0, count = this.parameters.size(); i < count; i++) {
arguments.checkValue(i, this.parameters.get(i), genericData, position, markers, context);
}
genericData.lockAvailable();
// Check Type Var Inference and Compatibility
final TypeParameterList typeParams = theClass.getTypeParameters();
for (int i = 0, count = typeParams.size(); i < count; i++) {
final ITypeParameter typeParameter = typeParams.get(i);
final IType typeArgument = genericData.resolveType(typeParameter);
if (typeArgument == null) {
final IType inferredType = typeParameter.getUpperBound();
markers.add(Markers.semantic(position, "constructor.typevar.infer", theClass.getName(), typeParameter.getName(), inferredType));
genericData.addMapping(typeParameter, inferredType);
} else if (!typeParameter.isAssignableFrom(typeArgument, genericData)) {
final Marker marker = Markers.semanticError(position, "constructor.typevar.incompatible", theClass.getName(), typeParameter.getName());
marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
markers.add(marker);
}
}
return classType.getConcreteType(genericData);
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class ModifierUtil method getFlags.
public static long getFlags(IClassMember member) {
final int flags = member.getAttributes().flags();
int javaModifiers = flags & JAVA_MODIFIER_MASK;
int dyvilModifiers = flags & DYVIL_MODIFIER_MASK;
if ((flags & PRIVATE_PROTECTED) == PRIVATE_PROTECTED) {
// for private protected members, move the private modifier
javaModifiers &= ~PRIVATE;
dyvilModifiers |= PRIVATE;
}
if (member.getElementType() == ElementType.METHOD) {
if ((flags & STATIC_ABSTRACT) == STATIC_ABSTRACT) {
// for static abstract methods, move the abstract modifier
javaModifiers &= ~ABSTRACT;
dyvilModifiers |= ABSTRACT;
}
if ((flags & FINAL) != 0) {
final IClass enclosingClass = member.getEnclosingClass();
if (enclosingClass != null && enclosingClass.isInterface()) {
// for final interface methods, move the final modifier
javaModifiers &= ~FINAL;
dyvilModifiers |= FINAL;
}
}
}
return (long) dyvilModifiers << 32 | javaModifiers;
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class ModifierUtil method checkMethodModifiers.
public static void checkMethodModifiers(MarkerList markers, IMethod member) {
final int flags = member.getAttributes().flags();
final boolean hasValue = member.getValue() != null;
final boolean isAbstract = (flags & ABSTRACT) != 0;
final boolean isNative = (flags & NATIVE) != 0;
// If the method does not have an implementation and is static
if (isAbstract) {
if (hasValue) {
markers.add(Markers.semanticError(member.getPosition(), "modifiers.abstract.implemented", Util.memberNamed(member)));
}
if (isNative) {
markers.add(Markers.semanticError(member.getPosition(), "modifiers.native.abstract", Util.memberNamed(member)));
}
final IClass enclosingClass = member.getEnclosingClass();
if (!enclosingClass.isAbstract()) {
markers.add(Markers.semanticError(member.getPosition(), "modifiers.abstract.concrete_class", Util.memberNamed(member), enclosingClass.getName()));
}
return;
}
if (hasValue) {
if (isNative) {
markers.add(Markers.semanticError(member.getPosition(), "modifiers.native.implemented", Util.memberNamed(member)));
}
return;
}
if (!isNative) {
markers.add(Markers.semanticError(member.getPosition(), "modifiers.unimplemented", Util.memberNamed(member)));
}
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class RootPackage method resolveInternalClass.
public IClass resolveInternalClass(String internal) {
IClass result = this.classCache.get(internal);
if (result != null) {
return result;
}
Package pack = this;
int nextIndex;
int startIndex = 0;
while ((nextIndex = internal.indexOf('/', startIndex)) >= 0) {
pack = pack.resolvePackage(internal.substring(startIndex, nextIndex));
startIndex = nextIndex + 1;
}
result = pack.resolveClass(internal.substring(startIndex));
this.classCache.put(internal, result);
return result;
}
Aggregations