use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor 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);
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method registerRecordVariantTagVariable.
public void registerRecordVariantTagVariable(Token identifierToken, Token typeToken) {
String identifier = this.getIdentifierFromToken(identifierToken);
TypeDescriptor type = this.getTypeDescriptor(typeToken);
if (!(type instanceof OrdinalDescriptor)) {
parser.SemErr("Record variant selector must be of ordinal type");
}
try {
currentLexicalScope.registerLocalVariable(identifier, type);
} 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 createReadVariableFromScope.
private ExpressionNode createReadVariableFromScope(String identifier, LexicalScope scope) {
// TODO: check if it is a constant or a variable
FrameSlot variableSlot = scope.getLocalSlot(identifier);
TypeDescriptor type = scope.getIdentifierDescriptor(identifier);
boolean isLocal = scope == currentLexicalScope;
boolean isReference = type instanceof ReferenceDescriptor;
boolean isConstant = type instanceof ConstantDescriptor;
if (isConstant) {
ConstantDescriptor constantType = (ConstantDescriptor) type;
return ReadConstantNodeGen.create(constantType.getValue(), constantType);
} else if (isLocal) {
if (isReference) {
return ReadReferenceVariableNodeGen.create(variableSlot, type);
} else {
return ReadLocalVariableNodeGen.create(variableSlot, type);
}
} else {
return ReadGlobalVariableNodeGen.create(variableSlot, type);
}
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class NodeFactory method addProgramArgumentsAssignmentNodes.
private void addProgramArgumentsAssignmentNodes() {
int currentArgument = 0;
for (String argumentIdentifier : this.mainProgramArgumentsIdentifiers) {
FrameSlot argumentSlot = this.currentLexicalScope.getLocalSlot(argumentIdentifier);
TypeDescriptor typeDescriptor = this.currentLexicalScope.getIdentifierDescriptor(argumentIdentifier);
if (typeDescriptor != null) {
if (ProgramArgumentAssignmentNode.supportsType(typeDescriptor)) {
this.currentLexicalScope.addScopeInitializationNode(new ProgramArgumentAssignmentNode(argumentSlot, typeDescriptor, currentArgument++));
}
// TODO: else -> show warning
}
}
}
use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor in project TrufflePascal by Aspect26.
the class BinaryExpressionNode method verifyBothCompatiblePointerTypes.
protected boolean verifyBothCompatiblePointerTypes(TypeDescriptor leftType, TypeDescriptor rightType) {
if (!(leftType instanceof PointerDescriptor && rightType instanceof PointerDescriptor)) {
return false;
}
TypeDescriptor leftInnerType = ((PointerDescriptor) leftType).getInnerTypeDescriptor();
TypeDescriptor rightInnerType = ((PointerDescriptor) rightType).getInnerTypeDescriptor();
return (leftInnerType == null) || (rightInnerType == null) || (rightInnerType.equals(leftInnerType));
}
Aggregations