use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class ConstructorCallParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case NEW:
if (type != DyvilKeywords.NEW) {
pm.report(token, "constructor.new");
pm.reparse();
}
final ArgumentList arguments = token.next().type() == BaseSymbols.OPEN_PARENTHESIS ? null : ArgumentList.empty();
this.call = new ConstructorCall(token.raw(), arguments);
this.mode = CONSTRUCTOR_PARAMETERS;
pm.pushParser(new TypeParser(this.call));
return;
case CONSTRUCTOR_PARAMETERS:
// ^
if (type == BaseSymbols.OPEN_PARENTHESIS) {
// new ... (
this.mode = CONSTRUCTOR_PARAMETERS_END;
ArgumentListParser.parseArguments(pm, token.next(), this.call);
return;
}
// Fallthrough
case ANONYMOUS_CLASS:
if (type == BaseSymbols.OPEN_CURLY_BRACKET && (this.flags & IGNORE_ANON_CLASS) == 0) {
// new ... ( ... ) { ...
this.parseBody(pm);
return;
}
pm.reparse();
this.end(pm, token.prev());
return;
case CONSTRUCTOR_PARAMETERS_END:
// new ... ( ... )
// ^
this.mode = ANONYMOUS_CLASS;
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.reparse();
pm.report(token, "constructor.call.close_paren");
}
return;
case ANONYMOUS_CLASS_END:
// new ... { ... } ...
// ^
this.end(pm, token);
if (type != BaseSymbols.CLOSE_CURLY_BRACKET) {
pm.reparse();
pm.report(token, "class.anonymous.body.end");
}
}
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class Template method resolveTypes.
@Override
public void resolveTypes() {
this.makeGenerateSpecMethod();
this.makeMainMethod();
// automatically infer package declaration
this.packageDeclaration = new PackageDeclaration(null, this.getPackage().getFullName());
this.templateClass.setSuperType(LazyTypes.Template);
this.templateClass.setSuperConstructorArguments(new ArgumentList(new StringValue(this.getTemplateName())));
super.resolveTypes();
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class FieldAssignment method resolveAsMethod.
@Override
protected IValue resolveAsMethod(IValue receiver, MarkerList markers, IContext context) {
final Name name = Util.addEq(this.name);
final ArgumentList argument = new ArgumentList(this.value);
final MethodAssignment assignment = new MethodAssignment(this.position, receiver, name, argument);
return assignment.resolveCall(markers, context, false);
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class MethodAssignment method writeExpression.
@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
if (Types.isVoid(type)) {
super.writeExpression(writer, type);
return;
}
final IValue expression = this.arguments.getFirst();
final Variable receiverVar = new Variable(null, this.receiver.getType(), this.receiver);
final Variable expressionVar = new Variable(null, expression.getType(), expression);
receiverVar.writeInit(writer);
expressionVar.writeInit(writer);
this.method.writeCall(writer, new FieldAccess(receiverVar), new ArgumentList(new FieldAccess(expressionVar)), this.genericData, Types.VOID, this.lineNumber());
expressionVar.writeGet(writer);
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class StringInterpolationExpr method foldConstants.
@Override
public IValue foldConstants() {
this.values.foldConstants();
// Merges adjacent String constants into one
final int size = this.values.size();
final ArgumentList newValues = new ArgumentList(size);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < size; i++) {
final IValue value = this.values.get(i);
if (value.toStringBuilder(builder)) {
continue;
}
moveString(builder, newValues);
newValues.add(value);
}
moveString(builder, newValues);
if (newValues.isEmpty()) {
return new StringValue("");
}
// assert newValues.size() >= 1
final IValue first = newValues.getFirst();
if (newValues.size() == 1 && isString(first)) {
return first;
}
this.values = newValues;
return this;
}
Aggregations