@@ -2476,6 +2476,79 @@ func (f *Fold) goString(indent int, field string) string {
24762476 }
24772477}
24782478
2479+ // Subobject is a a reference to an offset in an expression. This is
2480+ // used for C++20 manglings of class types used as the type of
2481+ // non-type template arguments.
2482+ //
2483+ // See https://github.com/itanium-cxx-abi/cxx-abi/issues/47.
2484+ type Subobject struct {
2485+ Type AST
2486+ SubExpr AST
2487+ Offset int
2488+ Selectors []int
2489+ PastEnd bool
2490+ }
2491+
2492+ func (so * Subobject ) print (ps * printState ) {
2493+ ps .print (so .SubExpr )
2494+ ps .writeString (".<" )
2495+ ps .print (so .Type )
2496+ ps .writeString (fmt .Sprintf (" at offset %d>" , so .Offset ))
2497+ }
2498+
2499+ func (so * Subobject ) Traverse (fn func (AST ) bool ) {
2500+ if fn (so ) {
2501+ so .Type .Traverse (fn )
2502+ so .SubExpr .Traverse (fn )
2503+ }
2504+ }
2505+
2506+ func (so * Subobject ) Copy (fn func (AST ) AST , skip func (AST ) bool ) AST {
2507+ if skip (so ) {
2508+ return nil
2509+ }
2510+ typ := so .Type .Copy (fn , skip )
2511+ subExpr := so .SubExpr .Copy (fn , skip )
2512+ if typ == nil && subExpr == nil {
2513+ return nil
2514+ }
2515+ if typ == nil {
2516+ typ = so .Type
2517+ }
2518+ if subExpr == nil {
2519+ subExpr = so .SubExpr
2520+ }
2521+ so = & Subobject {
2522+ Type : typ ,
2523+ SubExpr : subExpr ,
2524+ Offset : so .Offset ,
2525+ Selectors : so .Selectors ,
2526+ PastEnd : so .PastEnd ,
2527+ }
2528+ if r := fn (so ); r != nil {
2529+ return r
2530+ }
2531+ return so
2532+ }
2533+
2534+ func (so * Subobject ) GoString () string {
2535+ return so .goString (0 , "" )
2536+ }
2537+
2538+ func (so * Subobject ) goString (indent int , field string ) string {
2539+ var selectors string
2540+ for _ , s := range so .Selectors {
2541+ selectors += fmt .Sprintf (" %d" , s )
2542+ }
2543+ return fmt .Sprintf ("%*s%sSubobject:\n %s\n %s\n %*sOffset: %d\n %*sSelectors:%s\n %*sPastEnd: %t" ,
2544+ indent , "" , field ,
2545+ so .Type .goString (indent + 2 , "Type: " ),
2546+ so .SubExpr .goString (indent + 2 , "SubExpr: " ),
2547+ indent + 2 , "" , so .Offset ,
2548+ indent + 2 , "" , selectors ,
2549+ indent + 2 , "" , so .PastEnd )
2550+ }
2551+
24792552// New is a use of operator new in an expression.
24802553type New struct {
24812554 Op AST
0 commit comments