c-next 0.1.65 → 0.1.67
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/package.json +5 -1
- package/src/transpiler/Transpiler.ts +49 -42
- package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolAdapter.test.ts +129 -0
- package/src/transpiler/logic/symbols/cnext/adapters/TSymbolAdapter.ts +27 -3
- package/src/transpiler/output/codegen/CodeGenerator.ts +131 -186
- package/src/transpiler/output/codegen/TypeResolver.ts +2 -2
- package/src/transpiler/output/codegen/TypeValidator.ts +1 -1
- package/src/transpiler/output/codegen/__tests__/CodeGenerator.coverage.test.ts +1087 -0
- package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +665 -1315
- package/src/transpiler/output/codegen/__tests__/TypeResolver.test.ts +1 -1
- package/src/transpiler/output/codegen/__tests__/TypeValidator.resolution.test.ts +1 -1
- package/src/transpiler/output/codegen/__tests__/TypeValidator.test.ts +1 -1
- package/src/transpiler/output/codegen/analysis/MemberChainAnalyzer.ts +1 -1
- package/src/transpiler/output/codegen/analysis/StringLengthCounter.ts +1 -1
- package/src/transpiler/output/codegen/analysis/__tests__/MemberChainAnalyzer.test.ts +1 -1
- package/src/transpiler/output/codegen/analysis/__tests__/StringLengthCounter.test.ts +1 -1
- package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +1 -1
- package/src/transpiler/output/codegen/assignment/__tests__/AssignmentClassifier.test.ts +1 -1
- package/src/transpiler/output/codegen/assignment/handlers/AccessPatternHandlers.ts +24 -27
- package/src/transpiler/output/codegen/assignment/handlers/ArrayHandlers.ts +25 -18
- package/src/transpiler/output/codegen/assignment/handlers/BitAccessHandlers.ts +27 -33
- package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +39 -42
- package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +39 -97
- package/src/transpiler/output/codegen/assignment/handlers/RegisterUtils.ts +75 -0
- package/src/transpiler/output/codegen/assignment/handlers/SimpleHandler.ts +9 -6
- package/src/transpiler/output/codegen/assignment/handlers/SpecialHandlers.ts +30 -22
- package/src/transpiler/output/codegen/assignment/handlers/StringHandlers.ts +42 -50
- package/src/transpiler/output/codegen/assignment/handlers/TAssignmentHandler.ts +6 -5
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/AccessPatternHandlers.test.ts +81 -134
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/ArrayHandlers.test.ts +85 -124
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitAccessHandlers.test.ts +82 -124
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitmapHandlers.test.ts +135 -297
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/RegisterHandlers.test.ts +105 -227
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/RegisterUtils.test.ts +214 -1
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/SpecialHandlers.test.ts +66 -127
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/StringHandlers.test.ts +37 -83
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/handlerTestUtils.ts +162 -0
- package/src/transpiler/output/codegen/generators/expressions/PostfixExpressionGenerator.ts +618 -12
- package/src/transpiler/output/codegen/generators/expressions/__tests__/PostfixExpressionGenerator.test.ts +819 -0
- package/src/transpiler/output/codegen/helpers/ArrayInitHelper.ts +1 -1
- package/src/transpiler/output/codegen/helpers/AssignmentExpectedTypeResolver.ts +1 -1
- package/src/transpiler/output/codegen/helpers/AssignmentValidator.ts +1 -1
- package/src/transpiler/output/codegen/helpers/CppModeHelper.ts +1 -1
- package/src/transpiler/output/codegen/helpers/EnumAssignmentValidator.ts +1 -1
- package/src/transpiler/output/codegen/helpers/FloatBitHelper.ts +1 -1
- package/src/transpiler/output/codegen/helpers/ParameterInputAdapter.ts +337 -0
- package/src/transpiler/output/codegen/helpers/ParameterSignatureBuilder.ts +135 -0
- package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +1 -1
- package/src/transpiler/output/codegen/helpers/VariableDeclarationFormatter.ts +118 -0
- package/src/transpiler/output/codegen/helpers/__tests__/ArrayInitHelper.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentExpectedTypeResolver.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentValidator.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/CppModeHelper.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/EnumAssignmentValidator.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/FloatBitHelper.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/ParameterInputAdapter.test.ts +426 -0
- package/src/transpiler/output/codegen/helpers/__tests__/ParameterSignatureBuilder.test.ts +315 -0
- package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/VariableDeclarationFormatter.test.ts +333 -0
- package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +1 -1
- package/src/transpiler/output/codegen/resolution/ScopeResolver.ts +1 -1
- package/src/transpiler/output/codegen/resolution/SizeofResolver.ts +1 -1
- package/src/transpiler/output/codegen/resolution/__tests__/EnumTypeResolver.test.ts +1 -1
- package/src/transpiler/output/codegen/resolution/__tests__/SizeofResolver.test.ts +1 -1
- package/src/transpiler/output/codegen/types/ICodeGenApi.ts +57 -0
- package/src/transpiler/output/codegen/types/IParameterInput.ts +58 -0
- package/src/transpiler/output/codegen/types/IVariableFormatInput.ts +51 -0
- package/src/transpiler/output/headers/BaseHeaderGenerator.ts +20 -35
- package/src/transpiler/output/headers/HeaderGeneratorUtils.ts +21 -48
- package/src/transpiler/output/headers/__tests__/HeaderGeneratorUtils.test.ts +0 -64
- package/src/transpiler/{output/codegen → state}/CodeGenState.ts +46 -26
- package/src/transpiler/{output/codegen → state}/__tests__/CodeGenState.test.ts +12 -2
- package/src/transpiler/output/codegen/assignment/handlers/IHandlerDeps.ts +0 -161
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dependencies provided to assignment handlers (ADR-109).
|
|
3
|
-
*
|
|
4
|
-
* Handlers need access to various CodeGenerator capabilities without
|
|
5
|
-
* taking a direct dependency on the full CodeGenerator class. This
|
|
6
|
-
* interface defines the subset of functionality handlers need.
|
|
7
|
-
*/
|
|
8
|
-
import * as Parser from "../../../../logic/parser/grammar/CNextParser";
|
|
9
|
-
import ICodeGenSymbols from "../../../../types/ICodeGenSymbols";
|
|
10
|
-
import TTypeInfo from "../../types/TTypeInfo";
|
|
11
|
-
import ITargetCapabilities from "../../types/ITargetCapabilities";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Dependencies for assignment handlers.
|
|
15
|
-
*
|
|
16
|
-
* These are provided by CodeGenerator to enable handlers to:
|
|
17
|
-
* - Look up type information
|
|
18
|
-
* - Access symbol tables
|
|
19
|
-
* - Generate expressions
|
|
20
|
-
* - Track side effects (needsString, clampOps)
|
|
21
|
-
*/
|
|
22
|
-
interface IHandlerDeps {
|
|
23
|
-
// === Symbol information ===
|
|
24
|
-
|
|
25
|
-
/** Read-only symbol info (registers, bitmaps, structs, etc.) */
|
|
26
|
-
readonly symbols: ICodeGenSymbols;
|
|
27
|
-
|
|
28
|
-
/** Type registry: variable name -> type info */
|
|
29
|
-
readonly typeRegistry: ReadonlyMap<string, TTypeInfo>;
|
|
30
|
-
|
|
31
|
-
/** Current scope name (for this.* resolution), null if not in scope */
|
|
32
|
-
readonly currentScope: string | null;
|
|
33
|
-
|
|
34
|
-
/** Parameters of current function */
|
|
35
|
-
readonly currentParameters: ReadonlyMap<
|
|
36
|
-
string,
|
|
37
|
-
{ isStruct?: boolean; isArray?: boolean }
|
|
38
|
-
>;
|
|
39
|
-
|
|
40
|
-
/** Target platform capabilities */
|
|
41
|
-
readonly targetCapabilities: ITargetCapabilities;
|
|
42
|
-
|
|
43
|
-
// === Expression generation ===
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Generate C code for an expression.
|
|
47
|
-
*/
|
|
48
|
-
generateExpression(ctx: Parser.ExpressionContext): string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Try to evaluate an expression as a compile-time constant.
|
|
52
|
-
* Returns undefined if not a constant.
|
|
53
|
-
*/
|
|
54
|
-
tryEvaluateConstant(ctx: Parser.ExpressionContext): number | undefined;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Generate the C target string for an assignment target.
|
|
58
|
-
*/
|
|
59
|
-
generateAssignmentTarget(ctx: Parser.AssignmentTargetContext): string;
|
|
60
|
-
|
|
61
|
-
// === Type checking ===
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Check if a type name is a known struct.
|
|
65
|
-
*/
|
|
66
|
-
isKnownStruct(typeName: string): boolean;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Check if a name is a known scope.
|
|
70
|
-
*/
|
|
71
|
-
isKnownScope(name: string): boolean;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get member type info for a struct field.
|
|
75
|
-
*/
|
|
76
|
-
getMemberTypeInfo(structType: string, memberName: string): TTypeInfo | null;
|
|
77
|
-
|
|
78
|
-
// === Validation ===
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Validate bitmap field literal fits in field width.
|
|
82
|
-
*/
|
|
83
|
-
validateBitmapFieldLiteral(
|
|
84
|
-
expr: Parser.ExpressionContext,
|
|
85
|
-
width: number,
|
|
86
|
-
fieldName: string,
|
|
87
|
-
): void;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Validate cross-scope visibility for member access.
|
|
91
|
-
*/
|
|
92
|
-
validateCrossScopeVisibility(scopeName: string, memberName: string): void;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Check array bounds for compile-time constant indices.
|
|
96
|
-
*/
|
|
97
|
-
checkArrayBounds(
|
|
98
|
-
arrayName: string,
|
|
99
|
-
dimensions: readonly number[],
|
|
100
|
-
indexExprs: readonly Parser.ExpressionContext[],
|
|
101
|
-
line: number,
|
|
102
|
-
): void;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Analyze a member chain target for bit access.
|
|
106
|
-
* Returns { isBitAccess: false } if not bit access.
|
|
107
|
-
* Returns { isBitAccess: true, baseTarget, bitIndex, baseType } if bit access detected.
|
|
108
|
-
*/
|
|
109
|
-
analyzeMemberChainForBitAccess(targetCtx: Parser.AssignmentTargetContext): {
|
|
110
|
-
isBitAccess: boolean;
|
|
111
|
-
baseTarget?: string;
|
|
112
|
-
bitIndex?: string;
|
|
113
|
-
baseType?: string;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// === Float bit indexing ===
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Generate float bit write using shadow variable + memcpy.
|
|
120
|
-
* Returns the full statement for writing bits to a float variable.
|
|
121
|
-
* Returns null if typeInfo is not a float type.
|
|
122
|
-
*/
|
|
123
|
-
generateFloatBitWrite(
|
|
124
|
-
name: string,
|
|
125
|
-
typeInfo: TTypeInfo,
|
|
126
|
-
bitIndex: string,
|
|
127
|
-
width: string | null,
|
|
128
|
-
value: string,
|
|
129
|
-
): string | null;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Convert boolean expression to integer: true -> "1", false -> "0", else "(expr ? 1 : 0)"
|
|
133
|
-
*/
|
|
134
|
-
foldBooleanToInt(expr: string): string;
|
|
135
|
-
|
|
136
|
-
// === Side effects ===
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Mark that string.h is needed (for strncpy, memcpy).
|
|
140
|
-
*/
|
|
141
|
-
markNeedsString(): void;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Mark that a clamp operation helper is used.
|
|
145
|
-
*/
|
|
146
|
-
markClampOpUsed(op: string, typeName: string): void;
|
|
147
|
-
|
|
148
|
-
// === Atomic operations ===
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Generate atomic read-modify-write operation.
|
|
152
|
-
*/
|
|
153
|
-
generateAtomicRMW(
|
|
154
|
-
target: string,
|
|
155
|
-
cOp: string,
|
|
156
|
-
value: string,
|
|
157
|
-
typeInfo: TTypeInfo,
|
|
158
|
-
): string;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export default IHandlerDeps;
|