@@ -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,38 @@ 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
+ if (isa<TypeExpr>(memberExpr->getBase ())) {
431
+ auto baseTypeExpr = cast<TypeExpr>(memberExpr->getBase ());
432
+ auto label = memberExpr->getDecl ().getDecl ()->getBaseIdentifier ().str ();
433
+ return std::make_shared<MemberReferenceValue>(
434
+ baseTypeExpr->getInstanceType (), label.str ());
435
+ }
436
+ break ;
437
+ }
438
+
439
+ case ExprKind::InterpolatedStringLiteral: {
440
+ auto interpolatedStringExpr = cast<InterpolatedStringLiteralExpr>(expr);
441
+ auto tapExpr = interpolatedStringExpr->getAppendingExpr ();
442
+ auto &Ctx = tapExpr->getVar ()->getASTContext ();
443
+
444
+ std::vector<std::shared_ptr<CompileTimeValue>> segments;
445
+ interpolatedStringExpr->forEachSegment (
446
+ Ctx, [&](bool isInterpolation, CallExpr *segment) -> void {
447
+ auto arg = segment->getArgs ()->get (0 );
448
+ auto expr = arg.getExpr ();
449
+ segments.push_back (extractCompileTimeValue (expr));
450
+ });
451
+
452
+ return std::make_shared<InterpolatedStringLiteralValue>(segments);
453
+ }
454
+
411
455
default : {
412
456
break ;
413
457
}
@@ -725,23 +769,69 @@ void writeValue(llvm::json::OStream &JSON,
725
769
break ;
726
770
}
727
771
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) {
772
+ case CompileTimeValue::ValueKind::KeyPath: {
773
+ auto keyPathValue = cast<KeyPathValue>(value);
774
+ JSON.attribute (" valueKind" , " KeyPath" );
775
+ JSON.attributeObject (" value" , [&]() {
776
+ JSON.attribute (" path" , keyPathValue->getPath ());
777
+ JSON.attribute (" rootType" , toFullyQualifiedTypeNameString (
778
+ keyPathValue->getRootType ()));
779
+ JSON.attributeArray (" components" , [&] {
780
+ auto components = keyPathValue->getComponents ();
781
+ for (auto c : components) {
782
+ JSON.object ([&] {
783
+ JSON.attribute (" label" , c.Label );
784
+ JSON.attribute (" type" , toFullyQualifiedTypeNameString (c.Type ));
785
+ });
786
+ }
787
+ });
788
+ });
789
+ break ;
790
+ }
791
+
792
+ case CompileTimeValue::ValueKind::FunctionCall: {
793
+ auto functionCallValue = cast<FunctionCallValue>(value);
794
+ JSON.attribute (" valueKind" , " FunctionCall" );
795
+ JSON.attributeObject (" value" , [&]() {
796
+ JSON.attribute (" name" , functionCallValue->getIdentifier ());
797
+ if (functionCallValue->getParameters ().has_value ()) {
798
+ auto params = functionCallValue->getParameters ().value ();
799
+ JSON.attributeArray (" arguments" , [&] {
800
+ for (auto FP : params) {
737
801
JSON.object ([&] {
738
- JSON.attribute (" label" , c.Label );
739
- JSON.attribute (" type" , toFullyQualifiedTypeNameString (c.Type ));
802
+ JSON.attribute (" label" , FP.Label );
803
+ JSON.attribute (" type" , toFullyQualifiedTypeNameString (FP.Type ));
804
+ writeValue (JSON, FP.Value );
740
805
});
741
806
}
742
807
});
808
+ }
809
+ });
810
+ break ;
811
+ }
812
+
813
+ case CompileTimeValue::ValueKind::MemberReference: {
814
+ auto memberReferenceValue = cast<MemberReferenceValue>(value);
815
+ JSON.attribute (" valueKind" , " MemberReference" );
816
+ JSON.attributeObject (" value" , [&]() {
817
+ JSON.attribute (" baseType" , toFullyQualifiedTypeNameString (
818
+ memberReferenceValue->getBaseType ()));
819
+ JSON.attribute (" memberLabel" , memberReferenceValue->getMemberLabel ());
820
+ });
821
+ break ;
822
+ }
823
+ case CompileTimeValue::ValueKind::InterpolatedString: {
824
+ auto interpolatedStringValue = cast<InterpolatedStringLiteralValue>(value);
825
+ JSON.attribute (" valueKind" , " InterpolatedStringLiteral" );
826
+ JSON.attributeObject (" value" , [&]() {
827
+ JSON.attributeArray (" segments" , [&] {
828
+ auto segments = interpolatedStringValue->getSegments ();
829
+ for (auto s : segments) {
830
+ JSON.object ([&] { writeValue (JSON, s); });
831
+ }
743
832
});
744
- break ;
833
+ });
834
+ break ;
745
835
}
746
836
747
837
case CompileTimeValue::ValueKind::Runtime: {
0 commit comments