mirror of
https://github.com/golang/go
synced 2024-10-03 22:21:22 -06:00
structure field annotation strings
R=ken OCL=18176 CL=18176
This commit is contained in:
parent
ebf14c625d
commit
f27aaf4819
@ -450,10 +450,12 @@ stotype(Node *n, Type **t)
|
|||||||
Type *f;
|
Type *f;
|
||||||
Iter save;
|
Iter save;
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
String *note;
|
||||||
|
|
||||||
n = listfirst(&save, &n);
|
n = listfirst(&save, &n);
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
|
note = nil;
|
||||||
if(n == N) {
|
if(n == N) {
|
||||||
*t = T;
|
*t = T;
|
||||||
return t;
|
return t;
|
||||||
@ -471,8 +473,20 @@ loop:
|
|||||||
if(n->type->etype == TARRAY && n->type->bound < 0)
|
if(n->type->etype == TARRAY && n->type->bound < 0)
|
||||||
yyerror("type of a structure field cannot be an open array");
|
yyerror("type of a structure field cannot be an open array");
|
||||||
|
|
||||||
|
switch(n->val.ctype) {
|
||||||
|
case CTSTR:
|
||||||
|
note = n->val.u.sval;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
yyerror("structure field annotation must be string");
|
||||||
|
case CTxxx:
|
||||||
|
note = nil;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
f = typ(TFIELD);
|
f = typ(TFIELD);
|
||||||
f->type = n->type;
|
f->type = n->type;
|
||||||
|
f->note = note;
|
||||||
|
|
||||||
if(n->left != N && n->left->op == ONAME) {
|
if(n->left != N && n->left->op == ONAME) {
|
||||||
f->nname = n->left;
|
f->nname = n->left;
|
||||||
|
@ -147,6 +147,7 @@ struct Type
|
|||||||
|
|
||||||
// TFIELD
|
// TFIELD
|
||||||
Type* down; // also used in TMAP
|
Type* down; // also used in TMAP
|
||||||
|
String* note; // literal string annotation
|
||||||
|
|
||||||
// TARRAY
|
// TARRAY
|
||||||
int32 bound; // negative is dynamic array
|
int32 bound; // negative is dynamic array
|
||||||
|
@ -72,6 +72,7 @@
|
|||||||
%type <type> non_name_type Anon_fn_type Bnon_fn_type
|
%type <type> non_name_type Anon_fn_type Bnon_fn_type
|
||||||
%type <type> Anon_chan_type Bnon_chan_type
|
%type <type> Anon_chan_type Bnon_chan_type
|
||||||
%type <type> indcl fnlitdcl dotdotdot
|
%type <type> indcl fnlitdcl dotdotdot
|
||||||
|
%type <val> oliteral
|
||||||
|
|
||||||
%type <val> hidden_constant
|
%type <val> hidden_constant
|
||||||
%type <node> hidden_dcl hidden_structdcl
|
%type <node> hidden_dcl hidden_structdcl
|
||||||
@ -1388,10 +1389,11 @@ structdcl:
|
|||||||
$$ = nod(ODCLFIELD, $1, N);
|
$$ = nod(ODCLFIELD, $1, N);
|
||||||
$$ = nod(OLIST, $$, $3);
|
$$ = nod(OLIST, $$, $3);
|
||||||
}
|
}
|
||||||
| new_name type
|
| new_name type oliteral
|
||||||
{
|
{
|
||||||
$$ = nod(ODCLFIELD, $1, N);
|
$$ = nod(ODCLFIELD, $1, N);
|
||||||
$$->type = $2;
|
$$->type = $2;
|
||||||
|
$$->val = $3;
|
||||||
}
|
}
|
||||||
| embed
|
| embed
|
||||||
| '*' embed
|
| '*' embed
|
||||||
@ -1761,6 +1763,12 @@ oexport:
|
|||||||
$$ = 1;
|
$$ = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oliteral:
|
||||||
|
{
|
||||||
|
$$.ctype = CTxxx;
|
||||||
|
}
|
||||||
|
| LLITERAL
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* import syntax from header of
|
* import syntax from header of
|
||||||
* an output package
|
* an output package
|
||||||
|
@ -1078,9 +1078,12 @@ Tpretty(Fmt *fp, Type *t)
|
|||||||
if(t->sym == S || t->embedded) {
|
if(t->sym == S || t->embedded) {
|
||||||
if(exporting)
|
if(exporting)
|
||||||
fmtprint(fp, "? ");
|
fmtprint(fp, "? ");
|
||||||
return fmtprint(fp, "%T", t->type);
|
fmtprint(fp, "%T", t->type);
|
||||||
}
|
} else
|
||||||
return fmtprint(fp, "%hS %T", t->sym, t->type);
|
fmtprint(fp, "%hS %T", t->sym, t->type);
|
||||||
|
if(t->note)
|
||||||
|
fmtprint(fp, " \"%Z\"", t->note);
|
||||||
|
return 0;
|
||||||
|
|
||||||
case TFORW:
|
case TFORW:
|
||||||
if(exporting)
|
if(exporting)
|
||||||
|
Loading…
Reference in New Issue
Block a user