Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect //+private and the file/package variant #269

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/common/ast.odin
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ collect_value_decl :: proc(
skip_private: bool,
) {
if value_decl, ok := stmt.derived.(^ast.Value_Decl); ok {
is_deprecated := false
is_deprecated := false
is_private_file := false
is_package_file := false
is_builtin := false
is_private_pkg := false
is_builtin := false

for attribute in value_decl.attributes {
for elem in attribute.elems {
Expand All @@ -215,10 +215,10 @@ collect_value_decl :: proc(
case "\"file\"":
is_private_file = true
case "package":
is_package_file = true
is_private_pkg = true
}
} else {
is_package_file = true
is_private_pkg = true
}
}
}
Expand All @@ -229,7 +229,7 @@ collect_value_decl :: proc(
case "builtin":
is_builtin = true
case "private":
is_package_file = true
is_private_pkg = true
}
}
}
Expand All @@ -238,6 +238,25 @@ collect_value_decl :: proc(
if is_private_file && skip_private {
return
}

// If a private status is not explicitly set with an attribute above the declaration
// check the file comment.
if !is_private_file && !is_private_pkg && file.docs != nil {
for comment in file.docs.list {
txt := comment.text
if strings.has_prefix(txt, "//+private") {
txt = strings.trim_prefix(txt, "//+private")
is_private_pkg = true

if strings.has_prefix(txt, " ") {
txt = strings.trim_space(txt)
if txt == "file" {
is_private_file = true
}
}
}
}
}

for name, i in value_decl.names {
str := get_ast_node_string(name, file.src)
Expand All @@ -254,7 +273,7 @@ collect_value_decl :: proc(
attributes = value_decl.attributes[:],
deprecated = is_deprecated,
builtin = is_builtin,
package_private = is_package_file,
package_private = is_private_pkg,
},
)
} else {
Expand All @@ -270,7 +289,7 @@ collect_value_decl :: proc(
attributes = value_decl.attributes[:],
deprecated = is_deprecated,
builtin = is_builtin,
package_private = is_package_file,
package_private = is_private_pkg,
},
)
}
Expand Down
Loading