Deleted Added
full compact
SemaCXXScopeSpec.cpp (198092) SemaCXXScopeSpec.cpp (198954)
1//===--- SemaCXXScopeSpec.cpp - Semantic Analysis for C++ scope specifiers-===//
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//===----------------------------------------------------------------------===//

--- 8 unchanged lines hidden (view full) ---

17#include "clang/AST/ExprCXX.h"
18#include "clang/AST/NestedNameSpecifier.h"
19#include "clang/Basic/PartialDiagnostic.h"
20#include "clang/Parse/DeclSpec.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/Support/raw_ostream.h"
23using namespace clang;
24
1//===--- SemaCXXScopeSpec.cpp - Semantic Analysis for C++ scope specifiers-===//
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//===----------------------------------------------------------------------===//

--- 8 unchanged lines hidden (view full) ---

17#include "clang/AST/ExprCXX.h"
18#include "clang/AST/NestedNameSpecifier.h"
19#include "clang/Basic/PartialDiagnostic.h"
20#include "clang/Parse/DeclSpec.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/Support/raw_ostream.h"
23using namespace clang;
24
25/// \brief Find the current instantiation that associated with the given type.
26static CXXRecordDecl *
27getCurrentInstantiationOf(ASTContext &Context, DeclContext *CurContext,
28 QualType T) {
29 if (T.isNull())
30 return 0;
31
32 T = Context.getCanonicalType(T);
33
34 for (DeclContext *Ctx = CurContext; Ctx; Ctx = Ctx->getParent()) {
35 // If we've hit a namespace or the global scope, then the
36 // nested-name-specifier can't refer to the current instantiation.
37 if (Ctx->isFileContext())
38 return 0;
39
40 // Skip non-class contexts.
41 CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Ctx);
42 if (!Record)
43 continue;
44
45 // If this record type is not dependent,
46 if (!Record->isDependentType())
47 return 0;
48
49 // C++ [temp.dep.type]p1:
50 //
51 // In the definition of a class template, a nested class of a
52 // class template, a member of a class template, or a member of a
53 // nested class of a class template, a name refers to the current
54 // instantiation if it is
55 // -- the injected-class-name (9) of the class template or
56 // nested class,
57 // -- in the definition of a primary class template, the name
58 // of the class template followed by the template argument
59 // list of the primary template (as described below)
60 // enclosed in <>,
61 // -- in the definition of a nested class of a class template,
62 // the name of the nested class referenced as a member of
63 // the current instantiation, or
64 // -- in the definition of a partial specialization, the name
65 // of the class template followed by the template argument
66 // list of the partial specialization enclosed in <>. If
67 // the nth template parameter is a parameter pack, the nth
68 // template argument is a pack expansion (14.6.3) whose
69 // pattern is the name of the parameter pack.
70 // (FIXME: parameter packs)
71 //
72 // All of these options come down to having the
73 // nested-name-specifier type that is equivalent to the
74 // injected-class-name of one of the types that is currently in
75 // our context.
76 if (Context.getCanonicalType(Context.getTypeDeclType(Record)) == T)
77 return Record;
78
79 if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) {
80 QualType InjectedClassName
81 = Template->getInjectedClassNameType(Context);
82 if (T == Context.getCanonicalType(InjectedClassName))
83 return Template->getTemplatedDecl();
84 }
85 // FIXME: check for class template partial specializations
86 }
87
88 return 0;
89}
90
25/// \brief Compute the DeclContext that is associated with the given type.
26///
27/// \param T the type for which we are attempting to find a DeclContext.
28///
29/// \returns the declaration context represented by the type T,
30/// or NULL if the declaration context cannot be computed (e.g., because it is
31/// dependent and not the current instantiation).
32DeclContext *Sema::computeDeclContext(QualType T) {
33 if (const TagType *Tag = T->getAs<TagType>())
34 return Tag->getDecl();
35
91/// \brief Compute the DeclContext that is associated with the given type.
92///
93/// \param T the type for which we are attempting to find a DeclContext.
94///
95/// \returns the declaration context represented by the type T,
96/// or NULL if the declaration context cannot be computed (e.g., because it is
97/// dependent and not the current instantiation).
98DeclContext *Sema::computeDeclContext(QualType T) {
99 if (const TagType *Tag = T->getAs<TagType>())
100 return Tag->getDecl();
101
36 return 0;
102 return ::getCurrentInstantiationOf(Context, CurContext, T);
37}
38
39/// \brief Compute the DeclContext that is associated with the given
40/// scope specifier.
41///
42/// \param SS the C++ scope specifier as it appears in the source
43///
44/// \param EnteringContext when true, we will be entering the context of

--- 106 unchanged lines hidden (view full) ---

151CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) {
152 assert(getLangOptions().CPlusPlus && "Only callable in C++");
153 assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
154
155 if (!NNS->getAsType())
156 return 0;
157
158 QualType T = QualType(NNS->getAsType(), 0);
103}
104
105/// \brief Compute the DeclContext that is associated with the given
106/// scope specifier.
107///
108/// \param SS the C++ scope specifier as it appears in the source
109///
110/// \param EnteringContext when true, we will be entering the context of

--- 106 unchanged lines hidden (view full) ---

217CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) {
218 assert(getLangOptions().CPlusPlus && "Only callable in C++");
219 assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
220
221 if (!NNS->getAsType())
222 return 0;
223
224 QualType T = QualType(NNS->getAsType(), 0);
159 // If the nested name specifier does not refer to a type, then it
160 // does not refer to the current instantiation.
161 if (T.isNull())
162 return 0;
163
164 T = Context.getCanonicalType(T);
165
166 for (DeclContext *Ctx = CurContext; Ctx; Ctx = Ctx->getParent()) {
167 // If we've hit a namespace or the global scope, then the
168 // nested-name-specifier can't refer to the current instantiation.
169 if (Ctx->isFileContext())
170 return 0;
171
172 // Skip non-class contexts.
173 CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Ctx);
174 if (!Record)
175 continue;
176
177 // If this record type is not dependent,
178 if (!Record->isDependentType())
179 return 0;
180
181 // C++ [temp.dep.type]p1:
182 //
183 // In the definition of a class template, a nested class of a
184 // class template, a member of a class template, or a member of a
185 // nested class of a class template, a name refers to the current
186 // instantiation if it is
187 // -- the injected-class-name (9) of the class template or
188 // nested class,
189 // -- in the definition of a primary class template, the name
190 // of the class template followed by the template argument
191 // list of the primary template (as described below)
192 // enclosed in <>,
193 // -- in the definition of a nested class of a class template,
194 // the name of the nested class referenced as a member of
195 // the current instantiation, or
196 // -- in the definition of a partial specialization, the name
197 // of the class template followed by the template argument
198 // list of the partial specialization enclosed in <>. If
199 // the nth template parameter is a parameter pack, the nth
200 // template argument is a pack expansion (14.6.3) whose
201 // pattern is the name of the parameter pack.
202 // (FIXME: parameter packs)
203 //
204 // All of these options come down to having the
205 // nested-name-specifier type that is equivalent to the
206 // injected-class-name of one of the types that is currently in
207 // our context.
208 if (Context.getCanonicalType(Context.getTypeDeclType(Record)) == T)
209 return Record;
210
211 if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) {
212 QualType InjectedClassName
213 = Template->getInjectedClassNameType(Context);
214 if (T == Context.getCanonicalType(InjectedClassName))
215 return Template->getTemplatedDecl();
216 }
217 // FIXME: check for class template partial specializations
218 }
219
220 return 0;
225 return ::getCurrentInstantiationOf(Context, CurContext, T);
221}
222
223/// \brief Require that the context specified by SS be complete.
224///
225/// If SS refers to a type, this routine checks whether the type is
226/// complete enough (or can be made complete enough) for name lookup
227/// into the DeclContext. A type that is not yet completed can be
228/// considered "complete enough" if it is a class/struct/union/enum

--- 320 unchanged lines hidden ---
226}
227
228/// \brief Require that the context specified by SS be complete.
229///
230/// If SS refers to a type, this routine checks whether the type is
231/// complete enough (or can be made complete enough) for name lookup
232/// into the DeclContext. A type that is not yet completed can be
233/// considered "complete enough" if it is a class/struct/union/enum

--- 320 unchanged lines hidden ---