OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Annotate Ref in Prog with C types by parsing gcc debug output. | 5 // Annotate Ref in Prog with C types by parsing gcc debug output. |
6 // Conversion of debug output to Go types. | 6 // Conversion of debug output to Go types. |
7 | 7 |
8 package main | 8 package main |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 if dt.ByteSize < 0 && tag == "" { // opaque unnamed struct - sho
uld not be possible | 1229 if dt.ByteSize < 0 && tag == "" { // opaque unnamed struct - sho
uld not be possible |
1230 break | 1230 break |
1231 } | 1231 } |
1232 if tag == "" { | 1232 if tag == "" { |
1233 tag = "__" + strconv.Itoa(tagGen) | 1233 tag = "__" + strconv.Itoa(tagGen) |
1234 tagGen++ | 1234 tagGen++ |
1235 } else if t.C.Empty() { | 1235 } else if t.C.Empty() { |
1236 t.C.Set(dt.Kind + " " + tag) | 1236 t.C.Set(dt.Kind + " " + tag) |
1237 } | 1237 } |
1238 name := c.Ident("_Ctype_" + dt.Kind + "_" + tag) | 1238 name := c.Ident("_Ctype_" + dt.Kind + "_" + tag) |
1239 » » t.Go = name // publish before recursive calls | 1239 » » direct := *godefs && dt.StructName == "" |
1240 » » goIdent[name.Name] = name | 1240 » » if !direct { |
| 1241 » » » t.Go = name |
| 1242 » » » goIdent[name.Name] = name |
| 1243 » » } |
1241 if dt.ByteSize < 0 { | 1244 if dt.ByteSize < 0 { |
1242 // Size calculation in c.Struct/c.Opaque will die with s
ize=-1 (unknown), | 1245 // Size calculation in c.Struct/c.Opaque will die with s
ize=-1 (unknown), |
1243 // so execute the basic things that the struct case woul
d do | 1246 // so execute the basic things that the struct case woul
d do |
1244 // other than try to determine a Go representation. | 1247 // other than try to determine a Go representation. |
1245 tt := *t | 1248 tt := *t |
1246 tt.C = &TypeRepr{"%s %s", []interface{}{dt.Kind, tag}} | 1249 tt.C = &TypeRepr{"%s %s", []interface{}{dt.Kind, tag}} |
1247 tt.Go = c.Ident("struct{}") | 1250 tt.Go = c.Ident("struct{}") |
1248 typedef[name.Name] = &tt | 1251 typedef[name.Name] = &tt |
1249 break | 1252 break |
1250 } | 1253 } |
1251 switch dt.Kind { | 1254 switch dt.Kind { |
1252 case "class", "union": | 1255 case "class", "union": |
1253 t.Go = c.Opaque(t.Size) | 1256 t.Go = c.Opaque(t.Size) |
1254 if t.C.Empty() { | 1257 if t.C.Empty() { |
1255 t.C.Set("__typeof__(unsigned char[%d])", t.Size) | 1258 t.C.Set("__typeof__(unsigned char[%d])", t.Size) |
1256 } | 1259 } |
1257 t.Align = 1 // TODO: should probably base this on field
alignment. | 1260 t.Align = 1 // TODO: should probably base this on field
alignment. |
1258 typedef[name.Name] = t | 1261 typedef[name.Name] = t |
1259 case "struct": | 1262 case "struct": |
1260 g, csyntax, align := c.Struct(dt, pos) | 1263 g, csyntax, align := c.Struct(dt, pos) |
1261 if t.C.Empty() { | 1264 if t.C.Empty() { |
1262 t.C.Set(csyntax) | 1265 t.C.Set(csyntax) |
1263 } | 1266 } |
1264 t.Align = align | 1267 t.Align = align |
1265 » » » tt := *t | 1268 » » » if direct { |
1266 » » » if tag != "" { | 1269 » » » » t.Go = g |
1267 » » » » tt.C = &TypeRepr{"struct %s", []interface{}{tag}
} | 1270 » » » } else { |
| 1271 » » » » tt := *t |
| 1272 » » » » if tag != "" { |
| 1273 » » » » » tt.C = &TypeRepr{"struct %s", []interfac
e{}{tag}} |
| 1274 » » » » } |
| 1275 » » » » tt.Go = g |
| 1276 » » » » typedef[name.Name] = &tt |
1268 } | 1277 } |
1269 tt.Go = g | |
1270 typedef[name.Name] = &tt | |
1271 } | 1278 } |
1272 | 1279 |
1273 case *dwarf.TypedefType: | 1280 case *dwarf.TypedefType: |
1274 // Record typedef for printing. | 1281 // Record typedef for printing. |
1275 if dt.Name == "_GoString_" { | 1282 if dt.Name == "_GoString_" { |
1276 // Special C name for Go string type. | 1283 // Special C name for Go string type. |
1277 // Knows string layout used by compilers: pointer plus l
ength, | 1284 // Knows string layout used by compilers: pointer plus l
ength, |
1278 // which rounds up to 2 pointers after alignment. | 1285 // which rounds up to 2 pointers after alignment. |
1279 t.Go = c.string | 1286 t.Go = c.string |
1280 t.Size = c.ptrSize * 2 | 1287 t.Size = c.ptrSize * 2 |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 } | 1729 } |
1723 if prefix == "" { | 1730 if prefix == "" { |
1724 prefix = n.Name[:i+1] | 1731 prefix = n.Name[:i+1] |
1725 } else if prefix != n.Name[:i+1] { | 1732 } else if prefix != n.Name[:i+1] { |
1726 return "" | 1733 return "" |
1727 } | 1734 } |
1728 } | 1735 } |
1729 } | 1736 } |
1730 return prefix | 1737 return prefix |
1731 } | 1738 } |
OLD | NEW |