@@ -36,7 +36,6 @@ export class CFuncType {
3636}
3737
3838export class CPointer {
39- readonly typeName = "pointer" ;
4039 readonly bytes = 4 ;
4140 readonly alignment = 4 ;
4241 readonly incomplete = false ;
@@ -57,10 +56,13 @@ export class CPointer {
5756 get pointerGeneration ( ) : this {
5857 return this ; // no pointer generation (already a pointer!)
5958 }
59+
60+ get typeName ( ) : string {
61+ return this . type . typeName + "*" + ( this . qualifier ? " " + this . qualifier : "" ) ;
62+ }
6063}
6164
6265export class CArray {
63- readonly typeName = "array" ;
6466 readonly alignment : number ;
6567
6668 constructor ( readonly node : ParseNode | undefined , readonly type : CType , public length ?: number ) {
@@ -84,6 +86,14 @@ export class CArray {
8486 get pointerGeneration ( ) : CPointer {
8587 return addQualifier ( new CPointer ( this . node , this . type , false , this ) , getQualifier ( this ) ) ;
8688 }
89+
90+ get typeName ( ) : string {
91+ if ( this . length ) {
92+ return this . type . typeName + "[" + this . length + "]" ;
93+ } else {
94+ return this . type . typeName + "[]" ;
95+ }
96+ }
8797}
8898
8999export type CCompound = CStruct | CUnion | CEnum ;
@@ -93,7 +103,6 @@ export class CCompoundMember {
93103}
94104
95105export class CStruct {
96- readonly typeName = "struct" ;
97106 private _members : ReadonlyArray < CCompoundMember > | undefined ;
98107
99108 constructor ( public node : ParseNode | undefined , readonly name : string | undefined ) {
@@ -155,10 +164,17 @@ export class CStruct {
155164 get pointerGeneration ( ) : this {
156165 return this ; // no pointer generation
157166 }
167+
168+ get typeName ( ) : string {
169+ if ( this . name ) {
170+ return "struct " + this . name ;
171+ } else {
172+ return "struct {" + this . members . map ( x => x . type . typeName + " " + x . name + ";" ) . join ( " " ) + "}" ;
173+ }
174+ }
158175}
159176
160177export class CUnion {
161- readonly typeName = "union" ;
162178 private _members : ReadonlyArray < CCompoundMember > | undefined ;
163179
164180 constructor ( public node : ParseNode | undefined , readonly name : string | undefined ) {
@@ -212,6 +228,14 @@ export class CUnion {
212228 get pointerGeneration ( ) : this {
213229 return this ; // no pointer generation
214230 }
231+
232+ get typeName ( ) : string {
233+ if ( this . name ) {
234+ return "union " + this . name ;
235+ } else {
236+ return "union {" + this . members . map ( x => x . type . typeName + " " + x . name + ";" ) . join ( " " ) + "}" ;
237+ }
238+ }
215239}
216240
217241export type CEnumValue = { name : string , value : bigint } ;
@@ -260,17 +284,16 @@ export class CVoid {
260284}
261285
262286export class CArithmetic {
263- readonly typeName = "arithmetic" ;
264287 readonly incomplete = false ;
265288 readonly node = undefined ;
266289 readonly alignment : number ;
267290
268- private constructor ( readonly name : string , readonly bytes : number , readonly type : "float" | "signed" | "unsigned" ) {
291+ private constructor ( readonly typeName : string , readonly bytes : number , readonly type : "float" | "signed" | "unsigned" ) {
269292 this . alignment = bytes ;
270293 }
271294
272295 equals ( t : object ) : boolean {
273- return t instanceof CArithmetic && t . name === this . name && t . type === this . type && t . bytes === this . bytes ;
296+ return t instanceof CArithmetic && t . typeName === this . typeName && t . type === this . type && t . bytes === this . bytes ;
274297 }
275298
276299 get minValue ( ) : bigint | number {
@@ -347,13 +370,6 @@ export function addQualifier<T extends CType>(t: T, qualifier?: TypeQualifier):
347370 return type ;
348371}
349372
350- function withoutQualifiers < T extends CType > ( t : T ) : T {
351- if ( Object . prototype . hasOwnProperty . call ( t , "qualifier" ) ) {
352- return ( t as CQualifiedType < T > ) . _base ?? t ;
353- }
354- return t ;
355- }
356-
357373export function getQualifier ( t : CQualifiedType < CType > ) : TypeQualifier | undefined {
358374 return t ?. qualifier ;
359375}
0 commit comments