mirror of
https://github.com/golang/go
synced 2024-11-26 03:07:57 -07:00
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
This commit is contained in:
parent
019c8fc625
commit
389093feec
@ -394,6 +394,7 @@ struct Pkg
|
||||
uchar imported; // export data of this package was parsed
|
||||
char exported; // import line written in export data
|
||||
char direct; // imported directly
|
||||
char safe; // whether the package is marked as safe
|
||||
};
|
||||
|
||||
typedef struct Iter Iter;
|
||||
|
@ -251,7 +251,8 @@ import_package:
|
||||
} else if(strcmp(importpkg->name, $2->name) != 0)
|
||||
yyerror("conflicting names %s and %s for package \"%Z\"", importpkg->name, $2->name, importpkg->path);
|
||||
importpkg->direct = 1;
|
||||
|
||||
importpkg->safe = curio.importsafe;
|
||||
|
||||
if(safemode && !curio.importsafe)
|
||||
yyerror("cannot import unsafe package \"%Z\"", importpkg->path);
|
||||
}
|
||||
|
@ -602,7 +602,7 @@ void
|
||||
importfile(Val *f, int line)
|
||||
{
|
||||
Biobuf *imp;
|
||||
char *file, *p, *q;
|
||||
char *file, *p, *q, *tag;
|
||||
int32 c;
|
||||
int len;
|
||||
Strlit *path;
|
||||
@ -610,8 +610,6 @@ importfile(Val *f, int line)
|
||||
|
||||
USED(line);
|
||||
|
||||
// TODO(rsc): don't bother reloading imports more than once?
|
||||
|
||||
if(f->ctype != CTSTR) {
|
||||
yyerror("import statement not a string");
|
||||
fakeimport();
|
||||
@ -686,7 +684,11 @@ importfile(Val *f, int line)
|
||||
// to the lexer to avoid parsing export data twice.
|
||||
if(importpkg->imported) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user