c-next 0.2.15 → 0.2.16

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 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.15",
14
+ version: "0.2.16",
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",
@@ -111792,19 +111792,17 @@ var SymbolTable = class {
111792
111792
  /**
111793
111793
  * Register struct fields in structFields map for cross-file type resolution.
111794
111794
  * Called automatically when adding struct symbols.
111795
+ * Issue #981: Now preserves string dimensions (macro names) for proper array detection.
111795
111796
  */
111796
111797
  registerStructFields(struct) {
111797
111798
  const cName = SymbolNameUtils_default.getTranspiledCName(struct);
111798
111799
  for (const [fieldName, fieldInfo] of struct.fields) {
111799
111800
  const typeString = TypeResolver_default.getTypeName(fieldInfo.type);
111800
- const numericDims = fieldInfo.dimensions?.filter(
111801
- (d) => typeof d === "number"
111802
- );
111803
111801
  this.addStructField(
111804
111802
  cName,
111805
111803
  fieldName,
111806
111804
  typeString,
111807
- numericDims && numericDims.length > 0 ? numericDims : void 0
111805
+ fieldInfo.dimensions && fieldInfo.dimensions.length > 0 ? fieldInfo.dimensions : void 0
111808
111806
  );
111809
111807
  }
111810
111808
  }
@@ -111917,6 +111915,7 @@ var SymbolTable = class {
111917
111915
  // ========================================================================
111918
111916
  /**
111919
111917
  * Add a C symbol to the table
111918
+ * Issue #981: Also register struct fields for type resolution
111920
111919
  */
111921
111920
  addCSymbol(symbol) {
111922
111921
  const existing = this.cSymbols.get(symbol.name);
@@ -111931,6 +111930,23 @@ var SymbolTable = class {
111931
111930
  } else {
111932
111931
  this.cSymbolsByFile.set(symbol.sourceFile, [symbol]);
111933
111932
  }
111933
+ if (symbol.kind === "struct" && symbol.fields) {
111934
+ this.registerCStructFields(symbol.name, symbol.fields);
111935
+ }
111936
+ }
111937
+ /**
111938
+ * Register C struct fields in structFields map for cross-file type resolution.
111939
+ * Issue #981: Required for macro-sized array field detection on local struct variables.
111940
+ */
111941
+ registerCStructFields(structName, fields) {
111942
+ for (const [fieldName, fieldInfo] of fields) {
111943
+ this.addStructField(
111944
+ structName,
111945
+ fieldName,
111946
+ fieldInfo.type,
111947
+ fieldInfo.arrayDimensions
111948
+ );
111949
+ }
111934
111950
  }
111935
111951
  /**
111936
111952
  * Add multiple C symbols at once
@@ -112265,11 +112281,12 @@ Rename the C-Next symbol to resolve.`
112265
112281
  // Struct Field Information
112266
112282
  // ========================================================================
112267
112283
  /**
112268
- * Add struct field information
112284
+ * Add struct field information.
112285
+ * Issue #981: Accept (number | string)[] for arrayDimensions to support macro-sized arrays.
112269
112286
  * @param structName Name of the struct
112270
112287
  * @param fieldName Name of the field
112271
112288
  * @param fieldType Type of the field (e.g., "uint32_t")
112272
- * @param arrayDimensions Optional array dimensions if field is an array
112289
+ * @param arrayDimensions Optional array dimensions - numbers for resolved, strings for macros
112273
112290
  */
112274
112291
  addStructField(structName, fieldName, fieldType, arrayDimensions) {
112275
112292
  let fields = this.structFields.get(structName);
@@ -112279,7 +112296,7 @@ Rename the C-Next symbol to resolve.`
112279
112296
  }
112280
112297
  fields.set(fieldName, {
112281
112298
  type: fieldType,
112282
- arrayDimensions
112299
+ arrayDimensions: arrayDimensions ? [...arrayDimensions] : void 0
112283
112300
  });
112284
112301
  }
112285
112302
  /**
@@ -113675,6 +113692,22 @@ var ScopeUtils = class _ScopeUtils {
113675
113692
  return scope.name === "" && scope.parent === scope;
113676
113693
  }
113677
113694
  // ============================================================================
113695
+ // Visibility Utilities
113696
+ // ============================================================================
113697
+ /**
113698
+ * ADR-016: Get the default visibility for a scope member based on its type.
113699
+ *
113700
+ * Member-type-aware defaults reduce boilerplate:
113701
+ * - Functions: public by default (API surface)
113702
+ * - Variables/types: private by default (internal state)
113703
+ *
113704
+ * @param isFunction - Whether the member is a function declaration
113705
+ * @returns The default visibility for this member type
113706
+ */
113707
+ static getDefaultVisibility(isFunction) {
113708
+ return isFunction ? "public" : "private";
113709
+ }
113710
+ // ============================================================================
113678
113711
  // Path Utilities
113679
113712
  // ============================================================================
113680
113713
  /**
@@ -120061,7 +120094,9 @@ function generateEnumMembersFromAST(members, fullName, orchestrator) {
120061
120094
  return lines;
120062
120095
  }
120063
120096
  function processScopeMember(member, scopeName, input, state, orchestrator) {
120064
- const visibility = member.visibilityModifier()?.getText() || "private";
120097
+ const explicitVisibility = member.visibilityModifier()?.getText();
120098
+ const isFunction = member.functionDeclaration() !== null;
120099
+ const visibility = explicitVisibility ?? ScopeUtils_default.getDefaultVisibility(isFunction);
120065
120100
  const isPrivate = visibility === "private";
120066
120101
  if (member.variableDeclaration()) {
120067
120102
  const varDecl = member.variableDeclaration();
@@ -134560,7 +134595,9 @@ var ScopeCollector = class {
134560
134595
  const memberSymbols = [];
134561
134596
  for (const member of ctx.scopeMember()) {
134562
134597
  const visibilityMod = member.visibilityModifier();
134563
- const visibility = visibilityMod?.getText() ?? "private";
134598
+ const explicitVisibility = visibilityMod?.getText();
134599
+ const isFunction = member.functionDeclaration() !== null;
134600
+ const visibility = explicitVisibility ?? ScopeUtils_default.getDefaultVisibility(isFunction);
134564
134601
  const isPublic = visibility === "public";
134565
134602
  if (member.variableDeclaration()) {
134566
134603
  const varDecl = member.variableDeclaration();
@@ -135250,12 +135287,15 @@ var TSymbolInfoAdapter_default = TSymbolInfoAdapter;
135250
135287
  var RESERVED_FIELD_NAMES = /* @__PURE__ */ new Set([]);
135251
135288
  function parseArrayDimensions2(text) {
135252
135289
  const dimensions = [];
135253
- const arrayMatches = text.match(/\[(\d+)\]/g);
135290
+ const arrayMatches = text.match(/\[([^\]]+)\]/g);
135254
135291
  if (arrayMatches) {
135255
135292
  for (const match of arrayMatches) {
135256
- const size = Number.parseInt(match.slice(1, -1), 10);
135257
- if (!Number.isNaN(size)) {
135258
- dimensions.push(size);
135293
+ const content = match.slice(1, -1).trim();
135294
+ const numericValue = Number.parseInt(content, 10);
135295
+ if (!Number.isNaN(numericValue) && String(numericValue) === content) {
135296
+ dimensions.push(numericValue);
135297
+ } else {
135298
+ dimensions.push(content);
135259
135299
  }
135260
135300
  }
135261
135301
  }
@@ -135453,6 +135493,7 @@ var DeclaratorUtils = class _DeclaratorUtils {
135453
135493
  }
135454
135494
  /**
135455
135495
  * Extract array dimensions from a declarator.
135496
+ * Issue #981: Returns (number | string)[] to support macro-sized arrays.
135456
135497
  */
135457
135498
  static extractArrayDimensions(declarator) {
135458
135499
  const directDecl = declarator.directDeclarator?.();
@@ -136607,6 +136648,7 @@ var DeclaratorUtils2 = class _DeclaratorUtils {
136607
136648
  }
136608
136649
  /**
136609
136650
  * Extract array dimensions from a declarator.
136651
+ * Issue #981: Returns (number | string)[] to support macro-sized arrays.
136610
136652
  */
136611
136653
  static extractArrayDimensions(declarator) {
136612
136654
  const ptrDecl = declarator.pointerDeclarator?.();
@@ -136624,6 +136666,7 @@ var DeclaratorUtils2 = class _DeclaratorUtils {
136624
136666
  }
136625
136667
  /**
136626
136668
  * Extract array dimensions from a noPointerDeclarator.
136669
+ * Issue #981: Returns (number | string)[] to support macro-sized arrays.
136627
136670
  */
136628
136671
  static extractArrayDimensionsFromNoPtr(noPtr) {
136629
136672
  return SymbolUtils_default.parseArrayDimensions(noPtr.getText());