forked from OSchip/llvm-project
Added source order to CXXBaseOrMemberInitializer.
llvm-svn: 104712
This commit is contained in:
parent
338674a323
commit
341d783488
|
@ -1068,13 +1068,19 @@ class CXXBaseOrMemberInitializer {
|
||||||
/// RParenLoc - Location of the right paren of the ctor-initializer.
|
/// RParenLoc - Location of the right paren of the ctor-initializer.
|
||||||
SourceLocation RParenLoc;
|
SourceLocation RParenLoc;
|
||||||
|
|
||||||
/// \brief The number of array index variables stored after this object
|
|
||||||
/// in memory.
|
|
||||||
unsigned NumArrayIndices;
|
|
||||||
|
|
||||||
/// IsVirtual - If the initializer is a base initializer, this keeps track
|
/// IsVirtual - If the initializer is a base initializer, this keeps track
|
||||||
/// of whether the base is virtual or not.
|
/// of whether the base is virtual or not.
|
||||||
bool IsVirtual;
|
bool IsVirtual : 1;
|
||||||
|
|
||||||
|
/// IsWritten - Whether or not the initializer is explicitly written
|
||||||
|
/// in the sources.
|
||||||
|
bool IsWritten : 1;
|
||||||
|
/// SourceOrderOrNumArrayIndices - If IsImplicit is false, then this
|
||||||
|
/// number keeps track of the textual order of this initializer in the
|
||||||
|
/// original sources, counting from 0; otherwise, if IsImplicit is true,
|
||||||
|
/// it stores the number of array index variables stored after this
|
||||||
|
/// object in memory.
|
||||||
|
unsigned SourceOrderOrNumArrayIndices : 14;
|
||||||
|
|
||||||
CXXBaseOrMemberInitializer(ASTContext &Context,
|
CXXBaseOrMemberInitializer(ASTContext &Context,
|
||||||
FieldDecl *Member, SourceLocation MemberLoc,
|
FieldDecl *Member, SourceLocation MemberLoc,
|
||||||
|
@ -1170,6 +1176,30 @@ public:
|
||||||
/// \brief Determine the source range covering the entire initializer.
|
/// \brief Determine the source range covering the entire initializer.
|
||||||
SourceRange getSourceRange() const;
|
SourceRange getSourceRange() const;
|
||||||
|
|
||||||
|
/// isWritten - Returns true if this initializer is explicitly written
|
||||||
|
/// in the source code.
|
||||||
|
bool isWritten() const { return IsWritten; }
|
||||||
|
|
||||||
|
/// \brief Return the source position of the initializer, counting from 0.
|
||||||
|
/// If the initializer was implicit, -1 is returned.
|
||||||
|
int getSourceOrder() const {
|
||||||
|
return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Set the source order of this initializer. This method can only
|
||||||
|
/// be called once for each initializer; it cannot be called on an
|
||||||
|
/// initializer having a positive number of (implicit) array indices.
|
||||||
|
void setSourceOrder(int pos) {
|
||||||
|
assert(!IsWritten &&
|
||||||
|
"calling twice setSourceOrder() on the same initializer");
|
||||||
|
assert(SourceOrderOrNumArrayIndices == 0 &&
|
||||||
|
"setSourceOrder() used when there are implicit array indices");
|
||||||
|
assert(pos >= 0 &&
|
||||||
|
"setSourceOrder() used to make an initializer implicit");
|
||||||
|
IsWritten = true;
|
||||||
|
SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
|
||||||
|
}
|
||||||
|
|
||||||
FieldDecl *getAnonUnionMember() const {
|
FieldDecl *getAnonUnionMember() const {
|
||||||
return AnonUnionMember;
|
return AnonUnionMember;
|
||||||
}
|
}
|
||||||
|
@ -1183,20 +1213,22 @@ public:
|
||||||
|
|
||||||
/// \brief Determine the number of implicit array indices used while
|
/// \brief Determine the number of implicit array indices used while
|
||||||
/// described an array member initialization.
|
/// described an array member initialization.
|
||||||
unsigned getNumArrayIndices() const { return NumArrayIndices; }
|
unsigned getNumArrayIndices() const {
|
||||||
|
return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Retrieve a particular array index variable used to
|
/// \brief Retrieve a particular array index variable used to
|
||||||
/// describe an array member initialization.
|
/// describe an array member initialization.
|
||||||
VarDecl *getArrayIndex(unsigned I) {
|
VarDecl *getArrayIndex(unsigned I) {
|
||||||
assert(I < NumArrayIndices && "Out of bounds member array index");
|
assert(I < getNumArrayIndices() && "Out of bounds member array index");
|
||||||
return reinterpret_cast<VarDecl **>(this + 1)[I];
|
return reinterpret_cast<VarDecl **>(this + 1)[I];
|
||||||
}
|
}
|
||||||
const VarDecl *getArrayIndex(unsigned I) const {
|
const VarDecl *getArrayIndex(unsigned I) const {
|
||||||
assert(I < NumArrayIndices && "Out of bounds member array index");
|
assert(I < getNumArrayIndices() && "Out of bounds member array index");
|
||||||
return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
|
return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
|
||||||
}
|
}
|
||||||
void setArrayIndex(unsigned I, VarDecl *Index) {
|
void setArrayIndex(unsigned I, VarDecl *Index) {
|
||||||
assert(I < NumArrayIndices && "Out of bounds member array index");
|
assert(I < getNumArrayIndices() && "Out of bounds member array index");
|
||||||
reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
|
reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -701,7 +701,8 @@ CXXBaseOrMemberInitializer(ASTContext &Context,
|
||||||
TypeSourceInfo *TInfo, bool IsVirtual,
|
TypeSourceInfo *TInfo, bool IsVirtual,
|
||||||
SourceLocation L, Expr *Init, SourceLocation R)
|
SourceLocation L, Expr *Init, SourceLocation R)
|
||||||
: BaseOrMember(TInfo), Init(Init), AnonUnionMember(0),
|
: BaseOrMember(TInfo), Init(Init), AnonUnionMember(0),
|
||||||
LParenLoc(L), RParenLoc(R), NumArrayIndices(0), IsVirtual(IsVirtual)
|
LParenLoc(L), RParenLoc(R), IsVirtual(IsVirtual), IsWritten(false),
|
||||||
|
SourceOrderOrNumArrayIndices(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,8 +711,8 @@ CXXBaseOrMemberInitializer(ASTContext &Context,
|
||||||
FieldDecl *Member, SourceLocation MemberLoc,
|
FieldDecl *Member, SourceLocation MemberLoc,
|
||||||
SourceLocation L, Expr *Init, SourceLocation R)
|
SourceLocation L, Expr *Init, SourceLocation R)
|
||||||
: BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
|
: BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
|
||||||
AnonUnionMember(0), LParenLoc(L), RParenLoc(R) , NumArrayIndices(0),
|
AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
|
||||||
IsVirtual(false)
|
IsWritten(false), SourceOrderOrNumArrayIndices(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,8 +723,8 @@ CXXBaseOrMemberInitializer(ASTContext &Context,
|
||||||
VarDecl **Indices,
|
VarDecl **Indices,
|
||||||
unsigned NumIndices)
|
unsigned NumIndices)
|
||||||
: BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
|
: BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
|
||||||
AnonUnionMember(0), LParenLoc(L), RParenLoc(R) ,
|
AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
|
||||||
NumArrayIndices(NumIndices), IsVirtual(false)
|
IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices)
|
||||||
{
|
{
|
||||||
VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1);
|
VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1);
|
||||||
memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *));
|
memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *));
|
||||||
|
|
|
@ -2142,6 +2142,9 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl,
|
||||||
for (unsigned i = 0; i < NumMemInits; i++) {
|
for (unsigned i = 0; i < NumMemInits; i++) {
|
||||||
CXXBaseOrMemberInitializer *Init = MemInits[i];
|
CXXBaseOrMemberInitializer *Init = MemInits[i];
|
||||||
|
|
||||||
|
// Set the source order index.
|
||||||
|
Init->setSourceOrder(i);
|
||||||
|
|
||||||
if (Init->isMemberInitializer()) {
|
if (Init->isMemberInitializer()) {
|
||||||
FieldDecl *Field = Init->getMember();
|
FieldDecl *Field = Init->getMember();
|
||||||
if (CheckRedundantInit(*this, Init, Members[Field]) ||
|
if (CheckRedundantInit(*this, Init, Members[Field]) ||
|
||||||
|
|
Loading…
Reference in New Issue