Defining a new extension
Defining a new code_type involves four functions:
CodeDiffs.get_code_dispatch(::Val{code_type}, f, types; kwargs...)(notget_code!) should return a printable object (usually aString) representing the code forf(types).kwargsare the options passed to@code_diff.CodeDiffs.Cleanup.cleanup_code(::Val{:code_type}, code, dbinfo, cleanup_opts)does some cleanup on the code object to make it morediff-able.CodeDiffs.code_highlighter(::Val{code_type})returns af(io, obj)to print theobjto as text inio. This is done twice: once without highlighting (get(io, :color, false) == false), and another with highlighting.CodeDiffs.argconvert(::Val{code_type}, arg)convertsargas needed (by defaultargis unchanged)
Defining a new pre-processing step for functions and its arguments (like for KernelAbstractions.jl kernels) involves two functions:
CodeDiffs.extract_extra_options(f, kwargs)returns some additionalkwargswhich are passed toget_codeCodeDiffs.get_code(code_type, f, types; kwargs...)allows to changefdepending on its type. To avoid method ambiguities, do not put type constraints oncode_type.
Defining a new object type which can be put as an argument to @code_diff or @code_for invoves at one function: CodeDiffs.code_for_diff(obj::YourType; kwargs...). It must return two Strings, one without and the other without highlighting. When calling @code_for obj, code_for_diff(obj) will be called only if obj is not a call expression or a quoted Expr. kwargs are the options passed to @code_for or the options passed to @code_diff for the side of obj.