xref: /freebsd/contrib/llvm-project/lldb/tools/lldb-rpc/lldb-rpc-gen/server/RPCServerSourceEmitter.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- RPCServerSourceEmitter.h ------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 #ifndef LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H
10 #define LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H
11 
12 #include "RPCCommon.h"
13 
14 #include "clang/AST/AST.h"
15 
16 #include "llvm/Support/ToolOutputFile.h"
17 #include "llvm/Support/raw_ostream.h"
18 
19 using namespace clang;
20 
21 namespace lldb_rpc_gen {
22 /// Emit the source code for server-side *.cpp files.
23 class RPCServerSourceEmitter : public FileEmitter {
24 public:
RPCServerSourceEmitter(std::unique_ptr<llvm::ToolOutputFile> && OutputFile)25   RPCServerSourceEmitter(std::unique_ptr<llvm::ToolOutputFile> &&OutputFile)
26       : FileEmitter(std::move(OutputFile)) {
27     Begin();
28   }
29 
30   /// Given a Method, emits a server-side implementation of the method
31   /// for lldb-rpc-server
32   void EmitMethod(const Method &method);
33 
34 private:
35   void EmitCommentHeader(const Method &method);
36 
37   void EmitFunctionHeader(const Method &method);
38 
39   void EmitFunctionBody(const Method &method);
40 
41   void EmitFunctionFooter();
42 
43   void EmitStorageForParameters(const Method &method);
44 
45   void EmitStorageForOneParameter(QualType ParamType,
46                                   const std::string &ParamName,
47                                   const PrintingPolicy &Policy,
48                                   bool IsFollowedByLen);
49 
50   void EmitDecodeForParameters(const Method &method);
51 
52   void EmitDecodeForOneParameter(QualType ParamType,
53                                  const std::string &ParamName,
54                                  const PrintingPolicy &Policy);
55 
56   std::string CreateMethodCall(const Method &method);
57 
58   std::string CreateEncodeLine(const std::string &value,
59                                bool IsEncodingSBClass);
60 
61   void EmitEncodesForMutableParameters(const std::vector<Param> &Params);
62 
63   void EmitMethodCallAndEncode(const Method &method);
64 
65   void EmitCallbackFunction(const Method &method);
66 
Begin()67   void Begin() {
68     EmitLine("#include \"RPCUserServer.h\"");
69     EmitLine("#include \"SBAPI.h\"");
70     EmitLine("#include <lldb-rpc/common/RPCArgument.h>");
71     EmitLine("#include <lldb-rpc/common/RPCCommon.h>");
72     EmitLine("#include <lldb-rpc/common/RPCFunction.h>");
73     EmitLine("#include <lldb/API/LLDB.h>");
74     EmitLine("");
75     EmitLine("using namespace rpc_common;");
76     EmitLine("using namespace lldb;");
77   }
78 };
79 } // namespace lldb_rpc_gen
80 
81 #endif // LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H
82