@@ -287,13 +287,25 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
287
287
288
288
case ExprKind::Call: {
289
289
auto callExpr = cast<CallExpr>(expr);
290
- if (callExpr->getFn ()->getKind () == ExprKind::ConstructorRefCall) {
290
+ auto functionKind = callExpr->getFn ()->getKind ();
291
+
292
+ if (functionKind == ExprKind::DeclRef) {
293
+ auto declRefExpr = cast<DeclRefExpr>(callExpr->getFn ());
294
+ auto caseName =
295
+ declRefExpr->getDecl ()->getName ().getBaseIdentifier ().str ().str ();
296
+
297
+ std::vector<FunctionParameter> parameters =
298
+ extractFunctionArguments (callExpr->getArgs ());
299
+ return std::make_shared<FunctionCallValue>(caseName, parameters);
300
+ }
301
+
302
+ if (functionKind == ExprKind::ConstructorRefCall) {
291
303
std::vector<FunctionParameter> parameters =
292
304
extractFunctionArguments (callExpr->getArgs ());
293
305
return std::make_shared<InitCallValue>(callExpr->getType (), parameters);
294
306
}
295
307
296
- if (callExpr-> getFn ()-> getKind () == ExprKind::DotSyntaxCall) {
308
+ if (functionKind == ExprKind::DotSyntaxCall) {
297
309
auto dotSyntaxCallExpr = cast<DotSyntaxCallExpr>(callExpr->getFn ());
298
310
auto fn = dotSyntaxCallExpr->getFn ();
299
311
if (fn->getKind () == ExprKind::DeclRef) {
@@ -409,6 +421,38 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
409
421
return extractCompileTimeValue (injectIntoOptionalExpr->getSubExpr ());
410
422
}
411
423
424
+ case ExprKind::Load: {
425
+ auto loadExpr = cast<LoadExpr>(expr);
426
+ return extractCompileTimeValue (loadExpr->getSubExpr ());
427
+ }
428
+
429
+ case ExprKind::MemberRef: {
430
+ auto memberExpr = cast<MemberRefExpr>(expr);
431
+ if (isa<TypeExpr>(memberExpr->getBase ())) {
432
+ auto baseTypeExpr = cast<TypeExpr>(memberExpr->getBase ());
433
+ auto label = memberExpr->getDecl ().getDecl ()->getBaseIdentifier ().str ();
434
+ return std::make_shared<MemberReferenceValue>(
435
+ baseTypeExpr->getInstanceType (), label.str ());
436
+ }
437
+ break ;
438
+ }
439
+
440
+ case ExprKind::InterpolatedStringLiteral: {
441
+ auto interpolatedStringExpr = cast<InterpolatedStringLiteralExpr>(expr);
442
+ auto tapExpr = interpolatedStringExpr->getAppendingExpr ();
443
+ auto &Ctx = tapExpr->getVar ()->getASTContext ();
444
+
445
+ std::vector<std::shared_ptr<CompileTimeValue>> segments;
446
+ interpolatedStringExpr->forEachSegment (
447
+ Ctx, [&](bool isInterpolation, CallExpr *segment) -> void {
448
+ auto arg = segment->getArgs ()->get (0 );
449
+ auto expr = arg.getExpr ();
450
+ segments.push_back (extractCompileTimeValue (expr));
451
+ });
452
+
453
+ return std::make_shared<InterpolatedStringLiteralValue>(segments);
454
+ }
455
+
412
456
default : {
413
457
break ;
414
458
}
@@ -733,23 +777,69 @@ void writeValue(llvm::json::OStream &JSON,
733
777
break ;
734
778
}
735
779
736
- case CompileTimeValue::KeyPath: {
737
- auto keyPathValue = cast<KeyPathValue>(value);
738
- JSON.attribute (" valueKind" , " KeyPath" );
739
- JSON.attributeObject (" value" , [&]() {
740
- JSON.attribute (" path" , keyPathValue->getPath ());
741
- JSON.attribute (" rootType" , toFullyQualifiedTypeNameString (keyPathValue->getRootType ()));
742
- JSON.attributeArray (" components" , [&] {
743
- auto components = keyPathValue->getComponents ();
744
- for (auto c : components) {
780
+ case CompileTimeValue::ValueKind::KeyPath: {
781
+ auto keyPathValue = cast<KeyPathValue>(value);
782
+ JSON.attribute (" valueKind" , " KeyPath" );
783
+ JSON.attributeObject (" value" , [&]() {
784
+ JSON.attribute (" path" , keyPathValue->getPath ());
785
+ JSON.attribute (" rootType" , toFullyQualifiedTypeNameString (
786
+ keyPathValue->getRootType ()));
787
+ JSON.attributeArray (" components" , [&] {
788
+ auto components = keyPathValue->getComponents ();
789
+ for (auto c : components) {
790
+ JSON.object ([&] {
791
+ JSON.attribute (" label" , c.Label );
792
+ JSON.attribute (" type" , toFullyQualifiedTypeNameString (c.Type ));
793
+ });
794
+ }
795
+ });
796
+ });
797
+ break ;
798
+ }
799
+
800
+ case CompileTimeValue::ValueKind::FunctionCall: {
801
+ auto functionCallValue = cast<FunctionCallValue>(value);
802
+ JSON.attribute (" valueKind" , " FunctionCall" );
803
+ JSON.attributeObject (" value" , [&]() {
804
+ JSON.attribute (" name" , functionCallValue->getIdentifier ());
805
+ if (functionCallValue->getParameters ().has_value ()) {
806
+ auto params = functionCallValue->getParameters ().value ();
807
+ JSON.attributeArray (" arguments" , [&] {
808
+ for (auto FP : params) {
745
809
JSON.object ([&] {
746
- JSON.attribute (" label" , c.Label );
747
- JSON.attribute (" type" , toFullyQualifiedTypeNameString (c.Type ));
810
+ JSON.attribute (" label" , FP.Label );
811
+ JSON.attribute (" type" , toFullyQualifiedTypeNameString (FP.Type ));
812
+ writeValue (JSON, FP.Value );
748
813
});
749
814
}
750
815
});
816
+ }
817
+ });
818
+ break ;
819
+ }
820
+
821
+ case CompileTimeValue::ValueKind::MemberReference: {
822
+ auto memberReferenceValue = cast<MemberReferenceValue>(value);
823
+ JSON.attribute (" valueKind" , " MemberReference" );
824
+ JSON.attributeObject (" value" , [&]() {
825
+ JSON.attribute (" baseType" , toFullyQualifiedTypeNameString (
826
+ memberReferenceValue->getBaseType ()));
827
+ JSON.attribute (" memberLabel" , memberReferenceValue->getMemberLabel ());
828
+ });
829
+ break ;
830
+ }
831
+ case CompileTimeValue::ValueKind::InterpolatedString: {
832
+ auto interpolatedStringValue = cast<InterpolatedStringLiteralValue>(value);
833
+ JSON.attribute (" valueKind" , " InterpolatedStringLiteral" );
834
+ JSON.attributeObject (" value" , [&]() {
835
+ JSON.attributeArray (" segments" , [&] {
836
+ auto segments = interpolatedStringValue->getSegments ();
837
+ for (auto s : segments) {
838
+ JSON.object ([&] { writeValue (JSON, s); });
839
+ }
751
840
});
752
- break ;
841
+ });
842
+ break ;
753
843
}
754
844
755
845
case CompileTimeValue::ValueKind::Runtime: {
0 commit comments