Search in sources :

Example 31 with TypeDescriptor

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

the class IdentifiersTable method addProcedureInterfaceIfNotForwarded.

public void addProcedureInterfaceIfNotForwarded(String identifier, List<FormalParameter> formalParameters) throws LexicalException {
    TypeDescriptor descriptor = this.identifiersMap.get(identifier);
    if (descriptor != null) {
        if (!(descriptor instanceof ProcedureDescriptor)) {
            throw new LexicalException("Not a subroutine");
        } else {
            if (!SubroutineDescriptor.compareFormalParametersExact(((SubroutineDescriptor) descriptor).getFormalParameters(), formalParameters)) {
                throw new LexicalException("Argument types mismatch");
            }
        }
        return;
    }
    this.forwardProcedure(identifier, formalParameters);
}
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)

Example 32 with TypeDescriptor

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

the class IdentifiersTable method forwardProcedure.

public void forwardProcedure(String identifier, List<FormalParameter> formalParameters) throws LexicalException {
    TypeDescriptor typeDescriptor = new ProcedureDescriptor(formalParameters);
    this.registerNewIdentifier(identifier, typeDescriptor);
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) TypeTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeTypeDescriptor)

Example 33 with TypeDescriptor

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

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

the class NodeFactory method createInvokeNode.

private ExpressionNode createInvokeNode(String identifier, SubroutineDescriptor descriptor, LexicalScope subroutineScope, List<ExpressionNode> argumentNodes) {
    ExpressionNode[] arguments = argumentNodes.toArray(new ExpressionNode[argumentNodes.size()]);
    TypeDescriptor returnType = (descriptor instanceof FunctionDescriptor) ? ((FunctionDescriptor) descriptor).getReturnDescriptor() : null;
    if (subroutineScope instanceof UnitLexicalScope) {
        String unitIdentifier = subroutineScope.getName();
        return ContextInvokeNodeGen.create(identifier, unitIdentifier, arguments, returnType);
    } else {
        FrameSlot subroutineSlot = subroutineScope.getLocalSlot(identifier);
        return InvokeNodeGen.create(subroutineSlot, arguments, returnType);
    }
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FunctionDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.FunctionDescriptor)

Example 35 with TypeDescriptor

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