@opensip-cli/lang-cpp 0.1.0
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.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +31 -0
- package/dist/__tests__/adapter.test.d.ts +2 -0
- package/dist/__tests__/adapter.test.d.ts.map +1 -0
- package/dist/__tests__/adapter.test.js +166 -0
- package/dist/__tests__/adapter.test.js.map +1 -0
- package/dist/__tests__/strip.test.d.ts +2 -0
- package/dist/__tests__/strip.test.d.ts.map +1 -0
- package/dist/__tests__/strip.test.js +79 -0
- package/dist/__tests__/strip.test.js.map +1 -0
- package/dist/adapter.d.ts +19 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +26 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/strip.d.ts +5 -0
- package/dist/strip.d.ts.map +1 -0
- package/dist/strip.js +173 -0
- package/dist/strip.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
OpenSIP CLI
|
|
2
|
+
Copyright 2026 opensip-ai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
+
this software except in compliance with the License. A copy of the License is
|
|
6
|
+
included in the LICENSE file and is also available at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!-- Generated by scripts/build-package-readmes.mjs — do not edit by hand.
|
|
2
|
+
Change the package's "description" (or the generator template) and run
|
|
3
|
+
`pnpm docs:readmes`. CI enforces sync via `pnpm docs:readmes:check`. -->
|
|
4
|
+
|
|
5
|
+
# @opensip-cli/lang-cpp
|
|
6
|
+
|
|
7
|
+
> C/C++ language adapter for opensip-cli (clang-tidy backed)
|
|
8
|
+
|
|
9
|
+
This is an **internal library** of the opensip-cli toolkit. It is published so the CLI and tools can depend on it; most users will not install it directly.
|
|
10
|
+
|
|
11
|
+
Part of [**opensip-cli**](https://github.com/opensip-ai/opensip-cli) — an open-source codebase-analysis toolkit: fitness checks (`fit`), static call-graph analysis (`graph`), and simulation (`sim`).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Most users install the CLI, which bundles the first-party tools:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -fsSL https://opensip.ai/cli/install.sh | bash
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This package is published for the CLI and advanced plugin authors; most users should not install `@opensip-cli/lang-cpp` directly.
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
- 📚 Project docs: https://opensip.ai/docs/opensip-cli/
|
|
26
|
+
- 🧭 Package catalog (what every package does): https://github.com/opensip-ai/opensip-cli/blob/v0.1.0/docs/public/70-reference/02-package-catalog.md
|
|
27
|
+
- 📦 Source: https://github.com/opensip-ai/opensip-cli/tree/v0.1.0/packages/languages/lang-cpp
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
Apache-2.0 © opensip-ai
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/adapter.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { cppAdapter } from '../adapter.js';
|
|
3
|
+
import { stripComments, stripStrings } from '../strip.js';
|
|
4
|
+
describe('cppAdapter', () => {
|
|
5
|
+
it('declares the expected identity and extensions', () => {
|
|
6
|
+
expect(cppAdapter.id).toBe('cpp');
|
|
7
|
+
expect(cppAdapter.fileExtensions).toContain('.cpp');
|
|
8
|
+
expect(cppAdapter.fileExtensions).toContain('.h');
|
|
9
|
+
expect(cppAdapter.aliases).toContain('c');
|
|
10
|
+
});
|
|
11
|
+
it('parse() returns null (C/C++ uses clang-tidy CommandConfig instead)', () => {
|
|
12
|
+
expect(cppAdapter.parse('int main() { return 0; }', 'foo.cpp')).toBeNull();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
describe('cpp stripStrings', () => {
|
|
16
|
+
it('replaces regular string content', () => {
|
|
17
|
+
const src = 'std::string s = "hello";';
|
|
18
|
+
const out = stripStrings(src);
|
|
19
|
+
expect(out.length).toBe(src.length);
|
|
20
|
+
expect(out).not.toContain('hello');
|
|
21
|
+
expect(out).toContain('std::string s =');
|
|
22
|
+
});
|
|
23
|
+
it('handles backslash escapes inside strings', () => {
|
|
24
|
+
const src = String.raw `X = "needle\"middle"; Y`;
|
|
25
|
+
const out = stripStrings(src);
|
|
26
|
+
expect(out.length).toBe(src.length);
|
|
27
|
+
expect(out).not.toContain('needle');
|
|
28
|
+
expect(out).not.toContain('middle');
|
|
29
|
+
expect(out).toContain('X = ');
|
|
30
|
+
expect(out).toContain('; Y');
|
|
31
|
+
});
|
|
32
|
+
it('handles raw strings R"(...)"', () => {
|
|
33
|
+
const src = 'auto s = R"(raw "with quotes" inside)";';
|
|
34
|
+
const out = stripStrings(src);
|
|
35
|
+
expect(out.length).toBe(src.length);
|
|
36
|
+
expect(out).not.toContain('raw');
|
|
37
|
+
expect(out).not.toContain('quotes');
|
|
38
|
+
});
|
|
39
|
+
it('handles raw strings with delimiter R"d(...)d"', () => {
|
|
40
|
+
const src = 'auto s = R"xx(payload)xx";';
|
|
41
|
+
const out = stripStrings(src);
|
|
42
|
+
expect(out.length).toBe(src.length);
|
|
43
|
+
expect(out).not.toContain('payload');
|
|
44
|
+
});
|
|
45
|
+
it('preserves char literals', () => {
|
|
46
|
+
const src = "char c = 'x';";
|
|
47
|
+
const out = stripStrings(src);
|
|
48
|
+
expect(out).toBe(src);
|
|
49
|
+
});
|
|
50
|
+
it('preserves single-char baseline (length-preserving)', () => {
|
|
51
|
+
const src = "char c = 'A';";
|
|
52
|
+
const out = stripStrings(src);
|
|
53
|
+
expect(out).toBe(src);
|
|
54
|
+
expect(out.length).toBe(src.length);
|
|
55
|
+
});
|
|
56
|
+
it('preserves u8 char-literal prefix (C++17)', () => {
|
|
57
|
+
// F5a: u8'a' is a valid C++17 char literal opener.
|
|
58
|
+
const src = "char c = u8'a';";
|
|
59
|
+
const out = stripStrings(src);
|
|
60
|
+
expect(out).toBe(src);
|
|
61
|
+
expect(out.length).toBe(src.length);
|
|
62
|
+
});
|
|
63
|
+
it('preserves u, U, and L char-literal prefixes', () => {
|
|
64
|
+
const srcs = ["char16_t c = u'a';", "char32_t c = U'a';", "wchar_t c = L'a';"];
|
|
65
|
+
for (const src of srcs) {
|
|
66
|
+
const out = stripStrings(src);
|
|
67
|
+
expect(out).toBe(src);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
it('handles char literals with long unicode escape sequences', () => {
|
|
71
|
+
// F5b: previously `maxScan = startQuote + 8` cut off literals like
|
|
72
|
+
// '\u{1F600}' (10 chars between quotes) — should now scan to the
|
|
73
|
+
// closing quote.
|
|
74
|
+
const src = String.raw `char32_t c = '\u{1F600}'; int x = 1;`;
|
|
75
|
+
const out = stripStrings(src);
|
|
76
|
+
expect(out.length).toBe(src.length);
|
|
77
|
+
// The char literal should be preserved as code, and the trailing
|
|
78
|
+
// `int x = 1;` must remain intact (i.e. not consumed as if the
|
|
79
|
+
// literal were unterminated).
|
|
80
|
+
expect(out).toContain('int x = 1;');
|
|
81
|
+
expect(out).toContain(String.raw `'\u{1F600}'`);
|
|
82
|
+
});
|
|
83
|
+
// F12: identifier-prefix collisions in matchStringPrefix /
|
|
84
|
+
// matchCharLiteralPrefix must be anchored against identifier boundaries.
|
|
85
|
+
// `abcL"foo"` is `abcL` (identifier) followed by `"foo"` (regular string);
|
|
86
|
+
// the `L` must NOT be treated as a wide-string prefix mid-identifier.
|
|
87
|
+
it('does not mis-treat `L` as a wide-string prefix mid-identifier', () => {
|
|
88
|
+
const src = 'auto x = abcL"foo";';
|
|
89
|
+
const out = stripStrings(src);
|
|
90
|
+
expect(out.length).toBe(src.length);
|
|
91
|
+
// `foo` is inside a regular string; stripped.
|
|
92
|
+
expect(out).not.toContain('foo');
|
|
93
|
+
// The `abcL` identifier survives as code.
|
|
94
|
+
expect(out).toContain('abcL');
|
|
95
|
+
});
|
|
96
|
+
it('does not mis-treat `L` as a char-literal prefix mid-identifier', () => {
|
|
97
|
+
// `nameL'a'` should be parsed as the identifier `nameL` followed by
|
|
98
|
+
// a bare apostrophe (malformed); the bare apostrophe falls through
|
|
99
|
+
// to the bare-`'` branch (charPrefixLen === 0). The output is
|
|
100
|
+
// byte-equivalent to the input today regardless of the anchor (char
|
|
101
|
+
// literals are preserved as code), but anchoring matters for any
|
|
102
|
+
// future check that asks "where are the char-literal regions?".
|
|
103
|
+
const src = "nameL'a' + 1;";
|
|
104
|
+
const out = stripStrings(src);
|
|
105
|
+
expect(out.length).toBe(src.length);
|
|
106
|
+
// The identifier survives, and the trailing `+ 1;` is still code.
|
|
107
|
+
expect(out).toContain('nameL');
|
|
108
|
+
expect(out).toContain('+ 1;');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe('cpp stripComments line-continuation (F3)', () => {
|
|
112
|
+
it('continues a // line comment past a backslash-newline splice', () => {
|
|
113
|
+
// F3: in C/C++, `\<newline>` is a line splice (translation phase 2).
|
|
114
|
+
// The // comment should swallow the second physical line as well,
|
|
115
|
+
// and scanning should resume at `int x = 1;`.
|
|
116
|
+
const src = '// comment continued\\\nstill comment\nint x = 1;';
|
|
117
|
+
const out = stripComments(src);
|
|
118
|
+
expect(out.length).toBe(src.length);
|
|
119
|
+
// Both halves of the spliced comment should be stripped.
|
|
120
|
+
expect(out).not.toContain('comment continued');
|
|
121
|
+
expect(out).not.toContain('still comment');
|
|
122
|
+
// Code after the splice survives.
|
|
123
|
+
expect(out).toContain('int x = 1;');
|
|
124
|
+
});
|
|
125
|
+
it('does not over-extend when there is no backslash before the newline', () => {
|
|
126
|
+
const src = '// comment\nint x = 1;';
|
|
127
|
+
const out = stripComments(src);
|
|
128
|
+
expect(out.length).toBe(src.length);
|
|
129
|
+
expect(out).not.toContain('comment');
|
|
130
|
+
expect(out).toContain('int x = 1;');
|
|
131
|
+
});
|
|
132
|
+
it('preserves newlines inside multi-line raw strings', () => {
|
|
133
|
+
const src = 'auto s = R"(\nline1\nline2\n)";';
|
|
134
|
+
const out = stripStrings(src);
|
|
135
|
+
expect(out.length).toBe(src.length);
|
|
136
|
+
expect(out.split('\n').length).toBe(src.split('\n').length);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe('cpp stripComments', () => {
|
|
140
|
+
it('replaces line comments', () => {
|
|
141
|
+
const src = 'int x = 1; // line comment';
|
|
142
|
+
const out = stripComments(src);
|
|
143
|
+
expect(out.length).toBe(src.length);
|
|
144
|
+
expect(out).not.toContain('line comment');
|
|
145
|
+
expect(out).toContain('int x = 1;');
|
|
146
|
+
});
|
|
147
|
+
it('replaces block comments (no nesting)', () => {
|
|
148
|
+
const src = 'int x = /* block */ 1;';
|
|
149
|
+
const out = stripComments(src);
|
|
150
|
+
expect(out.length).toBe(src.length);
|
|
151
|
+
expect(out).not.toContain('block');
|
|
152
|
+
});
|
|
153
|
+
it('treats /* /* */ as one block comment ending at first */', () => {
|
|
154
|
+
const src = 'int x = /* outer /* inner */ remaining */ 1;';
|
|
155
|
+
const out = stripComments(src);
|
|
156
|
+
// Block comment is /* outer /* inner */ — `remaining */ 1;` survives as code
|
|
157
|
+
expect(out).toContain('remaining');
|
|
158
|
+
});
|
|
159
|
+
it('also strips strings', () => {
|
|
160
|
+
const src = '// hello\nauto s = "secret";';
|
|
161
|
+
const out = stripComments(src);
|
|
162
|
+
expect(out).not.toContain('secret');
|
|
163
|
+
expect(out).not.toContain('hello');
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=adapter.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.test.js","sourceRoot":"","sources":["../../src/__tests__/adapter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACpD,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oEAAoE,EAAE,GAAG,EAAE;QAC5E,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,0BAA0B,EAAE,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,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ip.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { stripStrings, stripComments } from '../strip.js';
|
|
3
|
+
describe('stripStrings (C/C++)', () => {
|
|
4
|
+
it('strips double-quoted strings', () => {
|
|
5
|
+
const out = stripStrings('const char* s = "hello";');
|
|
6
|
+
expect(out).not.toContain('hello');
|
|
7
|
+
});
|
|
8
|
+
it('strips raw string literals', () => {
|
|
9
|
+
const src = 'const char* s = R"foo(line1\nline2)foo";';
|
|
10
|
+
const out = stripStrings(src);
|
|
11
|
+
expect(out).not.toContain('line1');
|
|
12
|
+
expect(out).not.toContain('line2');
|
|
13
|
+
});
|
|
14
|
+
it('strips wide-char and Unicode-prefixed strings (L"...", u"...", U"...", u8"...")', () => {
|
|
15
|
+
expect(stripStrings('auto a = L"wide";')).not.toContain('wide');
|
|
16
|
+
expect(stripStrings('auto b = u"u16";')).not.toContain('u16');
|
|
17
|
+
expect(stripStrings('auto c = U"u32";')).not.toContain('u32');
|
|
18
|
+
expect(stripStrings('auto d = u8"u8s";')).not.toContain('u8s');
|
|
19
|
+
});
|
|
20
|
+
it('handles unterminated raw string', () => {
|
|
21
|
+
const out = stripStrings('const char* s = R"foo(unterminated');
|
|
22
|
+
expect(out).toContain('const char* s = ');
|
|
23
|
+
expect(out).not.toContain('unterminated');
|
|
24
|
+
});
|
|
25
|
+
it('handles unterminated regular string', () => {
|
|
26
|
+
const out = stripStrings('const char* s = "unterminated');
|
|
27
|
+
expect(out).toContain('const char* s = ');
|
|
28
|
+
});
|
|
29
|
+
it('preserves char literals', () => {
|
|
30
|
+
expect(stripStrings("char c = 'a';")).toContain("'a'");
|
|
31
|
+
});
|
|
32
|
+
it('handles char literal that overruns the 8-char scan window', () => {
|
|
33
|
+
// The scan looks at most 8 chars for the closing quote; an oversized
|
|
34
|
+
// char literal exits the scan fallback and just advances by one.
|
|
35
|
+
const out = stripStrings("char c = 'this_is_too_long");
|
|
36
|
+
expect(out).toContain('char c = ');
|
|
37
|
+
});
|
|
38
|
+
it('passes through code with no strings unchanged', () => {
|
|
39
|
+
const code = 'int main() { return 0; }';
|
|
40
|
+
expect(stripStrings(code)).toBe(code);
|
|
41
|
+
});
|
|
42
|
+
it('preserves wide-char and Unicode-prefixed char literals', () => {
|
|
43
|
+
expect(stripStrings("auto a = L'A';")).toContain("L'A'");
|
|
44
|
+
expect(stripStrings("auto b = u'B';")).toContain("u'B'");
|
|
45
|
+
expect(stripStrings("auto c = U'C';")).toContain("U'C'");
|
|
46
|
+
});
|
|
47
|
+
it('preserves char literal with escape sequence', () => {
|
|
48
|
+
expect(stripStrings(String.raw `char c = '\n';`)).toContain(String.raw `'\n'`);
|
|
49
|
+
});
|
|
50
|
+
it('handles u8R, uR, UR, LR raw-string prefixes', () => {
|
|
51
|
+
const variants = [
|
|
52
|
+
'auto s = u8R"foo(payload)foo";',
|
|
53
|
+
'auto s = uR"foo(payload)foo";',
|
|
54
|
+
'auto s = UR"foo(payload)foo";',
|
|
55
|
+
'auto s = LR"foo(payload)foo";',
|
|
56
|
+
];
|
|
57
|
+
for (const src of variants) {
|
|
58
|
+
const out = stripStrings(src);
|
|
59
|
+
expect(out).not.toContain('payload');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('stripComments (C/C++)', () => {
|
|
64
|
+
it('strips line comments', () => {
|
|
65
|
+
const out = stripComments('int x = 1; // comment');
|
|
66
|
+
expect(out).not.toContain('comment');
|
|
67
|
+
});
|
|
68
|
+
it('strips block comments', () => {
|
|
69
|
+
const out = stripComments('int x = 1; /* hidden */ int y = 2;');
|
|
70
|
+
expect(out).not.toContain('hidden');
|
|
71
|
+
expect(out).toContain('int x = 1;');
|
|
72
|
+
expect(out).toContain('int y = 2;');
|
|
73
|
+
});
|
|
74
|
+
it('handles unterminated block comment', () => {
|
|
75
|
+
const out = stripComments('int x = 1; /* oops');
|
|
76
|
+
expect(out).toContain('int x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,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,GAAG,GAAG,aAAa,CAAC,oBAAoB,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { LanguageAdapter } from '@opensip-cli/core';
|
|
2
|
+
/**
|
|
3
|
+
* C/C++ adapter. parse() returns null intentionally — for C/C++ we
|
|
4
|
+
* rely on external tools (clang-tidy) for AST analysis. Checks targeting
|
|
5
|
+
* C/C++ files use the CommandConfig pattern in @opensip-cli/checks-cpp.
|
|
6
|
+
*
|
|
7
|
+
* stripStrings/stripComments are still useful for regex-based checks
|
|
8
|
+
* that want to ignore string/comment content.
|
|
9
|
+
*
|
|
10
|
+
* Aliases note: `cpp` is the canonical id; `c` is the convenience
|
|
11
|
+
* alias (covers C-only files via `.c` / `.h` extensions). The unquoted
|
|
12
|
+
* `c++` form is omitted from the alias list because it is a YAML
|
|
13
|
+
* quoting footgun — users who write `languages: [c++]` unquoted hit a
|
|
14
|
+
* parser error, while `languages: [cpp]` and `languages: [c]` always
|
|
15
|
+
* round-trip cleanly.
|
|
16
|
+
*/
|
|
17
|
+
export declare const cppAdapter: LanguageAdapter<null>;
|
|
18
|
+
export declare const adapters: readonly [LanguageAdapter<null, unknown>];
|
|
19
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,EAAE,eAAe,CAAC,IAAI,CAO5C,CAAC;AAEF,eAAO,MAAM,QAAQ,2CAAwB,CAAC"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { stripComments, stripStrings } from './strip.js';
|
|
2
|
+
/**
|
|
3
|
+
* C/C++ adapter. parse() returns null intentionally — for C/C++ we
|
|
4
|
+
* rely on external tools (clang-tidy) for AST analysis. Checks targeting
|
|
5
|
+
* C/C++ files use the CommandConfig pattern in @opensip-cli/checks-cpp.
|
|
6
|
+
*
|
|
7
|
+
* stripStrings/stripComments are still useful for regex-based checks
|
|
8
|
+
* that want to ignore string/comment content.
|
|
9
|
+
*
|
|
10
|
+
* Aliases note: `cpp` is the canonical id; `c` is the convenience
|
|
11
|
+
* alias (covers C-only files via `.c` / `.h` extensions). The unquoted
|
|
12
|
+
* `c++` form is omitted from the alias list because it is a YAML
|
|
13
|
+
* quoting footgun — users who write `languages: [c++]` unquoted hit a
|
|
14
|
+
* parser error, while `languages: [cpp]` and `languages: [c]` always
|
|
15
|
+
* round-trip cleanly.
|
|
16
|
+
*/
|
|
17
|
+
export const cppAdapter = {
|
|
18
|
+
id: 'cpp',
|
|
19
|
+
fileExtensions: ['.cpp', '.cc', '.cxx', '.c++', '.hpp', '.hh', '.hxx', '.h', '.c'],
|
|
20
|
+
aliases: ['c'],
|
|
21
|
+
parse: () => null,
|
|
22
|
+
stripStrings,
|
|
23
|
+
stripComments,
|
|
24
|
+
};
|
|
25
|
+
export const adapters = [cppAdapter];
|
|
26
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAIzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,UAAU,GAA0B;IAC/C,EAAE,EAAE,KAAK;IACT,cAAc,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC;IAClF,OAAO,EAAE,CAAC,GAAG,CAAC;IACd,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;IACjB,YAAY;IACZ,aAAa;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,UAAU,CAAU,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/strip.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Returns C/C++ source with every string-literal region blanked out. */
|
|
2
|
+
export declare const stripStrings: (content: string) => string;
|
|
3
|
+
/** Returns C/C++ source with every string-literal AND comment region blanked out. */
|
|
4
|
+
export declare const stripComments: (content: string) => string;
|
|
5
|
+
//# sourceMappingURL=strip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAmLA,yEAAyE;AACzE,eAAO,MAAM,YAAY,6BAAwB,CAAC;AAClD,qFAAqF;AACrF,eAAO,MAAM,aAAa,6BAAyB,CAAC"}
|
package/dist/strip.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// C/C++ string and comment stripping.
|
|
2
|
+
//
|
|
3
|
+
// Recognizes:
|
|
4
|
+
// - Line comments (//) and block comments (NON-nesting)
|
|
5
|
+
// - Regular strings ("...") with backslash escapes
|
|
6
|
+
// - Raw strings (R"delim(...)delim", and prefixed forms u8R, uR, UR, LR)
|
|
7
|
+
// - Char literals ('a', '\n', u8'a', u'a', U'a', L'a', preserved as code)
|
|
8
|
+
// - Line splices in `//` line comments: a `\` immediately before `\n`
|
|
9
|
+
// continues the comment onto the next physical line (per C/C++ phase 2
|
|
10
|
+
// translation).
|
|
11
|
+
//
|
|
12
|
+
// NOTE: Broader preprocessor awareness (`#if 0` masking, macro splices in
|
|
13
|
+
// non-comment contexts, full phase-2 line-splicing across all token types)
|
|
14
|
+
// is intentionally OUT OF SCOPE for this strip primitive. We only honor
|
|
15
|
+
// `\<newline>` inside `//` line comments, which is the most common case
|
|
16
|
+
// where ignoring it produces visibly wrong output. See the lang-cpp
|
|
17
|
+
// architecture audit (F3, deferred items).
|
|
18
|
+
import { isIdentChar, makeStripper, scanBlockCommentNonNesting, scanCharLiteral, scanLineComment, scanRegularString, } from '@opensip-cli/core';
|
|
19
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity -- C++ has the largest token-set among the C-family packs (line/block comments, raw strings with optional encoding prefix, regular strings with optional encoding prefix, char literals with five opener forms); splitting the dispatch into per-token helpers would force shared mutable state across them and hurt readability. Suppression measured: 37/15 cognitive-complexity at this writing.
|
|
20
|
+
function scan(src) {
|
|
21
|
+
const stringRegions = [];
|
|
22
|
+
const commentRegions = [];
|
|
23
|
+
const len = src.length;
|
|
24
|
+
let i = 0;
|
|
25
|
+
while (i < len) {
|
|
26
|
+
const c = src[i];
|
|
27
|
+
const next = src[i + 1];
|
|
28
|
+
// Line comment: // ... \n
|
|
29
|
+
// Honor line splices: `\<newline>` continues the comment onto the next line.
|
|
30
|
+
if (c === '/' && next === '/') {
|
|
31
|
+
const start = i;
|
|
32
|
+
const lc = scanLineComment(src, i, { allowLineContinuation: true });
|
|
33
|
+
i = lc.end;
|
|
34
|
+
commentRegions.push({ start, end: i });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// Block comment: /* ... */ (no nesting in C/C++)
|
|
38
|
+
if (c === '/' && next === '*') {
|
|
39
|
+
const start = i;
|
|
40
|
+
const bc = scanBlockCommentNonNesting(src, i);
|
|
41
|
+
i = bc.end;
|
|
42
|
+
commentRegions.push({ start, end: i });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// Raw string with optional encoding prefix: R"d-char-seq(...)d-char-seq"
|
|
46
|
+
// Prefixes: R, u8R, uR, UR, LR
|
|
47
|
+
{
|
|
48
|
+
const rawPrefixLen = matchRawStringPrefix(src, i);
|
|
49
|
+
if (rawPrefixLen > 0) {
|
|
50
|
+
// After the prefix should be R" then delimiter then (
|
|
51
|
+
// Position immediately after prefix
|
|
52
|
+
const afterPrefix = i + rawPrefixLen;
|
|
53
|
+
if (src[afterPrefix] === '"') {
|
|
54
|
+
// Read d-char-seq up to (
|
|
55
|
+
let j = afterPrefix + 1;
|
|
56
|
+
const delimStart = j;
|
|
57
|
+
while (j < len && src[j] !== '(' && src[j] !== '"')
|
|
58
|
+
j++;
|
|
59
|
+
if (src[j] === '(') {
|
|
60
|
+
const delim = src.slice(delimStart, j);
|
|
61
|
+
const closingPattern = ')' + delim + '"';
|
|
62
|
+
// content starts at j+1, ends at start of closingPattern
|
|
63
|
+
const contentStart = j + 1;
|
|
64
|
+
const closeIdx = src.indexOf(closingPattern, contentStart);
|
|
65
|
+
if (closeIdx === -1) {
|
|
66
|
+
// Unterminated raw string — record what we have
|
|
67
|
+
stringRegions.push({ start: contentStart, end: len });
|
|
68
|
+
i = len;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
stringRegions.push({ start: contentStart, end: closeIdx });
|
|
72
|
+
i = closeIdx + closingPattern.length;
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Fall through — wasn't actually a raw string
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Regular string with optional encoding prefix: u8"...", u"...", U"...", L"..."
|
|
81
|
+
if (c === '"' || matchStringPrefix(src, i)) {
|
|
82
|
+
const prefixLen = c === '"' ? 0 : matchStringPrefix(src, i);
|
|
83
|
+
const quotePos = i + prefixLen;
|
|
84
|
+
if (src[quotePos] === '"') {
|
|
85
|
+
const result = scanRegularString(src, quotePos);
|
|
86
|
+
stringRegions.push({ start: quotePos + 1, end: result.contentEnd });
|
|
87
|
+
i = result.next;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Char literal: '...' — preserve (don't strip)
|
|
92
|
+
// Openers: ', L', u', U', u8' (C++17). Order matters: u8' must be
|
|
93
|
+
// checked before u' since 'u8' is a 2-char prefix.
|
|
94
|
+
{
|
|
95
|
+
const charPrefixLen = matchCharLiteralPrefix(src, i);
|
|
96
|
+
if (charPrefixLen >= 0) {
|
|
97
|
+
const startQuote = i + charPrefixLen;
|
|
98
|
+
// Scan the body from the opening apostrophe via the shared helper.
|
|
99
|
+
// Use a generous cap (12) so unicode escapes like '\u{1F600}'
|
|
100
|
+
// (10 chars including quotes) close cleanly. Branch order is
|
|
101
|
+
// load-bearing — see core's scanCharLiteral docstring.
|
|
102
|
+
// Scan past the literal (or, on overflow/unterminated, past the
|
|
103
|
+
// opening apostrophe so we don't loop). The shared helper returns
|
|
104
|
+
// `start + 1` on overflow — that's already the bail-out we want
|
|
105
|
+
// when no closing quote is found within the cap.
|
|
106
|
+
const result = scanCharLiteral(src, startQuote, { maxScan: 12 });
|
|
107
|
+
i = result.end;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
i++;
|
|
112
|
+
}
|
|
113
|
+
return { stringRegions, commentRegions };
|
|
114
|
+
}
|
|
115
|
+
/** Returns prefix length if src[i..] starts with a raw-string prefix (R, u8R, uR, UR, LR). 0 otherwise. */
|
|
116
|
+
function matchRawStringPrefix(src, i) {
|
|
117
|
+
if (src[i] === 'R')
|
|
118
|
+
return 1;
|
|
119
|
+
if (src[i] === 'u' && src[i + 1] === '8' && src[i + 2] === 'R')
|
|
120
|
+
return 3;
|
|
121
|
+
if ((src[i] === 'u' || src[i] === 'U' || src[i] === 'L') && src[i + 1] === 'R')
|
|
122
|
+
return 2;
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns prefix length if src[i..] starts with a regular-string prefix
|
|
127
|
+
* (u8, u, U, L). 0 otherwise.
|
|
128
|
+
*
|
|
129
|
+
* Anchored against identifier boundaries: a candidate prefix only counts
|
|
130
|
+
* if the character before `i` is not an identifier character (lang-cpp
|
|
131
|
+
* F12). Without this anchor, source like `abcL"foo"` would get the `L"`
|
|
132
|
+
* mis-recognized as a wide-string opener mid-identifier.
|
|
133
|
+
*/
|
|
134
|
+
function matchStringPrefix(src, i) {
|
|
135
|
+
if (i > 0 && isIdentChar(src[i - 1]))
|
|
136
|
+
return 0;
|
|
137
|
+
if (src[i] === 'u' && src[i + 1] === '8')
|
|
138
|
+
return 2;
|
|
139
|
+
if (src[i] === 'u' || src[i] === 'U' || src[i] === 'L')
|
|
140
|
+
return 1;
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns the length of the char-literal opener prefix at src[i..] (i.e. the
|
|
145
|
+
* number of chars before the opening `'`), or -1 if there is no char-literal
|
|
146
|
+
* opener at this position.
|
|
147
|
+
*
|
|
148
|
+
* Recognized openers: `'` (0), `L'` / `u'` / `U'` (1), `u8'` (2).
|
|
149
|
+
* Order matters: u8' must be checked before u'.
|
|
150
|
+
*
|
|
151
|
+
* Anchored against identifier boundaries (lang-cpp F12): a non-bare
|
|
152
|
+
* apostrophe candidate (i.e. one preceded by `L`/`u`/`U`/`u8`) only
|
|
153
|
+
* counts if the character before `i` is not an identifier character.
|
|
154
|
+
* The bare-apostrophe case (`src[i] === "'"`) is unaffected — `'` is
|
|
155
|
+
* never an identifier character.
|
|
156
|
+
*/
|
|
157
|
+
function matchCharLiteralPrefix(src, i) {
|
|
158
|
+
if (src[i] === "'")
|
|
159
|
+
return 0;
|
|
160
|
+
if (i > 0 && isIdentChar(src[i - 1]))
|
|
161
|
+
return -1;
|
|
162
|
+
if (src[i] === 'u' && src[i + 1] === '8' && src[i + 2] === "'")
|
|
163
|
+
return 2;
|
|
164
|
+
if ((src[i] === 'L' || src[i] === 'u' || src[i] === 'U') && src[i + 1] === "'")
|
|
165
|
+
return 1;
|
|
166
|
+
return -1;
|
|
167
|
+
}
|
|
168
|
+
const stripper = makeStripper(scan);
|
|
169
|
+
/** Returns C/C++ source with every string-literal region blanked out. */
|
|
170
|
+
export const stripStrings = stripper.stripStrings;
|
|
171
|
+
/** Returns C/C++ source with every string-literal AND comment region blanked out. */
|
|
172
|
+
export const stripComments = stripper.stripComments;
|
|
173
|
+
//# sourceMappingURL=strip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,EAAE;AACF,cAAc;AACd,wDAAwD;AACxD,mDAAmD;AACnD,yEAAyE;AACzE,0EAA0E;AAC1E,sEAAsE;AACtE,yEAAyE;AACzE,kBAAkB;AAClB,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,wEAAwE;AACxE,wEAAwE;AACxE,oEAAoE;AACpE,2CAA2C;AAE3C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,eAAe,EACf,eAAe,EACf,iBAAiB,GAGlB,MAAM,mB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AW,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;IAChD,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC;IACzE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC;IACzF,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAED,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AACpC,yEAAyE;AACzE,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;AAClD,qFAAqF;AACrF,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opensip-cli/lang-cpp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "C/C++ language adapter for opensip-cli (clang-tidy backed)",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"opensip-cli",
|
|
8
|
+
"static-analysis",
|
|
9
|
+
"code-quality",
|
|
10
|
+
"parser",
|
|
11
|
+
"ast",
|
|
12
|
+
"tree-sitter",
|
|
13
|
+
"cpp",
|
|
14
|
+
"c++"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/opensip-ai/opensip-cli.git",
|
|
19
|
+
"directory": "packages/languages/lang-cpp"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/opensip-ai/opensip-cli",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/opensip-ai/opensip-cli/issues"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"NOTICE"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@opensip-cli/core": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^24.13.2",
|
|
41
|
+
"vitest": "^4.1.8"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc",
|
|
45
|
+
"test": "vitest run --passWithNoTests",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"clean": "rm -rf dist"
|
|
48
|
+
}
|
|
49
|
+
}
|