use of dyvilx.tools.compiler.ast.reference.ReferenceType in project Dyvil by Dyvil.
the class PostfixType method resolveType.
@Override
public IType resolveType(MarkerList markers, IContext context) {
final String unqualified = this.name.unqualified;
final IType argument = this.arguments.get(0);
if (unqualified.length() == 1) {
switch(unqualified.charAt(0)) {
case '?':
return NullableType.apply(argument).resolveType(markers, context);
case '!':
return new ImplicitNullableType(argument).resolveType(markers, context);
case '*':
return new ReferenceType(argument).resolveType(markers, context);
case '^':
return new ImplicitReferenceType(argument).resolveType(markers, context);
}
}
return super.resolveType(markers, context);
}
use of dyvilx.tools.compiler.ast.reference.ReferenceType in project Dyvil by Dyvil.
the class ClassFormat method readType.
public static IType readType(String desc, int start, int end, boolean nullables) {
switch(desc.charAt(start)) {
// primitives
case 'V':
return Types.VOID;
case 'Z':
return Types.BOOLEAN;
case 'B':
return Types.BYTE;
case 'S':
return Types.SHORT;
case 'C':
return Types.CHAR;
case 'I':
return Types.INT;
case 'J':
return Types.LONG;
case 'F':
return Types.FLOAT;
case 'D':
return Types.DOUBLE;
case // class type
'L':
return readReferenceType(desc, start + 1, end, nullables);
case // reference type
'R':
final ReferenceType rt = new ReferenceType();
readTyped(desc, start + 1, rt::setType, true);
return rt;
case // null
NullType.NULL_DESC:
return Types.NULL;
case // none
NoneType.NONE_DESC:
return Types.NONE;
case // any
AnyType.ANY_DESC:
return Types.ANY;
case // type parameter reference
'T':
return new InternalTypeVarType(desc.substring(start + 1, end));
case // array type
'[':
final ArrayType arrayType = new ArrayType(readType(desc, start + 1, end, true));
return nullable(arrayType, nullables);
case // union
'|':
{
final UnionType union = new UnionType();
final int end1 = readTyped(desc, start + 1, union::setLeft, nullables);
readTyped(desc, end1, union::setRight, nullables);
return union;
}
case // intersection
'&':
{
final IntersectionType intersection = new IntersectionType();
final int end1 = readTyped(desc, start + 1, intersection::setLeft, nullables);
readTyped(desc, end1, intersection::setRight, nullables);
return intersection;
}
case // option
'?':
return new NullableType(readType(desc, start + 1, end, false));
}
return null;
}
use of dyvilx.tools.compiler.ast.reference.ReferenceType in project Dyvil by Dyvil.
the class IType method readType.
static IType readType(DataInput dis) throws IOException {
int tag = dis.readUnsignedByte();
IType type;
switch(tag) {
case UNKNOWN:
return Types.UNKNOWN;
case NULL:
return Types.NULL;
case NONE:
return Types.NONE;
case ANY:
return Types.ANY;
case PRIMITIVE:
return PrimitiveType.fromTypecode(dis.readByte());
case CLASS:
type = new ClassType();
break;
case PACKAGE:
type = new PackageType();
break;
case GENERIC:
type = new ClassGenericType();
break;
case TUPLE:
type = new TupleType();
break;
case LAMBDA:
type = new LambdaType();
break;
case ARRAY:
type = new ArrayType();
break;
case MAP:
type = new MapType();
break;
case OPTIONAL:
type = new NullableType();
break;
case IMPLICIT_OPTIONAL:
type = new ImplicitNullableType();
break;
case REFERENCE:
type = new ReferenceType();
break;
case ANNOTATED:
type = new AnnotatedType();
break;
case TYPE_VAR:
type = new NamedType();
break;
case WILDCARD_TYPE:
type = new WildcardType();
break;
case MISSING_TAG:
return null;
default:
throw new Error("Cannot decode TypeTag " + tag);
}
type.read(dis);
return type;
}
use of dyvilx.tools.compiler.ast.reference.ReferenceType in project Dyvil by Dyvil.
the class InternalGenericType method resolveType.
@Override
public IType resolveType(MarkerList markers, IContext context) {
this.arguments.resolveTypes(markers, context);
if (this.internalName.startsWith("dyvil/tuple/Tuple$Of")) {
return new TupleType(this.arguments);
}
if (this.internalName.startsWith("dyvil/function/Function$Of")) {
return new LambdaType(this.arguments);
}
switch(this.internalName) {
case "dyvil/ref/ObjectRef":
return new ReferenceType(ReferenceType.LazyFields.OBJECT_REF_CLASS, this.arguments.get(0));
case "dyvil/collection/Map":
return MapType.base(this.arguments.get(0), this.arguments.get(1));
case "dyvil/collection/MutableMap":
return MapType.mutable(this.arguments.get(0), this.arguments.get(1));
case "dyvil/collection/ImmutableMap":
return MapType.immutable(this.arguments.get(0), this.arguments.get(1));
}
final IClass iclass = Package.rootPackage.resolveInternalClass(this.internalName);
return new ClassGenericType(iclass, this.arguments);
}
Aggregations