aboutsummaryrefslogtreecommitdiff
path: root/lldb/tools/lldb-rpc-gen/server/RPCServerSourceEmitter.h
blob: a371dc100ff7a6a66ecb2621f9065591952ef161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//===-- RPCServerSourceEmitter.h ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
#ifndef LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H
#define LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H

#include "RPCCommon.h"

#include "clang/AST/AST.h"

#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"

using namespace clang;

namespace lldb_rpc_gen {
/// Emit the source code for server-side *.cpp files.
class RPCServerSourceEmitter : public FileEmitter {
public:
  RPCServerSourceEmitter(std::unique_ptr<llvm::ToolOutputFile> &&OutputFile)
      : FileEmitter(std::move(OutputFile)) {
    Begin();
  }

  /// Given a Method, emits a server-side implementation of the method
  /// for lldb-rpc-server
  void EmitMethod(const Method &method);

private:
  void EmitCommentHeader(const Method &method);

  void EmitFunctionHeader(const Method &method);

  void EmitFunctionBody(const Method &method);

  void EmitFunctionFooter();

  void EmitStorageForParameters(const Method &method);

  void EmitStorageForOneParameter(QualType ParamType,
                                  const std::string &ParamName,
                                  const PrintingPolicy &Policy,
                                  bool IsFollowedByLen);

  void EmitDecodeForParameters(const Method &method);

  void EmitDecodeForOneParameter(QualType ParamType,
                                 const std::string &ParamName,
                                 const PrintingPolicy &Policy);

  std::string CreateMethodCall(const Method &method);

  std::string CreateEncodeLine(const std::string &value,
                               bool IsEncodingSBClass);

  void EmitEncodesForMutableParameters(const std::vector<Param> &Params);

  void EmitMethodCallAndEncode(const Method &method);

  void EmitCallbackFunction(const Method &method);

  void Begin() {
    EmitLine("#include \"RPCUserServer.h\"");
    EmitLine("#include \"SBAPI.h\"");
    EmitLine("#include <lldb-rpc/common/RPCArgument.h>");
    EmitLine("#include <lldb-rpc/common/RPCCommon.h>");
    EmitLine("#include <lldb-rpc/common/RPCFunction.h>");
    EmitLine("#include <lldb/API/LLDB.h>");
    EmitLine("");
    EmitLine("using namespace rpc_common;");
    EmitLine("using namespace lldb;");
  }
};
} // namespace lldb_rpc_gen

#endif // LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H