summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-11-09 23:41:00 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-11-09 23:41:00 +0000
commit9e59b577d8221601419f734f14ff19c594c269d6 (patch)
tree1425c0ffa3234253224d48a6715d79b4ac7620dc /clang/lib/Sema
parent4fb13c051d7a628ae024ba59073221e234b5d4e1 (diff)
downloadbcm5719-llvm-9e59b577d8221601419f734f14ff19c594c269d6.tar.gz
bcm5719-llvm-9e59b577d8221601419f734f14ff19c594c269d6.zip
Introduce ScopedDecl::getLexicalDeclContext() which is different from ScopedDecl::getDeclContext() when there are nested-names.
e.g.: namespace A { void f(); // SemanticDC (getDeclContext) == LexicalDC (getLexicalDeclContext) == 'namespace A' } void A::f(); // SemanticDC == namespace 'A' // LexicalDC == global namespace llvm-svn: 58948
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/Sema.h4
-rw-r--r--clang/lib/Sema/SemaDecl.cpp34
2 files changed, 21 insertions, 17 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index 178ab13f166..d7518e0aa7b 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -109,10 +109,6 @@ public:
/// CurContext - This is the current declaration context of parsing.
DeclContext *CurContext;
- /// LexicalFileContext - The current lexical file declaration context,
- /// the translation unit or a namespace.
- DeclContext *LexicalFileContext;
-
/// PreDeclaratorDC - Keeps the declaration context before switching to the
/// context of a declarator's nested-name-specifier.
DeclContext *PreDeclaratorDC;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index cae05a365c0..6c71d508953 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -53,8 +53,8 @@ std::string Sema::getTypeAsString(TypeTy *Type) {
DeclContext *Sema::getContainingDC(DeclContext *DC) {
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) {
// A C++ out-of-line method will return to the file declaration context.
- if (!MD->isInlineDefinition())
- return LexicalFileContext;
+ if (MD->isOutOfLineDefinition())
+ return MD->getLexicalDeclContext();
// A C++ inline method is parsed *after* the topmost class it was declared in
// is fully parsed (it's "complete").
@@ -70,25 +70,24 @@ DeclContext *Sema::getContainingDC(DeclContext *DC) {
return DC;
}
- if (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC))
- return LexicalFileContext;
+ if (isa<ObjCMethodDecl>(DC))
+ return Context.getTranslationUnitDecl();
+
+ if (ScopedDecl *SD = dyn_cast<ScopedDecl>(DC))
+ return SD->getLexicalDeclContext();
return DC->getParent();
}
void Sema::PushDeclContext(DeclContext *DC) {
assert(getContainingDC(DC) == CurContext &&
- "The next DeclContext should be directly contained in the current one.");
+ "The next DeclContext should be lexically contained in the current one.");
CurContext = DC;
- if (CurContext->isFileContext())
- LexicalFileContext = CurContext;
}
void Sema::PopDeclContext() {
assert(CurContext && "DeclContext imbalance!");
CurContext = getContainingDC(CurContext);
- if (CurContext->isFileContext())
- LexicalFileContext = CurContext;
}
/// Add this decl to the scope shadowed decl chains.
@@ -1147,6 +1146,10 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
New = NewVD;
}
+ // Set the lexical context. If the declarator has a C++ scope specifier, the
+ // lexical context will be different from the semantic context.
+ New->setLexicalDeclContext(CurContext);
+
// If this has an identifier, add it to the scope stack.
if (II)
PushOnScopeChains(New, S);
@@ -2004,10 +2007,6 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
Diag(Definition->getLocation(), diag::err_previous_definition);
}
- if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
- if (isa<CXXRecordDecl>(CurContext))
- MD->setInlineDefinition(true);
-
PushDeclContext(FD);
// Check the validity of our function parameters
@@ -2267,6 +2266,11 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,
if (Attr)
ProcessDeclAttributeList(New, Attr);
+
+ // Set the lexical context. If the tag has a C++ scope specifier, the
+ // lexical context will be different from the semantic context.
+ New->setLexicalDeclContext(CurContext);
+
return New;
}
@@ -2421,6 +2425,10 @@ Sema::DeclTy *Sema::ActOnTagStruct(Scope *S, TagDecl::TagKind Kind, TagKind TK,
if (Attr)
ProcessDeclAttributeList(New, Attr);
+ // Set the lexical context. If the tag has a C++ scope specifier, the
+ // lexical context will be different from the semantic context.
+ New->setLexicalDeclContext(CurContext);
+
return New;
}
OpenPOWER on IntegriCloud