Search in sources :

Example 1 with ClassBody

use of dyvilx.tools.compiler.ast.classes.ClassBody in project Dyvil by Dyvil.

the class ConstructorCallParser method parseBody.

/**
 * Creates the body and initializes parsing for anonymous classes.
 *
 * @param pm
 * 	the current parsing context manager.
 */
private void parseBody(IParserManager pm) {
    final ClassConstructorCall classConstructorCall = this.call.toClassConstructor();
    this.call = classConstructorCall;
    final IClass nestedClass = classConstructorCall.getNestedClass();
    final ClassBody body = nestedClass.getBody();
    pm.pushParser(new ClassBodyParser(body), true);
    this.mode = ANONYMOUS_CLASS_END;
}
Also used : ClassBodyParser(dyvilx.tools.compiler.parser.classes.ClassBodyParser) IClass(dyvilx.tools.compiler.ast.classes.IClass) ClassConstructorCall(dyvilx.tools.compiler.ast.expression.access.ClassConstructorCall) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 2 with ClassBody

use of dyvilx.tools.compiler.ast.classes.ClassBody in project Dyvil by Dyvil.

the class Template method parse.

@Override
public void parse() {
    // class NAME { }
    final CodeClass theClass = new CodeClass(null, this.name, AttributeList.of(Modifiers.PUBLIC));
    final ClassBody classBody = new ClassBody(theClass);
    theClass.setBody(classBody);
    this.addClass(theClass);
    this.templateClass = theClass;
    // func generate(spec, writer) -> void = { ... }
    final CodeMethod genMethod = new CodeMethod(theClass, Name.fromRaw("generate"), Types.VOID, AttributeList.of(Modifiers.PUBLIC | Modifiers.OVERRIDE));
    final StatementList directives = new StatementList();
    genMethod.setValue(directives);
    classBody.addMethod(genMethod);
    this.genMethod = genMethod;
    // func main(args) -> void
    final CodeMethod mainMethod = new CodeMethod(theClass, Name.fromRaw("main"), Types.VOID, AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC));
    classBody.addMethod(mainMethod);
    this.mainMethod = mainMethod;
    // Parse
    new ParserManager(DyvilSymbols.INSTANCE, this.tokens.iterator(), this.markers).parse(new BlockParser(this, directives));
}
Also used : ParserManager(dyvilx.tools.parsing.ParserManager) BlockParser(dyvilx.tools.gensrc.parser.BlockParser) CodeMethod(dyvilx.tools.compiler.ast.method.CodeMethod) StatementList(dyvilx.tools.compiler.ast.statement.StatementList) CodeClass(dyvilx.tools.compiler.ast.classes.CodeClass) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 3 with ClassBody

use of dyvilx.tools.compiler.ast.classes.ClassBody in project Dyvil by Dyvil.

the class ClassMetadata method resolveTypesBody.

@Override
public void resolveTypesBody(MarkerList markers, IContext context) {
    // Check if a constructor needs to be generated
    final ClassBody body = this.theClass.getBody();
    if (body == null) {
        return;
    }
    this.checkMembers(body);
    if (body.constructorCount() <= 0) {
        return;
    }
    final ParameterList parameters = this.theClass.getParameters();
    final IConstructor constructor = body.getConstructor(parameters);
    if (constructor != null) {
        this.constructor = constructor;
        this.members |= CONSTRUCTOR;
        return;
    }
    if (parameters.isEmpty()) {
        // Do not generate an empty default constructor if there is any other constructor defined
        this.members |= CONSTRUCTOR;
    }
}
Also used : IConstructor(dyvilx.tools.compiler.ast.constructor.IConstructor) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 4 with ClassBody

use of dyvilx.tools.compiler.ast.classes.ClassBody in project Dyvil by Dyvil.

the class EnumClassMetadata method resolveTypesGenerate.

@Override
public void resolveTypesGenerate(MarkerList markers, IContext context) {
    super.resolveTypesGenerate(markers, context);
    final ClassBody body = this.theClass.createBody();
    body.addDataMember(this.createValuesField());
    body.addMethod(this.createValuesMethod());
    body.addMethod(this.createFromOrdMethod());
    body.addMethod(this.createFromNameMethod());
    // Replace super initializer calls from constructors
    for (IConstructor ctor : body.constructors()) {
        this.updateConstructor(ctor);
    }
}
Also used : IConstructor(dyvilx.tools.compiler.ast.constructor.IConstructor) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 5 with ClassBody

use of dyvilx.tools.compiler.ast.classes.ClassBody in project Dyvil by Dyvil.

the class CaseClassMetadata method resolveTypesGenerate.

@Override
public void resolveTypesGenerate(MarkerList markers, IContext context) {
    super.resolveTypesGenerate(markers, context);
    final ClassBody body = this.theClass.createBody();
    if ((this.members & APPLY) == 0) {
        this.applyMethod = this.createApplyMethod();
        body.addMethod(this.applyMethod);
    }
    if ((this.members & UNAPPLY) == 0) {
        this.unapplyMethod = this.createUnapplyMethod();
        body.addMethod(this.unapplyMethod);
    }
    if ((this.members & UNAPPLY_ANY) == 0) {
        this.unapplyAnyMethod = this.createUnapplyAnyMethod();
        body.addMethod(this.unapplyAnyMethod);
    }
}
Also used : ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Aggregations

ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)12 CodeClass (dyvilx.tools.compiler.ast.classes.CodeClass)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)2 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)2 Name (dyvil.lang.Name)1 TextSource (dyvil.source.TextSource)1 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)1 CodeAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation)1 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)1 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)1 ClassConstructorCall (dyvilx.tools.compiler.ast.expression.access.ClassConstructorCall)1 IField (dyvilx.tools.compiler.ast.field.IField)1 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)1 IMethod (dyvilx.tools.compiler.ast.method.IMethod)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)1 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)1 TypeList (dyvilx.tools.compiler.ast.type.TypeList)1 AnnotationParser (dyvilx.tools.compiler.parser.annotation.AnnotationParser)1 ClassBodyParser (dyvilx.tools.compiler.parser.classes.ClassBodyParser)1