Search in sources :

Example 36 with TypeDescriptor

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

Example 37 with TypeDescriptor

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

the class NodeFactory method startUnitFunctionImplementation.

public void startUnitFunctionImplementation(FunctionHeading heading) {
    String identifier = this.getIdentifierFromToken(heading.identifierToken);
    TypeDescriptor returnTypeDescriptor = heading.returnTypeDescriptor;
    try {
        if (currentLexicalScope.containsLocalIdentifier(identifier) && !currentLexicalScope.isSubroutine(identifier)) {
            parser.SemErr("Cannot implement. Not a function: " + identifier);
        } else if (!currentLexicalScope.containsLocalIdentifier(identifier)) {
            currentLexicalScope.forwardFunction(identifier, heading.formalParameters, returnTypeDescriptor);
        }
        currentLexicalScope = new LexicalScope(currentLexicalScope, identifier, parser.isUsingTPExtension());
        currentLexicalScope.registerReturnVariable(currentLexicalScope.getName(), returnTypeDescriptor);
        this.addParameterIdentifiersToLexicalScope(heading.formalParameters);
    } 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)

Example 38 with TypeDescriptor

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

the class NodeFactory method createReadDereferenceNode.

public ReadDereferenceNode createReadDereferenceNode(ExpressionNode pointerExpression) {
    PointerDescriptor pointerDescriptor = null;
    TypeDescriptor actualType = this.getActualType(pointerExpression.getType());
    if (actualType instanceof PointerDescriptor) {
        pointerDescriptor = (PointerDescriptor) actualType;
    } else {
        parser.SemErr("Can not dereference this type");
    }
    TypeDescriptor returnType = (pointerDescriptor != null) ? pointerDescriptor.getInnerTypeDescriptor() : null;
    return ReadDereferenceNodeGen.create(pointerExpression, returnType);
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) PointerDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.PointerDescriptor)

Example 39 with TypeDescriptor

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

the class FatalError method EnumDefinition.

TypeDescriptor EnumDefinition() {
    TypeDescriptor typeDescriptor;
    List<String> enumIdentifiers = new ArrayList<>();
    Expect(6);
    Expect(1);
    enumIdentifiers.add(factory.getIdentifierFromToken(t));
    while (la.kind == 10) {
        Get();
        Expect(1);
        enumIdentifiers.add(factory.getIdentifierFromToken(t));
    }
    Expect(7);
    typeDescriptor = factory.registerEnum(enumIdentifiers);
    return typeDescriptor;
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ArrayList(java.util.ArrayList)

Example 40 with TypeDescriptor

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

the class FatalError method Type.

TypeDescriptor Type() {
    TypeDescriptor typeDescriptor;
    typeDescriptor = null;
    if (isSubrange()) {
        typeDescriptor = SubrangeType();
    } else if (la.kind == 1) {
        Get();
        typeDescriptor = factory.getTypeDescriptor(t);
    } else if (la.kind == 6) {
        typeDescriptor = EnumDefinition();
    } else if (la.kind == 16 || la.kind == 17) {
        List<OrdinalDescriptor> ordinalDimensions = ArrayDefinition();
        while (continuesArray()) {
            Expect(14);
            List<OrdinalDescriptor> additionalDimensions = ArrayDefinition();
            ordinalDimensions.addAll(additionalDimensions);
        }
        Expect(14);
        Expect(1);
        typeDescriptor = factory.createArray(ordinalDimensions, t);
    } else if (la.kind == 15) {
        Get();
        Expect(14);
        OrdinalDescriptor ordinal = Ordinal();
        typeDescriptor = factory.createSetType(ordinal);
    } else if (la.kind == 20) {
        typeDescriptor = FileType();
    } else if (la.kind == 21) {
        typeDescriptor = RecordType();
    } else if (la.kind == 23) {
        typeDescriptor = PointerType();
    } else
        SynErr(73);
    return typeDescriptor;
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) List(java.util.List) ArrayList(java.util.ArrayList) OrdinalDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.OrdinalDescriptor)

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