zcov: / lib/Sema/SemaTemplate.h


Files: 1 Branches Taken: 62.5% 5 / 8
Generated: 2010-02-10 01:31 Branches Executed: 100.0% 8 / 8
Line Coverage: 100.0% 20 / 20


Programs: 12 Runs 18108


       1                 : //===------- SemaTemplate.h - C++ Templates ---------------------*- 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                 : //  This file provides types used in the semantic analysis of C++ templates.
      10                 : //
      11                 : //===----------------------------------------------------------------------===/
      12                 : #ifndef LLVM_CLANG_SEMA_TEMPLATE_H
      13                 : #define LLVM_CLANG_SEMA_TEMPLATE_H
      14                 : 
      15                 : #include "clang/AST/DeclTemplate.h"
      16                 : #include "llvm/ADT/SmallVector.h"
      17                 : #include <cassert>
      18                 : 
      19                 : namespace clang {
      20                 :   /// \brief Data structure that captures multiple levels of template argument
      21                 :   /// lists for use in template instantiation.
      22                 :   ///
      23                 :   /// Multiple levels of template arguments occur when instantiating the 
      24                 :   /// definitions of member templates. For example:
      25                 :   ///
      26                 :   /// \code
      27                 :   /// template<typename T>
      28                 :   /// struct X {
      29                 :   ///   template<T Value>
      30                 :   ///   struct Y {
      31                 :   ///     void f();
      32                 :   ///   };
      33                 :   /// };
      34                 :   /// \endcode
      35                 :   ///
      36                 :   /// When instantiating X<int>::Y<17>::f, the multi-level template argument
      37                 :   /// list will contain a template argument list (int) at depth 0 and a
      38                 :   /// template argument list (17) at depth 1.
      39             4155:   struct MultiLevelTemplateArgumentList {
      40                 :     /// \brief The template argument lists, stored from the innermost template
      41                 :     /// argument list (first) to the outermost template argument list (last).
      42                 :     llvm::SmallVector<const TemplateArgumentList *, 4> TemplateArgumentLists;
      43                 :     
      44                 :   public:
      45                 :     /// \brief Construct an empty set of template argument lists.
      46             2354:     MultiLevelTemplateArgumentList() { }
      47                 :     
      48                 :     /// \brief Construct a single-level template argument list.
      49                 :     explicit 
      50             1801:     MultiLevelTemplateArgumentList(const TemplateArgumentList &TemplateArgs) {
      51             1801:       TemplateArgumentLists.push_back(&TemplateArgs);
      52             1801:     }
      53                 :     
      54                 :     /// \brief Determine the number of levels in this template argument
      55                 :     /// list.
      56            28528:     unsigned getNumLevels() const { return TemplateArgumentLists.size(); }
      57                 :     
      58                 :     /// \brief Retrieve the template argument at a given depth and index.
      59            10338:     const TemplateArgument &operator()(unsigned Depth, unsigned Index) const {
                        0: branch 1 not taken
                    10338: branch 2 taken
      60            10338:       assert(Depth < TemplateArgumentLists.size());
                        0: branch 3 not taken
                    10338: branch 4 taken
      61            10338:       assert(Index < TemplateArgumentLists[getNumLevels() - Depth - 1]->size());
      62            10338:       return TemplateArgumentLists[getNumLevels() - Depth - 1]->get(Index);
      63                 :     }
      64                 :     
      65                 :     /// \brief Determine whether there is a non-NULL template argument at the
      66                 :     /// given depth and index.
      67                 :     ///
      68                 :     /// There must exist a template argument list at the given depth.
      69             3855:     bool hasTemplateArgument(unsigned Depth, unsigned Index) const {
                        0: branch 1 not taken
                     3855: branch 2 taken
      70             3855:       assert(Depth < TemplateArgumentLists.size());
      71                 :       
                       36: branch 3 taken
                     3819: branch 4 taken
      72             3855:       if (Index >= TemplateArgumentLists[getNumLevels() - Depth - 1]->size())
      73               36:         return false;
      74                 :       
      75             3819:       return !(*this)(Depth, Index).isNull();
      76                 :     }
      77                 :     
      78                 :     /// \brief Add a new outermost level to the multi-level template argument 
      79                 :     /// list.
      80             2448:     void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs) {
      81             2448:       TemplateArgumentLists.push_back(TemplateArgs);
      82             2448:     }
      83                 :     
      84                 :     /// \brief Retrieve the innermost template argument list.
      85             2465:     const TemplateArgumentList &getInnermost() const {
      86             2465:       return *TemplateArgumentLists.front();
      87                 :     }
      88                 :   };
      89                 :   
      90                 :   /// \brief The context in which partial ordering of function templates occurs.
      91                 :   enum TemplatePartialOrderingContext {
      92                 :     /// \brief Partial ordering of function templates for a function call.
      93                 :     TPOC_Call,
      94                 :     /// \brief Partial ordering of function templates for a call to a 
      95                 :     /// conversion function.
      96                 :     TPOC_Conversion,
      97                 :     /// \brief Partial ordering of function templates in other contexts, e.g.,
      98                 :     /// taking the address of a function template or matching a function 
      99                 :     /// template specialization to a function template.
     100                 :     TPOC_Other
     101                 :   };
     102                 : }
     103                 : 
     104                 : #endif // LLVM_CLANG_SEMA_TEMPLATE_H

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