Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:49

0001 //===-- ScriptedInterface.h -------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
0010 #define LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
0011 
0012 #include "ScriptedInterfaceUsages.h"
0013 
0014 #include "lldb/Core/StructuredDataImpl.h"
0015 #include "lldb/Utility/LLDBLog.h"
0016 #include "lldb/Utility/Log.h"
0017 #include "lldb/Utility/UnimplementedError.h"
0018 #include "lldb/lldb-private.h"
0019 
0020 #include "llvm/Support/Compiler.h"
0021 
0022 #include <string>
0023 
0024 namespace lldb_private {
0025 class ScriptedInterface {
0026 public:
0027   ScriptedInterface() = default;
0028   virtual ~ScriptedInterface() = default;
0029 
0030   StructuredData::GenericSP GetScriptObjectInstance() {
0031     return m_object_instance_sp;
0032   }
0033 
0034   struct AbstractMethodRequirement {
0035     llvm::StringLiteral name;
0036     size_t min_arg_count = 0;
0037   };
0038 
0039   virtual llvm::SmallVector<AbstractMethodRequirement>
0040   GetAbstractMethodRequirements() const = 0;
0041 
0042   llvm::SmallVector<llvm::StringLiteral> const GetAbstractMethods() const {
0043     llvm::SmallVector<llvm::StringLiteral> abstract_methods;
0044     llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
0045                     [](const AbstractMethodRequirement &requirement) {
0046                       return requirement.name;
0047                     });
0048     return abstract_methods;
0049   }
0050 
0051   template <typename Ret>
0052   static Ret ErrorWithMessage(llvm::StringRef caller_name,
0053                               llvm::StringRef error_msg, Status &error,
0054                               LLDBLog log_category = LLDBLog::Process) {
0055     LLDB_LOGF(GetLog(log_category), "%s ERROR = %s", caller_name.data(),
0056               error_msg.data());
0057     std::string full_error_message =
0058         llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
0059                     llvm::Twine(error_msg))
0060             .str();
0061     if (const char *detailed_error = error.AsCString())
0062       full_error_message +=
0063           llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
0064                       llvm::Twine(")"))
0065               .str();
0066     error = Status(std::move(full_error_message));
0067     return {};
0068   }
0069 
0070   template <typename T = StructuredData::ObjectSP>
0071   static bool CheckStructuredDataObject(llvm::StringRef caller, T obj,
0072                                         Status &error) {
0073     if (!obj)
0074       return ErrorWithMessage<bool>(caller, "Null Structured Data object",
0075                                     error);
0076 
0077     if (!obj->IsValid()) {
0078       return ErrorWithMessage<bool>(caller, "Invalid StructuredData object",
0079                                     error);
0080     }
0081 
0082     if (error.Fail())
0083       return ErrorWithMessage<bool>(caller, error.AsCString(), error);
0084 
0085     return true;
0086   }
0087 
0088   static bool CreateInstance(lldb::ScriptLanguage language,
0089                              ScriptedInterfaceUsages usages) {
0090     return false;
0091   }
0092 
0093 protected:
0094   StructuredData::GenericSP m_object_instance_sp;
0095 };
0096 } // namespace lldb_private
0097 #endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H