Commit 389093fe authored by David Symonds's avatar David Symonds

cmd/gc: preserve safe annotation of package def.

A package file may begin as either "package foo" or
"package foo safe". The latter is relevant when using -u.
https://golang.org/cl/6903059 resulted in the distinction
being dropped when a package was read for the second or later time.
This CL records whether that "safe" tag was present,
and includes it in the dummy statement generated for the lexer.

R=golang-dev, r, minux.ma, daniel.morsing, iant
CC=golang-dev
https://golang.org/cl/8255044
parent 019c8fc6
...@@ -394,6 +394,7 @@ struct Pkg ...@@ -394,6 +394,7 @@ struct Pkg
uchar imported; // export data of this package was parsed uchar imported; // export data of this package was parsed
char exported; // import line written in export data char exported; // import line written in export data
char direct; // imported directly char direct; // imported directly
char safe; // whether the package is marked as safe
}; };
typedef struct Iter Iter; typedef struct Iter Iter;
......
...@@ -251,7 +251,8 @@ import_package: ...@@ -251,7 +251,8 @@ import_package:
} else if(strcmp(importpkg->name, $2->name) != 0) } else if(strcmp(importpkg->name, $2->name) != 0)
yyerror("conflicting names %s and %s for package \"%Z\"", importpkg->name, $2->name, importpkg->path); yyerror("conflicting names %s and %s for package \"%Z\"", importpkg->name, $2->name, importpkg->path);
importpkg->direct = 1; importpkg->direct = 1;
importpkg->safe = curio.importsafe;
if(safemode && !curio.importsafe) if(safemode && !curio.importsafe)
yyerror("cannot import unsafe package \"%Z\"", importpkg->path); yyerror("cannot import unsafe package \"%Z\"", importpkg->path);
} }
......
...@@ -602,7 +602,7 @@ void ...@@ -602,7 +602,7 @@ void
importfile(Val *f, int line) importfile(Val *f, int line)
{ {
Biobuf *imp; Biobuf *imp;
char *file, *p, *q; char *file, *p, *q, *tag;
int32 c; int32 c;
int len; int len;
Strlit *path; Strlit *path;
...@@ -610,8 +610,6 @@ importfile(Val *f, int line) ...@@ -610,8 +610,6 @@ importfile(Val *f, int line)
USED(line); USED(line);
// TODO(rsc): don't bother reloading imports more than once?
if(f->ctype != CTSTR) { if(f->ctype != CTSTR) {
yyerror("import statement not a string"); yyerror("import statement not a string");
fakeimport(); fakeimport();
...@@ -686,7 +684,11 @@ importfile(Val *f, int line) ...@@ -686,7 +684,11 @@ importfile(Val *f, int line)
// to the lexer to avoid parsing export data twice. // to the lexer to avoid parsing export data twice.
if(importpkg->imported) { if(importpkg->imported) {
file = strdup(namebuf); file = strdup(namebuf);
p = smprint("package %s\n$$\n", importpkg->name); tag = "";
if(importpkg->safe) {
tag = "safe";
}
p = smprint("package %s %s\n$$\n", importpkg->name, tag);
cannedimports(file, p); cannedimports(file, p);
return; return;
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment