brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 2a309d0 Raw
108 lines · c
1//===-- RPCCommon.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_RPCCOMMON_H10#define LLDB_RPC_GEN_RPCCOMMON_H11 12#include "clang/AST/AST.h"13#include "clang/AST/ASTContext.h"14#include "clang/AST/DeclCXX.h"15#include "llvm/Support/ToolOutputFile.h"16#include "llvm/Support/raw_ostream.h"17 18#include <string>19 20using namespace clang;21 22namespace lldb_rpc_gen {23QualType GetUnderlyingType(QualType T);24QualType GetUnqualifiedUnderlyingType(QualType T);25std::string GetMangledName(ASTContext &Context, CXXMethodDecl *MDecl);26 27bool TypeIsFromLLDBPrivate(QualType T);28bool TypeIsSBClass(QualType T);29bool TypeIsConstCharPtr(QualType T);30bool TypeIsConstCharPtrPtr(QualType T);31bool TypeIsDisallowedClass(QualType T);32bool TypeIsCallbackFunctionPointer(QualType T);33 34bool MethodIsDisallowed(ASTContext &Context, CXXMethodDecl *MDecl);35 36std::string ReplaceLLDBNamespaceWithRPCNamespace(std::string Name);37std::string StripLLDBNamespace(std::string Name);38bool SBClassRequiresDefaultCtor(const std::string &ClassName);39bool SBClassRequiresCopyCtorAssign(const std::string &ClassName);40bool SBClassInheritsFromObjectRef(const std::string &ClassName);41std::string GetSBClassNameFromType(QualType T);42struct Param {43  std::string Name;44  QualType Type;45  std::string DefaultValueText;46  bool IsFollowedByLen;47};48 49enum GenerationKind : bool { eServer, eLibrary };50 51struct Method {52  enum Type { eOther, eConstructor, eDestructor };53 54  Method(CXXMethodDecl *MDecl, const PrintingPolicy &Policy,55         ASTContext &Context);56 57  // Adding a '<' allows us to use Methods in ordered containers.58  // The ordering is on memory addresses.59  bool operator<(const lldb_rpc_gen::Method &rhs) const;60  const PrintingPolicy &Policy;61  const ASTContext &Context;62  std::string QualifiedName;63  std::string BaseName;64  std::string MangledName;65  QualType ReturnType;66  QualType ThisType;67  std::vector<Param> Params;68  bool IsConst = false;69  bool IsInstance = false;70  bool IsCtor = false;71  bool IsCopyCtor = false;72  bool IsCopyAssign = false;73  bool IsMoveCtor = false;74  bool IsMoveAssign = false;75  bool IsDtor = false;76  bool IsConversionMethod = false;77  bool IsExplicitCtorOrConversionMethod = false;78  bool ContainsFunctionPointerParameter = false;79 80  std::string CreateParamListAsString(GenerationKind Generation,81                                      bool IncludeDefaultValue = false) const;82 83  bool RequiresConnectionParameter() const;84};85 86std::string87GetDefaultArgumentsForConstructor(std::string ClassName,88                                  const lldb_rpc_gen::Method &method);89 90class FileEmitter {91protected:92  FileEmitter(std::unique_ptr<llvm::ToolOutputFile> &&OutputFile)93      : OutputFile(std::move(OutputFile)), IndentLevel(0) {}94  void EmitLine(const std::string &line) {95    for (auto i = 0; i < IndentLevel; i++)96      OutputFile->os() << "  ";97 98    OutputFile->os() << line << "\n";99  }100 101  void EmitNewLine() { OutputFile->os() << "\n"; }102 103  std::unique_ptr<llvm::ToolOutputFile> OutputFile;104  uint8_t IndentLevel;105};106} // namespace lldb_rpc_gen107#endif // LLDB_RPC_GEN_RPCCOMMON_H108