本文整理汇总了C++中cxxrecorddecl::method_iterator::getCanonicalDecl方法的典型用法代码示例。如果您正苦于以下问题:C++ method_iterator::getCanonicalDecl方法的具体用法?C++ method_iterator::getCanonicalDecl怎么用?C++ method_iterator::getCanonicalDecl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cxxrecorddecl::method_iterator
的用法示例。
在下文中一共展示了method_iterator::getCanonicalDecl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Collect
void FinalOverriderCollector::Collect(const CXXRecordDecl *RD,
bool VirtualBase,
const CXXRecordDecl *InVirtualSubobject,
CXXFinalOverriderMap &Overriders) {
unsigned SubobjectNumber = 0;
if (!VirtualBase)
SubobjectNumber
= ++SubobjectCount[cast<CXXRecordDecl>(RD->getCanonicalDecl())];
for (CXXRecordDecl::base_class_const_iterator Base = RD->bases_begin(),
BaseEnd = RD->bases_end(); Base != BaseEnd; ++Base) {
if (const RecordType *RT = Base->getType()->getAs<RecordType>()) {
const CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(RT->getDecl());
if (!BaseDecl->isPolymorphic())
continue;
if (Overriders.empty() && !Base->isVirtual()) {
// There are no other overriders of virtual member functions,
// so let the base class fill in our overriders for us.
Collect(BaseDecl, false, InVirtualSubobject, Overriders);
continue;
}
// Collect all of the overridders from the base class subobject
// and merge them into the set of overridders for this class.
// For virtual base classes, populate or use the cached virtual
// overrides so that we do not walk the virtual base class (and
// its base classes) more than once.
CXXFinalOverriderMap ComputedBaseOverriders;
CXXFinalOverriderMap *BaseOverriders = &ComputedBaseOverriders;
if (Base->isVirtual()) {
CXXFinalOverriderMap *&MyVirtualOverriders = VirtualOverriders[BaseDecl];
BaseOverriders = MyVirtualOverriders;
if (!MyVirtualOverriders) {
MyVirtualOverriders = new CXXFinalOverriderMap;
// Collect may cause VirtualOverriders to reallocate, invalidating the
// MyVirtualOverriders reference. Set BaseOverriders to the right
// value now.
BaseOverriders = MyVirtualOverriders;
Collect(BaseDecl, true, BaseDecl, *MyVirtualOverriders);
}
} else
Collect(BaseDecl, false, InVirtualSubobject, ComputedBaseOverriders);
// Merge the overriders from this base class into our own set of
// overriders.
for (CXXFinalOverriderMap::iterator OM = BaseOverriders->begin(),
OMEnd = BaseOverriders->end();
OM != OMEnd;
++OM) {
const CXXMethodDecl *CanonOM
= cast<CXXMethodDecl>(OM->first->getCanonicalDecl());
Overriders[CanonOM].add(OM->second);
}
}
}
for (CXXRecordDecl::method_iterator M = RD->method_begin(),
MEnd = RD->method_end();
M != MEnd;
++M) {
// We only care about virtual methods.
if (!M->isVirtual())
continue;
CXXMethodDecl *CanonM = cast<CXXMethodDecl>(M->getCanonicalDecl());
if (CanonM->begin_overridden_methods()
== CanonM->end_overridden_methods()) {
// This is a new virtual function that does not override any
// other virtual function. Add it to the map of virtual
// functions for which we are tracking overridders.
// C++ [class.virtual]p2:
// For convenience we say that any virtual function overrides itself.
Overriders[CanonM].add(SubobjectNumber,
UniqueVirtualMethod(CanonM, SubobjectNumber,
InVirtualSubobject));
continue;
}
// This virtual method overrides other virtual methods, so it does
// not add any new slots into the set of overriders. Instead, we
// replace entries in the set of overriders with the new
// overrider. To do so, we dig down to the original virtual
// functions using data recursion and update all of the methods it
// overrides.
typedef std::pair<CXXMethodDecl::method_iterator,
CXXMethodDecl::method_iterator> OverriddenMethods;
SmallVector<OverriddenMethods, 4> Stack;
Stack.push_back(std::make_pair(CanonM->begin_overridden_methods(),
CanonM->end_overridden_methods()));
while (!Stack.empty()) {
OverriddenMethods OverMethods = Stack.back();
Stack.pop_back();
for (; OverMethods.first != OverMethods.second; ++OverMethods.first) {
const CXXMethodDecl *CanonOM
//.........这里部分代码省略.........