Search in sources :

Example 1 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class FieldAccess method resolveAsField.

@Override
protected IValue resolveAsField(IValue receiver, MarkerList markers, IContext context) {
    final IDataMember field = ICall.resolveField(context, receiver, this.name);
    if (field == null) {
        return null;
    }
    if (field.isEnumConstant()) {
        return new EnumValue(this.position, field);
    }
    this.receiver = receiver;
    this.field = field;
    this.capture(markers, context);
    return this;
}
Also used : EnumValue(dyvilx.tools.compiler.ast.expression.constant.EnumValue) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 2 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class EnumValue method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (this.field == null) {
        final IDataMember field = type.resolveField(this.name);
        if (field == null) {
            markers.add(Markers.semanticError(this.position, "resolve.field", this.name));
            return null;
        }
        this.field = field;
    }
    return super.withType(type, typeContext, markers, context);
}
Also used : IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 3 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class ProcessedText method resolve.

@Override
public IValue resolve(MarkerList markers, IContext context) {
    final int startLine = this.position.startLine();
    final int startColumn = this.position.startColumn();
    final StringInterpolationExpr parts = new StringInterpolationExpr();
    final String text = this.text;
    final int length = text.length();
    int prev = 0;
    for (int startIndex = 0; startIndex < length; ) {
        final int c = text.codePointAt(startIndex);
        // advance to an identifier character
        if (!Character.isJavaIdentifierStart(c)) {
            startIndex += Character.charCount(c);
            continue;
        }
        final int endIndex = identifierEnd(text, startIndex + 1, length);
        final String key = text.substring(startIndex, endIndex);
        final IDataMember field = context.resolveField(Name.fromRaw(key));
        if (field != null && (field.isLocal() || field.hasModifier(Modifiers.PUBLIC))) {
            // append contents before this identifier
            parts.append(new StringValue(text.substring(prev, startIndex)));
            final SourcePosition position = SourcePosition.apply(startLine, startColumn + startIndex, startColumn + endIndex);
            parts.append(new FieldAccess(position, null, field));
            // advance to the end of the identifier
            prev = endIndex;
            startIndex = endIndex;
            continue;
        }
        startIndex += Character.charCount(c);
    }
    if (prev != length) {
        parts.append(new StringValue(text.substring(prev, length)));
    }
    return new WriteCall(parts.resolve(markers, context));
}
Also used : SourcePosition(dyvil.source.position.SourcePosition) StringInterpolationExpr(dyvilx.tools.compiler.ast.expression.StringInterpolationExpr) StringValue(dyvilx.tools.compiler.ast.expression.constant.StringValue) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 4 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class CaseClasses method writeHashCode.

public static void writeHashCode(MethodWriter writer, IClass theClass) throws BytecodeException {
    writer.visitLdcInsn(31);
    final ParameterList parameters = theClass.getParameters();
    for (int i = 0, count = parameters.size(); i < count; i++) {
        final IDataMember parameter = parameters.get(i);
        // Load the value of the field
        writer.visitVarInsn(ALOAD, 0);
        parameter.writeGet(writer, null, 0);
        // Write the hashing strategy for the parameter
        writeHashCode(writer, parameter.getType());
        // Add the hash to the previous result
        writer.visitInsn(IADD);
        writer.visitLdcInsn(31);
        // Multiply the result by 31
        writer.visitInsn(IMUL);
    }
    writer.visitInsn(IRETURN);
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 5 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class StatementList method addVariable.

protected void addVariable(VariableStatement initializer, MarkerList markers, IContext context) {
    final IVariable variable = initializer.variable;
    final Name variableName = variable.getName();
    // Uninitialized Variables
    if (variable.getValue() == null) {
        variable.setValue(variable.getType().getDefaultValue());
        markers.add(Markers.semanticError(variable.getPosition(), "variable.uninitialized", variableName));
    }
    // Variable Name Shadowing
    final IDataMember dataMember = context.resolveField(variableName);
    if (dataMember != null && dataMember.isLocal() && !variable.hasModifier(Modifiers.GENERATED)) {
        markers.add(Markers.semantic(initializer.getPosition(), "variable.shadow", variableName));
    }
    // Actually add the Variable to the List (this has to happen after checking for shadowed variables)
    this.addVariable(variable);
}
Also used : IVariable(dyvilx.tools.compiler.ast.field.IVariable) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember) Name(dyvil.lang.Name)

Aggregations

IDataMember (dyvilx.tools.compiler.ast.field.IDataMember)10 Name (dyvil.lang.Name)2 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)2 IType (dyvilx.tools.compiler.ast.type.IType)2 SourcePosition (dyvil.source.position.SourcePosition)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 StringInterpolationExpr (dyvilx.tools.compiler.ast.expression.StringInterpolationExpr)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 EnumValue (dyvilx.tools.compiler.ast.expression.constant.EnumValue)1 StringValue (dyvilx.tools.compiler.ast.expression.constant.StringValue)1 IVariable (dyvilx.tools.compiler.ast.field.IVariable)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1 NamedType (dyvilx.tools.compiler.ast.type.raw.NamedType)1