brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · a371dc1 Raw
82 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9#ifndef LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H10#define LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H11 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 19using namespace clang;20 21namespace lldb_rpc_gen {22/// Emit the source code for server-side *.cpp files.23class RPCServerSourceEmitter : public FileEmitter {24public: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 method31  /// for lldb-rpc-server32  void EmitMethod(const Method &method);33 34private: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 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_gen80 81#endif // LLDB_RPC_GEN_RPCSERVERMETHODEMITTER_H82