use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method addParameterIdentifiersToLexicalScope.
private void addParameterIdentifiersToLexicalScope(List<FormalParameter> parameters) {
try {
int count = 0;
for (FormalParameter parameter : parameters) {
TypeDescriptor typeDescriptor = parameter.type;
if (typeDescriptor == null)
return;
if (parameter.isReference) {
FrameSlot frameSlot = this.currentLexicalScope.registerReferenceVariable(parameter.identifier, typeDescriptor);
final ReferenceInitializationNode initializationNode = new ReferenceInitializationNode(frameSlot, count++);
this.currentLexicalScope.addScopeInitializationNode(initializationNode);
} else {
this.currentLexicalScope.registerLocalVariable(parameter.identifier, typeDescriptor);
final ExpressionNode readNode = new ReadArgumentNode(count, parameters.get(count++).type);
final SimpleAssignmentNode assignment = this.createAssignmentNode(parameter.identifier, readNode);
this.currentLexicalScope.addScopeInitializationNode(assignment);
}
}
} 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 createReadFromRecordNode.
public ReadFromRecordNode createReadFromRecordNode(ExpressionNode recordExpression, Token identifierToken) {
TypeDescriptor descriptor = this.getActualType(recordExpression.getType());
String identifier = this.getIdentifierFromToken(identifierToken);
TypeDescriptor returnType = null;
if (!(descriptor instanceof RecordDescriptor)) {
parser.SemErr("Can not access non record type this way");
} else {
RecordDescriptor accessedRecordDescriptor = (RecordDescriptor) descriptor;
if (!accessedRecordDescriptor.containsIdentifier(identifier)) {
parser.SemErr("The record does not contain this identifier");
} else {
returnType = accessedRecordDescriptor.getLexicalScope().getIdentifierDescriptor(identifier);
}
}
return ReadFromRecordNodeGen.create(recordExpression, returnType, identifier);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method createSubroutineParameterPassNode.
public ExpressionNode createSubroutineParameterPassNode(Token variableToken) {
String variableIdentifier = this.getIdentifierFromToken(variableToken);
PascalSubroutine function = this.doLookup(variableIdentifier, LexicalScope::getSubroutine);
TypeDescriptor descriptor = this.doLookup(variableIdentifier, LexicalScope::getIdentifierDescriptor);
return new SubroutineLiteralNode(function, (SubroutineDescriptor) descriptor);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method stepIntoRecordElementScope.
private FrameSlot stepIntoRecordElementScope(String recordIdentifier) throws LexicalException {
TypeDescriptor recordDescriptor = this.currentLexicalScope.getIdentifierDescriptor(recordIdentifier);
if (recordDescriptor == null || !(recordDescriptor instanceof RecordDescriptor)) {
throw new LexicalException("Not a record: " + recordIdentifier);
} else {
FrameSlot recordSlot = this.currentLexicalScope.getLocalSlot(recordIdentifier);
this.currentLexicalScope = ((RecordDescriptor) recordDescriptor).getLexicalScope();
return recordSlot;
}
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method createAssignmentNode.
private SimpleAssignmentNode createAssignmentNode(String targetIdentifier, ExpressionNode valueNode) {
TypeDescriptor targetType = this.doLookup(targetIdentifier, LexicalScope::getIdentifierDescriptor);
this.checkTypesAreCompatible(valueNode.getType(), targetType);
FrameSlot targetSlot = this.doLookup(targetIdentifier, LexicalScope::getLocalSlot);
return SimpleAssignmentNodeGen.create(valueNode, targetSlot);
}
Aggregations