Search in sources :

Example 1 with ArrayDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor in project TrufflePascal by Aspect26.

the class NodeFactory method createReadFromArrayNode.

public ExpressionNode createReadFromArrayNode(ExpressionNode arrayExpression, List<ExpressionNode> indexes) {
    ExpressionNode readArrayNode = arrayExpression;
    for (ExpressionNode index : indexes) {
        TypeDescriptor actualType = this.getActualType(readArrayNode.getType());
        if (!(actualType instanceof ArrayDescriptor)) {
            parser.SemErr("Not an array");
            break;
        }
        ReadIndexNode readIndexNode = ReadIndexNodeGen.create(index, ((ArrayDescriptor) actualType).getOffset());
        TypeDescriptor returnType = ((ArrayDescriptor) actualType).getValuesDescriptor();
        readArrayNode = ReadFromArrayNodeGen.create(readArrayNode, readIndexNode, returnType);
    }
    return readArrayNode;
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ArrayDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor)

Example 2 with ArrayDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor in project TrufflePascal by Aspect26.

the class NodeFactory method createAssignmentToArray.

private StatementNode createAssignmentToArray(ExpressionNode arrayExpression, ExpressionNode indexExpressionNode, ExpressionNode valueNode) {
    TypeDescriptor expressionType = getActualType(arrayExpression.getType());
    int arrayOffset = 0;
    if (!(expressionType instanceof ArrayDescriptor)) {
        parser.SemErr("Not an array");
    } else {
        this.doTypeCheck(valueNode.getType(), ((ArrayDescriptor) expressionType).getValuesDescriptor());
        arrayOffset = ((ArrayDescriptor) expressionType).getOffset();
    }
    ReadIndexNode indexNode = ReadIndexNodeGen.create(indexExpressionNode, arrayOffset);
    return AssignToArrayNodeGen.create(arrayExpression, indexNode, valueNode);
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ArrayDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor)

Example 3 with ArrayDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor in project TrufflePascal by Aspect26.

the class NodeFactory method createArray.

public TypeDescriptor createArray(List<OrdinalDescriptor> ordinalDimensions, Token returnTypeToken) {
    String typeIdentifier = this.getTypeNameFromToken(returnTypeToken);
    TypeDescriptor returnTypeDescriptor = this.doLookup(typeIdentifier, LexicalScope::getTypeDescriptor);
    ArrayDescriptor array = currentLexicalScope.createArrayType(ordinalDimensions.get(ordinalDimensions.size() - 1), returnTypeDescriptor);
    for (int i = ordinalDimensions.size() - 2; i > -1; --i) {
        array = currentLexicalScope.createArrayType(ordinalDimensions.get(i), array);
    }
    return array;
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ArrayDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor)

Aggregations

TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)3 ArrayDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor)3