2008-11-17 22:58:09 +08:00
|
|
|
//===-- DeclarationName.cpp - Declaration names implementation --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the DeclarationName and DeclarationNameTable
|
|
|
|
// classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "clang/AST/DeclarationName.h"
|
2010-05-11 04:40:08 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2016-02-15 09:32:36 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2017-02-07 09:37:30 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2008-11-18 06:58:34 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2010-08-12 06:01:17 +08:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2009-11-05 06:24:30 +08:00
|
|
|
#include "clang/AST/TypeOrdering.h"
|
2008-11-17 22:58:09 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2010-12-15 15:29:18 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-04-17 17:56:45 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-11-17 22:58:09 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
/// CXXSpecialName - Records the type associated with one of the
|
|
|
|
/// "special" kinds of declaration names in C++, e.g., constructors,
|
|
|
|
/// destructors, and conversion functions.
|
2009-09-09 23:08:12 +08:00
|
|
|
class CXXSpecialName
|
2008-11-17 22:58:09 +08:00
|
|
|
: public DeclarationNameExtra, public llvm::FoldingSetNode {
|
|
|
|
public:
|
2008-11-18 04:34:05 +08:00
|
|
|
/// Type - The type associated with this declaration name.
|
2008-11-17 22:58:09 +08:00
|
|
|
QualType Type;
|
|
|
|
|
2008-11-18 04:34:05 +08:00
|
|
|
/// FETokenInfo - Extra information associated with this declaration
|
|
|
|
/// name that can be used by the front end.
|
|
|
|
void *FETokenInfo;
|
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) {
|
|
|
|
ID.AddInteger(ExtraKindOrNumArgs);
|
|
|
|
ID.AddPointer(Type.getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
/// Contains extra information for the name of a C++ deduction guide.
|
|
|
|
class CXXDeductionGuideNameExtra : public DeclarationNameExtra,
|
|
|
|
public llvm::FoldingSetNode {
|
|
|
|
public:
|
|
|
|
/// The template named by the deduction guide.
|
|
|
|
TemplateDecl *Template;
|
|
|
|
|
|
|
|
/// FETokenInfo - Extra information associated with this operator
|
|
|
|
/// name that can be used by the front end.
|
|
|
|
void *FETokenInfo;
|
|
|
|
|
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) {
|
|
|
|
ID.AddPointer(Template);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
/// CXXOperatorIdName - Contains extra information for the name of an
|
2009-09-09 23:08:12 +08:00
|
|
|
/// overloaded operator in C++, such as "operator+.
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
class CXXOperatorIdName : public DeclarationNameExtra {
|
|
|
|
public:
|
|
|
|
/// FETokenInfo - Extra information associated with this operator
|
|
|
|
/// name that can be used by the front end.
|
|
|
|
void *FETokenInfo;
|
|
|
|
};
|
|
|
|
|
2012-03-09 16:37:16 +08:00
|
|
|
/// CXXLiteralOperatorName - Contains the actual identifier that makes up the
|
2009-11-29 15:34:05 +08:00
|
|
|
/// name.
|
|
|
|
///
|
|
|
|
/// This identifier is stored here rather than directly in DeclarationName so as
|
|
|
|
/// to allow Objective-C selectors, which are about a million times more common,
|
|
|
|
/// to consume minimal memory.
|
2010-01-13 17:01:02 +08:00
|
|
|
class CXXLiteralOperatorIdName
|
|
|
|
: public DeclarationNameExtra, public llvm::FoldingSetNode {
|
2009-11-29 15:34:05 +08:00
|
|
|
public:
|
|
|
|
IdentifierInfo *ID;
|
2010-01-13 17:01:02 +08:00
|
|
|
|
2012-03-09 16:37:16 +08:00
|
|
|
/// FETokenInfo - Extra information associated with this operator
|
|
|
|
/// name that can be used by the front end.
|
|
|
|
void *FETokenInfo;
|
|
|
|
|
2010-01-13 17:01:02 +08:00
|
|
|
void Profile(llvm::FoldingSetNodeID &FSID) {
|
|
|
|
FSID.AddPointer(ID);
|
|
|
|
}
|
2009-11-29 15:34:05 +08:00
|
|
|
};
|
|
|
|
|
2010-02-13 09:04:05 +08:00
|
|
|
static int compareInt(unsigned A, unsigned B) {
|
|
|
|
return (A < B ? -1 : (A > B ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) {
|
2009-11-05 06:24:30 +08:00
|
|
|
if (LHS.getNameKind() != RHS.getNameKind())
|
2010-02-13 09:04:05 +08:00
|
|
|
return (LHS.getNameKind() < RHS.getNameKind() ? -1 : 1);
|
2009-11-05 06:24:30 +08:00
|
|
|
|
|
|
|
switch (LHS.getNameKind()) {
|
2010-02-13 09:04:05 +08:00
|
|
|
case DeclarationName::Identifier: {
|
|
|
|
IdentifierInfo *LII = LHS.getAsIdentifierInfo();
|
|
|
|
IdentifierInfo *RII = RHS.getAsIdentifierInfo();
|
|
|
|
if (!LII) return RII ? -1 : 0;
|
|
|
|
if (!RII) return 1;
|
|
|
|
|
|
|
|
return LII->getName().compare(RII->getName());
|
|
|
|
}
|
2008-11-17 22:58:09 +08:00
|
|
|
|
2009-11-05 06:24:30 +08:00
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector: {
|
|
|
|
Selector LHSSelector = LHS.getObjCSelector();
|
|
|
|
Selector RHSSelector = RHS.getObjCSelector();
|
2016-11-18 02:41:18 +08:00
|
|
|
// getNumArgs for ZeroArgSelector returns 0, but we still need to compare.
|
|
|
|
if (LHS.getNameKind() == DeclarationName::ObjCZeroArgSelector &&
|
|
|
|
RHS.getNameKind() == DeclarationName::ObjCZeroArgSelector) {
|
|
|
|
return LHSSelector.getAsIdentifierInfo()->getName().compare(
|
|
|
|
RHSSelector.getAsIdentifierInfo()->getName());
|
|
|
|
}
|
2010-02-13 09:04:05 +08:00
|
|
|
unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
|
|
|
|
for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
|
2011-02-19 06:29:55 +08:00
|
|
|
switch (LHSSelector.getNameForSlot(I).compare(
|
|
|
|
RHSSelector.getNameForSlot(I))) {
|
2016-11-18 02:41:18 +08:00
|
|
|
case -1: return -1;
|
|
|
|
case 1: return 1;
|
2009-11-05 06:24:30 +08:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-13 09:04:05 +08:00
|
|
|
|
|
|
|
return compareInt(LN, RN);
|
2009-11-05 06:24:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
2010-02-13 09:04:05 +08:00
|
|
|
if (QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType()))
|
|
|
|
return -1;
|
|
|
|
if (QualTypeOrdering()(RHS.getCXXNameType(), LHS.getCXXNameType()))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2017-02-07 09:37:30 +08:00
|
|
|
|
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
|
|
|
// We never want to compare deduction guide names for templates from
|
|
|
|
// different scopes, so just compare the template-name.
|
|
|
|
return compare(LHS.getCXXDeductionGuideTemplate()->getDeclName(),
|
|
|
|
RHS.getCXXDeductionGuideTemplate()->getDeclName());
|
|
|
|
|
2009-11-05 06:24:30 +08:00
|
|
|
case DeclarationName::CXXOperatorName:
|
2010-02-13 09:04:05 +08:00
|
|
|
return compareInt(LHS.getCXXOverloadedOperator(),
|
|
|
|
RHS.getCXXOverloadedOperator());
|
2009-11-29 15:34:05 +08:00
|
|
|
|
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
2010-02-13 09:04:05 +08:00
|
|
|
return LHS.getCXXLiteralIdentifier()->getName().compare(
|
|
|
|
RHS.getCXXLiteralIdentifier()->getName());
|
2009-11-05 06:24:30 +08:00
|
|
|
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
2010-02-13 09:04:05 +08:00
|
|
|
return 0;
|
2009-11-05 06:24:30 +08:00
|
|
|
}
|
2012-01-21 05:50:17 +08:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid DeclarationName Kind!");
|
2008-11-17 22:58:09 +08:00
|
|
|
}
|
|
|
|
|
2016-02-14 05:46:50 +08:00
|
|
|
static void printCXXConstructorDestructorName(QualType ClassType,
|
|
|
|
raw_ostream &OS,
|
2016-05-19 09:39:10 +08:00
|
|
|
PrintingPolicy Policy) {
|
|
|
|
// We know we're printing C++ here. Ensure we print types properly.
|
|
|
|
Policy.adjustForCPlusPlus();
|
|
|
|
|
2016-02-14 05:46:50 +08:00
|
|
|
if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) {
|
|
|
|
OS << *ClassRec->getDecl();
|
|
|
|
return;
|
|
|
|
}
|
2016-02-15 09:32:36 +08:00
|
|
|
if (Policy.SuppressTemplateArgsInCXXConstructors) {
|
|
|
|
if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) {
|
|
|
|
OS << *InjTy->getDecl();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-05-19 09:39:10 +08:00
|
|
|
ClassType.print(OS, Policy);
|
2016-02-14 05:46:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) {
|
|
|
|
DeclarationName &N = *this;
|
2013-05-15 05:04:00 +08:00
|
|
|
switch (N.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
|
|
|
if (const IdentifierInfo *II = N.getAsIdentifierInfo())
|
|
|
|
OS << II->getName();
|
2016-02-14 05:46:50 +08:00
|
|
|
return;
|
2013-05-15 05:04:00 +08:00
|
|
|
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
2014-01-04 01:59:55 +08:00
|
|
|
N.getObjCSelector().print(OS);
|
2016-02-14 05:46:50 +08:00
|
|
|
return;
|
2013-05-15 05:04:00 +08:00
|
|
|
|
2016-02-14 05:46:50 +08:00
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy);
|
2013-05-15 05:04:00 +08:00
|
|
|
|
|
|
|
case DeclarationName::CXXDestructorName: {
|
|
|
|
OS << '~';
|
2016-02-14 05:46:50 +08:00
|
|
|
return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy);
|
2013-05-15 05:04:00 +08:00
|
|
|
}
|
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
2017-02-08 08:35:25 +08:00
|
|
|
OS << "<deduction guide for ";
|
|
|
|
getCXXDeductionGuideTemplate()->getDeclName().print(OS, Policy);
|
|
|
|
OS << '>';
|
|
|
|
return;
|
2017-02-07 09:37:30 +08:00
|
|
|
|
2013-05-15 05:04:00 +08:00
|
|
|
case DeclarationName::CXXOperatorName: {
|
|
|
|
static const char* const OperatorNames[NUM_OVERLOADED_OPERATORS] = {
|
2014-05-12 13:36:57 +08:00
|
|
|
nullptr,
|
2013-05-15 05:04:00 +08:00
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
Spelling,
|
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
};
|
|
|
|
const char *OpName = OperatorNames[N.getCXXOverloadedOperator()];
|
|
|
|
assert(OpName && "not an overloaded operator");
|
|
|
|
|
|
|
|
OS << "operator";
|
|
|
|
if (OpName[0] >= 'a' && OpName[0] <= 'z')
|
|
|
|
OS << ' ';
|
2016-02-14 05:46:50 +08:00
|
|
|
OS << OpName;
|
|
|
|
return;
|
2013-05-15 05:04:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
2016-02-14 05:46:50 +08:00
|
|
|
OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName();
|
|
|
|
return;
|
2013-05-15 05:04:00 +08:00
|
|
|
|
|
|
|
case DeclarationName::CXXConversionFunctionName: {
|
|
|
|
OS << "operator ";
|
|
|
|
QualType Type = N.getCXXNameType();
|
2016-02-14 05:46:50 +08:00
|
|
|
if (const RecordType *Rec = Type->getAs<RecordType>()) {
|
|
|
|
OS << *Rec->getDecl();
|
|
|
|
return;
|
|
|
|
}
|
2016-05-19 09:39:10 +08:00
|
|
|
// We know we're printing C++ here, ensure we print 'bool' properly.
|
|
|
|
PrintingPolicy CXXPolicy = Policy;
|
|
|
|
CXXPolicy.adjustForCPlusPlus();
|
|
|
|
Type.print(OS, CXXPolicy);
|
2016-02-14 05:46:50 +08:00
|
|
|
return;
|
2013-05-15 05:04:00 +08:00
|
|
|
}
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
2016-02-14 05:46:50 +08:00
|
|
|
OS << "<using-directive>";
|
|
|
|
return;
|
2013-05-15 05:04:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Unexpected declaration name kind");
|
|
|
|
}
|
|
|
|
|
2016-02-14 05:46:50 +08:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
|
|
|
|
LangOptions LO;
|
|
|
|
N.print(OS, PrintingPolicy(LO));
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
DeclarationName::NameKind DeclarationName::getNameKind() const {
|
|
|
|
switch (getStoredNameKind()) {
|
|
|
|
case StoredIdentifier: return Identifier;
|
|
|
|
case StoredObjCZeroArgSelector: return ObjCZeroArgSelector;
|
|
|
|
case StoredObjCOneArgSelector: return ObjCOneArgSelector;
|
|
|
|
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
case StoredDeclarationNameExtra:
|
2008-11-17 22:58:09 +08:00
|
|
|
switch (getExtra()->ExtraKindOrNumArgs) {
|
2009-09-09 23:08:12 +08:00
|
|
|
case DeclarationNameExtra::CXXConstructor:
|
2008-11-17 22:58:09 +08:00
|
|
|
return CXXConstructorName;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
case DeclarationNameExtra::CXXDestructor:
|
2008-11-17 22:58:09 +08:00
|
|
|
return CXXDestructorName;
|
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationNameExtra::CXXDeductionGuide:
|
|
|
|
return CXXDeductionGuideName;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
case DeclarationNameExtra::CXXConversionFunction:
|
2008-11-17 22:58:09 +08:00
|
|
|
return CXXConversionFunctionName;
|
|
|
|
|
2009-11-29 15:34:05 +08:00
|
|
|
case DeclarationNameExtra::CXXLiteralOperator:
|
|
|
|
return CXXLiteralOperatorName;
|
|
|
|
|
2009-02-04 03:21:40 +08:00
|
|
|
case DeclarationNameExtra::CXXUsingDirective:
|
|
|
|
return CXXUsingDirective;
|
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
default:
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
// Check if we have one of the CXXOperator* enumeration values.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (getExtra()->ExtraKindOrNumArgs <
|
2009-02-04 03:21:40 +08:00
|
|
|
DeclarationNameExtra::CXXUsingDirective)
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
return CXXOperatorName;
|
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
return ObjCMultiArgSelector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't actually get here.
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("This should be unreachable!");
|
2008-11-17 22:58:09 +08:00
|
|
|
}
|
|
|
|
|
2010-01-12 02:40:55 +08:00
|
|
|
bool DeclarationName::isDependentName() const {
|
|
|
|
QualType T = getCXXNameType();
|
2017-02-07 09:37:30 +08:00
|
|
|
if (!T.isNull() && T->isDependentType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// A class-scope deduction guide in a dependent context has a dependent name.
|
|
|
|
auto *TD = getCXXDeductionGuideTemplate();
|
|
|
|
if (TD && TD->getDeclContext()->isDependentContext())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2010-01-12 02:40:55 +08:00
|
|
|
}
|
|
|
|
|
2008-11-18 06:58:34 +08:00
|
|
|
std::string DeclarationName::getAsString() const {
|
2010-04-17 17:56:45 +08:00
|
|
|
std::string Result;
|
|
|
|
llvm::raw_string_ostream OS(Result);
|
2013-05-15 05:04:00 +08:00
|
|
|
OS << *this;
|
2010-04-17 17:56:45 +08:00
|
|
|
return OS.str();
|
|
|
|
}
|
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
QualType DeclarationName::getCXXNameType() const {
|
|
|
|
if (CXXSpecialName *CXXName = getAsCXXSpecialName())
|
|
|
|
return CXXName->Type;
|
|
|
|
else
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
TemplateDecl *DeclarationName::getCXXDeductionGuideTemplate() const {
|
|
|
|
if (auto *Guide = getAsCXXDeductionGuideNameExtra())
|
|
|
|
return Guide->Template;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
OverloadedOperatorKind DeclarationName::getCXXOverloadedOperator() const {
|
|
|
|
if (CXXOperatorIdName *CXXOp = getAsCXXOperatorIdName()) {
|
2009-09-09 23:08:12 +08:00
|
|
|
unsigned value
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
= CXXOp->ExtraKindOrNumArgs - DeclarationNameExtra::CXXConversionFunction;
|
|
|
|
return static_cast<OverloadedOperatorKind>(value);
|
|
|
|
} else {
|
|
|
|
return OO_None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-29 15:34:05 +08:00
|
|
|
IdentifierInfo *DeclarationName::getCXXLiteralIdentifier() const {
|
|
|
|
if (CXXLiteralOperatorIdName *CXXLit = getAsCXXLiteralOperatorIdName())
|
|
|
|
return CXXLit->ID;
|
|
|
|
else
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2009-11-29 15:34:05 +08:00
|
|
|
}
|
|
|
|
|
2012-05-04 07:18:44 +08:00
|
|
|
void *DeclarationName::getFETokenInfoAsVoidSlow() const {
|
2008-11-18 04:34:05 +08:00
|
|
|
switch (getNameKind()) {
|
|
|
|
case Identifier:
|
2012-05-20 00:03:58 +08:00
|
|
|
llvm_unreachable("Handled by getFETokenInfo()");
|
2008-11-18 04:34:05 +08:00
|
|
|
|
|
|
|
case CXXConstructorName:
|
|
|
|
case CXXDestructorName:
|
|
|
|
case CXXConversionFunctionName:
|
|
|
|
return getAsCXXSpecialName()->FETokenInfo;
|
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
case CXXDeductionGuideName:
|
|
|
|
return getAsCXXDeductionGuideNameExtra()->FETokenInfo;
|
|
|
|
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
case CXXOperatorName:
|
|
|
|
return getAsCXXOperatorIdName()->FETokenInfo;
|
|
|
|
|
2009-11-29 15:34:05 +08:00
|
|
|
case CXXLiteralOperatorName:
|
2012-03-09 16:37:16 +08:00
|
|
|
return getAsCXXLiteralOperatorIdName()->FETokenInfo;
|
2009-11-29 15:34:05 +08:00
|
|
|
|
2008-11-18 04:34:05 +08:00
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Declaration name has no FETokenInfo");
|
2008-11-18 04:34:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationName::setFETokenInfo(void *T) {
|
|
|
|
switch (getNameKind()) {
|
|
|
|
case Identifier:
|
|
|
|
getAsIdentifierInfo()->setFETokenInfo(T);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CXXConstructorName:
|
|
|
|
case CXXDestructorName:
|
|
|
|
case CXXConversionFunctionName:
|
|
|
|
getAsCXXSpecialName()->FETokenInfo = T;
|
|
|
|
break;
|
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
case CXXDeductionGuideName:
|
|
|
|
getAsCXXDeductionGuideNameExtra()->FETokenInfo = T;
|
|
|
|
break;
|
|
|
|
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
case CXXOperatorName:
|
|
|
|
getAsCXXOperatorIdName()->FETokenInfo = T;
|
|
|
|
break;
|
|
|
|
|
2009-11-29 15:34:05 +08:00
|
|
|
case CXXLiteralOperatorName:
|
2012-03-09 16:37:16 +08:00
|
|
|
getAsCXXLiteralOperatorIdName()->FETokenInfo = T;
|
2009-11-29 15:34:05 +08:00
|
|
|
break;
|
|
|
|
|
2008-11-18 04:34:05 +08:00
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Declaration name has no FETokenInfo");
|
2008-11-18 04:34:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 03:21:40 +08:00
|
|
|
DeclarationName DeclarationName::getUsingDirectiveName() {
|
|
|
|
// Single instance of DeclarationNameExtra for using-directive
|
2009-12-10 08:07:02 +08:00
|
|
|
static const DeclarationNameExtra UDirExtra =
|
2009-02-04 03:21:40 +08:00
|
|
|
{ DeclarationNameExtra::CXXUsingDirective };
|
|
|
|
|
|
|
|
uintptr_t Ptr = reinterpret_cast<uintptr_t>(&UDirExtra);
|
|
|
|
Ptr |= StoredDeclarationNameExtra;
|
|
|
|
|
|
|
|
return DeclarationName(Ptr);
|
|
|
|
}
|
|
|
|
|
2016-01-30 03:38:18 +08:00
|
|
|
LLVM_DUMP_METHOD void DeclarationName::dump() const {
|
2013-05-15 05:04:00 +08:00
|
|
|
llvm::errs() << *this << '\n';
|
2009-11-16 06:30:43 +08:00
|
|
|
}
|
|
|
|
|
2011-01-12 17:06:06 +08:00
|
|
|
DeclarationNameTable::DeclarationNameTable(const ASTContext &C) : Ctx(C) {
|
2008-11-17 22:58:09 +08:00
|
|
|
CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
|
2010-01-13 17:01:02 +08:00
|
|
|
CXXLiteralOperatorNames = new llvm::FoldingSet<CXXLiteralOperatorIdName>;
|
2017-02-07 09:37:30 +08:00
|
|
|
CXXDeductionGuideNames = new llvm::FoldingSet<CXXDeductionGuideNameExtra>;
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
|
|
|
|
// Initialize the overloaded operator names.
|
2010-05-11 04:56:10 +08:00
|
|
|
CXXOperatorNames = new (Ctx) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) {
|
2009-09-09 23:08:12 +08:00
|
|
|
CXXOperatorNames[Op].ExtraKindOrNumArgs
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
= Op + DeclarationNameExtra::CXXConversionFunction;
|
2014-05-12 13:36:57 +08:00
|
|
|
CXXOperatorNames[Op].FETokenInfo = nullptr;
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
}
|
2008-11-17 22:58:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DeclarationNameTable::~DeclarationNameTable() {
|
2017-02-07 09:37:30 +08:00
|
|
|
auto *SpecialNames =
|
|
|
|
static_cast<llvm::FoldingSet<CXXSpecialName> *>(CXXSpecialNamesImpl);
|
|
|
|
auto *LiteralNames =
|
|
|
|
static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName> *>(
|
|
|
|
CXXLiteralOperatorNames);
|
|
|
|
auto *DeductionGuideNames =
|
|
|
|
static_cast<llvm::FoldingSet<CXXDeductionGuideNameExtra> *>(
|
|
|
|
CXXDeductionGuideNames);
|
2010-01-13 17:01:02 +08:00
|
|
|
|
|
|
|
delete SpecialNames;
|
|
|
|
delete LiteralNames;
|
2017-02-07 09:37:30 +08:00
|
|
|
delete DeductionGuideNames;
|
2010-05-11 04:40:08 +08:00
|
|
|
}
|
|
|
|
|
2012-12-02 00:35:25 +08:00
|
|
|
DeclarationName DeclarationNameTable::getCXXConstructorName(CanQualType Ty) {
|
|
|
|
return getCXXSpecialName(DeclarationName::CXXConstructorName,
|
|
|
|
Ty.getUnqualifiedType());
|
|
|
|
}
|
|
|
|
|
|
|
|
DeclarationName DeclarationNameTable::getCXXDestructorName(CanQualType Ty) {
|
|
|
|
return getCXXSpecialName(DeclarationName::CXXDestructorName,
|
|
|
|
Ty.getUnqualifiedType());
|
|
|
|
}
|
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
DeclarationName
|
|
|
|
DeclarationNameTable::getCXXDeductionGuideName(TemplateDecl *Template) {
|
|
|
|
Template = cast<TemplateDecl>(Template->getCanonicalDecl());
|
|
|
|
|
|
|
|
auto *DeductionGuideNames =
|
|
|
|
static_cast<llvm::FoldingSet<CXXDeductionGuideNameExtra> *>(
|
|
|
|
CXXDeductionGuideNames);
|
|
|
|
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
ID.AddPointer(Template);
|
|
|
|
|
|
|
|
void *InsertPos = nullptr;
|
|
|
|
if (auto *Name = DeductionGuideNames->FindNodeOrInsertPos(ID, InsertPos))
|
|
|
|
return DeclarationName(Name);
|
|
|
|
|
|
|
|
auto *Name = new (Ctx) CXXDeductionGuideNameExtra;
|
|
|
|
Name->ExtraKindOrNumArgs = DeclarationNameExtra::CXXDeductionGuide;
|
|
|
|
Name->Template = Template;
|
|
|
|
Name->FETokenInfo = nullptr;
|
|
|
|
|
|
|
|
DeductionGuideNames->InsertNode(Name, InsertPos);
|
|
|
|
return DeclarationName(Name);
|
|
|
|
}
|
|
|
|
|
2012-12-02 00:35:25 +08:00
|
|
|
DeclarationName
|
|
|
|
DeclarationNameTable::getCXXConversionFunctionName(CanQualType Ty) {
|
|
|
|
return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty);
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
DeclarationName
|
|
|
|
DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind,
|
2009-08-05 13:36:45 +08:00
|
|
|
CanQualType Ty) {
|
2008-11-17 22:58:09 +08:00
|
|
|
assert(Kind >= DeclarationName::CXXConstructorName &&
|
|
|
|
Kind <= DeclarationName::CXXConversionFunctionName &&
|
|
|
|
"Kind must be a C++ special name kind");
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::FoldingSet<CXXSpecialName> *SpecialNames
|
2008-11-17 22:58:09 +08:00
|
|
|
= static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
|
|
|
|
|
|
|
|
DeclarationNameExtra::ExtraKind EKind;
|
|
|
|
switch (Kind) {
|
2009-09-09 23:08:12 +08:00
|
|
|
case DeclarationName::CXXConstructorName:
|
2008-11-17 22:58:09 +08:00
|
|
|
EKind = DeclarationNameExtra::CXXConstructor;
|
2009-09-25 03:53:00 +08:00
|
|
|
assert(!Ty.hasQualifiers() &&"Constructor type must be unqualified");
|
2008-11-17 22:58:09 +08:00
|
|
|
break;
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
EKind = DeclarationNameExtra::CXXDestructor;
|
2009-09-25 03:53:00 +08:00
|
|
|
assert(!Ty.hasQualifiers() && "Destructor type must be unqualified");
|
2008-11-17 22:58:09 +08:00
|
|
|
break;
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
|
|
|
EKind = DeclarationNameExtra::CXXConversionFunction;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return DeclarationName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unique selector, to guarantee there is one per name.
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
ID.AddInteger(EKind);
|
|
|
|
ID.AddPointer(Ty.getAsOpaquePtr());
|
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
void *InsertPos = nullptr;
|
2008-11-17 22:58:09 +08:00
|
|
|
if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos))
|
|
|
|
return DeclarationName(Name);
|
|
|
|
|
2010-05-11 04:56:10 +08:00
|
|
|
CXXSpecialName *SpecialName = new (Ctx) CXXSpecialName;
|
2008-11-17 22:58:09 +08:00
|
|
|
SpecialName->ExtraKindOrNumArgs = EKind;
|
|
|
|
SpecialName->Type = Ty;
|
2014-05-12 13:36:57 +08:00
|
|
|
SpecialName->FETokenInfo = nullptr;
|
2008-11-17 22:58:09 +08:00
|
|
|
|
|
|
|
SpecialNames->InsertNode(SpecialName, InsertPos);
|
|
|
|
return DeclarationName(SpecialName);
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
DeclarationName
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
DeclarationNameTable::getCXXOperatorName(OverloadedOperatorKind Op) {
|
|
|
|
return DeclarationName(&CXXOperatorNames[(unsigned)Op]);
|
|
|
|
}
|
|
|
|
|
2009-11-29 15:34:05 +08:00
|
|
|
DeclarationName
|
|
|
|
DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) {
|
2010-01-13 17:01:02 +08:00
|
|
|
llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
|
|
|
|
= static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
|
|
|
|
(CXXLiteralOperatorNames);
|
|
|
|
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
ID.AddPointer(II);
|
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
void *InsertPos = nullptr;
|
2010-01-13 17:01:02 +08:00
|
|
|
if (CXXLiteralOperatorIdName *Name =
|
|
|
|
LiteralNames->FindNodeOrInsertPos(ID, InsertPos))
|
|
|
|
return DeclarationName (Name);
|
|
|
|
|
2010-05-11 04:56:10 +08:00
|
|
|
CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName;
|
2009-11-29 15:34:05 +08:00
|
|
|
LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator;
|
|
|
|
LiteralName->ID = II;
|
2014-05-12 13:36:57 +08:00
|
|
|
LiteralName->FETokenInfo = nullptr;
|
2010-01-13 17:01:02 +08:00
|
|
|
|
|
|
|
LiteralNames->InsertNode(LiteralName, InsertPos);
|
2009-11-29 15:34:05 +08:00
|
|
|
return DeclarationName(LiteralName);
|
|
|
|
}
|
|
|
|
|
2010-08-12 06:01:17 +08:00
|
|
|
DeclarationNameLoc::DeclarationNameLoc(DeclarationName Name) {
|
|
|
|
switch (Name.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
2010-08-12 06:01:17 +08:00
|
|
|
break;
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
2014-05-12 13:36:57 +08:00
|
|
|
NamedType.TInfo = nullptr;
|
2010-08-12 06:01:17 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 09:34:56 +08:00
|
|
|
bool DeclarationNameInfo::containsUnexpandedParameterPack() 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:
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
2010-12-15 09:34:56 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
|
|
|
if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo)
|
|
|
|
return TInfo->getType()->containsUnexpandedParameterPack();
|
|
|
|
|
|
|
|
return Name.getCXXNameType()->containsUnexpandedParameterPack();
|
|
|
|
}
|
2010-12-15 15:29:18 +08:00
|
|
|
llvm_unreachable("All name kinds handled.");
|
2010-12-15 09:34:56 +08:00
|
|
|
}
|
|
|
|
|
2011-07-01 09:22:09 +08:00
|
|
|
bool DeclarationNameInfo::isInstantiationDependent() 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:
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
2011-07-01 09:22:09 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
|
|
|
if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo)
|
|
|
|
return TInfo->getType()->isInstantiationDependentType();
|
|
|
|
|
|
|
|
return Name.getCXXNameType()->isInstantiationDependentType();
|
|
|
|
}
|
|
|
|
llvm_unreachable("All name kinds handled.");
|
|
|
|
}
|
|
|
|
|
2010-08-12 06:01:17 +08:00
|
|
|
std::string DeclarationNameInfo::getAsString() const {
|
|
|
|
std::string Result;
|
|
|
|
llvm::raw_string_ostream OS(Result);
|
|
|
|
printName(OS);
|
|
|
|
return OS.str();
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void DeclarationNameInfo::printName(raw_ostream &OS) const {
|
2010-08-12 06:01:17 +08:00
|
|
|
switch (Name.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
case DeclarationName::CXXOperatorName:
|
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
2013-05-15 05:04:00 +08:00
|
|
|
OS << Name;
|
2010-08-12 06:01:17 +08:00
|
|
|
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 ";
|
2014-01-22 08:27:42 +08:00
|
|
|
LangOptions LO;
|
|
|
|
LO.CPlusPlus = true;
|
2014-02-26 02:03:55 +08:00
|
|
|
LO.Bool = true;
|
2017-04-12 00:46:03 +08:00
|
|
|
PrintingPolicy PP(LO);
|
|
|
|
PP.SuppressScope = true;
|
|
|
|
OS << TInfo->getType().getAsString(PP);
|
2013-05-15 05:04:00 +08:00
|
|
|
} else
|
|
|
|
OS << Name;
|
2010-08-12 06:01:17 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Unexpected declaration name kind");
|
2010-08-12 06:01:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation DeclarationNameInfo::getEndLoc() const {
|
|
|
|
switch (Name.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
2010-08-12 06:01:17 +08:00
|
|
|
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;
|
|
|
|
}
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Unexpected declaration name kind");
|
2010-08-12 06:01:17 +08:00
|
|
|
}
|