zcov: / lib/AST/NestedNameSpecifier.cpp


Files: 1 Branches Taken: 68.2% 30 / 44
Generated: 2010-02-10 01:31 Branches Executed: 100.0% 44 / 44
Line Coverage: 93.8% 76 / 81


Programs: 2 Runs 3018


       1                 : //===--- NestedNameSpecifier.cpp - C++ nested name specifiers -----*- 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 defines the NestedNameSpecifier class, which represents
      11                 : //  a C++ nested-name-specifier.
      12                 : //
      13                 : //===----------------------------------------------------------------------===//
      14                 : #include "clang/AST/NestedNameSpecifier.h"
      15                 : #include "clang/AST/ASTContext.h"
      16                 : #include "clang/AST/Decl.h"
      17                 : #include "clang/AST/PrettyPrinter.h"
      18                 : #include "clang/AST/Type.h"
      19                 : #include "llvm/Support/raw_ostream.h"
      20                 : #include <cassert>
      21                 : 
      22                 : using namespace clang;
      23                 : 
      24                 : NestedNameSpecifier *
      25                 : NestedNameSpecifier::FindOrInsert(ASTContext &Context,
      26             3404:                                   const NestedNameSpecifier &Mockup) {
      27             3404:   llvm::FoldingSetNodeID ID;
      28             3404:   Mockup.Profile(ID);
      29                 : 
      30             3404:   void *InsertPos = 0;
      31                 :   NestedNameSpecifier *NNS
      32             3404:     = Context.NestedNameSpecifiers.FindNodeOrInsertPos(ID, InsertPos);
                     2280: branch 0 taken
                     1124: branch 1 taken
      33             3404:   if (!NNS) {
                     2280: branch 1 taken
                        0: branch 2 not taken
      34             2280:     NNS = new (Context, 4) NestedNameSpecifier(Mockup);
      35             2280:     Context.NestedNameSpecifiers.InsertNode(NNS, InsertPos);
      36                 :   }
      37                 : 
      38             3404:   return NNS;
      39                 : }
      40                 : 
      41                 : NestedNameSpecifier *
      42                 : NestedNameSpecifier::Create(ASTContext &Context, NestedNameSpecifier *Prefix,
      43               24:                             IdentifierInfo *II) {
                        0: branch 0 not taken
                       24: branch 1 taken
      44               24:   assert(II && "Identifier cannot be NULL");
                       20: branch 0 taken
                        4: branch 1 taken
                       20: branch 3 taken
                        0: branch 4 not taken
      45               24:   assert((!Prefix || Prefix->isDependent()) && "Prefix must be dependent");
      46                 : 
      47               24:   NestedNameSpecifier Mockup;
      48               24:   Mockup.Prefix.setPointer(Prefix);
      49               24:   Mockup.Prefix.setInt(Identifier);
      50               24:   Mockup.Specifier = II;
      51               24:   return FindOrInsert(Context, Mockup);
      52                 : }
      53                 : 
      54                 : NestedNameSpecifier *
      55                 : NestedNameSpecifier::Create(ASTContext &Context, NestedNameSpecifier *Prefix,
      56              555:                             NamespaceDecl *NS) {
                        0: branch 0 not taken
                      555: branch 1 taken
      57              555:   assert(NS && "Namespace cannot be NULL");
      58                 :   assert((!Prefix ||
      59                 :           (Prefix->getAsType() == 0 && Prefix->getAsIdentifier() == 0)) &&
                       64: branch 0 taken
                      491: branch 1 taken
                       64: branch 3 taken
                        0: branch 4 not taken
                       64: branch 6 taken
                        0: branch 7 not taken
      60              555:          "Broken nested name specifier");
      61              555:   NestedNameSpecifier Mockup;
      62              555:   Mockup.Prefix.setPointer(Prefix);
      63              555:   Mockup.Prefix.setInt(Namespace);
      64              555:   Mockup.Specifier = NS;
      65              555:   return FindOrInsert(Context, Mockup);
      66                 : }
      67                 : 
      68                 : NestedNameSpecifier *
      69                 : NestedNameSpecifier::Create(ASTContext &Context, NestedNameSpecifier *Prefix,
      70             2810:                             bool Template, Type *T) {
                        0: branch 0 not taken
                     2810: branch 1 taken
      71             2810:   assert(T && "Type cannot be NULL");
      72             2810:   NestedNameSpecifier Mockup;
      73             2810:   Mockup.Prefix.setPointer(Prefix);
                        0: branch 0 not taken
                     2810: branch 1 taken
      74             2810:   Mockup.Prefix.setInt(Template? TypeSpecWithTemplate : TypeSpec);
      75             2810:   Mockup.Specifier = T;
      76             2810:   return FindOrInsert(Context, Mockup);
      77                 : }
      78                 : 
      79                 : NestedNameSpecifier *
      80               15: NestedNameSpecifier::Create(ASTContext &Context, IdentifierInfo *II) {
                        0: branch 0 not taken
                       15: branch 1 taken
      81               15:   assert(II && "Identifier cannot be NULL");
      82               15:   NestedNameSpecifier Mockup;
      83               15:   Mockup.Prefix.setPointer(0);
      84               15:   Mockup.Prefix.setInt(Identifier);
      85               15:   Mockup.Specifier = II;
      86               15:   return FindOrInsert(Context, Mockup);
      87                 : }
      88                 : 
      89               85: NestedNameSpecifier *NestedNameSpecifier::GlobalSpecifier(ASTContext &Context) {
                       42: branch 0 taken
                       43: branch 1 taken
      90               85:   if (!Context.GlobalNestedNameSpecifier)
                       42: branch 1 taken
                        0: branch 2 not taken
      91               42:     Context.GlobalNestedNameSpecifier = new (Context, 4) NestedNameSpecifier();
      92               85:   return Context.GlobalNestedNameSpecifier;
      93                 : }
      94                 : 
      95                 : /// \brief Whether this nested name specifier refers to a dependent
      96                 : /// type or not.
      97            12584: bool NestedNameSpecifier::isDependent() const {
                      110: branch 1 taken
                     2073: branch 2 taken
                    10401: branch 3 taken
                        0: branch 4 not taken
      98            12584:   switch (getKind()) {
      99                 :   case Identifier:
     100                 :     // Identifier specifiers always represent dependent types
     101              110:     return true;
     102                 : 
     103                 :   case Namespace:
     104                 :   case Global:
     105             2073:     return false;
     106                 : 
     107                 :   case TypeSpec:
     108                 :   case TypeSpecWithTemplate:
     109            10401:     return getAsType()->isDependentType();
     110                 :   }
     111                 : 
     112                 :   // Necessary to suppress a GCC warning.
     113                0:   return false;
     114                 : }
     115                 : 
     116                 : /// \brief Print this nested name specifier to the given output
     117                 : /// stream.
     118                 : void
     119                 : NestedNameSpecifier::print(llvm::raw_ostream &OS,
     120              126:                            const PrintingPolicy &Policy) const {
                       27: branch 1 taken
                       99: branch 2 taken
     121              126:   if (getPrefix())
     122               27:     getPrefix()->print(OS, Policy);
     123                 : 
                        1: branch 1 taken
                       51: branch 2 taken
                        9: branch 3 taken
                        0: branch 4 not taken
                       65: branch 5 taken
                        0: branch 6 not taken
     124              126:   switch (getKind()) {
     125                 :   case Identifier:
     126                1:     OS << getAsIdentifier()->getName();
     127                1:     break;
     128                 : 
     129                 :   case Namespace:
     130               51:     OS << getAsNamespace()->getIdentifier()->getName();
     131               51:     break;
     132                 : 
     133                 :   case Global:
     134                9:     break;
     135                 : 
     136                 :   case TypeSpecWithTemplate:
     137                0:     OS << "template ";
     138                 :     // Fall through to print the type.
     139                 : 
     140                 :   case TypeSpec: {
     141               65:     std::string TypeStr;
     142               65:     Type *T = getAsType();
     143                 : 
     144               65:     PrintingPolicy InnerPolicy(Policy);
     145               65:     InnerPolicy.SuppressTagKind = true;
     146               65:     InnerPolicy.SuppressScope = true;
     147                 : 
     148                 :     // Nested-name-specifiers are intended to contain minimally-qualified
     149                 :     // types. An actual QualifiedNameType will not occur, since we'll store
     150                 :     // just the type that is referred to in the nested-name-specifier (e.g.,
     151                 :     // a TypedefType, TagType, etc.). However, when we are dealing with
     152                 :     // dependent template-id types (e.g., Outer<T>::template Inner<U>),
     153                 :     // the type requires its own nested-name-specifier for uniqueness, so we
     154                 :     // suppress that nested-name-specifier during printing.
     155                 :     assert(!isa<QualifiedNameType>(T) &&
                       65: branch 1 taken
                        0: branch 2 not taken
     156               65:            "Qualified name type in nested-name-specifier");
                       21: branch 0 taken
                       44: branch 1 taken
     157               65:     if (const TemplateSpecializationType *SpecType
     158               65:           = dyn_cast<TemplateSpecializationType>(T)) {
     159                 :       // Print the template name without its corresponding
     160                 :       // nested-name-specifier.
     161               21:       SpecType->getTemplateName().print(OS, InnerPolicy, true);
     162                 : 
     163                 :       // Print the template argument list.
     164                 :       TypeStr = TemplateSpecializationType::PrintTemplateArgumentList(
     165                 :                                                           SpecType->getArgs(),
     166                 :                                                        SpecType->getNumArgs(),
     167               21:                                                                  InnerPolicy);
     168                 :     } else {
     169                 :       // Print the type normally
     170               44:       TypeStr = QualType(T, 0).getAsString(InnerPolicy);
     171                 :     }
     172               65:     OS << TypeStr;
     173               65:     break;
     174                 :   }
     175                 :   }
     176                 : 
     177              126:   OS << "::";
     178              126: }
     179                 : 
     180             2309: void NestedNameSpecifier::Destroy(ASTContext &Context) {
     181             2309:   this->~NestedNameSpecifier();
     182             2309:   Context.Deallocate((void *)this);
     183             2309: }
     184                 : 
     185                0: void NestedNameSpecifier::dump(const LangOptions &LO) {
     186                0:   print(llvm::errs(), PrintingPolicy(LO));
     187                0: }

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