LLDB mainline
Plugins/TypeSystem/Clike/Type.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Type.h"
10
11using namespace lldb_private::clike;
12
13// LLVM RTTI.
14char Type::ID = 0;
15
16bool Type::HasFields(llvm::function_ref<void(Type *)> complete) {
17 Type *t = Desugar();
18 complete(t);
19 if (t->GetNumFields() != 0)
20 return true;
21 // A record without a definition (e.g., due to -flimit-debug-info) is
22 // treated as having fields so that it isn't hidden as an empty base class.
23 if (!t->IsComplete())
24 return true;
25 for (uint32_t i = 0, n = t->GetNumBaseClasses(); i < n; ++i) {
26 const BaseClass *base = t->GetBaseClassAtIndex(i);
27 if (base && base->GetType().Get().HasFields(complete))
28 return true;
29 }
30 return false;
31}
A direct base class of a C++ class or Objective-C interface.
TypeRef GetType() const
The base class type.
The base class of all Types in the Clike TypeSystem.
virtual const BaseClass * GetBaseClassAtIndex(uint32_t idx) const
virtual uint32_t GetNumBaseClasses() const
The direct base classes of a C++ class.
static char ID
LLVM-style RTTI support.
virtual bool IsComplete() const
True if this type is not a forward declaration.
virtual Type * Desugar()
Removes all sugar (typedefs, qualifiers, elaborated types, ...).
bool HasFields(llvm::function_ref< void(Type *)> complete)
True if this type is a record that has fields, either directly or in one of its base classes.