зеркало из https://github.com/microsoft/clang-1.git
Transition the last acceptable-result filter kind in LookupResult over to use
a simple IDNS mask by introducing a namespace for non-member operators. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102215 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
14b9162896
Коммит
f88b0d6c99
|
@ -132,7 +132,12 @@ public:
|
||||||
/// *introduces* a number of other declarations into the current
|
/// *introduces* a number of other declarations into the current
|
||||||
/// scope, and those declarations use the IDNS of their targets,
|
/// scope, and those declarations use the IDNS of their targets,
|
||||||
/// but the actual using declarations go in this namespace.
|
/// but the actual using declarations go in this namespace.
|
||||||
IDNS_Using = 0x0200
|
IDNS_Using = 0x0200,
|
||||||
|
|
||||||
|
/// This declaration is a C++ operator declared in a non-class
|
||||||
|
/// context. All such operators are also in IDNS_Ordinary.
|
||||||
|
/// C++ lexical operator lookup looks for these.
|
||||||
|
IDNS_NonMemberOperator = 0x0400
|
||||||
};
|
};
|
||||||
|
|
||||||
/// ObjCDeclQualifier - Qualifier used on types in method declarations
|
/// ObjCDeclQualifier - Qualifier used on types in method declarations
|
||||||
|
@ -533,6 +538,14 @@ public:
|
||||||
FOK_Declared : FOK_Undeclared);
|
FOK_Declared : FOK_Undeclared);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specifies that this declaration is a C++ overloaded non-member.
|
||||||
|
void setNonMemberOperator() {
|
||||||
|
assert(getKind() == Function || getKind() == FunctionTemplate);
|
||||||
|
assert((IdentifierNamespace & IDNS_Ordinary) &&
|
||||||
|
"visible non-member operators should be in ordinary namespace");
|
||||||
|
IdentifierNamespace |= IDNS_NonMemberOperator;
|
||||||
|
}
|
||||||
|
|
||||||
// Implement isa/cast/dyncast/etc.
|
// Implement isa/cast/dyncast/etc.
|
||||||
static bool classof(const Decl *) { return true; }
|
static bool classof(const Decl *) { return true; }
|
||||||
static bool classofKind(Kind K) { return true; }
|
static bool classofKind(Kind K) { return true; }
|
||||||
|
|
|
@ -197,6 +197,11 @@ void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
|
||||||
for (unsigned I = 0; I != NumParams; ++I)
|
for (unsigned I = 0; I != NumParams; ++I)
|
||||||
Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
|
Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
|
||||||
FD->setParams(Params.data(), NumParams);
|
FD->setParams(Params.data(), NumParams);
|
||||||
|
|
||||||
|
// FIXME: order this properly w.r.t. friendness
|
||||||
|
// FIXME: this same thing needs to happen for function templates
|
||||||
|
if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
|
||||||
|
FD->setNonMemberOperator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
|
void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
|
||||||
|
|
|
@ -124,7 +124,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef UnresolvedSetImpl::iterator iterator;
|
typedef UnresolvedSetImpl::iterator iterator;
|
||||||
typedef bool (*ResultFilter)(NamedDecl*, unsigned IDNS);
|
|
||||||
|
|
||||||
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc,
|
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc,
|
||||||
Sema::LookupNameKind LookupKind,
|
Sema::LookupNameKind LookupKind,
|
||||||
|
@ -136,7 +135,6 @@ public:
|
||||||
Name(Name),
|
Name(Name),
|
||||||
NameLoc(NameLoc),
|
NameLoc(NameLoc),
|
||||||
LookupKind(LookupKind),
|
LookupKind(LookupKind),
|
||||||
IsAcceptableFn(0),
|
|
||||||
IDNS(0),
|
IDNS(0),
|
||||||
Redecl(Redecl != Sema::NotForRedeclaration),
|
Redecl(Redecl != Sema::NotForRedeclaration),
|
||||||
HideTags(true),
|
HideTags(true),
|
||||||
|
@ -156,7 +154,6 @@ public:
|
||||||
Name(Other.Name),
|
Name(Other.Name),
|
||||||
NameLoc(Other.NameLoc),
|
NameLoc(Other.NameLoc),
|
||||||
LookupKind(Other.LookupKind),
|
LookupKind(Other.LookupKind),
|
||||||
IsAcceptableFn(Other.IsAcceptableFn),
|
|
||||||
IDNS(Other.IDNS),
|
IDNS(Other.IDNS),
|
||||||
Redecl(Other.Redecl),
|
Redecl(Other.Redecl),
|
||||||
HideTags(Other.HideTags),
|
HideTags(Other.HideTags),
|
||||||
|
@ -242,8 +239,7 @@ public:
|
||||||
|
|
||||||
/// \brief Tests whether the given declaration is acceptable.
|
/// \brief Tests whether the given declaration is acceptable.
|
||||||
bool isAcceptableDecl(NamedDecl *D) const {
|
bool isAcceptableDecl(NamedDecl *D) const {
|
||||||
assert(IsAcceptableFn);
|
return D->isInIdentifierNamespace(IDNS);
|
||||||
return IsAcceptableFn(D, IDNS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Returns the identifier namespace mask for this lookup.
|
/// \brief Returns the identifier namespace mask for this lookup.
|
||||||
|
@ -575,7 +571,6 @@ private:
|
||||||
SourceLocation NameLoc;
|
SourceLocation NameLoc;
|
||||||
SourceRange NameContextRange;
|
SourceRange NameContextRange;
|
||||||
Sema::LookupNameKind LookupKind;
|
Sema::LookupNameKind LookupKind;
|
||||||
ResultFilter IsAcceptableFn; // set by configure()
|
|
||||||
unsigned IDNS; // set by configure()
|
unsigned IDNS; // set by configure()
|
||||||
|
|
||||||
bool Redecl;
|
bool Redecl;
|
||||||
|
|
|
@ -3269,6 +3269,12 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
|
||||||
NewFD->setAccess(Access);
|
NewFD->setAccess(Access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NewFD->isOverloadedOperator() && !DC->isRecord() &&
|
||||||
|
NewFD->isInIdentifierNamespace(Decl::IDNS_Ordinary)) {
|
||||||
|
NewFD->setNonMemberOperator();
|
||||||
|
if (FunctionTemplate) FunctionTemplate->setNonMemberOperator();
|
||||||
|
}
|
||||||
|
|
||||||
// If we have a function template, check the template parameter
|
// If we have a function template, check the template parameter
|
||||||
// list. This will check and merge default template arguments.
|
// list. This will check and merge default template arguments.
|
||||||
if (FunctionTemplate) {
|
if (FunctionTemplate) {
|
||||||
|
|
|
@ -193,37 +193,6 @@ namespace {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsAcceptableIDNS(NamedDecl *D, unsigned IDNS) {
|
|
||||||
return D->isInIdentifierNamespace(IDNS);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsAcceptableOperatorName(NamedDecl *D, unsigned IDNS) {
|
|
||||||
return D->isInIdentifierNamespace(IDNS) &&
|
|
||||||
!D->getDeclContext()->isRecord();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the default result filter for the given lookup.
|
|
||||||
static inline
|
|
||||||
LookupResult::ResultFilter getResultFilter(Sema::LookupNameKind NameKind) {
|
|
||||||
switch (NameKind) {
|
|
||||||
case Sema::LookupOrdinaryName:
|
|
||||||
case Sema::LookupTagName:
|
|
||||||
case Sema::LookupMemberName:
|
|
||||||
case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
|
|
||||||
case Sema::LookupUsingDeclName:
|
|
||||||
case Sema::LookupObjCProtocolName:
|
|
||||||
case Sema::LookupNestedNameSpecifierName:
|
|
||||||
case Sema::LookupNamespaceName:
|
|
||||||
return &IsAcceptableIDNS;
|
|
||||||
|
|
||||||
case Sema::LookupOperatorName:
|
|
||||||
return &IsAcceptableOperatorName;
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm_unreachable("unkknown lookup kind");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve the set of identifier namespaces that correspond to a
|
// Retrieve the set of identifier namespaces that correspond to a
|
||||||
// specific kind of name lookup.
|
// specific kind of name lookup.
|
||||||
static inline unsigned getIDNS(Sema::LookupNameKind NameKind,
|
static inline unsigned getIDNS(Sema::LookupNameKind NameKind,
|
||||||
|
@ -232,7 +201,6 @@ static inline unsigned getIDNS(Sema::LookupNameKind NameKind,
|
||||||
unsigned IDNS = 0;
|
unsigned IDNS = 0;
|
||||||
switch (NameKind) {
|
switch (NameKind) {
|
||||||
case Sema::LookupOrdinaryName:
|
case Sema::LookupOrdinaryName:
|
||||||
case Sema::LookupOperatorName:
|
|
||||||
case Sema::LookupRedeclarationWithLinkage:
|
case Sema::LookupRedeclarationWithLinkage:
|
||||||
IDNS = Decl::IDNS_Ordinary;
|
IDNS = Decl::IDNS_Ordinary;
|
||||||
if (CPlusPlus) {
|
if (CPlusPlus) {
|
||||||
|
@ -241,6 +209,13 @@ static inline unsigned getIDNS(Sema::LookupNameKind NameKind,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Sema::LookupOperatorName:
|
||||||
|
// Operator lookup is its own crazy thing; it is not the same
|
||||||
|
// as (e.g.) looking up an operator name for redeclaration.
|
||||||
|
assert(!Redeclaration && "cannot do redeclaration operator lookup");
|
||||||
|
IDNS = Decl::IDNS_NonMemberOperator;
|
||||||
|
break;
|
||||||
|
|
||||||
case Sema::LookupTagName:
|
case Sema::LookupTagName:
|
||||||
if (CPlusPlus) {
|
if (CPlusPlus) {
|
||||||
IDNS = Decl::IDNS_Type;
|
IDNS = Decl::IDNS_Type;
|
||||||
|
@ -287,7 +262,6 @@ void LookupResult::configure() {
|
||||||
IDNS = getIDNS(LookupKind,
|
IDNS = getIDNS(LookupKind,
|
||||||
SemaRef.getLangOptions().CPlusPlus,
|
SemaRef.getLangOptions().CPlusPlus,
|
||||||
isForRedeclaration());
|
isForRedeclaration());
|
||||||
IsAcceptableFn = getResultFilter(LookupKind);
|
|
||||||
|
|
||||||
// If we're looking for one of the allocation or deallocation
|
// If we're looking for one of the allocation or deallocation
|
||||||
// operators, make sure that the implicitly-declared new and delete
|
// operators, make sure that the implicitly-declared new and delete
|
||||||
|
|
|
@ -1140,6 +1140,12 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
|
||||||
DC->makeDeclVisibleInContext(ToFriendD, /*Recoverable=*/ false);
|
DC->makeDeclVisibleInContext(ToFriendD, /*Recoverable=*/ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Function->isOverloadedOperator() && !DC->isRecord() &&
|
||||||
|
Function->isInIdentifierNamespace(Decl::IDNS_Ordinary)) {
|
||||||
|
Function->setNonMemberOperator();
|
||||||
|
if (FunctionTemplate) FunctionTemplate->setNonMemberOperator();
|
||||||
|
}
|
||||||
|
|
||||||
return Function;
|
return Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче