() clang AST , node, ASTContext, . . clang:: DeclRefExpr.
, , . , , . new/delete, ASTContext .
clang ASTContext , ( ASTContext).
, clang ASTContext:
/// Allocator that relies on clang AST context for actual memory
/// allocation. Any class that wishes to allocated an AST node may
/// create an instance of this class for that purpose
class ClangAllocator
{
public:
explicit ClangAllocator(clang::ASTContext& ast_context)
: m_ast_context(ast_context)
{
}
template<class ClassType, class ... Args>
inline ClassType* Alloc(Args&& ... args)
{
return new (m_ast_context) ClassType(std::forward<Args&&>(args)...);
}
private:
clang::ASTContext& m_ast_context;
};
AST, , , - TreeTransform Rebuild, .
AST node , - , std:: replace . :
std::replace(
immediate_parent->child_begin()
, immediate_parent->child_end()
, old_stmt
, new_stmt);