pycforge 0.15.2__py3-none-any.whl
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.
- pycforge/__init__.py +8 -0
- pycforge/__main__.py +2 -0
- pycforge/_version.py +1 -0
- pycforge/converter/__init__.py +0 -0
- pycforge/converter/analysis/__init__.py +5 -0
- pycforge/converter/analysis/functions.py +723 -0
- pycforge/converter/analysis/model.py +158 -0
- pycforge/converter/analysis/planning.py +464 -0
- pycforge/converter/analysis/stage.py +1976 -0
- pycforge/converter/analysis/symbols.py +237 -0
- pycforge/converter/analysis/validation.py +2166 -0
- pycforge/converter/c_output/__init__.py +2 -0
- pycforge/converter/c_output/conformance.py +297 -0
- pycforge/converter/c_output/renderer.py +220 -0
- pycforge/converter/conditional_regions/__init__.py +71 -0
- pycforge/converter/conditional_regions/analysis.py +481 -0
- pycforge/converter/conditional_regions/lowering.py +579 -0
- pycforge/converter/conditional_regions/model.py +243 -0
- pycforge/converter/conditional_regions/validation.py +690 -0
- pycforge/converter/containers/__init__.py +19 -0
- pycforge/converter/containers/analysis.py +542 -0
- pycforge/converter/containers/lowering.py +290 -0
- pycforge/converter/containers/model.py +146 -0
- pycforge/converter/contracts/__init__.py +0 -0
- pycforge/converter/contracts/configuration.py +178 -0
- pycforge/converter/contracts/identifiers.py +68 -0
- pycforge/converter/contracts/versions.py +71 -0
- pycforge/converter/core/__init__.py +0 -0
- pycforge/converter/core/artifact_io.py +87 -0
- pycforge/converter/core/cancellation.py +7 -0
- pycforge/converter/core/canonicalization.py +254 -0
- pycforge/converter/core/context.py +13 -0
- pycforge/converter/core/diagnostics.py +95 -0
- pycforge/converter/core/enums.py +23 -0
- pycforge/converter/core/fingerprint.py +22 -0
- pycforge/converter/core/pipeline.py +8 -0
- pycforge/converter/core/progress.py +25 -0
- pycforge/converter/core/request.py +50 -0
- pycforge/converter/core/resource_policy.py +31 -0
- pycforge/converter/core/result.py +23 -0
- pycforge/converter/core/serialization.py +36 -0
- pycforge/converter/core/stage.py +10 -0
- pycforge/converter/core/stage_artifact.py +80 -0
- pycforge/converter/core/stage_outcome.py +15 -0
- pycforge/converter/decision_trace/__init__.py +0 -0
- pycforge/converter/decision_trace/recorder.py +52 -0
- pycforge/converter/facade.py +459 -0
- pycforge/converter/frontend/__init__.py +4 -0
- pycforge/converter/frontend/normalizer.py +59 -0
- pycforge/converter/frontend/parser.py +20 -0
- pycforge/converter/frontend/source_document.py +93 -0
- pycforge/converter/frontend/stages.py +518 -0
- pycforge/converter/frontend/validation.py +76 -0
- pycforge/converter/io/__init__.py +0 -0
- pycforge/converter/io/atomic_writer.py +33 -0
- pycforge/converter/ir/__init__.py +1 -0
- pycforge/converter/ir/c_ir/__init__.py +4 -0
- pycforge/converter/ir/c_ir/builder.py +26 -0
- pycforge/converter/ir/c_ir/model.py +318 -0
- pycforge/converter/ir/c_ir/serialization.py +88 -0
- pycforge/converter/ir/c_ir/validation.py +834 -0
- pycforge/converter/ir/python_ir/__init__.py +17 -0
- pycforge/converter/ir/python_ir/nodes.py +86 -0
- pycforge/converter/keyword_calls/__init__.py +68 -0
- pycforge/converter/keyword_calls/analysis.py +458 -0
- pycforge/converter/keyword_calls/lowering.py +271 -0
- pycforge/converter/keyword_calls/model.py +304 -0
- pycforge/converter/keyword_calls/validation.py +802 -0
- pycforge/converter/keyword_only_calls/__init__.py +68 -0
- pycforge/converter/keyword_only_calls/analysis.py +640 -0
- pycforge/converter/keyword_only_calls/lowering.py +376 -0
- pycforge/converter/keyword_only_calls/model.py +328 -0
- pycforge/converter/keyword_only_calls/validation.py +1357 -0
- pycforge/converter/lowering.py +1000 -0
- pycforge/converter/modules/__init__.py +13 -0
- pycforge/converter/modules/analysis.py +1250 -0
- pycforge/converter/modules/lowering.py +200 -0
- pycforge/converter/modules/model.py +73 -0
- pycforge/converter/modules/stage.py +192 -0
- pycforge/converter/numeric_semantics/__init__.py +23 -0
- pycforge/converter/numeric_semantics/analysis.py +420 -0
- pycforge/converter/numeric_semantics/lowering.py +153 -0
- pycforge/converter/numeric_semantics/model.py +123 -0
- pycforge/converter/records/__init__.py +34 -0
- pycforge/converter/records/analysis.py +1394 -0
- pycforge/converter/records/lowering.py +393 -0
- pycforge/converter/records/model.py +319 -0
- pycforge/converter/rules/__init__.py +3 -0
- pycforge/converter/support_templates/__init__.py +49 -0
- pycforge/converter/support_templates/assembly.py +106 -0
- pycforge/converter/support_templates/factories.py +348 -0
- pycforge/converter/support_templates/model.py +159 -0
- pycforge/converter/support_templates/registry.py +388 -0
- pycforge/converter/telemetry/__init__.py +0 -0
- pycforge/converter/telemetry/sink.py +39 -0
- pycforge/ide/__init__.py +19 -0
- pycforge/ide/__main__.py +5 -0
- pycforge/ide/_worker_event_codec.py +276 -0
- pycforge/ide/_worker_protocol_json.py +197 -0
- pycforge/ide/_worker_protocol_types.py +90 -0
- pycforge/ide/_worker_request_codec.py +200 -0
- pycforge/ide/_worker_request_data.py +260 -0
- pycforge/ide/_worker_result_data.py +343 -0
- pycforge/ide/action_contract.py +469 -0
- pycforge/ide/action_validation.py +229 -0
- pycforge/ide/command_palette.py +223 -0
- pycforge/ide/controller.py +904 -0
- pycforge/ide/controller_conversion.py +546 -0
- pycforge/ide/controller_io.py +205 -0
- pycforge/ide/editor.py +951 -0
- pycforge/ide/editor_commands_qt.py +274 -0
- pycforge/ide/editor_lexical.py +43 -0
- pycforge/ide/editor_sidebars.py +236 -0
- pycforge/ide/editor_syntax.py +243 -0
- pycforge/ide/find_replace.py +535 -0
- pycforge/ide/icons.py +91 -0
- pycforge/ide/io_service.py +196 -0
- pycforge/ide/model.py +164 -0
- pycforge/ide/panels.py +903 -0
- pycforge/ide/positions.py +220 -0
- pycforge/ide/process_worker.py +130 -0
- pycforge/ide/qt.py +230 -0
- pycforge/ide/qt_actions.py +418 -0
- pycforge/ide/qt_close.py +169 -0
- pycforge/ide/qt_command_palette.py +297 -0
- pycforge/ide/qt_contract.py +220 -0
- pycforge/ide/qt_documents.py +590 -0
- pycforge/ide/qt_editor_buffers.py +113 -0
- pycforge/ide/qt_editor_surfaces.py +112 -0
- pycforge/ide/qt_menus.py +324 -0
- pycforge/ide/qt_projection.py +500 -0
- pycforge/ide/qt_shell.py +348 -0
- pycforge/ide/qt_shell_interactions.py +320 -0
- pycforge/ide/qt_state.py +393 -0
- pycforge/ide/qt_workspace_features.py +398 -0
- pycforge/ide/qt_workspace_navigation.py +208 -0
- pycforge/ide/qt_workspace_observers.py +173 -0
- pycforge/ide/qt_workspace_panels.py +545 -0
- pycforge/ide/qt_workspace_widgets.py +228 -0
- pycforge/ide/resources/icons/about.svg +1 -0
- pycforge/ide/resources/icons/add-document.svg +1 -0
- pycforge/ide/resources/icons/brand-mark.svg +1 -0
- pycforge/ide/resources/icons/bundle-search.svg +1 -0
- pycforge/ide/resources/icons/cancel.svg +1 -0
- pycforge/ide/resources/icons/check.svg +1 -0
- pycforge/ide/resources/icons/chevron-right.svg +1 -0
- pycforge/ide/resources/icons/close.svg +1 -0
- pycforge/ide/resources/icons/collapse-all.svg +1 -0
- pycforge/ide/resources/icons/command-palette.svg +1 -0
- pycforge/ide/resources/icons/convert.svg +1 -0
- pycforge/ide/resources/icons/copy.svg +1 -0
- pycforge/ide/resources/icons/cut.svg +1 -0
- pycforge/ide/resources/icons/decision-trace.svg +1 -0
- pycforge/ide/resources/icons/details.svg +1 -0
- pycforge/ide/resources/icons/diagnostics.svg +1 -0
- pycforge/ide/resources/icons/duplicate-line.svg +1 -0
- pycforge/ide/resources/icons/exit.svg +1 -0
- pycforge/ide/resources/icons/expand-all.svg +1 -0
- pycforge/ide/resources/icons/export.svg +1 -0
- pycforge/ide/resources/icons/find.svg +1 -0
- pycforge/ide/resources/icons/go-to-line.svg +1 -0
- pycforge/ide/resources/icons/go-to-output.svg +1 -0
- pycforge/ide/resources/icons/go-to-source.svg +1 -0
- pycforge/ide/resources/icons/history.svg +1 -0
- pycforge/ide/resources/icons/indent.svg +1 -0
- pycforge/ide/resources/icons/link-c.svg +1 -0
- pycforge/ide/resources/icons/mappings.svg +1 -0
- pycforge/ide/resources/icons/module.svg +1 -0
- pycforge/ide/resources/icons/move-down.svg +1 -0
- pycforge/ide/resources/icons/move-line-down.svg +1 -0
- pycforge/ide/resources/icons/move-line-up.svg +1 -0
- pycforge/ide/resources/icons/move-up.svg +1 -0
- pycforge/ide/resources/icons/next.svg +1 -0
- pycforge/ide/resources/icons/open.svg +1 -0
- pycforge/ide/resources/icons/outdent.svg +1 -0
- pycforge/ide/resources/icons/outline.svg +1 -0
- pycforge/ide/resources/icons/paste.svg +1 -0
- pycforge/ide/resources/icons/previous.svg +1 -0
- pycforge/ide/resources/icons/primary-module.svg +1 -0
- pycforge/ide/resources/icons/redo.svg +1 -0
- pycforge/ide/resources/icons/remove-document.svg +1 -0
- pycforge/ide/resources/icons/replace.svg +1 -0
- pycforge/ide/resources/icons/save-as.svg +1 -0
- pycforge/ide/resources/icons/save.svg +1 -0
- pycforge/ide/resources/icons/select-all.svg +1 -0
- pycforge/ide/resources/icons/settings.svg +1 -0
- pycforge/ide/resources/icons/show-c.svg +1 -0
- pycforge/ide/resources/icons/split-view.svg +1 -0
- pycforge/ide/resources/icons/summary.svg +1 -0
- pycforge/ide/resources/icons/telemetry.svg +1 -0
- pycforge/ide/resources/icons/toggle-comment.svg +1 -0
- pycforge/ide/resources/icons/toggle-fold.svg +1 -0
- pycforge/ide/resources/icons/undo.svg +1 -0
- pycforge/ide/resources/icons/whitespace.svg +1 -0
- pycforge/ide/revisions.py +400 -0
- pycforge/ide/search_service.py +280 -0
- pycforge/ide/session_history.py +150 -0
- pycforge/ide/source_editing.py +417 -0
- pycforge/ide/source_structure.py +558 -0
- pycforge/ide/source_structure_async.py +191 -0
- pycforge/ide/supervisor.py +503 -0
- pycforge/ide/theme.py +119 -0
- pycforge/ide/theme_stylesheet.py +598 -0
- pycforge/ide/theme_workspace_stylesheet.py +155 -0
- pycforge/ide/visual_tokens.py +142 -0
- pycforge/ide/worker_protocol.py +80 -0
- pycforge/ide/workspace_search.py +462 -0
- pycforge/ide/workspace_session.py +256 -0
- pycforge/laboratory/__init__.py +6 -0
- pycforge/laboratory/audits.py +2244 -0
- pycforge/laboratory/checkpoint_e.py +2685 -0
- pycforge/laboratory/cli.py +119 -0
- pycforge/laboratory/exit_codes.py +11 -0
- pycforge/laboratory/keyword_audit.py +661 -0
- pycforge/laboratory/keyword_only_audit.py +481 -0
- pycforge-0.15.2.dist-info/METADATA +209 -0
- pycforge-0.15.2.dist-info/RECORD +221 -0
- pycforge-0.15.2.dist-info/WHEEL +5 -0
- pycforge-0.15.2.dist-info/entry_points.txt +5 -0
- pycforge-0.15.2.dist-info/licenses/LICENSE +674 -0
- pycforge-0.15.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import TypeAlias
|
|
5
|
+
|
|
6
|
+
LEGACY_SCHEMA_VERSION = "c-ir/0.8"
|
|
7
|
+
SCHEMA_VERSION = "c-ir/0.9"
|
|
8
|
+
HELPER_SCHEMA_VERSION = "c-ir/0.10"
|
|
9
|
+
CONTAINER_SCHEMA_VERSION = "c-ir/0.11"
|
|
10
|
+
MODULE_SCHEMA_VERSION = "c-ir/0.12"
|
|
11
|
+
RECORD_SCHEMA_VERSION = "c-ir/0.13"
|
|
12
|
+
NUMERIC_SCHEMA_VERSION = "c-ir/0.14"
|
|
13
|
+
CONDITIONAL_SCHEMA_VERSION = "c-ir/0.14.1"
|
|
14
|
+
KEYWORD_CALL_SCHEMA_VERSION = "c-ir/0.14.2"
|
|
15
|
+
KEYWORD_ONLY_CALL_SCHEMA_VERSION = "c-ir/0.14.3"
|
|
16
|
+
SUPPORTED_SCHEMA_VERSIONS = (
|
|
17
|
+
LEGACY_SCHEMA_VERSION,
|
|
18
|
+
SCHEMA_VERSION,
|
|
19
|
+
HELPER_SCHEMA_VERSION,
|
|
20
|
+
CONTAINER_SCHEMA_VERSION,
|
|
21
|
+
MODULE_SCHEMA_VERSION,
|
|
22
|
+
RECORD_SCHEMA_VERSION,
|
|
23
|
+
NUMERIC_SCHEMA_VERSION,
|
|
24
|
+
CONDITIONAL_SCHEMA_VERSION,
|
|
25
|
+
KEYWORD_CALL_SCHEMA_VERSION,
|
|
26
|
+
KEYWORD_ONLY_CALL_SCHEMA_VERSION,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
class CStorage(str, Enum):
|
|
30
|
+
NONE = "none"
|
|
31
|
+
STATIC = "static"
|
|
32
|
+
EXTERN = "extern"
|
|
33
|
+
|
|
34
|
+
class CQualifier(str, Enum):
|
|
35
|
+
CONST = "const"
|
|
36
|
+
VOLATILE = "volatile"
|
|
37
|
+
|
|
38
|
+
class CUnaryOp(str, Enum):
|
|
39
|
+
NEGATE = "-"
|
|
40
|
+
LOGICAL_NOT = "!"
|
|
41
|
+
BITWISE_NOT = "~"
|
|
42
|
+
ADDRESS_OF = "&"
|
|
43
|
+
DEREFERENCE = "*"
|
|
44
|
+
|
|
45
|
+
class CBinaryOp(str, Enum):
|
|
46
|
+
MULTIPLY = "*"
|
|
47
|
+
DIVIDE = "/"
|
|
48
|
+
REMAINDER = "%"
|
|
49
|
+
ADD = "+"
|
|
50
|
+
SUBTRACT = "-"
|
|
51
|
+
SHIFT_LEFT = "<<"
|
|
52
|
+
SHIFT_RIGHT = ">>"
|
|
53
|
+
LESS = "<"
|
|
54
|
+
LESS_EQUAL = "<="
|
|
55
|
+
GREATER = ">"
|
|
56
|
+
GREATER_EQUAL = ">="
|
|
57
|
+
EQUAL = "=="
|
|
58
|
+
NOT_EQUAL = "!="
|
|
59
|
+
BIT_AND = "&"
|
|
60
|
+
BIT_XOR = "^"
|
|
61
|
+
BIT_OR = "|"
|
|
62
|
+
LOGICAL_AND = "&&"
|
|
63
|
+
LOGICAL_OR = "||"
|
|
64
|
+
|
|
65
|
+
class CMemberAccessMode(str, Enum):
|
|
66
|
+
DIRECT = "direct"
|
|
67
|
+
POINTER = "pointer"
|
|
68
|
+
|
|
69
|
+
@dataclass(frozen=True, slots=True)
|
|
70
|
+
class CProvenance:
|
|
71
|
+
origin_kind: str
|
|
72
|
+
source_document_id: str | None = None
|
|
73
|
+
source_node_ids: tuple[str, ...] = ()
|
|
74
|
+
source_span: dict[str, object] | None = None
|
|
75
|
+
rule_plan_id: str | None = None
|
|
76
|
+
|
|
77
|
+
@dataclass(frozen=True, slots=True)
|
|
78
|
+
class CType:
|
|
79
|
+
base: str
|
|
80
|
+
qualifiers: tuple[CQualifier, ...] = ()
|
|
81
|
+
pointer_depth: int = 0
|
|
82
|
+
array_extents: tuple[int, ...] = ()
|
|
83
|
+
object_const: bool = False
|
|
84
|
+
|
|
85
|
+
@dataclass(frozen=True, slots=True)
|
|
86
|
+
class CIdentifier:
|
|
87
|
+
binding_id: str
|
|
88
|
+
spelling: str
|
|
89
|
+
provenance: CProvenance
|
|
90
|
+
|
|
91
|
+
@dataclass(frozen=True, slots=True)
|
|
92
|
+
class CIntegerLiteral:
|
|
93
|
+
node_id: str
|
|
94
|
+
value: int
|
|
95
|
+
suffix: str = ""
|
|
96
|
+
provenance: CProvenance = CProvenance("synthetic")
|
|
97
|
+
|
|
98
|
+
@dataclass(frozen=True, slots=True)
|
|
99
|
+
class CFloatLiteral:
|
|
100
|
+
node_id: str
|
|
101
|
+
value: float
|
|
102
|
+
provenance: CProvenance
|
|
103
|
+
|
|
104
|
+
@dataclass(frozen=True, slots=True)
|
|
105
|
+
class CBooleanLiteral:
|
|
106
|
+
node_id: str
|
|
107
|
+
value: bool
|
|
108
|
+
provenance: CProvenance
|
|
109
|
+
|
|
110
|
+
@dataclass(frozen=True, slots=True)
|
|
111
|
+
class CStringLiteral:
|
|
112
|
+
node_id: str
|
|
113
|
+
value: str
|
|
114
|
+
encoding: str
|
|
115
|
+
provenance: CProvenance
|
|
116
|
+
|
|
117
|
+
@dataclass(frozen=True, slots=True)
|
|
118
|
+
class CIdentifierRef:
|
|
119
|
+
node_id: str
|
|
120
|
+
binding_id: str
|
|
121
|
+
provenance: CProvenance
|
|
122
|
+
|
|
123
|
+
@dataclass(frozen=True, slots=True)
|
|
124
|
+
class CUnaryExpr:
|
|
125
|
+
node_id: str
|
|
126
|
+
op: CUnaryOp
|
|
127
|
+
operand: "CExpression"
|
|
128
|
+
provenance: CProvenance
|
|
129
|
+
|
|
130
|
+
@dataclass(frozen=True, slots=True)
|
|
131
|
+
class CBinaryExpr:
|
|
132
|
+
node_id: str
|
|
133
|
+
op: CBinaryOp
|
|
134
|
+
left: "CExpression"
|
|
135
|
+
right: "CExpression"
|
|
136
|
+
provenance: CProvenance
|
|
137
|
+
|
|
138
|
+
@dataclass(frozen=True, slots=True)
|
|
139
|
+
class CCallExpr:
|
|
140
|
+
node_id: str
|
|
141
|
+
callee: CIdentifierRef
|
|
142
|
+
arguments: tuple["CExpression", ...]
|
|
143
|
+
provenance: CProvenance
|
|
144
|
+
|
|
145
|
+
@dataclass(frozen=True, slots=True)
|
|
146
|
+
class CInitializerList:
|
|
147
|
+
node_id: str
|
|
148
|
+
elements: tuple["CExpression", ...]
|
|
149
|
+
provenance: CProvenance
|
|
150
|
+
|
|
151
|
+
@dataclass(frozen=True, slots=True)
|
|
152
|
+
class CRecordInitializer:
|
|
153
|
+
node_id: str
|
|
154
|
+
record_type: CType
|
|
155
|
+
elements: tuple["CExpression", ...]
|
|
156
|
+
provenance: CProvenance
|
|
157
|
+
|
|
158
|
+
@dataclass(frozen=True, slots=True)
|
|
159
|
+
class CSubscriptExpr:
|
|
160
|
+
node_id: str
|
|
161
|
+
container: "CExpression"
|
|
162
|
+
index: "CExpression"
|
|
163
|
+
provenance: CProvenance
|
|
164
|
+
|
|
165
|
+
@dataclass(frozen=True, slots=True)
|
|
166
|
+
class CMemberAccessExpr:
|
|
167
|
+
node_id: str
|
|
168
|
+
receiver: "CExpression"
|
|
169
|
+
field_binding_id: str
|
|
170
|
+
mode: CMemberAccessMode
|
|
171
|
+
provenance: CProvenance
|
|
172
|
+
|
|
173
|
+
CExpression: TypeAlias = CIntegerLiteral | CFloatLiteral | CBooleanLiteral | CStringLiteral | CIdentifierRef | CUnaryExpr | CBinaryExpr | CCallExpr | CInitializerList | CRecordInitializer | CSubscriptExpr | CMemberAccessExpr
|
|
174
|
+
|
|
175
|
+
@dataclass(frozen=True, slots=True)
|
|
176
|
+
class CParameter:
|
|
177
|
+
node_id: str
|
|
178
|
+
identifier: CIdentifier
|
|
179
|
+
type_ref: CType
|
|
180
|
+
provenance: CProvenance
|
|
181
|
+
|
|
182
|
+
@dataclass(frozen=True, slots=True)
|
|
183
|
+
class CVariableDeclaration:
|
|
184
|
+
node_id: str
|
|
185
|
+
identifier: CIdentifier
|
|
186
|
+
type_ref: CType
|
|
187
|
+
initializer: CExpression | None
|
|
188
|
+
storage: CStorage
|
|
189
|
+
provenance: CProvenance
|
|
190
|
+
|
|
191
|
+
@dataclass(frozen=True, slots=True)
|
|
192
|
+
class CExpressionStatement:
|
|
193
|
+
node_id: str
|
|
194
|
+
expression: CExpression
|
|
195
|
+
provenance: CProvenance
|
|
196
|
+
|
|
197
|
+
@dataclass(frozen=True, slots=True)
|
|
198
|
+
class CReturnStatement:
|
|
199
|
+
node_id: str
|
|
200
|
+
expression: CExpression | None
|
|
201
|
+
provenance: CProvenance
|
|
202
|
+
|
|
203
|
+
@dataclass(frozen=True, slots=True)
|
|
204
|
+
class CAssignmentStatement:
|
|
205
|
+
node_id: str
|
|
206
|
+
target: CIdentifierRef | CSubscriptExpr | CMemberAccessExpr
|
|
207
|
+
value: CExpression
|
|
208
|
+
provenance: CProvenance
|
|
209
|
+
|
|
210
|
+
@dataclass(frozen=True, slots=True)
|
|
211
|
+
class CIfStatement:
|
|
212
|
+
node_id: str
|
|
213
|
+
condition: CExpression
|
|
214
|
+
then_block: "CBlock"
|
|
215
|
+
else_block: "CBlock | None"
|
|
216
|
+
provenance: CProvenance
|
|
217
|
+
|
|
218
|
+
@dataclass(frozen=True, slots=True)
|
|
219
|
+
class CWhileStatement:
|
|
220
|
+
node_id: str
|
|
221
|
+
condition: CExpression
|
|
222
|
+
body: "CBlock"
|
|
223
|
+
provenance: CProvenance
|
|
224
|
+
|
|
225
|
+
@dataclass(frozen=True, slots=True)
|
|
226
|
+
class CForStatement:
|
|
227
|
+
node_id: str
|
|
228
|
+
initializer: CVariableDeclaration
|
|
229
|
+
condition: CExpression
|
|
230
|
+
update: CAssignmentStatement
|
|
231
|
+
body: "CBlock"
|
|
232
|
+
provenance: CProvenance
|
|
233
|
+
|
|
234
|
+
@dataclass(frozen=True, slots=True)
|
|
235
|
+
class CBreakStatement:
|
|
236
|
+
node_id: str
|
|
237
|
+
provenance: CProvenance
|
|
238
|
+
|
|
239
|
+
@dataclass(frozen=True, slots=True)
|
|
240
|
+
class CContinueStatement:
|
|
241
|
+
node_id: str
|
|
242
|
+
provenance: CProvenance
|
|
243
|
+
|
|
244
|
+
CStatement: TypeAlias = CVariableDeclaration | CExpressionStatement | CReturnStatement | CAssignmentStatement | CIfStatement | CWhileStatement | CForStatement | CBreakStatement | CContinueStatement
|
|
245
|
+
|
|
246
|
+
@dataclass(frozen=True, slots=True)
|
|
247
|
+
class CBlock:
|
|
248
|
+
node_id: str
|
|
249
|
+
statements: tuple[CStatement, ...]
|
|
250
|
+
provenance: CProvenance
|
|
251
|
+
|
|
252
|
+
@dataclass(frozen=True, slots=True)
|
|
253
|
+
class CFunctionDefinition:
|
|
254
|
+
node_id: str
|
|
255
|
+
identifier: CIdentifier
|
|
256
|
+
return_type: CType
|
|
257
|
+
parameters: tuple[CParameter, ...]
|
|
258
|
+
body: CBlock
|
|
259
|
+
storage: CStorage
|
|
260
|
+
provenance: CProvenance
|
|
261
|
+
owner_module_id: str | None = None
|
|
262
|
+
owner_document_id: str | None = None
|
|
263
|
+
bundle_function_ordinal: int | None = None
|
|
264
|
+
|
|
265
|
+
@dataclass(frozen=True, slots=True)
|
|
266
|
+
class CFunctionPrototype:
|
|
267
|
+
node_id: str
|
|
268
|
+
identifier: CIdentifier
|
|
269
|
+
return_type: CType
|
|
270
|
+
parameters: tuple[CParameter, ...]
|
|
271
|
+
storage: CStorage
|
|
272
|
+
provenance: CProvenance
|
|
273
|
+
owner_module_id: str | None = None
|
|
274
|
+
owner_document_id: str | None = None
|
|
275
|
+
bundle_function_ordinal: int | None = None
|
|
276
|
+
|
|
277
|
+
@dataclass(frozen=True, slots=True)
|
|
278
|
+
class CInclude:
|
|
279
|
+
node_id: str
|
|
280
|
+
header: str
|
|
281
|
+
system: bool
|
|
282
|
+
provenance: CProvenance
|
|
283
|
+
|
|
284
|
+
@dataclass(frozen=True, slots=True)
|
|
285
|
+
class CRecordField:
|
|
286
|
+
node_id: str
|
|
287
|
+
identifier: CIdentifier
|
|
288
|
+
type_ref: CType
|
|
289
|
+
provenance: CProvenance
|
|
290
|
+
|
|
291
|
+
@dataclass(frozen=True, slots=True)
|
|
292
|
+
class CRecordDefinition:
|
|
293
|
+
node_id: str
|
|
294
|
+
identifier: CIdentifier
|
|
295
|
+
fields: tuple[CRecordField, ...]
|
|
296
|
+
provenance: CProvenance
|
|
297
|
+
|
|
298
|
+
CExternalDeclaration: TypeAlias = CRecordDefinition | CFunctionPrototype | CFunctionDefinition | CVariableDeclaration
|
|
299
|
+
|
|
300
|
+
@dataclass(frozen=True, slots=True)
|
|
301
|
+
class CModuleManifestEntry:
|
|
302
|
+
module_id: str
|
|
303
|
+
document_id: str
|
|
304
|
+
logical_name: str
|
|
305
|
+
bundle_ordinal: int
|
|
306
|
+
is_primary: bool
|
|
307
|
+
|
|
308
|
+
@dataclass(frozen=True, slots=True)
|
|
309
|
+
class CTranslationUnit:
|
|
310
|
+
schema_version: str
|
|
311
|
+
node_id: str
|
|
312
|
+
target_contract: str
|
|
313
|
+
includes: tuple[CInclude, ...]
|
|
314
|
+
declarations: tuple[CExternalDeclaration, ...]
|
|
315
|
+
provenance: CProvenance
|
|
316
|
+
module_manifest: tuple[CModuleManifestEntry, ...] = ()
|
|
317
|
+
module_order: tuple[str, ...] = ()
|
|
318
|
+
module_dependencies: tuple[tuple[str, str], ...] = ()
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from dataclasses import fields, is_dataclass
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Any
|
|
5
|
+
from .model import (
|
|
6
|
+
CONDITIONAL_SCHEMA_VERSION,
|
|
7
|
+
CONTAINER_SCHEMA_VERSION,
|
|
8
|
+
MODULE_SCHEMA_VERSION,
|
|
9
|
+
NUMERIC_SCHEMA_VERSION,
|
|
10
|
+
RECORD_SCHEMA_VERSION,
|
|
11
|
+
KEYWORD_CALL_SCHEMA_VERSION,
|
|
12
|
+
KEYWORD_ONLY_CALL_SCHEMA_VERSION,
|
|
13
|
+
CTranslationUnit,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
def to_data(value: Any) -> Any:
|
|
17
|
+
if isinstance(value, Enum): return value.value
|
|
18
|
+
if is_dataclass(value):
|
|
19
|
+
return {"kind": type(value).__name__, **{f.name: to_data(getattr(value, f.name)) for f in fields(value)}}
|
|
20
|
+
if isinstance(value, tuple): return [to_data(item) for item in value]
|
|
21
|
+
if isinstance(value, dict): return {str(k): to_data(v) for k,v in sorted(value.items())}
|
|
22
|
+
return value
|
|
23
|
+
|
|
24
|
+
def serialize_translation_unit(unit: CTranslationUnit) -> dict[str, Any]:
|
|
25
|
+
data = to_data(unit)
|
|
26
|
+
if unit.schema_version not in {RECORD_SCHEMA_VERSION, NUMERIC_SCHEMA_VERSION, CONDITIONAL_SCHEMA_VERSION, KEYWORD_CALL_SCHEMA_VERSION, KEYWORD_ONLY_CALL_SCHEMA_VERSION} and _contains_record_kind(data):
|
|
27
|
+
raise ValueError("record C IR nodes require schema c-ir/0.13")
|
|
28
|
+
if unit.schema_version not in {MODULE_SCHEMA_VERSION, RECORD_SCHEMA_VERSION, NUMERIC_SCHEMA_VERSION, CONDITIONAL_SCHEMA_VERSION, KEYWORD_CALL_SCHEMA_VERSION, KEYWORD_ONLY_CALL_SCHEMA_VERSION}:
|
|
29
|
+
data = _without_module_fields(data)
|
|
30
|
+
if unit.schema_version not in {
|
|
31
|
+
CONTAINER_SCHEMA_VERSION,
|
|
32
|
+
MODULE_SCHEMA_VERSION,
|
|
33
|
+
RECORD_SCHEMA_VERSION,
|
|
34
|
+
NUMERIC_SCHEMA_VERSION,
|
|
35
|
+
CONDITIONAL_SCHEMA_VERSION,
|
|
36
|
+
KEYWORD_CALL_SCHEMA_VERSION,
|
|
37
|
+
KEYWORD_ONLY_CALL_SCHEMA_VERSION,
|
|
38
|
+
}:
|
|
39
|
+
# C IR 0.8-0.10 are StableInternal serialized contracts. New 0.11
|
|
40
|
+
# array metadata must not rewrite their payloads or helper fingerprints.
|
|
41
|
+
return _without_container_type_fields(data)
|
|
42
|
+
return data
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _contains_record_kind(value: Any) -> bool:
|
|
46
|
+
if isinstance(value, list):
|
|
47
|
+
return any(_contains_record_kind(item) for item in value)
|
|
48
|
+
if isinstance(value, dict):
|
|
49
|
+
if value.get("kind") in {
|
|
50
|
+
"CRecordDefinition",
|
|
51
|
+
"CRecordField",
|
|
52
|
+
"CRecordInitializer",
|
|
53
|
+
"CMemberAccessExpr",
|
|
54
|
+
}:
|
|
55
|
+
return True
|
|
56
|
+
return any(_contains_record_kind(item) for item in value.values())
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _without_module_fields(value: Any) -> Any:
|
|
61
|
+
if isinstance(value, list):
|
|
62
|
+
return [_without_module_fields(item) for item in value]
|
|
63
|
+
if isinstance(value, dict):
|
|
64
|
+
return {
|
|
65
|
+
key: _without_module_fields(item)
|
|
66
|
+
for key, item in value.items()
|
|
67
|
+
if key not in {
|
|
68
|
+
"module_manifest",
|
|
69
|
+
"module_order",
|
|
70
|
+
"module_dependencies",
|
|
71
|
+
"owner_module_id",
|
|
72
|
+
"owner_document_id",
|
|
73
|
+
"bundle_function_ordinal",
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return value
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _without_container_type_fields(value: Any) -> Any:
|
|
80
|
+
if isinstance(value, list):
|
|
81
|
+
return [_without_container_type_fields(item) for item in value]
|
|
82
|
+
if isinstance(value, dict):
|
|
83
|
+
return {
|
|
84
|
+
key: _without_container_type_fields(item)
|
|
85
|
+
for key, item in value.items()
|
|
86
|
+
if key not in {"array_extents", "object_const"}
|
|
87
|
+
}
|
|
88
|
+
return value
|