use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class CompleteCommand method findInstanceMembers.
private static void findInstanceMembers(IType type, Set<IField> fields, Set<IProperty> properties, Set<IMethod> methods, String start, Set<IClass> dejaVu) {
final IClass iclass = type.getTheClass();
if (iclass == null || dejaVu.contains(iclass)) {
return;
}
dejaVu.add(iclass);
// Add members
final ParameterList parameterList = iclass.getParameters();
for (int i = 0, count = parameterList.size(); i < count; i++) {
checkMember(fields, (IField) parameterList.get(i), start, false);
}
findMembers(type, fields, properties, methods, start, false);
// Recursively scan super types
final IType superType = iclass.getSuperType();
if (superType != null) {
findInstanceMembers(superType.getConcreteType(type), fields, properties, methods, start, dejaVu);
}
for (IType interfaceType : iclass.getInterfaces()) {
findInstanceMembers(interfaceType.getConcreteType(type), fields, properties, methods, start, dejaVu);
}
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class LambdaExpr method inferReturnType.
public void inferReturnType(IType type, IType valueType) {
if (this.hasImplicitReturnType()) {
this.returnType = valueType;
}
if ((this.flags & LAMBDA_TYPE_INFERRED) != 0 || type.canExtract(LambdaType.class)) {
this.type = this.makeType();
return;
}
final ITypeContext tempContext = new MapTypeContext();
final ParameterList methodParams = this.method.getParameters();
final int size = Math.min(this.parameters.size(), methodParams.size());
for (int i = 0; i < size; i++) {
final IParameter lambdaParam = this.parameters.get(i);
final IParameter methodParam = methodParams.get(i);
methodParam.getType().inferTypes(lambdaParam.getType(), tempContext);
}
this.method.getType().inferTypes(valueType, tempContext);
final IType classType = this.method.getEnclosingClass().getThisType();
this.type = classType.getConcreteType(tempContext);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class LambdaExpr method isType.
@Override
public boolean isType(IType type) {
if (this.type != null && Types.isSuperType(type, this.type)) {
return true;
}
final IClass interfaceClass = type.getTheClass();
if (interfaceClass == null) {
return false;
}
if (interfaceClass == Types.OBJECT_CLASS) {
return true;
}
final IMethod method = interfaceClass.getFunctionalMethod();
if (method == null) {
return false;
}
final ParameterList methodParameters = method.getParameters();
final int parameterCount = this.parameters.size();
if (parameterCount != methodParameters.size()) {
return false;
}
for (int i = 0; i < parameterCount; i++) {
final IType lambdaParameterType = this.parameters.get(i).getCovariantType();
if (lambdaParameterType.isUninferred()) {
continue;
}
final IType methodParameterType = methodParameters.get(i).getCovariantType();
if (!Types.isSuperType(methodParameterType, lambdaParameterType)) {
return false;
}
}
return true;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class MapExpr method isType.
@Override
public boolean isType(IType type) {
if (!MapType.MapTypes.MAP_CLASS.isSubClassOf(type)) {
return this.isConvertibleFrom(type);
}
IType keyType = Types.resolveTypeSafely(type, MapType.MapTypes.KEY_VARIABLE);
IType valueType = Types.resolveTypeSafely(type, MapType.MapTypes.VALUE_VARIABLE);
return this.keys.isType(keyType) && this.values.isType(valueType);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class MapExpr method withType.
@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
if (!Types.isSuperClass(type, MapType.MapTypes.IMMUTABLE_MAP_CLASS.getClassType())) {
final Annotation annotation = type.getTheClass().getAnnotation(LazyTypes.MAP_CONVERTIBLE_CLASS);
if (annotation == null) {
return null;
}
// [ x : y, ... ] -> Type(x : y, ...))
final int size = this.keys.size();
final ArgumentList arguments = new ArgumentList(size);
for (int i = 0; i < size; i++) {
arguments.add(new ColonOperator(this.keys.get(i), this.values.get(i)));
}
return new LiteralConversion(this, annotation, arguments).withType(type, typeContext, markers, context);
}
final int size = this.keys.size();
final IType keyType = this.keyType = Types.resolveTypeSafely(type, MapType.MapTypes.KEY_VARIABLE);
final IType valueType = this.valueType = Types.resolveTypeSafely(type, MapType.MapTypes.VALUE_VARIABLE);
for (int i = 0; i < size; i++) {
final IValue key = TypeChecker.convertValue(this.keys.get(i), keyType, typeContext, markers, context, KEY_MARKER_SUPPLIER);
this.keys.set(i, key);
final IValue value = TypeChecker.convertValue(this.values.get(i), valueType, typeContext, markers, context, VALUE_MARKER_SUPPLIER);
this.values.set(i, value);
}
return this;
}
Aggregations