Search in sources :

Example 26 with TypeDescriptor

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

the class LexicalScope method isSubroutineParameter.

boolean isSubroutineParameter(String identifier, int parameterIndex) throws LexicalException {
    TypeDescriptor subroutineDescriptor = this.localIdentifiers.getIdentifierDescriptor(identifier);
    if (!(subroutineDescriptor instanceof SubroutineDescriptor)) {
        throw new LexicalException("Not a subroutine: " + identifier);
    }
    SubroutineDescriptor descriptor = (SubroutineDescriptor) subroutineDescriptor;
    return descriptor.isSubroutineParameter(parameterIndex);
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ReturnTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor) EnumTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.EnumTypeDescriptor) SubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)

Example 27 with TypeDescriptor

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

the class NodeFactory method createSimpleAssignment.

private StatementNode createSimpleAssignment(Token identifierToken, ExpressionNode valueNode) {
    String variableIdentifier = this.getIdentifierFromToken(identifierToken);
    FrameSlot frameSlot = this.doLookup(variableIdentifier, LexicalScope::getLocalSlot, true);
    TypeDescriptor targetType = this.doLookup(variableIdentifier, LexicalScope::getIdentifierDescriptor, true);
    this.checkTypesAreCompatible(valueNode.getType(), targetType);
    return (targetType instanceof ReferenceDescriptor) ? AssignReferenceNodeGen.create(valueNode, frameSlot) : SimpleAssignmentNodeGen.create(valueNode, frameSlot);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ReferenceDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.ReferenceDescriptor)

Example 28 with TypeDescriptor

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

the class NodeFactory method addUnitFunctionInterface.

public void addUnitFunctionInterface(Token identifierToken, List<FormalParameter> formalParameters, Token returnTypeToken) {
    String identifier = this.getIdentifierFromToken(identifierToken);
    TypeDescriptor returnTypeDescriptor = this.getTypeDescriptor(returnTypeToken);
    try {
        currentLexicalScope.forwardFunction(identifier, formalParameters, returnTypeDescriptor);
    } 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 29 with TypeDescriptor

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

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

the class IdentifiersTable method addFunctionInterfaceIfNotForwarded.

public void addFunctionInterfaceIfNotForwarded(String identifier, List<FormalParameter> formalParameters, TypeDescriptor returnType) throws LexicalException {
    TypeDescriptor descriptor = this.identifiersMap.get(identifier);
    if (descriptor != null) {
        if (!(descriptor instanceof FunctionDescriptor)) {
            throw new LexicalException("Not a subroutine");
        } else {
            if (!SubroutineDescriptor.compareFormalParametersExact(((SubroutineDescriptor) descriptor).getFormalParameters(), formalParameters)) {
                throw new LexicalException("Argument types mismatch");
            }
        }
        return;
    }
    this.forwardFunction(identifier, formalParameters, returnType);
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) TypeTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeTypeDescriptor)

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