[Compile Time Constant Extraction] Add extraction of arrays (#62491)

This commit is contained in:
James Paolantonio
2022-12-14 17:46:09 -05:00
committed by GitHub
parent a2879246ad
commit 5ec4143f4a
3 changed files with 113 additions and 5 deletions

View File

@@ -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;