Add //+private file to complement //+private (//+private package)

This commit is contained in:
gingerBill
2022-02-02 15:28:49 +00:00
parent a04d849e30
commit 78815778ee
5 changed files with 32 additions and 11 deletions
+6 -3
View File
@@ -3467,9 +3467,12 @@ void check_collect_value_decl(CheckerContext *c, Ast *decl) {
if (entity_visibility_kind == EntityVisiblity_Public &&
(c->scope->flags&ScopeFlag_File) &&
c->scope->file &&
(c->scope->file->flags & AstFile_IsPrivate)) {
entity_visibility_kind = EntityVisiblity_PrivateToPackage;
c->scope->file) {
if (c->scope->file->flags & AstFile_IsPrivatePkg) {
entity_visibility_kind = EntityVisiblity_PrivateToPackage;
} else if (c->scope->file->flags & AstFile_IsPrivateFile) {
entity_visibility_kind = EntityVisiblity_PrivateToFile;
}
}
if (entity_visibility_kind != EntityVisiblity_Public && !(c->scope->flags&ScopeFlag_File)) {
+1 -1
View File
@@ -245,7 +245,7 @@ bool is_entity_exported(Entity *e, bool allow_builtin = false) {
if (e->flags & EntityFlag_NotExported) {
return false;
}
if (e->file != nullptr && (e->file->flags & AstFile_IsPrivate) != 0) {
if (e->file != nullptr && (e->file->flags & (AstFile_IsPrivatePkg|AstFile_IsPrivateFile)) != 0) {
return false;
}
+10 -2
View File
@@ -5535,8 +5535,16 @@ bool parse_file(Parser *p, AstFile *f) {
if (!parse_build_tag(tok, lc)) {
return false;
}
} else if (lc == "+private") {
f->flags |= AstFile_IsPrivate;
} else if (string_starts_with(lc, str_lit("+private"))) {
f->flags |= AstFile_IsPrivatePkg;
String command = string_trim_starts_with(lc, str_lit("+private "));
if (lc == "+private") {
f->flags |= AstFile_IsPrivatePkg;
} else if (command == "package") {
f->flags |= AstFile_IsPrivatePkg;
} else if (command == "file") {
f->flags |= AstFile_IsPrivateFile;
}
} else if (lc == "+lazy") {
if (build_context.ignore_lazy) {
// Ignore
+5 -3
View File
@@ -78,9 +78,11 @@ struct ImportedFile {
};
enum AstFileFlag : u32 {
AstFile_IsPrivate = 1<<0,
AstFile_IsTest = 1<<1,
AstFile_IsLazy = 1<<2,
AstFile_IsPrivatePkg = 1<<0,
AstFile_IsPrivateFile = 1<<1,
AstFile_IsTest = 1<<3,
AstFile_IsLazy = 1<<4,
};
enum AstDelayQueueKind {
+10 -2
View File
@@ -195,8 +195,6 @@ template <isize N> bool operator > (String const &a, char const (&b)[N]) { retu
template <isize N> bool operator <= (String const &a, char const (&b)[N]) { return str_le(a, make_string(cast(u8 *)b, N-1)); }
template <isize N> bool operator >= (String const &a, char const (&b)[N]) { return str_ge(a, make_string(cast(u8 *)b, N-1)); }
gb_inline bool string_starts_with(String const &s, String const &prefix) {
if (prefix.len > s.len) {
return false;
@@ -230,6 +228,16 @@ gb_inline bool string_ends_with(String const &s, u8 suffix) {
return s[s.len-1] == suffix;
}
gb_inline String string_trim_starts_with(String const &s, String const &prefix) {
if (string_starts_with(s, prefix)) {
return substring(s, prefix.len, s.len);
}
return s;
}
gb_inline isize string_extension_position(String const &str) {
isize dot_pos = -1;
isize i = str.len;