Phase 2 of making the Decl class more lightweight...
Move Identifier/Loc instance variables (and associated getters/setters) down from Decl to ScopedDecl/FieldDecl.
Objc AST's can now inherit from Decl without getting instance variables and types that are C specific. For now, I am keeping NextDeclarator, since I believe it may be useful to ObjC. If not, it can be moved later.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41934 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 2cc1148..3095308 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -166,9 +166,9 @@
private:
/// Subroutines of ParseDeclarator()...
TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
- TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
- FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old);
- VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
+ TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
+ FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
+ VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);
/// AddTopLevelDecl - called after the decl has been fully processed.
/// Allows for bookkeeping and post-processing of each declaration.
void AddTopLevelDecl(Decl *current, Decl *last);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 02d9350..97e8e07 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -147,7 +147,7 @@
/// and scope as a previous declaration 'Old'. Figure out how to resolve this
/// situation, merging decls or emitting diagnostics as appropriate.
///
-TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
+TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *OldD) {
// Verify the old decl was also a typedef.
TypedefDecl *Old = dyn_cast<TypedefDecl>(OldD);
if (!Old) {
@@ -169,7 +169,7 @@
/// and scope as a previous declaration 'Old'. Figure out how to resolve this
/// situation, merging decls or emitting diagnostics as appropriate.
///
-FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
+FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, ScopedDecl *OldD) {
// Verify the old decl was also a function.
FunctionDecl *Old = dyn_cast<FunctionDecl>(OldD);
if (!Old) {
@@ -202,7 +202,7 @@
/// FIXME: Need to carefully consider tentative definition rules (C99 6.9.2p2).
/// For example, we incorrectly complain about i1, i4 from C99 6.9.2p4.
///
-VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
+VarDecl *Sema::MergeVarDecl(VarDecl *New, ScopedDecl *OldD) {
// Verify the old decl was also a variable.
VarDecl *Old = dyn_cast<VarDecl>(OldD);
if (!Old) {
@@ -571,7 +571,8 @@
VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
if (!VDecl) {
- Diag(RealDecl->getLocation(), diag::err_illegal_initializer);
+ Diag(dyn_cast<ScopedDecl>(RealDecl)->getLocation(),
+ diag::err_illegal_initializer);
RealDecl->setInvalidDecl();
return;
}
@@ -1280,7 +1281,8 @@
// Verify that there isn't already something declared with this name in this
// scope.
- if (Decl *PrevDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary, IdLoc, S)) {
+ if (ScopedDecl *PrevDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary,
+ IdLoc, S)) {
if (S->isDeclScope(PrevDecl)) {
if (isa<EnumConstantDecl>(PrevDecl))
Diag(IdLoc, diag::err_redefinition_of_enumerator, Id->getName());
diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp
index 9cca2c2..2e7e753 100644
--- a/Sema/SemaStmt.cpp
+++ b/Sema/SemaStmt.cpp
@@ -33,9 +33,11 @@
}
Sema::StmtResult Sema::ParseDeclStmt(DeclTy *decl) {
- if (decl)
- return new DeclStmt(static_cast<Decl *>(decl));
- else
+ if (decl) {
+ ScopedDecl *SD = dyn_cast<ScopedDecl>(static_cast<Decl *>(decl));
+ assert(SD && "Sema::ParseDeclStmt(): expected ScopedDecl");
+ return new DeclStmt(SD);
+ } else
return true; // error
}
@@ -57,7 +59,7 @@
/*empty*/;
if (i != NumElts) {
- Decl *D = cast<DeclStmt>(Elts[i])->getDecl();
+ ScopedDecl *D = cast<DeclStmt>(Elts[i])->getDecl();
Diag(D->getLocation(), diag::ext_mixed_decls_code);
}
}
@@ -484,7 +486,8 @@
if (BVD && !BVD->hasLocalStorage())
BVD = 0;
if (BVD == 0)
- Diag(D->getLocation(), diag::err_non_variable_decl_in_for);
+ Diag(dyn_cast<ScopedDecl>(D)->getLocation(),
+ diag::err_non_variable_decl_in_for);
// FIXME: mark decl erroneous!
}
}