@@ -54,6 +54,19 @@ const TYPE_SIZE_MAP: Record<string, number> = {
5454 strref : 4 ,
5555} ;
5656
57+ // Known types for JSDoc output
58+ const KNOWN_TYPES = new Set ( [
59+ "byte" ,
60+ "char" ,
61+ "word" ,
62+ "dword" ,
63+ "resref" ,
64+ "strref" ,
65+ "bytes" ,
66+ "char array" ,
67+ "byte array" ,
68+ ] ) ;
69+
5770const STRUCTURE_PREFIX_MAP : Record < string , string > = {
5871 header : "" ,
5972 body : "" ,
@@ -311,10 +324,25 @@ function isStructureItemArray(data: unknown): data is StructureItem[] {
311324 return Array . isArray ( data ) && data . length > 0 && typeof data [ 0 ] === "object" ;
312325}
313326
327+ interface StructureField {
328+ offset : number ;
329+ type : string ;
330+ }
331+
332+ /**
333+ * Validates that a type is known.
334+ */
335+ function validateType ( type : string ) : string {
336+ if ( ! KNOWN_TYPES . has ( type ) ) {
337+ throw new ValidationError ( `Unknown type: "${ type } "` ) ;
338+ }
339+ return type ;
340+ }
341+
314342/**
315343 * Loads a structure data file and computes offsets.
316344 */
317- function loadDatafile ( fpath : string , prefix : string ) : Map < string , string > {
345+ function loadDatafile ( fpath : string , prefix : string ) : Map < string , StructureField > {
318346 console . log ( `loading ${ fpath } ` ) ;
319347 const content = readFile ( fpath ) ;
320348 const parsed = yaml . load ( content ) ;
@@ -325,7 +353,7 @@ function loadDatafile(fpath: string, prefix: string): Map<string, string> {
325353
326354 const data = parsed ;
327355 let curOff = data [ 0 ] ?. offset ?? 0 ;
328- const items = new Map < string , string > ( ) ;
356+ const items = new Map < string , StructureField > ( ) ;
329357
330358 for ( const item of data ) {
331359 if ( item . offset !== undefined && item . offset !== curOff ) {
@@ -341,7 +369,10 @@ function loadDatafile(fpath: string, prefix: string): Map<string, string> {
341369 }
342370
343371 const iid = generateId ( item , prefix ) ;
344- items . set ( iid , `0x${ curOff . toString ( 16 ) } ` ) ;
372+ items . set ( iid , {
373+ offset : curOff ,
374+ type : validateType ( item . type ) ,
375+ } ) ;
345376 curOff += size ;
346377 }
347378
@@ -362,16 +393,17 @@ function getOutputDirName(formatName: string): string {
362393/**
363394 * Writes structure items to the appropriate output file.
364395 */
365- function writeStructureFile ( formatName : string , items : Map < string , string > , structuresDir : string ) : void {
396+ function writeStructureFile ( formatName : string , items : Map < string , StructureField > , structuresDir : string ) : void {
366397 const dirName = getOutputDirName ( formatName ) ;
367398 const outputDir = path . join ( structuresDir , dirName ) ;
368399 const outputFile = path . join ( outputDir , "iesdp.tph" ) ;
369400
370401 fs . mkdirSync ( outputDir , { recursive : true } ) ;
371402
372403 let text = "" ;
373- for ( const [ id , offset ] of items ) {
374- text += `OUTER_SET ${ id } = ${ offset } \n` ;
404+ for ( const [ id , field ] of items ) {
405+ text += `/** @type ${ field . type } */\n` ;
406+ text += `OUTER_SET ${ id } = 0x${ field . offset . toString ( 16 ) } \n` ;
375407 }
376408
377409 fs . writeFileSync ( outputFile , text ) ;
@@ -396,7 +428,7 @@ function processStructures(iesdpDir: string, structuresDir: string): void {
396428 continue ;
397429 }
398430
399- const items = new Map < string , string > ( ) ;
431+ const items = new Map < string , StructureField > ( ) ;
400432 const files = fs . readdirSync ( ffDir ) . sort ( ) ;
401433
402434 for ( const f of files ) {
0 commit comments