cifter-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cifter_cli-0.1.0/LICENSE +21 -0
- cifter_cli-0.1.0/PKG-INFO +201 -0
- cifter_cli-0.1.0/README.md +170 -0
- cifter_cli-0.1.0/pyproject.toml +86 -0
- cifter_cli-0.1.0/src/cifter/__init__.py +3 -0
- cifter_cli-0.1.0/src/cifter/__main__.py +4 -0
- cifter_cli-0.1.0/src/cifter/cli.py +90 -0
- cifter_cli-0.1.0/src/cifter/errors.py +4 -0
- cifter_cli-0.1.0/src/cifter/extract_flow.py +178 -0
- cifter_cli-0.1.0/src/cifter/extract_function.py +15 -0
- cifter_cli-0.1.0/src/cifter/extract_path.py +351 -0
- cifter_cli-0.1.0/src/cifter/model.py +142 -0
- cifter_cli-0.1.0/src/cifter/parser.py +138 -0
- cifter_cli-0.1.0/src/cifter/preprocessor.py +132 -0
- cifter_cli-0.1.0/src/cifter/render.py +8 -0
cifter_cli-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 t-kenji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cifter-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: C/C++ の関数実装を抽出する軽量 CLI
|
|
5
|
+
Keywords: c,c++,cpp,cli,tree-sitter,source-extraction,static-analysis
|
|
6
|
+
Author: t-kenji
|
|
7
|
+
Author-email: t-kenji <protect.2501@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: C
|
|
18
|
+
Classifier: Programming Language :: C++
|
|
19
|
+
Classifier: Topic :: Software Development
|
|
20
|
+
Requires-Dist: pcpp>=1.30
|
|
21
|
+
Requires-Dist: tree-sitter>=0.25.2
|
|
22
|
+
Requires-Dist: tree-sitter-c>=0.24.1
|
|
23
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4
|
|
24
|
+
Requires-Dist: typer>=0.24.1
|
|
25
|
+
Requires-Python: >=3.12
|
|
26
|
+
Project-URL: Homepage, https://github.com/t-kenji/cifter
|
|
27
|
+
Project-URL: Repository, https://github.com/t-kenji/cifter
|
|
28
|
+
Project-URL: Issues, https://github.com/t-kenji/cifter/issues
|
|
29
|
+
Project-URL: Changelog, https://github.com/t-kenji/cifter/blob/main/CHANGELOG.md
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# cifter
|
|
33
|
+
|
|
34
|
+
`cifter` は、C/C++ の関数実装を機械的かつ高速に抽出する CLI です。
|
|
35
|
+
`tree-sitter` で構文を捉え、行番号付き text として返します。重い意味解析や LLM 連携は行いません。
|
|
36
|
+
|
|
37
|
+
## 概要
|
|
38
|
+
|
|
39
|
+
- 単一の `--source` ファイルから抽出します
|
|
40
|
+
- 公開サブコマンドは `function` / `flow` / `path` の 3 つです
|
|
41
|
+
- 出力は元ソースと対応付け可能な行番号付き text です
|
|
42
|
+
- `-D NAME[=VALUE]` により条件分岐前処理を評価できます
|
|
43
|
+
|
|
44
|
+
## Why cifter
|
|
45
|
+
|
|
46
|
+
- 関数全体をそのまま抜き出したい
|
|
47
|
+
- 分岐の骨格だけを見たい
|
|
48
|
+
- 特定の route だけを細く追いたい
|
|
49
|
+
- 元の行番号を失わずにレビューや調査へ貼りたい
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
PyPI から install:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
python -m pip install cifter-cli
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
最小確認:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
cift --help
|
|
63
|
+
python -m cifter --help
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
GitHub Release の `wheel` / `sdist` から install することもできます。
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
python -m pip install ./cifter_cli-0.1.0-py3-none-any.whl
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
開発用:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
uv sync
|
|
76
|
+
uv run cift --help
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
サンプルソース:
|
|
82
|
+
|
|
83
|
+
```c
|
|
84
|
+
int FooFunction(int x)
|
|
85
|
+
{
|
|
86
|
+
if (x > 0) {
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
関数全体を抽出:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
cift function --name FooFunction --source foo.c
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
出力:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
1: int FooFunction(int x)
|
|
104
|
+
2: {
|
|
105
|
+
3: if (x > 0) {
|
|
106
|
+
4: return 1;
|
|
107
|
+
5: }
|
|
108
|
+
6:
|
|
109
|
+
7: return 0;
|
|
110
|
+
8: }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Commands
|
|
114
|
+
|
|
115
|
+
`function`:
|
|
116
|
+
指定した関数の実装全体をそのまま抽出します。レビュー対象の最小切り出しに向きます。
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
cift function --name FooFunction --source examples/demo.c
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`flow`:
|
|
123
|
+
制御構造の骨格だけを残します。`--track` を付けると、完全一致したアクセスパスを含む文を追加保持します。
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
cift flow --function FooFunction --source examples/demo.c --track state
|
|
127
|
+
cift flow --function FooFunction --source examples/demo.c --track 'ctx->state'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`path`:
|
|
131
|
+
指定した route だけを細く抽出します。親構造は残し、route 終端に達したコンテナでは後続の通常文も残します。
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
cift path --function FooFunction --source examples/demo.c --route 'case CMD_HOGE > if ret == OK'
|
|
135
|
+
cift path --function FooFunction --source examples/demo.c --route 'case CMD_HOGE > else if errno == EINT'
|
|
136
|
+
cift path --function ElseRoute --source examples/demo.c --route 'else'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Preprocessor / Track / Route
|
|
140
|
+
|
|
141
|
+
`-D`:
|
|
142
|
+
条件分岐前処理の評価に使うマクロを追加します。
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
cift function --name FooFunction --source examples/demo.c -D DEF_FOO -D ENABLE_BAR=1
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`--track`:
|
|
149
|
+
`flow` で保持したいアクセスパスです。構文上の完全一致だけを扱います。
|
|
150
|
+
|
|
151
|
+
- `state`
|
|
152
|
+
- `ctx->state`
|
|
153
|
+
- `a->b.c`
|
|
154
|
+
|
|
155
|
+
`--route`:
|
|
156
|
+
`path` で辿る最小 DSL です。
|
|
157
|
+
|
|
158
|
+
- `case CMD_HOGE`
|
|
159
|
+
- `case CMD_HOGE > if ret == OK`
|
|
160
|
+
- `case CMD_HOGE > else if errno == EINT`
|
|
161
|
+
- `default`
|
|
162
|
+
- `else`
|
|
163
|
+
|
|
164
|
+
## Limitations
|
|
165
|
+
|
|
166
|
+
- 対象は C/C++ のみです
|
|
167
|
+
- 入力は単一ファイルのみです
|
|
168
|
+
- 出力形式は text のみです
|
|
169
|
+
- 入力文字コードは UTF-8 前提です
|
|
170
|
+
- `.h` は現状 C 扱いです
|
|
171
|
+
- `--route` は `case` / `default` / `if` / `else` / `else if` のみ対応です
|
|
172
|
+
- `--track` は名前解決やスコープ解析を行いません
|
|
173
|
+
- ループ経路、`goto` 横断、意味解析、CFG 構築、JSON 出力は対象外です
|
|
174
|
+
|
|
175
|
+
## Examples
|
|
176
|
+
|
|
177
|
+
リポジトリには `examples/demo.c` を含めています。
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
cift function --name FooFunction --source examples/demo.c
|
|
181
|
+
cift flow --function FooFunction --source examples/demo.c --track 'ctx->state'
|
|
182
|
+
cift path --function FooFunction --source examples/demo.c --route 'case CMD_LOOP > if ret == OK'
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Development
|
|
186
|
+
|
|
187
|
+
開発者向け文書は `docs/` にまとめています。
|
|
188
|
+
|
|
189
|
+
- [docs/overview.md](/home/tkenji/Repos/cifter/docs/overview.md)
|
|
190
|
+
- [docs/cli.md](/home/tkenji/Repos/cifter/docs/cli.md)
|
|
191
|
+
- [docs/output-format.md](/home/tkenji/Repos/cifter/docs/output-format.md)
|
|
192
|
+
- [docs/pipeline.md](/home/tkenji/Repos/cifter/docs/pipeline.md)
|
|
193
|
+
- [docs/data-model.md](/home/tkenji/Repos/cifter/docs/data-model.md)
|
|
194
|
+
- [docs/architecture.md](/home/tkenji/Repos/cifter/docs/architecture.md)
|
|
195
|
+
- [docs/release.md](/home/tkenji/Repos/cifter/docs/release.md)
|
|
196
|
+
|
|
197
|
+
仕様の正本は `docs/specs/` にあります。
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
MIT License で配布します。詳細は `LICENSE` を参照してください。
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# cifter
|
|
2
|
+
|
|
3
|
+
`cifter` は、C/C++ の関数実装を機械的かつ高速に抽出する CLI です。
|
|
4
|
+
`tree-sitter` で構文を捉え、行番号付き text として返します。重い意味解析や LLM 連携は行いません。
|
|
5
|
+
|
|
6
|
+
## 概要
|
|
7
|
+
|
|
8
|
+
- 単一の `--source` ファイルから抽出します
|
|
9
|
+
- 公開サブコマンドは `function` / `flow` / `path` の 3 つです
|
|
10
|
+
- 出力は元ソースと対応付け可能な行番号付き text です
|
|
11
|
+
- `-D NAME[=VALUE]` により条件分岐前処理を評価できます
|
|
12
|
+
|
|
13
|
+
## Why cifter
|
|
14
|
+
|
|
15
|
+
- 関数全体をそのまま抜き出したい
|
|
16
|
+
- 分岐の骨格だけを見たい
|
|
17
|
+
- 特定の route だけを細く追いたい
|
|
18
|
+
- 元の行番号を失わずにレビューや調査へ貼りたい
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
PyPI から install:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
python -m pip install cifter-cli
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
最小確認:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
cift --help
|
|
32
|
+
python -m cifter --help
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
GitHub Release の `wheel` / `sdist` から install することもできます。
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
python -m pip install ./cifter_cli-0.1.0-py3-none-any.whl
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
開発用:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
uv sync
|
|
45
|
+
uv run cift --help
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
サンプルソース:
|
|
51
|
+
|
|
52
|
+
```c
|
|
53
|
+
int FooFunction(int x)
|
|
54
|
+
{
|
|
55
|
+
if (x > 0) {
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
関数全体を抽出:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
cift function --name FooFunction --source foo.c
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
出力:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
1: int FooFunction(int x)
|
|
73
|
+
2: {
|
|
74
|
+
3: if (x > 0) {
|
|
75
|
+
4: return 1;
|
|
76
|
+
5: }
|
|
77
|
+
6:
|
|
78
|
+
7: return 0;
|
|
79
|
+
8: }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Commands
|
|
83
|
+
|
|
84
|
+
`function`:
|
|
85
|
+
指定した関数の実装全体をそのまま抽出します。レビュー対象の最小切り出しに向きます。
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
cift function --name FooFunction --source examples/demo.c
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`flow`:
|
|
92
|
+
制御構造の骨格だけを残します。`--track` を付けると、完全一致したアクセスパスを含む文を追加保持します。
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
cift flow --function FooFunction --source examples/demo.c --track state
|
|
96
|
+
cift flow --function FooFunction --source examples/demo.c --track 'ctx->state'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`path`:
|
|
100
|
+
指定した route だけを細く抽出します。親構造は残し、route 終端に達したコンテナでは後続の通常文も残します。
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
cift path --function FooFunction --source examples/demo.c --route 'case CMD_HOGE > if ret == OK'
|
|
104
|
+
cift path --function FooFunction --source examples/demo.c --route 'case CMD_HOGE > else if errno == EINT'
|
|
105
|
+
cift path --function ElseRoute --source examples/demo.c --route 'else'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Preprocessor / Track / Route
|
|
109
|
+
|
|
110
|
+
`-D`:
|
|
111
|
+
条件分岐前処理の評価に使うマクロを追加します。
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
cift function --name FooFunction --source examples/demo.c -D DEF_FOO -D ENABLE_BAR=1
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`--track`:
|
|
118
|
+
`flow` で保持したいアクセスパスです。構文上の完全一致だけを扱います。
|
|
119
|
+
|
|
120
|
+
- `state`
|
|
121
|
+
- `ctx->state`
|
|
122
|
+
- `a->b.c`
|
|
123
|
+
|
|
124
|
+
`--route`:
|
|
125
|
+
`path` で辿る最小 DSL です。
|
|
126
|
+
|
|
127
|
+
- `case CMD_HOGE`
|
|
128
|
+
- `case CMD_HOGE > if ret == OK`
|
|
129
|
+
- `case CMD_HOGE > else if errno == EINT`
|
|
130
|
+
- `default`
|
|
131
|
+
- `else`
|
|
132
|
+
|
|
133
|
+
## Limitations
|
|
134
|
+
|
|
135
|
+
- 対象は C/C++ のみです
|
|
136
|
+
- 入力は単一ファイルのみです
|
|
137
|
+
- 出力形式は text のみです
|
|
138
|
+
- 入力文字コードは UTF-8 前提です
|
|
139
|
+
- `.h` は現状 C 扱いです
|
|
140
|
+
- `--route` は `case` / `default` / `if` / `else` / `else if` のみ対応です
|
|
141
|
+
- `--track` は名前解決やスコープ解析を行いません
|
|
142
|
+
- ループ経路、`goto` 横断、意味解析、CFG 構築、JSON 出力は対象外です
|
|
143
|
+
|
|
144
|
+
## Examples
|
|
145
|
+
|
|
146
|
+
リポジトリには `examples/demo.c` を含めています。
|
|
147
|
+
|
|
148
|
+
```sh
|
|
149
|
+
cift function --name FooFunction --source examples/demo.c
|
|
150
|
+
cift flow --function FooFunction --source examples/demo.c --track 'ctx->state'
|
|
151
|
+
cift path --function FooFunction --source examples/demo.c --route 'case CMD_LOOP > if ret == OK'
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Development
|
|
155
|
+
|
|
156
|
+
開発者向け文書は `docs/` にまとめています。
|
|
157
|
+
|
|
158
|
+
- [docs/overview.md](/home/tkenji/Repos/cifter/docs/overview.md)
|
|
159
|
+
- [docs/cli.md](/home/tkenji/Repos/cifter/docs/cli.md)
|
|
160
|
+
- [docs/output-format.md](/home/tkenji/Repos/cifter/docs/output-format.md)
|
|
161
|
+
- [docs/pipeline.md](/home/tkenji/Repos/cifter/docs/pipeline.md)
|
|
162
|
+
- [docs/data-model.md](/home/tkenji/Repos/cifter/docs/data-model.md)
|
|
163
|
+
- [docs/architecture.md](/home/tkenji/Repos/cifter/docs/architecture.md)
|
|
164
|
+
- [docs/release.md](/home/tkenji/Repos/cifter/docs/release.md)
|
|
165
|
+
|
|
166
|
+
仕様の正本は `docs/specs/` にあります。
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT License で配布します。詳細は `LICENSE` を参照してください。
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "cifter-cli"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "C/C++ の関数実装を抽出する軽量 CLI"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "t-kenji", email = "protect.2501@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
keywords = [
|
|
13
|
+
"c",
|
|
14
|
+
"c++",
|
|
15
|
+
"cpp",
|
|
16
|
+
"cli",
|
|
17
|
+
"tree-sitter",
|
|
18
|
+
"source-extraction",
|
|
19
|
+
"static-analysis",
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 3 - Alpha",
|
|
23
|
+
"Environment :: Console",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"License :: OSI Approved :: MIT License",
|
|
26
|
+
"Operating System :: OS Independent",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: C",
|
|
30
|
+
"Programming Language :: C++",
|
|
31
|
+
"Topic :: Software Development",
|
|
32
|
+
]
|
|
33
|
+
dependencies = [
|
|
34
|
+
"pcpp>=1.30",
|
|
35
|
+
"tree-sitter>=0.25.2",
|
|
36
|
+
"tree-sitter-c>=0.24.1",
|
|
37
|
+
"tree-sitter-cpp>=0.23.4",
|
|
38
|
+
"typer>=0.24.1",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.urls]
|
|
42
|
+
Homepage = "https://github.com/t-kenji/cifter"
|
|
43
|
+
Repository = "https://github.com/t-kenji/cifter"
|
|
44
|
+
Issues = "https://github.com/t-kenji/cifter/issues"
|
|
45
|
+
Changelog = "https://github.com/t-kenji/cifter/blob/main/CHANGELOG.md"
|
|
46
|
+
|
|
47
|
+
[project.scripts]
|
|
48
|
+
cift = "cifter:main"
|
|
49
|
+
|
|
50
|
+
[build-system]
|
|
51
|
+
requires = ["uv_build>=0.10.10,<0.11.0"]
|
|
52
|
+
build-backend = "uv_build"
|
|
53
|
+
|
|
54
|
+
[tool.uv.build-backend]
|
|
55
|
+
module-name = "cifter"
|
|
56
|
+
|
|
57
|
+
[dependency-groups]
|
|
58
|
+
dev = [
|
|
59
|
+
"pytest>=9.0.2",
|
|
60
|
+
"ruff>=0.15.6",
|
|
61
|
+
"ty>=0.0.23",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.ruff]
|
|
65
|
+
target-version = "py312"
|
|
66
|
+
line-length = 100
|
|
67
|
+
exclude = ["examples/*"]
|
|
68
|
+
|
|
69
|
+
[tool.ruff.lint]
|
|
70
|
+
extend-select = [
|
|
71
|
+
"B",
|
|
72
|
+
"I",
|
|
73
|
+
"RUF",
|
|
74
|
+
"SIM",
|
|
75
|
+
"UP"
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[tool.ty.rules]
|
|
79
|
+
possibly-unresolved-reference = "warn"
|
|
80
|
+
|
|
81
|
+
[tool.ty.environment]
|
|
82
|
+
python-version = "3.12"
|
|
83
|
+
root = ["./src"]
|
|
84
|
+
|
|
85
|
+
[tool.ty.src]
|
|
86
|
+
exclude = ["examples/*"]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Annotated
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from cifter.errors import CiftError
|
|
10
|
+
from cifter.extract_flow import extract_flow
|
|
11
|
+
from cifter.extract_function import extract_function
|
|
12
|
+
from cifter.extract_path import extract_path
|
|
13
|
+
from cifter.model import TrackPath
|
|
14
|
+
from cifter.parser import parse_source
|
|
15
|
+
from cifter.render import render_result
|
|
16
|
+
|
|
17
|
+
app = typer.Typer(no_args_is_help=True, help="C/C++ の関数実装を抽出する CLI")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main() -> None:
|
|
21
|
+
app()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
SourceOption = Annotated[
|
|
25
|
+
Path,
|
|
26
|
+
typer.Option(
|
|
27
|
+
"--source",
|
|
28
|
+
exists=True,
|
|
29
|
+
file_okay=True,
|
|
30
|
+
dir_okay=False,
|
|
31
|
+
readable=True,
|
|
32
|
+
resolve_path=True,
|
|
33
|
+
help="解析するソースファイル",
|
|
34
|
+
),
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@app.command("function")
|
|
39
|
+
def function_command(
|
|
40
|
+
name: Annotated[str, typer.Option("--name", help="抽出する関数名")],
|
|
41
|
+
source: SourceOption,
|
|
42
|
+
defines: Annotated[
|
|
43
|
+
list[str] | None,
|
|
44
|
+
typer.Option("--define", "-D", help="条件分岐評価に使うマクロ定義"),
|
|
45
|
+
] = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
_run(lambda: render_result(extract_function(parse_source(source, defines or []), name)))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@app.command("flow")
|
|
51
|
+
def flow_command(
|
|
52
|
+
function_name: Annotated[str, typer.Option("--function", help="対象関数名")],
|
|
53
|
+
source: SourceOption,
|
|
54
|
+
track: Annotated[list[str], typer.Option("--track", help="保持するアクセスパス")] | None = None,
|
|
55
|
+
defines: Annotated[
|
|
56
|
+
list[str] | None,
|
|
57
|
+
typer.Option("--define", "-D", help="条件分岐評価に使うマクロ定義"),
|
|
58
|
+
] = None,
|
|
59
|
+
) -> None:
|
|
60
|
+
def task() -> str:
|
|
61
|
+
parsed = parse_source(source, defines or [])
|
|
62
|
+
tracks = tuple(TrackPath.parse(value) for value in (track or []))
|
|
63
|
+
return render_result(extract_flow(parsed, function_name, tracks))
|
|
64
|
+
|
|
65
|
+
_run(task)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@app.command("path")
|
|
69
|
+
def path_command(
|
|
70
|
+
function_name: Annotated[str, typer.Option("--function", help="対象関数名")],
|
|
71
|
+
source: SourceOption,
|
|
72
|
+
route: Annotated[str, typer.Option("--route", help="抽出する経路 DSL")],
|
|
73
|
+
defines: Annotated[
|
|
74
|
+
list[str] | None,
|
|
75
|
+
typer.Option("--define", "-D", help="条件分岐評価に使うマクロ定義"),
|
|
76
|
+
] = None,
|
|
77
|
+
) -> None:
|
|
78
|
+
def task() -> str:
|
|
79
|
+
parsed = parse_source(source, defines or [])
|
|
80
|
+
return render_result(extract_path(parsed, function_name, route))
|
|
81
|
+
|
|
82
|
+
_run(task)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _run(task: Callable[[], str]) -> None:
|
|
86
|
+
try:
|
|
87
|
+
typer.echo(task())
|
|
88
|
+
except CiftError as error:
|
|
89
|
+
typer.echo(error.message, err=True)
|
|
90
|
+
raise typer.Exit(code=1) from error
|