@@ -3506,6 +3506,65 @@ def cursor(self):
35063506 return cursor
35073507
35083508
3509+ class Rewriter (ClangObject ):
3510+ """
3511+ The Rewriter is a wrapper class around clang::Rewriter
3512+
3513+ It enables rewriting buffers.
3514+ """
3515+
3516+ @staticmethod
3517+ def create (tu ):
3518+ """
3519+ Creates a new Rewriter
3520+ Parameters:
3521+ tu -- The translation unit for the target AST.
3522+ """
3523+ return Rewriter (conf .lib .clang_CXRewriter_create (tu ))
3524+
3525+ def __init__ (self , ptr ):
3526+ ClangObject .__init__ (self , ptr )
3527+
3528+ def __del__ (self ):
3529+ conf .lib .clang_CXRewriter_dispose (self )
3530+
3531+ def insert_text_before (self , loc , insert ):
3532+ """
3533+ Insert the specified string at the specified location in
3534+ the original buffer.
3535+ """
3536+ conf .lib .clang_CXRewriter_insertTextBefore (self , loc , insert )
3537+
3538+ def replace_text (self , extent , replacement ):
3539+ """
3540+ This method replaces a range of characters in the input buffer with
3541+ a new string.
3542+ """
3543+ conf .lib .clang_CXRewriter_replaceText (self , extent , replacement )
3544+
3545+ def remove_text (self , extent ):
3546+ """
3547+ Remove the specified text region.
3548+ """
3549+ conf .lib .clang_CXRewriter_removeText (self , extent )
3550+
3551+ def overwrite_changed_files (self ):
3552+ """
3553+ Save all changed files to disk.
3554+
3555+ Returns 1 if any files were not saved successfully,
3556+ returns 0 otherwise.
3557+ """
3558+ return conf .lib .clang_CXRewriter_overwriteChangedFiles (self )
3559+
3560+ def write_main_file_to_stdout (self ):
3561+ """
3562+ Writes the main file to stdout.
3563+ """
3564+ sys .stdout .flush ()
3565+ conf .lib .clang_CXRewriter_writeMainFileToStdOut (self )
3566+
3567+
35093568# Now comes the plumbing to hook up the C library.
35103569
35113570# Register callback types in common container.
@@ -3571,6 +3630,13 @@ def cursor(self):
35713630 ("clang_codeCompleteGetNumDiagnostics" , [CodeCompletionResults ], c_int ),
35723631 ("clang_createIndex" , [c_int , c_int ], c_object_p ),
35733632 ("clang_createTranslationUnit" , [Index , c_interop_string ], c_object_p ),
3633+ ("clang_CXRewriter_create" , [TranslationUnit ], c_object_p ),
3634+ ("clang_CXRewriter_dispose" , [Rewriter ]),
3635+ ("clang_CXRewriter_insertTextBefore" , [Rewriter , SourceLocation , c_interop_string ]),
3636+ ("clang_CXRewriter_overwriteChangedFiles" , [Rewriter ], c_int ),
3637+ ("clang_CXRewriter_removeText" , [Rewriter , SourceRange ]),
3638+ ("clang_CXRewriter_replaceText" , [Rewriter , SourceRange , c_interop_string ]),
3639+ ("clang_CXRewriter_writeMainFileToStdOut" , [Rewriter ]),
35743640 ("clang_CXXConstructor_isConvertingConstructor" , [Cursor ], bool ),
35753641 ("clang_CXXConstructor_isCopyConstructor" , [Cursor ], bool ),
35763642 ("clang_CXXConstructor_isDefaultConstructor" , [Cursor ], bool ),
0 commit comments