use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor 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);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method createSimpleAssignment.
private StatementNode createSimpleAssignment(Token identifierToken, ExpressionNode valueNode) {
String variableIdentifier = this.getIdentifierFromToken(identifierToken);
FrameSlot frameSlot = this.doLookup(variableIdentifier, LexicalScope::getLocalSlot, true);
TypeDescriptor targetType = this.doLookup(variableIdentifier, LexicalScope::getIdentifierDescriptor, true);
this.checkTypesAreCompatible(valueNode.getType(), targetType);
return (targetType instanceof ReferenceDescriptor) ? AssignReferenceNodeGen.create(valueNode, frameSlot) : SimpleAssignmentNodeGen.create(valueNode, frameSlot);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method addUnitFunctionInterface.
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());
}
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method createReadFromArrayNode.
public ExpressionNode createReadFromArrayNode(ExpressionNode arrayExpression, List<ExpressionNode> indexes) {
ExpressionNode readArrayNode = arrayExpression;
for (ExpressionNode index : indexes) {
TypeDescriptor actualType = this.getActualType(readArrayNode.getType());
if (!(actualType instanceof ArrayDescriptor)) {
parser.SemErr("Not an array");
break;
}
ReadIndexNode readIndexNode = ReadIndexNodeGen.create(index, ((ArrayDescriptor) actualType).getOffset());
TypeDescriptor returnType = ((ArrayDescriptor) actualType).getValuesDescriptor();
readArrayNode = ReadFromArrayNodeGen.create(readArrayNode, readIndexNode, returnType);
}
return readArrayNode;
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class IdentifiersTable method addFunctionInterfaceIfNotForwarded.
public void addFunctionInterfaceIfNotForwarded(String identifier, List<FormalParameter> formalParameters, TypeDescriptor returnType) throws LexicalException {
TypeDescriptor descriptor = this.identifiersMap.get(identifier);
if (descriptor != null) {
if (!(descriptor instanceof FunctionDescriptor)) {
throw new LexicalException("Not a subroutine");
} else {
if (!SubroutineDescriptor.compareFormalParametersExact(((SubroutineDescriptor) descriptor).getFormalParameters(), formalParameters)) {
throw new LexicalException("Argument types mismatch");
}
}
return;
}
this.forwardFunction(identifier, formalParameters, returnType);
}
Aggregations