[cfe-commits] r59462 - in /cfe/trunk: docs/InternalsManual.html include/clang/AST/DeclBase.h include/clang/AST/DeclarationName.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h lib/AST/DeclarationName.cpp lib/Parse/MinimalAction.cpp lib/Parse/ParseExprCXX.cpp lib/Sema/IdentifierResolver.cpp lib/Sema/IdentifierResolver.h lib/Sema/Sema.h lib/Sema/SemaCXXScopeSpec.cpp lib/Sema/SemaChecking.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaExprCXX.cpp test/SemaCXX/conversion-function.cpp

Douglas Gregor doug.gregor at gmail.com
Mon Nov 17 12:34:12 PST 2008


Author: dgregor
Date: Mon Nov 17 14:34:05 2008
New Revision: 59462

URL: http://llvm.org/viewvc/llvm-project?rev=59462&view=rev
Log:
Updated IdentifierResolver to deal with DeclarationNames. The names of
C++ constructors, destructors, and conversion functions now have a
FETokenInfo field that IdentifierResolver can access, so that these
special names are handled just like ordinary identifiers. A few other
Sema routines now use DeclarationNames instead of IdentifierInfo*'s.

To validate this design, this code also implements parsing and
semantic analysis for id-expressions that name conversion functions,
e.g.,

  return operator bool();

The new parser action ActOnConversionFunctionExpr takes the result of
parsing "operator type-id" and turning it into an expression, using
the IdentifierResolver with the DeclarationName of the conversion
function. ActOnDeclarator pushes those conversion function names into
scope so that the IdentifierResolver can find them, of course.


Modified:
    cfe/trunk/docs/InternalsManual.html
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/include/clang/AST/DeclarationName.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/lib/AST/DeclarationName.cpp
    cfe/trunk/lib/Parse/MinimalAction.cpp
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/lib/Sema/IdentifierResolver.cpp
    cfe/trunk/lib/Sema/IdentifierResolver.h
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/conversion-function.cpp

Modified: cfe/trunk/docs/InternalsManual.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/InternalsManual.html?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/docs/InternalsManual.html (original)
+++ cfe/trunk/docs/InternalsManual.html Mon Nov 17 14:34:05 2008
@@ -468,7 +468,7 @@
 
 <p>Given
   a <code>DeclarationName</code> <code>N</code>, <code>N.getNameKind()</code>
-  will produce a valid that describes what kind of name <code>N</code>
+  will produce a value that describes what kind of name <code>N</code>
   stores. There are 7 options (all of the names are inside
   the <code>DeclarationName</code> class)</p>
 <dl>

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Mon Nov 17 14:34:05 2008
@@ -185,6 +185,7 @@
     case OverloadedFunction:
     case CXXField:
     case CXXMethod:
+    case CXXConversion:
     case CXXClassVar:
       return IDNS_Ordinary;
     case Record:

Modified: cfe/trunk/include/clang/AST/DeclarationName.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclarationName.h?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclarationName.h (original)
+++ cfe/trunk/include/clang/AST/DeclarationName.h Mon Nov 17 14:34:05 2008
@@ -138,6 +138,10 @@
 
   friend class DeclarationNameTable;
 
+  /// getFETokenInfoAsVoid - Retrieves the front end-specified pointer
+  /// for this name as a void pointer.
+  void *getFETokenInfoAsVoid() const;
+
 public:
   /// DeclarationName - Used to create an empty selector.
   DeclarationName() : Ptr(0) { }
@@ -150,6 +154,13 @@
   // Construct a declaration name from an Objective-C selector.
   DeclarationName(Selector Sel);
 
+  // operator bool() - Evaluates true when this declaration name is
+  // non-empty.
+  operator bool() const { 
+    return ((Ptr & PtrMask) != 0) || 
+           (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
+  }
+
   /// getNameKind - Determine what kind of name this is.
   NameKind getNameKind() const;
 
@@ -176,6 +187,15 @@
   /// declaration name.
   Selector getObjCSelector() const;
 
+  /// getFETokenInfo/setFETokenInfo - The language front-end is
+  /// allowed to associate arbitrary metadata with some kinds of
+  /// declaration names, including normal identifiers and C++
+  /// constructors, destructors, and conversion functions.
+  template<typename T>
+  T *getFETokenInfo() const { return static_cast<T*>(getFETokenInfoAsVoid()); }
+
+  void setFETokenInfo(void *T);
+
   /// operator== - Determine whether the specified names are identical..
   friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
     return LHS.Ptr == RHS.Ptr;

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Mon Nov 17 14:34:05 2008
@@ -1375,9 +1375,12 @@
 DIAG(warn_conv_to_self_not_used, WARNING,
      "conversion function converting '%0' to itself will never be used")
 DIAG(warn_conv_to_base_not_used, WARNING,
-     "conversion function converting '%0' to its base class '%1' will never be used")
+     "conversion function converting '%0' to its base class '%1' will never "
+     "be used")
 DIAG(warn_conv_to_void_not_used, WARNING,
      "conversion function converting '%0' to '%1' will never be used")
+DIAG(err_no_conv_function, ERROR,
+     "no conversion function to type '%0'")
 
 
 DIAG(warn_not_compound_assign, WARNING,

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Mon Nov 17 14:34:05 2008
@@ -108,7 +108,7 @@
   /// An optional CXXScopeSpec can be passed to indicate the C++ scope (class or
   /// namespace) that the identifier must be a member of.
   /// i.e. for "foo::bar", 'II' will be "bar" and 'SS' will be "foo::".
-  virtual TypeTy *isTypeName(const IdentifierInfo &II, Scope *S,
+  virtual TypeTy *isTypeName(IdentifierInfo &II, Scope *S,
                              const CXXScopeSpec *SS = 0) = 0;
 
   /// isCurrentClassName - Return true if the specified name is the
@@ -133,7 +133,7 @@
                                                   const CXXScopeSpec &SS,
                                                   SourceLocation IdLoc,
                                                   SourceLocation CCLoc,
-                                                  const IdentifierInfo &II) {
+                                                  IdentifierInfo &II) {
     return 0;
   }
 
@@ -461,6 +461,19 @@
     return 0;
   }
   
+  /// ActOnConversionFunctionExpr - Parse a C++ conversion function
+  /// name (e.g., operator void const *) as an expression. This is
+  /// very similar to ActOnIdentifierExpr, except that instead of
+  /// providing an identifier the parser provides the type of the
+  /// conversion function.
+  virtual ExprResult ActOnConversionFunctionExpr(Scope *S, 
+                                                 SourceLocation OperatorLoc,
+                                                 TypeTy *Type,
+                                                 bool HasTrailingLParen,
+                                                 const CXXScopeSpec *SS = 0) {
+    return 0;
+  }
+
   virtual ExprResult ActOnPredefinedExpr(SourceLocation Loc,
                                          tok::TokenKind Kind) {
     return 0;
@@ -1016,7 +1029,7 @@
   
   /// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
   /// determine whether the name is a typedef or not in this scope.
-  virtual TypeTy *isTypeName(const IdentifierInfo &II, Scope *S,
+  virtual TypeTy *isTypeName(IdentifierInfo &II, Scope *S,
                              const CXXScopeSpec *SS);
 
   /// isCurrentClassName - Always returns false, because MinimalAction

Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Mon Nov 17 14:34:05 2008
@@ -25,8 +25,13 @@
 class CXXSpecialName 
   : public DeclarationNameExtra, public llvm::FoldingSetNode {
 public:
+  /// Type - The type associated with this declaration name.
   QualType Type;
 
+  /// FETokenInfo - Extra information associated with this declaration
+  /// name that can be used by the front end.
+  void *FETokenInfo;
+
   void Profile(llvm::FoldingSetNodeID &ID) {
     ID.AddInteger(ExtraKindOrNumArgs);
     ID.AddPointer(Type.getAsOpaquePtr());
@@ -114,6 +119,39 @@
   return Selector();
 }
 
+void *DeclarationName::getFETokenInfoAsVoid() const {
+  switch (getNameKind()) {
+  case Identifier:
+    return getAsIdentifierInfo()->getFETokenInfo<void>();
+
+  case CXXConstructorName:
+  case CXXDestructorName:
+  case CXXConversionFunctionName:
+    return getAsCXXSpecialName()->FETokenInfo;
+
+  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;
+
+  default:
+    assert(false && "Declaration name has no FETokenInfo");
+  }
+}
+
 DeclarationNameTable::DeclarationNameTable() {
   CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
 }
@@ -159,6 +197,7 @@
   CXXSpecialName *SpecialName = new CXXSpecialName;
   SpecialName->ExtraKindOrNumArgs = EKind;
   SpecialName->Type = Ty;
+  SpecialName->FETokenInfo = 0;
 
   SpecialNames->InsertNode(SpecialName, InsertPos);
   return DeclarationName(SpecialName);

Modified: cfe/trunk/lib/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/MinimalAction.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/MinimalAction.cpp (original)
+++ cfe/trunk/lib/Parse/MinimalAction.cpp Mon Nov 17 14:34:05 2008
@@ -58,7 +58,7 @@
 ///
 /// FIXME: Use the passed CXXScopeSpec for accurate C++ type checking.
 Action::TypeTy *
-MinimalAction::isTypeName(const IdentifierInfo &II, Scope *S,
+MinimalAction::isTypeName(IdentifierInfo &II, Scope *S,
                           const CXXScopeSpec *SS) {
   if (TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>())
     if (TI->isTypeName)

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon Nov 17 14:34:05 2008
@@ -131,7 +131,7 @@
   // unqualified-id:
   //   identifier
   //   operator-function-id
-  //   conversion-function-id                [TODO]
+  //   conversion-function-id
   //   '~' class-name                        [TODO]
   //   template-id                           [TODO]
   //
@@ -152,11 +152,15 @@
     if (IdentifierInfo *II = TryParseOperatorFunctionId()) {
       return Actions.ActOnIdentifierExpr(CurScope, OperatorLoc, *II, 
                                          Tok.is(tok::l_paren), &SS);
+    } else if (TypeTy *Type = ParseConversionFunctionId()) {
+      return Actions.ActOnConversionFunctionExpr(CurScope, OperatorLoc,
+                                                 Type, Tok.is(tok::l_paren), 
+                                                 &SS);
     }
-    // FIXME: Handle conversion-function-id.
-    unsigned DiagID = PP.getDiagnostics().getCustomDiagID(Diagnostic::Error,
-                                    "expected operator-function-id");
-    return Diag(Tok, DiagID);
+     
+    // We already complained about a bad conversion-function-id,
+    // above.
+    return true;
   }
 
   } // switch.

Modified: cfe/trunk/lib/Sema/IdentifierResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/IdentifierResolver.cpp (original)
+++ cfe/trunk/lib/Sema/IdentifierResolver.cpp Mon Nov 17 14:34:05 2008
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 //
 // This file implements the IdentifierResolver class, which is used for lexical
-// scoped lookup, based on identifier.
+// scoped lookup, based on declaration names.
 //
 //===----------------------------------------------------------------------===//
 
@@ -23,7 +23,7 @@
 // IdDeclInfoMap class
 //===----------------------------------------------------------------------===//
 
-/// IdDeclInfoMap - Associates IdDeclInfos with Identifiers.
+/// IdDeclInfoMap - Associates IdDeclInfos with declaration names.
 /// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each
 /// individual IdDeclInfo to heap.
 class IdentifierResolver::IdDeclInfoMap {
@@ -36,9 +36,9 @@
 public:
   IdDeclInfoMap() : CurIndex(VECTOR_SIZE) {}
 
-  /// Returns the IdDeclInfo associated to the IdentifierInfo.
+  /// Returns the IdDeclInfo associated to the DeclarationName.
   /// It creates a new IdDeclInfo if one was not created before for this id.
-  IdDeclInfo &operator[](IdentifierInfo *II);
+  IdDeclInfo &operator[](DeclarationName Name);
 };
 
 
@@ -173,19 +173,19 @@
 
 /// AddDecl - Link the decl to its shadowed decl chain.
 void IdentifierResolver::AddDecl(NamedDecl *D) {
-  IdentifierInfo *II = D->getIdentifier();
-  void *Ptr = II->getFETokenInfo<void>();
+  DeclarationName Name = D->getDeclName();
+  void *Ptr = Name.getFETokenInfo<void>();
 
   if (!Ptr) {
-    II->setFETokenInfo(D);
+    Name.setFETokenInfo(D);
     return;
   }
 
   IdDeclInfo *IDI;
 
   if (isDeclPtr(Ptr)) {
-    II->setFETokenInfo(NULL);
-    IDI = &(*IdDeclInfos)[II];
+    Name.setFETokenInfo(NULL);
+    IDI = &(*IdDeclInfos)[Name];
     NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
     IDI->AddDecl(PrevD);
   } else
@@ -198,18 +198,18 @@
 /// after the decl that the iterator points to, thus the 'Shadow' decl will be
 /// encountered before the 'D' decl.
 void IdentifierResolver::AddShadowedDecl(NamedDecl *D, NamedDecl *Shadow) {
-  assert(D->getIdentifier() == Shadow->getIdentifier() && "Different ids!");
+  assert(D->getDeclName() == Shadow->getDeclName() && "Different ids!");
   assert(LookupContext(D) == LookupContext(Shadow) && "Different context!");
 
-  IdentifierInfo *II = D->getIdentifier();
-  void *Ptr = II->getFETokenInfo<void>();
+  DeclarationName Name = D->getDeclName();
+  void *Ptr = Name.getFETokenInfo<void>();
   assert(Ptr && "No decl from Ptr ?");
 
   IdDeclInfo *IDI;
 
   if (isDeclPtr(Ptr)) {
-    II->setFETokenInfo(NULL);
-    IDI = &(*IdDeclInfos)[II];
+    Name.setFETokenInfo(NULL);
+    IDI = &(*IdDeclInfos)[Name];
     NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
     assert(PrevD == Shadow && "Invalid shadow decl ?");
     IDI->AddDecl(D);
@@ -225,29 +225,29 @@
 /// The decl must already be part of the decl chain.
 void IdentifierResolver::RemoveDecl(NamedDecl *D) {
   assert(D && "null param passed");
-  IdentifierInfo *II = D->getIdentifier();
-  void *Ptr = II->getFETokenInfo<void>();
+  DeclarationName Name = D->getDeclName();
+  void *Ptr = Name.getFETokenInfo<void>();
 
   assert(Ptr && "Didn't find this decl on its identifier's chain!");
 
   if (isDeclPtr(Ptr)) {
     assert(D == Ptr && "Didn't find this decl on its identifier's chain!");
-    II->setFETokenInfo(NULL);
+    Name.setFETokenInfo(NULL);
     return;
   }
   
   return toIdDeclInfo(Ptr)->RemoveDecl(D);
 }
 
-/// begin - Returns an iterator for decls of identifier 'II', starting at
+/// begin - Returns an iterator for decls with name 'Name', starting at
 /// declaration context 'Ctx'. If 'LookInParentCtx' is true, it will walk the
 /// decls of parent declaration contexts too.
 IdentifierResolver::iterator
-IdentifierResolver::begin(const IdentifierInfo *II, const DeclContext *Ctx,
+IdentifierResolver::begin(DeclarationName Name, const DeclContext *Ctx,
                           bool LookInParentCtx) {
   assert(Ctx && "null param passed");
 
-  void *Ptr = II->getFETokenInfo<void>();
+  void *Ptr = Name.getFETokenInfo<void>();
   if (!Ptr) return end();
 
   LookupContext LC(Ctx);
@@ -284,7 +284,7 @@
 void IdentifierResolver::iterator::PreIncIter() {
   NamedDecl *D = **this;
   LookupContext Ctx(D);
-  void *InfoPtr = D->getIdentifier()->getFETokenInfo<void>();
+  void *InfoPtr = D->getDeclName().getFETokenInfo<void>();
   assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
   IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
 
@@ -310,12 +310,11 @@
 // IdDeclInfoMap Implementation
 //===----------------------------------------------------------------------===//
 
-/// Returns the IdDeclInfo associated to the IdentifierInfo.
+/// Returns the IdDeclInfo associated to the DeclarationName.
 /// It creates a new IdDeclInfo if one was not created before for this id.
 IdentifierResolver::IdDeclInfo &
-IdentifierResolver::IdDeclInfoMap::operator[](IdentifierInfo *II) {
-  assert (II && "null IdentifierInfo passed");
-  void *Ptr = II->getFETokenInfo<void>();
+IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) {
+  void *Ptr = Name.getFETokenInfo<void>();
 
   if (Ptr) return *toIdDeclInfo(Ptr);
 
@@ -327,7 +326,7 @@
     CurIndex = 0;
   }
   IdDeclInfo *IDI = &IDIVecs.back()[CurIndex];
-  II->setFETokenInfo(reinterpret_cast<void*>(
+  Name.setFETokenInfo(reinterpret_cast<void*>(
                               reinterpret_cast<uintptr_t>(IDI) | 0x1)
                                                                      );
   ++CurIndex;

Modified: cfe/trunk/lib/Sema/IdentifierResolver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.h?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/IdentifierResolver.h (original)
+++ cfe/trunk/lib/Sema/IdentifierResolver.h Mon Nov 17 14:34:05 2008
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 //
 // This file defines the IdentifierResolver class, which is used for lexical
-// scoped lookup, based on identifier.
+// scoped lookup, based on declaration names.
 //
 //===----------------------------------------------------------------------===//
 
@@ -18,13 +18,14 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Parse/Scope.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/DeclCXX.h"
 
 namespace clang {
 
-/// IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
-/// It manages the shadowing chains of identifiers and implements efficent decl
-/// lookup based on an identifier.
+/// IdentifierResolver - Keeps track of shadowed decls on enclosing
+/// scopes.  It manages the shadowing chains of declaration names and
+/// implements efficent decl lookup based on a declaration name.
 class IdentifierResolver {
 
   /// LookupContext - A wrapper for DeclContext. DeclContext is only part of
@@ -79,10 +80,10 @@
     }
   };
 
-  /// IdDeclInfo - Keeps track of information about decls associated to a
-  /// particular identifier. IdDeclInfos are lazily constructed and assigned
-  /// to an identifier the first time a decl with that identifier is shadowed
-  /// in some scope.
+  /// IdDeclInfo - Keeps track of information about decls associated
+  /// to a particular declaration name. IdDeclInfos are lazily
+  /// constructed and assigned to a declaration name the first time a
+  /// decl with that declaration name is shadowed in some scope.
   class IdDeclInfo {
   public:
     typedef llvm::SmallVector<NamedDecl*, 2> DeclsTy;
@@ -123,7 +124,7 @@
 
 public:
 
-  /// iterator - Iterate over the decls of a specified identifier.
+  /// iterator - Iterate over the decls of a specified declaration name.
   /// It will walk or not the parent declaration contexts depending on how
   /// it was instantiated.
   class iterator {
@@ -192,11 +193,11 @@
     void PreIncIter();
   };
 
-  /// begin - Returns an iterator for decls of identifier 'II', starting at
+  /// begin - Returns an iterator for decls with the name 'Name', starting at
   /// declaration context 'Ctx'. If 'LookInParentCtx' is true, it will walk the
   /// decls of parent declaration contexts too.
   /// Default for 'LookInParentCtx is true.
-  static iterator begin(const IdentifierInfo *II, const DeclContext *Ctx,
+  static iterator begin(DeclarationName Name, const DeclContext *Ctx,
                         bool LookInParentCtx = true);
 
   /// end - Returns an iterator that has 'finished'.
@@ -230,12 +231,12 @@
   class IdDeclInfoMap;
   IdDeclInfoMap *IdDeclInfos;
 
-  /// Identifier's FETokenInfo contains a Decl pointer if lower bit == 0.
+  /// FETokenInfo contains a Decl pointer if lower bit == 0.
   static inline bool isDeclPtr(void *Ptr) {
     return (reinterpret_cast<uintptr_t>(Ptr) & 0x1) == 0;
   }
 
-  /// Identifier's FETokenInfo contains a IdDeclInfo pointer if lower bit == 1.
+  /// FETokenInfo contains a IdDeclInfo pointer if lower bit == 1.
   static inline IdDeclInfo *toIdDeclInfo(void *Ptr) {
     assert((reinterpret_cast<uintptr_t>(Ptr) & 0x1) == 1
           && "Ptr not a IdDeclInfo* !");

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Nov 17 14:34:05 2008
@@ -282,7 +282,7 @@
   //===--------------------------------------------------------------------===//
   // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
   //
-  virtual TypeTy *isTypeName(const IdentifierInfo &II, Scope *S,
+  virtual TypeTy *isTypeName(IdentifierInfo &II, Scope *S,
                              const CXXScopeSpec *SS);
   virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
   virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
@@ -462,7 +462,7 @@
   void CheckExtraCXXDefaultArguments(Declarator &D);
 
   /// More parsing and symbol table subroutines...
-  Decl *LookupDecl(const IdentifierInfo *II, unsigned NSI, Scope *S,
+  Decl *LookupDecl(DeclarationName Name, unsigned NSI, Scope *S,
                    const DeclContext *LookupCtx = 0,
                    bool enableLazyBuiltinCreation = true);
   ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
@@ -614,6 +614,11 @@
                                          IdentifierInfo &II,
                                          bool HasTrailingLParen,
                                          const CXXScopeSpec *SS = 0);
+  virtual ExprResult ActOnConversionFunctionExpr(Scope *S, 
+                                                 SourceLocation OperatorLoc,
+                                                 TypeTy *Ty,
+                                                 bool HasTrailingLParen,
+                                                 const CXXScopeSpec *SS);
   virtual ExprResult ActOnPredefinedExpr(SourceLocation Loc,
                                          tok::TokenKind Kind);
   virtual ExprResult ActOnNumericConstant(const Token &);
@@ -820,7 +825,7 @@
                                                   const CXXScopeSpec &SS,
                                                   SourceLocation IdLoc,
                                                   SourceLocation CCLoc,
-                                                  const IdentifierInfo &II);
+                                                  IdentifierInfo &II);
 
   /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
   /// scope or nested-name-specifier) is parsed, part of a declarator-id.

Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Mon Nov 17 14:34:05 2008
@@ -20,9 +20,9 @@
 
 namespace {
   Decl *LookupNestedName(DeclContext *LookupCtx, bool LookInParentCtx,
-                         const IdentifierInfo &II, bool &IdIsUndeclared) {
+                         DeclarationName Name, bool &IdIsUndeclared) {
     IdentifierResolver::iterator
-      I = IdentifierResolver::begin(&II, LookupCtx, LookInParentCtx),
+      I = IdentifierResolver::begin(Name, LookupCtx, LookInParentCtx),
       E = IdentifierResolver::end();
 
     if (I == E) {
@@ -67,15 +67,16 @@
                                                     const CXXScopeSpec &SS,
                                                     SourceLocation IdLoc,
                                                     SourceLocation CCLoc,
-                                                    const IdentifierInfo &II) {
+                                                    IdentifierInfo &II) {
   DeclContext *DC = static_cast<DeclContext*>(SS.getScopeRep());
   Decl *SD;
   bool IdIsUndeclared;
 
   if (DC)
-    SD = LookupNestedName(DC, false/*LookInParentCtx*/, II, IdIsUndeclared);
+    SD = LookupNestedName(DC, false/*LookInParentCtx*/, &II, IdIsUndeclared);
   else
-    SD = LookupNestedName(CurContext, true/*LookInParent*/, II, IdIsUndeclared);
+    SD = LookupNestedName(CurContext, true/*LookInParent*/, &II, 
+                          IdIsUndeclared);
 
   if (SD) {
     if (TypedefDecl *TD = dyn_cast<TypedefDecl>(SD)) {

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Nov 17 14:34:05 2008
@@ -29,7 +29,12 @@
   llvm::OwningPtr<CallExpr> TheCall(TheCallRaw);
   // Get the IdentifierInfo* for the called function.
   IdentifierInfo *FnInfo = FDecl->getIdentifier();
-  
+
+  // None of the checks below are needed for functions that don't have
+  // simple names (e.g., C++ conversion functions).
+  if (!FnInfo)
+    return TheCall.take();
+
   switch (FnInfo->getBuiltinID()) {
   case Builtin::BI__builtin___CFStringMakeConstantString:
     assert(TheCall->getNumArgs() == 1 &&

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Nov 17 14:34:05 2008
@@ -28,7 +28,7 @@
 #include "llvm/ADT/StringExtras.h"
 using namespace clang;
 
-Sema::TypeTy *Sema::isTypeName(const IdentifierInfo &II, Scope *S,
+Sema::TypeTy *Sema::isTypeName(IdentifierInfo &II, Scope *S,
                                const CXXScopeSpec *SS) {
   DeclContext *DC = 0;
   if (SS) {
@@ -113,7 +113,7 @@
     // We are pushing the name of a function, which might be an
     // overloaded name.
     IdentifierResolver::iterator
-        I = IdResolver.begin(FD->getIdentifier(),
+        I = IdResolver.begin(FD->getDeclName(),
                              FD->getDeclContext(), false/*LookInParentCtx*/);
     if (I != IdResolver.end() &&
         IdResolver.isDeclInScope(*I, FD->getDeclContext(), S) &&
@@ -126,7 +126,7 @@
         // FunctionDecl and put it into an OverloadedFunctionDecl.
         Ovl = OverloadedFunctionDecl::Create(Context, 
                                              FD->getDeclContext(),
-                                             FD->getIdentifier());
+                                             FD->getDeclName());
         Ovl->addOverload(dyn_cast<FunctionDecl>(*I));
         
         // Remove the name binding to the existing FunctionDecl...
@@ -187,17 +187,17 @@
 
 /// LookupDecl - Look up the inner-most declaration in the specified
 /// namespace.
-Decl *Sema::LookupDecl(const IdentifierInfo *II, unsigned NSI, Scope *S,
+Decl *Sema::LookupDecl(DeclarationName Name, unsigned NSI, Scope *S,
                        const DeclContext *LookupCtx,
                        bool enableLazyBuiltinCreation) {
-  if (II == 0) return 0;
+  if (!Name) return 0;
   unsigned NS = NSI;
   if (getLangOptions().CPlusPlus && (NS & Decl::IDNS_Ordinary))
     NS |= Decl::IDNS_Tag;
 
   IdentifierResolver::iterator 
-    I = LookupCtx ? IdResolver.begin(II, LookupCtx, false/*LookInParentCtx*/) :
-                    IdResolver.begin(II, CurContext, true/*LookInParentCtx*/);
+    I = LookupCtx ? IdResolver.begin(Name, LookupCtx, false/*LookInParentCtx*/)
+                  : IdResolver.begin(Name, CurContext, true/*LookInParentCtx*/);
   // Scan up the scope chain looking for a decl that matches this identifier
   // that is in the appropriate namespace.  This search should not take long, as
   // shadowing of names is uncommon, and deep shadowing is extremely uncommon.
@@ -209,13 +209,14 @@
   // corresponds to a compiler builtin, create the decl object for the builtin
   // now, injecting it into translation unit scope, and return it.
   if (NS & Decl::IDNS_Ordinary) {
-    if (enableLazyBuiltinCreation &&
+    IdentifierInfo *II = Name.getAsIdentifierInfo();
+    if (enableLazyBuiltinCreation && II &&
         (LookupCtx == 0 || isa<TranslationUnitDecl>(LookupCtx))) {
       // If this is a builtin on this (or all) targets, create the decl.
       if (unsigned BuiltinID = II->getBuiltinID())
         return LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID, S);
     }
-    if (getLangOptions().ObjC1) {
+    if (getLangOptions().ObjC1 && II) {
       // @interface and @compatibility_alias introduce typedef-like names.
       // Unlike typedef's, they can only be introduced at file-scope (and are 
       // therefore not scoped decls). They can, however, be shadowed by
@@ -1034,8 +1035,11 @@
       return ActOnConstructorDeclarator(Constructor);
     else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(NewFD))
       return ActOnDestructorDeclarator(Destructor);
-    else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(NewFD))
-      return ActOnConversionDeclarator(Conversion);
+    
+    // Extra checking for conversion functions, including recording
+    // the conversion function in its class.
+    if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(NewFD))
+      ActOnConversionDeclarator(Conversion);
 
     // Extra checking for C++ overloaded operators (C++ [over.oper]).
     if (NewFD->isOverloadedOperator() &&

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Nov 17 14:34:05 2008
@@ -19,6 +19,56 @@
 #include "clang/Basic/Diagnostic.h"
 using namespace clang;
 
+/// ActOnConversionFunctionExpr - Parse a C++ conversion function
+/// name (e.g., operator void const *) as an expression. This is
+/// very similar to ActOnIdentifierExpr, except that instead of
+/// providing an identifier the parser provides the type of the
+/// conversion function.
+Sema::ExprResult Sema::ActOnConversionFunctionExpr(Scope *S, 
+                                                   SourceLocation OperatorLoc,
+                                                   TypeTy *Ty,
+                                                   bool HasTrailingLParen,
+                                                   const CXXScopeSpec *SS) {
+  QualType ConvType = QualType::getFromOpaquePtr(Ty);
+  QualType ConvTypeCanon = Context.getCanonicalType(ConvType);
+  DeclarationName ConvName 
+    = Context.DeclarationNames.getCXXConversionFunctionName(ConvTypeCanon);
+
+  // We only expect to find a CXXConversionDecl.
+  Decl *D;
+  if (SS && !SS->isEmpty()) {
+    DeclContext *DC = static_cast<DeclContext*>(SS->getScopeRep());
+    if (DC == 0)
+      return true;
+    D = LookupDecl(ConvName, Decl::IDNS_Ordinary, S, DC);
+  } else
+    D = LookupDecl(ConvName, Decl::IDNS_Ordinary, S);
+  
+  if (D == 0) {
+    // If there is no conversion function that converts to this type,
+    // diagnose the problem.
+    if (SS && !SS->isEmpty())
+      return Diag(OperatorLoc, diag::err_typecheck_no_member,
+                  ConvType.getAsString(), SS->getRange());
+    else
+      return Diag(OperatorLoc, diag::err_no_conv_function, 
+                  ConvType.getAsString());
+  }
+  
+  assert(isa<CXXConversionDecl>(D) && "we had to find a conversion function");
+  CXXConversionDecl *Conversion = cast<CXXConversionDecl>(D);
+
+  // check if referencing a declaration with __attribute__((deprecated)).
+  if (Conversion->getAttr<DeprecatedAttr>())
+    Diag(OperatorLoc, diag::warn_deprecated, Conversion->getName());
+
+  // Only create DeclRefExpr's for valid Decl's.
+  if (Conversion->isInvalidDecl())
+    return true;
+  
+  // Create a normal DeclRefExpr.
+  return new DeclRefExpr(Conversion, Conversion->getType(), OperatorLoc);
+}
 
 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
 Action::ExprResult

Modified: cfe/trunk/test/SemaCXX/conversion-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion-function.cpp?rev=59462&r1=59461&r2=59462&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/conversion-function.cpp (original)
+++ cfe/trunk/test/SemaCXX/conversion-function.cpp Mon Nov 17 14:34:05 2008
@@ -3,6 +3,14 @@
 public:
   operator bool();
   operator int() const;
+
+  bool f() {
+    return operator bool();
+  }
+
+  float g() {
+    return operator float(); // expected-error{{no conversion function to type 'float'}}
+  }
 };
 
 operator int(); // expected-error{{conversion function must be a non-static member function}}





More information about the cfe-commits mailing list