[Compile Time Constant Extraction] Extract Nil Values for Optionals

This commit is contained in:
Venkatesh Sriram
2025-01-09 12:43:43 +05:30
parent f1f10517d5
commit c6c8526b87
4 changed files with 84 additions and 6 deletions

View File

@@ -198,8 +198,7 @@ static std::optional<std::string> extractRawLiteral(Expr *expr) {
switch (expr->getKind()) {
case ExprKind::BooleanLiteral:
case ExprKind::FloatLiteral:
case ExprKind::IntegerLiteral:
case ExprKind::NilLiteral: {
case ExprKind::IntegerLiteral: {
std::string literalOutput;
llvm::raw_string_ostream OutputStream(literalOutput);
expr->printConstExprValue(&OutputStream, nullptr);
@@ -230,7 +229,6 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
case ExprKind::BooleanLiteral:
case ExprKind::FloatLiteral:
case ExprKind::IntegerLiteral:
case ExprKind::NilLiteral:
case ExprKind::StringLiteral: {
auto rawLiteral = extractRawLiteral(expr);
if (rawLiteral.has_value()) {
@@ -240,6 +238,10 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
break;
}
case ExprKind::NilLiteral: {
return std::make_shared<NilLiteralValue>();
}
case ExprKind::Array: {
auto arrayExpr = cast<ArrayExpr>(expr);
std::vector<std::shared_ptr<CompileTimeValue>> elementValues;
@@ -710,6 +712,11 @@ void writeValue(llvm::json::OStream &JSON,
break;
}
case CompileTimeValue::ValueKind::NilLiteral: {
JSON.attribute("valueKind", "NilLiteral");
break;
}
case CompileTimeValue::ValueKind::InitCall: {
auto initCallValue = cast<InitCallValue>(value);