All files / transpiler/logic/symbols SymbolCollectorContext.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 6/6
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                                            190x                       171x 171x             168x             8x             666x             10x          
/**
 * SymbolCollectorContext
 * Shared context for C and C++ symbol collectors using composition.
 *
 * Extracted from CSymbolCollector and CppSymbolCollector to reduce duplication.
 */
 
import ICollectorContext from "./types/ICollectorContext";
import ISymbol from "../../../utils/types/ISymbol";
import SymbolTable from "./SymbolTable";
 
/**
 * Factory and utilities for symbol collector context
 */
class SymbolCollectorContext {
  /**
   * Create a new collector context
   */
  static create(
    sourceFile: string,
    symbolTable?: SymbolTable,
  ): ICollectorContext {
    return {
      sourceFile,
      symbols: [],
      warnings: [],
      symbolTable: symbolTable ?? null,
    };
  }
 
  /**
   * Reset context for reuse (clears symbols and warnings)
   */
  static reset(ctx: ICollectorContext): void {
    ctx.symbols = [];
    ctx.warnings = [];
  }
 
  /**
   * Get collected symbols
   */
  static getSymbols(ctx: ICollectorContext): ISymbol[] {
    return ctx.symbols;
  }
 
  /**
   * Get warnings generated during collection
   */
  static getWarnings(ctx: ICollectorContext): string[] {
    return ctx.warnings;
  }
 
  /**
   * Add a symbol to the context
   */
  static addSymbol(ctx: ICollectorContext, symbol: ISymbol): void {
    ctx.symbols.push(symbol);
  }
 
  /**
   * Add a warning to the context
   */
  static addWarning(ctx: ICollectorContext, message: string): void {
    ctx.warnings.push(message);
  }
}
 
export default SymbolCollectorContext;