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());
}
}
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;
}
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;
}
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());
}
}
Aggregations