Search in sources :

Example 1 with RecordDescriptor

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

the class NodeFactory method createReadFromRecordNode.

public ReadFromRecordNode createReadFromRecordNode(ExpressionNode recordExpression, Token identifierToken) {
    TypeDescriptor descriptor = this.getActualType(recordExpression.getType());
    String identifier = this.getIdentifierFromToken(identifierToken);
    TypeDescriptor returnType = null;
    if (!(descriptor instanceof RecordDescriptor)) {
        parser.SemErr("Can not access non record type this way");
    } else {
        RecordDescriptor accessedRecordDescriptor = (RecordDescriptor) descriptor;
        if (!accessedRecordDescriptor.containsIdentifier(identifier)) {
            parser.SemErr("The record does not contain this identifier");
        } else {
            returnType = accessedRecordDescriptor.getLexicalScope().getIdentifierDescriptor(identifier);
        }
    }
    return ReadFromRecordNodeGen.create(recordExpression, returnType, identifier);
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) RecordDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.RecordDescriptor)

Example 2 with RecordDescriptor

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

the class NodeFactory method stepIntoRecordElementScope.

private FrameSlot stepIntoRecordElementScope(String recordIdentifier) throws LexicalException {
    TypeDescriptor recordDescriptor = this.currentLexicalScope.getIdentifierDescriptor(recordIdentifier);
    if (recordDescriptor == null || !(recordDescriptor instanceof RecordDescriptor)) {
        throw new LexicalException("Not a record: " + recordIdentifier);
    } else {
        FrameSlot recordSlot = this.currentLexicalScope.getLocalSlot(recordIdentifier);
        this.currentLexicalScope = ((RecordDescriptor) recordDescriptor).getLexicalScope();
        return recordSlot;
    }
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) RecordDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.RecordDescriptor)

Example 3 with RecordDescriptor

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

the class NodeFactory method createAssignmentToRecordField.

private StatementNode createAssignmentToRecordField(ExpressionNode recordExpression, Token identifierToken, ExpressionNode valueNode) {
    String identifier = this.getIdentifierFromToken(identifierToken);
    TypeDescriptor expressionType = getActualType(recordExpression.getType());
    if (!(expressionType instanceof RecordDescriptor)) {
        parser.SemErr("Not a record");
    }
    return AssignToRecordFieldNodeGen.create(identifier, recordExpression, valueNode);
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) RecordDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.RecordDescriptor)

Aggregations

TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)3 RecordDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.RecordDescriptor)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 LexicalException (cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException)1