================ @@ -0,0 +1,124 @@ +#include "RPCLibraryHeaderEmitter.h" +#include "RPCCommon.h" + +#include "clang/AST/AST.h" +#include "clang/AST/Mangle.h" +#include "clang/Frontend/CompilerInstance.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; +using namespace lldb_rpc_gen; + +void RPCLibraryHeaderEmitter::StartClass(std::string ClassName) { + CurrentClass = std::move(ClassName); + std::string BaseClass = + lldb_rpc_gen::SBClassInheritsFromObjectRef(CurrentClass) + ? "ObjectRef" + : "LocalObjectRef"; + EmitLine("class " + CurrentClass + " : public rpc::" + BaseClass + " {"); + EmitLine("public:"); + IndentLevel++; + if (lldb_rpc_gen::SBClassRequiresDefaultCtor(CurrentClass)) + EmitLine(CurrentClass + "();"); + + // NOTE: There's currently only one RPC-specific extension that is actually + // used AFAICT. We can generalize this if we need more. + if (CurrentClass == "SBDebugger") + EmitLine("int SetIOFile(const char *path);"); +} + +void RPCLibraryHeaderEmitter::EndClass() { + if (lldb_rpc_gen::SBClassRequiresCopyCtorAssign(CurrentClass)) { + if (!CopyCtorEmitted) + EmitLine(CurrentClass + "(const lldb_rpc::" + CurrentClass + " &rhs);"); + if (!CopyAssignEmitted) + EmitLine(CurrentClass + " &operator=(const lldb_rpc::" + CurrentClass + + " &rhs);"); + } + if (!MoveCtorEmitted) + EmitLine(CurrentClass + "(lldb_rpc::" + CurrentClass + " &&rhs);"); + if (!MoveAssignEmitted) + EmitLine(CurrentClass + " &operator=(" + CurrentClass + " &&rhs);"); + + IndentLevel--; + EmitLine("}; // class " + CurrentClass); + CurrentClass.clear(); +} + +void RPCLibraryHeaderEmitter::EmitMethod(const Method &method) { + std::string DeclarationLine; + llvm::raw_string_ostream DeclarationLineStream(DeclarationLine); + + if (method.IsCopyCtor) + CopyCtorEmitted = true; + else if (method.IsCopyAssign) + CopyAssignEmitted = true; + else if (method.IsMoveCtor) + MoveCtorEmitted = true; + else if (method.IsMoveAssign) + MoveAssignEmitted = true; + + if (method.IsExplicitCtorOrConversionMethod) + DeclarationLineStream << "explicit "; + else if (!method.IsInstance) + DeclarationLineStream << "static "; + + if (!method.IsDtor && !method.IsConversionMethod && !method.IsCtor) + DeclarationLineStream << lldb_rpc_gen::ReplaceLLDBNamespaceWithRPCNamespace( + method.ReturnType.getAsString(method.Policy)) + << " "; ---------------- DavidSpickett wrote:
Let's add `{}` here, or put a blank line after it. The `<<` sort of lining up makes it look like it goes with the code outside the if. https://github.com/llvm/llvm-project/pull/147655 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits