This is an archive of the discontinued LLVM Phabricator instance.

Refactor SetBaseClassesForType and DeleteBaseClasses to be more C++'y
ClosedPublic

Authored by zturner on Oct 23 2018, 11:00 AM.

Details

Summary
[NFC] Refactor SetBaseClasses and DeleteBaseClasses.

We currently had a 2-step process where we had to call
SetBaseClassesForType and DeleteBaseClasses.  Every single caller
followed this exact 2-step process, and there was manual memory
management going on with raw pointers.  We can do better than this
by storing a vector of unique_ptrs and passing this around.
This makes for a cleaner API, and we only need to call one method
so there is no possibility of a user forgetting to call
DeleteBaseClassSpecifiers.

In addition to this, it also makes for a *simpler* API.  Part of
why I wanted to do this is because when I was implementing the native
PDB interface I had to spend some time understanding exactly what I
was deleting and why.  ClangAST has significant mental overhead
associated with it, and reducing the API surface can go along
way to making it simpler for people to understand.

Diff Detail

Repository
rLLDB LLDB

Event Timeline

zturner created this revision.Oct 23 2018, 11:00 AM
shafik added a subscriber: shafik.Oct 23 2018, 12:38 PM

+1 for modernizing code!

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
2262 ↗(On Diff #170700)

const auto &

3274 ↗(On Diff #170700)

Is this correct? the if/else below does not seem dependent on this result?

zturner added inline comments.Oct 23 2018, 1:07 PM
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
3273–3274 ↗(On Diff #170700)

If the result is a nullptr, then there is no base to begin with. This indicates an error, so continuing doesn't make sense. In fact, I think this was a bug with the previous implementation. We were pushing back a null base onto the list of base classes. I suspect it never actually happened in practice, though.

3273–3274 ↗(On Diff #170700)

One alternative would be to assert that it is *not* null, then continue as the previous code did. WDYT?

This revision was not accepted when it landed; it landed in state Needs Review.Oct 25 2018, 1:47 PM
This revision was automatically updated to reflect the committed changes.