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;
}
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));
}
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;
}
}
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);
}
}
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);
}
}
Aggregations