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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/AST/DeclarationName.h"
|
2008-11-18 01:58:34 +03:00
|
|
|
#include "clang/AST/Type.h"
|
|
|
|
#include "clang/AST/Decl.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"
|
|
|
|
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.
|
|
|
|
class CXXSpecialName
|
|
|
|
: 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
|
|
|
|
/// overloaded operator in C++, such as "operator+.
|
|
|
|
class CXXOperatorIdName : public DeclarationNameExtra {
|
|
|
|
public:
|
|
|
|
/// FETokenInfo - Extra information associated with this operator
|
|
|
|
/// name that can be used by the front end.
|
|
|
|
void *FETokenInfo;
|
|
|
|
};
|
|
|
|
|
2008-11-17 17:58:09 +03:00
|
|
|
bool operator<(DeclarationName LHS, DeclarationName RHS) {
|
|
|
|
if (IdentifierInfo *LhsId = LHS.getAsIdentifierInfo())
|
|
|
|
if (IdentifierInfo *RhsId = RHS.getAsIdentifierInfo())
|
|
|
|
return strcmp(LhsId->getName(), RhsId->getName()) < 0;
|
|
|
|
|
|
|
|
return LHS.getAsOpaqueInteger() < RHS.getAsOpaqueInteger();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
DeclarationName::DeclarationName(Selector Sel) {
|
2009-04-24 02:29:11 +04:00
|
|
|
if (!Sel.getAsOpaquePtr()) {
|
|
|
|
Ptr = StoredObjCZeroArgSelector;
|
|
|
|
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) {
|
|
|
|
case DeclarationNameExtra::CXXConstructor:
|
|
|
|
return CXXConstructorName;
|
|
|
|
|
|
|
|
case DeclarationNameExtra::CXXDestructor:
|
|
|
|
return CXXDestructorName;
|
|
|
|
|
|
|
|
case DeclarationNameExtra::CXXConversionFunction:
|
|
|
|
return CXXConversionFunctionName;
|
|
|
|
|
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.
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-11-18 01:58:34 +03:00
|
|
|
std::string DeclarationName::getAsString() const {
|
|
|
|
switch (getNameKind()) {
|
|
|
|
case Identifier:
|
|
|
|
if (const IdentifierInfo *II = getAsIdentifierInfo())
|
|
|
|
return II->getName();
|
|
|
|
return "";
|
|
|
|
|
|
|
|
case ObjCZeroArgSelector:
|
|
|
|
case ObjCOneArgSelector:
|
|
|
|
case ObjCMultiArgSelector:
|
2008-11-24 06:33:13 +03:00
|
|
|
return getObjCSelector().getAsString();
|
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>())
|
2008-11-24 07:00:27 +03:00
|
|
|
return ClassRec->getDecl()->getNameAsString();
|
2008-11-18 01:58:34 +03:00
|
|
|
return ClassType.getAsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXXDestructorName: {
|
|
|
|
std::string Result = "~";
|
|
|
|
QualType Type = getCXXNameType();
|
2009-07-30 01:53:49 +04:00
|
|
|
if (const RecordType *Rec = Type->getAs<RecordType>())
|
2008-11-24 07:00:27 +03:00
|
|
|
Result += Rec->getDecl()->getNameAsString();
|
2008-11-18 01:58:34 +03:00
|
|
|
else
|
|
|
|
Result += Type.getAsString();
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
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: {
|
|
|
|
static const char *OperatorNames[NUM_OVERLOADED_OPERATORS] = {
|
|
|
|
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");
|
|
|
|
|
|
|
|
std::string Result = "operator";
|
|
|
|
if (OpName[0] >= 'a' && OpName[0] <= 'z')
|
|
|
|
Result += ' ';
|
|
|
|
Result += OpName;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2008-11-18 01:58:34 +03:00
|
|
|
case CXXConversionFunctionName: {
|
|
|
|
std::string Result = "operator ";
|
|
|
|
QualType Type = getCXXNameType();
|
2009-07-30 01:53:49 +04:00
|
|
|
if (const RecordType *Rec = Type->getAs<RecordType>())
|
2008-11-24 07:00:27 +03:00
|
|
|
Result += Rec->getDecl()->getNameAsString();
|
2008-11-18 01:58:34 +03:00
|
|
|
else
|
|
|
|
Result += Type.getAsString();
|
|
|
|
return Result;
|
|
|
|
}
|
2009-02-03 22:21:40 +03:00
|
|
|
case CXXUsingDirective:
|
|
|
|
return "<using-directive>";
|
2008-11-18 01:58:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(false && "Unexpected declaration name kind");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
unsigned value
|
|
|
|
= CXXOp->ExtraKindOrNumArgs - DeclarationNameExtra::CXXConversionFunction;
|
|
|
|
return static_cast<OverloadedOperatorKind>(value);
|
|
|
|
} else {
|
|
|
|
return OO_None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
static DeclarationNameExtra UDirExtra =
|
|
|
|
{ DeclarationNameExtra::CXXUsingDirective };
|
|
|
|
|
|
|
|
uintptr_t Ptr = reinterpret_cast<uintptr_t>(&UDirExtra);
|
|
|
|
Ptr |= StoredDeclarationNameExtra;
|
|
|
|
|
|
|
|
return DeclarationName(Ptr);
|
|
|
|
}
|
|
|
|
|
2008-11-17 17:58:09 +03:00
|
|
|
DeclarationNameTable::DeclarationNameTable() {
|
|
|
|
CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
|
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.
|
|
|
|
CXXOperatorNames = new CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
|
|
|
|
for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) {
|
|
|
|
CXXOperatorNames[Op].ExtraKindOrNumArgs
|
|
|
|
= Op + DeclarationNameExtra::CXXConversionFunction;
|
|
|
|
CXXOperatorNames[Op].FETokenInfo = 0;
|
|
|
|
}
|
2008-11-17 17:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DeclarationNameTable::~DeclarationNameTable() {
|
2008-12-14 20:27:25 +03:00
|
|
|
llvm::FoldingSet<CXXSpecialName> *set =
|
|
|
|
static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
|
2008-12-15 00:53:25 +03:00
|
|
|
llvm::FoldingSetIterator<CXXSpecialName> I = set->begin(), E = set->end();
|
2008-12-14 20:27:25 +03:00
|
|
|
|
2008-12-15 00:53:25 +03:00
|
|
|
while (I != E) {
|
|
|
|
CXXSpecialName *n = &*I++;
|
|
|
|
delete n;
|
2008-12-14 20:27:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
delete set;
|
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
|
|
|
delete [] CXXOperatorNames;
|
2008-11-17 17:58:09 +03: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");
|
|
|
|
llvm::FoldingSet<CXXSpecialName> *SpecialNames
|
|
|
|
= static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
|
|
|
|
|
|
|
|
DeclarationNameExtra::ExtraKind EKind;
|
|
|
|
switch (Kind) {
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
EKind = DeclarationNameExtra::CXXConstructor;
|
2009-02-17 01:33:34 +03:00
|
|
|
assert(Ty.getCVRQualifiers() == 0 &&"Constructor type must be unqualified");
|
2008-11-17 17:58:09 +03:00
|
|
|
break;
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
EKind = DeclarationNameExtra::CXXDestructor;
|
2009-01-13 03:11:19 +03:00
|
|
|
assert(Ty.getCVRQualifiers() == 0 && "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);
|
|
|
|
|
|
|
|
CXXSpecialName *SpecialName = new CXXSpecialName;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
DeclarationName
|
|
|
|
DeclarationNameTable::getCXXOperatorName(OverloadedOperatorKind Op) {
|
|
|
|
return DeclarationName(&CXXOperatorNames[(unsigned)Op]);
|
|
|
|
}
|
|
|
|
|
2008-12-11 19:49:14 +03:00
|
|
|
unsigned
|
|
|
|
llvm::DenseMapInfo<clang::DeclarationName>::
|
|
|
|
getHashValue(clang::DeclarationName N) {
|
|
|
|
return DenseMapInfo<void*>::getHashValue(N.getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
|