Hello, Is there a way to clone a FunctionDecl, including the body Stmt if it exists? I want to add an entirely new decl to the AST with its own copy of the body. I would like to start with a completely identical Decl and body, and then modify it to produce a new overload, such that this cloned function would appear in overload resolution for calls to the original function. What I want to do is somewhat similar to template instantiation, but I've been looking through this mechanism and it *appears* that function templates don't actually duplicate the body of the function until LLVM code gen, is that true? I need a proper clone of the function so that mechanism is not useful as a starting point if that is the case. What is the most effective way to accomplish this? Thanks Dillon -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120327/a1b94e81/attachment.html>
On Tue, Mar 27, 2012 at 4:08 PM, Dillon Sharlet <dsharlet at gmail.com> wrote:> Hello, > > Is there a way to clone a FunctionDecl, including the body Stmt if it > exists? I want to add an entirely new decl to the AST with its own copy of > the body. I would like to start with a completely identical Decl and body, > and then modify it to produce a new overload, such that this cloned function > would appear in overload resolution for calls to the original function.There is code inside Sema to do something like this as part of template instantiation; see TreeTransform.h . It isn't exposed outside of Sema, though,> What I want to do is somewhat similar to template instantiation, but I've > been looking through this mechanism and it *appears* that function templates > don't actually duplicate the body of the function until LLVM code gen, is > that true?No, the instantiated function exists independently in the AST. cfe-dev would be a better list for followup questions. -Eli
Seemingly Similar Threads
- [LLVMdev] getelementptr being lowered to ptrtoint/.../inttoptr?
- [LLVMdev] Volunteers needed to moderate sessions and staff registration desk!
- [LLVMdev] Inline hint for methods defined in-class
- [LLVMdev] Inline hint for methods defined in-class
- [LLVMdev] Volunteers needed to moderate sessions and staff registration desk!