LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 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 #include <u.h> | 5 #include <u.h> |
6 #include <libc.h> | 6 #include <libc.h> |
7 #include "go.h" | 7 #include "go.h" |
8 #include "opnames.h" | 8 #include "opnames.h" |
9 | 9 |
10 // | 10 // |
(...skipping 10 matching lines...) Expand all Loading... |
21 // | 21 // |
22 // %V Val* Constant values | 22 // %V Val* Constant values |
23 // | 23 // |
24 // %S Sym* Symbols | 24 // %S Sym* Symbols |
25 // Flags: +,- #: mode (see below) | 25 // Flags: +,- #: mode (see below) |
26 // "%hS" unqualified identifier in any mode | 26 // "%hS" unqualified identifier in any mode |
27 // "%hhS" strip type qualifier off of method name | 27 // "%hhS" strip type qualifier off of method name |
28 // | 28 // |
29 // %T Type* Types | 29 // %T Type* Types |
30 // Flags: +,- #: mode (see below) | 30 // Flags: +,- #: mode (see below) |
31 //» » » 'l' definition instead of name. | 31 //» » » 'l' definition instead of name. |
32 // 'h' omit "func" and receiver in function types | 32 // 'h' omit "func" and receiver in function types |
33 //» » » 'u' (only in -/Sym mode) print type identifiers wit pack
age name instead of prefix. | 33 //» » » 'u' (only in -/Sym mode) print type identifiers wit pack
age name instead of prefix. |
34 // | 34 // |
35 // %N Node* Nodes | 35 // %N Node* Nodes |
36 // Flags: +,- #: mode (see below) | 36 // Flags: +,- #: mode (see below) |
37 // 'h' (only in +/debug mode) suppress recursion | 37 // 'h' (only in +/debug mode) suppress recursion |
38 // 'l' (only in Error mode) print "foo (type Bar)" | 38 // 'l' (only in Error mode) print "foo (type Bar)" |
39 // | 39 // |
40 // %H NodeList* NodeLists | 40 // %H NodeList* NodeLists |
41 // Flags: those of %N | 41 // Flags: those of %N |
42 // ',' separate items with ',' instead of ';' | 42 // ',' separate items with ',' instead of ';' |
43 // | 43 // |
44 //» %Z Strlit*» String literals | 44 //» %Z Strlit*» String literals |
45 // | 45 // |
46 // In mparith1.c: | 46 // In mparith1.c: |
47 // %B Mpint* Big integers | 47 // %B Mpint* Big integers |
48 // %F Mpflt* Big floats | 48 // %F Mpflt* Big floats |
49 // | 49 // |
50 // %S, %T and %N obey use the following flags to set the format mode: | 50 // %S, %T and %N obey use the following flags to set the format mode: |
51 enum { | 51 enum { |
52 FErr, // error mode (default) | 52 FErr, // error mode (default) |
53 FDbg, // "%+N" debug mode | 53 FDbg, // "%+N" debug mode |
54 FExp, // "%#N" export mode | 54 FExp, // "%#N" export mode |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 [TSTRING] = "string", | 535 [TSTRING] = "string", |
536 [TNIL] = "nil", | 536 [TNIL] = "nil", |
537 [TIDEAL] = "ideal", | 537 [TIDEAL] = "ideal", |
538 [TBLANK] = "blank", | 538 [TBLANK] = "blank", |
539 }; | 539 }; |
540 | 540 |
541 static int | 541 static int |
542 typefmt(Fmt *fp, Type *t) | 542 typefmt(Fmt *fp, Type *t) |
543 { | 543 { |
544 Type *t1; | 544 Type *t1; |
| 545 Sym *s; |
545 | 546 |
546 if(t == T) | 547 if(t == T) |
547 return fmtstrcpy(fp, "<T>"); | 548 return fmtstrcpy(fp, "<T>"); |
548 | 549 |
549 if (t == bytetype || t == runetype) { | 550 if (t == bytetype || t == runetype) { |
550 // in %-T mode collapse rune and byte with their originals. | 551 // in %-T mode collapse rune and byte with their originals. |
551 if(fmtmode != FTypeId) | 552 if(fmtmode != FTypeId) |
552 return fmtprint(fp, "%hS", t->sym); | 553 return fmtprint(fp, "%hS", t->sym); |
553 t = types[t->etype]; | 554 t = types[t->etype]; |
554 } | 555 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 if(t1->down) | 674 if(t1->down) |
674 fmtprint(fp, " %T;", t1); | 675 fmtprint(fp, " %T;", t1); |
675 else | 676 else |
676 fmtprint(fp, " %T ", t1); | 677 fmtprint(fp, " %T ", t1); |
677 fmtstrcpy(fp, "}"); | 678 fmtstrcpy(fp, "}"); |
678 } | 679 } |
679 return 0; | 680 return 0; |
680 | 681 |
681 case TFIELD: | 682 case TFIELD: |
682 if(!(fp->flags&FmtShort)) { | 683 if(!(fp->flags&FmtShort)) { |
683 » » » if(t->sym != S && !t->embedded) | 684 » » » s = t->sym; |
684 » » » » fmtprint(fp, "%hS ", t->sym); | 685 » » » switch(fmtmode) { |
685 » » » if((!t->sym || t->embedded) && fmtmode == FExp) | 686 » » » case FErr: |
686 » » » » fmtstrcpy(fp, "? "); | 687 » » » case FExp: |
| 688 » » » » // Take the name from the original, lest we subs
tituted it with .anon%d |
| 689 » » » » if (t->nname) |
| 690 » » » » » s = t->nname->orig->sym; |
| 691 |
| 692 » » » » if((s == S || t->embedded)) { |
| 693 » » » » » fmtstrcpy(fp, "? "); |
| 694 » » » » » break; |
| 695 » » » » } |
| 696 » » » » // fallthrough |
| 697 » » » default: |
| 698 » » » » if(!(s == S || t->embedded)) |
| 699 » » » » » fmtprint(fp, "%hS ", s); |
| 700 » » » } |
687 } | 701 } |
688 | 702 |
689 if(t->isddd) | 703 if(t->isddd) |
690 fmtprint(fp, "...%T", t->type->type); | 704 fmtprint(fp, "...%T", t->type->type); |
691 else | 705 else |
692 fmtprint(fp, "%T", t->type); | 706 fmtprint(fp, "%T", t->type); |
693 | 707 |
694 if(!(fp->flags&FmtShort) && t->note) | 708 if(!(fp->flags&FmtShort) && t->note) |
695 fmtprint(fp, " \"%Z\"", t->note); | 709 fmtprint(fp, " \"%Z\"", t->note); |
696 return 0; | 710 return 0; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 | 795 |
782 case OAS2: | 796 case OAS2: |
783 if(n->colas && !complexinit) { | 797 if(n->colas && !complexinit) { |
784 fmtprint(f, "%,H := %,H", n->list, n->rlist); | 798 fmtprint(f, "%,H := %,H", n->list, n->rlist); |
785 break; | 799 break; |
786 } | 800 } |
787 // fallthrough | 801 // fallthrough |
788 case OAS2DOTTYPE: | 802 case OAS2DOTTYPE: |
789 case OAS2FUNC: | 803 case OAS2FUNC: |
790 case OAS2MAPR: | 804 case OAS2MAPR: |
791 case OAS2MAPW: | |
792 case OAS2RECV: | 805 case OAS2RECV: |
793 fmtprint(f, "%,H = %,H", n->list, n->rlist); | 806 fmtprint(f, "%,H = %,H", n->list, n->rlist); |
794 break; | 807 break; |
795 | 808 |
796 case ORETURN: | 809 case ORETURN: |
797 fmtprint(f, "return %,H", n->list); | 810 fmtprint(f, "return %,H", n->list); |
798 break; | 811 break; |
799 | 812 |
800 case OPROC: | 813 case OPROC: |
801 fmtprint(f, "go %N", n->left); | 814 fmtprint(f, "go %N", n->left); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 [OSEND] = 3, | 973 [OSEND] = 3, |
961 [OANDAND] = 2, | 974 [OANDAND] = 2, |
962 [OOROR] = 1, | 975 [OOROR] = 1, |
963 | 976 |
964 // Statements handled by stmtfmt | 977 // Statements handled by stmtfmt |
965 [OAS] = -1, | 978 [OAS] = -1, |
966 [OAS2] = -1, | 979 [OAS2] = -1, |
967 [OAS2DOTTYPE] = -1, | 980 [OAS2DOTTYPE] = -1, |
968 [OAS2FUNC] = -1, | 981 [OAS2FUNC] = -1, |
969 [OAS2MAPR] = -1, | 982 [OAS2MAPR] = -1, |
970 [OAS2MAPW] = -1, | |
971 [OAS2RECV] = -1, | 983 [OAS2RECV] = -1, |
972 [OASOP] = -1, | 984 [OASOP] = -1, |
973 [OBREAK] = -1, | 985 [OBREAK] = -1, |
974 [OCASE] = -1, | 986 [OCASE] = -1, |
975 [OCONTINUE] = -1, | 987 [OCONTINUE] = -1, |
976 [ODCL] = -1, | 988 [ODCL] = -1, |
977 [ODCLFIELD] = -1, | 989 [ODCLFIELD] = -1, |
978 [ODEFER] = -1, | 990 [ODEFER] = -1, |
979 [OFALL] = -1, | 991 [OFALL] = -1, |
980 [OFOR] = -1, | 992 [OFOR] = -1, |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 dumplist(char *s, NodeList *l) | 1523 dumplist(char *s, NodeList *l) |
1512 { | 1524 { |
1513 print("%s\n%+H\n", s, l); | 1525 print("%s\n%+H\n", s, l); |
1514 } | 1526 } |
1515 | 1527 |
1516 void | 1528 void |
1517 dump(char *s, Node *n) | 1529 dump(char *s, Node *n) |
1518 { | 1530 { |
1519 print("%s [%p]\n%+N\n", s, n, n); | 1531 print("%s [%p]\n%+N\n", s, n, n); |
1520 } | 1532 } |
LEFT | RIGHT |