use of dyvilx.tools.compiler.ast.expression.ClassOperator in project Dyvil by Dyvil.
the class TypeClassParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case TYPE_CLASS:
if (type == DyvilKeywords.CLASS) {
this.value = new ClassOperator(token.raw());
this.mode = TYPE;
return;
}
if (type == DyvilKeywords.TYPE) {
this.value = new TypeOperator(token.raw());
this.mode = TYPE;
return;
}
throw new Error();
case TYPE:
if (TypeParser.isGenericStart(token, type)) {
this.mode = ANGLE_END;
pm.splitJump(token, 1);
pm.pushParser(new TypeParser(this.value, true));
return;
}
if (type == BaseSymbols.OPEN_PARENTHESIS) {
this.mode = PARENTHESES_END;
} else {
this.mode = END;
pm.reparse();
}
pm.pushParser(new TypeParser(this.value));
return;
case PARENTHESES_END:
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.report(token, this.isClassOperator() ? "classoperator.close_paren" : "typeoperator.close_paren");
return;
}
this.valueConsumer.setValue(this.value);
pm.popParser();
return;
case ANGLE_END:
if (!TypeParser.isGenericEnd(token, type)) {
pm.report(token, this.isClassOperator() ? "classoperator.close_angle" : "typeoperator.close_angle");
return;
}
this.valueConsumer.setValue(this.value);
pm.popParser();
pm.splitJump(token, 1);
return;
case END:
this.valueConsumer.setValue(this.value);
pm.popParser(true);
}
}
use of dyvilx.tools.compiler.ast.expression.ClassOperator in project Dyvil by Dyvil.
the class EnumClassMetadata method createFromNameMethod.
private CodeMethod createFromNameMethod() {
// @BytecodeName("valueOf")
// public static func from(name: String) -> EnumType
final SourcePosition position = this.theClass.position();
final IType type = this.theClass.getClassType();
final CodeMethod method = new CodeMethod(this.theClass, Name.fromRaw("from"), type, AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC));
method.setPosition(position);
method.setInternalName("valueOf");
final CodeParameter parameter = new CodeParameter(Name.fromRaw("name"), Types.STRING);
method.getParameters().add(parameter);
// = Enum.valueOf(class<EnumType>, name)
final MethodCall valueOfCall = new MethodCall(position, new ClassAccess(Types.ENUM), Name.fromRaw("valueOf"), new ArgumentList(new ClassOperator(this.theClass.getClassType()), new FieldAccess(parameter)));
method.setValue(valueOfCall);
return method;
}
Aggregations