LEFT | RIGHT |
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 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "debug/elf" | 9 "debug/elf" |
10 "debug/macho" | 10 "debug/macho" |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 return &Type{Size: p.PtrSize + 4, Align: p.PtrSize, C: "
GoString"} | 601 return &Type{Size: p.PtrSize + 4, Align: p.PtrSize, C: "
GoString"} |
602 } | 602 } |
603 if r, ok := goTypes[t.Name]; ok { | 603 if r, ok := goTypes[t.Name]; ok { |
604 if r.Align > p.PtrSize { | 604 if r.Align > p.PtrSize { |
605 r.Align = p.PtrSize | 605 r.Align = p.PtrSize |
606 } | 606 } |
607 return r | 607 return r |
608 } | 608 } |
609 case *ast.SelectorExpr: | 609 case *ast.SelectorExpr: |
610 id, ok := t.X.(*ast.Ident) | 610 id, ok := t.X.(*ast.Ident) |
611 » » if !ok || t.Sel.Name != "Pointer" { | 611 » » if ok && id.Name == "unsafe" && t.Sel.Name == "Pointer" { |
612 » » » break | 612 » » » return &Type{Size: p.PtrSize, Align: p.PtrSize, C: "void
*"} |
613 » » } | |
614 | |
615 » » // Check if it's unsafe.Pointer. | |
616 » » for _, d := range p.Decl { | |
617 » » » gd, ok := d.(*ast.GenDecl) | |
618 » » » if !ok || gd.Tok != token.IMPORT { | |
619 » » » » continue | |
620 » » » } | |
621 » » » for _, spec := range gd.Specs { | |
622 » » » » s, ok := spec.(*ast.ImportSpec) | |
623 » » » » if !ok || string(s.Path.Value) != "\"unsafe\"" { | |
624 » » » » » continue | |
625 » » » » } | |
626 » » » » if (s.Name == nil && id.Name == "unsafe") || | |
627 » » » » » (s.Name != nil && id.Name == s.Name.Name
) { | |
628 » » » » » return &Type{Size: p.PtrSize, Align: p.P
trSize, C: "void*"} | |
629 » » » » } | |
630 » » » } | |
631 } | 613 } |
632 } | 614 } |
633 error(e.Pos(), "unrecognized Go type %T", e) | 615 error(e.Pos(), "unrecognized Go type %T", e) |
634 return &Type{Size: 4, Align: 4, C: "int"} | 616 return &Type{Size: 4, Align: 4, C: "int"} |
635 } | 617 } |
636 | 618 |
637 const gccProlog = ` | 619 const gccProlog = ` |
638 // Usual nonsense: if x and y are not equal, the type will be invalid | 620 // Usual nonsense: if x and y are not equal, the type will be invalid |
639 // (have a negative array count) and an inscrutable error will come | 621 // (have a negative array count) and an inscrutable error will come |
640 // out of the compiler and hopefully mention "name". | 622 // out of the compiler and hopefully mention "name". |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 typedef unsigned short ushort; | 681 typedef unsigned short ushort; |
700 typedef long long int64; | 682 typedef long long int64; |
701 typedef unsigned long long uint64; | 683 typedef unsigned long long uint64; |
702 typedef __SIZE_TYPE__ uintptr; | 684 typedef __SIZE_TYPE__ uintptr; |
703 | 685 |
704 typedef struct { char *p; int n; } GoString; | 686 typedef struct { char *p; int n; } GoString; |
705 typedef void *GoMap; | 687 typedef void *GoMap; |
706 typedef void *GoChan; | 688 typedef void *GoChan; |
707 typedef struct { void *t; void *v; } GoInterface; | 689 typedef struct { void *t; void *v; } GoInterface; |
708 ` | 690 ` |
LEFT | RIGHT |