[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 6 10:09:25 PST 2023
================
@@ -99,25 +135,87 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
}
llvm::Expected<PythonObject> expected_return_object =
- llvm::createStringError(llvm::inconvertibleErrorCode(),
- "Resulting object is not initialized.");
+ create_error("Resulting object is not initialized.");
std::apply(
- [&method, &expected_return_object](auto &&...args) {
+ [&init, &expected_return_object](auto &&...args) {
llvm::consumeError(expected_return_object.takeError());
- expected_return_object = method(args...);
+ expected_return_object = init(args...);
},
transformed_args);
- if (llvm::Error e = expected_return_object.takeError())
- return std::move(e);
- result = std::move(expected_return_object.get());
+ if (!expected_return_object)
+ return expected_return_object.takeError();
+ result = expected_return_object.get();
}
if (!result.IsValid())
- return llvm::createStringError(
- llvm::inconvertibleErrorCode(),
- "Resulting object is not a valid Python Object.");
+ return create_error("Resulting object is not a valid Python Object.");
+ if (!result.HasAttribute("__class__"))
+ return create_error("Resulting object doesn't have '__class__' member.");
+
+ PythonObject obj_class = result.GetAttributeValue("__class__");
+ if (!obj_class.IsValid())
+ return create_error("Resulting class object is not a valid.");
+ if (!obj_class.HasAttribute("__name__"))
+ return create_error(
+ "Resulting object class doesn't have '__name__' member.");
+ PythonString obj_class_name =
+ obj_class.GetAttributeValue("__name__").AsType<PythonString>();
+
+ PythonObject object_class_mapping_proxy =
+ obj_class.GetAttributeValue("__dict__");
+ if (!obj_class.HasAttribute("__dict__"))
+ return create_error(
+ "Resulting object class doesn't have '__dict__' member.");
+
+ PythonCallable dict_converter = PythonModule::BuiltinsModule()
+ .ResolveName("dict")
+ .AsType<PythonCallable>();
+ if (!dict_converter.IsAllocated())
+ return create_error(
+ "Python 'builtins' module doesn't have 'dict' class.");
+
+ PythonDictionary object_class_dict =
+ dict_converter(object_class_mapping_proxy).AsType<PythonDictionary>();
+ if (!object_class_dict.IsAllocated())
+ return create_error("Coudn't create dictionary from resulting object "
+ "class mapping proxy object.");
+
+ auto checker_or_err = CheckAbstractMethodImplementation(object_class_dict);
+ if (!checker_or_err)
+ return checker_or_err.takeError();
+
+ for (const auto &method_checker : *checker_or_err)
+ switch (method_checker.second) {
+ case AbstractMethodCheckerCases::eNotImplemented:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "❌ Abstract method {0}.{1} not implemented.",
+ obj_class_name.GetString(), method_checker.first);
+ break;
+ case AbstractMethodCheckerCases::eNotAllocated:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "❌ Abstract method {0}.{1} not allocated.",
+ obj_class_name.GetString(), method_checker.first);
+ break;
+ case AbstractMethodCheckerCases::eNotCallable:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "❌ Abstract method {0}.{1} not callable.",
+ obj_class_name.GetString(), method_checker.first);
+ break;
+ case AbstractMethodCheckerCases::eValid:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "✅ Abstract method {0}.{1} implemented & valid.",
+ obj_class_name.GetString(), method_checker.first);
----------------
medismailben wrote:
💔
https://github.com/llvm/llvm-project/pull/71260
More information about the lldb-commits
mailing list