2023-03-12 18:34:55 -07:00
# refactor
2023-03-16 23:09:19 -07:00
Refactor c/c++ files (and problably others) with ease.
2023-03-12 18:34:55 -07:00
2023-04-19 12:53:01 -07:00
## Parameters
2023-03-12 18:34:55 -07:00
2023-03-16 23:09:19 -07:00
* `-num` : Used if more than one source file is provided (if used, number of destination files provided MUST MATCH).
2023-03-13 17:17:12 -07:00
* `-src` : Source file to refactor
* `-dst` : Destination file after the refactor (omit to use the same as source)
* `-spec` : Specification containing rules to use for the refactor.
2023-03-31 13:17:02 -07:00
* `-debug` : Use if on debug build and desire to attach to process, or to get a more verbose log.
2023-03-12 18:34:55 -07:00
2023-03-31 13:17:02 -07:00
## Syntax
2023-03-12 18:34:55 -07:00
2023-03-31 14:26:02 -07:00
* `not` Omit an a signature. (Modifies include, word, namespace, etc)
2023-03-31 13:17:02 -07:00
* `include` Preprocessor include `<file path>` related identifiers.
2023-03-12 18:34:55 -07:00
* `word` Fixed sized identifier.
* `namespace` Variable sized identifiers, mainly intended to redefine c-namespace of an identifier.
2023-03-16 23:19:32 -07:00
* `,` is used to delimit arguments (if doing a find and replace).
2023-03-12 18:34:55 -07:00
* `L-Value` is the signature to modify.
* `R-Value` is the substitute ( only available if rule does not use `not` keyword )
2023-04-19 12:53:01 -07:00
The only keyword here excluisve to c/c++ is the `include` as it does search specifically for `#include <L-Value>` .
2023-03-16 23:09:19 -07:00
However, the rest of the categorical keywords (word, namespace), can really be used for any langauge.
2023-04-19 12:53:01 -07:00
There is no semantic awareness this is truely just a simple find and replace, but with some filters specifiable, and
2023-03-16 23:09:19 -07:00
words/namespaces only being restricted to the rules for C/C++ identifiers (alphanumeric or underscores only)
2023-03-30 17:14:51 -07:00
The main benefit for using this over alts is its problably more ergonomic and performant for large refactors on libraries you may want to have automated in a script.
2023-03-16 23:09:19 -07:00
There are other programs more robust for doing that sort of thing but I was not able to find something this simple.
2023-04-03 00:53:59 -07:00
### Example scripts
2023-03-31 13:17:02 -07:00
2023-04-03 00:53:59 -07:00
See `scripts/template_reafactor.ps1` and the `test/*.refactor` related scripts on intended usage.
2023-03-31 13:17:02 -07:00
2023-04-03 00:53:59 -07:00
This app is not very nice to use directly from CLI. Instead run from a script after gathering the arguments.
2023-03-31 13:17:02 -07:00
There is a desire also to get this setup as a single-header library and also alternative with a minimalist GUI for simple refactors.
### Notes
2023-03-16 23:19:32 -07:00
2023-04-19 12:53:01 -07:00
* Building for debug provides some nice output with context on a per-line basis.
* Release will only show errors for asserts (that will kill the refactor early).
2023-03-16 23:09:19 -07:00
* If the refactor crashes, the files previously written to will retain their changes.
2023-03-31 13:17:02 -07:00
* Make sure to have the code backed up on a VCS or in some other way.
2023-03-16 23:19:32 -07:00
* The scripts used for building and otherwise are in the scripts directory and are all in powershell (with exception to the meson.build). Techncially there should be a powershell package available on other platorms but worst case it should be pretty easy to port these scripts to w/e shell script you'd perfer.
2023-03-12 18:34:55 -07:00
2023-03-31 13:17:02 -07:00
## Building
2023-04-19 12:53:01 -07:00
The project has all build configuration in the `scripts` directory.
2023-03-31 13:17:02 -07:00
2023-04-19 12:53:01 -07:00
* `build.ci.ps1` is intended for a continuous intergration setup (GH-worfklow for now).
2023-03-31 13:17:02 -07:00
* `build.ps1` is just a wrap of build.ci that just calls cls.
* `clean.ps1` will clean the workspace of all generated files.
2023-04-03 00:53:59 -07:00
* `get_sources.ps1` is used to gather sources since meson devs refuse to add dynamic retrival of sources for a build.
2023-03-31 13:17:02 -07:00
2023-04-19 12:53:01 -07:00
The project uses [meson ](https://github.com/mesonbuild/meson ) as the build tool.
Compiler : clang
2023-03-31 13:17:02 -07:00
OS: Windows 11 (windows-latest for github actions)
There should theoretically not be anything stopping it from building on other plaforms.
The library's main dependency is [zpl ](https://github.com/zpl-c ) which seems to support all major platforms.
## Testing
If the `test` parameter is provided to the build scripts, the project and thirdparty code will be refactored based on the specificiation files `*.refactor` residing in `test` .
With the refactors applied a meson configuraiton is setup (`meson.build` in test) and run to build. So long as it compiles, the feature set of the current version should work fine.
2023-03-31 14:26:02 -07:00
* There is an extra file `stb_image` that is parsed but unused during compilation.
2023-03-31 13:17:02 -07:00
* Planned for use in the namespace addition todo.
2023-04-19 12:53:01 -07:00
## TODO:
2023-03-17 15:12:20 -07:00
2023-03-16 23:09:19 -07:00
* Provide binaries in the release page for github. (debug and release builds)
2023-04-03 00:53:59 -07:00
* Ability to run and not emit any changes to files unless all files sucessfully are refactored.
2023-03-31 13:17:02 -07:00
* Would fix issue where a refactor overwrites files but failed to complete
* Can have a heavy memory cost, so most likely do not want on by default.
* Make comments ignored by default, and just have ability to specify custom comments.
* Would need a directive to add refactors to comments.
2023-04-19 12:53:01 -07:00
* Directive to add cpp namespaces on specific lines of a file, or near specific signatures.
* This can honestly be done also with placing words on specific lines..
2023-03-30 17:14:51 -07:00
* Provide a GUI build.
* Provide as a single-header library.
2023-04-03 00:53:59 -07:00
* Could add a test case where this library is refactored into pure C (most likely c99 or c11).
2023-03-31 14:26:02 -07:00
* Better tests:
* Automatically pull the zpl repo, refactor and format the library, and package the single header before using it in testing.
2023-04-19 12:53:01 -07:00
* Use gencpp editor/scanner functionality to give it more rich context refactors.
* Port to other platforms.
* Ability to change the naming convention of a signature (snake_case to PascalCase, etc)