2008-11-17 17:58:09 +03: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-11 00:40:08 +04:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
2008-11-17 17:58:09 +03:00
|
|
|
#include "clang/AST/DeclarationName.h"
|
2008-11-18 01:58:34 +03:00
|
|
|
#include "clang/AST/Type.h"
|
2010-08-12 02:01:17 +04:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2009-11-05 01:24:30 +03:00
|
|
|
#include "clang/AST/TypeOrdering.h"
|
2008-11-17 17:58:09 +03:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2009-04-23 01:45:53 +04:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2008-11-17 17:58:09 +03:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2010-12-15 10:29:18 +03:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-04-17 13:56:45 +04:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-11-17 17:58:09 +03: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 19:08:12 +04:00
|
|
|
class CXXSpecialName
|
2008-11-17 17:58:09 +03:00
|
|
|
: public DeclarationNameExtra, public llvm::FoldingSetNode {
|
|
|
|
public:
|
2008-11-17 23:34:05 +03:00
|
|
|
/// Type - The type associated with this declaration name.
|
2008-11-17 17:58:09 +03:00
|
|
|
QualType Type;
|
|
|
|
|
2008-11-17 23:34:05 +03:00
|
|
|
/// FETokenInfo - Extra information associated with this declaration
|
|
|
|
/// name that can be used by the front end.
|
|
|
|
void *FETokenInfo;
|
|
|
|
|
2008-11-17 17:58:09 +03:00
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) {
|
|
|
|
ID.AddInteger(ExtraKindOrNumArgs);
|
|
|
|
ID.AddPointer(Type.getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
/// CXXOperatorIdName - Contains extra information for the name of an
|
2009-09-09 19:08:12 +04: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
class CXXOperatorIdName : public DeclarationNameExtra {
|
|
|
|
public:
|
|
|
|
/// FETokenInfo - Extra information associated with this operator
|
|
|
|
/// name that can be used by the front end.
|
|
|
|
void *FETokenInfo;
|
|
|
|
};
|
|
|
|
|
2009-11-29 10:34:05 +03:00
|
|
|
/// CXXLiberalOperatorName - Contains the actual identifier that makes up the
|
|
|
|
/// 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 12:01:02 +03:00
|
|
|
class CXXLiteralOperatorIdName
|
|
|
|
: public DeclarationNameExtra, public llvm::FoldingSetNode {
|
2009-11-29 10:34:05 +03:00
|
|
|
public:
|
|
|
|
IdentifierInfo *ID;
|
2010-01-13 12:01:02 +03:00
|
|
|
|
|
|
|
void Profile(llvm::FoldingSetNodeID &FSID) {
|
|
|
|
FSID.AddPointer(ID);
|
|
|
|
}
|
2009-11-29 10:34:05 +03:00
|
|
|
};
|
|
|
|
|
2010-02-13 04:04:05 +03: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 01:24:30 +03:00
|
|
|
if (LHS.getNameKind() != RHS.getNameKind())
|
2010-02-13 04:04:05 +03:00
|
|
|
return (LHS.getNameKind() < RHS.getNameKind() ? -1 : 1);
|
2009-11-05 01:24:30 +03:00
|
|
|
|
|
|
|
switch (LHS.getNameKind()) {
|
2010-02-13 04:04:05 +03: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 17:58:09 +03:00
|
|
|
|
2009-11-05 01:24:30 +03:00
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector: {
|
|
|
|
Selector LHSSelector = LHS.getObjCSelector();
|
|
|
|
Selector RHSSelector = RHS.getObjCSelector();
|
2010-02-13 04:04:05 +03:00
|
|
|
unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
|
|
|
|
for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
|
2009-11-05 01:24:30 +03:00
|
|
|
IdentifierInfo *LHSId = LHSSelector.getIdentifierInfoForSlot(I);
|
|
|
|
IdentifierInfo *RHSId = RHSSelector.getIdentifierInfoForSlot(I);
|
|
|
|
|
|
|
|
switch (LHSId->getName().compare(RHSId->getName())) {
|
|
|
|
case -1: return true;
|
|
|
|
case 1: return false;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-13 04:04:05 +03:00
|
|
|
|
|
|
|
return compareInt(LN, RN);
|
2009-11-05 01:24:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
2010-02-13 04:04:05 +03:00
|
|
|
if (QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType()))
|
|
|
|
return -1;
|
|
|
|
if (QualTypeOrdering()(RHS.getCXXNameType(), LHS.getCXXNameType()))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2009-11-05 01:24:30 +03:00
|
|
|
|
|
|
|
case DeclarationName::CXXOperatorName:
|
2010-02-13 04:04:05 +03:00
|
|
|
return compareInt(LHS.getCXXOverloadedOperator(),
|
|
|
|
RHS.getCXXOverloadedOperator());
|
2009-11-29 10:34:05 +03:00
|
|
|
|
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
2010-02-13 04:04:05 +03:00
|
|
|
return LHS.getCXXLiteralIdentifier()->getName().compare(
|
|
|
|
RHS.getCXXLiteralIdentifier()->getName());
|
2009-11-05 01:24:30 +03:00
|
|
|
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
2010-02-13 04:04:05 +03:00
|
|
|
return 0;
|
2009-11-05 01:24:30 +03:00
|
|
|
}
|
|
|
|
|
2010-02-13 04:04:05 +03:00
|
|
|
return 0;
|
2008-11-17 17:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
DeclarationName::DeclarationName(Selector Sel) {
|
2009-04-24 02:29:11 +04:00
|
|
|
if (!Sel.getAsOpaquePtr()) {
|
2009-10-17 21:25:45 +04:00
|
|
|
Ptr = 0;
|
2009-04-24 02:29:11 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-17 17:58:09 +03:00
|
|
|
switch (Sel.getNumArgs()) {
|
|
|
|
case 0:
|
|
|
|
Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
|
2009-03-14 03:27:40 +03:00
|
|
|
assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
|
2008-11-17 17:58:09 +03:00
|
|
|
Ptr |= StoredObjCZeroArgSelector;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
|
2009-03-14 03:27:40 +03:00
|
|
|
assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
|
2008-11-17 17:58:09 +03:00
|
|
|
Ptr |= StoredObjCOneArgSelector;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Ptr = Sel.InfoPtr & ~Selector::ArgFlags;
|
2009-03-14 03:27:40 +03:00
|
|
|
assert((Ptr & PtrMask) == 0 && "Improperly aligned MultiKeywordSelector");
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
Ptr |= StoredDeclarationNameExtra;
|
2008-11-17 17:58:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
case StoredDeclarationNameExtra:
|
2008-11-17 17:58:09 +03:00
|
|
|
switch (getExtra()->ExtraKindOrNumArgs) {
|
2009-09-09 19:08:12 +04:00
|
|
|
case DeclarationNameExtra::CXXConstructor:
|
2008-11-17 17:58:09 +03:00
|
|
|
return CXXConstructorName;
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
case DeclarationNameExtra::CXXDestructor:
|
2008-11-17 17:58:09 +03:00
|
|
|
return CXXDestructorName;
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
case DeclarationNameExtra::CXXConversionFunction:
|
2008-11-17 17:58:09 +03:00
|
|
|
return CXXConversionFunctionName;
|
|
|
|
|
2009-11-29 10:34:05 +03:00
|
|
|
case DeclarationNameExtra::CXXLiteralOperator:
|
|
|
|
return CXXLiteralOperatorName;
|
|
|
|
|
2009-02-03 22:21:40 +03:00
|
|
|
case DeclarationNameExtra::CXXUsingDirective:
|
|
|
|
return CXXUsingDirective;
|
|
|
|
|
2008-11-17 17:58:09 +03: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
// Check if we have one of the CXXOperator* enumeration values.
|
2009-09-09 19:08:12 +04:00
|
|
|
if (getExtra()->ExtraKindOrNumArgs <
|
2009-02-03 22:21:40 +03: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
return CXXOperatorName;
|
|
|
|
|
2008-11-17 17:58:09 +03:00
|
|
|
return ObjCMultiArgSelector;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't actually get here.
|
2009-03-21 09:40:50 +03:00
|
|
|
assert(0 && "This should be unreachable!");
|
2008-11-17 17:58:09 +03:00
|
|
|
return Identifier;
|
|
|
|
}
|
|
|
|
|
2010-01-11 21:40:55 +03:00
|
|
|
bool DeclarationName::isDependentName() const {
|
|
|
|
QualType T = getCXXNameType();
|
|
|
|
return !T.isNull() && T->isDependentType();
|
|
|
|
}
|
|
|
|
|
2008-11-18 01:58:34 +03:00
|
|
|
std::string DeclarationName::getAsString() const {
|
2010-04-17 13:56:45 +04:00
|
|
|
std::string Result;
|
|
|
|
llvm::raw_string_ostream OS(Result);
|
|
|
|
printName(OS);
|
|
|
|
return OS.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationName::printName(llvm::raw_ostream &OS) const {
|
2008-11-18 01:58:34 +03:00
|
|
|
switch (getNameKind()) {
|
|
|
|
case Identifier:
|
|
|
|
if (const IdentifierInfo *II = getAsIdentifierInfo())
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << II->getName();
|
|
|
|
return;
|
2008-11-18 01:58:34 +03:00
|
|
|
|
|
|
|
case ObjCZeroArgSelector:
|
|
|
|
case ObjCOneArgSelector:
|
|
|
|
case ObjCMultiArgSelector:
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << getObjCSelector().getAsString();
|
|
|
|
return;
|
2008-11-18 01:58:34 +03:00
|
|
|
|
|
|
|
case CXXConstructorName: {
|
|
|
|
QualType ClassType = getCXXNameType();
|
2009-07-30 01:53:49 +04:00
|
|
|
if (const RecordType *ClassRec = ClassType->getAs<RecordType>())
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << ClassRec->getDecl();
|
|
|
|
else
|
|
|
|
OS << ClassType.getAsString();
|
|
|
|
return;
|
2008-11-18 01:58:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXXDestructorName: {
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << '~';
|
2008-11-18 01:58:34 +03:00
|
|
|
QualType Type = getCXXNameType();
|
2009-07-30 01:53:49 +04:00
|
|
|
if (const RecordType *Rec = Type->getAs<RecordType>())
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << Rec->getDecl();
|
2008-11-18 01:58:34 +03:00
|
|
|
else
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << Type.getAsString();
|
|
|
|
return;
|
2008-11-18 01:58:34 +03:00
|
|
|
}
|
|
|
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
case CXXOperatorName: {
|
2009-12-23 20:49:57 +03:00
|
|
|
static const char* const OperatorNames[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
0,
|
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
Spelling,
|
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
};
|
|
|
|
const char *OpName = OperatorNames[getCXXOverloadedOperator()];
|
|
|
|
assert(OpName && "not an overloaded operator");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << "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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
if (OpName[0] >= 'a' && OpName[0] <= 'z')
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << ' ';
|
|
|
|
OS << OpName;
|
|
|
|
return;
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
}
|
|
|
|
|
2010-04-17 13:56:45 +04:00
|
|
|
case CXXLiteralOperatorName:
|
|
|
|
OS << "operator \"\" " << getCXXLiteralIdentifier()->getName();
|
|
|
|
return;
|
2009-11-29 10:34:05 +03:00
|
|
|
|
2008-11-18 01:58:34 +03:00
|
|
|
case CXXConversionFunctionName: {
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << "operator ";
|
2008-11-18 01:58:34 +03:00
|
|
|
QualType Type = getCXXNameType();
|
2009-07-30 01:53:49 +04:00
|
|
|
if (const RecordType *Rec = Type->getAs<RecordType>())
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << Rec->getDecl();
|
2008-11-18 01:58:34 +03:00
|
|
|
else
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << Type.getAsString();
|
|
|
|
return;
|
2008-11-18 01:58:34 +03:00
|
|
|
}
|
2009-02-03 22:21:40 +03:00
|
|
|
case CXXUsingDirective:
|
2010-04-17 13:56:45 +04:00
|
|
|
OS << "<using-directive>";
|
|
|
|
return;
|
2008-11-18 01:58:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(false && "Unexpected declaration name kind");
|
|
|
|
}
|
|
|
|
|
2008-11-17 17:58:09 +03:00
|
|
|
QualType DeclarationName::getCXXNameType() const {
|
|
|
|
if (CXXSpecialName *CXXName = getAsCXXSpecialName())
|
|
|
|
return CXXName->Type;
|
|
|
|
else
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
OverloadedOperatorKind DeclarationName::getCXXOverloadedOperator() const {
|
|
|
|
if (CXXOperatorIdName *CXXOp = getAsCXXOperatorIdName()) {
|
2009-09-09 19:08:12 +04: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
= CXXOp->ExtraKindOrNumArgs - DeclarationNameExtra::CXXConversionFunction;
|
|
|
|
return static_cast<OverloadedOperatorKind>(value);
|
|
|
|
} else {
|
|
|
|
return OO_None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-29 10:34:05 +03:00
|
|
|
IdentifierInfo *DeclarationName::getCXXLiteralIdentifier() const {
|
|
|
|
if (CXXLiteralOperatorIdName *CXXLit = getAsCXXLiteralOperatorIdName())
|
|
|
|
return CXXLit->ID;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-17 17:58:09 +03:00
|
|
|
Selector DeclarationName::getObjCSelector() const {
|
|
|
|
switch (getNameKind()) {
|
|
|
|
case ObjCZeroArgSelector:
|
|
|
|
return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 0);
|
|
|
|
|
|
|
|
case ObjCOneArgSelector:
|
|
|
|
return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 1);
|
|
|
|
|
|
|
|
case ObjCMultiArgSelector:
|
|
|
|
return Selector(reinterpret_cast<MultiKeywordSelector *>(Ptr & ~PtrMask));
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Selector();
|
|
|
|
}
|
|
|
|
|
2008-11-17 23:34:05 +03:00
|
|
|
void *DeclarationName::getFETokenInfoAsVoid() const {
|
|
|
|
switch (getNameKind()) {
|
|
|
|
case Identifier:
|
|
|
|
return getAsIdentifierInfo()->getFETokenInfo<void>();
|
|
|
|
|
|
|
|
case CXXConstructorName:
|
|
|
|
case CXXDestructorName:
|
|
|
|
case CXXConversionFunctionName:
|
|
|
|
return getAsCXXSpecialName()->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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
case CXXOperatorName:
|
|
|
|
return getAsCXXOperatorIdName()->FETokenInfo;
|
|
|
|
|
2009-11-29 10:34:05 +03:00
|
|
|
case CXXLiteralOperatorName:
|
|
|
|
return getCXXLiteralIdentifier()->getFETokenInfo<void>();
|
|
|
|
|
2008-11-17 23:34:05 +03:00
|
|
|
default:
|
|
|
|
assert(false && "Declaration name has no FETokenInfo");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationName::setFETokenInfo(void *T) {
|
|
|
|
switch (getNameKind()) {
|
|
|
|
case Identifier:
|
|
|
|
getAsIdentifierInfo()->setFETokenInfo(T);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CXXConstructorName:
|
|
|
|
case CXXDestructorName:
|
|
|
|
case CXXConversionFunctionName:
|
|
|
|
getAsCXXSpecialName()->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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
case CXXOperatorName:
|
|
|
|
getAsCXXOperatorIdName()->FETokenInfo = T;
|
|
|
|
break;
|
|
|
|
|
2009-11-29 10:34:05 +03:00
|
|
|
case CXXLiteralOperatorName:
|
|
|
|
getCXXLiteralIdentifier()->setFETokenInfo(T);
|
|
|
|
break;
|
|
|
|
|
2008-11-17 23:34:05 +03:00
|
|
|
default:
|
|
|
|
assert(false && "Declaration name has no FETokenInfo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 22:21:40 +03:00
|
|
|
DeclarationName DeclarationName::getUsingDirectiveName() {
|
|
|
|
// Single instance of DeclarationNameExtra for using-directive
|
2009-12-10 03:07:02 +03:00
|
|
|
static const DeclarationNameExtra UDirExtra =
|
2009-02-03 22:21:40 +03:00
|
|
|
{ DeclarationNameExtra::CXXUsingDirective };
|
|
|
|
|
|
|
|
uintptr_t Ptr = reinterpret_cast<uintptr_t>(&UDirExtra);
|
|
|
|
Ptr |= StoredDeclarationNameExtra;
|
|
|
|
|
|
|
|
return DeclarationName(Ptr);
|
|
|
|
}
|
|
|
|
|
2009-11-16 01:30:43 +03:00
|
|
|
void DeclarationName::dump() const {
|
2010-04-17 13:56:45 +04:00
|
|
|
printName(llvm::errs());
|
|
|
|
llvm::errs() << '\n';
|
2009-11-16 01:30:43 +03:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:06:06 +03:00
|
|
|
DeclarationNameTable::DeclarationNameTable(const ASTContext &C) : Ctx(C) {
|
2008-11-17 17:58:09 +03:00
|
|
|
CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
|
2010-01-13 12:01:02 +03:00
|
|
|
CXXLiteralOperatorNames = new llvm::FoldingSet<CXXLiteralOperatorIdName>;
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
|
|
|
|
// Initialize the overloaded operator names.
|
2010-05-11 00:56:10 +04: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) {
|
2009-09-09 19:08:12 +04: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
= Op + DeclarationNameExtra::CXXConversionFunction;
|
|
|
|
CXXOperatorNames[Op].FETokenInfo = 0;
|
|
|
|
}
|
2008-11-17 17:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DeclarationNameTable::~DeclarationNameTable() {
|
2010-01-13 12:01:02 +03:00
|
|
|
llvm::FoldingSet<CXXSpecialName> *SpecialNames =
|
2008-12-14 20:27:25 +03:00
|
|
|
static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
|
2010-05-11 00:56:10 +04:00
|
|
|
llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
|
|
|
|
= static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
|
|
|
|
(CXXLiteralOperatorNames);
|
2010-01-13 12:01:02 +03:00
|
|
|
|
|
|
|
delete SpecialNames;
|
|
|
|
delete LiteralNames;
|
2010-05-11 00:40:08 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
DeclarationName
|
|
|
|
DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind,
|
2009-08-05 09:36:45 +04:00
|
|
|
CanQualType Ty) {
|
2008-11-17 17:58:09 +03:00
|
|
|
assert(Kind >= DeclarationName::CXXConstructorName &&
|
|
|
|
Kind <= DeclarationName::CXXConversionFunctionName &&
|
|
|
|
"Kind must be a C++ special name kind");
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::FoldingSet<CXXSpecialName> *SpecialNames
|
2008-11-17 17:58:09 +03:00
|
|
|
= static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
|
|
|
|
|
|
|
|
DeclarationNameExtra::ExtraKind EKind;
|
|
|
|
switch (Kind) {
|
2009-09-09 19:08:12 +04:00
|
|
|
case DeclarationName::CXXConstructorName:
|
2008-11-17 17:58:09 +03:00
|
|
|
EKind = DeclarationNameExtra::CXXConstructor;
|
2009-09-24 23:53:00 +04:00
|
|
|
assert(!Ty.hasQualifiers() &&"Constructor type must be unqualified");
|
2008-11-17 17:58:09 +03:00
|
|
|
break;
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
EKind = DeclarationNameExtra::CXXDestructor;
|
2009-09-24 23:53:00 +04:00
|
|
|
assert(!Ty.hasQualifiers() && "Destructor type must be unqualified");
|
2008-11-17 17:58:09 +03: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());
|
|
|
|
|
|
|
|
void *InsertPos = 0;
|
|
|
|
if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos))
|
|
|
|
return DeclarationName(Name);
|
|
|
|
|
2010-05-11 00:56:10 +04:00
|
|
|
CXXSpecialName *SpecialName = new (Ctx) CXXSpecialName;
|
2008-11-17 17:58:09 +03:00
|
|
|
SpecialName->ExtraKindOrNumArgs = EKind;
|
|
|
|
SpecialName->Type = Ty;
|
2008-11-17 23:34:05 +03:00
|
|
|
SpecialName->FETokenInfo = 0;
|
2008-11-17 17:58:09 +03:00
|
|
|
|
|
|
|
SpecialNames->InsertNode(SpecialName, InsertPos);
|
|
|
|
return DeclarationName(SpecialName);
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
DeclarationNameTable::getCXXOperatorName(OverloadedOperatorKind Op) {
|
|
|
|
return DeclarationName(&CXXOperatorNames[(unsigned)Op]);
|
|
|
|
}
|
|
|
|
|
2009-11-29 10:34:05 +03:00
|
|
|
DeclarationName
|
|
|
|
DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) {
|
2010-01-13 12:01:02 +03:00
|
|
|
llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
|
|
|
|
= static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
|
|
|
|
(CXXLiteralOperatorNames);
|
|
|
|
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
ID.AddPointer(II);
|
|
|
|
|
|
|
|
void *InsertPos = 0;
|
|
|
|
if (CXXLiteralOperatorIdName *Name =
|
|
|
|
LiteralNames->FindNodeOrInsertPos(ID, InsertPos))
|
|
|
|
return DeclarationName (Name);
|
|
|
|
|
2010-05-11 00:56:10 +04:00
|
|
|
CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName;
|
2009-11-29 10:34:05 +03:00
|
|
|
LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator;
|
|
|
|
LiteralName->ID = II;
|
2010-01-13 12:01:02 +03:00
|
|
|
|
|
|
|
LiteralNames->InsertNode(LiteralName, InsertPos);
|
2009-11-29 10:34:05 +03:00
|
|
|
return DeclarationName(LiteralName);
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
unsigned
|
2008-12-11 19:49:14 +03:00
|
|
|
llvm::DenseMapInfo<clang::DeclarationName>::
|
|
|
|
getHashValue(clang::DeclarationName N) {
|
|
|
|
return DenseMapInfo<void*>::getHashValue(N.getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 04:34:56 +03: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:
|
|
|
|
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 10:29:18 +03:00
|
|
|
llvm_unreachable("All name kinds handled.");
|
2010-12-15 04:34:56 +03:00
|
|
|
}
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
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();
|
|
|
|
}
|