c-next 0.2.14 → 0.2.15
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/dist/index.js +42 -4
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/src/transpiler/logic/symbols/c/__tests__/CResolver.integration.test.ts +28 -0
- package/src/transpiler/logic/symbols/c/collectors/VariableCollector.ts +12 -1
- package/src/transpiler/state/CodeGenState.ts +45 -3
- package/src/transpiler/state/__tests__/CodeGenState.test.ts +145 -3
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
11
11
|
// package.json
|
|
12
12
|
var package_default = {
|
|
13
13
|
name: "c-next",
|
|
14
|
-
version: "0.2.
|
|
14
|
+
version: "0.2.15",
|
|
15
15
|
description: "A safer C for embedded systems development. Transpiles to clean, readable C.",
|
|
16
16
|
packageManager: "npm@11.9.0",
|
|
17
17
|
type: "module",
|
|
@@ -112676,7 +112676,7 @@ var DEFAULT_TARGET = {
|
|
|
112676
112676
|
hasLdrexStrex: false,
|
|
112677
112677
|
hasBasepri: false
|
|
112678
112678
|
};
|
|
112679
|
-
var CodeGenState = class {
|
|
112679
|
+
var CodeGenState = class _CodeGenState {
|
|
112680
112680
|
// ===========================================================================
|
|
112681
112681
|
// GENERATOR REFERENCE (for handler access)
|
|
112682
112682
|
// ===========================================================================
|
|
@@ -113043,6 +113043,19 @@ var CodeGenState = class {
|
|
|
113043
113043
|
if (symbol?.kind === "variable" && symbol.type) {
|
|
113044
113044
|
return this.convertTSymbolToTypeInfo(symbol);
|
|
113045
113045
|
}
|
|
113046
|
+
const cSymbol = this.symbolTable.getCSymbol(name);
|
|
113047
|
+
if (cSymbol?.kind === "variable" && cSymbol.type) {
|
|
113048
|
+
const baseType = _CodeGenState.stripTrailingPointers(cSymbol.type);
|
|
113049
|
+
if (this.symbolTable.isTypedefStructType(baseType) || this.symbolTable.getStructFields(baseType)) {
|
|
113050
|
+
return {
|
|
113051
|
+
baseType,
|
|
113052
|
+
bitWidth: 0,
|
|
113053
|
+
isArray: cSymbol.isArray || false,
|
|
113054
|
+
isConst: cSymbol.isConst || false,
|
|
113055
|
+
isPointer: cSymbol.type.endsWith("*")
|
|
113056
|
+
};
|
|
113057
|
+
}
|
|
113058
|
+
}
|
|
113046
113059
|
return void 0;
|
|
113047
113060
|
}
|
|
113048
113061
|
/**
|
|
@@ -113061,7 +113074,15 @@ var CodeGenState = class {
|
|
|
113061
113074
|
return true;
|
|
113062
113075
|
}
|
|
113063
113076
|
const symbol = this.symbolTable.getTSymbol(name);
|
|
113064
|
-
|
|
113077
|
+
if (symbol?.kind === "variable" && symbol.type !== void 0) {
|
|
113078
|
+
return true;
|
|
113079
|
+
}
|
|
113080
|
+
const cSymbol = this.symbolTable.getCSymbol(name);
|
|
113081
|
+
if (cSymbol?.kind === "variable" && cSymbol.type) {
|
|
113082
|
+
const baseType = _CodeGenState.stripTrailingPointers(cSymbol.type);
|
|
113083
|
+
return this.symbolTable.isTypedefStructType(baseType) || !!this.symbolTable.getStructFields(baseType);
|
|
113084
|
+
}
|
|
113085
|
+
return false;
|
|
113065
113086
|
}
|
|
113066
113087
|
/**
|
|
113067
113088
|
* Set variable type info in the local registry.
|
|
@@ -113087,6 +113108,17 @@ var CodeGenState = class {
|
|
|
113087
113108
|
* Convert a TSymbol IVariableSymbol to TTypeInfo for unified type lookups.
|
|
113088
113109
|
* ADR-055 Phase 7: Works with typed TSymbol instead of ISymbol.
|
|
113089
113110
|
*/
|
|
113111
|
+
/**
|
|
113112
|
+
* Strip trailing pointer stars from a C type string (e.g., "font_t*" → "font_t").
|
|
113113
|
+
* Uses string operations instead of regex to avoid SonarCloud ReDoS flag (S5852).
|
|
113114
|
+
*/
|
|
113115
|
+
static stripTrailingPointers(type) {
|
|
113116
|
+
let end = type.length;
|
|
113117
|
+
while (end > 0 && type[end - 1] === "*") {
|
|
113118
|
+
end--;
|
|
113119
|
+
}
|
|
113120
|
+
return type.slice(0, end).trim();
|
|
113121
|
+
}
|
|
113090
113122
|
static convertTSymbolToTypeInfo(symbol) {
|
|
113091
113123
|
const typeName = TypeResolver_default.getTypeName(symbol.type);
|
|
113092
113124
|
const stringPattern = /^string<(\d+)>$/;
|
|
@@ -135949,6 +135981,8 @@ var VariableCollector2 = class {
|
|
|
135949
135981
|
*/
|
|
135950
135982
|
static collect(name, baseType, declarator, sourceFile, line, isExtern) {
|
|
135951
135983
|
const arrayDimensions = declarator ? DeclaratorUtils_default.extractArrayDimensions(declarator) : [];
|
|
135984
|
+
const hasPointer = declarator?.pointer?.() !== null && declarator?.pointer?.() !== void 0;
|
|
135985
|
+
const resolvedType = hasPointer ? `${baseType}*` : baseType;
|
|
135952
135986
|
return {
|
|
135953
135987
|
kind: "variable",
|
|
135954
135988
|
name,
|
|
@@ -135956,7 +135990,7 @@ var VariableCollector2 = class {
|
|
|
135956
135990
|
sourceLine: line,
|
|
135957
135991
|
sourceLanguage: ESourceLanguage_default.C,
|
|
135958
135992
|
isExported: !isExtern,
|
|
135959
|
-
type:
|
|
135993
|
+
type: resolvedType,
|
|
135960
135994
|
isArray: arrayDimensions.length > 0,
|
|
135961
135995
|
arrayDimensions: arrayDimensions.length > 0 ? arrayDimensions : void 0,
|
|
135962
135996
|
isExtern
|
|
@@ -135966,6 +136000,10 @@ var VariableCollector2 = class {
|
|
|
135966
136000
|
* Collect a variable from declaration specifiers (when identifier appears as typedefName).
|
|
135967
136001
|
* This handles the C grammar ambiguity where variable names can be parsed as typedef names.
|
|
135968
136002
|
*
|
|
136003
|
+
* Note: No pointer detection here — this path handles declarations without an
|
|
136004
|
+
* initDeclaratorList. Pointer declarations (e.g., `font_t *ptr`) always produce
|
|
136005
|
+
* an initDeclaratorList (the `*` creates a declarator), so they go through collect().
|
|
136006
|
+
*
|
|
135969
136007
|
* @param name Variable name
|
|
135970
136008
|
* @param baseType Variable type
|
|
135971
136009
|
* @param sourceFile Source file path
|