Added locations and type source info for DeclarationName.

llvm-svn: 110860
This commit is contained in:
Abramo Bagnara 2010-08-11 22:01:17 +00:00
parent 00c37ef021
commit d6d2f18905
31 changed files with 959 additions and 452 deletions

View File

@ -870,7 +870,8 @@ public:
return getExtQualType(T, Qs);
}
DeclarationName getNameForTemplate(TemplateName Name);
DeclarationNameInfo getNameForTemplate(TemplateName Name,
SourceLocation NameLoc);
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
UnresolvedSetIterator End);

View File

@ -1153,11 +1153,15 @@ private:
DependentFunctionTemplateSpecializationInfo *>
TemplateOrSpecialization;
/// DNLoc - Provides source/type location info for the
/// declaration name embedded in the DeclaratorDecl base class.
DeclarationNameLoc DNLoc;
protected:
FunctionDecl(Kind DK, DeclContext *DC, SourceLocation L,
DeclarationName N, QualType T, TypeSourceInfo *TInfo,
FunctionDecl(Kind DK, DeclContext *DC, const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
StorageClass S, StorageClass SCAsWritten, bool isInline)
: DeclaratorDecl(DK, DC, L, N, T, TInfo),
: DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo),
DeclContext(DK),
ParamInfo(0), Body(),
SClass(S), SClassAsWritten(SCAsWritten), IsInline(isInline),
@ -1165,7 +1169,9 @@ protected:
HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false),
IsCopyAssignment(false),
HasImplicitReturnZero(false),
EndRangeLoc(L), TemplateOrSpecialization() {}
EndRangeLoc(NameInfo.getEndLoc()),
TemplateOrSpecialization(),
DNLoc(NameInfo.getInfo()) {}
typedef Redeclarable<FunctionDecl> redeclarable_base;
virtual FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
@ -1185,8 +1191,24 @@ public:
StorageClass S = None,
StorageClass SCAsWritten = None,
bool isInline = false,
bool hasWrittenPrototype = true) {
DeclarationNameInfo NameInfo(N, L);
return FunctionDecl::Create(C, DC, NameInfo, T, TInfo, S, SCAsWritten,
isInline, hasWrittenPrototype);
}
static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
StorageClass S = None,
StorageClass SCAsWritten = None,
bool isInline = false,
bool hasWrittenPrototype = true);
DeclarationNameInfo getNameInfo() const {
return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
}
virtual void getNameForDiagnostic(std::string &S,
const PrintingPolicy &Policy,
bool Qualified) const;

View File

@ -1065,19 +1065,20 @@ public:
/// struct/union/class.
class CXXMethodDecl : public FunctionDecl {
protected:
CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T, TypeSourceInfo *TInfo,
CXXMethodDecl(Kind DK, CXXRecordDecl *RD,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isStatic, StorageClass SCAsWritten, bool isInline)
: FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
: FunctionDecl(DK, RD, NameInfo, T, TInfo, (isStatic ? Static : None),
SCAsWritten, isInline) {}
public:
static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
QualType T, TypeSourceInfo *TInfo,
bool isStatic = false,
StorageClass SCAsWritten = FunctionDecl::None,
bool isInline = false);
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isStatic = false,
StorageClass SCAsWritten = FunctionDecl::None,
bool isInline = false);
bool isStatic() const { return getStorageClass() == Static; }
bool isInstance() const { return !isStatic(); }
@ -1392,11 +1393,11 @@ class CXXConstructorDecl : public CXXMethodDecl {
CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
unsigned NumBaseOrMemberInitializers;
CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T, TypeSourceInfo *TInfo,
CXXConstructorDecl(CXXRecordDecl *RD, const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isExplicitSpecified, bool isInline,
bool isImplicitlyDeclared)
: CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false,
: CXXMethodDecl(CXXConstructor, RD, NameInfo, T, TInfo, false,
FunctionDecl::None, isInline),
IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
@ -1406,7 +1407,7 @@ class CXXConstructorDecl : public CXXMethodDecl {
public:
static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty);
static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isExplicit,
bool isInline, bool isImplicitlyDeclared);
@ -1540,10 +1541,9 @@ class CXXDestructorDecl : public CXXMethodDecl {
FunctionDecl *OperatorDelete;
CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T,
bool isInline, bool isImplicitlyDeclared)
: CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false,
CXXDestructorDecl(CXXRecordDecl *RD, const DeclarationNameInfo &NameInfo,
QualType T, bool isInline, bool isImplicitlyDeclared)
: CXXMethodDecl(CXXDestructor, RD, NameInfo, T, /*TInfo=*/0, false,
FunctionDecl::None, isInline),
ImplicitlyDefined(false), OperatorDelete(0) {
setImplicit(isImplicitlyDeclared);
@ -1552,7 +1552,7 @@ class CXXDestructorDecl : public CXXMethodDecl {
public:
static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty);
static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
const DeclarationNameInfo &NameInfo,
QualType T, bool isInline,
bool isImplicitlyDeclared);
@ -1601,17 +1601,17 @@ class CXXConversionDecl : public CXXMethodDecl {
/// explicitly wrote a cast. This is a C++0x feature.
bool IsExplicitSpecified : 1;
CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T, TypeSourceInfo *TInfo,
CXXConversionDecl(CXXRecordDecl *RD, const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isInline, bool isExplicitSpecified)
: CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false,
: CXXMethodDecl(CXXConversion, RD, NameInfo, T, TInfo, false,
FunctionDecl::None, isInline),
IsExplicitSpecified(isExplicitSpecified) { }
public:
static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty);
static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isInline, bool isExplicit);

View File

@ -30,6 +30,7 @@ namespace clang {
class IdentifierInfo;
class MultiKeywordSelector;
class UsingDirectiveDecl;
class TypeSourceInfo;
/// DeclarationName - The name of a declaration. In the common case,
/// this just stores an IdentifierInfo pointer to a normal
@ -367,6 +368,146 @@ public:
DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
};
/// DeclarationNameLoc - Additional source/type location info
/// for a declaration name. Needs a DeclarationName in order
/// to be interpreted correctly.
struct DeclarationNameLoc {
union {
// The source location for identifier stored elsewhere.
// struct {} Identifier;
// Type info for constructors, destructors and conversion functions.
// Locations (if any) for the tilde (destructor) or operator keyword
// (conversion) are stored elsewhere.
struct {
TypeSourceInfo* TInfo;
} NamedType;
// The location (if any) of the operator keyword is stored elsewhere.
struct {
unsigned BeginOpNameLoc;
unsigned EndOpNameLoc;
} CXXOperatorName;
// The location (if any) of the operator keyword is stored elsewhere.
struct {
unsigned OpNameLoc;
} CXXLiteralOperatorName;
// struct {} CXXUsingDirective;
// struct {} ObjCZeroArgSelector;
// struct {} ObjCOneArgSelector;
// struct {} ObjCMultiArgSelector;
};
DeclarationNameLoc(DeclarationName Name);
// FIXME: this should go away once all DNLocs are properly initialized.
DeclarationNameLoc() { NamedType.TInfo = 0; }
}; // struct DeclarationNameLoc
/// DeclarationNameInfo - A collector data type for bundling together
/// a DeclarationName and the correspnding source/type location info.
struct DeclarationNameInfo {
private:
/// Name - The declaration name, also encoding name kind.
DeclarationName Name;
/// Loc - The main source location for the declaration name.
SourceLocation NameLoc;
/// Info - Further source/type location info for special kinds of names.
DeclarationNameLoc LocInfo;
public:
// FIXME: remove it.
DeclarationNameInfo() {}
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
: Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
DeclarationNameLoc LocInfo)
: Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
/// getName - Returns the embedded declaration name.
DeclarationName getName() const { return Name; }
/// setName - Sets the embedded declaration name.
void setName(DeclarationName N) { Name = N; }
/// getLoc - Returns the main location of the declaration name.
SourceLocation getLoc() const { return NameLoc; }
/// setLoc - Sets the main location of the declaration name.
void setLoc(SourceLocation L) { NameLoc = L; }
const DeclarationNameLoc &getInfo() const { return LocInfo; }
DeclarationNameLoc &getInfo() { return LocInfo; }
void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
/// getNamedTypeInfo - Returns the source type info associated to
/// the name. Assumes it is a constructor, destructor or conversion.
TypeSourceInfo *getNamedTypeInfo() const {
assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
Name.getNameKind() == DeclarationName::CXXDestructorName ||
Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
return LocInfo.NamedType.TInfo;
}
/// setNamedTypeInfo - Sets the source type info associated to
/// the name. Assumes it is a constructor, destructor or conversion.
void setNamedTypeInfo(TypeSourceInfo *TInfo) {
assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
Name.getNameKind() == DeclarationName::CXXDestructorName ||
Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
LocInfo.NamedType.TInfo = TInfo;
}
/// getCXXOperatorNameRange - Gets the range of the operator name
/// (without the operator keyword). Assumes it is a (non-literal) operator.
SourceRange getCXXOperatorNameRange() const {
assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
return SourceRange(
SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
);
}
/// setCXXOperatorNameRange - Sets the range of the operator name
/// (without the operator keyword). Assumes it is a C++ operator.
void setCXXOperatorNameRange(SourceRange R) {
assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
}
/// getCXXLiteralOperatorNameLoc - Returns the location of the literal
/// operator name (not the operator keyword).
/// Assumes it is a literal operator.
SourceLocation getCXXLiteralOperatorNameLoc() const {
assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
return SourceLocation::
getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
}
/// setCXXLiteralOperatorNameLoc - Sets the location of the literal
/// operator name (not the operator keyword).
/// Assumes it is a literal operator.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
}
/// getAsString - Retrieve the human-readable string for this name.
std::string getAsString() const;
/// printName - Print the human-readable name to a stream.
void printName(llvm::raw_ostream &OS) const;
/// getBeginLoc - Retrieve the location of the first token.
SourceLocation getBeginLoc() const { return NameLoc; }
/// getEndLoc - Retrieve the location of the last token.
SourceLocation getEndLoc() const;
/// getSourceRange - The range of the declaration name.
SourceRange getSourceRange() const {
return SourceRange(getBeginLoc(), getEndLoc());
}
};
/// Insertion operator for diagnostics. This allows sending DeclarationName's
/// into a diagnostic with <<.
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
@ -385,6 +526,12 @@ inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
return PD;
}
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
DeclarationNameInfo DNInfo) {
DNInfo.printName(OS);
return OS;
}
} // end namespace clang
namespace llvm {

View File

@ -522,10 +522,14 @@ class DeclRefExpr : public Expr {
// (2) the declaration's name was followed by an explicit template
// argument list.
llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
// Loc - The location of the declaration name itself.
SourceLocation Loc;
/// DNLoc - Provides source/type location info for the
/// declaration name embedded in DecoratedD.
DeclarationNameLoc DNLoc;
/// \brief Retrieve the qualifier that preceded the declaration name, if any.
NameQualifier *getNameQualifier() {
if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
@ -563,6 +567,11 @@ class DeclRefExpr : public Expr {
const TemplateArgumentListInfo *TemplateArgs,
QualType T);
DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
ValueDecl *D, const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs,
QualType T);
/// \brief Construct an empty declaration reference expression.
explicit DeclRefExpr(EmptyShell Empty)
: Expr(DeclRefExprClass, Empty) { }
@ -585,6 +594,14 @@ public:
QualType T,
const TemplateArgumentListInfo *TemplateArgs = 0);
static DeclRefExpr *Create(ASTContext &Context,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
ValueDecl *D,
const DeclarationNameInfo &NameInfo,
QualType T,
const TemplateArgumentListInfo *TemplateArgs = 0);
/// \brief Construct an empty declaration reference expression.
static DeclRefExpr *CreateEmpty(ASTContext &Context,
bool HasQualifier, unsigned NumTemplateArgs);
@ -593,6 +610,10 @@ public:
const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
DeclarationNameInfo getNameInfo() const {
return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
}
SourceLocation getLocation() const { return Loc; }
void setLocation(SourceLocation L) { Loc = L; }
virtual SourceRange getSourceRange() const;
@ -1586,6 +1607,10 @@ class MemberExpr : public Expr {
/// MemberLoc - This is the location of the member name.
SourceLocation MemberLoc;
/// MemberDNLoc - Provides source/type location info for the
/// declaration name embedded in MemberDecl.
DeclarationNameLoc MemberDNLoc;
/// IsArrow - True if this is "X->F", false if this is "X.F".
bool IsArrow : 1;
@ -1633,17 +1658,32 @@ class MemberExpr : public Expr {
}
public:
MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
const DeclarationNameInfo &NameInfo, QualType ty)
: Expr(MemberExprClass, ty,
base->isTypeDependent(), base->isValueDependent()),
Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()),
MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow),
HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {
assert(memberdecl->getDeclName() == NameInfo.getName());
}
// NOTE: this constructor should be used only when it is known that
// the member name can not provide additional syntactic info
// (i.e., source locations for C++ operator names or type source info
// for constructors, destructors and conversion oeprators).
MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
SourceLocation l, QualType ty)
: Expr(MemberExprClass, ty,
base->isTypeDependent(), base->isValueDependent()),
Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(),
IsArrow(isarrow),
HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
NestedNameSpecifier *qual, SourceRange qualrange,
ValueDecl *memberdecl, DeclAccessPair founddecl,
SourceLocation l,
DeclarationNameInfo MemberNameInfo,
const TemplateArgumentListInfo *targs,
QualType ty);
@ -1739,6 +1779,12 @@ public:
return getExplicitTemplateArgumentList()->RAngleLoc;
}
/// \brief Retrieve the member declaration name info.
DeclarationNameInfo getMemberNameInfo() const {
return DeclarationNameInfo(MemberDecl->getDeclName(),
MemberLoc, MemberDNLoc);
}
bool isArrow() const { return IsArrow; }
void setArrow(bool A) { IsArrow = A; }
@ -1750,9 +1796,8 @@ public:
virtual SourceRange getSourceRange() const {
// If we have an implicit base (like a C++ implicit this),
// make sure not to return its location
SourceLocation EndLoc = MemberLoc;
if (HasExplicitTemplateArgumentList)
EndLoc = getRAngleLoc();
SourceLocation EndLoc = (HasExplicitTemplateArgumentList)
? getRAngleLoc() : getMemberNameInfo().getEndLoc();
SourceLocation BaseLoc = getBase()->getLocStart();
if (BaseLoc.isInvalid())

View File

@ -1411,7 +1411,7 @@ class OverloadExpr : public Expr {
unsigned NumResults;
/// The common name of these declarations.
DeclarationName Name;
DeclarationNameInfo NameInfo;
/// The scope specifier, if any.
NestedNameSpecifier *Qualifier;
@ -1419,16 +1419,13 @@ class OverloadExpr : public Expr {
/// The source range of the scope specifier.
SourceRange QualifierRange;
/// The location of the name.
SourceLocation NameLoc;
protected:
/// True if the name was a template-id.
bool HasExplicitTemplateArgs;
OverloadExpr(StmtClass K, ASTContext &C, QualType T, bool Dependent,
NestedNameSpecifier *Qualifier, SourceRange QRange,
DeclarationName Name, SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
bool HasTemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End);
@ -1473,13 +1470,17 @@ public:
/// Gets the number of declarations in the unresolved set.
unsigned getNumDecls() const { return NumResults; }
/// Gets the full name info.
const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
/// Gets the name looked up.
DeclarationName getName() const { return Name; }
void setName(DeclarationName N) { Name = N; }
DeclarationName getName() const { return NameInfo.getName(); }
void setName(DeclarationName N) { NameInfo.setName(N); }
/// Gets the location of the name.
SourceLocation getNameLoc() const { return NameLoc; }
void setNameLoc(SourceLocation Loc) { NameLoc = Loc; }
SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); }
/// Fetches the nested-name qualifier, if one was given.
NestedNameSpecifier *getQualifier() const { return Qualifier; }
@ -1542,11 +1543,11 @@ class UnresolvedLookupExpr : public OverloadExpr {
UnresolvedLookupExpr(ASTContext &C, QualType T, bool Dependent,
CXXRecordDecl *NamingClass,
NestedNameSpecifier *Qualifier, SourceRange QRange,
DeclarationName Name, SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
bool RequiresADL, bool Overloaded, bool HasTemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End)
: OverloadExpr(UnresolvedLookupExprClass, C, T, Dependent, Qualifier,
QRange, Name, NameLoc, HasTemplateArgs, Begin, End),
QRange, NameInfo, HasTemplateArgs, Begin, End),
RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
{}
@ -1561,16 +1562,15 @@ public:
CXXRecordDecl *NamingClass,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
bool ADL, bool Overloaded,
UnresolvedSetIterator Begin,
UnresolvedSetIterator End) {
return new(C) UnresolvedLookupExpr(C,
Dependent ? C.DependentTy : C.OverloadTy,
Dependent, NamingClass,
Qualifier, QualifierRange,
Name, NameLoc, ADL, Overloaded, false,
Qualifier, QualifierRange, NameInfo,
ADL, Overloaded, false,
Begin, End);
}
@ -1579,8 +1579,7 @@ public:
CXXRecordDecl *NamingClass,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
bool ADL,
const TemplateArgumentListInfo &Args,
UnresolvedSetIterator Begin,
@ -1642,7 +1641,7 @@ public:
}
virtual SourceRange getSourceRange() const {
SourceRange Range(getNameLoc());
SourceRange Range(getNameInfo().getSourceRange());
if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
return Range;
@ -1673,10 +1672,7 @@ public:
/// declaration can be found.
class DependentScopeDeclRefExpr : public Expr {
/// The name of the entity we will be referencing.
DeclarationName Name;
/// Location of the name of the declaration we're referencing.
SourceLocation Loc;
DeclarationNameInfo NameInfo;
/// QualifierRange - The source range that covers the
/// nested-name-specifier.
@ -1692,12 +1688,10 @@ class DependentScopeDeclRefExpr : public Expr {
DependentScopeDeclRefExpr(QualType T,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
bool HasExplicitTemplateArgs)
: Expr(DependentScopeDeclRefExprClass, T, true, true),
Name(Name), Loc(NameLoc),
QualifierRange(QualifierRange), Qualifier(Qualifier),
NameInfo(NameInfo), QualifierRange(QualifierRange), Qualifier(Qualifier),
HasExplicitTemplateArgs(HasExplicitTemplateArgs)
{}
@ -1705,20 +1699,23 @@ public:
static DependentScopeDeclRefExpr *Create(ASTContext &C,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs = 0);
static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
unsigned NumTemplateArgs);
/// \brief Retrieve the name that this expression refers to.
DeclarationName getDeclName() const { return Name; }
void setDeclName(DeclarationName N) { Name = N; }
const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
/// \brief Retrieve the name that this expression refers to.
DeclarationName getDeclName() const { return NameInfo.getName(); }
void setDeclName(DeclarationName N) { NameInfo.setName(N); }
/// \brief Retrieve the location of the name within the expression.
SourceLocation getLocation() const { return Loc; }
void setLocation(SourceLocation L) { Loc = L; }
SourceLocation getLocation() const { return NameInfo.getLoc(); }
void setLocation(SourceLocation L) { NameInfo.setLoc(L); }
/// \brief Retrieve the source range of the nested-name-specifier.
SourceRange getQualifierRange() const { return QualifierRange; }
@ -2003,10 +2000,7 @@ class CXXDependentScopeMemberExpr : public Expr {
/// \brief The member to which this member expression refers, which
/// can be name, overloaded operator, or destructor.
/// FIXME: could also be a template-id
DeclarationName Member;
/// \brief The location of the member name.
SourceLocation MemberLoc;
DeclarationNameInfo MemberNameInfo;
CXXDependentScopeMemberExpr(ASTContext &C,
Expr *Base, QualType BaseType, bool IsArrow,
@ -2014,8 +2008,7 @@ class CXXDependentScopeMemberExpr : public Expr {
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
DeclarationNameInfo MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs);
public:
@ -2026,14 +2019,13 @@ public:
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc)
DeclarationNameInfo MemberNameInfo)
: Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
Base(Base), BaseType(BaseType), IsArrow(IsArrow),
HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
Qualifier(Qualifier), QualifierRange(QualifierRange),
FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Member(Member), MemberLoc(MemberLoc) { }
MemberNameInfo(MemberNameInfo) { }
static CXXDependentScopeMemberExpr *
Create(ASTContext &C,
@ -2042,8 +2034,7 @@ public:
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
DeclarationNameInfo MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs);
static CXXDependentScopeMemberExpr *
@ -2104,13 +2095,20 @@ public:
/// \brief Retrieve the name of the member that this expression
/// refers to.
DeclarationName getMember() const { return Member; }
void setMember(DeclarationName N) { Member = N; }
const DeclarationNameInfo &getMemberNameInfo() const {
return MemberNameInfo;
}
void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; }
/// \brief Retrieve the name of the member that this expression
/// refers to.
DeclarationName getMember() const { return MemberNameInfo.getName(); }
void setMember(DeclarationName N) { MemberNameInfo.setName(N); }
// \brief Retrieve the location of the name of the member that this
// expression refers to.
SourceLocation getMemberLoc() const { return MemberLoc; }
void setMemberLoc(SourceLocation L) { MemberLoc = L; }
SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); }
/// \brief Determines whether this member expression actually had a C++
/// template argument list explicitly specified, e.g., x.f<int>.
@ -2180,12 +2178,12 @@ public:
else if (getQualifier())
Range.setBegin(getQualifierRange().getBegin());
else
Range.setBegin(MemberLoc);
Range.setBegin(MemberNameInfo.getBeginLoc());
if (hasExplicitTemplateArgs())
Range.setEnd(getRAngleLoc());
else
Range.setEnd(MemberLoc);
Range.setEnd(MemberNameInfo.getEndLoc());
return Range;
}
@ -2238,8 +2236,7 @@ class UnresolvedMemberExpr : public OverloadExpr {
SourceLocation OperatorLoc,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Member,
SourceLocation MemberLoc,
const DeclarationNameInfo &MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End);
@ -2254,8 +2251,7 @@ public:
SourceLocation OperatorLoc,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Member,
SourceLocation MemberLoc,
const DeclarationNameInfo &MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End);
@ -2299,6 +2295,11 @@ public:
/// \brief Retrieves the naming class of this lookup.
CXXRecordDecl *getNamingClass() const;
/// \brief Retrieve the full name info for the member that this expression
/// refers to.
const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); }
/// \brief Retrieve the name of the member that this expression
/// refers to.
DeclarationName getMemberName() const { return getName(); }
@ -2353,18 +2354,14 @@ public:
}
virtual SourceRange getSourceRange() const {
SourceRange Range;
SourceRange Range = getMemberNameInfo().getSourceRange();
if (!isImplicitAccess())
Range.setBegin(Base->getSourceRange().getBegin());
else if (getQualifier())
Range.setBegin(getQualifierRange().getBegin());
else
Range.setBegin(getMemberLoc());
if (hasExplicitTemplateArgs())
Range.setEnd(getRAngleLoc());
else
Range.setEnd(getMemberLoc());
return Range;
}

View File

@ -2534,21 +2534,31 @@ bool ASTContext::UnwrapSimilarPointerTypes(QualType &T1, QualType &T2) {
return false;
}
DeclarationName ASTContext::getNameForTemplate(TemplateName Name) {
DeclarationNameInfo ASTContext::getNameForTemplate(TemplateName Name,
SourceLocation NameLoc) {
if (TemplateDecl *TD = Name.getAsTemplateDecl())
return TD->getDeclName();
// DNInfo work in progress: CHECKME: what about DNLoc?
return DeclarationNameInfo(TD->getDeclName(), NameLoc);
if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
DeclarationName DName;
if (DTN->isIdentifier()) {
return DeclarationNames.getIdentifier(DTN->getIdentifier());
DName = DeclarationNames.getIdentifier(DTN->getIdentifier());
return DeclarationNameInfo(DName, NameLoc);
} else {
return DeclarationNames.getCXXOperatorName(DTN->getOperator());
DName = DeclarationNames.getCXXOperatorName(DTN->getOperator());
// DNInfo work in progress: FIXME: source locations?
DeclarationNameLoc DNLoc;
DNLoc.CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding();
DNLoc.CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding();
return DeclarationNameInfo(DName, NameLoc, DNLoc);
}
}
OverloadedTemplateStorage *Storage = Name.getAsOverloadedTemplate();
assert(Storage);
return (*Storage->begin())->getDeclName();
// DNInfo work in progress: CHECKME: what about DNLoc?
return DeclarationNameInfo((*Storage->begin())->getDeclName(), NameLoc);
}
TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) {

View File

@ -81,6 +81,8 @@ namespace {
bool ImportDeclParts(NamedDecl *D, DeclContext *&DC,
DeclContext *&LexicalDC, DeclarationName &Name,
SourceLocation &Loc);
void ImportDeclarationNameLoc(const DeclarationNameInfo &From,
DeclarationNameInfo& To);
void ImportDeclContext(DeclContext *FromDC);
bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord);
bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
@ -1386,6 +1388,40 @@ bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC,
return false;
}
void
ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From,
DeclarationNameInfo& To) {
// NOTE: To.Name and To.Loc are already imported.
// We only have to import To.LocInfo.
switch (To.getName().getNameKind()) {
case DeclarationName::Identifier:
case DeclarationName::ObjCZeroArgSelector:
case DeclarationName::ObjCOneArgSelector:
case DeclarationName::ObjCMultiArgSelector:
case DeclarationName::CXXUsingDirective:
return;
case DeclarationName::CXXOperatorName: {
SourceRange Range = From.getCXXOperatorNameRange();
To.setCXXOperatorNameRange(Importer.Import(Range));
return;
}
case DeclarationName::CXXLiteralOperatorName: {
SourceLocation Loc = From.getCXXLiteralOperatorNameLoc();
To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc));
return;
}
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName: {
TypeSourceInfo *FromTInfo = From.getNamedTypeInfo();
To.setNamedTypeInfo(Importer.Import(FromTInfo));
return;
}
assert(0 && "Unknown name kind.");
}
}
void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC) {
for (DeclContext::decl_iterator From = FromDC->decls_begin(),
FromEnd = FromDC->decls_end();
@ -1823,7 +1859,7 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
SourceLocation Loc;
if (ImportDeclParts(D, DC, LexicalDC, Name, Loc))
return 0;
// Try to find a function in our own ("to") context with the same name, same
// type, and in the same context as the function we're importing.
if (!LexicalDC->isFunctionOrMethod()) {
@ -1872,6 +1908,10 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
}
}
DeclarationNameInfo NameInfo(Name, Loc);
// Import additional name location/type info.
ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
// Import the type.
QualType T = Importer.Import(D->getType());
if (T.isNull())
@ -1894,26 +1934,26 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
ToFunction = CXXConstructorDecl::Create(Importer.getToContext(),
cast<CXXRecordDecl>(DC),
Loc, Name, T, TInfo,
NameInfo, T, TInfo,
FromConstructor->isExplicit(),
D->isInlineSpecified(),
D->isImplicit());
} else if (isa<CXXDestructorDecl>(D)) {
ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
cast<CXXRecordDecl>(DC),
Loc, Name, T,
NameInfo, T,
D->isInlineSpecified(),
D->isImplicit());
} else if (CXXConversionDecl *FromConversion
= dyn_cast<CXXConversionDecl>(D)) {
ToFunction = CXXConversionDecl::Create(Importer.getToContext(),
cast<CXXRecordDecl>(DC),
Loc, Name, T, TInfo,
NameInfo, T, TInfo,
D->isInlineSpecified(),
FromConversion->isExplicit());
} else {
ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, Loc,
Name, T, TInfo, D->getStorageClass(),
ToFunction = FunctionDecl::Create(Importer.getToContext(), DC,
NameInfo, T, TInfo, D->getStorageClass(),
D->getStorageClassAsWritten(),
D->isInlineSpecified(),
D->hasWrittenPrototype());

View File

@ -1706,12 +1706,11 @@ ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
}
FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
DeclarationName N, QualType T,
TypeSourceInfo *TInfo,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
StorageClass S, StorageClass SCAsWritten,
bool isInline, bool hasWrittenPrototype) {
FunctionDecl *New = new (C) FunctionDecl(Function, DC, L, N, T, TInfo,
FunctionDecl *New = new (C) FunctionDecl(Function, DC, NameInfo, T, TInfo,
S, SCAsWritten, isInline);
New->HasWrittenPrototype = hasWrittenPrototype;
return New;

View File

@ -619,10 +619,10 @@ CXXDestructorDecl *CXXRecordDecl::getDestructor() const {
CXXMethodDecl *
CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isStatic, StorageClass SCAsWritten, bool isInline) {
return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, TInfo,
return new (C) CXXMethodDecl(CXXMethod, RD, NameInfo, T, TInfo,
isStatic, SCAsWritten, isInline);
}
@ -818,20 +818,21 @@ SourceRange CXXBaseOrMemberInitializer::getSourceRange() const {
CXXConstructorDecl *
CXXConstructorDecl::Create(ASTContext &C, EmptyShell Empty) {
return new (C) CXXConstructorDecl(0, SourceLocation(), DeclarationName(),
return new (C) CXXConstructorDecl(0, DeclarationNameInfo(),
QualType(), 0, false, false, false);
}
CXXConstructorDecl *
CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isExplicit,
bool isInline,
bool isImplicitlyDeclared) {
assert(N.getNameKind() == DeclarationName::CXXConstructorName &&
assert(NameInfo.getName().getNameKind()
== DeclarationName::CXXConstructorName &&
"Name must refer to a constructor");
return new (C) CXXConstructorDecl(RD, L, N, T, TInfo, isExplicit,
return new (C) CXXConstructorDecl(RD, NameInfo, T, TInfo, isExplicit,
isInline, isImplicitlyDeclared);
}
@ -926,34 +927,38 @@ bool CXXConstructorDecl::isCopyConstructorLikeSpecialization() const {
CXXDestructorDecl *
CXXDestructorDecl::Create(ASTContext &C, EmptyShell Empty) {
return new (C) CXXDestructorDecl(0, SourceLocation(), DeclarationName(),
return new (C) CXXDestructorDecl(0, DeclarationNameInfo(),
QualType(), false, false);
}
CXXDestructorDecl *
CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
const DeclarationNameInfo &NameInfo,
QualType T, bool isInline,
bool isImplicitlyDeclared) {
assert(N.getNameKind() == DeclarationName::CXXDestructorName &&
assert(NameInfo.getName().getNameKind()
== DeclarationName::CXXDestructorName &&
"Name must refer to a destructor");
return new (C) CXXDestructorDecl(RD, L, N, T, isInline, isImplicitlyDeclared);
return new (C) CXXDestructorDecl(RD, NameInfo, T, isInline,
isImplicitlyDeclared);
}
CXXConversionDecl *
CXXConversionDecl::Create(ASTContext &C, EmptyShell Empty) {
return new (C) CXXConversionDecl(0, SourceLocation(), DeclarationName(),
return new (C) CXXConversionDecl(0, DeclarationNameInfo(),
QualType(), 0, false, false);
}
CXXConversionDecl *
CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isInline, bool isExplicit) {
assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName &&
assert(NameInfo.getName().getNameKind()
== DeclarationName::CXXConversionFunctionName &&
"Name must refer to a conversion function");
return new (C) CXXConversionDecl(RD, L, N, T, TInfo, isInline, isExplicit);
return new (C) CXXConversionDecl(RD, NameInfo, T, TInfo,
isInline, isExplicit);
}
LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,

View File

@ -347,7 +347,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
PrintingPolicy SubPolicy(Policy);
SubPolicy.SuppressSpecifiers = false;
std::string Proto = D->getNameAsString();
std::string Proto = D->getNameInfo().getAsString();
if (isa<FunctionType>(D->getType().getTypePtr())) {
const FunctionType *AFT = D->getType()->getAs<FunctionType>();

View File

@ -15,6 +15,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeOrdering.h"
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/DenseMap.h"
@ -485,3 +486,98 @@ getHashValue(clang::DeclarationName N) {
return DenseMapInfo<void*>::getHashValue(N.getAsOpaquePtr());
}
DeclarationNameLoc::DeclarationNameLoc(DeclarationName Name) {
switch (Name.getNameKind()) {
case DeclarationName::Identifier:
break;
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
NamedType.TInfo = 0;
break;
case DeclarationName::CXXOperatorName:
CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding();
CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding();
break;
case DeclarationName::CXXLiteralOperatorName:
CXXLiteralOperatorName.OpNameLoc = SourceLocation().getRawEncoding();
break;
case DeclarationName::ObjCZeroArgSelector:
case DeclarationName::ObjCOneArgSelector:
case DeclarationName::ObjCMultiArgSelector:
// FIXME: ?
break;
case DeclarationName::CXXUsingDirective:
break;
}
}
std::string DeclarationNameInfo::getAsString() const {
std::string Result;
llvm::raw_string_ostream OS(Result);
printName(OS);
return OS.str();
}
void DeclarationNameInfo::printName(llvm::raw_ostream &OS) const {
switch (Name.getNameKind()) {
case DeclarationName::Identifier:
case DeclarationName::ObjCZeroArgSelector:
case DeclarationName::ObjCOneArgSelector:
case DeclarationName::ObjCMultiArgSelector:
case DeclarationName::CXXOperatorName:
case DeclarationName::CXXLiteralOperatorName:
case DeclarationName::CXXUsingDirective:
Name.printName(OS);
return;
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) {
if (Name.getNameKind() == DeclarationName::CXXDestructorName)
OS << '~';
else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
OS << "operator ";
OS << TInfo->getType().getAsString();
}
else
Name.printName(OS);
return;
}
assert(false && "Unexpected declaration name kind");
}
SourceLocation DeclarationNameInfo::getEndLoc() const {
switch (Name.getNameKind()) {
case DeclarationName::Identifier:
return NameLoc;
case DeclarationName::CXXOperatorName: {
unsigned raw = LocInfo.CXXOperatorName.EndOpNameLoc;
return SourceLocation::getFromRawEncoding(raw);
}
case DeclarationName::CXXLiteralOperatorName: {
unsigned raw = LocInfo.CXXLiteralOperatorName.OpNameLoc;
return SourceLocation::getFromRawEncoding(raw);
}
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo)
return TInfo->getTypeLoc().getEndLoc();
else
return NameLoc;
// DNInfo work in progress: FIXME.
case DeclarationName::ObjCZeroArgSelector:
case DeclarationName::ObjCOneArgSelector:
case DeclarationName::ObjCMultiArgSelector:
case DeclarationName::CXXUsingDirective:
return NameLoc;
}
assert(false && "Unexpected declaration name kind");
return SourceLocation();
}

View File

@ -209,6 +209,28 @@ DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier,
computeDependence();
}
DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
ValueDecl *D, const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs,
QualType T)
: Expr(DeclRefExprClass, T, false, false),
DecoratedD(D,
(Qualifier? HasQualifierFlag : 0) |
(TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)),
Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) {
if (Qualifier) {
NameQualifier *NQ = getNameQualifier();
NQ->NNS = Qualifier;
NQ->Range = QualifierRange;
}
if (TemplateArgs)
getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs);
computeDependence();
}
DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
@ -216,6 +238,18 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
SourceLocation NameLoc,
QualType T,
const TemplateArgumentListInfo *TemplateArgs) {
return Create(Context, Qualifier, QualifierRange, D,
DeclarationNameInfo(D->getDeclName(), NameLoc),
T, TemplateArgs);
}
DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
ValueDecl *D,
const DeclarationNameInfo &NameInfo,
QualType T,
const TemplateArgumentListInfo *TemplateArgs) {
std::size_t Size = sizeof(DeclRefExpr);
if (Qualifier != 0)
Size += sizeof(NameQualifier);
@ -224,7 +258,7 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>());
return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameLoc,
return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameInfo,
TemplateArgs, T);
}
@ -242,9 +276,7 @@ DeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, bool HasQualifier,
}
SourceRange DeclRefExpr::getSourceRange() const {
// FIXME: Does not handle multi-token names well, e.g., operator[].
SourceRange R(Loc);
SourceRange R = getNameInfo().getSourceRange();
if (hasQualifier())
R.setBegin(getQualifierRange().getBegin());
if (hasExplicitTemplateArgumentList())
@ -623,7 +655,7 @@ MemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow,
SourceRange qualrange,
ValueDecl *memberdecl,
DeclAccessPair founddecl,
SourceLocation l,
DeclarationNameInfo nameinfo,
const TemplateArgumentListInfo *targs,
QualType ty) {
std::size_t Size = sizeof(MemberExpr);
@ -638,7 +670,7 @@ MemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow,
Size += ExplicitTemplateArgumentList::sizeFor(*targs);
void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>());
MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, l, ty);
MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, ty);
if (hasQualOrFound) {
if (qual && qual->isDependent()) {

View File

@ -159,8 +159,9 @@ UnresolvedLookupExpr *
UnresolvedLookupExpr::Create(ASTContext &C, bool Dependent,
CXXRecordDecl *NamingClass,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange, DeclarationName Name,
SourceLocation NameLoc, bool ADL,
SourceRange QualifierRange,
const DeclarationNameInfo &NameInfo,
bool ADL,
const TemplateArgumentListInfo &Args,
UnresolvedSetIterator Begin,
UnresolvedSetIterator End)
@ -171,8 +172,8 @@ UnresolvedLookupExpr::Create(ASTContext &C, bool Dependent,
= new (Mem) UnresolvedLookupExpr(C,
Dependent ? C.DependentTy : C.OverloadTy,
Dependent, NamingClass,
Qualifier, QualifierRange,
Name, NameLoc, ADL,
Qualifier, QualifierRange, NameInfo,
ADL,
/*Overload*/ true,
/*ExplicitTemplateArgs*/ true,
Begin, End);
@ -196,14 +197,14 @@ UnresolvedLookupExpr::CreateEmpty(ASTContext &C, unsigned NumTemplateArgs) {
OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C, QualType T,
bool Dependent, NestedNameSpecifier *Qualifier,
SourceRange QRange, DeclarationName Name,
SourceLocation NameLoc, bool HasTemplateArgs,
SourceRange QRange,
const DeclarationNameInfo &NameInfo,
bool HasTemplateArgs,
UnresolvedSetIterator Begin,
UnresolvedSetIterator End)
: Expr(K, T, Dependent, Dependent),
Results(0), NumResults(0), Name(Name), Qualifier(Qualifier),
QualifierRange(QRange), NameLoc(NameLoc),
HasExplicitTemplateArgs(HasTemplateArgs)
Results(0), NumResults(0), NameInfo(NameInfo), Qualifier(Qualifier),
QualifierRange(QRange), HasExplicitTemplateArgs(HasTemplateArgs)
{
initializeResults(C, Begin, End);
}
@ -262,8 +263,7 @@ DependentScopeDeclRefExpr *
DependentScopeDeclRefExpr::Create(ASTContext &C,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *Args) {
std::size_t size = sizeof(DependentScopeDeclRefExpr);
if (Args) size += ExplicitTemplateArgumentList::sizeFor(*Args);
@ -272,8 +272,7 @@ DependentScopeDeclRefExpr::Create(ASTContext &C,
DependentScopeDeclRefExpr *DRE
= new (Mem) DependentScopeDeclRefExpr(C.DependentTy,
Qualifier, QualifierRange,
Name, NameLoc,
Args != 0);
NameInfo, Args != 0);
if (Args)
reinterpret_cast<ExplicitTemplateArgumentList*>(DRE+1)
@ -291,7 +290,7 @@ DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
void *Mem = C.Allocate(size);
return new (Mem) DependentScopeDeclRefExpr(QualType(), 0, SourceRange(),
DeclarationName(),SourceLocation(),
DeclarationNameInfo(),
NumTemplateArgs != 0);
}
@ -750,8 +749,7 @@ CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
DeclarationNameInfo MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs)
: Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
Base(Base), BaseType(BaseType), IsArrow(IsArrow),
@ -759,7 +757,7 @@ CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
OperatorLoc(OperatorLoc),
Qualifier(Qualifier), QualifierRange(QualifierRange),
FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Member(Member), MemberLoc(MemberLoc) {
MemberNameInfo(MemberNameInfo) {
if (TemplateArgs)
getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs);
}
@ -771,15 +769,14 @@ CXXDependentScopeMemberExpr::Create(ASTContext &C,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
DeclarationNameInfo MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
if (!TemplateArgs)
return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
IsArrow, OperatorLoc,
Qualifier, QualifierRange,
FirstQualifierFoundInScope,
Member, MemberLoc);
MemberNameInfo);
std::size_t size = sizeof(CXXDependentScopeMemberExpr);
if (TemplateArgs)
@ -790,7 +787,7 @@ CXXDependentScopeMemberExpr::Create(ASTContext &C,
IsArrow, OperatorLoc,
Qualifier, QualifierRange,
FirstQualifierFoundInScope,
Member, MemberLoc, TemplateArgs);
MemberNameInfo, TemplateArgs);
}
CXXDependentScopeMemberExpr *
@ -800,8 +797,7 @@ CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
0, SourceLocation(), 0,
SourceRange(), 0,
DeclarationName(),
SourceLocation());
DeclarationNameInfo());
std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
@ -810,8 +806,7 @@ CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
= new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
0, SourceLocation(), 0,
SourceRange(), 0,
DeclarationName(),
SourceLocation(), 0);
DeclarationNameInfo(), 0);
E->HasExplicitTemplateArgs = true;
return E;
}
@ -834,13 +829,12 @@ UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C, QualType T,
SourceLocation OperatorLoc,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName MemberName,
SourceLocation MemberLoc,
const DeclarationNameInfo &MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin,
UnresolvedSetIterator End)
: OverloadExpr(UnresolvedMemberExprClass, C, T, Dependent,
Qualifier, QualifierRange, MemberName, MemberLoc,
Qualifier, QualifierRange, MemberNameInfo,
TemplateArgs != 0, Begin, End),
IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
@ -855,8 +849,7 @@ UnresolvedMemberExpr::Create(ASTContext &C, bool Dependent,
SourceLocation OperatorLoc,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
DeclarationName Member,
SourceLocation MemberLoc,
const DeclarationNameInfo &MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin,
UnresolvedSetIterator End) {
@ -869,7 +862,7 @@ UnresolvedMemberExpr::Create(ASTContext &C, bool Dependent,
Dependent ? C.DependentTy : C.OverloadTy,
Dependent, HasUnresolvedUsing, Base, BaseType,
IsArrow, OperatorLoc, Qualifier, QualifierRange,
Member, MemberLoc, TemplateArgs, Begin, End);
MemberNameInfo, TemplateArgs, Begin, End);
}
UnresolvedMemberExpr *

View File

@ -472,7 +472,7 @@ void StmtPrinter::VisitExpr(Expr *Node) {
void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
if (NestedNameSpecifier *Qualifier = Node->getQualifier())
Qualifier->print(OS, Policy);
OS << Node->getDecl();
OS << Node->getNameInfo();
if (Node->hasExplicitTemplateArgumentList())
OS << TemplateSpecializationType::PrintTemplateArgumentList(
Node->getTemplateArgs(),
@ -483,7 +483,7 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
void StmtPrinter::VisitDependentScopeDeclRefExpr(
DependentScopeDeclRefExpr *Node) {
Node->getQualifier()->print(OS, Policy);
OS << Node->getDeclName().getAsString();
OS << Node->getNameInfo();
if (Node->hasExplicitTemplateArgs())
OS << TemplateSpecializationType::PrintTemplateArgumentList(
Node->getTemplateArgs(),
@ -494,7 +494,7 @@ void StmtPrinter::VisitDependentScopeDeclRefExpr(
void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
if (Node->getQualifier())
Node->getQualifier()->print(OS, Policy);
OS << Node->getName().getAsString();
OS << Node->getNameInfo();
if (Node->hasExplicitTemplateArgs())
OS << TemplateSpecializationType::PrintTemplateArgumentList(
Node->getTemplateArgs(),
@ -777,7 +777,7 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
if (NestedNameSpecifier *Qualifier = Node->getQualifier())
Qualifier->print(OS, Policy);
OS << Node->getMemberDecl();
OS << Node->getMemberNameInfo();
if (Node->hasExplicitTemplateArgumentList())
OS << TemplateSpecializationType::PrintTemplateArgumentList(
@ -1201,7 +1201,7 @@ void StmtPrinter::VisitCXXDependentScopeMemberExpr(
// FIXME: Track use of "template" keyword explicitly?
OS << "template ";
OS << Node->getMember().getAsString();
OS << Node->getMemberNameInfo();
if (Node->hasExplicitTemplateArgs()) {
OS << TemplateSpecializationType::PrintTemplateArgumentList(
@ -1221,7 +1221,7 @@ void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
// FIXME: this might originally have been written with 'template'
OS << Node->getMemberName().getAsString();
OS << Node->getMemberNameInfo();
if (Node->hasExplicitTemplateArgs()) {
OS << TemplateSpecializationType::PrintTemplateArgumentList(

View File

@ -231,6 +231,7 @@ void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
VisitDeclaratorDecl(FD);
// FIXME: read DeclarationNameLoc.
FD->IdentifierNamespace = Record[Idx++];
switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
@ -1403,7 +1404,7 @@ Decl *PCHReader::ReadDeclRecord(unsigned Index, pch::DeclID ID) {
D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
break;
case pch::DECL_CXX_METHOD:
D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(),
QualType(), 0);
break;
case pch::DECL_CXX_CONSTRUCTOR:

View File

@ -401,6 +401,7 @@ void PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
NumTemplateArgs);
E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
// FIXME: read DeclarationNameLoc.
E->setLocation(Reader.ReadSourceLocation(Record, Idx));
}
@ -1154,6 +1155,7 @@ PCHStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
E->setFirstQualifierFoundInScope(
cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])));
// FIXME: read whole DeclarationNameInfo.
E->setMember(Reader.ReadDeclarationName(Record, Idx));
E->setMemberLoc(Reader.ReadSourceLocation(Record, Idx));
}
@ -1169,6 +1171,7 @@ PCHStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
NumTemplateArgs);
// FIXME: read whole DeclarationNameInfo.
E->setDeclName(Reader.ReadDeclarationName(Record, Idx));
E->setLocation(Reader.ReadSourceLocation(Record, Idx));
E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
@ -1207,6 +1210,7 @@ void PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) {
}
E->initializeResults(*Reader.getContext(), Decls.begin(), Decls.end());
// FIXME: read whole DeclarationNameInfo.
E->setName(Reader.ReadDeclarationName(Record, Idx));
E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
@ -1475,11 +1479,13 @@ Stmt *PCHReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) {
QualType T = GetType(Record[Idx++]);
Expr *Base = ReadSubExpr();
ValueDecl *MemberD = cast<ValueDecl>(GetDecl(Record[Idx++]));
// FIXME: read DeclarationNameLoc.
SourceLocation MemberLoc = ReadSourceLocation(Record, Idx);
DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc);
bool IsArrow = Record[Idx++];
S = MemberExpr::Create(*Context, Base, IsArrow, NNS, QualifierRange,
MemberD, FoundDecl, MemberLoc,
MemberD, FoundDecl, MemberNameInfo,
NumTemplateArgs ? &ArgInfo : 0, T);
break;
}

View File

@ -214,6 +214,7 @@ void PCHDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
VisitDeclaratorDecl(D);
// FIXME: write DeclarationNameLoc.
Record.push_back(D->getIdentifierNamespace());
Record.push_back(D->getTemplatedKind());

View File

@ -382,6 +382,7 @@ void PCHStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
AddExplicitTemplateArgumentList(*E->getExplicitTemplateArgumentList());
Writer.AddDeclRef(E->getDecl(), Record);
// FIXME: write DeclarationNameLoc.
Writer.AddSourceLocation(E->getLocation(), Record);
Code = pch::EXPR_DECL_REF;
}
@ -552,6 +553,7 @@ void PCHStmtWriter::VisitMemberExpr(MemberExpr *E) {
Writer.AddTypeRef(E->getType(), Record);
Writer.AddStmt(E->getBase());
Writer.AddDeclRef(E->getMemberDecl(), Record);
// FIXME: write DeclarationNameLoc.
Writer.AddSourceLocation(E->getMemberLoc(), Record);
Record.push_back(E->isArrow());
Code = pch::EXPR_MEMBER;
@ -1178,6 +1180,7 @@ PCHStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
Writer.AddSourceRange(E->getQualifierRange(), Record);
Writer.AddDeclRef(E->getFirstQualifierFoundInScope(), Record);
// FIXME: write whole DeclarationNameInfo.
Writer.AddDeclarationName(E->getMember(), Record);
Writer.AddSourceLocation(E->getMemberLoc(), Record);
Code = pch::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
@ -1199,6 +1202,7 @@ PCHStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
Record.push_back(0);
}
// FIXME: write whole DeclarationNameInfo.
Writer.AddDeclarationName(E->getDeclName(), Record);
Writer.AddSourceLocation(E->getLocation(), Record);
Writer.AddSourceRange(E->getQualifierRange(), Record);
@ -1242,6 +1246,7 @@ void PCHStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
Record.push_back(OvI.getAccess());
}
// FIXME: write whole DeclarationNameInfo.
Writer.AddDeclarationName(E->getName(), Record);
Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
Writer.AddSourceRange(E->getQualifierRange(), Record);

View File

@ -125,15 +125,34 @@ public:
typedef UnresolvedSetImpl::iterator iterator;
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc,
LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo,
Sema::LookupNameKind LookupKind,
Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
: ResultKind(NotFound),
Paths(0),
NamingClass(0),
SemaRef(SemaRef),
Name(Name),
NameLoc(NameLoc),
NameInfo(NameInfo),
LookupKind(LookupKind),
IDNS(0),
Redecl(Redecl != Sema::NotForRedeclaration),
HideTags(true),
Diagnose(Redecl == Sema::NotForRedeclaration)
{
configure();
}
// TODO: consider whether this constructor should be restricted to take
// as input a const IndentifierInfo* (instead of Name),
// forcing other cases towards the constructor taking a DNInfo.
LookupResult(Sema &SemaRef, DeclarationName Name,
SourceLocation NameLoc, Sema::LookupNameKind LookupKind,
Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
: ResultKind(NotFound),
Paths(0),
NamingClass(0),
SemaRef(SemaRef),
NameInfo(Name, NameLoc),
LookupKind(LookupKind),
IDNS(0),
Redecl(Redecl != Sema::NotForRedeclaration),
@ -151,8 +170,7 @@ public:
Paths(0),
NamingClass(0),
SemaRef(Other.SemaRef),
Name(Other.Name),
NameLoc(Other.NameLoc),
NameInfo(Other.NameInfo),
LookupKind(Other.LookupKind),
IDNS(Other.IDNS),
Redecl(Other.Redecl),
@ -165,14 +183,24 @@ public:
if (Paths) deletePaths(Paths);
}
/// Gets the name info to look up.
const DeclarationNameInfo &getLookupNameInfo() const {
return NameInfo;
}
/// \brief Sets the name info to look up.
void setLookupNameInfo(const DeclarationNameInfo &NameInfo) {
this->NameInfo = NameInfo;
}
/// Gets the name to look up.
DeclarationName getLookupName() const {
return Name;
return NameInfo.getName();
}
/// \brief Sets the name to look up.
void setLookupName(DeclarationName Name) {
this->Name = Name;
NameInfo.setName(Name);
}
/// Gets the kind of lookup to perform.
@ -444,7 +472,7 @@ public:
/// Gets the location of the identifier. This isn't always defined:
/// sometimes we're doing lookups on synthesized names.
SourceLocation getNameLoc() const {
return NameLoc;
return NameInfo.getLoc();
}
/// \brief Get the Sema object that this lookup result is searching
@ -572,8 +600,7 @@ private:
// Parameters.
Sema &SemaRef;
DeclarationName Name;
SourceLocation NameLoc;
DeclarationNameInfo NameInfo;
SourceRange NameContextRange;
Sema::LookupNameKind LookupKind;
unsigned IDNS; // set by configure()

View File

@ -785,8 +785,8 @@ public:
TypeSourceInfo *ReturnTypeInfo);
/// \brief Create a LocInfoType to hold the given QualType and TypeSourceInfo.
QualType CreateLocInfoType(QualType T, TypeSourceInfo *TInfo);
DeclarationName GetNameForDeclarator(Declarator &D);
DeclarationName GetNameFromUnqualifiedId(const UnqualifiedId &Name);
DeclarationNameInfo GetNameForDeclarator(Declarator &D);
DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
static QualType GetTypeFromParser(TypeTy *Ty, TypeSourceInfo **TInfo = 0);
bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
bool CheckDistantExceptionSpec(QualType T);
@ -1916,14 +1916,16 @@ public:
bool AllowBuiltinCreation=false);
OwningExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
bool isAddressOfOperand,
const TemplateArgumentListInfo *TemplateArgs);
OwningExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
SourceLocation Loc,
const CXXScopeSpec *SS = 0);
OwningExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
const DeclarationNameInfo &NameInfo,
const CXXScopeSpec *SS = 0);
VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field,
llvm::SmallVectorImpl<FieldDecl *> &Path);
OwningExprResult
@ -1943,18 +1945,16 @@ public:
bool HasTrailingLParen);
OwningExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc);
const DeclarationNameInfo &NameInfo);
OwningExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs);
OwningExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
LookupResult &R,
bool ADL);
OwningExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
SourceLocation Loc,
const DeclarationNameInfo &NameInfo,
NamedDecl *D);
virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
@ -2014,8 +2014,7 @@ public:
bool IsArrow,
CXXScopeSpec &SS,
NamedDecl *FirstQualifierInScope,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs);
OwningExprResult BuildMemberReferenceExpr(ExprArg Base,
@ -2043,8 +2042,7 @@ public:
SourceLocation OpLoc,
const CXXScopeSpec &SS,
NamedDecl *FirstQualifierInScope,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs);
virtual OwningExprResult ActOnMemberAccessExpr(Scope *S, ExprArg Base,
@ -3073,8 +3071,7 @@ public:
bool RequiresADL,
const TemplateArgumentListInfo &TemplateArgs);
OwningExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo &TemplateArgs);
virtual TemplateNameKind ActOnDependentTemplateName(Scope *S,
@ -3974,7 +3971,9 @@ public:
SubstNestedNameSpecifier(NestedNameSpecifier *NNS,
SourceRange Range,
const MultiLevelTemplateArgumentList &TemplateArgs);
DeclarationNameInfo
SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
const MultiLevelTemplateArgumentList &TemplateArgs);
TemplateName
SubstTemplateName(TemplateName Name, SourceLocation Loc,
const MultiLevelTemplateArgumentList &TemplateArgs);

View File

@ -1881,79 +1881,110 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
/// GetNameForDeclarator - Determine the full declaration name for the
/// given Declarator.
DeclarationName Sema::GetNameForDeclarator(Declarator &D) {
DeclarationNameInfo Sema::GetNameForDeclarator(Declarator &D) {
return GetNameFromUnqualifiedId(D.getName());
}
/// \brief Retrieves the canonicalized name from a parsed unqualified-id.
DeclarationName Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) {
/// \brief Retrieves the declaration name from a parsed unqualified-id.
DeclarationNameInfo
Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) {
DeclarationNameInfo NameInfo;
NameInfo.setLoc(Name.StartLocation);
switch (Name.getKind()) {
case UnqualifiedId::IK_Identifier:
return DeclarationName(Name.Identifier);
case UnqualifiedId::IK_OperatorFunctionId:
return Context.DeclarationNames.getCXXOperatorName(
Name.OperatorFunctionId.Operator);
case UnqualifiedId::IK_LiteralOperatorId:
return Context.DeclarationNames.getCXXLiteralOperatorName(
Name.Identifier);
case UnqualifiedId::IK_Identifier:
NameInfo.setName(Name.Identifier);
NameInfo.setLoc(Name.StartLocation);
return NameInfo;
case UnqualifiedId::IK_ConversionFunctionId: {
QualType Ty = GetTypeFromParser(Name.ConversionFunctionId);
if (Ty.isNull())
return DeclarationName();
return Context.DeclarationNames.getCXXConversionFunctionName(
Context.getCanonicalType(Ty));
}
case UnqualifiedId::IK_ConstructorName: {
QualType Ty = GetTypeFromParser(Name.ConstructorName);
if (Ty.isNull())
return DeclarationName();
return Context.DeclarationNames.getCXXConstructorName(
Context.getCanonicalType(Ty));
}
case UnqualifiedId::IK_ConstructorTemplateId: {
// In well-formed code, we can only have a constructor
// template-id that refers to the current context, so go there
// to find the actual type being constructed.
CXXRecordDecl *CurClass = dyn_cast<CXXRecordDecl>(CurContext);
if (!CurClass || CurClass->getIdentifier() != Name.TemplateId->Name)
return DeclarationName();
case UnqualifiedId::IK_OperatorFunctionId:
NameInfo.setName(Context.DeclarationNames.getCXXOperatorName(
Name.OperatorFunctionId.Operator));
NameInfo.setLoc(Name.StartLocation);
NameInfo.getInfo().CXXOperatorName.BeginOpNameLoc
= Name.OperatorFunctionId.SymbolLocations[0];
NameInfo.getInfo().CXXOperatorName.EndOpNameLoc
= Name.EndLocation.getRawEncoding();
return NameInfo;
// Determine the type of the class being constructed.
QualType CurClassType = Context.getTypeDeclType(CurClass);
case UnqualifiedId::IK_LiteralOperatorId:
NameInfo.setName(Context.DeclarationNames.getCXXLiteralOperatorName(
Name.Identifier));
NameInfo.setLoc(Name.StartLocation);
NameInfo.setCXXLiteralOperatorNameLoc(Name.EndLocation);
return NameInfo;
// FIXME: Check two things: that the template-id names the same type as
// CurClassType, and that the template-id does not occur when the name
// was qualified.
return Context.DeclarationNames.getCXXConstructorName(
Context.getCanonicalType(CurClassType));
}
case UnqualifiedId::IK_DestructorName: {
QualType Ty = GetTypeFromParser(Name.DestructorName);
if (Ty.isNull())
return DeclarationName();
return Context.DeclarationNames.getCXXDestructorName(
Context.getCanonicalType(Ty));
}
case UnqualifiedId::IK_TemplateId: {
TemplateName TName
= TemplateName::getFromVoidPointer(Name.TemplateId->Template);
return Context.getNameForTemplate(TName);
}
case UnqualifiedId::IK_ConversionFunctionId: {
TypeSourceInfo *TInfo;
QualType Ty = GetTypeFromParser(Name.ConversionFunctionId, &TInfo);
if (Ty.isNull())
return DeclarationNameInfo();
NameInfo.setName(Context.DeclarationNames.getCXXConversionFunctionName(
Context.getCanonicalType(Ty)));
NameInfo.setLoc(Name.StartLocation);
NameInfo.setNamedTypeInfo(TInfo);
return NameInfo;
}
case UnqualifiedId::IK_ConstructorName: {
TypeSourceInfo *TInfo;
QualType Ty = GetTypeFromParser(Name.ConstructorName, &TInfo);
if (Ty.isNull())
return DeclarationNameInfo();
NameInfo.setName(Context.DeclarationNames.getCXXConstructorName(
Context.getCanonicalType(Ty)));
NameInfo.setLoc(Name.StartLocation);
NameInfo.setNamedTypeInfo(TInfo);
return NameInfo;
}
case UnqualifiedId::IK_ConstructorTemplateId: {
// In well-formed code, we can only have a constructor
// template-id that refers to the current context, so go there
// to find the actual type being constructed.
CXXRecordDecl *CurClass = dyn_cast<CXXRecordDecl>(CurContext);
if (!CurClass || CurClass->getIdentifier() != Name.TemplateId->Name)
return DeclarationNameInfo();
// Determine the type of the class being constructed.
QualType CurClassType = Context.getTypeDeclType(CurClass);
// FIXME: Check two things: that the template-id names the same type as
// CurClassType, and that the template-id does not occur when the name
// was qualified.
NameInfo.setName(Context.DeclarationNames.getCXXConstructorName(
Context.getCanonicalType(CurClassType)));
NameInfo.setLoc(Name.StartLocation);
// FIXME: should we retrieve TypeSourceInfo?
NameInfo.setNamedTypeInfo(0);
return NameInfo;
}
case UnqualifiedId::IK_DestructorName: {
TypeSourceInfo *TInfo;
QualType Ty = GetTypeFromParser(Name.DestructorName, &TInfo);
if (Ty.isNull())
return DeclarationNameInfo();
NameInfo.setName(Context.DeclarationNames.getCXXDestructorName(
Context.getCanonicalType(Ty)));
NameInfo.setLoc(Name.StartLocation);
NameInfo.setNamedTypeInfo(TInfo);
return NameInfo;
}
case UnqualifiedId::IK_TemplateId: {
TemplateName TName
= TemplateName::getFromVoidPointer(Name.TemplateId->Template);
SourceLocation TNameLoc = Name.TemplateId->TemplateNameLoc;
return Context.getNameForTemplate(TName, TNameLoc);
}
} // switch (Name.getKind())
assert(false && "Unknown name kind");
return DeclarationName();
return DeclarationNameInfo();
}
/// isNearlyMatchingFunction - Determine whether the C++ functions
@ -2047,7 +2078,9 @@ Sema::DeclPtrTy
Sema::HandleDeclarator(Scope *S, Declarator &D,
MultiTemplateParamsArg TemplateParamLists,
bool IsFunctionDefinition) {
DeclarationName Name = GetNameForDeclarator(D);
// TODO: consider using NameInfo for diagnostic.
DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
DeclarationName Name = NameInfo.getName();
// All of these full declarators require an identifier. If it doesn't have
// one, the ParsedFreeStandingDeclSpec action should be used.
@ -2111,7 +2144,7 @@ Sema::HandleDeclarator(Scope *S, Declarator &D,
TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
QualType R = TInfo->getType();
LookupResult Previous(*this, Name, D.getIdentifierLoc(), LookupOrdinaryName,
LookupResult Previous(*this, NameInfo, LookupOrdinaryName,
ForRedeclaration);
// See if this is a redefinition of a variable in the same scope.
@ -2497,7 +2530,7 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
LookupResult &Previous,
MultiTemplateParamsArg TemplateParamLists,
bool &Redeclaration) {
DeclarationName Name = GetNameForDeclarator(D);
DeclarationName Name = GetNameForDeclarator(D).getName();
// Check that there are no default arguments (C++ only).
if (getLangOptions().CPlusPlus)
@ -2961,7 +2994,9 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
bool IsFunctionDefinition, bool &Redeclaration) {
assert(R.getTypePtr()->isFunctionType());
DeclarationName Name = GetNameForDeclarator(D);
// TODO: consider using NameInfo for diagnostic.
DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
DeclarationName Name = NameInfo.getName();
FunctionDecl::StorageClass SC = FunctionDecl::None;
switch (D.getDeclSpec().getStorageClassSpec()) {
default: assert(0 && "Unknown storage class!");
@ -3041,7 +3076,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
// Create the new declaration
NewFD = CXXConstructorDecl::Create(Context,
cast<CXXRecordDecl>(DC),
D.getIdentifierLoc(), Name, R, TInfo,
NameInfo, R, TInfo,
isExplicit, isInline,
/*isImplicitlyDeclared=*/false);
} else if (Name.getNameKind() == DeclarationName::CXXDestructorName) {
@ -3051,7 +3086,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
NewFD = CXXDestructorDecl::Create(Context,
cast<CXXRecordDecl>(DC),
D.getIdentifierLoc(), Name, R,
NameInfo, R,
isInline,
/*isImplicitlyDeclared=*/false);
NewFD->setTypeSourceInfo(TInfo);
@ -3076,7 +3111,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
CheckConversionDeclarator(D, R, SC);
NewFD = CXXConversionDecl::Create(Context, cast<CXXRecordDecl>(DC),
D.getIdentifierLoc(), Name, R, TInfo,
NameInfo, R, TInfo,
isInline, isExplicit);
isVirtualOkay = true;
@ -3111,7 +3146,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
// This is a C++ method declaration.
NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(DC),
D.getIdentifierLoc(), Name, R, TInfo,
NameInfo, R, TInfo,
isStatic, SCAsWritten, isInline);
isVirtualOkay = !isStatic;
@ -3128,8 +3163,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
(!isa<FunctionType>(R.getTypePtr()) && R->isFunctionProtoType());
NewFD = FunctionDecl::Create(Context, DC,
D.getIdentifierLoc(),
Name, R, TInfo, SC, SCAsWritten, isInline,
NameInfo, R, TInfo, SC, SCAsWritten, isInline,
HasPrototype);
}
@ -3726,6 +3760,8 @@ void Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
DeclarationName Name
= Context.DeclarationNames.getCXXDestructorName(
Context.getCanonicalType(ClassType));
// NewFD->getDeclName().dump();
// Name.dump();
if (NewFD->getDeclName() != Name) {
Diag(NewFD->getLocation(), diag::err_destructor_name);
return NewFD->setInvalidDecl();

View File

@ -893,10 +893,11 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
ExprTy *BW, ExprTy *InitExpr, bool IsDefinition,
bool Deleted) {
const DeclSpec &DS = D.getDeclSpec();
DeclarationName Name = GetNameForDeclarator(D);
DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
DeclarationName Name = NameInfo.getName();
SourceLocation Loc = NameInfo.getLoc();
Expr *BitWidth = static_cast<Expr*>(BW);
Expr *Init = static_cast<Expr*>(InitExpr);
SourceLocation Loc = D.getIdentifierLoc();
assert(isa<CXXRecordDecl>(CurContext));
assert(!DS.isFriendSpecified());
@ -3476,7 +3477,7 @@ Sema::DeclPtrTy Sema::ActOnUsingDeclaration(Scope *S,
return DeclPtrTy();
}
DeclarationName TargetName = GetNameFromUnqualifiedId(Name);
DeclarationName TargetName = GetNameFromUnqualifiedId(Name).getName();
if (!TargetName)
return DeclPtrTy();
@ -4248,9 +4249,9 @@ CXXConstructorDecl *Sema::DeclareImplicitDefaultConstructor(
= Context.getCanonicalType(Context.getTypeDeclType(ClassDecl));
DeclarationName Name
= Context.DeclarationNames.getCXXConstructorName(ClassType);
DeclarationNameInfo NameInfo(Name, ClassDecl->getLocation());
CXXConstructorDecl *DefaultCon
= CXXConstructorDecl::Create(Context, ClassDecl,
ClassDecl->getLocation(), Name,
= CXXConstructorDecl::Create(Context, ClassDecl, NameInfo,
Context.getFunctionType(Context.VoidTy,
0, 0, false, 0,
ExceptSpec.hasExceptionSpecification(),
@ -4354,9 +4355,9 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(CXXRecordDecl *ClassDecl) {
= Context.getCanonicalType(Context.getTypeDeclType(ClassDecl));
DeclarationName Name
= Context.DeclarationNames.getCXXDestructorName(ClassType);
DeclarationNameInfo NameInfo(Name, ClassDecl->getLocation());
CXXDestructorDecl *Destructor
= CXXDestructorDecl::Create(Context, ClassDecl,
ClassDecl->getLocation(), Name, Ty,
= CXXDestructorDecl::Create(Context, ClassDecl, NameInfo, Ty,
/*isInline=*/true,
/*isImplicitlyDeclared=*/true);
Destructor->setAccess(AS_public);
@ -4751,8 +4752,9 @@ CXXMethodDecl *Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
// An implicitly-declared copy assignment operator is an inline public
// member of its class.
DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal);
DeclarationNameInfo NameInfo(Name, ClassDecl->getLocation());
CXXMethodDecl *CopyAssignment
= CXXMethodDecl::Create(Context, ClassDecl, ClassDecl->getLocation(), Name,
= CXXMethodDecl::Create(Context, ClassDecl, NameInfo,
Context.getFunctionType(RetType, &ArgType, 1,
false, 0,
ExceptSpec.hasExceptionSpecification(),
@ -5227,9 +5229,9 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor(
DeclarationName Name
= Context.DeclarationNames.getCXXConstructorName(
Context.getCanonicalType(ClassType));
DeclarationNameInfo NameInfo(Name, ClassDecl->getLocation());
CXXConstructorDecl *CopyConstructor
= CXXConstructorDecl::Create(Context, ClassDecl,
ClassDecl->getLocation(), Name,
= CXXConstructorDecl::Create(Context, ClassDecl, NameInfo,
Context.getFunctionType(Context.VoidTy,
&ArgType, 1,
false, 0,
@ -6305,7 +6307,8 @@ Sema::ActOnFriendFunctionDecl(Scope *S,
// namespace scope are not considered.
CXXScopeSpec &ScopeQual = D.getCXXScopeSpec();
DeclarationName Name = GetNameForDeclarator(D);
DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
DeclarationName Name = NameInfo.getName();
assert(Name);
// The context we found the declaration in, or in which we should
@ -6315,7 +6318,7 @@ Sema::ActOnFriendFunctionDecl(Scope *S,
// FIXME: handle local classes
// Recover from invalid scope qualifiers as if they just weren't there.
LookupResult Previous(*this, Name, D.getIdentifierLoc(), LookupOrdinaryName,
LookupResult Previous(*this, NameInfo, LookupOrdinaryName,
ForRedeclaration);
if (!ScopeQual.isInvalid() && ScopeQual.isSet()) {
DC = computeDeclContext(ScopeQual);

View File

@ -459,13 +459,20 @@ static bool ShouldSnapshotBlockValueReference(Sema &S, BlockScopeInfo *CurBlock,
}
/// BuildDeclRefExpr - Build a DeclRefExpr.
Sema::OwningExprResult
Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, SourceLocation Loc,
const CXXScopeSpec *SS) {
DeclarationNameInfo NameInfo(D->getDeclName(), Loc);
return BuildDeclRefExpr(D, Ty, NameInfo, SS);
}
/// BuildDeclRefExpr - Build a DeclRefExpr.
Sema::OwningExprResult
Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty,
const DeclarationNameInfo &NameInfo,
const CXXScopeSpec *SS) {
if (Context.getCanonicalType(Ty) == Context.UndeducedAutoTy) {
Diag(Loc,
Diag(NameInfo.getLoc(),
diag::err_auto_variable_cannot_appear_in_own_initializer)
<< D->getDeclName();
return ExprError();
@ -479,7 +486,8 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, SourceLocation Loc,
} else if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) {
if (const FunctionDecl *FD = MD->getParent()->isLocalClass()) {
if (VD->hasLocalStorage() && VD->getDeclContext() != CurContext) {
Diag(Loc, diag::err_reference_to_local_var_in_enclosing_function)
Diag(NameInfo.getLoc(),
diag::err_reference_to_local_var_in_enclosing_function)
<< D->getIdentifier() << FD->getDeclName();
Diag(D->getLocation(), diag::note_local_variable_declared_here)
<< D->getIdentifier();
@ -489,12 +497,12 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, SourceLocation Loc,
}
}
MarkDeclarationReferenced(Loc, D);
MarkDeclarationReferenced(NameInfo.getLoc(), D);
return Owned(DeclRefExpr::Create(Context,
SS? (NestedNameSpecifier *)SS->getScopeRep() : 0,
SS? SS->getRange() : SourceRange(),
D, Loc, Ty));
D, NameInfo, Ty));
}
/// \brief Given a field that represents a member of an anonymous
@ -639,7 +647,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
return Owned(Result);
}
/// Decomposes the given name into a DeclarationName, its location, and
/// Decomposes the given name into a DeclarationNameInfo, its location, and
/// possibly a list of template arguments.
///
/// If this produces template arguments, it is permitted to call
@ -651,8 +659,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
static void DecomposeUnqualifiedId(Sema &SemaRef,
const UnqualifiedId &Id,
TemplateArgumentListInfo &Buffer,
DeclarationName &Name,
SourceLocation &NameLoc,
DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *&TemplateArgs) {
if (Id.getKind() == UnqualifiedId::IK_TemplateId) {
Buffer.setLAngleLoc(Id.TemplateId->LAngleLoc);
@ -666,13 +673,11 @@ static void DecomposeUnqualifiedId(Sema &SemaRef,
TemplateName TName =
Sema::TemplateTy::make(Id.TemplateId->Template).getAsVal<TemplateName>();
Name = SemaRef.Context.getNameForTemplate(TName);
NameLoc = Id.TemplateId->TemplateNameLoc;
SourceLocation TNameLoc = Id.TemplateId->TemplateNameLoc;
NameInfo = SemaRef.Context.getNameForTemplate(TName, TNameLoc);
TemplateArgs = &Buffer;
} else {
Name = SemaRef.GetNameFromUnqualifiedId(Id);
NameLoc = Id.StartLocation;
NameInfo = SemaRef.GetNameFromUnqualifiedId(Id);
TemplateArgs = 0;
}
}
@ -903,8 +908,8 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
CXXDependentScopeMemberExpr *DepExpr =
CXXDependentScopeMemberExpr::Create(
Context, DepThis, DepThisType, true, SourceLocation(),
ULE->getQualifier(), ULE->getQualifierRange(), NULL, Name,
R.getNameLoc(), &TList);
ULE->getQualifier(), ULE->getQualifierRange(), NULL,
R.getLookupNameInfo(), &TList);
CallsUndergoingInstantiation.back()->setCallee(DepExpr);
} else {
Diag(R.getNameLoc(), diagnostic) << Name;
@ -1066,13 +1071,13 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S,
TemplateArgumentListInfo TemplateArgsBuffer;
// Decompose the UnqualifiedId into the following data.
DeclarationName Name;
SourceLocation NameLoc;
DeclarationNameInfo NameInfo;
const TemplateArgumentListInfo *TemplateArgs;
DecomposeUnqualifiedId(*this, Id, TemplateArgsBuffer,
Name, NameLoc, TemplateArgs);
DecomposeUnqualifiedId(*this, Id, TemplateArgsBuffer, NameInfo, TemplateArgs);
DeclarationName Name = NameInfo.getName();
IdentifierInfo *II = Name.getAsIdentifierInfo();
SourceLocation NameLoc = NameInfo.getLoc();
// C++ [temp.dep.expr]p3:
// An id-expression is type-dependent if it contains:
@ -1103,13 +1108,12 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S,
}
if (DependentID) {
return ActOnDependentIdExpression(SS, Name, NameLoc,
isAddressOfOperand,
return ActOnDependentIdExpression(SS, NameInfo, isAddressOfOperand,
TemplateArgs);
}
bool IvarLookupFollowUp = false;
// Perform the required lookup.
LookupResult R(*this, Name, NameLoc, LookupOrdinaryName);
LookupResult R(*this, NameInfo, LookupOrdinaryName);
if (TemplateArgs) {
// Lookup the template name again to correctly establish the context in
// which it was found. This is really unfortunate as we already did the
@ -1271,23 +1275,23 @@ Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
/// this path.
Sema::OwningExprResult
Sema::BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc) {
const DeclarationNameInfo &NameInfo) {
DeclContext *DC;
if (!(DC = computeDeclContext(SS, false)) || DC->isDependentContext())
return BuildDependentDeclRefExpr(SS, Name, NameLoc, 0);
return BuildDependentDeclRefExpr(SS, NameInfo, 0);
if (RequireCompleteDeclContext(SS, DC))
return ExprError();
LookupResult R(*this, Name, NameLoc, LookupOrdinaryName);
LookupResult R(*this, NameInfo, LookupOrdinaryName);
LookupQualifiedName(R, DC);
if (R.isAmbiguous())
return ExprError();
if (R.empty()) {
Diag(NameLoc, diag::err_no_member) << Name << DC << SS.getRange();
Diag(NameInfo.getLoc(), diag::err_no_member)
<< NameInfo.getName() << DC << SS.getRange();
return ExprError();
}
@ -1563,7 +1567,8 @@ Sema::PerformObjectMemberConversion(Expr *&From,
static MemberExpr *BuildMemberExpr(ASTContext &C, Expr *Base, bool isArrow,
const CXXScopeSpec &SS, ValueDecl *Member,
DeclAccessPair FoundDecl,
SourceLocation Loc, QualType Ty,
const DeclarationNameInfo &MemberNameInfo,
QualType Ty,
const TemplateArgumentListInfo *TemplateArgs = 0) {
NestedNameSpecifier *Qualifier = 0;
SourceRange QualifierRange;
@ -1573,7 +1578,8 @@ static MemberExpr *BuildMemberExpr(ASTContext &C, Expr *Base, bool isArrow,
}
return MemberExpr::Create(C, Base, isArrow, Qualifier, QualifierRange,
Member, FoundDecl, Loc, TemplateArgs, Ty);
Member, FoundDecl, MemberNameInfo,
TemplateArgs, Ty);
}
/// Builds an implicit member access expression. The current context
@ -1703,7 +1709,8 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
// If this is a single, fully-resolved result and we don't need ADL,
// just build an ordinary singleton decl ref.
if (!NeedsADL && R.isSingleResult() && !R.getAsSingle<FunctionTemplateDecl>())
return BuildDeclarationNameExpr(SS, R.getNameLoc(), R.getFoundDecl());
return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(),
R.getFoundDecl());
// We only need to check the declaration if there's exactly one
// result, because in the overloaded case the results can only be
@ -1722,8 +1729,7 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
UnresolvedLookupExpr *ULE
= UnresolvedLookupExpr::Create(Context, Dependent, R.getNamingClass(),
(NestedNameSpecifier*) SS.getScopeRep(),
SS.getRange(),
R.getLookupName(), R.getNameLoc(),
SS.getRange(), R.getLookupNameInfo(),
NeedsADL, R.isOverloadedResult(),
R.begin(), R.end());
@ -1734,11 +1740,13 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
/// \brief Complete semantic analysis for a reference to the given declaration.
Sema::OwningExprResult
Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
SourceLocation Loc, NamedDecl *D) {
const DeclarationNameInfo &NameInfo,
NamedDecl *D) {
assert(D && "Cannot refer to a NULL declaration");
assert(!isa<FunctionTemplateDecl>(D) &&
"Cannot refer unambiguously to a function template");
SourceLocation Loc = NameInfo.getLoc();
if (CheckDeclInExpr(*this, Loc, D))
return ExprError();
@ -1830,7 +1838,8 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
// If this reference is not in a block or if the referenced variable is
// within the block, create a normal DeclRefExpr.
return BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(), Loc, &SS);
return BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
NameInfo, &SS);
}
Sema::OwningExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc,
@ -2534,7 +2543,7 @@ Sema::ActOnDependentMemberExpr(ExprArg Base, QualType BaseType,
bool IsArrow, SourceLocation OpLoc,
const CXXScopeSpec &SS,
NamedDecl *FirstQualifierInScope,
DeclarationName Name, SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
Expr *BaseExpr = Base.takeAs<Expr>();
@ -2552,13 +2561,14 @@ Sema::ActOnDependentMemberExpr(ExprArg Base, QualType BaseType,
if (PT && (!getLangOptions().ObjC1 ||
PT->getPointeeType()->isRecordType())) {
assert(BaseExpr && "cannot happen with implicit member accesses");
Diag(NameLoc, diag::err_typecheck_member_reference_struct_union)
Diag(NameInfo.getLoc(), diag::err_typecheck_member_reference_struct_union)
<< BaseType << BaseExpr->getSourceRange();
return ExprError();
}
}
assert(BaseType->isDependentType() || Name.isDependentName() ||
assert(BaseType->isDependentType() ||
NameInfo.getName().isDependentName() ||
isDependentScopeSpecifier(SS));
// Get the type being accessed in BaseType. If this is an arrow, the BaseExpr
@ -2568,8 +2578,7 @@ Sema::ActOnDependentMemberExpr(ExprArg Base, QualType BaseType,
static_cast<NestedNameSpecifier*>(SS.getScopeRep()),
SS.getRange(),
FirstQualifierInScope,
Name, NameLoc,
TemplateArgs));
NameInfo, TemplateArgs));
}
/// We know that the given qualified member reference points only to
@ -2713,7 +2722,7 @@ Sema::BuildMemberReferenceExpr(ExprArg BaseArg, QualType BaseType,
SourceLocation OpLoc, bool IsArrow,
CXXScopeSpec &SS,
NamedDecl *FirstQualifierInScope,
DeclarationName Name, SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
Expr *Base = BaseArg.takeAs<Expr>();
@ -2722,10 +2731,9 @@ Sema::BuildMemberReferenceExpr(ExprArg BaseArg, QualType BaseType,
return ActOnDependentMemberExpr(ExprArg(*this, Base), BaseType,
IsArrow, OpLoc,
SS, FirstQualifierInScope,
Name, NameLoc,
TemplateArgs);
NameInfo, TemplateArgs);
LookupResult R(*this, Name, NameLoc, LookupMemberName);
LookupResult R(*this, NameInfo, LookupMemberName);
// Implicit member accesses.
if (!Base) {
@ -2777,8 +2785,9 @@ Sema::BuildMemberReferenceExpr(ExprArg Base, QualType BaseExprType,
NestedNameSpecifier *Qualifier =
static_cast<NestedNameSpecifier*>(SS.getScopeRep());
DeclarationName MemberName = R.getLookupName();
SourceLocation MemberLoc = R.getNameLoc();
const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo();
DeclarationName MemberName = MemberNameInfo.getName();
SourceLocation MemberLoc = MemberNameInfo.getLoc();
if (R.isAmbiguous())
return ExprError();
@ -2827,7 +2836,7 @@ Sema::BuildMemberReferenceExpr(ExprArg Base, QualType BaseExprType,
BaseExpr, BaseExprType,
IsArrow, OpLoc,
Qualifier, SS.getRange(),
MemberName, MemberLoc,
MemberNameInfo,
TemplateArgs, R.begin(), R.end());
return Owned(MemExpr);
@ -2849,7 +2858,7 @@ Sema::BuildMemberReferenceExpr(ExprArg Base, QualType BaseExprType,
if (!BaseExpr) {
// If this is not an instance member, convert to a non-member access.
if (!MemberDecl->isCXXInstanceMember())
return BuildDeclarationNameExpr(SS, R.getNameLoc(), MemberDecl);
return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), MemberDecl);
SourceLocation Loc = R.getNameLoc();
if (SS.getRange().isValid())
@ -2900,34 +2909,36 @@ Sema::BuildMemberReferenceExpr(ExprArg Base, QualType BaseExprType,
if (PerformObjectMemberConversion(BaseExpr, Qualifier, FoundDecl, FD))
return ExprError();
return Owned(BuildMemberExpr(Context, BaseExpr, IsArrow, SS,
FD, FoundDecl, MemberLoc, MemberType));
FD, FoundDecl, MemberNameInfo,
MemberType));
}
if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) {
MarkDeclarationReferenced(MemberLoc, Var);
return Owned(BuildMemberExpr(Context, BaseExpr, IsArrow, SS,
Var, FoundDecl, MemberLoc,
Var, FoundDecl, MemberNameInfo,
Var->getType().getNonReferenceType()));
}
if (FunctionDecl *MemberFn = dyn_cast<FunctionDecl>(MemberDecl)) {
MarkDeclarationReferenced(MemberLoc, MemberDecl);
return Owned(BuildMemberExpr(Context, BaseExpr, IsArrow, SS,
MemberFn, FoundDecl, MemberLoc,
MemberFn, FoundDecl, MemberNameInfo,
MemberFn->getType()));
}
if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) {
MarkDeclarationReferenced(MemberLoc, MemberDecl);
return Owned(BuildMemberExpr(Context, BaseExpr, IsArrow, SS,
Enum, FoundDecl, MemberLoc, Enum->getType()));
Enum, FoundDecl, MemberNameInfo,
Enum->getType()));
}
Owned(BaseExpr);
// We found something that we didn't expect. Complain.
if (isa<TypeDecl>(MemberDecl))
Diag(MemberLoc,diag::err_typecheck_member_reference_type)
Diag(MemberLoc, diag::err_typecheck_member_reference_type)
<< MemberName << BaseType << int(IsArrow);
else
Diag(MemberLoc, diag::err_typecheck_member_reference_unknown)
@ -3310,12 +3321,12 @@ Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, ExprArg BaseArg,
TemplateArgumentListInfo TemplateArgsBuffer;
// Decompose the name into its component parts.
DeclarationName Name;
SourceLocation NameLoc;
DeclarationNameInfo NameInfo;
const TemplateArgumentListInfo *TemplateArgs;
DecomposeUnqualifiedId(*this, Id, TemplateArgsBuffer,
Name, NameLoc, TemplateArgs);
NameInfo, TemplateArgs);
DeclarationName Name = NameInfo.getName();
bool IsArrow = (OpKind == tok::arrow);
NamedDecl *FirstQualifierInScope
@ -3332,10 +3343,9 @@ Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, ExprArg BaseArg,
Result = ActOnDependentMemberExpr(ExprArg(*this, Base), Base->getType(),
IsArrow, OpLoc,
SS, FirstQualifierInScope,
Name, NameLoc,
TemplateArgs);
NameInfo, TemplateArgs);
} else {
LookupResult R(*this, Name, NameLoc, LookupMemberName);
LookupResult R(*this, NameInfo, LookupMemberName);
Result = LookupMemberExpr(R, Base, IsArrow, OpLoc,
SS, ObjCImpDecl, TemplateArgs != 0);
@ -3351,7 +3361,7 @@ Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, ExprArg BaseArg,
// call now.
if (!HasTrailingLParen &&
Id.getKind() == UnqualifiedId::IK_DestructorName)
return DiagnoseDtorReference(NameLoc, move(Result));
return DiagnoseDtorReference(NameInfo.getLoc(), move(Result));
return move(Result);
}

View File

@ -3041,7 +3041,7 @@ CXXMemberCallExpr *Sema::BuildCXXMemberCallExpr(Expr *Exp,
assert(0 && "Calling BuildCXXMemberCallExpr with invalid call?");
MemberExpr *ME =
new (Context) MemberExpr(Exp, /*IsArrow=*/false, Method,
new (Context) MemberExpr(Exp, /*IsArrow=*/false, Method,
SourceLocation(), Method->getType());
QualType ResultType = Method->getCallResultType();
MarkDeclarationReferenced(Exp->getLocStart(), Method);

View File

@ -267,7 +267,7 @@ void LookupResult::configure() {
// operators, make sure that the implicitly-declared new and delete
// operators can be found.
if (!isForRedeclaration()) {
switch (Name.getCXXOverloadedOperator()) {
switch (NameInfo.getName().getCXXOverloadedOperator()) {
case OO_New:
case OO_Delete:
case OO_Array_New:

View File

@ -6645,6 +6645,8 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn,
OverloadedOperatorKind Op = UnaryOperator::getOverloadedOperator(Opc);
assert(Op != OO_None && "Invalid opcode for overloaded unary operator");
DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op);
// TODO: provide better source location info.
DeclarationNameInfo OpNameInfo(OpName, OpLoc);
Expr *Args[2] = { Input, 0 };
unsigned NumArgs = 1;
@ -6669,7 +6671,7 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn,
CXXRecordDecl *NamingClass = 0; // because lookup ignores member operators
UnresolvedLookupExpr *Fn
= UnresolvedLookupExpr::Create(Context, /*Dependent*/ true, NamingClass,
0, SourceRange(), OpName, OpLoc,
0, SourceRange(), OpNameInfo,
/*ADL*/ true, IsOverloaded(Fns),
Fns.begin(), Fns.end());
input.release();
@ -6839,9 +6841,11 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
// FIXME: save results of ADL from here?
CXXRecordDecl *NamingClass = 0; // because lookup ignores member operators
// TODO: provide better source location info in DNLoc component.
DeclarationNameInfo OpNameInfo(OpName, OpLoc);
UnresolvedLookupExpr *Fn
= UnresolvedLookupExpr::Create(Context, /*Dependent*/ true, NamingClass,
0, SourceRange(), OpName, OpLoc,
0, SourceRange(), OpNameInfo,
/*ADL*/ true, IsOverloaded(Fns),
Fns.begin(), Fns.end());
return Owned(new (Context) CXXOperatorCallExpr(Context, Op, Fn,
@ -7036,9 +7040,12 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
if (Args[0]->isTypeDependent() || Args[1]->isTypeDependent()) {
CXXRecordDecl *NamingClass = 0; // because lookup ignores member operators
// CHECKME: no 'operator' keyword?
DeclarationNameInfo OpNameInfo(OpName, LLoc);
OpNameInfo.setCXXOperatorNameRange(SourceRange(LLoc, RLoc));
UnresolvedLookupExpr *Fn
= UnresolvedLookupExpr::Create(Context, /*Dependent*/ true, NamingClass,
0, SourceRange(), OpName, LLoc,
0, SourceRange(), OpNameInfo,
/*ADL*/ true, /*Overloaded*/ false,
UnresolvedSetIterator(),
UnresolvedSetIterator());
@ -7790,7 +7797,7 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found,
MemExpr->getQualifierRange(),
Fn,
Found,
MemExpr->getMemberLoc(),
MemExpr->getMemberNameInfo(),
TemplateArgs,
Fn->getType());
}

View File

@ -334,8 +334,7 @@ void Sema::LookupTemplateName(LookupResult &Found,
/// specifier naming a dependent type.
Sema::OwningExprResult
Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
bool isAddressOfOperand,
const TemplateArgumentListInfo *TemplateArgs) {
NestedNameSpecifier *Qualifier
@ -358,22 +357,21 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
/*Op*/ SourceLocation(),
Qualifier, SS.getRange(),
FirstQualifierInScope,
Name, NameLoc,
NameInfo,
TemplateArgs));
}
return BuildDependentDeclRefExpr(SS, Name, NameLoc, TemplateArgs);
return BuildDependentDeclRefExpr(SS, NameInfo, TemplateArgs);
}
Sema::OwningExprResult
Sema::BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
return Owned(DependentScopeDeclRefExpr::Create(Context,
static_cast<NestedNameSpecifier*>(SS.getScopeRep()),
SS.getRange(),
Name, NameLoc,
NameInfo,
TemplateArgs));
}
@ -1598,7 +1596,7 @@ Sema::OwningExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,
UnresolvedLookupExpr *ULE
= UnresolvedLookupExpr::Create(Context, Dependent, R.getNamingClass(),
Qualifier, QualifierRange,
R.getLookupName(), R.getNameLoc(),
R.getLookupNameInfo(),
RequiresADL, TemplateArgs,
R.begin(), R.end());
@ -1608,17 +1606,16 @@ Sema::OwningExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,
// We actually only call this from template instantiation.
Sema::OwningExprResult
Sema::BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
DeclarationName Name,
SourceLocation NameLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo &TemplateArgs) {
DeclContext *DC;
if (!(DC = computeDeclContext(SS, false)) ||
DC->isDependentContext() ||
RequireCompleteDeclContext(SS, DC))
return BuildDependentDeclRefExpr(SS, Name, NameLoc, &TemplateArgs);
return BuildDependentDeclRefExpr(SS, NameInfo, &TemplateArgs);
bool MemberOfUnknownSpecialization;
LookupResult R(*this, Name, NameLoc, LookupOrdinaryName);
LookupResult R(*this, NameInfo, LookupOrdinaryName);
LookupTemplateName(R, (Scope*) 0, SS, QualType(), /*Entering*/ false,
MemberOfUnknownSpecialization);
@ -1626,14 +1623,15 @@ Sema::BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
return ExprError();
if (R.empty()) {
Diag(NameLoc, diag::err_template_kw_refers_to_non_template)
<< Name << SS.getRange();
Diag(NameInfo.getLoc(), diag::err_template_kw_refers_to_non_template)
<< NameInfo.getName() << SS.getRange();
return ExprError();
}
if (ClassTemplateDecl *Temp = R.getAsSingle<ClassTemplateDecl>()) {
Diag(NameLoc, diag::err_template_kw_refers_to_class_template)
<< (NestedNameSpecifier*) SS.getScopeRep() << Name << SS.getRange();
Diag(NameInfo.getLoc(), diag::err_template_kw_refers_to_class_template)
<< (NestedNameSpecifier*) SS.getScopeRep()
<< NameInfo.getName() << SS.getRange();
Diag(Temp->getLocation(), diag::note_referenced_class_template);
return ExprError();
}
@ -1693,7 +1691,7 @@ TemplateNameKind Sema::ActOnDependentTemplateName(Scope *S,
} else if (TNK == TNK_Non_template) {
Diag(Name.getSourceRange().getBegin(),
diag::err_template_kw_refers_to_non_template)
<< GetNameFromUnqualifiedId(Name)
<< GetNameFromUnqualifiedId(Name).getName()
<< Name.getSourceRange()
<< TemplateKWLoc;
return TNK_Non_template;
@ -1726,7 +1724,7 @@ TemplateNameKind Sema::ActOnDependentTemplateName(Scope *S,
Diag(Name.getSourceRange().getBegin(),
diag::err_template_kw_refers_to_non_template)
<< GetNameFromUnqualifiedId(Name)
<< GetNameFromUnqualifiedId(Name).getName()
<< Name.getSourceRange()
<< TemplateKWLoc;
return TNK_Non_template;
@ -2047,12 +2045,15 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param,
// We have a template argument such as \c T::template X, which we
// parsed as a template template argument. However, since we now
// know that we need a non-type template argument, convert this
// template name into an expression.
// template name into an expression.
DeclarationNameInfo NameInfo(DTN->getIdentifier(),
Arg.getTemplateNameLoc());
Expr *E = DependentScopeDeclRefExpr::Create(Context,
DTN->getQualifier(),
Arg.getTemplateQualifierRange(),
DTN->getIdentifier(),
Arg.getTemplateNameLoc());
NameInfo);
TemplateArgument Result;
if (CheckTemplateArgument(NTTP, NTTPType, E, Result))
@ -4938,7 +4939,9 @@ Sema::DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
SourceLocation TemplateLoc,
Declarator &D) {
// Explicit instantiations always require a name.
DeclarationName Name = GetNameForDeclarator(D);
// TODO: check if/when DNInfo should replace Name.
DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
DeclarationName Name = NameInfo.getName();
if (!Name) {
if (!D.isInvalidType())
Diag(D.getDeclSpec().getSourceRange().getBegin(),
@ -4988,7 +4991,7 @@ Sema::DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
= ExternLoc.isInvalid()? TSK_ExplicitInstantiationDefinition
: TSK_ExplicitInstantiationDeclaration;
LookupResult Previous(*this, Name, D.getIdentifierLoc(), LookupOrdinaryName);
LookupResult Previous(*this, NameInfo, LookupOrdinaryName);
LookupParsedName(Previous, S, &D.getCXXScopeSpec());
if (!R->isFunctionType()) {

View File

@ -1611,6 +1611,15 @@ Sema::SubstNestedNameSpecifier(NestedNameSpecifier *NNS,
return Instantiator.TransformNestedNameSpecifier(NNS, Range);
}
/// \brief Do template substitution on declaration name info.
DeclarationNameInfo
Sema::SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
const MultiLevelTemplateArgumentList &TemplateArgs) {
TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(),
NameInfo.getName());
return Instantiator.TransformDeclarationNameInfo(NameInfo);
}
TemplateName
Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc,
const MultiLevelTemplateArgumentList &TemplateArgs) {

View File

@ -1294,39 +1294,27 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
CXXRecordDecl *Record = cast<CXXRecordDecl>(DC);
CXXMethodDecl *Method = 0;
DeclarationName Name = D->getDeclName();
DeclarationNameInfo NameInfo
= SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
QualType ClassTy = SemaRef.Context.getTypeDeclType(Record);
Name = SemaRef.Context.DeclarationNames.getCXXConstructorName(
SemaRef.Context.getCanonicalType(ClassTy));
Method = CXXConstructorDecl::Create(SemaRef.Context, Record,
Constructor->getLocation(),
Name, T, TInfo,
NameInfo, T, TInfo,
Constructor->isExplicit(),
Constructor->isInlineSpecified(),
false);
} else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) {
QualType ClassTy = SemaRef.Context.getTypeDeclType(Record);
Name = SemaRef.Context.DeclarationNames.getCXXDestructorName(
SemaRef.Context.getCanonicalType(ClassTy));
Method = CXXDestructorDecl::Create(SemaRef.Context, Record,
Destructor->getLocation(), Name,
T, Destructor->isInlineSpecified(),
NameInfo, T,
Destructor->isInlineSpecified(),
false);
} else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) {
CanQualType ConvTy
= SemaRef.Context.getCanonicalType(
T->getAs<FunctionType>()->getResultType());
Name = SemaRef.Context.DeclarationNames.getCXXConversionFunctionName(
ConvTy);
Method = CXXConversionDecl::Create(SemaRef.Context, Record,
Conversion->getLocation(), Name,
T, TInfo,
NameInfo, T, TInfo,
Conversion->isInlineSpecified(),
Conversion->isExplicit());
} else {
Method = CXXMethodDecl::Create(SemaRef.Context, Record, D->getLocation(),
D->getDeclName(), T, TInfo,
Method = CXXMethodDecl::Create(SemaRef.Context, Record,
NameInfo, T, TInfo,
D->isStatic(),
D->getStorageClassAsWritten(),
D->isInlineSpecified());
@ -1390,8 +1378,8 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
if (InitMethodInstantiation(Method, D))
Method->setInvalidDecl();
LookupResult Previous(SemaRef, Name, SourceLocation(),
Sema::LookupOrdinaryName, Sema::ForRedeclaration);
LookupResult Previous(SemaRef, NameInfo, Sema::LookupOrdinaryName,
Sema::ForRedeclaration);
if (!FunctionTemplate || TemplateParams || isFriend) {
SemaRef.LookupQualifiedName(Previous, Record);

View File

@ -276,9 +276,9 @@ public:
/// and destructor names and then (if needed) rebuilds the declaration name.
/// Identifiers and selectors are returned unmodified. Sublcasses may
/// override this function to provide alternate behavior.
DeclarationName TransformDeclarationName(DeclarationName Name,
SourceLocation Loc,
QualType ObjectType = QualType());
DeclarationNameInfo
TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
QualType ObjectType = QualType());
/// \brief Transform the given template name.
///
@ -1032,15 +1032,16 @@ public:
/// Subclasses may override this routine to provide different behavior.
OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
ValueDecl *VD, SourceLocation Loc,
ValueDecl *VD,
const DeclarationNameInfo &NameInfo,
TemplateArgumentListInfo *TemplateArgs) {
CXXScopeSpec SS;
SS.setScopeRep(Qualifier);
SS.setRange(QualifierRange);
// FIXME: loses template args.
return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
}
/// \brief Build a new expression in parentheses.
@ -1149,7 +1150,7 @@ public:
bool isArrow,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
SourceLocation MemberLoc,
const DeclarationNameInfo &MemberNameInfo,
ValueDecl *Member,
NamedDecl *FoundDecl,
const TemplateArgumentListInfo *ExplicitTemplateArgs,
@ -1165,7 +1166,7 @@ public:
MemberExpr *ME =
new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Member, MemberLoc,
Member, MemberNameInfo,
cast<FieldDecl>(Member)->getType());
return getSema().Owned(ME);
}
@ -1182,8 +1183,7 @@ public:
// FIXME: this involves duplicating earlier analysis in a lot of
// cases; we should avoid this when possible.
LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
Sema::LookupMemberName);
LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
R.addDecl(FoundDecl);
R.resolveKind();
@ -1252,11 +1252,11 @@ public:
CXXScopeSpec SS;
QualType BaseType = ((Expr*) Base.get())->getType();
DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
OpLoc, /*IsArrow*/ false,
SS, /*FirstQualifierInScope*/ 0,
DeclarationName(&Accessor),
AccessorLoc,
NameInfo,
/* TemplateArgs */ 0);
}
@ -1654,18 +1654,17 @@ public:
/// Subclasses may override this routine to provide different behavior.
OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
SourceRange QualifierRange,
DeclarationName Name,
SourceLocation Location,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
CXXScopeSpec SS;
SS.setRange(QualifierRange);
SS.setScopeRep(NNS);
if (TemplateArgs)
return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
*TemplateArgs);
return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
}
/// \brief Build a new template-id expression.
@ -1745,8 +1744,7 @@ public:
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NamedDecl *FirstQualifierInScope,
DeclarationName Name,
SourceLocation MemberLoc,
const DeclarationNameInfo &MemberNameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
CXXScopeSpec SS;
SS.setRange(QualifierRange);
@ -1755,7 +1753,8 @@ public:
return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
OperatorLoc, IsArrow,
SS, FirstQualifierInScope,
Name, MemberLoc, TemplateArgs);
MemberNameInfo,
TemplateArgs);
}
/// \brief Build a new member reference expression.
@ -2098,12 +2097,13 @@ TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
}
template<typename Derived>
DeclarationName
TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
SourceLocation Loc,
QualType ObjectType) {
DeclarationNameInfo
TreeTransform<Derived>
::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
QualType ObjectType) {
DeclarationName Name = NameInfo.getName();
if (!Name)
return Name;
return DeclarationNameInfo();
switch (Name.getNameKind()) {
case DeclarationName::Identifier:
@ -2113,24 +2113,41 @@ TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
case DeclarationName::CXXOperatorName:
case DeclarationName::CXXLiteralOperatorName:
case DeclarationName::CXXUsingDirective:
return Name;
return NameInfo;
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName: {
TemporaryBase Rebase(*this, Loc, Name);
QualType T = getDerived().TransformType(Name.getCXXNameType(),
ObjectType);
if (T.isNull())
return DeclarationName();
TypeSourceInfo *NewTInfo;
CanQualType NewCanTy;
if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
if (!NewTInfo)
return DeclarationNameInfo();
NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
}
else {
NewTInfo = 0;
TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
ObjectType);
if (NewT.isNull())
return DeclarationNameInfo();
NewCanTy = SemaRef.Context.getCanonicalType(NewT);
}
return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Name.getNameKind(),
SemaRef.Context.getCanonicalType(T));
DeclarationName NewName
= SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
NewCanTy);
DeclarationNameInfo NewNameInfo(NameInfo);
NewNameInfo.setName(NewName);
NewNameInfo.setNamedTypeInfo(NewTInfo);
return NewNameInfo;
}
}
return DeclarationName();
assert(0 && "Unknown name kind.");
return DeclarationNameInfo();
}
template<typename Derived>
@ -4197,9 +4214,15 @@ TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
if (!ND)
return SemaRef.ExprError();
if (!getDerived().AlwaysRebuild() &&
DeclarationNameInfo NameInfo
= getDerived().TransformDeclarationNameInfo(E->getNameInfo());
if (!NameInfo.getName())
return SemaRef.ExprError();
if (!getDerived().AlwaysRebuild() &&
Qualifier == E->getQualifier() &&
ND == E->getDecl() &&
NameInfo.getName() == E->getDecl()->getDeclName() &&
!E->hasExplicitTemplateArgumentList()) {
// Mark it referenced in the new context regardless.
@ -4223,7 +4246,7 @@ TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
}
return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
ND, E->getLocation(), TemplateArgs);
ND, NameInfo, TemplateArgs);
}
template<typename Derived>
@ -4522,7 +4545,7 @@ TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
E->isArrow(),
Qualifier,
E->getQualifierRange(),
E->getMemberLoc(),
E->getMemberNameInfo(),
Member,
FoundDecl,
(E->hasExplicitTemplateArgumentList()
@ -5573,27 +5596,29 @@ TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
template<typename Derived>
Sema::OwningExprResult
TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
DependentScopeDeclRefExpr *E) {
DependentScopeDeclRefExpr *E) {
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
E->getQualifierRange());
if (!NNS)
return SemaRef.ExprError();
DeclarationName Name
= getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
if (!Name)
DeclarationNameInfo NameInfo
= getDerived().TransformDeclarationNameInfo(E->getNameInfo());
if (!NameInfo.getName())
return SemaRef.ExprError();
if (!E->hasExplicitTemplateArgs()) {
if (!getDerived().AlwaysRebuild() &&
NNS == E->getQualifier() &&
Name == E->getDeclName())
// Note: it is sufficient to compare the Name component of NameInfo:
// if name has not changed, DNLoc has not changed either.
NameInfo.getName() == E->getDeclName())
return SemaRef.Owned(E->Retain());
return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
E->getQualifierRange(),
Name, E->getLocation(),
NameInfo,
/*TemplateArgs*/ 0);
}
@ -5607,7 +5632,7 @@ TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
E->getQualifierRange(),
Name, E->getLocation(),
NameInfo,
&TransArgs);
}
@ -5799,7 +5824,7 @@ TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
template<typename Derived>
Sema::OwningExprResult
TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
CXXDependentScopeMemberExpr *E) {
CXXDependentScopeMemberExpr *E) {
// Transform the base of the expression.
OwningExprResult Base(SemaRef, (Expr*) 0);
Expr *OldBase;
@ -5847,10 +5872,10 @@ TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
return SemaRef.ExprError();
}
DeclarationName Name
= getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
ObjectType);
if (!Name)
DeclarationNameInfo NameInfo
= getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
ObjectType);
if (!NameInfo.getName())
return SemaRef.ExprError();
if (!E->hasExplicitTemplateArgs()) {
@ -5860,7 +5885,7 @@ TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Base.get() == OldBase &&
BaseType == E->getBaseType() &&
Qualifier == E->getQualifier() &&
Name == E->getMember() &&
NameInfo.getName() == E->getMember() &&
FirstQualifierInScope == E->getFirstQualifierFoundInScope())
return SemaRef.Owned(E->Retain());
@ -5871,8 +5896,7 @@ TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Qualifier,
E->getQualifierRange(),
FirstQualifierInScope,
Name,
E->getMemberLoc(),
NameInfo,
/*TemplateArgs*/ 0);
}
@ -5891,8 +5915,7 @@ TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Qualifier,
E->getQualifierRange(),
FirstQualifierInScope,
Name,
E->getMemberLoc(),
NameInfo,
&TransArgs);
}
@ -5920,7 +5943,7 @@ TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old)
return SemaRef.ExprError();
}
LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
LookupResult R(SemaRef, Old->getMemberNameInfo(),
Sema::LookupOrdinaryName);
// Transform all the decls.
@ -6265,7 +6288,7 @@ TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
E->getDecl()));
if (!ND)
return SemaRef.ExprError();
if (!getDerived().AlwaysRebuild() &&
ND == E->getDecl()) {
// Mark it referenced in the new context regardless.
@ -6275,8 +6298,9 @@ TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
return SemaRef.Owned(E->Retain());
}
DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
ND, E->getLocation(), 0);
ND, NameInfo, 0);
}
//===----------------------------------------------------------------------===//
@ -6708,18 +6732,19 @@ TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
Destroyed,
/*FIXME?*/true);
}
TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
DeclarationName Name
= SemaRef.Context.DeclarationNames.getCXXDestructorName(
SemaRef.Context.getCanonicalType(DestroyedType->getType()));
DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
SemaRef.Context.getCanonicalType(DestroyedType->getType())));
DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
NameInfo.setNamedTypeInfo(DestroyedType);
// FIXME: the ScopeType should be tacked onto SS.
return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
OperatorLoc, isArrow,
SS, /*FIXME: FirstQualifier*/ 0,
Name, Destroyed.getLocation(),
NameInfo,
/*TemplateArgs*/ 0);
}