Search in sources :

Example 1 with ClassOperator

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);
    }
}
Also used : TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) TypeOperator(dyvilx.tools.compiler.ast.expression.TypeOperator) ClassOperator(dyvilx.tools.compiler.ast.expression.ClassOperator)

Example 2 with ClassOperator

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;
}
Also used : CodeMethod(dyvilx.tools.compiler.ast.method.CodeMethod) SourcePosition(dyvil.source.position.SourcePosition) ClassOperator(dyvilx.tools.compiler.ast.expression.ClassOperator) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

ClassOperator (dyvilx.tools.compiler.ast.expression.ClassOperator)2 SourcePosition (dyvil.source.position.SourcePosition)1 TypeOperator (dyvilx.tools.compiler.ast.expression.TypeOperator)1 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)1 IType (dyvilx.tools.compiler.ast.type.IType)1 TypeParser (dyvilx.tools.compiler.parser.type.TypeParser)1