Search in sources :

Example 1 with SubroutineDescriptor

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

the class NodeFactory method createSubroutineCall.

public ExpressionNode createSubroutineCall(Token identifierToken, List<ExpressionNode> params) {
    String identifier = this.getIdentifierFromToken(identifierToken);
    return this.doLookup(identifier, (LexicalScope foundInScope, String foundIdentifier) -> {
        if (foundInScope.isSubroutine(foundIdentifier)) {
            SubroutineDescriptor subroutineDescriptor = foundInScope.getSubroutineDescriptor(foundIdentifier, params);
            subroutineDescriptor.verifyArguments(params);
            return this.createInvokeNode(foundIdentifier, subroutineDescriptor, foundInScope, params);
        } else {
            throw new LexicalException(foundIdentifier + " is not a subroutine.");
        }
    });
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) SubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)

Example 2 with SubroutineDescriptor

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

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

the class BuiltinUnitAbstr method importTo.

@Override
public void importTo(UnitLexicalScope lexicalScope) {
    List<UnitSubroutineData> unitFunctions = this.getIdentifiers();
    for (UnitSubroutineData unitFunction : unitFunctions) {
        String identifier = unitFunction.identifier.toLowerCase();
        SubroutineDescriptor descriptor = unitFunction.descriptor;
        // register to identifiers table and function registry
        lexicalScope.registerBuiltinSubroutine(identifier, descriptor);
    }
    lexicalScope.markAllIdentifiersPublic();
}
Also used : SubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)

Example 4 with SubroutineDescriptor

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

Aggregations

SubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)4 LexicalException (cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException)3 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)2 EnumTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.EnumTypeDescriptor)2 ReturnTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)2