forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple generations of function for offset calculation of virtual b... #32
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0013988
Fix multiple generations of function for offset calculation of virtua…
CristinaCristescu e1062a1
Add the cache for the base offset to the ClassInfo.
CristinaCristescu c094f98
Improve caching of the offset in TClingClassInfo.
CristinaCristescu 81f7144
Move offset calculation to TClingClassInfo.
CristinaCristescu 5583f58
Fixes to caching of base offset.
CristinaCristescu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ static std::string FullyQualifiedName(const Decl *decl) { | |
} | ||
|
||
TClingClassInfo::TClingClassInfo(cling::Interpreter *interp) | ||
: fInterp(interp), fFirstTime(true), fDescend(false), fDecl(0), fType(0), fOffsetFunctions(0) | ||
: fInterp(interp), fFirstTime(true), fDescend(false), fDecl(0), fType(0), fOffsetCache(0) | ||
{ | ||
TranslationUnitDecl *TU = | ||
interp->getCI()->getASTContext().getTranslationUnitDecl(); | ||
|
@@ -98,7 +98,7 @@ TClingClassInfo::TClingClassInfo(cling::Interpreter *interp) | |
|
||
TClingClassInfo::TClingClassInfo(cling::Interpreter *interp, const char *name) | ||
: fInterp(interp), fFirstTime(true), fDescend(false), fDecl(0), fType(0), | ||
fTitle(""), fOffsetFunctions(0) | ||
fTitle(""), fOffsetCache(0) | ||
{ | ||
const cling::LookupHelper& lh = fInterp->getLookupHelper(); | ||
const Type *type = 0; | ||
|
@@ -120,17 +120,18 @@ TClingClassInfo::TClingClassInfo(cling::Interpreter *interp, const char *name) | |
TClingClassInfo::TClingClassInfo(cling::Interpreter *interp, | ||
const Type &tag) | ||
: fInterp(interp), fFirstTime(true), fDescend(false), fDecl(0), fType(0), | ||
fTitle(""), fOffsetFunctions(0) | ||
fTitle(""), fOffsetCache(0) | ||
{ | ||
Init(tag); | ||
} | ||
|
||
void TClingClassInfo::AddBaseOffsetFunction(const clang::Decl* decl, OffsetPtrFunc_t func) | ||
void TClingClassInfo::AddBaseOffsetValue(const clang::Decl* decl, long offset) | ||
{ | ||
// Add a function pointer for the offset from this class to the base class | ||
// Add the offset value from this class to the non-virtual base class | ||
// determined by the parameter decl. | ||
|
||
fOffsetFunctions[decl] = func; | ||
|
||
OffsetPtrFunc_t executableFunc = 0; | ||
fOffsetCache[decl] = std::make_pair(offset, executableFunc); | ||
} | ||
|
||
long TClingClassInfo::ClassProperty() const | ||
|
@@ -234,14 +235,6 @@ void TClingClassInfo::Destruct(void *arena) const | |
cf.ExecDestructor(this, arena, /*nary=*/0, /*withFree=*/false); | ||
} | ||
|
||
OffsetPtrFunc_t TClingClassInfo::FindBaseOffsetFunction(const clang::Decl* decl) const | ||
{ | ||
// Find a pointer function for computing the offset to the base class determined | ||
// by the parameter decl. | ||
|
||
return fOffsetFunctions.lookup(decl); | ||
} | ||
|
||
const FunctionTemplateDecl *TClingClassInfo::GetFunctionTemplate(const char *fname) const | ||
{ | ||
// Return any method or function in this scope with the name 'fname'. | ||
|
@@ -533,6 +526,32 @@ long TClingClassInfo::GetOffset(const CXXMethodDecl* md) const | |
return offset; | ||
} | ||
|
||
ptrdiff_t TClingClassInfo::GetBaseOffset(TClingClassInfo* base, void* address) | ||
{ | ||
// Check for the offset in the cache. | ||
llvm::DenseMapIterator<const clang::Decl *, std::pair<ptrdiff_t, long (*)(void *)>, llvm::DenseMapInfo<const clang::Decl *>, true> iter | ||
= fOffsetCache.find(base->GetDecl()); | ||
if (iter != fOffsetCache.end()) { | ||
std::pair<ptrdiff_t, OffsetPtrFunc_t> offsetCache = (*iter).second; | ||
if (OffsetPtrFunc_t executableFunc = offsetCache.second) { | ||
if (address) { | ||
return (*executableFunc)(address); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else we know its a virtual base but we don't have an object - generating the offset function (as will happen here) won't help! I.e. we are missing an error message and a return -1 or whatever you return in these cases. |
||
} | ||
else { | ||
Error("TClingBaseClassInfo::Offset", "The address of the object for virtual base offset calculation is not valid."); | ||
return -1; | ||
} | ||
} | ||
else { | ||
return offsetCache.first; | ||
} | ||
} | ||
|
||
// Compute the offset. | ||
TClingBaseClassInfo binfo(fInterp, this, base); | ||
return binfo.Offset(address); | ||
} | ||
|
||
static bool HasBody(const clang::FunctionDecl &decl, const cling::Interpreter &interp) | ||
{ | ||
if (decl.hasBody()) return true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline in header?