Handle null types

This commit is contained in:
Rafał Grodziński
2025-07-05 09:36:12 +09:00
parent ae4afd309b
commit cd3fa8b6e4
3 changed files with 16 additions and 6 deletions

View File

@@ -228,6 +228,9 @@ llvm::Value *ModuleBuilder::valueForExpression(shared_ptr<Expression> expression
} }
llvm::Value *ModuleBuilder::valueForLiteral(shared_ptr<ExpressionLiteral> expression) { llvm::Value *ModuleBuilder::valueForLiteral(shared_ptr<ExpressionLiteral> expression) {
if (expression->getValueType() == nullptr)
return llvm::UndefValue::get(typeVoid);
switch (expression->getValueType()->getKind()) { switch (expression->getValueType()->getKind()) {
case ValueTypeKind::NONE: case ValueTypeKind::NONE:
return llvm::UndefValue::get(typeVoid); return llvm::UndefValue::get(typeVoid);

View File

@@ -367,6 +367,9 @@ string Logger::toString(shared_ptr<ExpressionGrouping> expression) {
} }
string Logger::toString(shared_ptr<ExpressionLiteral> expression) { string Logger::toString(shared_ptr<ExpressionLiteral> expression) {
if (expression->getValueType() == nullptr)
return "?";
switch (expression->getValueType()->getKind()) { switch (expression->getValueType()->getKind()) {
case ValueTypeKind::NONE: case ValueTypeKind::NONE:
return "NONE"; return "NONE";
@@ -392,6 +395,8 @@ string Logger::toString(shared_ptr<ExpressionCall> expression) {
string Logger::toString(shared_ptr<ExpressionBlock> expression) { string Logger::toString(shared_ptr<ExpressionBlock> expression) {
string text; string text;
text += toString(expression->getStatementBlock()); text += toString(expression->getStatementBlock());
if (!text.empty())
text += '\n';
if (expression->getResultStatementExpression() != nullptr) if (expression->getResultStatementExpression() != nullptr)
text += toString(expression->getResultStatementExpression()); text += toString(expression->getResultStatementExpression());
return text; return text;

View File

@@ -54,6 +54,7 @@ Expression(ExpressionKind::BINARY, nullptr), operation(ExpressionBinaryOperation
break; break;
} }
if (left->getValueType() != nullptr && right->getValueType() != nullptr) {
// Types must match // Types must match
if (left->getValueType() != right->getValueType()) if (left->getValueType() != right->getValueType())
valueType = ValueType::NONE; valueType = ValueType::NONE;
@@ -61,6 +62,7 @@ Expression(ExpressionKind::BINARY, nullptr), operation(ExpressionBinaryOperation
// Booleans can only do = or != // Booleans can only do = or !=
if (valueType->getKind() == ValueTypeKind::BOOL && (token->getKind() != TokenKind::EQUAL || token->getKind() != TokenKind::NOT_EQUAL)) if (valueType->getKind() == ValueTypeKind::BOOL && (token->getKind() != TokenKind::EQUAL || token->getKind() != TokenKind::NOT_EQUAL))
valueType = ValueType::NONE; valueType = ValueType::NONE;
}
} }
ExpressionBinaryOperation ExpressionBinary::getOperation() { ExpressionBinaryOperation ExpressionBinary::getOperation() {