mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Compile Time Constant Extraction] Add extraction of arrays (#62491)
This commit is contained in:
committed by
GitHub
parent
a2879246ad
commit
5ec4143f4a
@@ -123,7 +123,6 @@ parseProtocolListFromFile(StringRef protocolListFilePath,
|
||||
static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
|
||||
if (expr) {
|
||||
switch (expr->getKind()) {
|
||||
case ExprKind::Array:
|
||||
case ExprKind::Dictionary:
|
||||
|
||||
case ExprKind::BooleanLiteral:
|
||||
@@ -140,6 +139,15 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ExprKind::Array: {
|
||||
auto arrayExpr = cast<ArrayExpr>(expr);
|
||||
std::vector<std::shared_ptr<CompileTimeValue>> elementValues;
|
||||
for (const auto elementExpr : arrayExpr->getElements()) {
|
||||
elementValues.push_back(extractCompileTimeValue(elementExpr));
|
||||
}
|
||||
return std::make_shared<ArrayValue>(elementValues);
|
||||
}
|
||||
|
||||
case ExprKind::Tuple: {
|
||||
auto tupleExpr = cast<TupleExpr>(expr);
|
||||
|
||||
@@ -190,6 +198,11 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ExprKind::Erasure: {
|
||||
auto erasureExpr = cast<ErasureExpr>(expr);
|
||||
return extractCompileTimeValue(erasureExpr->getSubExpr());
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
@@ -373,6 +386,18 @@ void writeValue(llvm::json::OStream &JSON,
|
||||
break;
|
||||
}
|
||||
|
||||
case CompileTimeValue::ValueKind::Array: {
|
||||
auto arrayValue = cast<ArrayValue>(value);
|
||||
|
||||
JSON.attribute("valueKind", "Array");
|
||||
JSON.attributeArray("value", [&] {
|
||||
for (auto CTP : arrayValue->getElements()) {
|
||||
JSON.object([&] { writeValue(JSON, CTP); });
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case CompileTimeValue::ValueKind::Runtime: {
|
||||
JSON.attribute("valueKind", "Runtime");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user