@geastack/geatsc-plugin-gea 0.1.6

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.
Files changed (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +37 -0
  3. package/dist/analyze.d.ts +4 -0
  4. package/dist/analyze.js +195 -0
  5. package/dist/cpp-canvas-colors.d.ts +4 -0
  6. package/dist/cpp-canvas-colors.js +226 -0
  7. package/dist/cpp-field-access.d.ts +49 -0
  8. package/dist/cpp-field-access.js +144 -0
  9. package/dist/cpp-ir-dom-style.d.ts +1 -0
  10. package/dist/cpp-ir-dom-style.js +49 -0
  11. package/dist/cpp-ir.d.ts +30 -0
  12. package/dist/cpp-ir.js +2426 -0
  13. package/dist/cpp-keyed-component-diagnostics.d.ts +8 -0
  14. package/dist/cpp-keyed-component-diagnostics.js +74 -0
  15. package/dist/cpp-keyed-list-diagnostics.d.ts +17 -0
  16. package/dist/cpp-keyed-list-diagnostics.js +84 -0
  17. package/dist/cpp-mounted-lowering.d.ts +81 -0
  18. package/dist/cpp-mounted-lowering.js +2235 -0
  19. package/dist/cpp-mounted.d.ts +25 -0
  20. package/dist/cpp-mounted.js +1376 -0
  21. package/dist/cpp-reactive-component-diagnostics.d.ts +2 -0
  22. package/dist/cpp-reactive-component-diagnostics.js +76 -0
  23. package/dist/cpp-reactive-component.d.ts +14 -0
  24. package/dist/cpp-reactive-component.js +349 -0
  25. package/dist/cpp-replacements.d.ts +14 -0
  26. package/dist/cpp-replacements.js +787 -0
  27. package/dist/cpp-source-replacements.d.ts +11 -0
  28. package/dist/cpp-source-replacements.js +257 -0
  29. package/dist/cpp-store-hub.d.ts +7 -0
  30. package/dist/cpp-store-hub.js +160 -0
  31. package/dist/cpp-store-method-body-parser.d.ts +2 -0
  32. package/dist/cpp-store-method-body-parser.js +392 -0
  33. package/dist/cpp-store-method-context.d.ts +48 -0
  34. package/dist/cpp-store-method-context.js +114 -0
  35. package/dist/cpp-store-method-expressions.d.ts +12 -0
  36. package/dist/cpp-store-method-expressions.js +1263 -0
  37. package/dist/cpp-store-method-replacements.d.ts +5 -0
  38. package/dist/cpp-store-method-replacements.js +1521 -0
  39. package/dist/cpp-store-method-targets.d.ts +19 -0
  40. package/dist/cpp-store-method-targets.js +296 -0
  41. package/dist/cpp-store-typed-arrays.d.ts +2 -0
  42. package/dist/cpp-store-typed-arrays.js +655 -0
  43. package/dist/cpp-stores.d.ts +73 -0
  44. package/dist/cpp-stores.js +1739 -0
  45. package/dist/cpp-template-renderer.d.ts +23 -0
  46. package/dist/cpp-template-renderer.js +3530 -0
  47. package/dist/css-style-declaration-shims.d.ts +3 -0
  48. package/dist/css-style-declaration-shims.js +47 -0
  49. package/dist/host-declarations.d.ts +11 -0
  50. package/dist/host-declarations.js +320 -0
  51. package/dist/host-shims.d.ts +3 -0
  52. package/dist/host-shims.js +3217 -0
  53. package/dist/index.d.ts +3 -0
  54. package/dist/index.js +1239 -0
  55. package/dist/load-ir.d.ts +7 -0
  56. package/dist/load-ir.js +40 -0
  57. package/dist/types.d.ts +604 -0
  58. package/dist/types.js +1 -0
  59. package/dist/utils.d.ts +26 -0
  60. package/dist/utils.js +723 -0
  61. package/dist/validate.d.ts +3 -0
  62. package/dist/validate.js +226 -0
  63. package/package.json +57 -0
@@ -0,0 +1,392 @@
1
+ import ts from 'typescript';
2
+ export function parseStoreMethodBody(body) {
3
+ const source = ts.createSourceFile('__gea_store_method.ts', `function __gea_store_method() ${body}`, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
4
+ const fn = source.statements.find(ts.isFunctionDeclaration);
5
+ return fn?.body ? lowerStatementList(fn.body.statements) : null;
6
+ }
7
+ function lowerStatementList(statements) {
8
+ const lowered = [];
9
+ for (let i = 0; i < statements.length; i++) {
10
+ const statement = statements[i];
11
+ // Guard-continue rewrite: `if (cond) continue; <rest>` is equivalent to
12
+ // `if (!cond) { <rest> }`. The supported store-method control-flow IR has no
13
+ // `continue`; without this rewrite a leading guard-continue (a common loop
14
+ // idiom) forces the whole method onto the generic compiled-store fallback,
15
+ // whose value-copy + dangling-ref array lowering is exactly what we want to
16
+ // avoid. Only the early-guard shape (consequent is a bare `continue`, no
17
+ // else) is matched.
18
+ const guard = continueGuard(statement);
19
+ if (guard) {
20
+ const rest = lowerStatementList(statements.slice(i + 1));
21
+ if (rest === null)
22
+ return null;
23
+ // `if (cond) { body…; continue } <rest>` ≡ `if (cond) { body… } else { <rest> }`
24
+ // (and with an empty body, the original `if (!cond) { <rest> }` shape).
25
+ if (guard.body.length > 0) {
26
+ lowered.push({ kind: 'if', test: guard.test, consequent: guard.body, alternate: rest });
27
+ }
28
+ else {
29
+ lowered.push({ kind: 'if', test: { kind: 'unary', op: '!', arg: guard.test }, consequent: rest });
30
+ }
31
+ return lowered;
32
+ }
33
+ const next = lowerStatement(statement);
34
+ if (!next)
35
+ return null;
36
+ lowered.push(...next);
37
+ }
38
+ return lowered;
39
+ }
40
+ function continueGuard(statement) {
41
+ if (!ts.isIfStatement(statement) || statement.elseStatement)
42
+ return null;
43
+ const then = statement.thenStatement;
44
+ const isBareContinue = (s) => ts.isContinueStatement(s) && !s.label;
45
+ let bodyStatements = null;
46
+ if (isBareContinue(then)) {
47
+ bodyStatements = [];
48
+ }
49
+ else if (ts.isBlock(then) && then.statements.length >= 1 && isBareContinue(then.statements[then.statements.length - 1])) {
50
+ bodyStatements = then.statements.slice(0, -1);
51
+ }
52
+ if (bodyStatements === null)
53
+ return null;
54
+ const test = lowerExpression(statement.expression);
55
+ if (!test)
56
+ return null;
57
+ const body = lowerStatementList(bodyStatements);
58
+ if (body === null)
59
+ return null;
60
+ return { test, body };
61
+ }
62
+ function lowerStatement(statement) {
63
+ if (ts.isBlock(statement))
64
+ return lowerStatementList(statement.statements);
65
+ if (ts.isVariableStatement(statement))
66
+ return lowerVariableDeclarations(statement.declarationList);
67
+ if (ts.isExpressionStatement(statement)) {
68
+ const lowered = lowerExpressionStatement(statement.expression);
69
+ return lowered ? [lowered] : null;
70
+ }
71
+ if (ts.isIfStatement(statement)) {
72
+ const lowered = lowerIfStatement(statement);
73
+ return lowered ? [lowered] : null;
74
+ }
75
+ if (ts.isForStatement(statement)) {
76
+ const lowered = lowerForStatement(statement);
77
+ return lowered ? [lowered] : null;
78
+ }
79
+ if (ts.isWhileStatement(statement)) {
80
+ // `while (cond) body` is `for (; cond; ) body` — the IR's `for` already
81
+ // models optional init/update, so no new statement kind is needed.
82
+ const test = lowerExpression(statement.expression);
83
+ if (!test)
84
+ return null;
85
+ const body = lowerStatement(statement.statement);
86
+ return body ? [{ kind: 'for', test, body }] : null;
87
+ }
88
+ if (ts.isReturnStatement(statement)) {
89
+ if (!statement.expression)
90
+ return [{ kind: 'return' }];
91
+ const value = lowerExpression(statement.expression);
92
+ return value ? [{ kind: 'return', value }] : null;
93
+ }
94
+ return null;
95
+ }
96
+ function lowerVariableDeclarations(declarationList) {
97
+ const mutable = (declarationList.flags & ts.NodeFlags.Const) === 0;
98
+ const lowered = [];
99
+ for (const declaration of declarationList.declarations) {
100
+ if (!ts.isIdentifier(declaration.name))
101
+ return null;
102
+ const localType = declaration.type ? lowerLocalType(declaration.type) ?? undefined : undefined;
103
+ if (!declaration.initializer) {
104
+ lowered.push({ kind: 'var', name: declaration.name.text, mutable, localType });
105
+ continue;
106
+ }
107
+ const init = lowerExpression(declaration.initializer);
108
+ if (!init)
109
+ return null;
110
+ lowered.push({ kind: 'var', name: declaration.name.text, mutable, init, localType });
111
+ }
112
+ return lowered;
113
+ }
114
+ function lowerArrayElementType(element) {
115
+ if (ts.isTypeReferenceNode(element) && ts.isIdentifier(element.typeName)) {
116
+ return { kind: 'array', elementTypeName: element.typeName.text };
117
+ }
118
+ // Primitive-element arrays (`number[]`, `string[]`, `boolean[]`) lower to a
119
+ // native std::vector of the primitive C++ type. Without this they had no
120
+ // recorded local type and fell back to a boxed std::vector<gea_cpp_value>
121
+ // with a dynamic `.push` probe that fails to compile against std::vector.
122
+ switch (element.kind) {
123
+ case ts.SyntaxKind.NumberKeyword:
124
+ return { kind: 'array', elementPrimitive: 'number' };
125
+ case ts.SyntaxKind.StringKeyword:
126
+ return { kind: 'array', elementPrimitive: 'string' };
127
+ case ts.SyntaxKind.BooleanKeyword:
128
+ return { kind: 'array', elementPrimitive: 'boolean' };
129
+ default:
130
+ return null;
131
+ }
132
+ }
133
+ function lowerLocalType(type) {
134
+ if (ts.isArrayTypeNode(type)) {
135
+ return lowerArrayElementType(type.elementType);
136
+ }
137
+ if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName) && type.typeName.text === 'Array' && type.typeArguments?.length === 1) {
138
+ return lowerArrayElementType(type.typeArguments[0]);
139
+ }
140
+ return null;
141
+ }
142
+ function lowerExpressionStatement(expression) {
143
+ const assignment = lowerAssignmentExpression(expression);
144
+ if (assignment)
145
+ return assignment;
146
+ const update = lowerUpdateExpressionAsAssignment(expression);
147
+ if (update)
148
+ return update;
149
+ const expr = lowerExpression(expression);
150
+ return expr ? { kind: 'expr', expr } : null;
151
+ }
152
+ function lowerIfStatement(statement) {
153
+ const test = lowerExpression(statement.expression);
154
+ const consequent = lowerStatement(statement.thenStatement);
155
+ if (!test || !consequent)
156
+ return null;
157
+ if (!statement.elseStatement)
158
+ return { kind: 'if', test, consequent };
159
+ const alternate = lowerStatement(statement.elseStatement);
160
+ if (!alternate)
161
+ return null;
162
+ return { kind: 'if', test, consequent, alternate };
163
+ }
164
+ function lowerForStatement(statement) {
165
+ let init;
166
+ let test;
167
+ let update;
168
+ if (statement.initializer) {
169
+ init = lowerForInit(statement.initializer) ?? undefined;
170
+ if (!init)
171
+ return null;
172
+ }
173
+ if (statement.condition) {
174
+ test = lowerExpression(statement.condition) ?? undefined;
175
+ if (!test)
176
+ return null;
177
+ }
178
+ if (statement.incrementor) {
179
+ update = lowerExpression(statement.incrementor) ?? undefined;
180
+ if (!update)
181
+ return null;
182
+ }
183
+ const body = lowerStatement(statement.statement);
184
+ return body ? { kind: 'for', init, test, update, body } : null;
185
+ }
186
+ function lowerForInit(initializer) {
187
+ if (ts.isVariableDeclarationList(initializer)) {
188
+ const declarations = lowerVariableDeclarations(initializer);
189
+ return declarations?.length === 1 ? declarations[0] : null;
190
+ }
191
+ const assignment = lowerAssignmentExpression(initializer);
192
+ return assignment?.kind === 'assign' ? assignment : null;
193
+ }
194
+ function lowerAssignmentExpression(expression) {
195
+ if (!ts.isBinaryExpression(expression))
196
+ return null;
197
+ const assignmentOp = assignmentOperator(expression.operatorToken.kind);
198
+ if (!assignmentOp)
199
+ return null;
200
+ const target = lowerExpression(expression.left);
201
+ const right = lowerExpression(expression.right);
202
+ if (!target || !right)
203
+ return null;
204
+ if (assignmentOp === '=')
205
+ return { kind: 'assign', target, value: right };
206
+ return { kind: 'assign', target, value: { kind: 'binary', op: assignmentOp, left: target, right } };
207
+ }
208
+ function lowerUpdateExpressionAsAssignment(expression) {
209
+ if (!ts.isPrefixUnaryExpression(expression) && !ts.isPostfixUnaryExpression(expression))
210
+ return null;
211
+ const op = expression.operator === ts.SyntaxKind.PlusPlusToken ? '+' : expression.operator === ts.SyntaxKind.MinusMinusToken ? '-' : null;
212
+ if (!op)
213
+ return null;
214
+ const target = lowerExpression(expression.operand);
215
+ return target ? { kind: 'assign', target, value: { kind: 'binary', op, left: target, right: { kind: 'number', value: 1 } } } : null;
216
+ }
217
+ function lowerExpression(expression) {
218
+ if (ts.isParenthesizedExpression(expression))
219
+ return lowerExpression(expression.expression);
220
+ if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isNonNullExpression(expression) || ts.isSatisfiesExpression(expression)) {
221
+ return lowerExpression(expression.expression);
222
+ }
223
+ if (ts.isNumericLiteral(expression))
224
+ return { kind: 'number', value: Number(expression.text) };
225
+ if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression))
226
+ return { kind: 'string', value: expression.text };
227
+ if (expression.kind === ts.SyntaxKind.TrueKeyword)
228
+ return { kind: 'boolean', value: true };
229
+ if (expression.kind === ts.SyntaxKind.FalseKeyword)
230
+ return { kind: 'boolean', value: false };
231
+ if (expression.kind === ts.SyntaxKind.NullKeyword)
232
+ return { kind: 'null' };
233
+ if (ts.isIdentifier(expression))
234
+ return { kind: 'identifier', name: expression.text };
235
+ if (expression.kind === ts.SyntaxKind.ThisKeyword)
236
+ return { kind: 'this' };
237
+ if (ts.isPropertyAccessExpression(expression)) {
238
+ const object = lowerExpression(expression.expression);
239
+ return object ? { kind: 'member', object, property: expression.name.text } : null;
240
+ }
241
+ if (ts.isElementAccessExpression(expression)) {
242
+ const object = lowerExpression(expression.expression);
243
+ const index = expression.argumentExpression ? lowerExpression(expression.argumentExpression) : null;
244
+ return object && index ? { kind: 'index', object, index } : null;
245
+ }
246
+ if (ts.isCallExpression(expression)) {
247
+ const callee = lowerExpression(expression.expression);
248
+ const args = expression.arguments.map((arg) => lowerExpression(arg));
249
+ return callee && allExpressions(args) ? { kind: 'call', callee, args } : null;
250
+ }
251
+ if (ts.isObjectLiteralExpression(expression))
252
+ return lowerObjectLiteral(expression);
253
+ if (ts.isArrayLiteralExpression(expression)) {
254
+ const elements = expression.elements.map((element) => lowerExpression(element));
255
+ return allExpressions(elements) ? { kind: 'array', elements } : null;
256
+ }
257
+ if (ts.isPrefixUnaryExpression(expression)) {
258
+ const op = unaryOperator(expression.operator);
259
+ const arg = lowerExpression(expression.operand);
260
+ return op && arg ? { kind: 'unary', op, arg } : null;
261
+ }
262
+ if (ts.isPostfixUnaryExpression(expression)) {
263
+ const op = expression.operator === ts.SyntaxKind.PlusPlusToken ? '++' : expression.operator === ts.SyntaxKind.MinusMinusToken ? '--' : null;
264
+ const arg = lowerExpression(expression.operand);
265
+ return op && arg ? { kind: 'update', op, arg, prefix: false } : null;
266
+ }
267
+ if (ts.isBinaryExpression(expression))
268
+ return lowerBinaryExpression(expression);
269
+ if (ts.isConditionalExpression(expression)) {
270
+ const test = lowerExpression(expression.condition);
271
+ const consequent = lowerExpression(expression.whenTrue);
272
+ const alternate = lowerExpression(expression.whenFalse);
273
+ return test && consequent && alternate ? { kind: 'conditional', test, consequent, alternate } : null;
274
+ }
275
+ if (ts.isTemplateExpression(expression))
276
+ return lowerTemplateExpression(expression);
277
+ return null;
278
+ }
279
+ function lowerObjectLiteral(expression) {
280
+ const fields = [];
281
+ for (const property of expression.properties) {
282
+ if (!ts.isPropertyAssignment(property))
283
+ return null;
284
+ const name = propertyName(property.name);
285
+ const value = lowerExpression(property.initializer);
286
+ if (!name || !value)
287
+ return null;
288
+ fields.push({ name, value });
289
+ }
290
+ return { kind: 'object', fields };
291
+ }
292
+ function lowerBinaryExpression(expression) {
293
+ const op = binaryOperator(expression.operatorToken.kind);
294
+ const left = lowerExpression(expression.left);
295
+ const right = lowerExpression(expression.right);
296
+ if (!op || !left || !right)
297
+ return null;
298
+ return { kind: op === '&&' || op === '||' ? 'logical' : 'binary', op, left, right };
299
+ }
300
+ function lowerTemplateExpression(expression) {
301
+ const parts = [];
302
+ if (expression.head.text)
303
+ parts.push({ kind: 'string', value: expression.head.text });
304
+ for (const span of expression.templateSpans) {
305
+ const expr = lowerExpression(span.expression);
306
+ if (!expr)
307
+ return null;
308
+ parts.push(expr);
309
+ if (span.literal.text)
310
+ parts.push({ kind: 'string', value: span.literal.text });
311
+ }
312
+ if (parts.length === 0)
313
+ return { kind: 'string', value: '' };
314
+ return parts.reduce((left, right) => ({ kind: 'binary', op: '+', left, right }));
315
+ }
316
+ function propertyName(name) {
317
+ if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name))
318
+ return name.text;
319
+ return null;
320
+ }
321
+ function allExpressions(values) {
322
+ return values.every((value) => value !== null);
323
+ }
324
+ function assignmentOperator(kind) {
325
+ if (kind === ts.SyntaxKind.EqualsToken)
326
+ return '=';
327
+ if (kind === ts.SyntaxKind.PlusEqualsToken)
328
+ return '+';
329
+ if (kind === ts.SyntaxKind.MinusEqualsToken)
330
+ return '-';
331
+ if (kind === ts.SyntaxKind.AsteriskEqualsToken)
332
+ return '*';
333
+ if (kind === ts.SyntaxKind.SlashEqualsToken)
334
+ return '/';
335
+ if (kind === ts.SyntaxKind.PercentEqualsToken)
336
+ return '%';
337
+ if (kind === ts.SyntaxKind.BarEqualsToken)
338
+ return '|';
339
+ if (kind === ts.SyntaxKind.LessThanLessThanEqualsToken)
340
+ return '<<';
341
+ if (kind === ts.SyntaxKind.GreaterThanGreaterThanEqualsToken)
342
+ return '>>';
343
+ if (kind === ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken)
344
+ return '>>>';
345
+ return null;
346
+ }
347
+ function binaryOperator(kind) {
348
+ if (kind === ts.SyntaxKind.PlusToken)
349
+ return '+';
350
+ if (kind === ts.SyntaxKind.MinusToken)
351
+ return '-';
352
+ if (kind === ts.SyntaxKind.AsteriskToken)
353
+ return '*';
354
+ if (kind === ts.SyntaxKind.SlashToken)
355
+ return '/';
356
+ if (kind === ts.SyntaxKind.PercentToken)
357
+ return '%';
358
+ if (kind === ts.SyntaxKind.LessThanToken)
359
+ return '<';
360
+ if (kind === ts.SyntaxKind.LessThanEqualsToken)
361
+ return '<=';
362
+ if (kind === ts.SyntaxKind.GreaterThanToken)
363
+ return '>';
364
+ if (kind === ts.SyntaxKind.GreaterThanEqualsToken)
365
+ return '>=';
366
+ if (kind === ts.SyntaxKind.EqualsEqualsToken || kind === ts.SyntaxKind.EqualsEqualsEqualsToken)
367
+ return '==';
368
+ if (kind === ts.SyntaxKind.ExclamationEqualsToken || kind === ts.SyntaxKind.ExclamationEqualsEqualsToken)
369
+ return '!=';
370
+ if (kind === ts.SyntaxKind.AmpersandAmpersandToken)
371
+ return '&&';
372
+ if (kind === ts.SyntaxKind.BarBarToken)
373
+ return '||';
374
+ if (kind === ts.SyntaxKind.BarToken)
375
+ return '|';
376
+ if (kind === ts.SyntaxKind.LessThanLessThanToken)
377
+ return '<<';
378
+ if (kind === ts.SyntaxKind.GreaterThanGreaterThanToken)
379
+ return '>>';
380
+ if (kind === ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken)
381
+ return '>>>';
382
+ return null;
383
+ }
384
+ function unaryOperator(kind) {
385
+ if (kind === ts.SyntaxKind.PlusToken)
386
+ return '+';
387
+ if (kind === ts.SyntaxKind.MinusToken)
388
+ return '-';
389
+ if (kind === ts.SyntaxKind.ExclamationToken)
390
+ return '!';
391
+ return null;
392
+ }
@@ -0,0 +1,48 @@
1
+ import type { GeaIrConstant, GeaIrStore, GeaIrStoreExpr, GeaIrStoreLocalType } from './types.js';
2
+ import type { StoreFieldPlan, StoreMethodPlan } from './cpp-stores.js';
3
+ export interface StoreMethodLowerContext {
4
+ store: GeaIrStore;
5
+ storeFields: StoreFieldPlan[];
6
+ storeMethods: StoreMethodPlan[];
7
+ params: Set<string>;
8
+ paramHints: Map<string, StoreMethodHint>;
9
+ topLevelFunctionNames: Map<string, string>;
10
+ topLevelValueNames: Map<string, string>;
11
+ locals: Set<string>;
12
+ constants: Map<string, number | string | boolean | null>;
13
+ localTypes: Map<string, GeaIrStoreLocalType>;
14
+ tempIndex: number;
15
+ arrayElementAliases: Map<string, StoreArrayElementAlias>;
16
+ arrayItemAliases: Map<string, string>;
17
+ arrayItemFieldAliases: Map<string, string>;
18
+ dirtyArrayFields: Set<string>;
19
+ needsFieldSet: boolean;
20
+ needsArrayLengthSet: boolean;
21
+ needsArrayItemSet: boolean;
22
+ needsDynamicArrayItemSet: boolean;
23
+ needsArrayPush: boolean;
24
+ needsArrayUnshift: boolean;
25
+ needsArraySplice: boolean;
26
+ needsArrayPop: boolean;
27
+ needsArrayShift: boolean;
28
+ }
29
+ export type StoreMethodHint = 'any' | 'number' | 'string' | 'boolean';
30
+ export interface StoreArrayElementAlias {
31
+ arrayField: string;
32
+ itemExpression: string;
33
+ indexExpression: string;
34
+ }
35
+ export interface StoreArrayElementAliasField {
36
+ alias: StoreArrayElementAlias;
37
+ itemField: string;
38
+ }
39
+ export declare function arrayElementAliasFieldTarget(context: StoreMethodLowerContext, expr: GeaIrStoreExpr): StoreArrayElementAliasField | null;
40
+ export declare function arrayItemAliasKey(arrayFieldName: string, indexName: string): string;
41
+ export declare function arrayItemFieldAliasKey(arrayFieldName: string, indexName: string, itemFieldName: string): string;
42
+ export declare function constantMap(store: GeaIrStore, globalConstants?: ReadonlyMap<string, GeaIrConstant>): Map<string, number | string | boolean | null>;
43
+ export declare function fieldHint(store: GeaIrStore, fieldName: string): StoreMethodHint;
44
+ export declare function arrayItemFieldHint(store: GeaIrStore, arrayFieldName: string, itemFieldName: string): StoreMethodHint;
45
+ export declare function typedArrayItemFieldAccess(store: GeaIrStore, arrayFieldName: string, itemFieldName: string, itemExpression: string): string | null;
46
+ export declare function localArrayTypeRef(context: StoreMethodLowerContext, localName: string): string | null;
47
+ export declare function localArrayCppType(context: StoreMethodLowerContext, localName: string): string | null;
48
+ export declare function nextStoreMethodTemp(context: StoreMethodLowerContext, label: string): string;
@@ -0,0 +1,114 @@
1
+ import { sanitizeCppIdentifier } from './utils.js';
2
+ export function arrayElementAliasFieldTarget(context, expr) {
3
+ if (expr.kind !== 'member' || expr.object.kind !== 'identifier')
4
+ return null;
5
+ const alias = context.arrayElementAliases.get(expr.object.name);
6
+ return alias ? { alias, itemField: expr.property } : null;
7
+ }
8
+ export function arrayItemAliasKey(arrayFieldName, indexName) {
9
+ return `${arrayFieldName}\0${indexName}`;
10
+ }
11
+ export function arrayItemFieldAliasKey(arrayFieldName, indexName, itemFieldName) {
12
+ return `${arrayFieldName}\0${indexName}\0${itemFieldName}`;
13
+ }
14
+ export function constantMap(store, globalConstants = new Map()) {
15
+ const map = new Map();
16
+ for (const constant of globalConstants.values())
17
+ addConstant(map, constant);
18
+ for (const constant of store.constants ?? []) {
19
+ addConstant(map, constant);
20
+ }
21
+ return map;
22
+ }
23
+ function addConstant(map, constant) {
24
+ if (constant.valueType === 'number')
25
+ map.set(constant.name, Number(constant.value));
26
+ else if (constant.valueType === 'boolean')
27
+ map.set(constant.name, constant.value === 'true');
28
+ else if (constant.valueType === 'null')
29
+ map.set(constant.name, null);
30
+ else if (constant.valueType === 'string')
31
+ map.set(constant.name, constant.value);
32
+ }
33
+ export function fieldHint(store, fieldName) {
34
+ const field = store.fields.find((candidate) => candidate.name === fieldName);
35
+ if (field?.shape?.kind === 'literal') {
36
+ if (field.shape.valueType === 'boolean')
37
+ return 'boolean';
38
+ if (field.shape.valueType === 'number')
39
+ return 'number';
40
+ if (field.shape.valueType === 'string')
41
+ return 'string';
42
+ }
43
+ return 'any';
44
+ }
45
+ export function arrayItemFieldHint(store, arrayFieldName, itemFieldName) {
46
+ const field = store.fields.find((candidate) => candidate.name === arrayFieldName);
47
+ const itemField = field?.shape?.kind === 'array' && field.shape.element?.kind === 'object'
48
+ ? field.shape.element.fields.find((candidate) => candidate.name === itemFieldName)
49
+ : undefined;
50
+ if (itemField?.shape?.kind === 'literal') {
51
+ if (itemField.shape.valueType === 'boolean')
52
+ return 'boolean';
53
+ if (itemField.shape.valueType === 'number')
54
+ return 'number';
55
+ if (itemField.shape.valueType === 'string')
56
+ return 'string';
57
+ }
58
+ return 'any';
59
+ }
60
+ export function typedArrayItemFieldAccess(store, arrayFieldName, itemFieldName, itemExpression) {
61
+ const field = store.fields.find((candidate) => candidate.name === arrayFieldName);
62
+ if (!field)
63
+ return null;
64
+ const shape = field.shape;
65
+ // A named TS element type is already emitted by geatsc as a typed record
66
+ // struct, even when one of its fields is itself an array or record. The Gea
67
+ // plugin only attaches typedStorage metadata to the all-primitive fast path,
68
+ // so requiring typedStorage here incorrectly demoted valid accesses such as
69
+ // `this.pages[i].chapterStarts` to a numeric dynamic-field read.
70
+ if (!field.typedStorage && !(shape?.kind === 'array' && !!shape.elementTypeName))
71
+ return null;
72
+ const itemField = field.shape?.kind === 'array' && field.shape.element?.kind === 'object'
73
+ ? field.shape.element.fields.find((candidate) => candidate.name === itemFieldName)
74
+ : undefined;
75
+ // Named-type enrichment is intentionally partial today: it records the
76
+ // primitive members it can use for plugin fast paths and omits nested
77
+ // arrays/records. That omission must not override TypeScript's validated
78
+ // named record. Only anonymous inline object arrays require the field to be
79
+ // present in the IR shape.
80
+ if (shape?.kind === 'array' && shape.element?.kind === 'object' && !shape.elementTypeName && !itemField)
81
+ return null;
82
+ return `${itemExpression}.${sanitizeCppIdentifier(itemFieldName)}`;
83
+ }
84
+ // C++ element type for a primitive-element local array, or null.
85
+ const PRIMITIVE_ARRAY_CPP = {
86
+ number: 'double',
87
+ string: 'std::string',
88
+ boolean: 'bool',
89
+ };
90
+ export function localArrayTypeRef(context, localName) {
91
+ const localType = context.localTypes.get(localName);
92
+ if (localType?.kind !== 'array')
93
+ return null;
94
+ if ('elementPrimitive' in localType) {
95
+ return PRIMITIVE_ARRAY_CPP[localType.elementPrimitive];
96
+ }
97
+ const matchingField = context.store.fields.find((field) => field.typedStorage?.elementTypeName === localType.elementTypeName);
98
+ if (matchingField?.typedStorage) {
99
+ return matchingField.typedStorage.useInterfaceStruct
100
+ ? `::${matchingField.typedStorage.itemType}`
101
+ : matchingField.typedStorage.itemType;
102
+ }
103
+ return `::${interfaceItemSymbol(localType.elementTypeName)}`;
104
+ }
105
+ export function localArrayCppType(context, localName) {
106
+ const elementType = localArrayTypeRef(context, localName);
107
+ return elementType ? `std::vector<${elementType}>` : null;
108
+ }
109
+ export function nextStoreMethodTemp(context, label) {
110
+ return `__gea_${sanitizeCppIdentifier(`${label}_${context.tempIndex++}`)}`;
111
+ }
112
+ function interfaceItemSymbol(name) {
113
+ return `__gea_type_${sanitizeCppIdentifier(name)}`;
114
+ }
@@ -0,0 +1,12 @@
1
+ import { type StoreMethodHint, type StoreMethodLowerContext } from './cpp-store-method-context.js';
2
+ import type { GeaIrStoreExpr } from './types.js';
3
+ export declare function lowerExpr(context: StoreMethodLowerContext, expr: GeaIrStoreExpr, hint: StoreMethodHint): string | null;
4
+ export declare function lowerForUpdate(context: StoreMethodLowerContext, expr: GeaIrStoreExpr): string | null;
5
+ export declare function assignmentHint(target: GeaIrStoreExpr): StoreMethodHint;
6
+ export interface GlobalStoreFieldTarget {
7
+ access: string;
8
+ storeAccess: string;
9
+ fieldName: string;
10
+ hint: StoreMethodHint;
11
+ }
12
+ export declare function globalStoreFieldTarget(context: StoreMethodLowerContext, expr: GeaIrStoreExpr): GlobalStoreFieldTarget | null;