Skip to content

Commit 1042955

Browse files
committed
[NFC] Add an operation to change the current options on NFC
1 parent 4edfd79 commit 1042955

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

include/swift/AST/InFlightSubstitution.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ class InFlightSubstitution {
5555
conformedProtocol);
5656
}
5757

58+
class OptionsAdjustmentScope {
59+
InFlightSubstitution &IFS;
60+
SubstOptions SavedOptions;
61+
62+
public:
63+
OptionsAdjustmentScope(InFlightSubstitution &IFS, SubstOptions newOptions)
64+
: IFS(IFS), SavedOptions(IFS.Options) {
65+
IFS.Options = newOptions;
66+
}
67+
68+
OptionsAdjustmentScope(const OptionsAdjustmentScope &) = delete;
69+
OptionsAdjustmentScope &operator=(const OptionsAdjustmentScope &) = delete;
70+
71+
~OptionsAdjustmentScope() {
72+
IFS.Options = SavedOptions;
73+
}
74+
};
75+
76+
template <class Fn>
77+
auto withNewOptions(SubstOptions options, Fn &&fn)
78+
-> decltype(std::forward<Fn>(fn)()) {
79+
OptionsAdjustmentScope scope(*this, options);
80+
return std::forward<Fn>(fn)();
81+
}
82+
5883
SubstOptions getOptions() const {
5984
return Options;
6085
}

0 commit comments

Comments
 (0)