mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #78511 from venkatesh5789/null-value-optional-extraction
[Compile Time Constant Extraction] Extract Nil Values for Optionals
This commit is contained in:
@@ -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;
|
||||
@@ -715,6 +717,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user