Skip to main content

cppguts

If your project depends on some external C/C++ projects and you want to make some changes in external functions/methods and then copy/paste these changes automatically - this package may help you.

There are two tools:

  1. editcpp used to edit source code;
  2. dumpcpp used to print some information about C/C++ translation units

We will discuss editcpp as it is the objective tool.

editcpp doesn't work with templates.

The idea behind editcpp tool

editcpp uses libclang to find function/method definition start/end lines in text file (.c, .h, .hpp, .cpp or whatever C/C++ extension). libclang parses each dest.cpp and src.cpp and everything that is included by #include preprocessor directives. Then editcpp tool selects all functions and methods defined in dest.cpp and src.cpp (it assumes that you know where old and new function/method definition resides) and tries to find matching functions/methods. After that editcpp copies function/method definition from src.cpp and pastes it to the dest.cpp while deleting old funcion/method definition.

To find common function editcpp checks:

  • are they both definitions?
  • are they both const?
  • are they both static?
  • are they both vitual?
  • are they both functions?
  • are they both methods?
  • do they both have the same name?
  • do they both have the same return type and arg types?
  • do they both have the same semantic parent (classname)? (for methods only)

Notes

  • you are free to pass any clang argument after editcpp otions but don't pass file without flag to clang (as we usually do when using clang)
  • if you parse files that includes non standard headers then you probably need to pass -I<include_dir> flag to clang to include directories;
  • if you parse C++ files then it may be necessary to pass -std=c++03 (or higher) flag to inform clang that the file is C++;
  • if your new function/method definition uses external types then these types must be preliminary declared (not necessary to define them);

Remember that after editcpp finds common functions/methods it will simply copy selected text lines from one file to another

Example

original function/method definition file dest.h:

#include <iostream>

// helper class that is used by the target class `Src`
class SrcPrivate {
public:
 SrcPrivate(){};

 void add(int v){
   val += v;
 }

 void substract(int v){
   val -= v;
 }

private:
 int val;
}

// target class
class Src {
 // method defined inside the class
 void add(SrcPrivate p, int v){
   p.add(v);
 }

// method defined outside the class
 void substract(SrcPrivate p, int v);

// we won't tuch this method
 void untouched_print(int v){
   std::cout << "The value is:\t" << v << std::endl;
 }
}

void Src::substract(SrcPrivate p, int v){
 p.substract(v);
}

// simple function
void foo(int &v){
 v--;
}

namespace ns {
 // function in namespace
 void bar(int &v){
   v++;
 }
}

new function/method definition file src.h:

class SrcPrivate;   // declare helper type

// target class
class Src {
  // NEW method definition inside class
  void add(SrcPrivate p, int v){

    p.add(v) + 10;

  }

  // NEW method definition ouside class
  void substract(SrcPrivate p, int v);
}

void Src::substract(SrcPrivate p, int v){
  p.substract(v) - 10;
}

// NEW simple function definition 
void foo(int &v){
  v -= 10;
}

// NEW function definition in namespace
namespace ns {
  void bar(int &v){
    v += 10;
  }
}

Run:

editcpp --src-file=src.h --dest-file=dest.h --oldfile-keep -std=c++03

The -std=c++03 tells the clang to parse the files as C++. Also you may need to use any other clang flags like -I to include directories that are required by the files.

--oldfile-keep (default) is used to keep the original file (it will be renamed by adding _OLD_N suffix). Otherwise use --oldfile-delete to delete the original file.

Another option is to run the test (though the test deletes all the generated files so you better take a look in /tests dir):

python -m unittest cppguts.tests.test_cppguts

Metadata

Release files for cppguts 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cppguts 1.0.2
File Size Uploaded Provenance
cppguts-1.0.2.tar.gz 8.9 kB Without provenance Details

Release files / cppguts-1.0.2.tar.gz

Download URL cppguts-1.0.2.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5abd2ded6cf24e0393577631ca127397feb3db4d48a6da31781de7482c9daa14
BLAKE2b-256 checksum
How to use checksums
4f079c0934542294273a19c09e9d90d942c7a619e1bc5d022ef5e6fd1d7d8d7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.7

Security for cppguts 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page