use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class IdentifiersTable method addProcedureInterfaceIfNotForwarded.
public void addProcedureInterfaceIfNotForwarded(String identifier, List<FormalParameter> formalParameters) throws LexicalException {
TypeDescriptor descriptor = this.identifiersMap.get(identifier);
if (descriptor != null) {
if (!(descriptor instanceof ProcedureDescriptor)) {
throw new LexicalException("Not a subroutine");
} else {
if (!SubroutineDescriptor.compareFormalParametersExact(((SubroutineDescriptor) descriptor).getFormalParameters(), formalParameters)) {
throw new LexicalException("Argument types mismatch");
}
}
return;
}
this.forwardProcedure(identifier, formalParameters);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class IdentifiersTable method forwardProcedure.
public void forwardProcedure(String identifier, List<FormalParameter> formalParameters) throws LexicalException {
TypeDescriptor typeDescriptor = new ProcedureDescriptor(formalParameters);
this.registerNewIdentifier(identifier, typeDescriptor);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method createAssignmentToArray.
private StatementNode createAssignmentToArray(ExpressionNode arrayExpression, ExpressionNode indexExpressionNode, ExpressionNode valueNode) {
TypeDescriptor expressionType = getActualType(arrayExpression.getType());
int arrayOffset = 0;
if (!(expressionType instanceof ArrayDescriptor)) {
parser.SemErr("Not an array");
} else {
this.doTypeCheck(valueNode.getType(), ((ArrayDescriptor) expressionType).getValuesDescriptor());
arrayOffset = ((ArrayDescriptor) expressionType).getOffset();
}
ReadIndexNode indexNode = ReadIndexNodeGen.create(indexExpressionNode, arrayOffset);
return AssignToArrayNodeGen.create(arrayExpression, indexNode, valueNode);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method createInvokeNode.
private ExpressionNode createInvokeNode(String identifier, SubroutineDescriptor descriptor, LexicalScope subroutineScope, List<ExpressionNode> argumentNodes) {
ExpressionNode[] arguments = argumentNodes.toArray(new ExpressionNode[argumentNodes.size()]);
TypeDescriptor returnType = (descriptor instanceof FunctionDescriptor) ? ((FunctionDescriptor) descriptor).getReturnDescriptor() : null;
if (subroutineScope instanceof UnitLexicalScope) {
String unitIdentifier = subroutineScope.getName();
return ContextInvokeNodeGen.create(identifier, unitIdentifier, arguments, returnType);
} else {
FrameSlot subroutineSlot = subroutineScope.getLocalSlot(identifier);
return InvokeNodeGen.create(subroutineSlot, arguments, returnType);
}
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor 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;
}
Aggregations