@@ -381,6 +381,31 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
381
381
return extractCompileTimeValue (injectIntoOptionalExpr->getSubExpr ());
382
382
}
383
383
384
+ case ExprKind::MemberRef: {
385
+ auto memberRefExpr = cast<MemberRefExpr>(expr);
386
+ // somehow check raw representable
387
+ auto base = memberRefExpr->getBase ();
388
+ if (base->getKind () == ExprKind::Type) {
389
+ auto type = cast<TypeExpr>(base)->getInstanceType ();
390
+ // FIXME: ApolloZhu check type == expr->getType()
391
+ // FIXME: ApolloZhu need a better way of getDecl for all types
392
+ auto typeDecl = type->getAs <NominalType>()->getDecl ();
393
+ for (auto &protocol : typeDecl->getAllProtocols ()) {
394
+ if (protocol->getKnownProtocolKind () &&
395
+ *protocol->getKnownProtocolKind () ==
396
+ KnownProtocolKind::RawRepresentable) {
397
+ auto decl = memberRefExpr->getMember ().getDecl ();
398
+ // FIXME: ApolloZhu check it's actually VarDecl
399
+ auto caseName = decl->getName ().getBaseIdentifier ().str ().str ();
400
+ auto init = cast<VarDecl>(decl)->getParentInitializer ();
401
+ return std::make_shared<RawRepresentableValue>(
402
+ caseName, extractCompileTimeValue (init));
403
+ }
404
+ }
405
+ }
406
+ break ;
407
+ }
408
+
384
409
default : {
385
410
break ;
386
411
}
@@ -587,6 +612,16 @@ void writeValue(llvm::json::OStream &JSON,
587
612
break ;
588
613
}
589
614
615
+ case CompileTimeValue::ValueKind::RawRepresentable: {
616
+ auto rawRepresentable = cast<RawRepresentableValue>(value);
617
+ JSON.attribute (" valueKind" , " RawRepresentable" );
618
+ JSON.attributeObject (" value" , [&]() {
619
+ JSON.attribute (" name" , rawRepresentable->getName ());
620
+ writeValue (JSON, rawRepresentable->getValue ());
621
+ });
622
+ break ;
623
+ }
624
+
590
625
case CompileTimeValue::ValueKind::InitCall: {
591
626
auto initCallValue = cast<InitCallValue>(value);
592
627
0 commit comments