• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aas-core-works / aas-core-codegen / 23051946462

13 Mar 2026 12:59PM UTC coverage: 83.657% (+1.2%) from 82.428%
23051946462

push

github

web-flow
Turn on coveralls (#596)

The site coveralls.io was down so we had to turn off the coverage
upload temporarily.

30831 of 36854 relevant lines covered (83.66%)

3.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.52
/aas_core_codegen/cpp/main.py
1
"""Generate C++ code to handle models based on the meta-model."""
2
import pathlib
4✔
3
from typing import TextIO, Sequence, Tuple, Callable, Optional, List
4✔
4

5
from aas_core_codegen import run, intermediate, specific_implementations
4✔
6
from aas_core_codegen.common import Stripped, Error
4✔
7
from aas_core_codegen.cpp import lib as cpp_lib, tests as cpp_tests
4✔
8

9

10
def execute(context: run.Context, stdout: TextIO, stderr: TextIO) -> int:
4✔
11
    """Generate the code."""
12
    verified_ir_table, errors = cpp_lib.verify_for_types(
4✔
13
        symbol_table=context.symbol_table
14
    )
15

16
    assert verified_ir_table is not None
4✔
17

18
    unsupported_contracts_errors = (
4✔
19
        intermediate.errors_if_contracts_for_functions_or_methods_defined(
20
            verified_ir_table
21
        )
22
    )
23
    if unsupported_contracts_errors is not None:
4✔
24
        run.write_error_report(
×
25
            message=f"We do not support pre and post-conditions and snapshots "
26
            f"at the moment. Please notify the developers if you need this "
27
            f"feature (based on meta-model {context.model_path})",
28
            errors=[
29
                context.lineno_columner.error_message(error)
30
                for error in unsupported_contracts_errors
31
            ],
32
            stderr=stderr,
33
        )
34
        return 1
×
35

36
    unsupported_methods_errors = (
4✔
37
        intermediate.errors_if_non_implementation_specific_methods(verified_ir_table)
38
    )
39
    if unsupported_methods_errors is not None:
4✔
40
        run.write_error_report(
×
41
            message=f"We added some support for understood methods already and keep "
42
            f"maintaining it as it is only a matter of time when we will "
43
            f"introduce their transpilation. Introducing them after the fact "
44
            f"would have been much more difficult.\n"
45
            f"\n"
46
            f"At the given moment, however, we deliberately focus only on "
47
            f"implementation-specific methods. "
48
            f"(based on meta-model {context.model_path})",
49
            errors=[
50
                context.lineno_columner.error_message(error)
51
                for error in unsupported_methods_errors
52
            ],
53
            stderr=stderr,
54
        )
55
        return 1
×
56

57
    # region Namespace
58

59
    namespace_key = specific_implementations.ImplementationKey("namespace.txt")
4✔
60
    namespace_text = context.spec_impls.get(namespace_key, None)
4✔
61
    if namespace_text is None:
4✔
62
        stderr.write(f"The namespace snippet is missing: {namespace_key}\n")
×
63
        return 1
×
64

65
    library_namespace = Stripped(namespace_text.strip())
4✔
66

67
    # endregion
68

69
    try:
4✔
70
        context.output_dir.mkdir(exist_ok=True, parents=True)
4✔
71
    except Exception as exception:
×
72
        stderr.write(
×
73
            f"Failed to create the output directory {context.output_dir}: {exception}"
74
        )
75
        return 1
×
76

77
    src_dir = pathlib.Path("src")
4✔
78
    assert not src_dir.is_absolute()
4✔
79

80
    include_dir = pathlib.Path("include") / library_namespace.replace("::", "/")
4✔
81
    assert not include_dir.is_absolute()
4✔
82

83
    test_dir = pathlib.Path("test")
4✔
84
    assert not test_dir.is_absolute()
4✔
85

86
    rel_paths_generators: Sequence[
4✔
87
        Tuple[pathlib.Path, Callable[[], Tuple[Optional[str], Optional[List[Error]]]]]
88
    ] = [
89
        (
90
            include_dir / "common.hpp",
91
            lambda: (
92
                cpp_lib.generate_common_header(library_namespace=library_namespace),
93
                None,
94
            ),
95
        ),
96
        (
97
            src_dir / "common.cpp",
98
            lambda: (
99
                cpp_lib.generate_common_implementation(
100
                    library_namespace=library_namespace
101
                ),
102
                None,
103
            ),
104
        ),
105
        (
106
            include_dir / "constants.hpp",
107
            lambda: cpp_lib.generate_constants_header(
108
                symbol_table=context.symbol_table, library_namespace=library_namespace
109
            ),
110
        ),
111
        (
112
            src_dir / "constants.cpp",
113
            lambda: cpp_lib.generate_constants_implementation(
114
                symbol_table=context.symbol_table, library_namespace=library_namespace
115
            ),
116
        ),
117
        (
118
            include_dir / "enhancing.hpp",
119
            lambda: cpp_lib.generate_enhancing_header(
120
                symbol_table=context.symbol_table, library_namespace=library_namespace
121
            ),
122
        ),
123
        (
124
            include_dir / "iteration.hpp",
125
            lambda: cpp_lib.generate_iteration_header(
126
                symbol_table=context.symbol_table, library_namespace=library_namespace
127
            ),
128
        ),
129
        (
130
            src_dir / "iteration.cpp",
131
            lambda: cpp_lib.generate_iteration_implementation(
132
                symbol_table=context.symbol_table, library_namespace=library_namespace
133
            ),
134
        ),
135
        (
136
            include_dir / "jsonization.hpp",
137
            lambda: (
138
                cpp_lib.generate_jsonization_header(
139
                    symbol_table=verified_ir_table, library_namespace=library_namespace
140
                ),
141
                None,
142
            ),
143
        ),
144
        (
145
            src_dir / "jsonization.cpp",
146
            lambda: cpp_lib.generate_jsonization_implementation(
147
                symbol_table=context.symbol_table,
148
                spec_impls=context.spec_impls,
149
                library_namespace=library_namespace,
150
            ),
151
        ),
152
        (
153
            include_dir / "pattern.hpp",
154
            lambda: (
155
                cpp_lib.generate_pattern_header(
156
                    symbol_table=context.symbol_table,
157
                    library_namespace=library_namespace,
158
                ),
159
                None,
160
            ),
161
        ),
162
        (
163
            src_dir / "pattern.cpp",
164
            lambda: cpp_lib.generate_pattern_implementation(
165
                symbol_table=context.symbol_table,
166
                library_namespace=library_namespace,
167
            ),
168
        ),
169
        (
170
            include_dir / "revm.hpp",
171
            lambda: (
172
                cpp_lib.generate_revm_header(library_namespace=library_namespace),
173
                None,
174
            ),
175
        ),
176
        (
177
            src_dir / "revm.cpp",
178
            lambda: (
179
                cpp_lib.generate_revm_implementation(
180
                    library_namespace=library_namespace,
181
                ),
182
                None,
183
            ),
184
        ),
185
        (
186
            include_dir / "stringification.hpp",
187
            lambda: (
188
                cpp_lib.generate_stringification_header(
189
                    symbol_table=context.symbol_table,
190
                    library_namespace=library_namespace,
191
                ),
192
                None,
193
            ),
194
        ),
195
        (
196
            src_dir / "stringification.cpp",
197
            lambda: (
198
                cpp_lib.generate_stringification_implementation(
199
                    symbol_table=context.symbol_table,
200
                    library_namespace=library_namespace,
201
                ),
202
                None,
203
            ),
204
        ),
205
        (
206
            include_dir / "types.hpp",
207
            lambda: cpp_lib.generate_types_header(
208
                symbol_table=verified_ir_table,
209
                library_namespace=library_namespace,
210
            ),
211
        ),
212
        (
213
            src_dir / "types.cpp",
214
            lambda: cpp_lib.generate_types_implementation(
215
                symbol_table=context.symbol_table,
216
                spec_impls=context.spec_impls,
217
                library_namespace=library_namespace,
218
            ),
219
        ),
220
        (
221
            include_dir / "verification.hpp",
222
            lambda: cpp_lib.generate_verification_header(
223
                symbol_table=verified_ir_table,
224
                spec_impls=context.spec_impls,
225
                library_namespace=library_namespace,
226
            ),
227
        ),
228
        (
229
            src_dir / "verification.cpp",
230
            lambda: cpp_lib.generate_verification_implementation(
231
                symbol_table=context.symbol_table,
232
                spec_impls=context.spec_impls,
233
                library_namespace=library_namespace,
234
            ),
235
        ),
236
        (
237
            include_dir / "visitation.hpp",
238
            lambda: (
239
                cpp_lib.generate_visitation_header(
240
                    symbol_table=verified_ir_table, library_namespace=library_namespace
241
                ),
242
                None,
243
            ),
244
        ),
245
        (
246
            src_dir / "visitation.cpp",
247
            lambda: (
248
                cpp_lib.generate_visitation_implementation(
249
                    symbol_table=verified_ir_table, library_namespace=library_namespace
250
                ),
251
                None,
252
            ),
253
        ),
254
        (
255
            include_dir / "wstringification.hpp",
256
            lambda: (
257
                cpp_lib.generate_wstringification_header(
258
                    symbol_table=context.symbol_table,
259
                    library_namespace=library_namespace,
260
                ),
261
                None,
262
            ),
263
        ),
264
        (
265
            src_dir / "wstringification.cpp",
266
            lambda: (
267
                cpp_lib.generate_wstringification_implementation(
268
                    symbol_table=context.symbol_table,
269
                    library_namespace=library_namespace,
270
                ),
271
                None,
272
            ),
273
        ),
274
        (
275
            include_dir / "xmlization.hpp",
276
            lambda: (
277
                cpp_lib.generate_xmlization_header(
278
                    symbol_table=verified_ir_table, library_namespace=library_namespace
279
                ),
280
                None,
281
            ),
282
        ),
283
        (
284
            src_dir / "xmlization.cpp",
285
            lambda: cpp_lib.generate_xmlization_implementation(
286
                symbol_table=context.symbol_table,
287
                spec_impls=context.spec_impls,
288
                library_namespace=library_namespace,
289
            ),
290
        ),
291
        (
292
            test_dir / "common.hpp",
293
            lambda: (
294
                cpp_tests.generate_common_header(library_namespace=library_namespace),
295
                None,
296
            ),
297
        ),
298
        (
299
            test_dir / "common.cpp",
300
            lambda: (
301
                cpp_tests.generate_common_implementation(
302
                    library_namespace=library_namespace
303
                ),
304
                None,
305
            ),
306
        ),
307
        (
308
            test_dir / "common_examples.hpp",
309
            lambda: (
310
                cpp_tests.generate_common_examples_header(
311
                    symbol_table=context.symbol_table,
312
                    library_namespace=library_namespace,
313
                ),
314
                None,
315
            ),
316
        ),
317
        (
318
            test_dir / "common_examples.cpp",
319
            lambda: (
320
                cpp_tests.generate_common_examples_implementation(
321
                    symbol_table=context.symbol_table,
322
                    library_namespace=library_namespace,
323
                ),
324
                None,
325
            ),
326
        ),
327
        (
328
            test_dir / "common_jsonization.hpp",
329
            lambda: (
330
                cpp_tests.generate_common_jsonization_header(
331
                    library_namespace=library_namespace
332
                ),
333
                None,
334
            ),
335
        ),
336
        (
337
            test_dir / "common_jsonization.cpp",
338
            lambda: (
339
                cpp_tests.generate_common_jsonization_implementation(
340
                    library_namespace=library_namespace
341
                ),
342
                None,
343
            ),
344
        ),
345
        (
346
            test_dir / "common_xmlization.hpp",
347
            lambda: (
348
                cpp_tests.generate_common_xmlization_header(
349
                    library_namespace=library_namespace
350
                ),
351
                None,
352
            ),
353
        ),
354
        (
355
            test_dir / "common_xmlization.cpp",
356
            lambda: (
357
                cpp_tests.generate_common_xmlization_implementation(
358
                    library_namespace=library_namespace
359
                ),
360
                None,
361
            ),
362
        ),
363
        (
364
            test_dir / "test_descent_and_descent_once.cpp",
365
            lambda: (
366
                cpp_tests.generate_test_descent_and_descent_once_implementation(
367
                    symbol_table=context.symbol_table,
368
                    library_namespace=library_namespace,
369
                ),
370
                None,
371
            ),
372
        ),
373
        (
374
            test_dir / "test_jsonization_dispatch.cpp",
375
            lambda: (
376
                cpp_tests.generate_test_jsonization_dispatch_implementation(
377
                    symbol_table=context.symbol_table,
378
                    library_namespace=library_namespace,
379
                ),
380
                None,
381
            ),
382
        ),
383
        (
384
            test_dir / "test_jsonization_of_concrete_classes.cpp",
385
            lambda: (
386
                cpp_tests.generate_test_jsonization_of_concrete_classes_implementation(
387
                    symbol_table=context.symbol_table,
388
                    library_namespace=library_namespace,
389
                ),
390
                None,
391
            ),
392
        ),
393
        (
394
            test_dir / "test_revm.cpp",
395
            lambda: (
396
                cpp_tests.generate_test_revm_implementation(
397
                    library_namespace=library_namespace
398
                ),
399
                None,
400
            ),
401
        ),
402
        (
403
            test_dir / "test_stringification_base64.cpp",
404
            lambda: (
405
                cpp_tests.generate_test_stringification_base64_implementation(
406
                    library_namespace=library_namespace,
407
                ),
408
                None,
409
            ),
410
        ),
411
        (
412
            test_dir / "test_stringification_of_enums.cpp",
413
            lambda: (
414
                cpp_tests.generate_test_stringification_of_enums_implementation(
415
                    symbol_table=context.symbol_table,
416
                    library_namespace=library_namespace,
417
                ),
418
                None,
419
            ),
420
        ),
421
        (
422
            test_dir / "test_verification.cpp",
423
            lambda: (
424
                cpp_tests.generate_test_verification_implementation(
425
                    symbol_table=context.symbol_table,
426
                    library_namespace=library_namespace,
427
                ),
428
                None,
429
            ),
430
        ),
431
        (
432
            test_dir / "test_wstringification_of_enums.cpp",
433
            lambda: (
434
                cpp_tests.generate_test_wstringification_of_enums_implementation(
435
                    symbol_table=context.symbol_table,
436
                    library_namespace=library_namespace,
437
                ),
438
                None,
439
            ),
440
        ),
441
        (
442
            test_dir / "test_xmlization_dispatch.cpp",
443
            lambda: (
444
                cpp_tests.generate_test_xmlization_dispatch_implementation(
445
                    symbol_table=context.symbol_table,
446
                    library_namespace=library_namespace,
447
                ),
448
                None,
449
            ),
450
        ),
451
        (
452
            test_dir / "test_xmlization_of_concrete_classes.cpp",
453
            lambda: (
454
                cpp_tests.generate_test_xmlization_of_concrete_classes_implementation(
455
                    symbol_table=context.symbol_table,
456
                    library_namespace=library_namespace,
457
                ),
458
                None,
459
            ),
460
        ),
461
        (
462
            test_dir / "test_x_or_default.cpp",
463
            lambda: (
464
                cpp_tests.generate_test_x_or_default_implementation(
465
                    symbol_table=context.symbol_table,
466
                    library_namespace=library_namespace,
467
                ),
468
                None,
469
            ),
470
        ),
471
    ]
472

473
    for rel_path, generator_func in rel_paths_generators:
4✔
474
        assert not rel_path.is_absolute()
4✔
475

476
        code, errors = generator_func()
4✔
477

478
        if errors is not None:
4✔
479
            run.write_error_report(
×
480
                message=f"Failed to generate {rel_path} "
481
                f"based on {context.model_path}",
482
                errors=[
483
                    context.lineno_columner.error_message(error) for error in errors
484
                ],
485
                stderr=stderr,
486
            )
487
            return 1
×
488

489
        assert code is not None
4✔
490

491
        pth = context.output_dir / rel_path
4✔
492

493
        try:
4✔
494
            pth.parent.mkdir(parents=True, exist_ok=True)
4✔
495
        except Exception as exception:
×
496
            run.write_error_report(
×
497
                message=f"Failed to create the directory {pth.parent}",
498
                errors=[str(exception)],
499
                stderr=stderr,
500
            )
501
            return 1
×
502

503
        try:
4✔
504
            pth.write_text(code, encoding="utf-8")
4✔
505
        except Exception as exception:
×
506
            run.write_error_report(
×
507
                message=f"Failed to write to {pth}",
508
                errors=[str(exception)],
509
                stderr=stderr,
510
            )
511
            return 1
×
512

513
    stdout.write(f"Code generated to: {context.output_dir}\n")
4✔
514
    return 0
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc