diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-04-20 15:44:41 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-04-20 15:44:41 +0200 |
commit | 50104cc32a498f7517a51c8dc93106c51c7a54b4 (patch) | |
tree | 47af80be259cc7c45d0eaec7d42e61fa38c8e4fb /src/cmd/gc | |
parent | c072558b90f1bbedc2022b0f30c8b1ac4712538e (diff) | |
download | golang-upstream/2011.03.07.1.tar.gz |
Imported Upstream version 2011.03.07.1upstream/2011.03.07.1
Diffstat (limited to 'src/cmd/gc')
-rw-r--r-- | src/cmd/gc/const.c | 6 | ||||
-rw-r--r-- | src/cmd/gc/doc.go | 2 | ||||
-rw-r--r-- | src/cmd/gc/export.c | 12 | ||||
-rw-r--r-- | src/cmd/gc/go.y | 9 | ||||
-rw-r--r-- | src/cmd/gc/init.c | 27 | ||||
-rw-r--r-- | src/cmd/gc/reflect.c | 33 | ||||
-rw-r--r-- | src/cmd/gc/subr.c | 11 | ||||
-rw-r--r-- | src/cmd/gc/typecheck.c | 6 |
8 files changed, 73 insertions, 33 deletions
diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c index 0ee693c02..a54c40f6c 100644 --- a/src/cmd/gc/const.c +++ b/src/cmd/gc/const.c @@ -1051,12 +1051,12 @@ int cmpslit(Node *l, Node *r) { int32 l1, l2, i, m; - char *s1, *s2; + uchar *s1, *s2; l1 = l->val.u.sval->len; l2 = r->val.u.sval->len; - s1 = l->val.u.sval->s; - s2 = r->val.u.sval->s; + s1 = (uchar*)l->val.u.sval->s; + s2 = (uchar*)r->val.u.sval->s; m = l1; if(l2 < m) diff --git a/src/cmd/gc/doc.go b/src/cmd/gc/doc.go index 21e1b103b..3fe7fafdd 100644 --- a/src/cmd/gc/doc.go +++ b/src/cmd/gc/doc.go @@ -43,6 +43,8 @@ Flags: disable optimization -S write assembly language text to standard output + -u + disallow importing packages not marked as safe -V print the compiler version diff --git a/src/cmd/gc/export.c b/src/cmd/gc/export.c index 594509915..09b963f27 100644 --- a/src/cmd/gc/export.c +++ b/src/cmd/gc/export.c @@ -51,6 +51,12 @@ exportname(char *s) return isupperrune(r); } +static int +initname(char *s) +{ + return strcmp(s, "init") == 0; +} + void autoexport(Node *n, int ctxt) { @@ -60,7 +66,7 @@ autoexport(Node *n, int ctxt) return; if(n->ntype && n->ntype->op == OTFUNC && n->ntype->left) // method return; - if(exportname(n->sym->name) || strcmp(n->sym->name, "init") == 0) + if(exportname(n->sym->name) || initname(n->sym->name)) exportsym(n); else packagesym(n); @@ -304,7 +310,7 @@ importsym(Sym *s, int op) // mark the symbol so it is not reexported if(s->def == N) { - if(exportname(s->name)) + if(exportname(s->name) || initname(s->name)) s->flags |= SymExport; else s->flags |= SymPackage; // package scope @@ -374,7 +380,7 @@ importvar(Sym *s, Type *t, int ctxt) { Node *n; - if(!exportname(s->name) && !mypackage(s)) + if(!exportname(s->name) && !initname(s->name) && !mypackage(s)) return; importsym(s, ONAME); diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 86e3cae33..4b838a491 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -640,10 +640,15 @@ if_stmt: { markdcl(); } - if_header loop_body + if_header + { + if($3->ntest == N) + yyerror("missing condition in if statement"); + } + loop_body { $$ = $3; - $$->nbody = $4; + $$->nbody = $5; // no popdcl; maybe there's an LELSE } diff --git a/src/cmd/gc/init.c b/src/cmd/gc/init.c index dc073443e..af4eb0336 100644 --- a/src/cmd/gc/init.c +++ b/src/cmd/gc/init.c @@ -30,19 +30,19 @@ renameinit(Node *n) /* * hand-craft the following initialization code - * var initdone·<file> uint8 (1) - * func Init·<file>() (2) - * if initdone·<file> != 0 { (3) - * if initdone·<file> == 2 (4) + * var initdone· uint8 (1) + * func init() (2) + * if initdone· != 0 { (3) + * if initdone· == 2 (4) * return * throw(); (5) * } - * initdone.<file> = 1; (6) + * initdone· = 1; (6) * // over all matching imported symbols - * <pkg>.init·<file>() (7) + * <pkg>.init() (7) * { <init stmts> } (8) - * init·<file>() // if any (9) - * initdone.<file> = 2; (10) + * init·<n>() // if any (9) + * initdone· = 2; (10) * return (11) * } */ @@ -79,7 +79,7 @@ anyinit(NodeList *n) // are there any imported init functions for(h=0; h<NHASH; h++) for(s = hash[h]; s != S; s = s->link) { - if(s->name[0] != 'I' || strncmp(s->name, "Init·", 6) != 0) + if(s->name[0] != 'i' || strcmp(s->name, "init") != 0) continue; if(s->def == N) continue; @@ -118,12 +118,7 @@ fninit(NodeList *n) // (2) maxarg = 0; - snprint(namebuf, sizeof(namebuf), "Init·"); - - // this is a botch since we need a known name to - // call the top level init function out of rt0 - if(strcmp(localpkg->name, "main") == 0) - snprint(namebuf, sizeof(namebuf), "init"); + snprint(namebuf, sizeof(namebuf), "init"); fn = nod(ODCLFUNC, N, N); initsym = lookup(namebuf); @@ -154,7 +149,7 @@ fninit(NodeList *n) // (7) for(h=0; h<NHASH; h++) for(s = hash[h]; s != S; s = s->link) { - if(s->name[0] != 'I' || strncmp(s->name, "Init·", 6) != 0) + if(s->name[0] != 'i' || strcmp(s->name, "init") != 0) continue; if(s->def == N) continue; diff --git a/src/cmd/gc/reflect.c b/src/cmd/gc/reflect.c index 36c245d47..8129bf1ce 100644 --- a/src/cmd/gc/reflect.c +++ b/src/cmd/gc/reflect.c @@ -10,6 +10,7 @@ static NodeList* signatlist; static Sym* dtypesym(Type*); +static Sym* weaktypesym(Type*); static int sigcmp(Sig *a, Sig *b) @@ -570,9 +571,17 @@ dcommontype(Sym *s, int ot, Type *t) { int i; Sym *s1; + Sym *sptr; char *p; dowidth(t); + + sptr = nil; + if(t->sym != nil && !isptr[t->etype]) + sptr = dtypesym(ptrto(t)); + else + sptr = weaktypesym(ptrto(t)); + s1 = dextratype(t); // empty interface pointing at this type. @@ -592,7 +601,8 @@ dcommontype(Sym *s, int ot, Type *t) // fieldAlign uint8; // kind uint8; // string *string; - // *nameInfo; + // *extraType; + // ptrToThis *Type // } ot = duintptr(s, ot, t->width); ot = duint32(s, ot, typehash(t)); @@ -616,7 +626,7 @@ dcommontype(Sym *s, int ot, Type *t) ot = dsymptr(s, ot, s1, 0); // extraType else ot = duintptr(s, ot, 0); - + ot = dsymptr(s, ot, sptr, 0); // ptr to type return ot; } @@ -662,6 +672,25 @@ typename(Type *t) } static Sym* +weaktypesym(Type *t) +{ + char *p; + Sym *s; + static Pkg *weak; + + if(weak == nil) { + weak = mkpkg(strlit("weak.type")); + weak->name = "weak.type"; + weak->prefix = "weak.type"; // not weak%2etype + } + + p = smprint("%#-T", t); + s = pkglookup(p, weak); + free(p); + return s; +} + +static Sym* dtypesym(Type *t) { int ot, n, isddd, dupok; diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index 0755ca3cd..142e5ba41 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -203,7 +203,6 @@ fatal(char *fmt, ...) flusherrors(); -*(int*)0=0; print("%L: internal compiler error: ", lineno); va_start(arg, fmt); vfprint(1, fmt, arg); @@ -1909,8 +1908,12 @@ assignop(Type *src, Type *dst, char **why) return 0; } if(src->etype == TINTER && dst->etype != TBLANK) { - if(why != nil) - *why = ": need type assertion"; + if(why != nil) { + if(isptrto(dst, TINTER)) + *why = smprint(":\n\t%T is interface, not pointer to interface", src); + else + *why = ": need type assertion"; + } return 0; } @@ -2265,7 +2268,7 @@ syslook(char *name, int copy) s = pkglookup(name, runtimepkg); if(s == S || s->def == N) - fatal("looksys: cant find runtime.%s", name); + fatal("syslook: can't find runtime.%s", name); if(!copy) return s->def; diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 5edca964a..3e8f35877 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -318,7 +318,7 @@ reswitch: n->left = N; goto ret; } - if(!isptr[t->etype]) { + if(!isptr[t->etype] || (t->type != T && t->type->etype == TANY) /* unsafe.Pointer */) { yyerror("invalid indirect of %+N", n->left); goto error; } @@ -1613,7 +1613,7 @@ typecheckaste(int op, Node *call, int isddd, Type *tstruct, NodeList *nl, char * exportassignok(tn->type, desc); if(assignop(tn->type, tl->type->type, &why) == 0) { if(call != N) - yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type->type, desc, call, why); + yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type->type, call, why); else yyerror("cannot use %T as type %T in %s%s", tn->type, tl->type->type, desc, why); } @@ -1625,7 +1625,7 @@ typecheckaste(int op, Node *call, int isddd, Type *tstruct, NodeList *nl, char * exportassignok(tn->type, desc); if(assignop(tn->type, tl->type, &why) == 0) { if(call != N) - yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type, desc, call, why); + yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type, call, why); else yyerror("cannot use %T as type %T in %s%s", tn->type, tl->type, desc, why); } |