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