teemperor created this revision.
teemperor added a reviewer: labath.
Herald added subscribers: lldb-commits, JDevlieghere, mgorny.
Herald added a project: LLDB.

There are a lot of classes using TypeSystem in some way (mostly indirectly
through CompilerType) and we can't really unittest this code at the moment 
without
having some kind of mock TypeSystem.

This adds a MockTypeSystem to the TestingSupport that provides a stub 
implementation
for all the deleted functions. Also adds a very basic CompilerTest that just 
uses the MockTypeSystem
as a simple TypeSystem placeholder.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D70775

Files:
  lldb/unittests/Symbol/CMakeLists.txt
  lldb/unittests/Symbol/CompilerTypeTest.cpp
  lldb/unittests/TestingSupport/CMakeLists.txt
  lldb/unittests/TestingSupport/MockTypeSystem.cpp
  lldb/unittests/TestingSupport/MockTypeSystem.h

Index: lldb/unittests/TestingSupport/MockTypeSystem.h
===================================================================
--- /dev/null
+++ lldb/unittests/TestingSupport/MockTypeSystem.h
@@ -0,0 +1,407 @@
+//===-- MockTypeSystem.h -----------------------------==---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeSystem.h"
+
+namespace lldb_private {
+/// A TypeSystem implementation that throws an error if any of its methods are
+/// called. Should be used as a base class for new TypeSystem subclasses in
+/// tests.
+struct MockTypeSystem : public TypeSystem {
+  // llvm casting support
+  static char ID;
+  bool isA(const void *ClassID) const override { return ClassID == &ID; }
+  static bool classof(const TypeSystem *ts) { return ts->isA(&ID); }
+
+  ConstString GetPluginName() override { llvm_unreachable("not implemented"); }
+
+  uint32_t GetPluginVersion() override { llvm_unreachable("not implemented"); }
+
+  ConstString DeclGetName(void *opaque_decl) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetTypeForDecl(void *opaque_decl) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) override {
+    llvm_unreachable("not implemented");
+  }
+
+  ConstString DeclContextGetName(void *opaque_decl_ctx) override {
+    llvm_unreachable("not implemented");
+  }
+
+  ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool
+  DeclContextIsClassMethod(void *opaque_decl_ctx,
+                           lldb::LanguageType *language_ptr,
+                           bool *is_instance_method_ptr,
+                           ConstString *language_object_name_ptr) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool DeclContextIsContainedInLookup(void *opaque_decl_ctx,
+                                      void *other_opaque_decl_ctx) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsArrayType(lldb::opaque_compiler_type_t type,
+                   CompilerType *element_type, uint64_t *size,
+                   bool *is_incomplete) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsAggregateType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsCharType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsCompleteType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsDefined(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
+                           bool &is_complex) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsFunctionType(lldb::opaque_compiler_type_t type,
+                      bool *is_variadic_ptr) override {
+    llvm_unreachable("not implemented");
+  }
+
+  size_t
+  GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
+                                          const size_t index) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
+                          CompilerType *function_pointer_type_ptr) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsIntegerType(lldb::opaque_compiler_type_t type,
+                     bool &is_signed) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
+                             CompilerType *target_type, bool check_cplusplus,
+                             bool check_objc) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsPointerType(lldb::opaque_compiler_type_t type,
+                     CompilerType *pointee_type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsScalarType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsVoidType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool CanPassInRegisters(const CompilerType &type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool SupportsLanguage(lldb::LanguageType language) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool GetCompleteType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t GetPointerByteSize() override {
+    llvm_unreachable("not implemented");
+  }
+
+  ConstString GetTypeName(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t
+  GetTypeInfo(lldb::opaque_compiler_type_t type,
+              CompilerType *pointee_or_element_compiler_type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  lldb::LanguageType
+  GetMinimumLanguage(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type,
+                                   uint64_t *stride) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type,
+                                              size_t idx) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType
+  GetFunctionReturnType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  TypeMemberFunctionImpl
+  GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type,
+                           size_t idx) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override {
+    llvm_unreachable("not implemented");
+  }
+
+  llvm::Optional<uint64_t>
+  GetBitSize(lldb::opaque_compiler_type_t type,
+             ExecutionContextScope *exe_scope) override {
+    llvm_unreachable("not implemented");
+  }
+
+  lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
+                             uint64_t &count) override {
+    llvm_unreachable("not implemented");
+  }
+
+  lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
+                          bool omit_empty_base_classes,
+                          const ExecutionContext *exe_ctx) override {
+    llvm_unreachable("not implemented");
+  }
+
+  lldb::BasicType
+  GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
+                               std::string &name, uint64_t *bit_offset_ptr,
+                               uint32_t *bitfield_bit_size_ptr,
+                               bool *is_bitfield_ptr) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t
+  GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type,
+                                         size_t idx,
+                                         uint32_t *bit_offset_ptr) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type,
+                                          size_t idx,
+                                          uint32_t *bit_offset_ptr) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetChildCompilerTypeAtIndex(
+      lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
+      bool transparent_pointers, bool omit_empty_base_classes,
+      bool ignore_array_bounds, std::string &child_name,
+      uint32_t &child_byte_size, int32_t &child_byte_offset,
+      uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
+      bool &child_is_base_class, bool &child_is_deref_of_parent,
+      ValueObject *valobj, uint64_t &language_flags) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
+                                   const char *name,
+                                   bool omit_empty_base_classes) override {
+    llvm_unreachable("not implemented");
+  }
+
+  size_t
+  GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type,
+                                const char *name, bool omit_empty_base_classes,
+                                std::vector<uint32_t> &child_indexes) override {
+    llvm_unreachable("not implemented");
+  }
+
+#ifndef NDEBUG
+  /// Convenience LLVM-style dump method for use in the debugger only.
+  LLVM_DUMP_METHOD void dump(lldb::opaque_compiler_type_t type) const override {
+    llvm_unreachable("not implemented");
+  }
+#endif
+
+  void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
+                 Stream *s, lldb::Format format, const DataExtractor &data,
+                 lldb::offset_t data_offset, size_t data_byte_size,
+                 uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
+                 bool show_types, bool show_summary, bool verbose,
+                 uint32_t depth) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s,
+                     lldb::Format format, const DataExtractor &data,
+                     lldb::offset_t data_offset, size_t data_byte_size,
+                     uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
+                     ExecutionContextScope *exe_scope) override {
+    llvm_unreachable("not implemented");
+  }
+
+  void DumpTypeDescription(lldb::opaque_compiler_type_t type) override {}
+
+  void DumpTypeDescription(lldb::opaque_compiler_type_t type,
+                           Stream *s) override {}
+
+  bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
+                   Stream *s, const DataExtractor &data,
+                   lldb::offset_t data_offset, size_t data_byte_size) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type,
+                                CompilerType *pointee_type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsCStringType(lldb::opaque_compiler_type_t type,
+                     uint32_t &length) override {
+    llvm_unreachable("not implemented");
+  }
+
+  llvm::Optional<size_t>
+  GetTypeBitAlign(lldb::opaque_compiler_type_t type,
+                  ExecutionContextScope *exe_scope) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
+                                                   size_t bit_size) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsBeingDefined(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+  bool IsConst(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type,
+                                  CompilerType *base_type_ptr) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsTypedefType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsVectorType(lldb::opaque_compiler_type_t type,
+                    CompilerType *element_type, uint64_t *size) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType
+  GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override {
+    llvm_unreachable("not implemented");
+  }
+
+  bool IsReferenceType(lldb::opaque_compiler_type_t type,
+                       CompilerType *pointee_type, bool *is_rvalue) override {
+    llvm_unreachable("not implemented");
+  }
+};
+} // namespace lldb_private
Index: lldb/unittests/TestingSupport/MockTypeSystem.cpp
===================================================================
--- /dev/null
+++ lldb/unittests/TestingSupport/MockTypeSystem.cpp
@@ -0,0 +1,11 @@
+//===-- MockTypeSystem.cpp ---------------------------==---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MockTypeSystem.h"
+
+char lldb_private::MockTypeSystem::ID;
Index: lldb/unittests/TestingSupport/CMakeLists.txt
===================================================================
--- lldb/unittests/TestingSupport/CMakeLists.txt
+++ lldb/unittests/TestingSupport/CMakeLists.txt
@@ -1,6 +1,7 @@
 set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
 add_lldb_library(lldbUtilityHelpers
   MockTildeExpressionResolver.cpp
+  MockTypeSystem.cpp
   TestUtilities.cpp
 
   LINK_LIBS
Index: lldb/unittests/Symbol/CompilerTypeTest.cpp
===================================================================
--- /dev/null
+++ lldb/unittests/Symbol/CompilerTypeTest.cpp
@@ -0,0 +1,45 @@
+//===-- CompilerTypeTest.cpp -------------------------==---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/CompilerType.h"
+#include "TestingSupport/MockTypeSystem.h"
+
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+namespace {
+struct TestTypeSystem : public lldb_private::MockTypeSystem {
+  void *GetOpaqueValidType() { return &valid_type_storage; }
+
+private:
+  int valid_type_storage;
+};
+} // namespace
+
+TEST(CompilerType, DefaultConstructor) {
+  CompilerType type;
+  EXPECT_EQ(nullptr, type.GetTypeSystem());
+  EXPECT_EQ(nullptr, type.GetOpaqueQualType());
+}
+
+TEST(CompilerType, Constructor) {
+  TestTypeSystem ts;
+  CompilerType type(&ts, ts.GetOpaqueValidType());
+  EXPECT_EQ(&ts, type.GetTypeSystem());
+  EXPECT_EQ(ts.GetOpaqueValidType(), type.GetOpaqueQualType());
+}
+
+TEST(CompilerType, Clear) {
+  TestTypeSystem ts;
+  CompilerType type(&ts, ts.GetOpaqueValidType());
+
+  type.Clear();
+  EXPECT_EQ(nullptr, type.GetTypeSystem());
+  EXPECT_EQ(nullptr, type.GetOpaqueQualType());
+}
Index: lldb/unittests/Symbol/CMakeLists.txt
===================================================================
--- lldb/unittests/Symbol/CMakeLists.txt
+++ lldb/unittests/Symbol/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_lldb_unittest(SymbolTests
+  CompilerTypeTest.cpp
   LocateSymbolFileTest.cpp
   PostfixExpressionTest.cpp
   TestClangASTContext.cpp
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to