| Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 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" | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclCXX.h" | 
| Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 18 | #include "clang/AST/PrettyPrinter.h" | 
| Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 19 | #include "clang/AST/Type.h" | 
| Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 20 | #include "clang/AST/TypeLoc.h" | 
| Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 22 | #include <cassert> | 
| Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 23 |  | 
| Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 24 | using namespace clang; | 
|  | 25 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 26 | NestedNameSpecifier * | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 27 | NestedNameSpecifier::FindOrInsert(const ASTContext &Context, | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 28 | const NestedNameSpecifier &Mockup) { | 
|  | 29 | llvm::FoldingSetNodeID ID; | 
|  | 30 | Mockup.Profile(ID); | 
| Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 31 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 32 | void *InsertPos = 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | NestedNameSpecifier *NNS | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 34 | = Context.NestedNameSpecifiers.FindNodeOrInsertPos(ID, InsertPos); | 
|  | 35 | if (!NNS) { | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 36 | NNS = new (Context, 4) NestedNameSpecifier(Mockup); | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 37 | Context.NestedNameSpecifiers.InsertNode(NNS, InsertPos); | 
|  | 38 | } | 
| Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 39 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 40 | return NNS; | 
| Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 41 | } | 
| Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 42 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 43 | NestedNameSpecifier * | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 44 | NestedNameSpecifier::Create(const ASTContext &Context, | 
|  | 45 | NestedNameSpecifier *Prefix, IdentifierInfo *II) { | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 46 | assert(II && "Identifier cannot be NULL"); | 
| Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 47 | assert((!Prefix || Prefix->isDependent()) && "Prefix must be dependent"); | 
| Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 48 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 49 | NestedNameSpecifier Mockup; | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 50 | Mockup.Prefix.setPointer(Prefix); | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 51 | Mockup.Prefix.setInt(StoredIdentifier); | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 52 | Mockup.Specifier = II; | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 53 | return FindOrInsert(Context, Mockup); | 
|  | 54 | } | 
| Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 55 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 56 | NestedNameSpecifier * | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 57 | NestedNameSpecifier::Create(const ASTContext &Context, | 
|  | 58 | NestedNameSpecifier *Prefix, NamespaceDecl *NS) { | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 59 | assert(NS && "Namespace cannot be NULL"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 60 | assert((!Prefix || | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 61 | (Prefix->getAsType() == 0 && Prefix->getAsIdentifier() == 0)) && | 
|  | 62 | "Broken nested name specifier"); | 
|  | 63 | NestedNameSpecifier Mockup; | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 64 | Mockup.Prefix.setPointer(Prefix); | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 65 | Mockup.Prefix.setInt(StoredNamespaceOrAlias); | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 66 | Mockup.Specifier = NS; | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 67 | return FindOrInsert(Context, Mockup); | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | NestedNameSpecifier * | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 71 | NestedNameSpecifier::Create(const ASTContext &Context, | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 72 | NestedNameSpecifier *Prefix, | 
|  | 73 | NamespaceAliasDecl *Alias) { | 
|  | 74 | assert(Alias && "Namespace alias cannot be NULL"); | 
|  | 75 | assert((!Prefix || | 
|  | 76 | (Prefix->getAsType() == 0 && Prefix->getAsIdentifier() == 0)) && | 
|  | 77 | "Broken nested name specifier"); | 
|  | 78 | NestedNameSpecifier Mockup; | 
|  | 79 | Mockup.Prefix.setPointer(Prefix); | 
|  | 80 | Mockup.Prefix.setInt(StoredNamespaceOrAlias); | 
|  | 81 | Mockup.Specifier = Alias; | 
|  | 82 | return FindOrInsert(Context, Mockup); | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | NestedNameSpecifier * | 
|  | 86 | NestedNameSpecifier::Create(const ASTContext &Context, | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 87 | NestedNameSpecifier *Prefix, | 
| John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 88 | bool Template, const Type *T) { | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 89 | assert(T && "Type cannot be NULL"); | 
|  | 90 | NestedNameSpecifier Mockup; | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 91 | Mockup.Prefix.setPointer(Prefix); | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 92 | Mockup.Prefix.setInt(Template? StoredTypeSpecWithTemplate : StoredTypeSpec); | 
| John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 93 | Mockup.Specifier = const_cast<Type*>(T); | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 94 | return FindOrInsert(Context, Mockup); | 
|  | 95 | } | 
| Douglas Gregor | 2700dcd | 2009-09-02 23:58:38 +0000 | [diff] [blame] | 96 |  | 
|  | 97 | NestedNameSpecifier * | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 98 | NestedNameSpecifier::Create(const ASTContext &Context, IdentifierInfo *II) { | 
| Douglas Gregor | 2700dcd | 2009-09-02 23:58:38 +0000 | [diff] [blame] | 99 | assert(II && "Identifier cannot be NULL"); | 
|  | 100 | NestedNameSpecifier Mockup; | 
|  | 101 | Mockup.Prefix.setPointer(0); | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 102 | Mockup.Prefix.setInt(StoredIdentifier); | 
| Douglas Gregor | 2700dcd | 2009-09-02 23:58:38 +0000 | [diff] [blame] | 103 | Mockup.Specifier = II; | 
|  | 104 | return FindOrInsert(Context, Mockup); | 
|  | 105 | } | 
|  | 106 |  | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 107 | NestedNameSpecifier * | 
|  | 108 | NestedNameSpecifier::GlobalSpecifier(const ASTContext &Context) { | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 109 | if (!Context.GlobalNestedNameSpecifier) | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 110 | Context.GlobalNestedNameSpecifier = new (Context, 4) NestedNameSpecifier(); | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 111 | return Context.GlobalNestedNameSpecifier; | 
|  | 112 | } | 
|  | 113 |  | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 114 | NestedNameSpecifier::SpecifierKind NestedNameSpecifier::getKind() const { | 
|  | 115 | if (Specifier == 0) | 
|  | 116 | return Global; | 
|  | 117 |  | 
|  | 118 | switch (Prefix.getInt()) { | 
|  | 119 | case StoredIdentifier: | 
|  | 120 | return Identifier; | 
|  | 121 |  | 
|  | 122 | case StoredNamespaceOrAlias: | 
|  | 123 | return isa<NamespaceDecl>(static_cast<NamedDecl *>(Specifier))? Namespace | 
|  | 124 | : NamespaceAlias; | 
|  | 125 |  | 
|  | 126 | case StoredTypeSpec: | 
|  | 127 | return TypeSpec; | 
|  | 128 |  | 
|  | 129 | case StoredTypeSpecWithTemplate: | 
|  | 130 | return TypeSpecWithTemplate; | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | return Global; | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | /// \brief Retrieve the namespace stored in this nested name | 
|  | 137 | /// specifier. | 
|  | 138 | NamespaceDecl *NestedNameSpecifier::getAsNamespace() const { | 
|  | 139 | if (Prefix.getInt() == StoredNamespaceOrAlias) | 
|  | 140 | return dyn_cast<NamespaceDecl>(static_cast<NamedDecl *>(Specifier)); | 
|  | 141 |  | 
|  | 142 | return 0; | 
|  | 143 | } | 
|  | 144 |  | 
|  | 145 | /// \brief Retrieve the namespace alias stored in this nested name | 
|  | 146 | /// specifier. | 
|  | 147 | NamespaceAliasDecl *NestedNameSpecifier::getAsNamespaceAlias() const { | 
|  | 148 | if (Prefix.getInt() == StoredNamespaceOrAlias) | 
|  | 149 | return dyn_cast<NamespaceAliasDecl>(static_cast<NamedDecl *>(Specifier)); | 
|  | 150 |  | 
|  | 151 | return 0; | 
|  | 152 | } | 
|  | 153 |  | 
|  | 154 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 155 | /// \brief Whether this nested name specifier refers to a dependent | 
|  | 156 | /// type or not. | 
|  | 157 | bool NestedNameSpecifier::isDependent() const { | 
|  | 158 | switch (getKind()) { | 
|  | 159 | case Identifier: | 
|  | 160 | // Identifier specifiers always represent dependent types | 
|  | 161 | return true; | 
|  | 162 |  | 
|  | 163 | case Namespace: | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 164 | case NamespaceAlias: | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 165 | case Global: | 
|  | 166 | return false; | 
|  | 167 |  | 
|  | 168 | case TypeSpec: | 
|  | 169 | case TypeSpecWithTemplate: | 
|  | 170 | return getAsType()->isDependentType(); | 
| Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 171 | } | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 172 |  | 
|  | 173 | // Necessary to suppress a GCC warning. | 
|  | 174 | return false; | 
|  | 175 | } | 
|  | 176 |  | 
| Douglas Gregor | d093722 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 177 | bool NestedNameSpecifier::containsUnexpandedParameterPack() const { | 
|  | 178 | switch (getKind()) { | 
|  | 179 | case Identifier: | 
|  | 180 | return getPrefix() && getPrefix()->containsUnexpandedParameterPack(); | 
|  | 181 |  | 
|  | 182 | case Namespace: | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 183 | case NamespaceAlias: | 
| Douglas Gregor | d093722 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 184 | case Global: | 
|  | 185 | return false; | 
|  | 186 |  | 
|  | 187 | case TypeSpec: | 
|  | 188 | case TypeSpecWithTemplate: | 
|  | 189 | return getAsType()->containsUnexpandedParameterPack(); | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | // Necessary to suppress a GCC warning. | 
|  | 193 | return false; | 
|  | 194 | } | 
|  | 195 |  | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 196 | /// \brief Print this nested name specifier to the given output | 
|  | 197 | /// stream. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 198 | void | 
|  | 199 | NestedNameSpecifier::print(llvm::raw_ostream &OS, | 
| Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 200 | const PrintingPolicy &Policy) const { | 
| Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 201 | if (getPrefix()) | 
| Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 202 | getPrefix()->print(OS, Policy); | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 203 |  | 
|  | 204 | switch (getKind()) { | 
|  | 205 | case Identifier: | 
|  | 206 | OS << getAsIdentifier()->getName(); | 
|  | 207 | break; | 
|  | 208 |  | 
|  | 209 | case Namespace: | 
| Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 210 | OS << getAsNamespace()->getName(); | 
|  | 211 | break; | 
|  | 212 |  | 
|  | 213 | case NamespaceAlias: | 
|  | 214 | OS << getAsNamespaceAlias()->getName(); | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 215 | break; | 
|  | 216 |  | 
|  | 217 | case Global: | 
|  | 218 | break; | 
|  | 219 |  | 
|  | 220 | case TypeSpecWithTemplate: | 
|  | 221 | OS << "template "; | 
|  | 222 | // Fall through to print the type. | 
|  | 223 |  | 
|  | 224 | case TypeSpec: { | 
|  | 225 | std::string TypeStr; | 
| John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 226 | const Type *T = getAsType(); | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 227 |  | 
| Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 228 | PrintingPolicy InnerPolicy(Policy); | 
| John McCall | 2191b20 | 2009-09-05 06:31:47 +0000 | [diff] [blame] | 229 | InnerPolicy.SuppressScope = true; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 230 |  | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 231 | // Nested-name-specifiers are intended to contain minimally-qualified | 
| Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 232 | // types. An actual ElaboratedType will not occur, since we'll store | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 233 | // just the type that is referred to in the nested-name-specifier (e.g., | 
|  | 234 | // a TypedefType, TagType, etc.). However, when we are dealing with | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 235 | // dependent template-id types (e.g., Outer<T>::template Inner<U>), | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 236 | // the type requires its own nested-name-specifier for uniqueness, so we | 
|  | 237 | // suppress that nested-name-specifier during printing. | 
| Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 238 | assert(!isa<ElaboratedType>(T) && | 
|  | 239 | "Elaborated type in nested-name-specifier"); | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 240 | if (const TemplateSpecializationType *SpecType | 
|  | 241 | = dyn_cast<TemplateSpecializationType>(T)) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | // Print the template name without its corresponding | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 243 | // nested-name-specifier. | 
|  | 244 | SpecType->getTemplateName().print(OS, InnerPolicy, true); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 |  | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 246 | // Print the template argument list. | 
|  | 247 | TypeStr = TemplateSpecializationType::PrintTemplateArgumentList( | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | SpecType->getArgs(), | 
|  | 249 | SpecType->getNumArgs(), | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 250 | InnerPolicy); | 
|  | 251 | } else { | 
|  | 252 | // Print the type normally | 
| Douglas Gregor | fee8a3c | 2009-11-10 00:39:07 +0000 | [diff] [blame] | 253 | TypeStr = QualType(T, 0).getAsString(InnerPolicy); | 
| Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 254 | } | 
| Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 255 | OS << TypeStr; | 
|  | 256 | break; | 
|  | 257 | } | 
|  | 258 | } | 
|  | 259 |  | 
|  | 260 | OS << "::"; | 
|  | 261 | } | 
|  | 262 |  | 
| Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 263 | void NestedNameSpecifier::dump(const LangOptions &LO) { | 
|  | 264 | print(llvm::errs(), PrintingPolicy(LO)); | 
| Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 265 | } | 
| Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 266 |  | 
|  | 267 | unsigned | 
|  | 268 | NestedNameSpecifierLoc::getLocalDataLength(NestedNameSpecifier *Qualifier) { | 
|  | 269 | assert(Qualifier && "Expected a non-NULL qualifier"); | 
|  | 270 |  | 
|  | 271 | // Location of the trailing '::'. | 
|  | 272 | unsigned Length = sizeof(unsigned); | 
|  | 273 |  | 
|  | 274 | switch (Qualifier->getKind()) { | 
|  | 275 | case NestedNameSpecifier::Global: | 
|  | 276 | // Nothing more to add. | 
|  | 277 | break; | 
|  | 278 |  | 
|  | 279 | case NestedNameSpecifier::Identifier: | 
|  | 280 | case NestedNameSpecifier::Namespace: | 
|  | 281 | case NestedNameSpecifier::NamespaceAlias: | 
|  | 282 | // The location of the identifier or namespace name. | 
|  | 283 | Length += sizeof(unsigned); | 
|  | 284 | break; | 
|  | 285 |  | 
|  | 286 | case NestedNameSpecifier::TypeSpecWithTemplate: | 
|  | 287 | case NestedNameSpecifier::TypeSpec: | 
|  | 288 | // The "void*" that points at the TypeLoc data. | 
|  | 289 | // Note: the 'template' keyword is part of the TypeLoc. | 
|  | 290 | Length += sizeof(void *); | 
|  | 291 | break; | 
|  | 292 | } | 
|  | 293 |  | 
|  | 294 | return Length; | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | unsigned | 
|  | 298 | NestedNameSpecifierLoc::getDataLength(NestedNameSpecifier *Qualifier) { | 
|  | 299 | unsigned Length = 0; | 
|  | 300 | for (; Qualifier; Qualifier = Qualifier->getPrefix()) | 
|  | 301 | Length += getLocalDataLength(Qualifier); | 
|  | 302 | return Length; | 
|  | 303 | } | 
|  | 304 |  | 
|  | 305 | namespace { | 
|  | 306 | /// \brief Load a (possibly unaligned) source location from a given address | 
|  | 307 | /// and offset. | 
|  | 308 | SourceLocation LoadSourceLocation(void *Data, unsigned Offset) { | 
|  | 309 | unsigned Raw; | 
|  | 310 | memcpy(&Raw, static_cast<char *>(Data) + Offset, sizeof(unsigned)); | 
|  | 311 | return SourceLocation::getFromRawEncoding(Raw); | 
|  | 312 | } | 
|  | 313 |  | 
|  | 314 | /// \brief Load a (possibly unaligned) pointer from a given address and | 
|  | 315 | /// offset. | 
|  | 316 | void *LoadPointer(void *Data, unsigned Offset) { | 
|  | 317 | void *Result; | 
|  | 318 | memcpy(&Result, static_cast<char *>(Data) + Offset, sizeof(void*)); | 
|  | 319 | return Result; | 
|  | 320 | } | 
|  | 321 | } | 
|  | 322 |  | 
|  | 323 | SourceRange NestedNameSpecifierLoc::getSourceRange() { | 
|  | 324 | NestedNameSpecifierLoc First = *this; | 
|  | 325 | while (NestedNameSpecifierLoc Prefix= First.getPrefix()) | 
|  | 326 | First = Prefix; | 
|  | 327 |  | 
|  | 328 | return SourceRange(First.getLocalSourceRange().getBegin(), | 
|  | 329 | getLocalSourceRange().getEnd()); | 
|  | 330 | } | 
|  | 331 |  | 
|  | 332 | SourceRange NestedNameSpecifierLoc::getLocalSourceRange() { | 
|  | 333 | unsigned Offset = getDataLength(Qualifier->getPrefix()); | 
|  | 334 | switch (Qualifier->getKind()) { | 
|  | 335 | case NestedNameSpecifier::Global: | 
|  | 336 | return LoadSourceLocation(Data, Offset); | 
|  | 337 |  | 
|  | 338 | case NestedNameSpecifier::Identifier: | 
|  | 339 | case NestedNameSpecifier::Namespace: | 
|  | 340 | case NestedNameSpecifier::NamespaceAlias: | 
|  | 341 | return SourceRange(LoadSourceLocation(Data, Offset), | 
|  | 342 | LoadSourceLocation(Data, Offset + sizeof(unsigned))); | 
|  | 343 |  | 
|  | 344 | case NestedNameSpecifier::TypeSpecWithTemplate: | 
|  | 345 | case NestedNameSpecifier::TypeSpec: { | 
|  | 346 | // The "void*" that points at the TypeLoc data. | 
|  | 347 | // Note: the 'template' keyword is part of the TypeLoc. | 
|  | 348 | void *TypeData = LoadPointer(Data, Offset); | 
|  | 349 | TypeLoc TL(Qualifier->getAsType(), TypeData); | 
|  | 350 | return SourceRange(TL.getBeginLoc(), | 
|  | 351 | LoadSourceLocation(Data, Offset + sizeof(void*))); | 
|  | 352 | } | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | return SourceRange(); | 
|  | 356 | } |