Search in sources :

Example 1 with TypeDescriptor

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

the class NodeFactory method addParameterIdentifiersToLexicalScope.

private void addParameterIdentifiersToLexicalScope(List<FormalParameter> parameters) {
    try {
        int count = 0;
        for (FormalParameter parameter : parameters) {
            TypeDescriptor typeDescriptor = parameter.type;
            if (typeDescriptor == null)
                return;
            if (parameter.isReference) {
                FrameSlot frameSlot = this.currentLexicalScope.registerReferenceVariable(parameter.identifier, typeDescriptor);
                final ReferenceInitializationNode initializationNode = new ReferenceInitializationNode(frameSlot, count++);
                this.currentLexicalScope.addScopeInitializationNode(initializationNode);
            } else {
                this.currentLexicalScope.registerLocalVariable(parameter.identifier, typeDescriptor);
                final ExpressionNode readNode = new ReadArgumentNode(count, parameters.get(count++).type);
                final SimpleAssignmentNode assignment = this.createAssignmentNode(parameter.identifier, readNode);
                this.currentLexicalScope.addScopeInitializationNode(assignment);
            }
        }
    } catch (LexicalException e) {
        parser.SemErr(e.getMessage());
    }
}
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)

Example 2 with TypeDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor 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 3 with TypeDescriptor

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

the class NodeFactory method createSubroutineParameterPassNode.

public ExpressionNode createSubroutineParameterPassNode(Token variableToken) {
    String variableIdentifier = this.getIdentifierFromToken(variableToken);
    PascalSubroutine function = this.doLookup(variableIdentifier, LexicalScope::getSubroutine);
    TypeDescriptor descriptor = this.doLookup(variableIdentifier, LexicalScope::getIdentifierDescriptor);
    return new SubroutineLiteralNode(function, (SubroutineDescriptor) descriptor);
}
Also used : PascalSubroutine(cz.cuni.mff.d3s.trupple.language.runtime.customvalues.PascalSubroutine) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)

Example 4 with TypeDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor 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 5 with TypeDescriptor

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

the class NodeFactory method createAssignmentNode.

private SimpleAssignmentNode createAssignmentNode(String targetIdentifier, ExpressionNode valueNode) {
    TypeDescriptor targetType = this.doLookup(targetIdentifier, LexicalScope::getIdentifierDescriptor);
    this.checkTypesAreCompatible(valueNode.getType(), targetType);
    FrameSlot targetSlot = this.doLookup(targetIdentifier, LexicalScope::getLocalSlot);
    return SimpleAssignmentNodeGen.create(valueNode, targetSlot);
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot)

Aggregations

TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)50 LexicalException (cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException)9 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)7 TypeTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeTypeDescriptor)6 OrdinalDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.OrdinalDescriptor)5 ArrayList (java.util.ArrayList)4 ArrayDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor)3 EnumTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.EnumTypeDescriptor)3 RecordDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.RecordDescriptor)3 ReturnTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)3 PointerDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.PointerDescriptor)2 ReferenceDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.ReferenceDescriptor)2 ConstantDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.constant.ConstantDescriptor)2 SubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)2 List (java.util.List)2 StatementNode (cz.cuni.mff.d3s.trupple.language.nodes.statement.StatementNode)1 BinaryArgumentPrimitiveTypes (cz.cuni.mff.d3s.trupple.language.nodes.utils.BinaryArgumentPrimitiveTypes)1 PascalSubroutine (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.PascalSubroutine)1 UnknownIdentifierException (cz.cuni.mff.d3s.trupple.parser.exceptions.UnknownIdentifierException)1 SetDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.SetDescriptor)1