3535#include < utility>
3636#include < variant>
3737#include < vector>
38+ #if __cplusplus >= 202002L
39+ #include < concepts>
40+ #endif
3841
3942namespace lldb_private ::transport {
4043
@@ -95,9 +98,7 @@ class MethodNotFound : public llvm::ErrorInfo<MethodNotFound> {
9598 std::string m_method;
9699};
97100
98- /*
99- FIXME: Once we upgrade to c++20, use this concept for JSONTransport.
100-
101+ #if __cplusplus >= 202002L
101102// / A ProtocolDescriptor details the types used in a JSONTransport for handling
102103// / transport communication.
103104template <typename T>
@@ -107,7 +108,7 @@ concept ProtocolDescriptor = requires {
107108 typename T::Resp;
108109 typename T::Evt;
109110};
110- */
111+ # endif
111112
112113// / A transport is responsible for maintaining the connection to a client
113114// / application, and reading/writing structured messages to it.
@@ -116,8 +117,12 @@ concept ProtocolDescriptor = requires {
116117// / - Messages will not be sent concurrently.
117118// / - Messages MAY be sent while Run() is reading, or its callback is active.
118119// /
119- // / FIXME: Once we upgrade to c++20, use `template <ProtocolDescriptor Proto>`
120- template <typename Proto> class JSONTransport {
120+ #if __cplusplus >= 202002L
121+ template <ProtocolDescriptor Proto>
122+ #else
123+ template <typename Proto>
124+ #endif
125+ class JSONTransport {
121126public:
122127 using Req = typename Proto::Req;
123128 using Resp = typename Proto::Resp;
@@ -179,9 +184,15 @@ template <typename Proto> class IOTransport : public JSONTransport<Proto> {
179184 IOTransport (lldb::IOObjectSP in, lldb::IOObjectSP out)
180185 : m_in(in), m_out(out) {}
181186
182- llvm::Error Send (const Proto::Evt &evt) override { return Write (evt); }
183- llvm::Error Send (const Proto::Req &req) override { return Write (req); }
184- llvm::Error Send (const Proto::Resp &resp) override { return Write (resp); }
187+ llvm::Error Send (const typename Proto::Evt &evt) override {
188+ return Write (evt);
189+ }
190+ llvm::Error Send (const typename Proto::Req &req) override {
191+ return Write (req);
192+ }
193+ llvm::Error Send (const typename Proto::Resp &resp) override {
194+ return Write (resp);
195+ }
185196
186197 llvm::Expected<MainLoop::ReadHandleUP>
187198 RegisterMessageHandler (MainLoop &loop, MessageHandler &handler) override {
@@ -261,7 +272,11 @@ template <typename Proto> class IOTransport : public JSONTransport<Proto> {
261272};
262273
263274// / A transport class for JSON with a HTTP header.
275+ #if __cplusplus >= 202002L
276+ template <ProtocolDescriptor Proto>
277+ #else
264278template <typename Proto>
279+ #endif
265280class HTTPDelimitedJSONTransport : public IOTransport <Proto> {
266281public:
267282 using IOTransport<Proto>::IOTransport;
@@ -328,7 +343,12 @@ class HTTPDelimitedJSONTransport : public IOTransport<Proto> {
328343};
329344
330345// / A transport class for JSON RPC.
331- template <typename Proto> class JSONRPCTransport : public IOTransport <Proto> {
346+ #if __cplusplus >= 202002L
347+ template <ProtocolDescriptor Proto>
348+ #else
349+ template <typename Proto>
350+ #endif
351+ class JSONRPCTransport : public IOTransport <Proto> {
332352public:
333353 using IOTransport<Proto>::IOTransport;
334354
@@ -384,9 +404,7 @@ using OutgoingRequest = typename detail::request_t<R, P>::type;
384404// / A function to send an outgoing event.
385405template <typename P> using OutgoingEvent = typename detail::event_t <P>::type;
386406
387- /*
388- FIXME: With c++20, we should use this concept:
389-
407+ #if __cplusplus >= 202002L
390408// / This represents a protocol description that includes additional helpers
391409// / for constructing requests, responses and events to work with `Binder`.
392410template <typename T>
@@ -417,23 +435,22 @@ concept BindingBuilder =
417435 // / Looking up in flight responses.
418436 { T::KeyFor (resp) } -> std::same_as<typename T::Id>;
419437 // / Extract method from request.
420- { T::KeyFor(req) } -> std::same_as<llvm::StringRef >;
438+ { T::KeyFor (req) } -> std::same_as<std::string >;
421439 // / Extract method from event.
422- { T::KeyFor(evt) } -> std::same_as<llvm::StringRef >;
440+ { T::KeyFor (evt) } -> std::same_as<std::string >;
423441 // / @}
424442
425443 // / Extracting information from associated types.
426444 // / @{
427445 // / Extract parameters from a request.
428446 { T::Extract (req) } -> std::same_as<std::optional<llvm::json::Value>>;
429447 // / Extract result from a response.
430- { T::Extract(resp) } ->
431- std::same_as<llvm::Expected<llvm::json::Value>>;
448+ { T::Extract (resp) } -> std::same_as<llvm::Expected<llvm::json::Value>>;
432449 // / Extract parameters from an event.
433450 { T::Extract (evt) } -> std::same_as<std::optional<llvm::json::Value>>;
434451 // / @}
435452 };
436- */
453+ # endif
437454
438455// / Binder collects a table of functions that handle calls.
439456// /
@@ -461,13 +478,16 @@ concept BindingBuilder =
461478// / cout << *result << "\n";
462479// / });
463480// / \endcode
464- // / FIXME: In c++20 use `template <BindingBuilder Proto>`.
481+ #if __cplusplus >= 202002L
482+ template <BindingBuilder Proto>
483+ #else
465484template <typename Proto>
485+ #endif
466486class Binder : public JSONTransport <Proto>::MessageHandler {
467- using Req = Proto::Req;
468- using Resp = Proto::Resp;
469- using Evt = Proto::Evt;
470- using Id = Proto::Id;
487+ using Req = typename Proto::Req;
488+ using Resp = typename Proto::Resp;
489+ using Evt = typename Proto::Evt;
490+ using Id = typename Proto::Id;
471491 using Transport = JSONTransport<Proto>;
472492 using MessageHandler = typename Transport::MessageHandler;
473493
@@ -625,15 +645,23 @@ class Binder : public JSONTransport<Proto>::MessageHandler {
625645 };
626646};
627647
648+ #if __cplusplus >= 202002L
649+ template <BindingBuilder Proto>
650+ #else
628651template <typename Proto>
652+ #endif
629653template <typename Fn, typename ... Args>
630654void Binder<Proto>::OnDisconnect(Fn &&fn, Args &&...args) {
631655 m_disconnect_handler = [fn, args...]() mutable {
632656 std::invoke (std::forward<Fn>(fn), std::forward<Args>(args)...);
633657 };
634658}
635659
660+ #if __cplusplus >= 202002L
661+ template <BindingBuilder Proto>
662+ #else
636663template <typename Proto>
664+ #endif
637665template <typename Fn, typename ... Args>
638666void Binder<Proto>::OnError(Fn &&fn, Args &&...args) {
639667 m_error_handler = [fn, args...](llvm::Error error) mutable {
@@ -642,7 +670,11 @@ void Binder<Proto>::OnError(Fn &&fn, Args &&...args) {
642670 };
643671}
644672
673+ #if __cplusplus >= 202002L
674+ template <BindingBuilder Proto>
675+ #else
645676template <typename Proto>
677+ #endif
646678template <typename Result, typename Params, typename Fn, typename ... Args>
647679void Binder<Proto>::Bind(llvm::StringLiteral method, Fn &&fn, Args &&...args) {
648680 assert (m_request_handlers.find (method) == m_request_handlers.end () &&
@@ -699,7 +731,11 @@ void Binder<Proto>::Bind(llvm::StringLiteral method, Fn &&fn, Args &&...args) {
699731 }
700732}
701733
734+ #if __cplusplus >= 202002L
735+ template <BindingBuilder Proto>
736+ #else
702737template <typename Proto>
738+ #endif
703739template <typename Params, typename Fn, typename ... Args>
704740void Binder<Proto>::Bind(llvm::StringLiteral method, Fn &&fn, Args &&...args) {
705741 assert (m_event_handlers.find (method) == m_event_handlers.end () &&
@@ -720,7 +756,11 @@ void Binder<Proto>::Bind(llvm::StringLiteral method, Fn &&fn, Args &&...args) {
720756 }
721757}
722758
759+ #if __cplusplus >= 202002L
760+ template <BindingBuilder Proto>
761+ #else
723762template <typename Proto>
763+ #endif
724764template <typename Result, typename Params>
725765OutgoingRequest<Result, Params>
726766Binder<Proto>::Bind(llvm::StringLiteral method) {
@@ -785,7 +825,11 @@ Binder<Proto>::Bind(llvm::StringLiteral method) {
785825 }
786826}
787827
828+ #if __cplusplus >= 202002L
829+ template <BindingBuilder Proto>
830+ #else
788831template <typename Proto>
832+ #endif
789833template <typename Params>
790834OutgoingEvent<Params> Binder<Proto>::Bind(llvm::StringLiteral method) {
791835 if constexpr (std::is_void_v<Params>) {
@@ -803,7 +847,11 @@ OutgoingEvent<Params> Binder<Proto>::Bind(llvm::StringLiteral method) {
803847 }
804848}
805849
850+ #if __cplusplus >= 202002L
851+ template <BindingBuilder Proto>
852+ #else
806853template <typename Proto>
854+ #endif
807855template <typename T>
808856llvm::Expected<T> Binder<Proto>::Parse(const llvm::json::Value &raw,
809857 llvm::StringRef method) {
0 commit comments