2008-10-24 12:54:22 +08:00
|
|
|
//===------ SemaInherit.h - C++ Inheritance ---------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides Sema data structures that help analyse C++
|
|
|
|
// inheritance semantics, including searching the inheritance
|
|
|
|
// hierarchy.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_SEMA_INHERIT_H
|
|
|
|
#define LLVM_CLANG_SEMA_INHERIT_H
|
|
|
|
|
2009-02-07 08:15:38 +08:00
|
|
|
#include "Sema.h"
|
2009-01-15 08:26:24 +08:00
|
|
|
#include "clang/AST/DeclarationName.h"
|
|
|
|
#include "clang/AST/DeclBase.h"
|
2008-10-24 12:54:22 +08:00
|
|
|
#include "clang/AST/Type.h"
|
|
|
|
#include "clang/AST/TypeOrdering.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class CXXBaseSpecifier;
|
|
|
|
|
|
|
|
/// BasePathElement - An element in a path from a derived class to a
|
|
|
|
/// base class. Each step in the path references the link from a
|
|
|
|
/// derived class to one of its direct base classes, along with a
|
|
|
|
/// base "number" that identifies which base subobject of the
|
|
|
|
/// original derived class we are referencing.
|
|
|
|
struct BasePathElement {
|
|
|
|
/// Base - The base specifier that states the link from a derived
|
|
|
|
/// class to a base class, which will be followed by this base
|
|
|
|
/// path element.
|
|
|
|
const CXXBaseSpecifier *Base;
|
|
|
|
|
2009-03-28 02:54:29 +08:00
|
|
|
/// Class - The record decl of the class that the base is a base of.
|
2009-03-28 12:17:27 +08:00
|
|
|
const CXXRecordDecl *Class;
|
2009-03-28 02:54:29 +08:00
|
|
|
|
2008-10-24 12:54:22 +08:00
|
|
|
/// SubobjectNumber - Identifies which base class subobject (of type
|
|
|
|
/// @c Base->getType()) this base path element refers to. This
|
|
|
|
/// value is only valid if @c !Base->isVirtual(), because there
|
|
|
|
/// is no base numbering for the zero or one virtual bases of a
|
|
|
|
/// given type.
|
|
|
|
int SubobjectNumber;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// BasePath - Represents a path from a specific derived class
|
|
|
|
/// (which is not represented as part of the path) to a particular
|
2009-01-15 08:26:24 +08:00
|
|
|
/// (direct or indirect) base class subobject that contains some
|
|
|
|
/// number of declarations with the same name. Individual elements
|
2008-10-24 12:54:22 +08:00
|
|
|
/// in the path are described by the BasePathElement structure,
|
|
|
|
/// which captures both the link from a derived class to one of its
|
|
|
|
/// direct bases and identification describing which base class
|
2009-01-15 08:26:24 +08:00
|
|
|
/// subobject is being used.
|
|
|
|
struct BasePath : public llvm::SmallVector<BasePathElement, 4> {
|
|
|
|
/// Decls - The set of declarations found inside this base class
|
|
|
|
/// subobject.
|
|
|
|
DeclContext::lookup_result Decls;
|
|
|
|
};
|
2008-10-24 12:54:22 +08:00
|
|
|
|
|
|
|
/// BasePaths - Represents the set of paths from a derived class to
|
|
|
|
/// one of its (direct or indirect) bases. For example, given the
|
|
|
|
/// following class hierachy:
|
|
|
|
///
|
|
|
|
/// @code
|
|
|
|
/// class A { };
|
|
|
|
/// class B : public A { };
|
|
|
|
/// class C : public A { };
|
|
|
|
/// class D : public B, public C{ };
|
|
|
|
/// @endcode
|
|
|
|
///
|
|
|
|
/// There are two potential BasePaths to represent paths from D to a
|
|
|
|
/// base subobject of type A. One path is (D,0) -> (B,0) -> (A,0)
|
|
|
|
/// and another is (D,0)->(C,0)->(A,1). These two paths actually
|
|
|
|
/// refer to two different base class subobjects of the same type,
|
|
|
|
/// so the BasePaths object refers to an ambiguous path. On the
|
|
|
|
/// other hand, consider the following class hierarchy:
|
|
|
|
///
|
|
|
|
/// @code
|
|
|
|
/// class A { };
|
|
|
|
/// class B : public virtual A { };
|
|
|
|
/// class C : public virtual A { };
|
|
|
|
/// class D : public B, public C{ };
|
|
|
|
/// @endcode
|
|
|
|
///
|
|
|
|
/// Here, there are two potential BasePaths again, (D, 0) -> (B, 0)
|
|
|
|
/// -> (A,v) and (D, 0) -> (C, 0) -> (A, v), but since both of them
|
|
|
|
/// refer to the same base class subobject of type A (the virtual
|
|
|
|
/// one), there is no ambiguity.
|
|
|
|
class BasePaths {
|
2009-01-16 08:38:09 +08:00
|
|
|
/// Origin - The type from which this search originated.
|
|
|
|
QualType Origin;
|
|
|
|
|
2008-10-24 12:54:22 +08:00
|
|
|
/// Paths - The actual set of paths that can be taken from the
|
|
|
|
/// derived class to the same base class.
|
|
|
|
std::list<BasePath> Paths;
|
|
|
|
|
|
|
|
/// ClassSubobjects - Records the class subobjects for each class
|
|
|
|
/// type that we've seen. The first element in the pair says
|
|
|
|
/// whether we found a path to a virtual base for that class type,
|
|
|
|
/// while the element contains the number of non-virtual base
|
|
|
|
/// class subobjects for that class type. The key of the map is
|
|
|
|
/// the cv-unqualified canonical type of the base class subobject.
|
|
|
|
std::map<QualType, std::pair<bool, unsigned>, QualTypeOrdering>
|
|
|
|
ClassSubobjects;
|
|
|
|
|
2008-10-31 22:43:28 +08:00
|
|
|
/// FindAmbiguities - Whether Sema::IsDerivedFrom should try find
|
2008-10-24 12:54:22 +08:00
|
|
|
/// ambiguous paths while it is looking for a path from a derived
|
|
|
|
/// type to a base type.
|
|
|
|
bool FindAmbiguities;
|
|
|
|
|
2008-10-31 22:43:28 +08:00
|
|
|
/// RecordPaths - Whether Sema::IsDerivedFrom should record paths
|
2008-10-24 12:54:22 +08:00
|
|
|
/// while it is determining whether there are paths from a derived
|
|
|
|
/// type to a base type.
|
|
|
|
bool RecordPaths;
|
|
|
|
|
2008-10-31 22:43:28 +08:00
|
|
|
/// DetectVirtual - Whether Sema::IsDerivedFrom should abort the search
|
|
|
|
/// if it finds a path that goes across a virtual base. The virtual class
|
|
|
|
/// is also recorded.
|
|
|
|
bool DetectVirtual;
|
|
|
|
|
2008-10-24 12:54:22 +08:00
|
|
|
/// ScratchPath - A BasePath that is used by Sema::IsDerivedFrom
|
|
|
|
/// to help build the set of paths.
|
|
|
|
BasePath ScratchPath;
|
|
|
|
|
2008-10-31 22:43:28 +08:00
|
|
|
/// DetectedVirtual - The base class that is virtual.
|
2009-02-28 09:32:25 +08:00
|
|
|
const RecordType *DetectedVirtual;
|
2008-10-31 22:43:28 +08:00
|
|
|
|
2008-10-24 12:54:22 +08:00
|
|
|
friend class Sema;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef std::list<BasePath>::const_iterator paths_iterator;
|
|
|
|
|
|
|
|
/// BasePaths - Construct a new BasePaths structure to record the
|
|
|
|
/// paths for a derived-to-base search.
|
2008-10-31 22:43:28 +08:00
|
|
|
explicit BasePaths(bool FindAmbiguities = true,
|
|
|
|
bool RecordPaths = true,
|
|
|
|
bool DetectVirtual = true)
|
|
|
|
: FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths),
|
|
|
|
DetectVirtual(DetectVirtual), DetectedVirtual(0)
|
|
|
|
{}
|
2008-10-24 12:54:22 +08:00
|
|
|
|
|
|
|
paths_iterator begin() const { return Paths.begin(); }
|
|
|
|
paths_iterator end() const { return Paths.end(); }
|
|
|
|
|
2009-01-15 08:26:24 +08:00
|
|
|
BasePath& front() { return Paths.front(); }
|
|
|
|
const BasePath& front() const { return Paths.front(); }
|
|
|
|
|
2008-10-24 12:54:22 +08:00
|
|
|
bool isAmbiguous(QualType BaseType);
|
|
|
|
|
|
|
|
/// isFindingAmbiguities - Whether we are finding multiple paths
|
|
|
|
/// to detect ambiguities.
|
|
|
|
bool isFindingAmbiguities() const { return FindAmbiguities; }
|
|
|
|
|
|
|
|
/// isRecordingPaths - Whether we are recording paths.
|
|
|
|
bool isRecordingPaths() const { return RecordPaths; }
|
|
|
|
|
|
|
|
/// setRecordingPaths - Specify whether we should be recording
|
|
|
|
/// paths or not.
|
|
|
|
void setRecordingPaths(bool RP) { RecordPaths = RP; }
|
|
|
|
|
2008-10-31 22:43:28 +08:00
|
|
|
/// isDetectingVirtual - Whether we are detecting virtual bases.
|
|
|
|
bool isDetectingVirtual() const { return DetectVirtual; }
|
|
|
|
|
|
|
|
/// getDetectedVirtual - The virtual base discovered on the path.
|
2009-02-28 09:32:25 +08:00
|
|
|
const RecordType* getDetectedVirtual() const {
|
2008-10-31 22:43:28 +08:00
|
|
|
return DetectedVirtual;
|
|
|
|
}
|
|
|
|
|
2009-01-16 08:38:09 +08:00
|
|
|
/// @brief Retrieve the type from which this base-paths search
|
|
|
|
/// began
|
|
|
|
QualType getOrigin() const { return Origin; }
|
|
|
|
void setOrigin(QualType Type) { Origin = Type; }
|
|
|
|
|
2008-10-24 12:54:22 +08:00
|
|
|
void clear();
|
2009-01-15 08:26:24 +08:00
|
|
|
|
|
|
|
void swap(BasePaths &Other);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// MemberLookupCriteria - Criteria for performing lookup of a
|
|
|
|
/// member of a C++ class. Objects of this type are used to direct
|
|
|
|
/// Sema::LookupCXXClassMember.
|
|
|
|
struct MemberLookupCriteria {
|
|
|
|
/// MemberLookupCriteria - Constructs member lookup criteria to
|
|
|
|
/// search for a base class of type Base.
|
|
|
|
explicit MemberLookupCriteria(QualType Base)
|
|
|
|
: LookupBase(true), Base(Base) { }
|
|
|
|
|
|
|
|
/// MemberLookupCriteria - Constructs member lookup criteria to
|
|
|
|
/// search for a class member with the given Name.
|
|
|
|
explicit MemberLookupCriteria(DeclarationName Name,
|
Eliminated LookupCriteria, whose creation was causing a bottleneck for
LookupName et al. Instead, use an enum and a bool to describe its
contents.
Optimized the C/Objective-C path through LookupName, eliminating any
unnecessarily C++isms. Simplify IdentifierResolver::iterator, removing
some code and arguments that are no longer used.
Eliminated LookupDeclInScope/LookupDeclInContext, moving all callers
over to LookupName, LookupQualifiedName, or LookupParsedName, as
appropriate.
All together, I'm seeing a 0.2% speedup on Cocoa.h with PTH and
-disable-free. Plus, we're down to three name-lookup routines.
llvm-svn: 63354
2009-01-30 09:04:22 +08:00
|
|
|
Sema::LookupNameKind NameKind,
|
|
|
|
unsigned IDNS)
|
|
|
|
: LookupBase(false), Name(Name), NameKind(NameKind), IDNS(IDNS) { }
|
2009-01-15 08:26:24 +08:00
|
|
|
|
|
|
|
/// LookupBase - True if we are looking for a base class (whose
|
|
|
|
/// type is Base). If false, we are looking for a named member of
|
|
|
|
/// the class (with the name Name).
|
|
|
|
bool LookupBase;
|
|
|
|
|
|
|
|
/// Base - The type of the base class we're searching for, if
|
|
|
|
/// LookupBase is true.
|
|
|
|
QualType Base;
|
|
|
|
|
|
|
|
/// Name - The name of the member we're searching for, if
|
|
|
|
/// LookupBase is false.
|
|
|
|
DeclarationName Name;
|
|
|
|
|
Eliminated LookupCriteria, whose creation was causing a bottleneck for
LookupName et al. Instead, use an enum and a bool to describe its
contents.
Optimized the C/Objective-C path through LookupName, eliminating any
unnecessarily C++isms. Simplify IdentifierResolver::iterator, removing
some code and arguments that are no longer used.
Eliminated LookupDeclInScope/LookupDeclInContext, moving all callers
over to LookupName, LookupQualifiedName, or LookupParsedName, as
appropriate.
All together, I'm seeing a 0.2% speedup on Cocoa.h with PTH and
-disable-free. Plus, we're down to three name-lookup routines.
llvm-svn: 63354
2009-01-30 09:04:22 +08:00
|
|
|
Sema::LookupNameKind NameKind;
|
|
|
|
unsigned IDNS;
|
2008-10-24 12:54:22 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|