Search in sources :

Example 1 with ReturnTypeDescriptor

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

the class NodeFactory method startUnitFunctionImplementation.

/**
 * Changes the current state to represent that tha parser started parsing implementation of a function of currently
 * parsed unit.
 * @param heading signature of the function
 */
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(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) ReturnTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)

Example 2 with ReturnTypeDescriptor

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

the class NodeFactory method isReturnVariable.

/**
 * Checks whether the specified identifier is identifier of a return variable of any function visible from the
 * current lexical scope.
 */
public boolean isReturnVariable(Token identifierToken) {
    String identifier = this.getIdentifierFromToken(identifierToken);
    TypeDescriptor typeDescriptor = this.doLookup(identifier, LexicalScope::getIdentifierDescriptor, true);
    return typeDescriptor instanceof ReturnTypeDescriptor;
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ReturnTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor) ReturnTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)

Example 3 with ReturnTypeDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor 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) ReturnTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor) ArrayDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor)

Example 4 with ReturnTypeDescriptor

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

the class NodeFactory method addUnitFunctionInterface.

/**
 * Add new function to the currently parsed unit's lexical scope.
 * @param identifierToken identifier ot the function
 * @param formalParameters formal parameters of the function
 */
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) ReturnTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)

Aggregations

TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)4 ReturnTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)4 LexicalException (cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException)2 ArrayDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.ArrayDescriptor)1