[cfe-commits] r39197 - in /cfe/cfe/trunk: AST/SemaDecl.cpp Sema/SemaDecl.cpp include/clang/AST/Decl.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:41:01 PDT 2007
Author: sabre
Date: Wed Jul 11 11:41:01 2007
New Revision: 39197
URL: http://llvm.org/viewvc/llvm-project?rev=39197&view=rev
Log:
When a decl is popped from its current scope, link it to the decl chain for
the containing function. This avoids leaking decls.
Modified:
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/include/clang/AST/Decl.h
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39197&r1=39196&r2=39197&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:41:01 2007
@@ -35,11 +35,16 @@
II.setFETokenInfo(D->getNext());
- // FIXME: Push the decl on the parent function list if in a function.
- // FIXME: Don't delete the decl when it gets popped!
- // delete D;
-
-
+ // This will have to be revisited for C++: there we want to nest stuff in
+ // namespace decls etc. Even for C, we might want a top-level translation
+ // unit decl or something.
+ if (!CurFunctionDecl)
+ continue;
+
+ // Chain this decl to the containing function, it now owns the memory for
+ // the decl.
+ D->setNext(CurFunctionDecl->getDeclChain());
+ CurFunctionDecl->setDeclChain(D);
}
}
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39197&r1=39196&r2=39197&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:41:01 2007
@@ -35,11 +35,16 @@
II.setFETokenInfo(D->getNext());
- // FIXME: Push the decl on the parent function list if in a function.
- // FIXME: Don't delete the decl when it gets popped!
- // delete D;
-
-
+ // This will have to be revisited for C++: there we want to nest stuff in
+ // namespace decls etc. Even for C, we might want a top-level translation
+ // unit decl or something.
+ if (!CurFunctionDecl)
+ continue;
+
+ // Chain this decl to the containing function, it now owns the memory for
+ // the decl.
+ D->setNext(CurFunctionDecl->getDeclChain());
+ CurFunctionDecl->setDeclChain(D);
}
}
Modified: cfe/cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Decl.h?rev=39197&r1=39196&r2=39197&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:41:01 2007
@@ -42,7 +42,9 @@
/// Type.
TypeRef DeclType;
- /// Scope stack info when parsing, otherwise decl list when scope is popped.
+ /// When this decl is in scope while parsing, the Next field contains a
+ /// pointer to the shadowed decl of the same name. When the scope is popped,
+ /// Decls are relinked onto a containing decl object.
///
Decl *Next;
@@ -57,6 +59,7 @@
TypeRef getType() const { return DeclType; }
Kind getKind() const { return DeclKind; }
Decl *getNext() const { return Next; }
+ void setNext(Decl *N) { Next = N; }
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *) { return true; }
@@ -117,13 +120,19 @@
class FunctionDecl : public ObjectDecl {
// Args etc.
Stmt *Body; // Null if a prototype.
+
+ /// DeclChain - Linked list of declarations that are defined inside this
+ /// function.
+ Decl *DeclChain;
public:
FunctionDecl(IdentifierInfo *Id, TypeRef T, Decl *Next)
- : ObjectDecl(Function, Id, T, Next), Body(0) {}
+ : ObjectDecl(Function, Id, T, Next), Body(0), DeclChain(0) {}
Stmt *getBody() const { return Body; }
void setBody(Stmt *B) { Body = B; }
+ Decl *getDeclChain() const { return DeclChain; }
+ void setDeclChain(Decl *D) { DeclChain = D; }
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == Function; }
More information about the cfe-commits
mailing list