Skip to content

Commit

Permalink
cleanup: BasicTypeId
Browse files Browse the repository at this point in the history
  • Loading branch information
kindlich committed Aug 31, 2024
1 parent a8b7a13 commit 1bc4e81
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public String format(TypeID type) {

@Override
public String visitBasic(BasicTypeID basic) {
return basic.name;
return basic.getName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum BasicTypeID implements TypeID, TypeSymbol {
UNDETERMINED("undetermined"),
INVALID("invalid");

public final String name;
private final String name;
private ResolvingType members;

private Expression defaultValue = null;
Expand Down Expand Up @@ -63,11 +63,6 @@ public <C, R, E extends Exception> R accept(C context, TypeVisitorWithContext<C,
return visitor.visitBasic(context, this);
}

@Override
public boolean isOptional() {
return false;
}

@Override
public boolean isValueType() {
return true;
Expand Down Expand Up @@ -96,7 +91,7 @@ public Expression getDefaultValue() {

@Override
public void extractTypeParameters(List<TypeParameter> typeParameters) {

// BasicTypeIDs don't have type parameters
}

private Expression generateDefaultValue() {
Expand Down Expand Up @@ -183,10 +178,11 @@ public String getName() {

@Override
public ResolvingType resolve(TypeID[] typeArguments) {
if (members == null)
members = BasicTypeMembers.get(this);
if(typeArguments.length > 0) {
throw new IllegalArgumentException(this + " cannot have type arguments");
}

return members;
return this.resolve();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.openzen.zenscript.codemodel.compilation.CastedEval;
import org.openzen.zenscript.codemodel.compilation.CastedExpression;
import org.openzen.zenscript.codemodel.compilation.CompileErrors;
import org.openzen.zenscript.codemodel.compilation.ResolvingType;
import org.openzen.zenscript.codemodel.expression.CompareExpression;
import org.openzen.zenscript.codemodel.expression.Expression;
import org.openzen.zenscript.codemodel.identifiers.MethodID;
Expand All @@ -21,7 +22,7 @@ public class BasicTypeMembers {
private static final MethodID CONSTRUCTOR = MethodID.staticOperator(OperatorType.CONSTRUCTOR);
private static final MethodID COMPARE = MethodID.operator(OperatorType.COMPARE);

public static MemberSet.Resolving get(BasicTypeID type) {
public static ResolvingType get(BasicTypeID type) {
switch (type) {
case VOID:
case NULL:
Expand Down Expand Up @@ -600,9 +601,7 @@ private static void comparator(MemberSet.Builder builder) {
new MethodInstance(getComparator((BasicTypeID) typeID)),
type);
return new CastedExpression(CastedExpression.Level.EXACT, value);
}).orElseGet(() -> {
return new CastedExpression(CastedExpression.Level.INVALID, compiler.at(position).invalid(CompileErrors.cannotCompare(left.type, rightCompiled.type)));
});
}).orElseGet(() -> new CastedExpression(CastedExpression.Level.INVALID, compiler.at(position).invalid(CompileErrors.cannotCompare(left.type, rightCompiled.type))));
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private String mangleExpansionTarget(final TypeID target) {
return this.oneOf(
() -> this.mangleIf(EXP_TAR_MANGLE_ARRAY_ID, target::asArray, it -> Character.toString('D') + it.dimension + 'C' + this.mangleExpansionTarget(it.elementType)),
() -> this.mangleIf(EXP_TAR_MANGLE_ASSOC_ID, target::asAssoc, it -> this.mangleKv(this.mangleExpansionTarget(it.keyType), this.mangleExpansionTarget(it.valueType))),
() -> this.mangleIf(EXP_TAR_MANGLE_BASIC_ID, target, BasicTypeID.class, it -> it.name),
() -> this.mangleIf(EXP_TAR_MANGLE_BASIC_ID, target, BasicTypeID.class, BasicTypeID::getName),
() -> this.mangleIf(EXP_TAR_MANGLE_DEFINITION_ID, target::asDefinition, it -> {
final String name = it.definition.getName();
final int simpleNameBegin = name.lastIndexOf('.');
Expand Down

0 comments on commit 1bc4e81

Please sign in to comment.