Search in sources :

Example 31 with ArgumentList

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");
            }
    }
}
Also used : TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) ClassConstructorCall(dyvilx.tools.compiler.ast.expression.access.ClassConstructorCall) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall)

Example 32 with ArgumentList

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();
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) StringValue(dyvilx.tools.compiler.ast.expression.constant.StringValue) PackageDeclaration(dyvilx.tools.compiler.ast.header.PackageDeclaration)

Example 33 with ArgumentList

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);
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Name(dyvil.lang.Name)

Example 34 with ArgumentList

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);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Variable(dyvilx.tools.compiler.ast.field.Variable) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 35 with ArgumentList

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;
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) StringValue(dyvilx.tools.compiler.ast.expression.constant.StringValue)

Aggregations

ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)37 IValue (dyvilx.tools.compiler.ast.expression.IValue)17 IType (dyvilx.tools.compiler.ast.type.IType)10 SourcePosition (dyvil.source.position.SourcePosition)8 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)5 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)5 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)5 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)5 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)4 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)4 MarkerLevel (dyvil.util.MarkerLevel)3 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)3 StringValue (dyvilx.tools.compiler.ast.expression.constant.StringValue)3 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)3 Marker (dyvilx.tools.parsing.marker.Marker)3 Reason (dyvil.annotation.Deprecated.Reason)2 Name (dyvil.lang.Name)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)2