|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See https://swift.org/LICENSE.txt for license information
|
@@ -41,13 +41,18 @@ class Instrumenter : InstrumenterBase {
|
41 | 41 | std::mt19937_64 &RNG;
|
42 | 42 | unsigned &TmpNameIndex;
|
43 | 43 | bool HighPerformance;
|
| 44 | + bool ExtendedCallbacks; |
44 | 45 |
|
45 | 46 | DeclNameRef DebugPrintName;
|
46 | 47 | DeclNameRef PrintName;
|
47 | 48 | DeclNameRef PostPrintName;
|
| 49 | + DeclNameRef PostPrintExtendedName; |
48 | 50 | DeclNameRef LogWithIDName;
|
| 51 | + DeclNameRef LogWithIDExtendedName; |
49 | 52 | DeclNameRef LogScopeExitName;
|
| 53 | + DeclNameRef LogScopeExitExtendedName; |
50 | 54 | DeclNameRef LogScopeEntryName;
|
| 55 | + DeclNameRef LogScopeEntryExtendedName; |
51 | 56 | DeclNameRef SendDataName;
|
52 | 57 |
|
53 | 58 | struct BracePair {
|
@@ -126,12 +131,17 @@ class Instrumenter : InstrumenterBase {
|
126 | 131 | unsigned &TmpNameIndex)
|
127 | 132 | : InstrumenterBase(C, DC), RNG(RNG), TmpNameIndex(TmpNameIndex),
|
128 | 133 | HighPerformance(HP),
|
| 134 | + ExtendedCallbacks(C.LangOpts.hasFeature(Feature::PlaygroundExtendedCallbacks)), |
129 | 135 | DebugPrintName(C.getIdentifier("__builtin_debugPrint")),
|
130 | 136 | PrintName(C.getIdentifier("__builtin_print")),
|
131 | 137 | PostPrintName(C.getIdentifier("__builtin_postPrint")),
|
| 138 | + PostPrintExtendedName(C.getIdentifier("__builtin_postPrint_extended")), |
132 | 139 | LogWithIDName(C.getIdentifier("__builtin_log_with_id")),
|
| 140 | + LogWithIDExtendedName(C.getIdentifier("__builtin_log_with_id_extended")), |
133 | 141 | LogScopeExitName(C.getIdentifier("__builtin_log_scope_exit")),
|
| 142 | + LogScopeExitExtendedName(C.getIdentifier("__builtin_log_scope_exit_extended")), |
134 | 143 | LogScopeEntryName(C.getIdentifier("__builtin_log_scope_entry")),
|
| 144 | + LogScopeEntryExtendedName(C.getIdentifier("__builtin_log_scope_entry_extended")), |
135 | 145 | SendDataName(C.getIdentifier("__builtin_send_data")) { }
|
136 | 146 |
|
137 | 147 | Stmt *transformStmt(Stmt *S) {
|
@@ -736,7 +746,7 @@ class Instrumenter : InstrumenterBase {
|
736 | 746 | }
|
737 | 747 |
|
738 | 748 | Added<Stmt *> logPostPrint(SourceRange SR) {
|
739 |
| - return buildLoggerCallWithArgs(PostPrintName, {}, SR); |
| 749 | + return buildLoggerCallWithArgs(ExtendedCallbacks ? PostPrintExtendedName : PostPrintName, {}, SR); |
740 | 750 | }
|
741 | 751 |
|
742 | 752 | std::pair<PatternBindingDecl *, VarDecl *>
|
@@ -776,15 +786,15 @@ class Instrumenter : InstrumenterBase {
|
776 | 786 | const unsigned id_num = Distribution(RNG);
|
777 | 787 | Expr *IDExpr = IntegerLiteralExpr::createFromUnsigned(Context, id_num, SourceLoc());
|
778 | 788 |
|
779 |
| - return buildLoggerCallWithArgs(LogWithIDName, { *E, NameExpr, IDExpr }, SR); |
| 789 | + return buildLoggerCallWithArgs(ExtendedCallbacks ? LogWithIDExtendedName : LogWithIDName, { *E, NameExpr, IDExpr }, SR); |
780 | 790 | }
|
781 | 791 |
|
782 | 792 | Added<Stmt *> buildScopeEntry(SourceRange SR) {
|
783 |
| - return buildLoggerCallWithArgs(LogScopeEntryName, {}, SR); |
| 793 | + return buildLoggerCallWithArgs(ExtendedCallbacks ? LogScopeEntryExtendedName : LogScopeEntryName, {}, SR); |
784 | 794 | }
|
785 | 795 |
|
786 | 796 | Added<Stmt *> buildScopeExit(SourceRange SR) {
|
787 |
| - return buildLoggerCallWithArgs(LogScopeExitName, {}, SR); |
| 797 | + return buildLoggerCallWithArgs(ExtendedCallbacks ? LogScopeExitExtendedName : LogScopeExitName, {}, SR); |
788 | 798 | }
|
789 | 799 |
|
790 | 800 | Added<Stmt *> buildLoggerCallWithArgs(DeclNameRef LoggerName,
|
@@ -813,14 +823,28 @@ class Instrumenter : InstrumenterBase {
|
813 | 823 |
|
814 | 824 | llvm::SmallVector<Expr *, 6> ArgsWithSourceRange(Args.begin(), Args.end());
|
815 | 825 |
|
816 |
| - ArgsWithSourceRange.append( |
817 |
| - {StartLine, EndLine, StartColumn, EndColumn, ModuleExpr, FileExpr}); |
818 |
| - |
819 | 826 | UnresolvedDeclRefExpr *LoggerRef = new (Context)
|
820 | 827 | UnresolvedDeclRefExpr(LoggerName, DeclRefKind::Ordinary,
|
821 | 828 | DeclNameLoc(SR.End));
|
822 | 829 | LoggerRef->setImplicit(true);
|
823 | 830 |
|
| 831 | + if (ExtendedCallbacks) { |
| 832 | + StringRef filePath = Context.SourceMgr.getDisplayNameForLoc(SR.Start); |
| 833 | + |
| 834 | + Expr *FilePathExpr = new (Context) StringLiteralExpr( |
| 835 | + Context.AllocateCopy(filePath), SourceRange(), /*implicit=*/true); |
| 836 | + |
| 837 | + std::string moduleName = std::string(TypeCheckDC->getParentModule()->getName()); |
| 838 | + Expr *ModuleNameExpr = new (Context) StringLiteralExpr( |
| 839 | + Context.AllocateCopy(moduleName), SourceRange(), /*implicit=*/true); |
| 840 | + |
| 841 | + ArgsWithSourceRange.append( |
| 842 | + {StartLine, EndLine, StartColumn, EndColumn, ModuleNameExpr, FilePathExpr}); |
| 843 | + } else { |
| 844 | + ArgsWithSourceRange.append( |
| 845 | + {StartLine, EndLine, StartColumn, EndColumn, ModuleExpr, FileExpr}); |
| 846 | + } |
| 847 | + |
824 | 848 | auto *ArgList =
|
825 | 849 | ArgumentList::forImplicitUnlabeled(Context, ArgsWithSourceRange);
|
826 | 850 | ApplyExpr *LoggerCall =
|
|
0 commit comments