Skip to content

Instantly share code, notes, and snippets.

@tristan0x
Last active August 2, 2017 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristan0x/9a69a06aeff72e8004b3ea270d13589c to your computer and use it in GitHub Desktop.
Save tristan0x/9a69a06aeff72e8004b3ea270d13589c to your computer and use it in GitHub Desktop.
C++ mass renaming

Ctags

List of all kind symbols that can be extracted

$ ctags --list-kinds=C++
c  classes
d  macro definitions
e  enumerators (values inside an enumeration)
f  function definitions
g  enumeration names
l  local variables [off]
m  class, struct, and union members
n  namespaces
p  function prototypes [off]
s  structure names
t  typedefs
u  union names
v  variable definitions
x  external and forward variable declarations [off]
$

Create a classes_and_functions file with all class and function symbols for all *.cpp files located in the current directory:

$ ctags --language-force=C++ --C++-kinds=cf -o classes_and_functions *.cpp
$ cat classes_and_functions
!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR	Darren Hiebert	/dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME	Exuberant Ctags	//
!_TAG_PROGRAM_URL	http://ctags.sourceforge.net	/official site/
!_TAG_PROGRAM_VERSION	5.9~svn20110310	//
main	boost_multi_array_2D.cpp	/^int main(void) {$/;"	f
main	boost_ublas_double.cpp	/^int main(void) {$/;"	f
main	create_attribute_string_integer.cpp	/^int main(void) {$/;"	f
main	create_dataset_double.cpp	/^int main(void) {$/;"	f
main	parallel_hdf5_write_dataset.cpp	/^int main(int argc, char** argv) {$/;"f
main	read_write_dataset_string.cpp	/^int main(void) {$/;"	f
main	read_write_single_scalar.cpp	/^int main(void) {$/;"	f
main	read_write_vector_dataset.cpp	/^int main(void) {$/;"	f
main	select_by_id_dataset_cpp11.cpp	/^int main(void) {$/;"	f
main	select_partial_dataset_cpp11.cpp	/^int main(void) {$/;"	f
read_dataset	read_write_vector_dataset.cpp	/^void read_dataset() {$/;"	f
write_dataset	read_write_vector_dataset.cpp	/^void write_dataset() {$/;"	f

Note the kind of symbol at the end of each line.

Camel case to snake case

def convert(name):
    s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
    return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()

https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case

Docker image with everythind bundled

Here is a Dockerfile you can use to create a Docker image providing every tools required:

FROM ubuntu:16.04

RUN apt-get update \
 && apt-get install -y ctags wget xz-utils python \
 && wget http://releases.llvm.org/4.0.1/clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar.xz \
 && xz -d clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar.xz \
 && tar xf clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar

ENV PATH="${PWD}/clang+llvm-4.0.1-x86_64-linux-gnu-debian8/bin:${PATH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment