Search in sources :

Example 11 with TypeDescriptor

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

the class LexicalScope method isReferenceParameter.

boolean isReferenceParameter(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.isReferenceParameter(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 12 with TypeDescriptor

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

the class NodeFactory method registerRecordVariantTagVariable.

public void registerRecordVariantTagVariable(Token identifierToken, Token typeToken) {
    String identifier = this.getIdentifierFromToken(identifierToken);
    TypeDescriptor type = this.getTypeDescriptor(typeToken);
    if (!(type instanceof OrdinalDescriptor)) {
        parser.SemErr("Record variant selector must be of ordinal type");
    }
    try {
        currentLexicalScope.registerLocalVariable(identifier, type);
    } 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) OrdinalDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.OrdinalDescriptor)

Example 13 with TypeDescriptor

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

the class NodeFactory method createReadVariableFromScope.

private ExpressionNode createReadVariableFromScope(String identifier, LexicalScope scope) {
    // TODO: check if it is a constant or a variable
    FrameSlot variableSlot = scope.getLocalSlot(identifier);
    TypeDescriptor type = scope.getIdentifierDescriptor(identifier);
    boolean isLocal = scope == currentLexicalScope;
    boolean isReference = type instanceof ReferenceDescriptor;
    boolean isConstant = type instanceof ConstantDescriptor;
    if (isConstant) {
        ConstantDescriptor constantType = (ConstantDescriptor) type;
        return ReadConstantNodeGen.create(constantType.getValue(), constantType);
    } else if (isLocal) {
        if (isReference) {
            return ReadReferenceVariableNodeGen.create(variableSlot, type);
        } else {
            return ReadLocalVariableNodeGen.create(variableSlot, type);
        }
    } else {
        return ReadGlobalVariableNodeGen.create(variableSlot, type);
    }
}
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 14 with TypeDescriptor

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

the class NodeFactory method addProgramArgumentsAssignmentNodes.

private void addProgramArgumentsAssignmentNodes() {
    int currentArgument = 0;
    for (String argumentIdentifier : this.mainProgramArgumentsIdentifiers) {
        FrameSlot argumentSlot = this.currentLexicalScope.getLocalSlot(argumentIdentifier);
        TypeDescriptor typeDescriptor = this.currentLexicalScope.getIdentifierDescriptor(argumentIdentifier);
        if (typeDescriptor != null) {
            if (ProgramArgumentAssignmentNode.supportsType(typeDescriptor)) {
                this.currentLexicalScope.addScopeInitializationNode(new ProgramArgumentAssignmentNode(argumentSlot, typeDescriptor, currentArgument++));
            }
        // TODO: else -> show warning
        }
    }
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)

Example 15 with TypeDescriptor

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

the class BinaryExpressionNode method verifyBothCompatiblePointerTypes.

protected boolean verifyBothCompatiblePointerTypes(TypeDescriptor leftType, TypeDescriptor rightType) {
    if (!(leftType instanceof PointerDescriptor && rightType instanceof PointerDescriptor)) {
        return false;
    }
    TypeDescriptor leftInnerType = ((PointerDescriptor) leftType).getInnerTypeDescriptor();
    TypeDescriptor rightInnerType = ((PointerDescriptor) rightType).getInnerTypeDescriptor();
    return (leftInnerType == null) || (rightInnerType == null) || (rightInnerType.equals(leftInnerType));
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) PointerDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.PointerDescriptor)

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