file-local / package-local decls
This commit is contained in:
+51
-18
@@ -56,6 +56,12 @@ Numeric_Category :: enum u8 {
|
||||
Float,
|
||||
}
|
||||
|
||||
Visibility :: enum u8 {
|
||||
Public,
|
||||
Package,
|
||||
File,
|
||||
}
|
||||
|
||||
Kind :: enum u8 {
|
||||
Invalid,
|
||||
Void,
|
||||
@@ -109,7 +115,7 @@ Node :: struct {
|
||||
tuple: bool,
|
||||
opaque: bool,
|
||||
declared: bool,
|
||||
package_hidden: bool,
|
||||
visibility: Visibility,
|
||||
explicit_backing: bool,
|
||||
}
|
||||
|
||||
@@ -193,13 +199,21 @@ intern :: proc(store: ^Store, candidate: Node) -> Type {
|
||||
return id
|
||||
}
|
||||
|
||||
named :: proc(store: ^Store, pkg, name: u32, qualifier: u32 = 0, file: u32 = 0xffff_ffff, package_hidden := false) -> Type {
|
||||
normalized_file := file if qualifier != 0 else u32(0)
|
||||
named :: proc(
|
||||
store: ^Store,
|
||||
pkg, name: u32,
|
||||
qualifier: u32 = 0,
|
||||
file: u32 = 0xffff_ffff,
|
||||
visibility := Visibility.Public,
|
||||
) -> Type {
|
||||
normalized_file := file if qualifier != 0 || visibility == .File else u32(0)
|
||||
for existing, index in store.nodes {
|
||||
if (existing.kind == .Named || existing.kind == .Alias || existing.kind == .Distinct ||
|
||||
existing.kind == .Enum || existing.kind == .Struct || existing.kind == .Union) &&
|
||||
existing.pkg == pkg && existing.name == name && existing.qualifier == qualifier &&
|
||||
(qualifier == 0 || existing.file == normalized_file) {
|
||||
((qualifier != 0 && existing.file == normalized_file) ||
|
||||
(qualifier == 0 && visibility == .File && existing.visibility == .File && existing.file == normalized_file) ||
|
||||
(qualifier == 0 && visibility != .File && existing.visibility != .File)) {
|
||||
return DYNAMIC_START+Type(index)
|
||||
}
|
||||
}
|
||||
@@ -209,22 +223,41 @@ named :: proc(store: ^Store, pkg, name: u32, qualifier: u32 = 0, file: u32 = 0xf
|
||||
name=name,
|
||||
qualifier=qualifier,
|
||||
file=normalized_file,
|
||||
visibility=visibility,
|
||||
})
|
||||
}
|
||||
|
||||
find_named :: proc(store: ^Store, pkg, name: u32, qualifier: u32 = 0, file: u32 = 0xffff_ffff) -> Type {
|
||||
fallback := INVALID
|
||||
for existing, index in store.nodes {
|
||||
if (existing.kind == .Named || existing.kind == .Alias || existing.kind == .Distinct ||
|
||||
existing.kind == .Enum || existing.kind == .Struct || existing.kind == .Union) &&
|
||||
existing.pkg == pkg && existing.name == name && existing.qualifier == qualifier &&
|
||||
(!existing.package_hidden || file != 0xffff_ffff) {
|
||||
return DYNAMIC_START+Type(index)
|
||||
if (existing.kind != .Named && existing.kind != .Alias && existing.kind != .Distinct &&
|
||||
existing.kind != .Enum && existing.kind != .Struct && existing.kind != .Union) ||
|
||||
existing.pkg != pkg || existing.name != name || existing.qualifier != qualifier {
|
||||
continue
|
||||
}
|
||||
if qualifier != 0 {
|
||||
if existing.file == file {
|
||||
return DYNAMIC_START+Type(index)
|
||||
}
|
||||
continue
|
||||
}
|
||||
switch existing.visibility {
|
||||
case .Public:
|
||||
fallback = DYNAMIC_START+Type(index)
|
||||
case .Package:
|
||||
if file != 0xffff_ffff {
|
||||
fallback = DYNAMIC_START+Type(index)
|
||||
}
|
||||
case .File:
|
||||
if existing.file == file {
|
||||
return DYNAMIC_START+Type(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
return INVALID
|
||||
return fallback
|
||||
}
|
||||
|
||||
define_alias :: proc(store: ^Store, id, child: Type, package_hidden := false) -> bool {
|
||||
define_alias :: proc(store: ^Store, id, child: Type, visibility := Visibility.Public) -> bool {
|
||||
existing, ok := node(store, id)
|
||||
if !ok || existing.kind != .Named || existing.declared {
|
||||
return false
|
||||
@@ -232,12 +265,12 @@ define_alias :: proc(store: ^Store, id, child: Type, package_hidden := false) ->
|
||||
index := int(id-DYNAMIC_START)
|
||||
store.nodes[index].kind = .Alias
|
||||
store.nodes[index].child = child
|
||||
store.nodes[index].package_hidden = package_hidden
|
||||
store.nodes[index].visibility = visibility
|
||||
store.nodes[index].declared = true
|
||||
return true
|
||||
}
|
||||
|
||||
define_distinct :: proc(store: ^Store, id, child: Type, package_hidden := false) -> bool {
|
||||
define_distinct :: proc(store: ^Store, id, child: Type, visibility := Visibility.Public) -> bool {
|
||||
existing, ok := node(store, id)
|
||||
if !ok || existing.kind != .Named || existing.declared {
|
||||
return false
|
||||
@@ -245,12 +278,12 @@ define_distinct :: proc(store: ^Store, id, child: Type, package_hidden := false)
|
||||
index := int(id-DYNAMIC_START)
|
||||
store.nodes[index].kind = .Distinct
|
||||
store.nodes[index].child = child
|
||||
store.nodes[index].package_hidden = package_hidden
|
||||
store.nodes[index].visibility = visibility
|
||||
store.nodes[index].declared = true
|
||||
return true
|
||||
}
|
||||
|
||||
define_enum :: proc(store: ^Store, id, backing: Type, members: []Enum_Member, explicit_backing: bool, package_hidden := false) -> bool {
|
||||
define_enum :: proc(store: ^Store, id, backing: Type, members: []Enum_Member, explicit_backing: bool, visibility := Visibility.Public) -> bool {
|
||||
existing, ok := node(store, id)
|
||||
if !ok || existing.kind != .Named || existing.declared {
|
||||
return false
|
||||
@@ -261,7 +294,7 @@ define_enum :: proc(store: ^Store, id, backing: Type, members: []Enum_Member, ex
|
||||
store.nodes[index].field_start = u32(len(store.enum_members))
|
||||
store.nodes[index].field_count = u32(len(members))
|
||||
store.nodes[index].explicit_backing = explicit_backing
|
||||
store.nodes[index].package_hidden = package_hidden
|
||||
store.nodes[index].visibility = visibility
|
||||
store.nodes[index].declared = true
|
||||
append(&store.enum_members, ..members)
|
||||
return true
|
||||
@@ -278,7 +311,7 @@ define_record :: proc(
|
||||
tag: Type = INVALID,
|
||||
declared_tag: Type = INVALID,
|
||||
tuple := false,
|
||||
package_hidden := false,
|
||||
visibility := Visibility.Public,
|
||||
) -> bool {
|
||||
existing, ok := node(store, id)
|
||||
if !ok || (existing.kind != .Named && existing.kind != .Struct && existing.kind != .Union) ||
|
||||
@@ -290,7 +323,7 @@ define_record :: proc(
|
||||
store.nodes[index].c_layout = c_layout
|
||||
store.nodes[index].tuple = tuple
|
||||
store.nodes[index].opaque = opaque
|
||||
store.nodes[index].package_hidden = package_hidden
|
||||
store.nodes[index].visibility = visibility
|
||||
store.nodes[index].declared = true
|
||||
store.nodes[index].explicit_size = explicit_size
|
||||
store.nodes[index].explicit_alignment = explicit_alignment
|
||||
|
||||
Reference in New Issue
Block a user