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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | 183x 183x 183x 183x 183x 183x 143x 143x 143x 143x 143x 143x 137x 167x 30x 134x 33x 135x 35x 148x 6x 137x 26x 4x 106x 30x 8x 140x | /**
* TranspilerState
* Encapsulates accumulated state Maps/Sets for the Transpiler.
*
* Issue #587: Provides clear state lifecycle management with explicit reset()
* and typed accessors for all accumulated data.
*/
import ICodeGenSymbols from "./ICodeGenSymbols";
/**
* Encapsulates the 6 accumulated state fields from Transpiler.
*
* State groups:
* - Group 1 (Header Generation): symbolCollectors, passByValueParams, userIncludes
* - Group 2 (Symbol Resolution): symbolInfoByFile
* - Group 3 (Cross-file Type Info): headerIncludeDirectives
* - Group 4 (Cycle Prevention): processedHeaders
*/
class TranspilerState {
// === Group 1: Header Generation State ===
/** Issue #220: Store ICodeGenSymbols per file for header generation (ADR-055) */
private readonly symbolCollectors = new Map<string, ICodeGenSymbols>();
/** Issue #280: Store pass-by-value params per file for header generation */
private readonly passByValueParams = new Map<
string,
ReadonlyMap<string, ReadonlySet<string>>
>();
/** Issue #424: Store user includes per file for header generation */
private readonly userIncludes = new Map<string, string[]>();
// === Group 2: Symbol Resolution State ===
/** Issue #465: Store ICodeGenSymbols per file during stage 3 for external enum resolution */
private readonly symbolInfoByFile = new Map<string, ICodeGenSymbols>();
// === Group 3: Cross-file Type Info ===
/**
* Issue #497: Map resolved header paths to their include directives.
* Used to include C headers in generated .h files instead of forward-declaring types.
*/
private readonly headerIncludeDirectives = new Map<string, string>();
// === Group 4: Cycle Prevention ===
/** Issue #321: Track processed headers to avoid cycles during recursive include resolution */
private readonly processedHeaders = new Set<string>();
// === Lifecycle ===
/**
* Reset all accumulated state.
* Call at the start of run() to ensure clean state for each transpilation.
*/
reset(): void {
this.symbolCollectors.clear();
this.passByValueParams.clear();
this.userIncludes.clear();
this.symbolInfoByFile.clear();
this.headerIncludeDirectives.clear();
this.processedHeaders.clear();
}
// === Symbol Collectors (Group 1) ===
/**
* Store symbol info for a file (used in header generation).
*/
setSymbolInfo(filePath: string, info: ICodeGenSymbols): void {
this.symbolCollectors.set(filePath, info);
}
/**
* Get symbol info for a file.
*/
getSymbolInfo(filePath: string): ICodeGenSymbols | undefined {
return this.symbolCollectors.get(filePath);
}
/**
* Get all symbol info values (for aggregating across files).
*/
getAllSymbolInfo(): Iterable<ICodeGenSymbols> {
return this.symbolCollectors.values();
}
// === Pass-By-Value Params (Group 1) ===
/**
* Store pass-by-value params for a file.
*/
setPassByValueParams(
filePath: string,
params: ReadonlyMap<string, ReadonlySet<string>>,
): void {
this.passByValueParams.set(filePath, params);
}
/**
* Get pass-by-value params for a file.
*/
getPassByValueParams(
filePath: string,
): ReadonlyMap<string, ReadonlySet<string>> | undefined {
return this.passByValueParams.get(filePath);
}
// === User Includes (Group 1) ===
/**
* Store user includes for a file.
*/
setUserIncludes(filePath: string, includes: string[]): void {
this.userIncludes.set(filePath, includes);
}
/**
* Get user includes for a file.
*/
getUserIncludes(filePath: string): string[] {
return this.userIncludes.get(filePath) ?? [];
}
// === Symbol Info By File (Group 2) ===
/**
* Store ICodeGenSymbols for external enum resolution.
*/
setFileSymbolInfo(filePath: string, info: ICodeGenSymbols): void {
this.symbolInfoByFile.set(filePath, info);
}
/**
* Get ICodeGenSymbols for external enum resolution.
*/
getFileSymbolInfo(filePath: string): ICodeGenSymbols | undefined {
return this.symbolInfoByFile.get(filePath);
}
/**
* Get the entire symbolInfoByFile map (for context building).
*/
getSymbolInfoByFileMap(): ReadonlyMap<string, ICodeGenSymbols> {
return this.symbolInfoByFile;
}
// === Header Include Directives (Group 3) ===
/**
* Store an include directive for a header path.
*/
setHeaderDirective(headerPath: string, directive: string): void {
this.headerIncludeDirectives.set(headerPath, directive);
}
/**
* Get the include directive for a header path.
*/
getHeaderDirective(headerPath: string): string | undefined {
return this.headerIncludeDirectives.get(headerPath);
}
/**
* Get all header include directives (for building external type headers).
*/
getAllHeaderDirectives(): ReadonlyMap<string, string> {
return this.headerIncludeDirectives;
}
// === Processed Headers (Group 4) ===
/**
* Mark a header as processed to prevent cycles.
*/
markHeaderProcessed(absolutePath: string): void {
this.processedHeaders.add(absolutePath);
}
/**
* Check if a header has been processed.
*/
isHeaderProcessed(absolutePath: string): boolean {
return this.processedHeaders.has(absolutePath);
}
/**
* Get the processed headers Set (for external APIs that require Set access).
* Issue #592: Used by IncludeResolver.resolveHeadersTransitively().
*/
getProcessedHeadersSet(): Set<string> {
return this.processedHeaders;
}
}
export default TranspilerState;
|