mirror of
https://github.com/Ed94/refactor.git
synced 2025-04-19 07:20:17 -07:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
50033cc819 | |||
22f74f3dc6 | |||
6395d022f1 | |||
4d5cbd3e8d | |||
b21e1bf603 | |||
12779449a4 | |||
5efd14322e | |||
c4efd1890d | |||
063a3a972c | |||
e301b400ba | |||
6bc4346652 | |||
6e91555a20 | |||
1b0c5d176c | |||
ea09b27b3b | |||
d344043c44 |
10
.github/workflows/main.yml
vendored
10
.github/workflows/main.yml
vendored
@ -16,11 +16,13 @@ on:
|
|||||||
inputs:
|
inputs:
|
||||||
type:
|
type:
|
||||||
description: 'Meson buildtype (release, debug, etc.)'
|
description: 'Meson buildtype (release, debug, etc.)'
|
||||||
|
default: release
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
test:
|
test:
|
||||||
description: 'Run tests (test)'
|
description: 'Run tests (test)'
|
||||||
required: false
|
default: test
|
||||||
|
required: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@ -81,7 +83,7 @@ jobs:
|
|||||||
if (-not [string]::IsNullOrEmpty($type)) { $args += $type }
|
if (-not [string]::IsNullOrEmpty($type)) { $args += $type }
|
||||||
if (-not [string]::IsNullOrEmpty($test)) { $args += $test }
|
if (-not [string]::IsNullOrEmpty($test)) { $args += $test }
|
||||||
|
|
||||||
& .\scripts\build.ci.ps1 debug test
|
Invoke-Expression "& .\scripts\build.ci.ps1 $args"
|
||||||
|
|
||||||
- name: Get Short Commit SHA
|
- name: Get Short Commit SHA
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
@ -96,13 +98,13 @@ jobs:
|
|||||||
New-Item -ItemType Directory -Path "./artifact"
|
New-Item -ItemType Directory -Path "./artifact"
|
||||||
Copy-Item "./build/refactor.exe" -Destination "./artifact/refactor.exe"
|
Copy-Item "./build/refactor.exe" -Destination "./artifact/refactor.exe"
|
||||||
|
|
||||||
Compress-Archive -Path "./artifact/*" -DestinationPath "./artifact/refactor-${env:SHORT_SHA}.zip"
|
Compress-Archive -Path "./artifact/*" -DestinationPath "./artifact/refactor-$($env:SHORT_SHA).zip"
|
||||||
|
|
||||||
- name: Upload Release
|
- name: Upload Release
|
||||||
uses: ncipollo/release-action@v1
|
uses: ncipollo/release-action@v1
|
||||||
with:
|
with:
|
||||||
tag: Release
|
tag: Release
|
||||||
artifacts: ./artifact/refactor-${env:SHORT_SHA}.zip
|
artifacts: ./artifact/refactor-${{ env.SHORT_SHA }}.zip
|
||||||
omitBody: true
|
omitBody: true
|
||||||
# bodyFile: "body.md"
|
# bodyFile: "body.md"
|
||||||
allowUpdates: true
|
allowUpdates: true
|
||||||
|
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
@ -47,10 +47,10 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/refactor.exe",
|
"program": "${workspaceFolder}/build/refactor.exe",
|
||||||
"args": [
|
"args": [
|
||||||
"-source=./refactor.cpp",
|
"-src=./project/refactor.cpp",
|
||||||
"-destination=./Test/refactor.cpp",
|
"-dst=./Test/refactor.cpp",
|
||||||
|
|
||||||
"-specification=./Test/zpl.refactor"
|
"-spec=./Test/zpl.refactor"
|
||||||
],
|
],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceRoot}",
|
"cwd": "${workspaceRoot}",
|
||||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
BSD 3-Clause License
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2023, Ed_
|
Copyright (c) 2023, Edward R. Gonzalez
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
64
Readme.md
64
Readme.md
@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
Refactor c/c++ files (and problably others) with ease.
|
Refactor c/c++ files (and problably others) with ease.
|
||||||
|
|
||||||
## Parameters :
|
## Parameters
|
||||||
|
|
||||||
* `-num` : Used if more than one source file is provided (if used, number of destination files provided MUST MATCH).
|
* `-num` : Used if more than one source file is provided (if used, number of destination files provided MUST MATCH).
|
||||||
* `-src` : Source file to refactor
|
* `-src` : Source file to refactor
|
||||||
* `-dst` : Destination file after the refactor (omit to use the same as source)
|
* `-dst` : Destination file after the refactor (omit to use the same as source)
|
||||||
* `-spec` : Specification containing rules to use for the refactor.
|
* `-spec` : Specification containing rules to use for the refactor.
|
||||||
* `-debug` : Use only if on debug build and desire to attach to process.
|
* `-debug` : Use if on debug build and desire to attach to process, or to get a more verbose log.
|
||||||
|
|
||||||
## Syntax :
|
## Syntax
|
||||||
|
|
||||||
* `not` Omit word or namespace.
|
* `not` Omit an a signature. (Modifies include, word, namespace, etc)
|
||||||
* `include` Preprocessor include <file> related identifiers.
|
* `include` Preprocessor include `<file path>` related identifiers.
|
||||||
* `word` Fixed sized identifier.
|
* `word` Fixed sized identifier.
|
||||||
* `namespace` Variable sized identifiers, mainly intended to redefine c-namespace of an identifier.
|
* `namespace` Variable sized identifiers, mainly intended to redefine c-namespace of an identifier.
|
||||||
* `,` is used to delimit arguments (if doing a find and replace).
|
* `,` is used to delimit arguments (if doing a find and replace).
|
||||||
@ -30,20 +30,60 @@ The main benefit for using this over alts is its problably more ergonomic and pe
|
|||||||
|
|
||||||
There are other programs more robust for doing that sort of thing but I was not able to find something this simple.
|
There are other programs more robust for doing that sort of thing but I was not able to find something this simple.
|
||||||
|
|
||||||
### Note
|
### Example scripts
|
||||||
|
|
||||||
|
See `scripts/template_reafactor.ps1` and the `test/*.refactor` related scripts on intended usage.
|
||||||
|
|
||||||
|
This app is not very nice to use directly from CLI. Instead run from a script after gathering the arguments.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
* Building for debug provides some nice output with context on a per-line basis.
|
* 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).
|
* Release will only show errors for asserts (that will kill the refactor early).
|
||||||
* If the refactor crashes, the files previously written to will retain their changes.
|
* If the refactor crashes, the files previously written to will retain their changes.
|
||||||
Make sure to have the code backed up on a VCS or in some other way.
|
* Make sure to have the code backed up on a VCS or in some other way.
|
||||||
* This was compiled using meson with ninja and clang on windows 11. The ZPL library used however should work fine on the other major os platforms and compiler venders.
|
|
||||||
* 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.
|
* 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.
|
||||||
|
|
||||||
TODO:
|
## Building
|
||||||
|
|
||||||
|
The project has all build configuration in the `scripts` directory.
|
||||||
|
|
||||||
|
* `build.ci.ps1` is intended for a continuous intergration setup (GH-worfklow for now).
|
||||||
|
* `build.ps1` is just a wrap of build.ci that just calls cls.
|
||||||
|
* `clean.ps1` will clean the workspace of all generated files.
|
||||||
|
* `get_sources.ps1` is used to gather sources since meson devs refuse to add dynamic retrival of sources for a build.
|
||||||
|
|
||||||
|
The project uses [meson](https://github.com/mesonbuild/meson) as the build tool.
|
||||||
|
Compiler : clang
|
||||||
|
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.
|
||||||
|
|
||||||
|
* There is an extra file `stb_image` that is parsed but unused during compilation.
|
||||||
|
* Planned for use in the namespace addition todo.
|
||||||
|
|
||||||
|
## TODO:
|
||||||
|
|
||||||
* Possibly come up with a better name.
|
|
||||||
* Test to see how much needs to be ported for other platforms (if at all)
|
|
||||||
* Provide binaries in the release page for github. (debug and release builds)
|
* Provide binaries in the release page for github. (debug and release builds)
|
||||||
* Directive to ignore comments (with a way to specify the comment signature). Right now comments that meet the signature of words or namespaces are refactored.
|
* Ability to run and not emit any changes to files unless all files sucessfully are refactored.
|
||||||
|
* 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.
|
||||||
* Provide a GUI build.
|
* Provide a GUI build.
|
||||||
* Provide as a single-header library.
|
* Provide as a single-header library.
|
||||||
|
* Could add a test case where this library is refactored into pure C (most likely c99 or c11).
|
||||||
|
* Better tests:
|
||||||
|
* Automatically pull the zpl repo, refactor and format the library, and package the single header before using it in testing.
|
||||||
|
* 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)
|
||||||
|
@ -21,21 +21,168 @@ include IO.cpp, IO.refactored.cpp
|
|||||||
include Spec.hpp, Spec.refactored.hpp
|
include Spec.hpp, Spec.refactored.hpp
|
||||||
include Spec.cpp, Spec.refactored.cpp
|
include Spec.cpp, Spec.refactored.cpp
|
||||||
|
|
||||||
// Remove the zpl namespace.
|
// Removes the namespace.
|
||||||
namespace zpl_
|
namespace zpl_
|
||||||
|
namespace zpl_re_, regex_
|
||||||
// Don't expose zpl internals
|
namespace zpl_random_, rng_
|
||||||
not namespace zpl__
|
namespace zpl_pr, process_
|
||||||
|
namespace zpl__, __
|
||||||
|
namespace ZPL_ADT_, EADT
|
||||||
|
namespace ZPL_ALLOCATION_, EAllocation
|
||||||
|
namespace ZPL_CSV_ERROR, ECSV_Error
|
||||||
|
namespace ZPL_FILE_MODE_, EFileMode_
|
||||||
|
namespace ZPL_FILE_ERROR_, EFileError_
|
||||||
|
namespace ZPL_SEEK_WHENCE_, ESeekWhence_
|
||||||
|
namespace ZPL_FILE_STANDARD_, EFileStandard_
|
||||||
|
namespace ZPL_FILE_STREAM_, EFileStream_
|
||||||
|
namespace ZPL_JSON_ERROR_, EJSON_Error_
|
||||||
|
namespace ZPL_RE_ERROR_, ERegexError_
|
||||||
|
namespace ZPL_OPTS_, EOpts_
|
||||||
|
namespace ZPL_OPTS_ERR, EOptsError_
|
||||||
|
namespace ZPL_PR_OPTS_, EProcessOpts_
|
||||||
|
|
||||||
// Macro exposure
|
// Macro exposure
|
||||||
//namespace ZPL_
|
//namespace ZPL_
|
||||||
//not word ZPL_IMPLEMENTATION
|
//not word ZPL_IMPLEMENTATION
|
||||||
|
|
||||||
// Name conflicts
|
// Type Renames
|
||||||
word opts, options
|
word zpl_aabb2, AABB2
|
||||||
|
word zpl_aabb3, AABB3
|
||||||
|
word zpl_adt_assign_style, ADT_AssignStyle
|
||||||
|
word zpl_adt_delim_style, ADT_DelimStyle
|
||||||
|
word zpl_adt_error, ADT_Error
|
||||||
|
word zpl_adt_naming_style, ADT_NamingStyle
|
||||||
|
word zpl_adt_node, ADT_Node
|
||||||
|
word zpl_adt_props, ADT_Props
|
||||||
|
word zpl_adt_type, ADT_Type
|
||||||
|
word zpl_affinity, Affinity
|
||||||
|
word zpl_allocation_header_event, AllocationHeaderEvent
|
||||||
|
word zpl_allocator, AllocatorInfo
|
||||||
|
word zpl_allocator_proc, AllocatorProc
|
||||||
|
word zpl_alloc_flags, AllocFlags
|
||||||
|
word zpl_alloc_type, AllocType
|
||||||
|
word zpl_arena, Arena
|
||||||
|
word zpl_arena_snapshot, ArenaSnapshot
|
||||||
|
word zpl_array, Array
|
||||||
|
word zpl_array_header, ArrayHeader
|
||||||
|
word zpl_buffer, Buffer
|
||||||
|
word zpl_buffer_header, BufferHeader
|
||||||
|
word zpl_compare_proc, CompareProc
|
||||||
|
word zpl_csv_error, CSV_Error
|
||||||
|
word zpl_csv_object, CSV_Object
|
||||||
|
word zpl_dll_handle, DLLHandle
|
||||||
|
word zpl_dll_proc, DLLProc
|
||||||
|
word zpl_dir_type, DirType
|
||||||
|
word zpl_dir_entry, DirEntry
|
||||||
|
word zpl_dir_info, DirInfo
|
||||||
|
word zpl_file_contents, FileContents
|
||||||
|
word zpl_file_descriptor, FileDescriptor
|
||||||
|
word zpl_file_error, FileError
|
||||||
|
word zpl_file, FileInfo
|
||||||
|
word zpl_file_mode, FileMode
|
||||||
|
word zpl_file_mode_flag, FileModeFlag
|
||||||
|
word zpl_file_operations, FileOperations
|
||||||
|
word zpl_file_close_proc, FileCloseProc
|
||||||
|
word zpl_file_read_proc, FileReadProc
|
||||||
|
word zpl_file_seek_proc, FileSeekProc
|
||||||
|
word zpl_file_write_proc, FileWriteProc
|
||||||
|
word zpl_file_standard_type, FileStandardType
|
||||||
|
word zpl_file_stream_flags, FileStreamFlags
|
||||||
|
word zpl_float2, Float2
|
||||||
|
word zpl_float3, Float3
|
||||||
|
word zpl_float4, Float4
|
||||||
|
word zpl_frustum, Frustum
|
||||||
|
word zpl_half, Half
|
||||||
|
word zpl_jobs_priority, JobsPriority
|
||||||
|
word zpl_jobs_status, JobsStatus
|
||||||
|
word zpl_jobs_system, JobsSystem
|
||||||
|
word zpl_json_error, JSON_Error
|
||||||
|
word zpl_json_object, JSON_Object
|
||||||
|
word zpl_list, List
|
||||||
|
word zpl_mat2, Mat2
|
||||||
|
word zpl_mat3, Mat3
|
||||||
|
word zpl_mat4, Mat4
|
||||||
|
word zpl_mutex, Mutex
|
||||||
|
word zpl_plane, Plane
|
||||||
|
word zpl_pool, Pool
|
||||||
|
word zpl_pr, Process
|
||||||
|
word zpl_pr_si, ProcessStartupInfo
|
||||||
|
word zpl_quat, Quat
|
||||||
|
word zpl_rect2, Rect2
|
||||||
|
word zpl_rect3, Rect3
|
||||||
|
word zpl_re, Regex
|
||||||
|
word zpl_re_capture, RegexCapture
|
||||||
|
word zpl_regex_error, RegexError
|
||||||
|
wrod zpl_random, RNG
|
||||||
|
word zpl_rune, Rune
|
||||||
|
word zpl_scratch_memory, ScratchMemory
|
||||||
|
word zpl_seek_whence_type, SeekWhenceType
|
||||||
|
word zpl_semaphore, Semaphore
|
||||||
|
word zpl_string, String
|
||||||
|
word zpl_string_header, StringHeader
|
||||||
|
word zpl_sync, Sync
|
||||||
|
word zpl_opts, Opts
|
||||||
|
word zpl_opts_entry, OptsEntry
|
||||||
|
word zpl_opts_err, OptsError
|
||||||
|
word zpl_opts_err_type, OptsErrorType
|
||||||
|
word zpl_opts_types, OptsTypes
|
||||||
|
word zpl_tar_errors, TarErrors
|
||||||
|
word zpl_tar_file_type, TarFileType
|
||||||
|
word zpl_tar_record, TarRecord
|
||||||
|
word zpl_tar_unpack_proc, TarUnpackProc
|
||||||
|
word zpl_thread, Thread
|
||||||
|
word zpl_thread_job, ThreadJob
|
||||||
|
word zpl_thread_proc, ThreadProc
|
||||||
|
word zpl_thread_queue, ThreadQueue
|
||||||
|
word zpl_thread_worker, ThreadWorker
|
||||||
|
word zpl_vec2, Vec2
|
||||||
|
word zpl_vec3, Vec3
|
||||||
|
word zpl_vec4, Vec4
|
||||||
|
word zpl_virtual_memory, VirtualMemory
|
||||||
|
|
||||||
word zpl_strncmp, str_compare
|
// Function Renames
|
||||||
|
word zpl_lfence, fence_load
|
||||||
|
word zpl_mfence, fence_memory
|
||||||
|
word zpl_sfence, fence_store
|
||||||
|
word zpl_memchr, mem_find
|
||||||
|
word zpl_memcopy, mem_copy
|
||||||
|
word zpl_memmove, mem_move
|
||||||
|
word zpl_memset, mem_set
|
||||||
|
word zpl_memswap, mem_swap
|
||||||
|
word zpl_exit, process_exit
|
||||||
|
word zpl_rdtsc, read_cpu_time_stamp_counter
|
||||||
word zpl_strcmp, str_compare
|
word zpl_strcmp, str_compare
|
||||||
|
word zpl_strncmp, str_compare
|
||||||
|
word zpl_strcat, str_concat
|
||||||
|
word zpl_strcpy, str_copy
|
||||||
|
word zpl_strncpy, str_copy
|
||||||
|
word zpl_strlcpy, str_copy_nulpad
|
||||||
|
word zpl_strdup, str_dup
|
||||||
|
word zpl_strchr, str_find
|
||||||
|
word zpl_strrchr, str_find_last
|
||||||
|
word zpl_strstr, str_find_substr
|
||||||
|
word zpl_snprintf, str_fmt
|
||||||
|
word zpl_snprintf_va, str_fmt_va
|
||||||
|
word zpl_asprintf, str_fmt_alloc
|
||||||
|
word zpl_asprintf_va, str_fmt_alloc_va
|
||||||
|
word zpl_bprintf, str_fmt_buf
|
||||||
|
word zpl_bprintf_va, str_fmt_buf_va
|
||||||
|
word zpl_printf, str_fmt_out
|
||||||
|
word zpl_printf_va, str_fmt_out_va
|
||||||
|
word zpl_printf_err, str_fmt_out_err
|
||||||
|
word zpl_printf_err_va, str_fmt_out_err_va
|
||||||
|
word zpl_fprintf, str_fmt_file
|
||||||
|
word zpl_fprintf_va, str_fmt_file_va
|
||||||
|
word zpl_strlen, str_len
|
||||||
|
word zpl_strnlen, str_len
|
||||||
|
word zpl_strrev, str_reverse
|
||||||
|
word zpl_strtok, str_tok
|
||||||
|
word zpl_strtok_r, str_tok_reentrant
|
||||||
|
word zpl_sleep, thread_sleep
|
||||||
|
word zpl_sleep_ms, thread_sleep_ms
|
||||||
|
word zpl_yield_thread, thread_yield
|
||||||
|
word zpl_utf8_strlen, utf8_len
|
||||||
|
word zpl_utf8_strnlen, utf8_len
|
||||||
|
|
||||||
// Undesired typedefs
|
// Undesired typedefs
|
||||||
word zpl_i8, s8
|
word zpl_i8, s8
|
||||||
@ -51,21 +198,7 @@ word zpl_uintptr, uptr
|
|||||||
word zpl_usize, uw
|
word zpl_usize, uw
|
||||||
word zpl_isize, sw
|
word zpl_isize, sw
|
||||||
|
|
||||||
// Conflicts with std. (Uncomment if using c externs)
|
// Undesired exposures.
|
||||||
not word zpl_memchr
|
word cast, zpl_cast
|
||||||
not word zpl_memmove
|
|
||||||
not word zpl_memset
|
not word zpl_thread_local
|
||||||
not word zpl_memswap
|
|
||||||
not word zpl_memcopy
|
|
||||||
not word zpl_printf
|
|
||||||
not word zpl_printf_va
|
|
||||||
not word zpl_printf_err
|
|
||||||
not word zpl_printf_err_va
|
|
||||||
not word zpl_fprintf
|
|
||||||
not word zpl_fprintf_va
|
|
||||||
not word zpl_snprintf
|
|
||||||
not word zpl_snprintf_va
|
|
||||||
not word zpl_strchr
|
|
||||||
not word zpl_strlen
|
|
||||||
not word zpl_strnlen
|
|
||||||
not word zpl_exit
|
|
||||||
|
6
Test/stb_image.refactor
Normal file
6
Test/stb_image.refactor
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
__VERSION 1
|
||||||
|
|
||||||
|
not comments
|
||||||
|
|
||||||
|
namespace stbi_
|
||||||
|
not namepsace stbi__
|
@ -9,6 +9,9 @@ __VERSION 1
|
|||||||
// Precedence (highest to lowest):
|
// Precedence (highest to lowest):
|
||||||
// word, namespace, regex
|
// word, namespace, regex
|
||||||
|
|
||||||
|
// This is a cpp refactor specification for zpl.h
|
||||||
|
// Its intended that the content will be within a cpp namesapce
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
not comments
|
not comments
|
||||||
|
|
||||||
@ -20,22 +23,172 @@ not include header/essentials/collections/array.h
|
|||||||
not include header/essentials/collections/list.h
|
not include header/essentials/collections/list.h
|
||||||
not include header/core/file.h
|
not include header/core/file.h
|
||||||
not include header/opts.h
|
not include header/opts.h
|
||||||
|
not include header/regex.h
|
||||||
not include source/core/file.c
|
not include source/core/file.c
|
||||||
not include source/opts.c
|
not include source/opts.c
|
||||||
|
|
||||||
// Removes the namespace.
|
// Removes the namespace.
|
||||||
namespace zpl_
|
namespace zpl_
|
||||||
|
namespace zpl_re_, regex_
|
||||||
// Don't expose internals
|
namespace zpl_random_, rng_
|
||||||
not namespace zpl__
|
namespace zpl_pr, process_
|
||||||
|
namespace zpl__, __
|
||||||
|
namespace ZPL_ADT_, EADT
|
||||||
|
namespace ZPL_ALLOCATION_, EAllocation_
|
||||||
|
namespace ZPL_CSV_ERROR, ECSV_Error_
|
||||||
|
namespace ZPL_FILE_MODE_, EFileMode_
|
||||||
|
namespace ZPL_FILE_ERROR_, EFileError_
|
||||||
|
namespace ZPL_SEEK_WHENCE_, ESeekWhence_
|
||||||
|
namespace ZPL_FILE_STANDARD_, EFileStandard_
|
||||||
|
namespace ZPL_FILE_STREAM_, EFileStream_
|
||||||
|
namespace ZPL_JSON_ERROR_, EJSON_Error_
|
||||||
|
namespace ZPL_RE_ERROR_, ERegexError_
|
||||||
|
namespace ZPL_OPTS_, EOpts_
|
||||||
|
namespace ZPL_OPTS_ERR, EOptsError_
|
||||||
|
namespace ZPL_PR_OPTS_, EProcessOpts_
|
||||||
|
|
||||||
// Macro exposure
|
// Macro exposure
|
||||||
//namespace ZPL_
|
//namespace ZPL_
|
||||||
//not word ZPL_IMPLEMENTATION
|
//not word ZPL_IMPLEMENTATION
|
||||||
|
|
||||||
word cast, zpl_cast
|
// Type Renames
|
||||||
word zpl_strncmp, str_compare
|
word zpl_aabb2, AABB2
|
||||||
|
word zpl_aabb3, AABB3
|
||||||
|
word zpl_adt_assign_style, ADT_AssignStyle
|
||||||
|
word zpl_adt_delim_style, ADT_DelimStyle
|
||||||
|
word zpl_adt_error, ADT_Error
|
||||||
|
word zpl_adt_naming_style, ADT_NamingStyle
|
||||||
|
word zpl_adt_node, ADT_Node
|
||||||
|
word zpl_adt_props, ADT_Props
|
||||||
|
word zpl_adt_type, ADT_Type
|
||||||
|
word zpl_affinity, Affinity
|
||||||
|
word zpl_allocation_header_event, AllocationHeaderEvent
|
||||||
|
word zpl_allocator, AllocatorInfo
|
||||||
|
word zpl_allocator_proc, AllocatorProc
|
||||||
|
word zpl_alloc_flags, AllocFlags
|
||||||
|
word zpl_alloc_type, AllocType
|
||||||
|
word zpl_arena, Arena
|
||||||
|
word zpl_arena_snapshot, ArenaSnapshot
|
||||||
|
word zpl_array, Array
|
||||||
|
word zpl_array_header, ArrayHeader
|
||||||
|
word zpl_buffer, Buffer
|
||||||
|
word zpl_buffer_header, BufferHeader
|
||||||
|
word zpl_compare_proc, CompareProc
|
||||||
|
word zpl_csv_error, CSV_Error
|
||||||
|
word zpl_csv_object, CSV_Object
|
||||||
|
word zpl_dll_handle, DLLHandle
|
||||||
|
word zpl_dll_proc, DLLProc
|
||||||
|
word zpl_dir_type, DirType
|
||||||
|
word zpl_dir_entry, DirEntry
|
||||||
|
word zpl_dir_info, DirInfo
|
||||||
|
word zpl_file_contents, FileContents
|
||||||
|
word zpl_file_descriptor, FileDescriptor
|
||||||
|
word zpl_file_error, FileError
|
||||||
|
word zpl_file, FileInfo
|
||||||
|
word zpl_file_mode, FileMode
|
||||||
|
word zpl_file_mode_flag, FileModeFlag
|
||||||
|
word zpl_file_operations, FileOperations
|
||||||
|
word zpl_file_close_proc, FileCloseProc
|
||||||
|
word zpl_file_read_proc, FileReadProc
|
||||||
|
word zpl_file_seek_proc, FileSeekProc
|
||||||
|
word zpl_file_write_proc, FileWriteProc
|
||||||
|
word zpl_file_standard_type, FileStandardType
|
||||||
|
word zpl_file_stream_flags, FileStreamFlags
|
||||||
|
word zpl_float2, Float2
|
||||||
|
word zpl_float3, Float3
|
||||||
|
word zpl_float4, Float4
|
||||||
|
word zpl_frustum, Frustum
|
||||||
|
word zpl_half, Half
|
||||||
|
word zpl_jobs_priority, JobsPriority
|
||||||
|
word zpl_jobs_status, JobsStatus
|
||||||
|
word zpl_jobs_system, JobsSystem
|
||||||
|
word zpl_json_error, JSON_Error
|
||||||
|
word zpl_json_object, JSON_Object
|
||||||
|
word zpl_list, List
|
||||||
|
word zpl_mat2, Mat2
|
||||||
|
word zpl_mat3, Mat3
|
||||||
|
word zpl_mat4, Mat4
|
||||||
|
word zpl_mutex, Mutex
|
||||||
|
word zpl_plane, Plane
|
||||||
|
word zpl_pool, Pool
|
||||||
|
word zpl_pr, Process
|
||||||
|
word zpl_pr_si, ProcessStartupInfo
|
||||||
|
word zpl_quat, Quat
|
||||||
|
word zpl_rect2, Rect2
|
||||||
|
word zpl_rect3, Rect3
|
||||||
|
word zpl_re, Regex
|
||||||
|
word zpl_re_capture, RegexCapture
|
||||||
|
word zpl_regex_error, RegexError
|
||||||
|
wrod zpl_random, RNG
|
||||||
|
word zpl_rune, Rune
|
||||||
|
word zpl_scratch_memory, ScratchMemory
|
||||||
|
word zpl_seek_whence_type, SeekWhenceType
|
||||||
|
word zpl_semaphore, Semaphore
|
||||||
|
word zpl_string, String
|
||||||
|
word zpl_string_header, StringHeader
|
||||||
|
word zpl_sync, Sync
|
||||||
|
word zpl_opts, Opts
|
||||||
|
word zpl_opts_entry, OptsEntry
|
||||||
|
word zpl_opts_err, OptsError
|
||||||
|
word zpl_opts_err_type, OptsErrorType
|
||||||
|
word zpl_opts_types, OptsTypes
|
||||||
|
word zpl_tar_errors, TarErrors
|
||||||
|
word zpl_tar_file_type, TarFileType
|
||||||
|
word zpl_tar_record, TarRecord
|
||||||
|
word zpl_tar_unpack_proc, TarUnpackProc
|
||||||
|
word zpl_thread, Thread
|
||||||
|
word zpl_thread_job, ThreadJob
|
||||||
|
word zpl_thread_proc, ThreadProc
|
||||||
|
word zpl_thread_queue, ThreadQueue
|
||||||
|
word zpl_thread_worker, ThreadWorker
|
||||||
|
word zpl_vec2, Vec2
|
||||||
|
word zpl_vec3, Vec3
|
||||||
|
word zpl_vec4, Vec4
|
||||||
|
word zpl_virtual_memory, VirtualMemory
|
||||||
|
|
||||||
|
// Function Renames
|
||||||
|
word zpl_lfence, fence_load
|
||||||
|
word zpl_mfence, fence_memory
|
||||||
|
word zpl_sfence, fence_store
|
||||||
|
word zpl_memchr, mem_find
|
||||||
|
word zpl_memcopy, mem_copy
|
||||||
|
word zpl_memmove, mem_move
|
||||||
|
word zpl_memset, mem_set
|
||||||
|
word zpl_memswap, mem_swap
|
||||||
|
word zpl_exit, process_exit
|
||||||
|
word zpl_rdtsc, read_cpu_time_stamp_counter
|
||||||
word zpl_strcmp, str_compare
|
word zpl_strcmp, str_compare
|
||||||
|
word zpl_strncmp, str_compare
|
||||||
|
word zpl_strcat, str_concat
|
||||||
|
word zpl_strcpy, str_copy
|
||||||
|
word zpl_strncpy, str_copy
|
||||||
|
word zpl_strlcpy, str_copy_nulpad
|
||||||
|
word zpl_strdup, str_dup
|
||||||
|
word zpl_strchr, str_find
|
||||||
|
word zpl_strrchr, str_find_last
|
||||||
|
word zpl_strstr, str_find_substr
|
||||||
|
word zpl_snprintf, str_fmt
|
||||||
|
word zpl_snprintf_va, str_fmt_va
|
||||||
|
word zpl_asprintf, str_fmt_alloc
|
||||||
|
word zpl_asprintf_va, str_fmt_alloc_va
|
||||||
|
word zpl_bprintf, str_fmt_buf
|
||||||
|
word zpl_bprintf_va, str_fmt_buf_va
|
||||||
|
word zpl_printf, str_fmt_out
|
||||||
|
word zpl_printf_va, str_fmt_out_va
|
||||||
|
word zpl_printf_err, str_fmt_out_err
|
||||||
|
word zpl_printf_err_va, str_fmt_out_err_va
|
||||||
|
word zpl_fprintf, str_fmt_file
|
||||||
|
word zpl_fprintf_va, str_fmt_file_va
|
||||||
|
word zpl_strlen, str_len
|
||||||
|
word zpl_strnlen, str_len
|
||||||
|
word zpl_strrev, str_reverse
|
||||||
|
word zpl_strtok, str_tok
|
||||||
|
word zpl_strtok_r, str_tok_reentrant
|
||||||
|
word zpl_sleep, thread_sleep
|
||||||
|
word zpl_sleep_ms, thread_sleep_ms
|
||||||
|
word zpl_yield_thread, thread_yield
|
||||||
|
word zpl_utf8_strlen, utf8_len
|
||||||
|
word zpl_utf8_strnlen, utf8_len
|
||||||
|
|
||||||
// Undesired typedefs
|
// Undesired typedefs
|
||||||
word zpl_i8, s8
|
word zpl_i8, s8
|
||||||
@ -52,39 +205,10 @@ word zpl_usize, uw
|
|||||||
word zpl_isize, sw
|
word zpl_isize, sw
|
||||||
|
|
||||||
// Undesired exposures.
|
// Undesired exposures.
|
||||||
//not word zpl_allocator
|
word cast, zpl_cast
|
||||||
//not word zpl_arena
|
|
||||||
//not word zpl_array
|
|
||||||
//not word zpl_file
|
|
||||||
//not word zpl_list
|
|
||||||
//not word zpl_pool
|
|
||||||
//not word zpl_opts
|
|
||||||
|
|
||||||
// Conflicts with refactor
|
not word zpl_thread_local
|
||||||
word arena, a_arena
|
|
||||||
word array, a_array
|
// Name Conflicts
|
||||||
word alloc, a_allocator
|
|
||||||
word file, a_file
|
|
||||||
word file_size, fsize
|
word file_size, fsize
|
||||||
word list, a_list
|
word alloc, allocator
|
||||||
word opts, a_opts
|
|
||||||
word pool, a_pool
|
|
||||||
|
|
||||||
// Conflicts with std. (Uncomment if using c externs)
|
|
||||||
not word zpl_memchr
|
|
||||||
not word zpl_memmove
|
|
||||||
not word zpl_memset
|
|
||||||
not word zpl_memswap
|
|
||||||
not word zpl_memcopy
|
|
||||||
not word zpl_printf
|
|
||||||
not word zpl_printf_va
|
|
||||||
not word zpl_printf_err
|
|
||||||
not word zpl_printf_err_va
|
|
||||||
not word zpl_fprintf
|
|
||||||
not word zpl_fprintf_va
|
|
||||||
not word zpl_snprintf
|
|
||||||
not word zpl_snprintf_va
|
|
||||||
not word zpl_strchr
|
|
||||||
not word zpl_strlen
|
|
||||||
not word zpl_strnlen
|
|
||||||
not word zpl_exit
|
|
||||||
|
@ -50,7 +50,7 @@ namespace IO
|
|||||||
|
|
||||||
zpl_file_close( & src );
|
zpl_file_close( & src );
|
||||||
}
|
}
|
||||||
while ( path++, left--, left > 1 );
|
while ( path++, left--, left > 0 );
|
||||||
|
|
||||||
uw persist_size = Largest_Src_Size * 2 + 8;
|
uw persist_size = Largest_Src_Size * 2 + 8;
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ The program execution is pretty much outlined quite clearly in `int main()`.
|
|||||||
There are constraints for specific variables;
|
There are constraints for specific variables;
|
||||||
|
|
||||||
* `Path_Size_Largest` : Longest path size is set to 1 KB of characters.
|
* `Path_Size_Largest` : Longest path size is set to 1 KB of characters.
|
||||||
* `Token_Max_Length` : Set to 1 KB characters as well.
|
* `Token_Max_Length` : Set to 128 KB.
|
||||||
* `Array_Reserve_Num` : Is set to 4 KB.
|
* `Array_Reserve_Num` : Is set to 4 KB.
|
||||||
* Initial Global arena size : Set to 2 megabytes.
|
* Initial Global arena size : Set to 2 megabytes.
|
||||||
|
|
||||||
The `Path_Size_Largest` and `Token_Max_Length` are compile-time constraints that the runtime will not have a fallback for, if 1 KB is not enough it will need to be changed for your use case.
|
The `Path_Size_Largest` and `Token_Max_Length` are compile-time constraints that the runtime will not have a fallback for, if current size is not enough it will need to be changed for your use case.
|
||||||
|
|
||||||
`Array_Reserve_Num` is used to dictate the assumed amount of tokens will be held in total for any of spec's arrays holding ignores and refactor entries. If any of the array's exceed 4 KB they will grow triggering a resize which will bog down the speed of the refactor. Adjust if you think you can increase or lower for use case.
|
`Array_Reserve_Num` is used to dictate the assumed amount of tokens will be held in total for any of spec's arrays holding ignores and refactor entries. If any of the array's exceed 4 KB they will grow triggering a resize which will bog down the speed of the refactor. Adjust if you think you can increase or lower for use case.
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
namespace Spec
|
namespace Spec
|
||||||
{
|
{
|
||||||
ct uw Array_Reserve_Num = zpl_kilobytes(4);
|
ct uw Array_Reserve_Num = zpl_kilobytes(4);
|
||||||
ct uw Token_Max_Length = zpl_kilobytes(1);
|
ct uw Token_Max_Length = 128;
|
||||||
|
|
||||||
namespace StaticData
|
namespace StaticData
|
||||||
{
|
{
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#include "IO.cpp"
|
#include "IO.cpp"
|
||||||
#include "Spec.cpp"
|
#include "Spec.cpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void parse_options( int num, char** arguments )
|
void parse_options( int num, char** arguments )
|
||||||
{
|
{
|
||||||
zpl_opts opts;
|
zpl_opts opts;
|
||||||
@ -162,6 +160,11 @@ void parse_options( int num, char** arguments )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Refactor will problably have the execution and arg parsing (main and opts)
|
||||||
|
moved to a separate file.
|
||||||
|
*/
|
||||||
|
|
||||||
zpl_arena Refactor_Buffer;
|
zpl_arena Refactor_Buffer;
|
||||||
|
|
||||||
void refactor()
|
void refactor()
|
||||||
@ -211,21 +214,37 @@ void refactor()
|
|||||||
|
|
||||||
#define pos (IO::Current_Size - left)
|
#define pos (IO::Current_Size - left)
|
||||||
|
|
||||||
|
struct Snapshot
|
||||||
|
{
|
||||||
|
char const* Src;
|
||||||
|
sw Left;
|
||||||
|
uw Col;
|
||||||
|
uw Line;
|
||||||
|
};
|
||||||
|
|
||||||
#define move_forward( Amount_ ) \
|
#define move_forward( Amount_ ) \
|
||||||
|
do { \
|
||||||
if ( left - Amount_ <= 0 ) \
|
if ( left - Amount_ <= 0 ) \
|
||||||
goto End_Search; \
|
goto End_Search; \
|
||||||
\
|
\
|
||||||
|
const sw end = Amount_ - 1; \
|
||||||
|
\
|
||||||
|
line += src[end] == '\n'; \
|
||||||
left -= Amount_; \
|
left -= Amount_; \
|
||||||
col += Amount_; \
|
col = (col + Amount_) * src[end] != '\n'; \
|
||||||
src += Amount_ \
|
src += Amount_; \
|
||||||
|
} \
|
||||||
|
while (0) \
|
||||||
|
|
||||||
#define move_back( Amount_ ) \
|
#define restore( Snapshot_ ) \
|
||||||
left += Amount_; \
|
src = Snapshot_.Src; \
|
||||||
col -= Amount_; \
|
left = Snapshot_.Left; \
|
||||||
src -= Amount_ \
|
col = Snapshot_.Col; \
|
||||||
|
line = Snapshot_.Line \
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
// Check for comments if ignoring.
|
||||||
if ( Spec::Ignore_Comments && src[0] == '/' && left - 2 > 0 )
|
if ( Spec::Ignore_Comments && src[0] == '/' && left - 2 > 0 )
|
||||||
{
|
{
|
||||||
if ( src[1] == '/' )
|
if ( src[1] == '/' )
|
||||||
@ -259,37 +278,33 @@ void refactor()
|
|||||||
{
|
{
|
||||||
Spec::Entry* ignore = Spec::Ignore_Includes;
|
Spec::Entry* ignore = Spec::Ignore_Includes;
|
||||||
sw ignores_left = zpl_array_count( Spec::Ignore_Includes);
|
sw ignores_left = zpl_array_count( Spec::Ignore_Includes);
|
||||||
sw rewind = 0;
|
Snapshot backup = { src, left, col, line };
|
||||||
|
|
||||||
if ( '#' != src[0] )
|
if ( '#' != src[0] )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
move_forward( 1 );
|
move_forward( 1 );
|
||||||
rewind++;
|
|
||||||
|
|
||||||
// Ignore whitespace
|
// Ignore whitespace
|
||||||
while ( zpl_char_is_space( src[0] ) )
|
while ( zpl_char_is_space( src[0] ) )
|
||||||
{
|
{
|
||||||
move_forward( 1 );
|
move_forward( 1 );
|
||||||
rewind++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
||||||
{
|
{
|
||||||
move_back( rewind );
|
restore( backup );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 sig_size = sizeof(include_sig) - 1;
|
const u32 sig_size = sizeof(include_sig) - 1;
|
||||||
|
|
||||||
move_forward( sig_size );
|
move_forward( sig_size );
|
||||||
rewind += sig_size;
|
|
||||||
|
|
||||||
// Ignore whitespace
|
// Ignore whitespace
|
||||||
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
||||||
{
|
{
|
||||||
move_forward(1);
|
move_forward(1);
|
||||||
rewind++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; ignores_left; ignores_left--, ignore++ )
|
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||||
@ -318,121 +333,42 @@ void refactor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
move_back( rewind );
|
restore( backup );
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
// Word Ignores
|
|
||||||
{
|
|
||||||
Spec::Entry* ignore = Spec::Ignore_Words;
|
|
||||||
sw ignores_left = zpl_array_count( Spec::Ignore_Words);
|
|
||||||
|
|
||||||
for ( ; ignores_left; ignores_left--, ignore++ )
|
|
||||||
{
|
|
||||||
if ( ignore->Sig[0] != src[0] )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
zpl_string_clear( current );
|
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( ignore->Sig );
|
|
||||||
current = zpl_string_append_length( current, src, sig_length );
|
|
||||||
|
|
||||||
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
|
||||||
{
|
|
||||||
char before = src[-1];
|
|
||||||
char after = src[sig_length];
|
|
||||||
|
|
||||||
if ( zpl_char_is_alphanumeric( before ) || before == '_'
|
|
||||||
|| zpl_char_is_alphanumeric( after ) || after == '_' )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_fmt("\nIgnored %-81s line %d, col %d", current, line, col );
|
|
||||||
|
|
||||||
move_forward( sig_length );
|
|
||||||
goto Skip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Namespace Ignores
|
|
||||||
{
|
|
||||||
Spec::Entry* ignore = Spec::Ignore_Namespaces;
|
|
||||||
sw ignores_left = zpl_array_count( Spec::Ignore_Namespaces);
|
|
||||||
|
|
||||||
for ( ; ignores_left; ignores_left--, ignore++ )
|
|
||||||
{
|
|
||||||
if ( ignore->Sig[0] != src[0] )
|
|
||||||
{
|
|
||||||
ignore++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
zpl_string_clear( current );
|
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( ignore->Sig );
|
|
||||||
current = zpl_string_append_length( current, src, sig_length );
|
|
||||||
|
|
||||||
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
|
||||||
{
|
|
||||||
u32 length = sig_length;
|
|
||||||
char const* ns_content = src + sig_length;
|
|
||||||
|
|
||||||
while ( zpl_char_is_alphanumeric( ns_content[0] ) || ns_content[0] == '_' )
|
|
||||||
{
|
|
||||||
length++;
|
|
||||||
ns_content++;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if Build_Debug
|
|
||||||
zpl_string_clear( preview );
|
|
||||||
preview = zpl_string_append_length( preview, src, length );
|
|
||||||
log_fmt("\nIgnored %-40s %-40s line %d, column %d", preview, ignore->Sig, line, col );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
move_forward( length );
|
|
||||||
goto Skip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Includes to match
|
// Includes to match
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Spec::Entry* include = Spec::Includes;
|
Spec::Entry* include = Spec::Includes;
|
||||||
sw includes_left = zpl_array_count ( Spec::Includes);
|
sw includes_left = zpl_array_count ( Spec::Includes);
|
||||||
sw rewind = 0;
|
Snapshot backup = { src, left, col, line };
|
||||||
|
|
||||||
if ( '#' != src[0] )
|
if ( '#' != src[0] )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
move_forward( 1 );
|
move_forward( 1 );
|
||||||
rewind++;
|
|
||||||
|
|
||||||
// Ignore whitespace
|
// Ignore whitespace
|
||||||
while ( zpl_char_is_space( src[0] ) )
|
while ( zpl_char_is_space( src[0] ) )
|
||||||
{
|
{
|
||||||
move_forward( 1 );
|
move_forward( 1 );
|
||||||
rewind++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
if ( zpl_strncmp( include_sig, src, sizeof(include_sig) - 1 ) != 0 )
|
||||||
{
|
{
|
||||||
move_back( rewind );
|
restore( backup );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 sig_size = sizeof(include_sig) - 1;
|
const u32 sig_size = sizeof(include_sig) - 1;
|
||||||
|
|
||||||
move_forward( sig_size );
|
move_forward( sig_size );
|
||||||
rewind += sig_size;
|
|
||||||
|
|
||||||
// Ignore whitespace
|
// Ignore whitespace
|
||||||
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
while ( zpl_char_is_space( src[0] ) || src[0] == '\"' || src[0] == '<' )
|
||||||
{
|
{
|
||||||
move_forward( 1 );
|
move_forward( 1 );
|
||||||
rewind++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; includes_left; includes_left--, include++ )
|
for ( ; includes_left; includes_left--, include++ )
|
||||||
@ -473,10 +409,44 @@ void refactor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
move_back( rewind );
|
restore( backup );
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
|
// Word Ignores
|
||||||
|
{
|
||||||
|
Spec::Entry* ignore = Spec::Ignore_Words;
|
||||||
|
sw ignores_left = zpl_array_count( Spec::Ignore_Words);
|
||||||
|
|
||||||
|
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||||
|
{
|
||||||
|
if ( ignore->Sig[0] != src[0] )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
zpl_string_clear( current );
|
||||||
|
|
||||||
|
u32 sig_length = zpl_string_length( ignore->Sig );
|
||||||
|
current = zpl_string_append_length( current, src, sig_length );
|
||||||
|
|
||||||
|
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
||||||
|
{
|
||||||
|
char before = src[-1];
|
||||||
|
char after = src[sig_length];
|
||||||
|
|
||||||
|
if ( zpl_char_is_alphanumeric( before ) || before == '_'
|
||||||
|
|| zpl_char_is_alphanumeric( after ) || after == '_' )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_fmt("\nIgnored %-81s line %d, col %d", current, line, col );
|
||||||
|
|
||||||
|
move_forward( sig_length );
|
||||||
|
goto Skip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Words to match
|
// Words to match
|
||||||
{
|
{
|
||||||
Spec::Entry* word = Spec::Words;
|
Spec::Entry* word = Spec::Words;
|
||||||
@ -525,6 +495,53 @@ void refactor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Namespace Ignores
|
||||||
|
{
|
||||||
|
Spec::Entry* ignore = Spec::Ignore_Namespaces;
|
||||||
|
sw ignores_left = zpl_array_count( Spec::Ignore_Namespaces);
|
||||||
|
|
||||||
|
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||||
|
{
|
||||||
|
if ( ignore->Sig[0] != src[0] )
|
||||||
|
{
|
||||||
|
ignore++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (( zpl_char_is_alphanumeric( src[-1] ) || src[-1] == '_') )
|
||||||
|
{
|
||||||
|
ignore++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
zpl_string_clear( current );
|
||||||
|
|
||||||
|
u32 sig_length = zpl_string_length( ignore->Sig );
|
||||||
|
current = zpl_string_append_length( current, src, sig_length );
|
||||||
|
|
||||||
|
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
||||||
|
{
|
||||||
|
u32 length = sig_length;
|
||||||
|
char const* ns_content = src + sig_length;
|
||||||
|
|
||||||
|
while ( zpl_char_is_alphanumeric( ns_content[0] ) || ns_content[0] == '_' )
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
ns_content++;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if Build_Debug
|
||||||
|
zpl_string_clear( preview );
|
||||||
|
preview = zpl_string_append_length( preview, src, length );
|
||||||
|
log_fmt("\nIgnored %-40s %-40s line %d, column %d", preview, ignore->Sig, line, col );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
move_forward( length );
|
||||||
|
goto Skip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Namespaces to match
|
// Namespaces to match
|
||||||
{
|
{
|
||||||
Spec::Entry* nspace = Spec::Namespaces;
|
Spec::Entry* nspace = Spec::Namespaces;
|
||||||
@ -536,6 +553,9 @@ void refactor()
|
|||||||
if ( nspace->Sig[0] != src[0] )
|
if ( nspace->Sig[0] != src[0] )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (( zpl_char_is_alphanumeric( src[-1] ) || src[-1] == '_') )
|
||||||
|
continue;
|
||||||
|
|
||||||
zpl_string_clear( current );
|
zpl_string_clear( current );
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( nspace->Sig );
|
u32 sig_length = zpl_string_length( nspace->Sig );
|
||||||
@ -555,7 +575,7 @@ void refactor()
|
|||||||
Token entry {};
|
Token entry {};
|
||||||
|
|
||||||
entry.Start = pos;
|
entry.Start = pos;
|
||||||
entry.End = pos + length;
|
entry.End = pos + sig_length;
|
||||||
entry.Sig = nspace->Sig;
|
entry.Sig = nspace->Sig;
|
||||||
|
|
||||||
buffer_size += sig_length;
|
buffer_size += sig_length;
|
||||||
@ -563,7 +583,7 @@ void refactor()
|
|||||||
if ( nspace->Sub != nullptr )
|
if ( nspace->Sub != nullptr )
|
||||||
{
|
{
|
||||||
entry.Sub = nspace->Sub;
|
entry.Sub = nspace->Sub;
|
||||||
buffer_size += zpl_string_length( entry.Sub ) - length;
|
buffer_size += zpl_string_length( entry.Sub ) - sig_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
zpl_array_append( tokens, entry );
|
zpl_array_append( tokens, entry );
|
||||||
@ -581,12 +601,6 @@ void refactor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Skip:
|
Skip:
|
||||||
if ( src[0] == '\n' )
|
|
||||||
{
|
|
||||||
line++;
|
|
||||||
col = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
move_forward( 1 );
|
move_forward( 1 );
|
||||||
}
|
}
|
||||||
while ( left );
|
while ( left );
|
||||||
|
@ -29,7 +29,10 @@ if ( -not( Test-Path $path_build ) )
|
|||||||
$args_meson += "setup"
|
$args_meson += "setup"
|
||||||
$args_meson += $path_build
|
$args_meson += $path_build
|
||||||
|
|
||||||
Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
|
# Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
|
||||||
|
Push-Location $path_scripts
|
||||||
|
Invoke-Expression "& meson $args_meson"
|
||||||
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $type )
|
if ( $type )
|
||||||
@ -39,14 +42,19 @@ if ( $type )
|
|||||||
$args_meson += $path_build
|
$args_meson += $path_build
|
||||||
$args_meson += "--buildtype $($type)"
|
$args_meson += "--buildtype $($type)"
|
||||||
|
|
||||||
Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
|
# Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
|
||||||
|
Push-Location $path_scripts
|
||||||
|
Invoke-Expression "& meson $args_meson"
|
||||||
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
|
||||||
$args_ninja = @()
|
$args_ninja = @()
|
||||||
$args_ninja += "-C"
|
$args_ninja += "-C"
|
||||||
$args_ninja += $path_build
|
$args_ninja += $path_build
|
||||||
|
|
||||||
Start-Process ninja $args_ninja -Wait -NoNewWindow -WorkingDirectory $path_root
|
Push-Location $path_root
|
||||||
|
ninja $args_ninja
|
||||||
|
Pop-Location
|
||||||
#endregion Regular Build
|
#endregion Regular Build
|
||||||
|
|
||||||
|
|
||||||
@ -56,7 +64,8 @@ if ( $test -eq $true )
|
|||||||
write-host "`n`nBuilding Test`n"
|
write-host "`n`nBuilding Test`n"
|
||||||
|
|
||||||
# Refactor thirdparty libraries
|
# Refactor thirdparty libraries
|
||||||
& (Join-Path $PSScriptRoot 'refactor_and_format.ps1')
|
Invoke-Expression "& $(Join-Path $PSScriptRoot 'refactor_and_format.ps1') $args"
|
||||||
|
|
||||||
|
|
||||||
$path_test = Join-Path $path_root test
|
$path_test = Join-Path $path_root test
|
||||||
$path_test_build = Join-Path $path_test build
|
$path_test_build = Join-Path $path_test build
|
||||||
@ -67,15 +76,17 @@ if ( $test -eq $true )
|
|||||||
$args_meson += "setup"
|
$args_meson += "setup"
|
||||||
$args_meson += $path_test_build
|
$args_meson += $path_test_build
|
||||||
|
|
||||||
Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_test
|
Push-Location $path_test
|
||||||
|
& meson $args_meson
|
||||||
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
|
||||||
$args_ninja = @()
|
$args_ninja = @()
|
||||||
$args_ninja += "-C"
|
$args_ninja += "-C"
|
||||||
$args_ninja += $path_test_build
|
$args_ninja += $path_test_build
|
||||||
|
|
||||||
write-host $args_ninja
|
Push-Location $path_root
|
||||||
|
ninja $args_ninja
|
||||||
Start-Process ninja $args_ninja -Wait -NoNewWindow -WorkingDirectory $path_root
|
Pop-Location
|
||||||
#endregion Test Build
|
#endregion Test Build
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
cls
|
cls
|
||||||
& (Join-Path $PSScriptRoot 'build.ci.ps1')
|
Invoke-Expression "& $(Join-Path $PSScriptRoot 'build.ci.ps1') $args"
|
||||||
|
@ -8,7 +8,6 @@ $path_project = Join-Path $path_root project
|
|||||||
$path_test = Join-Path $path_root test
|
$path_test = Join-Path $path_root test
|
||||||
$path_thirdparty = Join-Path $path_root thirdparty
|
$path_thirdparty = Join-Path $path_root thirdparty
|
||||||
|
|
||||||
$file_spec = Join-Path $path_test zpl.refactor
|
|
||||||
$refactor = Join-Path $path_build refactor.exe
|
$refactor = Join-Path $path_build refactor.exe
|
||||||
|
|
||||||
# Gather the files to be formatted.
|
# Gather the files to be formatted.
|
||||||
@ -25,48 +24,44 @@ foreach ( $file in $targetFiles )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
write-host "Beginning thirdpary refactor...`n"
|
write-host "Beginning thirdpary refactor..."
|
||||||
|
|
||||||
$refactors = @(@())
|
$file_spec = Join-Path $path_test zpl.refactor
|
||||||
|
|
||||||
if ( $false ){
|
$refactorParams = @(
|
||||||
foreach ( $file in $targetFiles )
|
"-src=$(Join-Path $path_thirdparty "zpl.h")",
|
||||||
{
|
"-dst=$(Join-Path $path_test "zpl.refactored.h")",
|
||||||
$destination = Join-Path $path_test (Split-Path $file -leaf)
|
|
||||||
$destination = $destination.Replace( '.h', '.refactored.h' )
|
|
||||||
|
|
||||||
$refactorParams = @(
|
|
||||||
"-src=$($file)",
|
|
||||||
"-dst=$($destination)"
|
|
||||||
"-spec=$($file_spec)"
|
"-spec=$($file_spec)"
|
||||||
)
|
)
|
||||||
|
|
||||||
$refactors += (Start-Process $refactor $refactorParams -NoNewWindow -PassThru)
|
if ( $args.Contains( "debug" ) )
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$refactorParams = @(
|
|
||||||
# "-debug",
|
|
||||||
"-num=$($targetFiles.Count)"
|
|
||||||
"-src=$($targetFiles)",
|
|
||||||
"-dst=$($refactoredFiles)",
|
|
||||||
"-spec=$($file_spec)"
|
|
||||||
)
|
|
||||||
|
|
||||||
Start-Process $refactor $refactorParams -NoNewWindow -PassThru -Wait
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( $process in $refactors )
|
|
||||||
{
|
{
|
||||||
if ( $process )
|
$refactorParams += "-debug"
|
||||||
{
|
|
||||||
$process.WaitForExit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "`nRefactoring complete`n`n"
|
write-host "`zpl refactor: " $refactorParams
|
||||||
|
& $refactor $refactorParams
|
||||||
|
|
||||||
write-host "Beginning project refactor...`n"
|
$file_spec = Join-Path $path_test "stb_image.refactor"
|
||||||
|
|
||||||
|
$refactorParams = @(
|
||||||
|
"-src=$(Join-Path $path_thirdparty "stb_image.h")",
|
||||||
|
"-dst=$(Join-Path $path_test "stb_image.refactored.h")",
|
||||||
|
"-spec=$($file_spec)"
|
||||||
|
)
|
||||||
|
|
||||||
|
if ( $args.Contains( "debug" ) )
|
||||||
|
{
|
||||||
|
$refactorParams += "-debug"
|
||||||
|
}
|
||||||
|
|
||||||
|
write-host "`n`nstb_image refactor: " $refactorParams
|
||||||
|
& $refactor $refactorParams
|
||||||
|
|
||||||
|
Write-Host "`nRefactoring complete`n"
|
||||||
|
|
||||||
|
|
||||||
|
write-host "Beginning project refactor..."
|
||||||
|
|
||||||
# Gather the files to be formatted.
|
# Gather the files to be formatted.
|
||||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||||
@ -74,8 +69,6 @@ $refactoredFiles = @()
|
|||||||
|
|
||||||
$file_spec = Join-Path $path_test project.refactor
|
$file_spec = Join-Path $path_test project.refactor
|
||||||
|
|
||||||
write-host "FILE SPEC:" $file_spec
|
|
||||||
|
|
||||||
foreach ( $file in $targetFiles )
|
foreach ( $file in $targetFiles )
|
||||||
{
|
{
|
||||||
$destination = Join-Path $path_test (Split-Path $file -leaf)
|
$destination = Join-Path $path_test (Split-Path $file -leaf)
|
||||||
@ -86,16 +79,20 @@ foreach ( $file in $targetFiles )
|
|||||||
}
|
}
|
||||||
|
|
||||||
$refactorParams = @(
|
$refactorParams = @(
|
||||||
# "-debug",
|
|
||||||
"-num=$($targetFiles.Count)"
|
"-num=$($targetFiles.Count)"
|
||||||
"-src=$($targetFiles)",
|
"-src=$($targetFiles)",
|
||||||
"-dst=$($refactoredFiles)",
|
"-dst=$($refactoredFiles)",
|
||||||
"-spec=$($file_spec)"
|
"-spec=$($file_spec)"
|
||||||
)
|
)
|
||||||
|
|
||||||
Start-Process $refactor $refactorParams -NoNewWindow -PassThru -Wait
|
if ( $args.Contains( "debug" ) )
|
||||||
|
{
|
||||||
|
$refactorParams += "-debug"
|
||||||
|
}
|
||||||
|
|
||||||
write-host "`nRefactoring complete`n`n"
|
& $refactor $refactorParams
|
||||||
|
|
||||||
|
write-host "`nRefactoring complete`n"
|
||||||
|
|
||||||
|
|
||||||
# Can't format zpl library... (It hangs clang format)
|
# Can't format zpl library... (It hangs clang format)
|
||||||
@ -115,3 +112,4 @@ clang-format $formatParams $targetFiles
|
|||||||
|
|
||||||
Write-Host "`nFormatting complete"
|
Write-Host "`nFormatting complete"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
scripts/template_reafactor.ps1
Normal file
38
scripts/template_reafactor.ps1
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
[string[]] $include = '*.h', '*.hh', '*.hpp', '*.c', '*.cc', '*.cpp'
|
||||||
|
[string[]] $exclude = '*.g.*', '*.refactor'
|
||||||
|
|
||||||
|
# Change this to your root directory if needed.
|
||||||
|
$path_root = $PSScriptRoot
|
||||||
|
|
||||||
|
# Change this to your desired destination
|
||||||
|
$path_dest = $path_root
|
||||||
|
|
||||||
|
# Gather the files to be formatted.
|
||||||
|
$targetFiles = @(Get-ChildItem -Recurse -Path $path_root -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||||
|
$refactoredFiles = @()
|
||||||
|
|
||||||
|
foreach ( $file in $targetFiles )
|
||||||
|
{
|
||||||
|
$destination = Join-Path $path_dest (Split-Path $file -leaf)
|
||||||
|
$destination = $destination.Replace( '.h', '.refactored.h' )
|
||||||
|
$destination = $destination.Replace( '.c', '.refactored.c' )
|
||||||
|
|
||||||
|
$refactoredFiles += $destination
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
write-host "Beginning refactor...`n"
|
||||||
|
|
||||||
|
$refactors = @(@())
|
||||||
|
|
||||||
|
$refactorParams = @(
|
||||||
|
# "-debug",
|
||||||
|
"-num=$($targetFiles.Count)"
|
||||||
|
"-src=$($targetFiles)",
|
||||||
|
"-dst=$($refactoredFiles)",
|
||||||
|
"-spec=$($file_spec)"
|
||||||
|
)
|
||||||
|
|
||||||
|
& $refactor $refactorParams
|
||||||
|
|
||||||
|
Write-Host "`nRefactoring complete`n`n"
|
7987
thirdparty/stb_image.h
vendored
Normal file
7987
thirdparty/stb_image.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11917
thirdparty/zpl.h
vendored
11917
thirdparty/zpl.h
vendored
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user