zcov: / lib/Sema/SemaInit.h


Files: 1 Branches Taken: 64.3% 9 / 14
Generated: 2010-02-10 01:31 Branches Executed: 85.7% 12 / 14
Line Coverage: 96.3% 79 / 82


Programs: 16 Runs 24144


       1                 : //===--- SemaInit.h - Semantic Analysis for Initializers --------*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : // This file provides supporting data types for initialization of objects.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : #ifndef LLVM_CLANG_SEMA_INIT_H
      14                 : #define LLVM_CLANG_SEMA_INIT_H
      15                 : 
      16                 : #include "SemaOverload.h"
      17                 : #include "clang/AST/Type.h"
      18                 : #include "clang/AST/UnresolvedSet.h"
      19                 : #include "clang/Parse/Action.h"
      20                 : #include "clang/Basic/SourceLocation.h"
      21                 : #include "llvm/ADT/PointerIntPair.h"
      22                 : #include "llvm/ADT/SmallVector.h"
      23                 : #include <cassert>
      24                 : 
      25                 : namespace llvm {
      26                 :   class raw_ostream;
      27                 : }
      28                 : 
      29                 : namespace clang {
      30                 :   
      31                 : class CXXBaseSpecifier;
      32                 : class DeclaratorDecl;
      33                 : class DeclaratorInfo;
      34                 : class FieldDecl;
      35                 : class FunctionDecl;
      36                 : class ParmVarDecl;
      37                 : class Sema;
      38                 : class TypeLoc;
      39                 : class VarDecl;
      40                 :   
      41                 : /// \brief Describes an entity that is being initialized.
      42                 : class InitializedEntity {
      43                 : public:
      44                 :   /// \brief Specifies the kind of entity being initialized.
      45                 :   enum EntityKind {
      46                 :     /// \brief The entity being initialized is a variable.
      47                 :     EK_Variable,
      48                 :     /// \brief The entity being initialized is a function parameter.
      49                 :     EK_Parameter,
      50                 :     /// \brief The entity being initialized is the result of a function call.
      51                 :     EK_Result,
      52                 :     /// \brief The entity being initialized is an exception object that
      53                 :     /// is being thrown.
      54                 :     EK_Exception,
      55                 :     /// \brief The entity being initialized is a non-static data member 
      56                 :     /// subobject.
      57                 :     EK_Member,
      58                 :     /// \brief The entity being initialized is an element of an array.
      59                 :     EK_ArrayElement,
      60                 :     /// \brief The entity being initialized is an object (or array of
      61                 :     /// objects) allocated via new.
      62                 :     EK_New,
      63                 :     /// \brief The entity being initialized is a temporary object.
      64                 :     EK_Temporary,
      65                 :     /// \brief The entity being initialized is a base member subobject.
      66                 :     EK_Base,
      67                 :     /// \brief The entity being initialized is an element of a vector.
      68                 :     /// or vector.
      69                 :     EK_VectorElement
      70                 :   };
      71                 :   
      72                 : private:
      73                 :   /// \brief The kind of entity being initialized.
      74                 :   EntityKind Kind;
      75                 : 
      76                 :   /// \brief If non-NULL, the parent entity in which this
      77                 :   /// initialization occurs.
      78                 :   const InitializedEntity *Parent;
      79                 : 
      80                 :   /// \brief The type of the object or reference being initialized.
      81                 :   QualType Type;
      82                 :   
      83                 :   union {
      84                 :     /// \brief When Kind == EK_Variable, EK_Parameter, or EK_Member, 
      85                 :     /// the VarDecl, ParmVarDecl, or FieldDecl, respectively.
      86                 :     DeclaratorDecl *VariableOrMember;
      87                 :     
      88                 :     /// \brief When Kind == EK_Result, EK_Exception, or EK_New, the
      89                 :     /// location of the 'return', 'throw', or 'new' keyword,
      90                 :     /// respectively. When Kind == EK_Temporary, the location where
      91                 :     /// the temporary is being created.
      92                 :     unsigned Location;
      93                 :     
      94                 :     /// \brief When Kind == EK_Base, the base specifier that provides the 
      95                 :     /// base class.
      96                 :     CXXBaseSpecifier *Base;
      97                 : 
      98                 :     /// \brief When Kind = EK_ArrayElement or EK_VectorElement, the
      99                 :     /// index of the array or vector element being initialized.
     100                 :     unsigned Index;
     101                 :   };
     102                 : 
     103              531:   InitializedEntity() { }
     104                 : 
     105                 :   /// \brief Create the initialization entity for a variable.
     106             8858:   InitializedEntity(VarDecl *Var)
     107                 :     : Kind(EK_Variable), Parent(0), Type(Var->getType()),
     108             8858:       VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Var)) { }
     109                 :   
     110                 :   /// \brief Create the initialization entity for a parameter.
     111             8089:   InitializedEntity(ParmVarDecl *Parm)
     112                 :     : Kind(EK_Parameter), Parent(0), Type(Parm->getType().getUnqualifiedType()),
     113             8089:       VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm)) { }
     114                 :   
     115                 :   /// \brief Create the initialization entity for the result of a
     116                 :   /// function, throwing an object, performing an explicit cast, or
     117                 :   /// initializing a parameter for which there is no declaration.
     118             4728:   InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type)
     119             4728:     : Kind(Kind), Parent(0), Type(Type), Location(Loc.getRawEncoding()) { }
     120                 :   
     121                 :   /// \brief Create the initialization entity for a member subobject.
     122             1535:   InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent) 
     123                 :     : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
     124             1535:       VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Member)) { }
     125                 :   
     126                 :   /// \brief Create the initialization entity for an array element.
     127                 :   InitializedEntity(ASTContext &Context, unsigned Index, 
     128                 :                     const InitializedEntity &Parent);
     129                 : 
     130                 : public:
     131                 :   /// \brief Create the initialization entity for a variable.
     132             8858:   static InitializedEntity InitializeVariable(VarDecl *Var) {
     133             8858:     return InitializedEntity(Var);
     134                 :   }
     135                 :   
     136                 :   /// \brief Create the initialization entity for a parameter.
     137             8089:   static InitializedEntity InitializeParameter(ParmVarDecl *Parm) {
     138             8089:     return InitializedEntity(Parm);
     139                 :   }
     140                 : 
     141                 :   /// \brief Create the initialization entity for a parameter that is
     142                 :   /// only known by its type.
     143              120:   static InitializedEntity InitializeParameter(QualType Type) {
     144              120:     return InitializedEntity(EK_Parameter, SourceLocation(), Type);
     145                 :   }
     146                 : 
     147                 :   /// \brief Create the initialization entity for the result of a function.
     148                 :   static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
     149             4107:                                             QualType Type) {
     150             4107:     return InitializedEntity(EK_Result, ReturnLoc, Type);
     151                 :   }
     152                 : 
     153                 :   /// \brief Create the initialization entity for an exception object.
     154                 :   static InitializedEntity InitializeException(SourceLocation ThrowLoc,
     155                 :                                                QualType Type) {
     156                 :     return InitializedEntity(EK_Exception, ThrowLoc, Type);
     157                 :   }
     158                 : 
     159                 :   /// \brief Create the initialization entity for an object allocated via new.
     160              103:   static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) {
     161              103:     return InitializedEntity(EK_New, NewLoc, Type);
     162                 :   }
     163                 :   
     164                 :   /// \brief Create the initialization entity for a temporary.
     165              398:   static InitializedEntity InitializeTemporary(QualType Type) {
     166              398:     return InitializedEntity(EK_Temporary, SourceLocation(), Type);
     167                 :   }
     168                 :   
     169                 :   /// \brief Create the initialization entity for a base class subobject.
     170                 :   static InitializedEntity InitializeBase(ASTContext &Context,
     171                 :                                           CXXBaseSpecifier *Base);
     172                 :   
     173                 :   /// \brief Create the initialization entity for a member subobject.
     174                 :   static InitializedEntity InitializeMember(FieldDecl *Member,
     175             1535:                                           const InitializedEntity *Parent = 0) {
     176             1535:     return InitializedEntity(Member, Parent);
     177                 :   }
     178                 :   
     179                 :   /// \brief Create the initialization entity for an array element.
     180                 :   static InitializedEntity InitializeElement(ASTContext &Context, 
     181                 :                                              unsigned Index, 
     182             1811:                                              const InitializedEntity &Parent) {
     183             1811:     return InitializedEntity(Context, Index, Parent);
     184                 :   }
     185                 : 
     186                 :   /// \brief Determine the kind of initialization.
     187            38323:   EntityKind getKind() const { return Kind; }
     188                 :   
     189                 :   /// \brief Retrieve the parent of the entity being initialized, when
     190                 :   /// the initialization itself is occuring within the context of a
     191                 :   /// larger initialization.
     192                 :   const InitializedEntity *getParent() const { return Parent; }
     193                 : 
     194                 :   /// \brief Retrieve type being initialized.
     195            71474:   QualType getType() const { return Type; }
     196                 :   
     197                 :   /// \brief Retrieve the name of the entity being initialized.
     198                 :   DeclarationName getName() const;
     199                 : 
     200                 :   /// \brief Retrieve the variable, parameter, or field being
     201                 :   /// initialized.
     202                 :   DeclaratorDecl *getDecl() const;
     203                 : 
     204                 :   /// \brief Retrieve the base specifier.
     205                2:   CXXBaseSpecifier *getBaseSpecifier() const {
                        2: branch 1 taken
                        0: branch 2 not taken
     206                2:     assert(getKind() == EK_Base && "Not a base specifier");
     207                2:     return Base;
     208                 :   }
     209                 : 
     210                 :   /// \brief Determine the location of the 'return' keyword when initializing
     211                 :   /// the result of a function call.
     212               12:   SourceLocation getReturnLoc() const {
                       12: branch 1 taken
                        0: branch 2 not taken
     213               12:     assert(getKind() == EK_Result && "No 'return' location!");
     214               12:     return SourceLocation::getFromRawEncoding(Location);
     215                 :   }
     216                 :   
     217                 :   /// \brief Determine the location of the 'throw' keyword when initializing
     218                 :   /// an exception object.
     219                0:   SourceLocation getThrowLoc() const {
                        0: branch 1 not taken
                        0: branch 2 not taken
     220                0:     assert(getKind() == EK_Exception && "No 'throw' location!");
     221                0:     return SourceLocation::getFromRawEncoding(Location);
     222                 :   }
     223                 : 
     224                 :   /// \brief If this is already the initializer for an array or vector
     225                 :   /// element, sets the element index.
     226             3706:   void setElementIndex(unsigned Index) {
                     1760: branch 1 taken
                     1946: branch 2 taken
                        0: branch 4 not taken
                     1760: branch 5 taken
     227             3706:     assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement);
     228             3706:     this->Index = Index;
     229             3706:   }
     230                 : };
     231                 :   
     232                 : /// \brief Describes the kind of initialization being performed, along with 
     233                 : /// location information for tokens related to the initialization (equal sign,
     234                 : /// parentheses).
     235                 : class InitializationKind {
     236                 : public:
     237                 :   /// \brief The kind of initialization being performed.
     238                 :   enum InitKind {
     239                 :     IK_Direct,  ///< Direct initialization
     240                 :     IK_Copy,    ///< Copy initialization
     241                 :     IK_Default, ///< Default initialization
     242                 :     IK_Value    ///< Value initialization
     243                 :   };
     244                 :   
     245                 : private:
     246                 :   /// \brief The kind of initialization that we're storing.
     247                 :   enum StoredInitKind {
     248                 :     SIK_Direct = IK_Direct,   ///< Direct initialization
     249                 :     SIK_Copy = IK_Copy,       ///< Copy initialization
     250                 :     SIK_Default = IK_Default, ///< Default initialization
     251                 :     SIK_Value = IK_Value,     ///< Value initialization
     252                 :     SIK_ImplicitValue,        ///< Implicit value initialization
     253                 :     SIK_DirectCast,  ///< Direct initialization due to a cast
     254                 :     /// \brief Direct initialization due to a C-style or functional cast.
     255                 :     SIK_DirectCStyleOrFunctionalCast
     256                 :   };
     257                 :   
     258                 :   /// \brief The kind of initialization being performed.
     259                 :   StoredInitKind Kind;
     260                 :   
     261                 :   /// \brief The source locations involved in the initialization.
     262                 :   SourceLocation Locations[3];
     263                 :   
     264                 :   InitializationKind(StoredInitKind Kind, SourceLocation Loc1, 
     265            25765:                      SourceLocation Loc2, SourceLocation Loc3)
                    77295: branch 1 taken
                    25765: branch 2 taken
     266            25765:     : Kind(Kind) 
     267                 :   {
     268            25765:     Locations[0] = Loc1;
     269            25765:     Locations[1] = Loc2;
     270            25765:     Locations[2] = Loc3;
     271            25765:   }
     272                 :   
     273                 : public:
     274                 :   /// \brief Create a direct initialization.
     275                 :   static InitializationKind CreateDirect(SourceLocation InitLoc,
     276                 :                                          SourceLocation LParenLoc,
     277              534:                                          SourceLocation RParenLoc) {
     278              534:     return InitializationKind(SIK_Direct, InitLoc, LParenLoc, RParenLoc);
     279                 :   }
     280                 : 
     281                 :   /// \brief Create a direct initialization due to a cast.
     282                 :   static InitializationKind CreateCast(SourceRange TypeRange,
     283              285:                                        bool IsCStyleCast) {
     284                 :     return InitializationKind(IsCStyleCast? SIK_DirectCStyleOrFunctionalCast
     285                 :                                           : SIK_DirectCast,
     286                 :                               TypeRange.getBegin(), TypeRange.getBegin(), 
     287              285:                               TypeRange.getEnd());
     288                 :   }
     289                 :   
     290                 :   /// \brief Create a copy initialization.
     291                 :   static InitializationKind CreateCopy(SourceLocation InitLoc,
     292            20193:                                        SourceLocation EqualLoc) {
     293            20193:     return InitializationKind(SIK_Copy, InitLoc, EqualLoc, EqualLoc);
     294                 :   }
     295                 :   
     296                 :   /// \brief Create a default initialization.
     297             3681:   static InitializationKind CreateDefault(SourceLocation InitLoc) {
     298             3681:     return InitializationKind(SIK_Default, InitLoc, InitLoc, InitLoc);
     299                 :   }
     300                 :   
     301                 :   /// \brief Create a value initialization.
     302                 :   static InitializationKind CreateValue(SourceLocation InitLoc,
     303                 :                                         SourceLocation LParenLoc,
     304                 :                                         SourceLocation RParenLoc,
     305             1072:                                         bool isImplicit = false) {
     306                 :     return InitializationKind(isImplicit? SIK_ImplicitValue : SIK_Value, 
                      989: branch 0 taken
                       83: branch 1 taken
     307             1072:                               InitLoc, LParenLoc, RParenLoc);
     308                 :   }
     309                 :   
     310                 :   /// \brief Determine the initialization kind.
     311            84556:   InitKind getKind() const {
     312            84556:     if (Kind > SIK_ImplicitValue)
     313                1:       return IK_Direct;
     314            84555:     if (Kind == SIK_ImplicitValue)
     315             2007:       return IK_Value;
     316                 : 
     317            82548:     return (InitKind)Kind;
     318                 :   }
     319                 :   
     320                 :   /// \brief Determine whether this initialization is an explicit cast.
     321             4335:   bool isExplicitCast() const {
     322             4335:     return Kind == SIK_DirectCast || Kind == SIK_DirectCStyleOrFunctionalCast;
     323                 :   }
     324                 :   
     325                 :   /// \brief Determine whether this initialization is a C-style cast.
     326               55:   bool isCStyleOrFunctionalCast() const { 
     327               55:     return Kind == SIK_DirectCStyleOrFunctionalCast; 
     328                 :   }
     329                 : 
     330                 :   /// \brief Determine whether this initialization is an implicit
     331                 :   /// value-initialization, e.g., as occurs during aggregate
     332                 :   /// initialization.
     333              468:   bool isImplicitValueInit() const { return Kind == SIK_ImplicitValue; }
     334                 : 
     335                 :   /// \brief Retrieve the location at which initialization is occurring.
     336            42598:   SourceLocation getLocation() const { return Locations[0]; }
     337                 :   
     338                 :   /// \brief Retrieve the source range that covers the initialization.
     339               22:   SourceRange getRange() const { 
     340               22:     return SourceRange(Locations[0], Locations[2]);
     341                 :   }
     342                 :   
     343                 :   /// \brief Retrieve the location of the equal sign for copy initialization
     344                 :   /// (if present).
     345                 :   SourceLocation getEqualLoc() const {
     346                 :     assert(Kind == SIK_Copy && "Only copy initialization has an '='");
     347                 :     return Locations[1];
     348                 :   }
     349                 :   
     350                 :   /// \brief Retrieve the source range containing the locations of the open
     351                 :   /// and closing parentheses for value and direct initializations.
     352                 :   SourceRange getParenRange() const {
     353                 :     assert((getKind() == IK_Direct || Kind == SIK_Value) &&
     354                 :            "Only direct- and value-initialization have parentheses");
     355                 :     return SourceRange(Locations[1], Locations[2]);
     356                 :   }
     357                 : };
     358                 : 
     359                 : /// \brief Describes the sequence of initializations required to initialize
     360                 : /// a given object or reference with a set of arguments.
     361                 : class InitializationSequence {
     362                 : public:
     363                 :   /// \brief Describes the kind of initialization sequence computed.
     364                 :   ///
     365                 :   /// FIXME: Much of this information is in the initialization steps... why is
     366                 :   /// it duplicated here?
     367                 :   enum SequenceKind {
     368                 :     /// \brief A failed initialization sequence. The failure kind tells what
     369                 :     /// happened.
     370                 :     FailedSequence = 0,
     371                 :     
     372                 :     /// \brief A dependent initialization, which could not be
     373                 :     /// type-checked due to the presence of dependent types or
     374                 :     /// dependently-type expressions.
     375                 :     DependentSequence,
     376                 : 
     377                 :     /// \brief A user-defined conversion sequence.
     378                 :     UserDefinedConversion,
     379                 :     
     380                 :     /// \brief A constructor call.
     381                 :     ConstructorInitialization,
     382                 :     
     383                 :     /// \brief A reference binding.
     384                 :     ReferenceBinding,
     385                 : 
     386                 :     /// \brief List initialization
     387                 :     ListInitialization,
     388                 :     
     389                 :     /// \brief Zero-initialization.
     390                 :     ZeroInitialization,
     391                 :     
     392                 :     /// \brief No initialization required.
     393                 :     NoInitialization,
     394                 :     
     395                 :     /// \brief Standard conversion sequence.
     396                 :     StandardConversion,
     397                 : 
     398                 :     /// \brief C conversion sequence.
     399                 :     CAssignment,
     400                 : 
     401                 :     /// \brief String initialization
     402                 :     StringInit
     403                 :   };
     404                 :   
     405                 :   /// \brief Describes the kind of a particular step in an initialization
     406                 :   /// sequence.
     407                 :   enum StepKind {
     408                 :     /// \brief Resolve the address of an overloaded function to a specific
     409                 :     /// function declaration.
     410                 :     SK_ResolveAddressOfOverloadedFunction,
     411                 :     /// \brief Perform a derived-to-base cast, producing an rvalue.
     412                 :     SK_CastDerivedToBaseRValue,
     413                 :     /// \brief Perform a derived-to-base cast, producing an lvalue.
     414                 :     SK_CastDerivedToBaseLValue,
     415                 :     /// \brief Reference binding to an lvalue.
     416                 :     SK_BindReference,
     417                 :     /// \brief Reference binding to a temporary.
     418                 :     SK_BindReferenceToTemporary,
     419                 :     /// \brief Perform a user-defined conversion, either via a conversion
     420                 :     /// function or via a constructor.
     421                 :     SK_UserConversion,
     422                 :     /// \brief Perform a qualification conversion, producing an rvalue.
     423                 :     SK_QualificationConversionRValue,
     424                 :     /// \brief Perform a qualification conversion, producing an lvalue.
     425                 :     SK_QualificationConversionLValue,
     426                 :     /// \brief Perform an implicit conversion sequence.
     427                 :     SK_ConversionSequence,
     428                 :     /// \brief Perform list-initialization
     429                 :     SK_ListInitialization,
     430                 :     /// \brief Perform initialization via a constructor.
     431                 :     SK_ConstructorInitialization,
     432                 :     /// \brief Zero-initialize the object
     433                 :     SK_ZeroInitialization,
     434                 :     /// \brief C assignment
     435                 :     SK_CAssignment,
     436                 :     /// \brief Initialization by string
     437                 :     SK_StringInit
     438                 :   };
     439                 :   
     440                 :   /// \brief A single step in the initialization sequence.
     441            46670:   class Step {
     442                 :   public:
     443                 :     /// \brief The kind of conversion or initialization step we are taking.
     444                 :     StepKind Kind;
     445                 :     
     446                 :     // \brief The type that results from this initialization.
     447                 :     QualType Type;
     448                 :     
     449                 :     union {
     450                 :       /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind ==
     451                 :       /// SK_UserConversion, the function that the expression should be 
     452                 :       /// resolved to or the conversion function to call, respectively.
     453                 :       ///
     454                 :       /// Always a FunctionDecl.
     455                 :       /// For conversion decls, the naming class is the source type.
     456                 :       /// For construct decls, the naming class is the target type.
     457                 :       DeclAccessPair Function;
     458                 :       
     459                 :       /// \brief When Kind = SK_ConversionSequence, the implicit conversion
     460                 :       /// sequence 
     461                 :       ImplicitConversionSequence *ICS;
     462                 :     };
     463                 :     
     464                 :     void Destroy();
     465                 :   };
     466                 :   
     467                 : private:
     468                 :   /// \brief The kind of initialization sequence computed.
     469                 :   enum SequenceKind SequenceKind;
     470                 :   
     471                 :   /// \brief Steps taken by this initialization.
     472                 :   llvm::SmallVector<Step, 4> Steps;
     473                 :   
     474                 : public:
     475                 :   /// \brief Describes why initialization failed.
     476                 :   enum FailureKind {
     477                 :     /// \brief Too many initializers provided for a reference.
     478                 :     FK_TooManyInitsForReference,
     479                 :     /// \brief Array must be initialized with an initializer list.
     480                 :     FK_ArrayNeedsInitList,
     481                 :     /// \brief Array must be initialized with an initializer list or a 
     482                 :     /// string literal.
     483                 :     FK_ArrayNeedsInitListOrStringLiteral,
     484                 :     /// \brief Cannot resolve the address of an overloaded function.
     485                 :     FK_AddressOfOverloadFailed,
     486                 :     /// \brief Overloading due to reference initialization failed.
     487                 :     FK_ReferenceInitOverloadFailed,
     488                 :     /// \brief Non-const lvalue reference binding to a temporary.
     489                 :     FK_NonConstLValueReferenceBindingToTemporary,
     490                 :     /// \brief Non-const lvalue reference binding to an lvalue of unrelated
     491                 :     /// type.
     492                 :     FK_NonConstLValueReferenceBindingToUnrelated,
     493                 :     /// \brief Rvalue reference binding to an lvalue.
     494                 :     FK_RValueReferenceBindingToLValue,
     495                 :     /// \brief Reference binding drops qualifiers.
     496                 :     FK_ReferenceInitDropsQualifiers,
     497                 :     /// \brief Reference binding failed.
     498                 :     FK_ReferenceInitFailed,
     499                 :     /// \brief Implicit conversion failed.
     500                 :     FK_ConversionFailed,
     501                 :     /// \brief Too many initializers for scalar
     502                 :     FK_TooManyInitsForScalar,
     503                 :     /// \brief Reference initialization from an initializer list
     504                 :     FK_ReferenceBindingToInitList,
     505                 :     /// \brief Initialization of some unused destination type with an
     506                 :     /// initializer list.
     507                 :     FK_InitListBadDestinationType,
     508                 :     /// \brief Overloading for a user-defined conversion failed.
     509                 :     FK_UserConversionOverloadFailed,
     510                 :     /// \brief Overloaded for initialization by constructor failed.
     511                 :     FK_ConstructorOverloadFailed,
     512                 :     /// \brief Default-initialization of a 'const' object.
     513                 :     FK_DefaultInitOfConst
     514                 :   };
     515                 :   
     516                 : private:
     517                 :   /// \brief The reason why initialization failued.
     518                 :   FailureKind Failure;
     519                 : 
     520                 :   /// \brief The failed result of overload resolution.
     521                 :   OverloadingResult FailedOverloadResult;
     522                 :   
     523                 :   /// \brief The candidate set created when initialization failed.
     524                 :   OverloadCandidateSet FailedCandidateSet;
     525                 :   
     526                 : public:
     527                 :   /// \brief Try to perform initialization of the given entity, creating a 
     528                 :   /// record of the steps required to perform the initialization.
     529                 :   ///
     530                 :   /// The generated initialization sequence will either contain enough
     531                 :   /// information to diagnose 
     532                 :   ///
     533                 :   /// \param S the semantic analysis object.
     534                 :   ///
     535                 :   /// \param Entity the entity being initialized.
     536                 :   ///
     537                 :   /// \param Kind the kind of initialization being performed.
     538                 :   ///
     539                 :   /// \param Args the argument(s) provided for initialization.
     540                 :   ///
     541                 :   /// \param NumArgs the number of arguments provided for initialization.
     542                 :   InitializationSequence(Sema &S, 
     543                 :                          const InitializedEntity &Entity,
     544                 :                          const InitializationKind &Kind,
     545                 :                          Expr **Args,
     546                 :                          unsigned NumArgs);
     547                 :   
     548                 :   ~InitializationSequence();
     549                 :   
     550                 :   /// \brief Perform the actual initialization of the given entity based on
     551                 :   /// the computed initialization sequence.
     552                 :   ///
     553                 :   /// \param S the semantic analysis object.
     554                 :   ///
     555                 :   /// \param Entity the entity being initialized.
     556                 :   ///
     557                 :   /// \param Kind the kind of initialization being performed.
     558                 :   ///
     559                 :   /// \param Args the argument(s) provided for initialization, ownership of
     560                 :   /// which is transfered into the routine.
     561                 :   ///
     562                 :   /// \param ResultType if non-NULL, will be set to the type of the
     563                 :   /// initialized object, which is the type of the declaration in most
     564                 :   /// cases. However, when the initialized object is a variable of
     565                 :   /// incomplete array type and the initializer is an initializer
     566                 :   /// list, this type will be set to the completed array type.
     567                 :   ///
     568                 :   /// \returns an expression that performs the actual object initialization, if
     569                 :   /// the initialization is well-formed. Otherwise, emits diagnostics
     570                 :   /// and returns an invalid expression.
     571                 :   Action::OwningExprResult Perform(Sema &S,
     572                 :                                    const InitializedEntity &Entity,
     573                 :                                    const InitializationKind &Kind,
     574                 :                                    Action::MultiExprArg Args,
     575                 :                                    QualType *ResultType = 0);
     576                 :   
     577                 :   /// \brief Diagnose an potentially-invalid initialization sequence.
     578                 :   ///
     579                 :   /// \returns true if the initialization sequence was ill-formed, 
     580                 :   /// false otherwise.
     581                 :   bool Diagnose(Sema &S, 
     582                 :                 const InitializedEntity &Entity,
     583                 :                 const InitializationKind &Kind,
     584                 :                 Expr **Args, unsigned NumArgs);
     585                 :   
     586                 :   /// \brief Determine the kind of initialization sequence computed.
     587              886:   enum SequenceKind getKind() const { return SequenceKind; }
     588                 :   
     589                 :   /// \brief Set the kind of sequence computed.
     590            25248:   void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
     591                 :   
     592                 :   /// \brief Determine whether the initialization sequence is valid.
     593             1010:   operator bool() const { return SequenceKind != FailedSequence; }
     594                 :   
     595                 :   typedef llvm::SmallVector<Step, 4>::const_iterator step_iterator;
     596            22552:   step_iterator step_begin() const { return Steps.begin(); }
     597            22552:   step_iterator step_end()   const { return Steps.end(); }
     598                 : 
     599                 :   /// \brief Add a new step in the initialization that resolves the address
     600                 :   /// of an overloaded function to a specific function declaration.
     601                 :   ///
     602                 :   /// \param Function the function to which the overloaded function reference
     603                 :   /// resolves.
     604                 :   void AddAddressOverloadResolutionStep(FunctionDecl *Function);
     605                 :   
     606                 :   /// \brief Add a new step in the initialization that performs a derived-to-
     607                 :   /// base cast.
     608                 :   ///
     609                 :   /// \param BaseType the base type to which we will be casting.
     610                 :   ///
     611                 :   /// \param IsLValue true if the result of this cast will be treated as 
     612                 :   /// an lvalue.
     613                 :   void AddDerivedToBaseCastStep(QualType BaseType, bool IsLValue);
     614                 :      
     615                 :   /// \brief Add a new step binding a reference to an object.
     616                 :   ///
     617                 :   /// \param BindingTemporary true if we are binding a reference to a temporary
     618                 :   /// object (thereby extending its lifetime); false if we are binding to an
     619                 :   /// lvalue or an lvalue treated as an rvalue.
     620                 :   void AddReferenceBindingStep(QualType T, bool BindingTemporary);
     621                 :   
     622                 :   /// \brief Add a new step invoking a conversion function, which is either
     623                 :   /// a constructor or a conversion function.
     624                 :   void AddUserConversionStep(FunctionDecl *Function,
     625                 :                              AccessSpecifier Access,
     626                 :                              QualType T);
     627                 :   
     628                 :   /// \brief Add a new step that performs a qualification conversion to the
     629                 :   /// given type.
     630                 :   void AddQualificationConversionStep(QualType Ty, bool IsLValue);
     631                 :   
     632                 :   /// \brief Add a new step that applies an implicit conversion sequence.
     633                 :   void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
     634                 :                                  QualType T);
     635                 : 
     636                 :   /// \brief Add a list-initialiation step  
     637                 :   void AddListInitializationStep(QualType T);
     638                 : 
     639                 :   /// \brief Add a constructor-initialization step.
     640                 :   void AddConstructorInitializationStep(CXXConstructorDecl *Constructor,
     641                 :                                         AccessSpecifier Access,
     642                 :                                         QualType T);
     643                 : 
     644                 :   /// \brief Add a zero-initialization step.
     645                 :   void AddZeroInitializationStep(QualType T);
     646                 :   
     647                 :   /// \brief Add a C assignment step.
     648                 :   //
     649                 :   // FIXME: It isn't clear whether this should ever be needed;
     650                 :   // ideally, we would handle everything needed in C in the common
     651                 :   // path. However, that isn't the case yet.
     652                 :   void AddCAssignmentStep(QualType T);
     653                 : 
     654                 :   /// \brief Add a string init step.
     655                 :   void AddStringInitStep(QualType T);
     656                 : 
     657                 :   /// \brief Note that this initialization sequence failed.
     658              107:   void SetFailed(FailureKind Failure) {
     659              107:     SequenceKind = FailedSequence;
     660              107:     this->Failure = Failure;
     661              107:   }
     662                 :   
     663                 :   /// \brief Note that this initialization sequence failed due to failed
     664                 :   /// overload resolution.
     665                 :   void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
     666                 :   
     667                 :   /// \brief Retrieve a reference to the candidate set when overload
     668                 :   /// resolution fails.
     669             2056:   OverloadCandidateSet &getFailedCandidateSet() {
     670             2056:     return FailedCandidateSet;
     671                 :   }
     672                 : 
     673                 :   /// \brief Determine why initialization failed.
     674                 :   FailureKind getFailureKind() const {
     675                 :     assert(getKind() == FailedSequence && "Not an initialization failure!");
     676                 :     return Failure;
     677                 :   }
     678                 :   
     679                 :   /// \brief Dump a representation of this initialization sequence to 
     680                 :   /// the given stream, for debugging purposes.
     681                 :   void dump(llvm::raw_ostream &OS) const;
     682                 :   
     683                 :   /// \brief Dump a representation of this initialization sequence to 
     684                 :   /// standard error, for debugging purposes.
     685                 :   void dump() const;
     686                 : };
     687                 :   
     688                 : } // end namespace clang
     689                 : 
     690                 : #endif // LLVM_CLANG_SEMA_INIT_H

Generated: 2010-02-10 01:31 by zcov