zcov: / include/clang/Parse/Template.h


Files: 1 Branches Taken: 71.4% 10 / 14
Generated: 2010-02-10 01:31 Branches Executed: 100.0% 14 / 14
Line Coverage: 100.0% 37 / 37


Programs: 14 Runs 21126


       1                 : //===--- Template.h - Template Parsing Data Types -------------------------===//
       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 data structures that store the parsed representation of
      11                 : //  templates.
      12                 : //
      13                 : //===----------------------------------------------------------------------===//
      14                 : #ifndef LLVM_CLANG_PARSE_TEMPLATE_H
      15                 : #define LLVM_CLANG_PARSE_TEMPLATE_H
      16                 : 
      17                 : #include "clang/Parse/DeclSpec.h"
      18                 : #include "clang/Parse/Ownership.h"
      19                 : #include <cassert>
      20                 : 
      21                 : namespace clang {  
      22                 :   /// \brief Represents the parsed form of a C++ template argument.
      23             3142:   class ParsedTemplateArgument {
      24                 :   public:
      25                 :     /// \brief Describes the kind of template argument that was parsed.
      26                 :     enum KindType {
      27                 :       /// \brief A template type parameter, stored as a type.
      28                 :       Type,
      29                 :       /// \brief A non-type template parameter, stored as an expression.
      30                 :       NonType,
      31                 :       /// \brief A template template argument, stored as a template name.
      32                 :       Template
      33                 :     };
      34                 : 
      35                 :     /// \brief Build an empty template argument. This template argument 
      36              523:     ParsedTemplateArgument() : Kind(Type), Arg(0) { }
      37                 :     
      38                 :     /// \brief Create a template type argument or non-type template argument.
      39                 :     ///
      40                 :     /// \param Arg the template type argument or non-type template argument.
      41                 :     /// \param Loc the location of the type.
      42             3107:     ParsedTemplateArgument(KindType Kind, void *Arg, SourceLocation Loc)
      43             3107:       : Kind(Kind), Arg(Arg), Loc(Loc) { }
      44                 :     
      45                 :     /// \brief Create a template template argument.
      46                 :     ///
      47                 :     /// \param SS the C++ scope specifier that precedes the template name, if
      48                 :     /// any.
      49                 :     ///
      50                 :     /// \param Template the template to which this template template 
      51                 :     /// argument refers.
      52                 :     ///
      53                 :     /// \param TemplateLoc the location of the template name.
      54                 :     ParsedTemplateArgument(const CXXScopeSpec &SS,
      55                 :                            ActionBase::TemplateTy Template, 
      56               46:                            SourceLocation TemplateLoc) 
      57                 :       : Kind(ParsedTemplateArgument::Template), Arg(Template.get()), 
      58               46:         Loc(TemplateLoc), SS(SS) { }
      59                 :     
      60                 :     /// \brief Determine whether the given template argument is invalid.
      61             3711:     bool isInvalid() { return Arg == 0; }
      62                 :     
      63                 :     /// \brief Determine what kind of template argument we have.
      64             3166:     KindType getKind() const { return Kind; }
      65                 :     
      66                 :     /// \brief Retrieve the template type argument's type.
      67             2573:     ActionBase::TypeTy *getAsType() const {
                        0: branch 0 not taken
                     2573: branch 1 taken
      68             2573:       assert(Kind == Type && "Not a template type argument");
      69             2573:       return Arg;
      70                 :     }
      71                 :     
      72                 :     /// \brief Retrieve the non-type template argument's expression.
      73              525:     ActionBase::ExprTy *getAsExpr() const {
                        0: branch 0 not taken
                      525: branch 1 taken
      74              525:       assert(Kind == NonType && "Not a non-type template argument");
      75              525:       return Arg;
      76                 :     }
      77                 :     
      78                 :     /// \brief Retrieve the template template argument's template name.
      79               46:     ActionBase::TemplateTy getAsTemplate() const {
                        0: branch 0 not taken
                       46: branch 1 taken
      80               46:       assert(Kind == Template && "Not a template template argument");
      81               46:       return ActionBase::TemplateTy::make(Arg);
      82                 :     }
      83                 :     
      84                 :     /// \brief Retrieve the location of the template argument.
      85               46:     SourceLocation getLocation() const { return Loc; }
      86                 :     
      87                 :     /// \brief Retrieve the nested-name-specifier that precedes the template
      88                 :     /// name in a template template argument.
      89               46:     const CXXScopeSpec &getScopeSpec() const {
      90                 :       assert(Kind == Template && 
                        0: branch 0 not taken
                       46: branch 1 taken
      91               46:              "Only template template arguments can have a scope specifier");
      92               46:       return SS;
      93                 :     }
      94                 :     
      95                 :   private:
      96                 :     KindType Kind;
      97                 :     
      98                 :     /// \brief The actual template argument representation, which may be
      99                 :     /// an \c ActionBase::TypeTy* (for a type), an ActionBase::ExprTy* (for an
     100                 :     /// expression), or an ActionBase::TemplateTy (for a template).
     101                 :     void *Arg;
     102                 : 
     103                 :     /// \brief the location of the template argument.
     104                 :     SourceLocation Loc;
     105                 :     
     106                 :     /// \brief The nested-name-specifier that can accompany a template template
     107                 :     /// argument.
     108                 :     CXXScopeSpec SS;
     109                 :   };
     110                 :   
     111                 :   /// \brief Information about a template-id annotation
     112                 :   /// token.
     113                 :   ///
     114                 :   /// A template-id annotation token contains the template declaration, 
     115                 :   /// template arguments, whether those template arguments were types, 
     116                 :   /// expressions, or template names, and the source locations for important 
     117                 :   /// tokens. All of the information about template arguments is allocated 
     118                 :   /// directly after this structure.
     119                 :   struct TemplateIdAnnotation {
     120                 :     /// TemplateNameLoc - The location of the template name within the
     121                 :     /// source.
     122                 :     SourceLocation TemplateNameLoc;
     123                 :     
     124                 :     /// FIXME: Temporarily stores the name of a specialization
     125                 :     IdentifierInfo *Name;
     126                 :     
     127                 :     /// FIXME: Temporarily stores the overloaded operator kind.
     128                 :     OverloadedOperatorKind Operator;
     129                 :     
     130                 :     /// The declaration of the template corresponding to the
     131                 :     /// template-name. This is an Action::TemplateTy.
     132                 :     void *Template;
     133                 :     
     134                 :     /// The kind of template that Template refers to.
     135                 :     TemplateNameKind Kind;
     136                 :     
     137                 :     /// The location of the '<' before the template argument
     138                 :     /// list.
     139                 :     SourceLocation LAngleLoc;
     140                 :     
     141                 :     /// The location of the '>' after the template argument
     142                 :     /// list.
     143                 :     SourceLocation RAngleLoc;
     144                 :     
     145                 :     /// NumArgs - The number of template arguments.
     146                 :     unsigned NumArgs;
     147                 :     
     148                 :     /// \brief Retrieves a pointer to the template arguments
     149             5066:     ParsedTemplateArgument *getTemplateArgs() { 
     150             5066:       return reinterpret_cast<ParsedTemplateArgument *>(this + 1); 
     151                 :     }
     152                 :     
     153             2539:     static TemplateIdAnnotation* Allocate(unsigned NumArgs) {
     154                 :       TemplateIdAnnotation *TemplateId
     155                 :       = (TemplateIdAnnotation *)std::malloc(sizeof(TemplateIdAnnotation) +
     156             2539:                                       sizeof(ParsedTemplateArgument) * NumArgs);
     157             2539:       TemplateId->NumArgs = NumArgs;
     158             2539:       return TemplateId;
     159                 :     }
     160                 :     
     161             2533:     void Destroy() { free(this); }
     162                 :   };
     163                 :   
     164                 : #if !defined(DISABLE_SMART_POINTERS)
     165             7365:   inline void ASTTemplateArgsPtr::destroy() {
                     7346: branch 0 taken
                       19: branch 1 taken
     166             7365:     if (!Count)
     167             7346:       return;
     168                 :     
                       31: branch 0 taken
                       19: branch 1 taken
     169               50:     for (unsigned I = 0; I != Count; ++I)
                        9: branch 1 taken
                       22: branch 2 taken
     170               31:       if (Args[I].getKind() == ParsedTemplateArgument::NonType)
     171                9:         Actions.DeleteExpr(Args[I].getAsExpr());
     172                 :     
     173               19:     Count = 0;
     174                 :   }
     175                 : #endif
     176                 :   
     177                 :   inline const ParsedTemplateArgument &
     178             3124:   ASTTemplateArgsPtr::operator[](unsigned Arg) const { 
     179             3124:     return Args[Arg]; 
     180                 :   }
     181                 : }
     182                 : 
     183                 : #endif

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