mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Improve //+vet; remove using in many places; add //+vet !using-stmt where necessary
This commit is contained in:
@@ -184,28 +184,26 @@ decode_xml :: proc(input: string, options := XML_Decode_Options{}, allocator :=
|
|||||||
|
|
||||||
advance :: proc(t: ^Tokenizer) -> (err: Error) {
|
advance :: proc(t: ^Tokenizer) -> (err: Error) {
|
||||||
if t == nil { return .Tokenizer_Is_Nil }
|
if t == nil { return .Tokenizer_Is_Nil }
|
||||||
using t
|
|
||||||
|
|
||||||
#no_bounds_check {
|
#no_bounds_check {
|
||||||
if read_offset < len(src) {
|
if t.read_offset < len(t.src) {
|
||||||
offset = read_offset
|
t.offset = t.read_offset
|
||||||
r, w = rune(src[read_offset]), 1
|
t.r, t.w = rune(t.src[t.read_offset]), 1
|
||||||
switch {
|
switch {
|
||||||
case r == 0:
|
case t.r == 0:
|
||||||
return .Illegal_NUL_Character
|
return .Illegal_NUL_Character
|
||||||
case r >= utf8.RUNE_SELF:
|
case t.r >= utf8.RUNE_SELF:
|
||||||
r, w = utf8.decode_rune_in_string(src[read_offset:])
|
t.r, t.w = utf8.decode_rune_in_string(t.src[t.read_offset:])
|
||||||
if r == utf8.RUNE_ERROR && w == 1 {
|
if t.r == utf8.RUNE_ERROR && t.w == 1 {
|
||||||
return .Illegal_UTF_Encoding
|
return .Illegal_UTF_Encoding
|
||||||
} else if r == utf8.RUNE_BOM && offset > 0 {
|
} else if t.r == utf8.RUNE_BOM && t.offset > 0 {
|
||||||
return .Illegal_BOM
|
return .Illegal_BOM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
read_offset += w
|
t.read_offset += t.w
|
||||||
return .None
|
return .None
|
||||||
} else {
|
} else {
|
||||||
offset = len(src)
|
t.offset = len(t.src)
|
||||||
r = -1
|
t.r = -1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,26 +271,25 @@ _extract_xml_entity :: proc(t: ^Tokenizer) -> (entity: string, err: Error) {
|
|||||||
All of these would be in the ASCII range.
|
All of these would be in the ASCII range.
|
||||||
Even if one is not, it doesn't matter. All characters we need to compare to extract are.
|
Even if one is not, it doesn't matter. All characters we need to compare to extract are.
|
||||||
*/
|
*/
|
||||||
using t
|
|
||||||
|
|
||||||
length := len(t.src)
|
length := len(t.src)
|
||||||
found := false
|
found := false
|
||||||
|
|
||||||
#no_bounds_check {
|
#no_bounds_check {
|
||||||
for read_offset < length {
|
for t.read_offset < length {
|
||||||
if src[read_offset] == ';' {
|
if t.src[t.read_offset] == ';' {
|
||||||
|
t.read_offset += 1
|
||||||
found = true
|
found = true
|
||||||
read_offset += 1
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
read_offset += 1
|
t.read_offset += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
return string(src[offset + 1 : read_offset - 1]), .None
|
return string(t.src[t.offset + 1 : t.read_offset - 1]), .None
|
||||||
}
|
}
|
||||||
return string(src[offset : read_offset]), .Invalid_Entity_Encoding
|
return string(t.src[t.offset : t.read_offset]), .Invalid_Entity_Encoding
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -19,43 +19,39 @@ import "core:fmt"
|
|||||||
*/
|
*/
|
||||||
print :: proc(writer: io.Writer, doc: ^Document) -> (written: int, err: io.Error) {
|
print :: proc(writer: io.Writer, doc: ^Document) -> (written: int, err: io.Error) {
|
||||||
if doc == nil { return }
|
if doc == nil { return }
|
||||||
using fmt
|
written += fmt.wprintf(writer, "[XML Prolog]\n")
|
||||||
|
|
||||||
written += wprintf(writer, "[XML Prolog]\n")
|
|
||||||
|
|
||||||
for attr in doc.prologue {
|
for attr in doc.prologue {
|
||||||
written += wprintf(writer, "\t%v: %v\n", attr.key, attr.val)
|
written += fmt.wprintf(writer, "\t%v: %v\n", attr.key, attr.val)
|
||||||
}
|
}
|
||||||
|
|
||||||
written += wprintf(writer, "[Encoding] %v\n", doc.encoding)
|
written += fmt.wprintf(writer, "[Encoding] %v\n", doc.encoding)
|
||||||
|
|
||||||
if len(doc.doctype.ident) > 0 {
|
if len(doc.doctype.ident) > 0 {
|
||||||
written += wprintf(writer, "[DOCTYPE] %v\n", doc.doctype.ident)
|
written += fmt.wprintf(writer, "[DOCTYPE] %v\n", doc.doctype.ident)
|
||||||
|
|
||||||
if len(doc.doctype.rest) > 0 {
|
if len(doc.doctype.rest) > 0 {
|
||||||
wprintf(writer, "\t%v\n", doc.doctype.rest)
|
fmt.wprintf(writer, "\t%v\n", doc.doctype.rest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for comment in doc.comments {
|
for comment in doc.comments {
|
||||||
written += wprintf(writer, "[Pre-root comment] %v\n", comment)
|
written += fmt.wprintf(writer, "[Pre-root comment] %v\n", comment)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(doc.elements) > 0 {
|
if len(doc.elements) > 0 {
|
||||||
wprintln(writer, " --- ")
|
fmt.wprintln(writer, " --- ")
|
||||||
print_element(writer, doc, 0)
|
print_element(writer, doc, 0)
|
||||||
wprintln(writer, " --- ")
|
fmt.wprintln(writer, " --- ")
|
||||||
}
|
}
|
||||||
|
|
||||||
return written, .None
|
return written, .None
|
||||||
}
|
}
|
||||||
|
|
||||||
print_element :: proc(writer: io.Writer, doc: ^Document, element_id: Element_ID, indent := 0) -> (written: int, err: io.Error) {
|
print_element :: proc(writer: io.Writer, doc: ^Document, element_id: Element_ID, indent := 0) -> (written: int, err: io.Error) {
|
||||||
using fmt
|
|
||||||
|
|
||||||
tab :: proc(writer: io.Writer, indent: int) {
|
tab :: proc(writer: io.Writer, indent: int) {
|
||||||
for _ in 0..=indent {
|
for _ in 0..=indent {
|
||||||
wprintf(writer, "\t")
|
fmt.wprintf(writer, "\t")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,13 +60,13 @@ print_element :: proc(writer: io.Writer, doc: ^Document, element_id: Element_ID,
|
|||||||
element := doc.elements[element_id]
|
element := doc.elements[element_id]
|
||||||
|
|
||||||
if element.kind == .Element {
|
if element.kind == .Element {
|
||||||
wprintf(writer, "<%v>\n", element.ident)
|
fmt.wprintf(writer, "<%v>\n", element.ident)
|
||||||
|
|
||||||
for value in element.value {
|
for value in element.value {
|
||||||
switch v in value {
|
switch v in value {
|
||||||
case string:
|
case string:
|
||||||
tab(writer, indent + 1)
|
tab(writer, indent + 1)
|
||||||
wprintf(writer, "[Value] %v\n", v)
|
fmt.wprintf(writer, "[Value] %v\n", v)
|
||||||
case Element_ID:
|
case Element_ID:
|
||||||
print_element(writer, doc, v, indent + 1)
|
print_element(writer, doc, v, indent + 1)
|
||||||
}
|
}
|
||||||
@@ -78,10 +74,10 @@ print_element :: proc(writer: io.Writer, doc: ^Document, element_id: Element_ID,
|
|||||||
|
|
||||||
for attr in element.attribs {
|
for attr in element.attribs {
|
||||||
tab(writer, indent + 1)
|
tab(writer, indent + 1)
|
||||||
wprintf(writer, "[Attr] %v: %v\n", attr.key, attr.val)
|
fmt.wprintf(writer, "[Attr] %v: %v\n", attr.key, attr.val)
|
||||||
}
|
}
|
||||||
} else if element.kind == .Comment {
|
} else if element.kind == .Comment {
|
||||||
wprintf(writer, "[COMMENT] %v\n", element.value)
|
fmt.wprintf(writer, "[COMMENT] %v\n", element.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return written, .None
|
return written, .None
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//+vet !using-stmt
|
||||||
package netpbm
|
package netpbm
|
||||||
|
|
||||||
import "core:bytes"
|
import "core:bytes"
|
||||||
|
|||||||
@@ -80,11 +80,10 @@ time :: proc(c: image.PNG_Chunk) -> (res: tIME, ok: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core_time :: proc(c: image.PNG_Chunk) -> (t: coretime.Time, ok: bool) {
|
core_time :: proc(c: image.PNG_Chunk) -> (t: coretime.Time, ok: bool) {
|
||||||
if png_time, png_ok := time(c); png_ok {
|
if t, png_ok := time(c); png_ok {
|
||||||
using png_time
|
|
||||||
return coretime.datetime_to_time(
|
return coretime.datetime_to_time(
|
||||||
int(year), int(month), int(day),
|
int(t.year), int(t.month), int(t.day),
|
||||||
int(hour), int(minute), int(second),
|
int(t.hour), int(t.minute), int(t.second),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return {}, false
|
return {}, false
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
// package png implements a PNG image reader
|
// package png implements a PNG image reader
|
||||||
//
|
//
|
||||||
// The PNG specification is at https://www.w3.org/TR/PNG/.
|
// The PNG specification is at https://www.w3.org/TR/PNG/.
|
||||||
|
//+vet !using-stmt
|
||||||
package png
|
package png
|
||||||
|
|
||||||
import "core:compress"
|
import "core:compress"
|
||||||
@@ -444,15 +445,14 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
|
|||||||
img.width = int(header.width)
|
img.width = int(header.width)
|
||||||
img.height = int(header.height)
|
img.height = int(header.height)
|
||||||
|
|
||||||
using header
|
|
||||||
h := image.PNG_IHDR{
|
h := image.PNG_IHDR{
|
||||||
width = width,
|
width = header.width,
|
||||||
height = height,
|
height = header.height,
|
||||||
bit_depth = bit_depth,
|
bit_depth = header.bit_depth,
|
||||||
color_type = color_type,
|
color_type = header.color_type,
|
||||||
compression_method = compression_method,
|
compression_method = header.compression_method,
|
||||||
filter_method = filter_method,
|
filter_method = header.filter_method,
|
||||||
interlace_method = interlace_method,
|
interlace_method = header.interlace_method,
|
||||||
}
|
}
|
||||||
info.header = h
|
info.header = h
|
||||||
|
|
||||||
|
|||||||
+35
-35
@@ -63,100 +63,100 @@ split_url :: proc(url: string, allocator := context.allocator) -> (scheme, host,
|
|||||||
}
|
}
|
||||||
|
|
||||||
join_url :: proc(scheme, host, path: string, queries: map[string]string, allocator := context.allocator) -> string {
|
join_url :: proc(scheme, host, path: string, queries: map[string]string, allocator := context.allocator) -> string {
|
||||||
using strings
|
b := strings.builder_make(allocator)
|
||||||
|
strings.builder_grow(&b, len(scheme) + 3 + len(host) + 1 + len(path))
|
||||||
|
|
||||||
b := builder_make(allocator)
|
strings.write_string(&b, scheme)
|
||||||
builder_grow(&b, len(scheme) + 3 + len(host) + 1 + len(path))
|
strings.write_string(&b, "://")
|
||||||
|
strings.write_string(&b, strings.trim_space(host))
|
||||||
write_string(&b, scheme)
|
|
||||||
write_string(&b, "://")
|
|
||||||
write_string(&b, trim_space(host))
|
|
||||||
|
|
||||||
if path != "" {
|
if path != "" {
|
||||||
if path[0] != '/' do write_string(&b, "/")
|
if path[0] != '/' {
|
||||||
write_string(&b, trim_space(path))
|
strings.write_string(&b, "/")
|
||||||
|
}
|
||||||
|
strings.write_string(&b, strings.trim_space(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
query_length := len(queries)
|
query_length := len(queries)
|
||||||
if query_length > 0 do write_string(&b, "?")
|
if query_length > 0 {
|
||||||
|
strings.write_string(&b, "?")
|
||||||
|
}
|
||||||
i := 0
|
i := 0
|
||||||
for query_name, query_value in queries {
|
for query_name, query_value in queries {
|
||||||
write_string(&b, query_name)
|
strings.write_string(&b, query_name)
|
||||||
if query_value != "" {
|
if query_value != "" {
|
||||||
write_string(&b, "=")
|
strings.write_string(&b, "=")
|
||||||
write_string(&b, query_value)
|
strings.write_string(&b, query_value)
|
||||||
}
|
}
|
||||||
if i < query_length - 1 {
|
if i < query_length - 1 {
|
||||||
write_string(&b, "&")
|
strings.write_string(&b, "&")
|
||||||
}
|
}
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return to_string(b)
|
return strings.to_string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
percent_encode :: proc(s: string, allocator := context.allocator) -> string {
|
percent_encode :: proc(s: string, allocator := context.allocator) -> string {
|
||||||
using strings
|
b := strings.builder_make(allocator)
|
||||||
|
strings.builder_grow(&b, len(s) + 16) // NOTE(tetra): A reasonable number to allow for the number of things we need to escape.
|
||||||
b := builder_make(allocator)
|
|
||||||
builder_grow(&b, len(s) + 16) // NOTE(tetra): A reasonable number to allow for the number of things we need to escape.
|
|
||||||
|
|
||||||
for ch in s {
|
for ch in s {
|
||||||
switch ch {
|
switch ch {
|
||||||
case 'A'..='Z', 'a'..='z', '0'..='9', '-', '_', '.', '~':
|
case 'A'..='Z', 'a'..='z', '0'..='9', '-', '_', '.', '~':
|
||||||
write_rune(&b, ch)
|
strings.write_rune(&b, ch)
|
||||||
case:
|
case:
|
||||||
bytes, n := utf8.encode_rune(ch)
|
bytes, n := utf8.encode_rune(ch)
|
||||||
for byte in bytes[:n] {
|
for byte in bytes[:n] {
|
||||||
buf: [2]u8 = ---
|
buf: [2]u8 = ---
|
||||||
t := strconv.append_int(buf[:], i64(byte), 16)
|
t := strconv.append_int(buf[:], i64(byte), 16)
|
||||||
write_rune(&b, '%')
|
strings.write_rune(&b, '%')
|
||||||
write_string(&b, t)
|
strings.write_string(&b, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return to_string(b)
|
return strings.to_string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
percent_decode :: proc(encoded_string: string, allocator := context.allocator) -> (decoded_string: string, ok: bool) {
|
percent_decode :: proc(encoded_string: string, allocator := context.allocator) -> (decoded_string: string, ok: bool) {
|
||||||
using strings
|
b := strings.builder_make(allocator)
|
||||||
|
strings.builder_grow(&b, len(encoded_string))
|
||||||
b := builder_make(allocator)
|
defer if !ok do strings.builder_destroy(&b)
|
||||||
builder_grow(&b, len(encoded_string))
|
|
||||||
defer if !ok do builder_destroy(&b)
|
|
||||||
|
|
||||||
s := encoded_string
|
s := encoded_string
|
||||||
|
|
||||||
for len(s) > 0 {
|
for len(s) > 0 {
|
||||||
i := index_byte(s, '%')
|
i := strings.index_byte(s, '%')
|
||||||
if i == -1 {
|
if i == -1 {
|
||||||
write_string(&b, s) // no '%'s; the string is already decoded
|
strings.write_string(&b, s) // no '%'s; the string is already decoded
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
write_string(&b, s[:i])
|
strings.write_string(&b, s[:i])
|
||||||
s = s[i:]
|
s = s[i:]
|
||||||
|
|
||||||
if len(s) == 0 do return // percent without anything after it
|
if len(s) == 0 do return // percent without anything after it
|
||||||
s = s[1:]
|
s = s[1:]
|
||||||
|
|
||||||
if s[0] == '%' {
|
if s[0] == '%' {
|
||||||
write_byte(&b, '%')
|
strings.write_byte(&b, '%')
|
||||||
s = s[1:]
|
s = s[1:]
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(s) < 2 do return // percent without encoded value
|
if len(s) < 2 {
|
||||||
|
return // percent without encoded value
|
||||||
|
}
|
||||||
|
|
||||||
val := hex.decode_sequence(s[:2]) or_return
|
val := hex.decode_sequence(s[:2]) or_return
|
||||||
write_byte(&b, val)
|
strings.write_byte(&b, val)
|
||||||
s = s[2:]
|
s = s[2:]
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true
|
ok = true
|
||||||
decoded_string = to_string(b)
|
decoded_string = strings.to_string(b)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -336,22 +336,20 @@ hint_current_line :: proc(p: ^Printer, hint: Line_Type) {
|
|||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
||||||
using ast
|
|
||||||
|
|
||||||
if decl == nil {
|
if decl == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
#partial switch v in decl.derived_stmt {
|
#partial switch v in decl.derived_stmt {
|
||||||
case ^Expr_Stmt:
|
case ^ast.Expr_Stmt:
|
||||||
move_line(p, decl.pos)
|
move_line(p, decl.pos)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
if p.config.semicolons {
|
if p.config.semicolons {
|
||||||
push_generic_token(p, .Semicolon, 0)
|
push_generic_token(p, .Semicolon, 0)
|
||||||
}
|
}
|
||||||
case ^When_Stmt:
|
case ^ast.When_Stmt:
|
||||||
visit_stmt(p, cast(^Stmt)decl)
|
visit_stmt(p, cast(^ast.Stmt)decl)
|
||||||
case ^Foreign_Import_Decl:
|
case ^ast.Foreign_Import_Decl:
|
||||||
if len(v.attributes) > 0 {
|
if len(v.attributes) > 0 {
|
||||||
sort.sort(sort_attribute(&v.attributes))
|
sort.sort(sort_attribute(&v.attributes))
|
||||||
move_line(p, v.attributes[0].pos)
|
move_line(p, v.attributes[0].pos)
|
||||||
@@ -370,7 +368,7 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
|||||||
for path in v.fullpaths {
|
for path in v.fullpaths {
|
||||||
push_ident_token(p, path, 0)
|
push_ident_token(p, path, 0)
|
||||||
}
|
}
|
||||||
case ^Foreign_Block_Decl:
|
case ^ast.Foreign_Block_Decl:
|
||||||
if len(v.attributes) > 0 {
|
if len(v.attributes) > 0 {
|
||||||
sort.sort(sort_attribute(&v.attributes))
|
sort.sort(sort_attribute(&v.attributes))
|
||||||
move_line(p, v.attributes[0].pos)
|
move_line(p, v.attributes[0].pos)
|
||||||
@@ -383,7 +381,7 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
|||||||
|
|
||||||
visit_expr(p, v.foreign_library)
|
visit_expr(p, v.foreign_library)
|
||||||
visit_stmt(p, v.body)
|
visit_stmt(p, v.body)
|
||||||
case ^Import_Decl:
|
case ^ast.Import_Decl:
|
||||||
move_line(p, decl.pos)
|
move_line(p, decl.pos)
|
||||||
|
|
||||||
if v.name.text != "" {
|
if v.name.text != "" {
|
||||||
@@ -395,7 +393,7 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
|||||||
push_ident_token(p, v.fullpath, 1)
|
push_ident_token(p, v.fullpath, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ^Value_Decl:
|
case ^ast.Value_Decl:
|
||||||
if len(v.attributes) > 0 {
|
if len(v.attributes) > 0 {
|
||||||
sort.sort(sort_attribute(&v.attributes))
|
sort.sort(sort_attribute(&v.attributes))
|
||||||
move_line(p, v.attributes[0].pos)
|
move_line(p, v.attributes[0].pos)
|
||||||
@@ -447,9 +445,9 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
|||||||
|
|
||||||
for value in v.values {
|
for value in v.values {
|
||||||
#partial switch a in value.derived {
|
#partial switch a in value.derived {
|
||||||
case ^Union_Type, ^Enum_Type, ^Struct_Type:
|
case ^ast.Union_Type, ^ast.Enum_Type, ^ast.Struct_Type:
|
||||||
add_semicolon = false || called_in_stmt
|
add_semicolon = false || called_in_stmt
|
||||||
case ^Proc_Lit:
|
case ^ast.Proc_Lit:
|
||||||
add_semicolon = false
|
add_semicolon = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -510,40 +508,38 @@ visit_attributes :: proc(p: ^Printer, attributes: [dynamic]^ast.Attribute) {
|
|||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Generic, empty_block := false, block_stmt := false) {
|
visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Generic, empty_block := false, block_stmt := false) {
|
||||||
using ast
|
|
||||||
|
|
||||||
if stmt == nil {
|
if stmt == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch v in stmt.derived_stmt {
|
switch v in stmt.derived_stmt {
|
||||||
case ^Bad_Stmt:
|
case ^ast.Bad_Stmt:
|
||||||
case ^Bad_Decl:
|
case ^ast.Bad_Decl:
|
||||||
case ^Package_Decl:
|
case ^ast.Package_Decl:
|
||||||
|
|
||||||
case ^Empty_Stmt:
|
case ^ast.Empty_Stmt:
|
||||||
push_generic_token(p, .Semicolon, 0)
|
push_generic_token(p, .Semicolon, 0)
|
||||||
case ^Tag_Stmt:
|
case ^ast.Tag_Stmt:
|
||||||
push_generic_token(p, .Hash, 1)
|
push_generic_token(p, .Hash, 1)
|
||||||
push_generic_token(p, v.op.kind, 1, v.op.text)
|
push_generic_token(p, v.op.kind, 1, v.op.text)
|
||||||
visit_stmt(p, v.stmt)
|
visit_stmt(p, v.stmt)
|
||||||
|
|
||||||
|
|
||||||
case ^Import_Decl:
|
case ^ast.Import_Decl:
|
||||||
visit_decl(p, cast(^Decl)stmt, true)
|
visit_decl(p, cast(^ast.Decl)stmt, true)
|
||||||
return
|
return
|
||||||
case ^Value_Decl:
|
case ^ast.Value_Decl:
|
||||||
visit_decl(p, cast(^Decl)stmt, true)
|
visit_decl(p, cast(^ast.Decl)stmt, true)
|
||||||
return
|
return
|
||||||
case ^Foreign_Import_Decl:
|
case ^ast.Foreign_Import_Decl:
|
||||||
visit_decl(p, cast(^Decl)stmt, true)
|
visit_decl(p, cast(^ast.Decl)stmt, true)
|
||||||
return
|
return
|
||||||
case ^Foreign_Block_Decl:
|
case ^ast.Foreign_Block_Decl:
|
||||||
visit_decl(p, cast(^Decl)stmt, true)
|
visit_decl(p, cast(^ast.Decl)stmt, true)
|
||||||
return
|
return
|
||||||
|
|
||||||
case ^Using_Stmt:
|
case ^ast.Using_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
push_generic_token(p, .Using, 1)
|
push_generic_token(p, .Using, 1)
|
||||||
@@ -553,7 +549,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
if p.config.semicolons {
|
if p.config.semicolons {
|
||||||
push_generic_token(p, .Semicolon, 0)
|
push_generic_token(p, .Semicolon, 0)
|
||||||
}
|
}
|
||||||
case ^Block_Stmt:
|
case ^ast.Block_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
if v.pos.line == v.end.line {
|
if v.pos.line == v.end.line {
|
||||||
@@ -583,7 +579,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
visit_end_brace(p, v.end)
|
visit_end_brace(p, v.end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ^If_Stmt:
|
case ^ast.If_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
if v.label != nil {
|
if v.label != nil {
|
||||||
@@ -606,7 +602,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
|
|
||||||
uses_do := false
|
uses_do := false
|
||||||
|
|
||||||
if check_stmt, ok := v.body.derived.(^Block_Stmt); ok && check_stmt.uses_do {
|
if check_stmt, ok := v.body.derived.(^ast.Block_Stmt); ok && check_stmt.uses_do {
|
||||||
uses_do = true
|
uses_do = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,7 +633,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
|
|
||||||
visit_stmt(p, v.else_stmt)
|
visit_stmt(p, v.else_stmt)
|
||||||
}
|
}
|
||||||
case ^Switch_Stmt:
|
case ^ast.Switch_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
if v.label != nil {
|
if v.label != nil {
|
||||||
@@ -665,7 +661,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
|
|
||||||
visit_expr(p, v.cond)
|
visit_expr(p, v.cond)
|
||||||
visit_stmt(p, v.body)
|
visit_stmt(p, v.body)
|
||||||
case ^Case_Clause:
|
case ^ast.Case_Clause:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
if !p.config.indent_cases {
|
if !p.config.indent_cases {
|
||||||
@@ -689,7 +685,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
if !p.config.indent_cases {
|
if !p.config.indent_cases {
|
||||||
indent(p)
|
indent(p)
|
||||||
}
|
}
|
||||||
case ^Type_Switch_Stmt:
|
case ^ast.Type_Switch_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
hint_current_line(p, {.Switch_Stmt})
|
hint_current_line(p, {.Switch_Stmt})
|
||||||
@@ -707,7 +703,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
|
|
||||||
visit_stmt(p, v.tag)
|
visit_stmt(p, v.tag)
|
||||||
visit_stmt(p, v.body)
|
visit_stmt(p, v.body)
|
||||||
case ^Assign_Stmt:
|
case ^ast.Assign_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
hint_current_line(p, {.Assign})
|
hint_current_line(p, {.Assign})
|
||||||
@@ -721,13 +717,13 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
if block_stmt && p.config.semicolons {
|
if block_stmt && p.config.semicolons {
|
||||||
push_generic_token(p, .Semicolon, 0)
|
push_generic_token(p, .Semicolon, 0)
|
||||||
}
|
}
|
||||||
case ^Expr_Stmt:
|
case ^ast.Expr_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
if block_stmt && p.config.semicolons {
|
if block_stmt && p.config.semicolons {
|
||||||
push_generic_token(p, .Semicolon, 0)
|
push_generic_token(p, .Semicolon, 0)
|
||||||
}
|
}
|
||||||
case ^For_Stmt:
|
case ^ast.For_Stmt:
|
||||||
// this should be simplified
|
// this should be simplified
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
@@ -764,7 +760,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
|
|
||||||
visit_stmt(p, v.body)
|
visit_stmt(p, v.body)
|
||||||
|
|
||||||
case ^Inline_Range_Stmt:
|
case ^ast.Inline_Range_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
if v.label != nil {
|
if v.label != nil {
|
||||||
@@ -790,7 +786,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
visit_stmt(p, v.body)
|
visit_stmt(p, v.body)
|
||||||
|
|
||||||
case ^Range_Stmt:
|
case ^ast.Range_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
if v.label != nil {
|
if v.label != nil {
|
||||||
@@ -816,7 +812,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
|
|
||||||
visit_stmt(p, v.body)
|
visit_stmt(p, v.body)
|
||||||
case ^Return_Stmt:
|
case ^ast.Return_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
push_generic_token(p, .Return, 1)
|
push_generic_token(p, .Return, 1)
|
||||||
@@ -828,7 +824,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
if block_stmt && p.config.semicolons {
|
if block_stmt && p.config.semicolons {
|
||||||
push_generic_token(p, .Semicolon, 0)
|
push_generic_token(p, .Semicolon, 0)
|
||||||
}
|
}
|
||||||
case ^Defer_Stmt:
|
case ^ast.Defer_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
push_generic_token(p, .Defer, 0)
|
push_generic_token(p, .Defer, 0)
|
||||||
|
|
||||||
@@ -837,7 +833,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
if p.config.semicolons {
|
if p.config.semicolons {
|
||||||
push_generic_token(p, .Semicolon, 0)
|
push_generic_token(p, .Semicolon, 0)
|
||||||
}
|
}
|
||||||
case ^When_Stmt:
|
case ^ast.When_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
push_generic_token(p, .When, 1)
|
push_generic_token(p, .When, 1)
|
||||||
visit_expr(p, v.cond)
|
visit_expr(p, v.cond)
|
||||||
@@ -857,7 +853,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
visit_stmt(p, v.else_stmt)
|
visit_stmt(p, v.else_stmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ^Branch_Stmt:
|
case ^ast.Branch_Stmt:
|
||||||
move_line(p, v.pos)
|
move_line(p, v.pos)
|
||||||
|
|
||||||
push_generic_token(p, v.tok.kind, 0)
|
push_generic_token(p, v.tok.kind, 0)
|
||||||
@@ -921,8 +917,6 @@ push_poly_params :: proc(p: ^Printer, poly_params: ^ast.Field_List) {
|
|||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
||||||
using ast
|
|
||||||
|
|
||||||
if expr == nil {
|
if expr == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -930,14 +924,14 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
set_source_position(p, expr.pos)
|
set_source_position(p, expr.pos)
|
||||||
|
|
||||||
switch v in expr.derived_expr {
|
switch v in expr.derived_expr {
|
||||||
case ^Bad_Expr:
|
case ^ast.Bad_Expr:
|
||||||
|
|
||||||
case ^Tag_Expr:
|
case ^ast.Tag_Expr:
|
||||||
push_generic_token(p, .Hash, 1)
|
push_generic_token(p, .Hash, 1)
|
||||||
push_generic_token(p, v.op.kind, 1, v.op.text)
|
push_generic_token(p, v.op.kind, 1, v.op.text)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
|
|
||||||
case ^Inline_Asm_Expr:
|
case ^ast.Inline_Asm_Expr:
|
||||||
push_generic_token(p, v.tok.kind, 1, v.tok.text)
|
push_generic_token(p, v.tok.kind, 1, v.tok.text)
|
||||||
|
|
||||||
push_generic_token(p, .Open_Paren, 1)
|
push_generic_token(p, .Open_Paren, 1)
|
||||||
@@ -954,42 +948,42 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
push_generic_token(p, .Comma, 0)
|
push_generic_token(p, .Comma, 0)
|
||||||
visit_expr(p, v.constraints_string)
|
visit_expr(p, v.constraints_string)
|
||||||
push_generic_token(p, .Close_Brace, 0)
|
push_generic_token(p, .Close_Brace, 0)
|
||||||
case ^Undef:
|
case ^ast.Undef:
|
||||||
push_generic_token(p, .Undef, 1)
|
push_generic_token(p, .Undef, 1)
|
||||||
case ^Auto_Cast:
|
case ^ast.Auto_Cast:
|
||||||
push_generic_token(p, v.op.kind, 1)
|
push_generic_token(p, v.op.kind, 1)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
case ^Ternary_If_Expr:
|
case ^ast.Ternary_If_Expr:
|
||||||
visit_expr(p, v.x)
|
visit_expr(p, v.x)
|
||||||
push_generic_token(p, v.op1.kind, 1)
|
push_generic_token(p, v.op1.kind, 1)
|
||||||
visit_expr(p, v.cond)
|
visit_expr(p, v.cond)
|
||||||
push_generic_token(p, v.op2.kind, 1)
|
push_generic_token(p, v.op2.kind, 1)
|
||||||
visit_expr(p, v.y)
|
visit_expr(p, v.y)
|
||||||
case ^Ternary_When_Expr:
|
case ^ast.Ternary_When_Expr:
|
||||||
visit_expr(p, v.x)
|
visit_expr(p, v.x)
|
||||||
push_generic_token(p, v.op1.kind, 1)
|
push_generic_token(p, v.op1.kind, 1)
|
||||||
visit_expr(p, v.cond)
|
visit_expr(p, v.cond)
|
||||||
push_generic_token(p, v.op2.kind, 1)
|
push_generic_token(p, v.op2.kind, 1)
|
||||||
visit_expr(p, v.y)
|
visit_expr(p, v.y)
|
||||||
case ^Or_Else_Expr:
|
case ^ast.Or_Else_Expr:
|
||||||
visit_expr(p, v.x)
|
visit_expr(p, v.x)
|
||||||
push_generic_token(p, v.token.kind, 1)
|
push_generic_token(p, v.token.kind, 1)
|
||||||
visit_expr(p, v.y)
|
visit_expr(p, v.y)
|
||||||
case ^Or_Return_Expr:
|
case ^ast.Or_Return_Expr:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
push_generic_token(p, v.token.kind, 1)
|
push_generic_token(p, v.token.kind, 1)
|
||||||
case ^Selector_Call_Expr:
|
case ^ast.Selector_Call_Expr:
|
||||||
visit_expr(p, v.call.expr)
|
visit_expr(p, v.call.expr)
|
||||||
push_generic_token(p, .Open_Paren, 1)
|
push_generic_token(p, .Open_Paren, 1)
|
||||||
visit_exprs(p, v.call.args, {.Add_Comma})
|
visit_exprs(p, v.call.args, {.Add_Comma})
|
||||||
push_generic_token(p, .Close_Paren, 0)
|
push_generic_token(p, .Close_Paren, 0)
|
||||||
case ^Ellipsis:
|
case ^ast.Ellipsis:
|
||||||
push_generic_token(p, .Ellipsis, 1)
|
push_generic_token(p, .Ellipsis, 1)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
case ^Relative_Type:
|
case ^ast.Relative_Type:
|
||||||
visit_expr(p, v.tag)
|
visit_expr(p, v.tag)
|
||||||
visit_expr(p, v.type)
|
visit_expr(p, v.type)
|
||||||
case ^Slice_Expr:
|
case ^ast.Slice_Expr:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
push_generic_token(p, .Open_Bracket, 0)
|
push_generic_token(p, .Open_Bracket, 0)
|
||||||
visit_expr(p, v.low)
|
visit_expr(p, v.low)
|
||||||
@@ -999,37 +993,37 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
visit_expr(p, v.high)
|
visit_expr(p, v.high)
|
||||||
}
|
}
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
case ^Ident:
|
case ^ast.Ident:
|
||||||
if .Enforce_Poly_Names in options {
|
if .Enforce_Poly_Names in options {
|
||||||
push_generic_token(p, .Dollar, 1)
|
push_generic_token(p, .Dollar, 1)
|
||||||
push_ident_token(p, v.name, 0)
|
push_ident_token(p, v.name, 0)
|
||||||
} else {
|
} else {
|
||||||
push_ident_token(p, v.name, 1)
|
push_ident_token(p, v.name, 1)
|
||||||
}
|
}
|
||||||
case ^Deref_Expr:
|
case ^ast.Deref_Expr:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
push_generic_token(p, v.op.kind, 0)
|
push_generic_token(p, v.op.kind, 0)
|
||||||
case ^Type_Cast:
|
case ^ast.Type_Cast:
|
||||||
push_generic_token(p, v.tok.kind, 1)
|
push_generic_token(p, v.tok.kind, 1)
|
||||||
push_generic_token(p, .Open_Paren, 0)
|
push_generic_token(p, .Open_Paren, 0)
|
||||||
visit_expr(p, v.type)
|
visit_expr(p, v.type)
|
||||||
push_generic_token(p, .Close_Paren, 0)
|
push_generic_token(p, .Close_Paren, 0)
|
||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
case ^Basic_Directive:
|
case ^ast.Basic_Directive:
|
||||||
push_generic_token(p, v.tok.kind, 1)
|
push_generic_token(p, v.tok.kind, 1)
|
||||||
push_ident_token(p, v.name, 0)
|
push_ident_token(p, v.name, 0)
|
||||||
case ^Distinct_Type:
|
case ^ast.Distinct_Type:
|
||||||
push_generic_token(p, .Distinct, 1)
|
push_generic_token(p, .Distinct, 1)
|
||||||
visit_expr(p, v.type)
|
visit_expr(p, v.type)
|
||||||
case ^Dynamic_Array_Type:
|
case ^ast.Dynamic_Array_Type:
|
||||||
visit_expr(p, v.tag)
|
visit_expr(p, v.tag)
|
||||||
push_generic_token(p, .Open_Bracket, 1)
|
push_generic_token(p, .Open_Bracket, 1)
|
||||||
push_generic_token(p, .Dynamic, 0)
|
push_generic_token(p, .Dynamic, 0)
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.elem)
|
visit_expr(p, v.elem)
|
||||||
case ^Bit_Set_Type:
|
case ^ast.Bit_Set_Type:
|
||||||
push_generic_token(p, .Bit_Set, 1)
|
push_generic_token(p, .Bit_Set, 1)
|
||||||
push_generic_token(p, .Open_Bracket, 0)
|
push_generic_token(p, .Open_Bracket, 0)
|
||||||
|
|
||||||
@@ -1041,7 +1035,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
case ^Union_Type:
|
case ^ast.Union_Type:
|
||||||
push_generic_token(p, .Union, 1)
|
push_generic_token(p, .Union, 1)
|
||||||
|
|
||||||
push_poly_params(p, v.poly_params)
|
push_poly_params(p, v.poly_params)
|
||||||
@@ -1066,7 +1060,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
visit_exprs(p, v.variants, {.Add_Comma, .Trailing})
|
visit_exprs(p, v.variants, {.Add_Comma, .Trailing})
|
||||||
visit_end_brace(p, v.end)
|
visit_end_brace(p, v.end)
|
||||||
}
|
}
|
||||||
case ^Enum_Type:
|
case ^ast.Enum_Type:
|
||||||
push_generic_token(p, .Enum, 1)
|
push_generic_token(p, .Enum, 1)
|
||||||
|
|
||||||
hint_current_line(p, {.Enum})
|
hint_current_line(p, {.Enum})
|
||||||
@@ -1089,7 +1083,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_source_position(p, v.end)
|
set_source_position(p, v.end)
|
||||||
case ^Struct_Type:
|
case ^ast.Struct_Type:
|
||||||
push_generic_token(p, .Struct, 1)
|
push_generic_token(p, .Struct, 1)
|
||||||
|
|
||||||
hint_current_line(p, {.Struct})
|
hint_current_line(p, {.Struct})
|
||||||
@@ -1124,7 +1118,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_source_position(p, v.end)
|
set_source_position(p, v.end)
|
||||||
case ^Proc_Lit:
|
case ^ast.Proc_Lit:
|
||||||
switch v.inlining {
|
switch v.inlining {
|
||||||
case .None:
|
case .None:
|
||||||
case .Inline:
|
case .Inline:
|
||||||
@@ -1143,16 +1137,16 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
} else {
|
} else {
|
||||||
push_generic_token(p, .Undef, 1)
|
push_generic_token(p, .Undef, 1)
|
||||||
}
|
}
|
||||||
case ^Proc_Type:
|
case ^ast.Proc_Type:
|
||||||
visit_proc_type(p, v)
|
visit_proc_type(p, v)
|
||||||
case ^Basic_Lit:
|
case ^ast.Basic_Lit:
|
||||||
push_generic_token(p, v.tok.kind, 1, v.tok.text)
|
push_generic_token(p, v.tok.kind, 1, v.tok.text)
|
||||||
case ^Binary_Expr:
|
case ^ast.Binary_Expr:
|
||||||
visit_binary_expr(p, v)
|
visit_binary_expr(p, v)
|
||||||
case ^Implicit_Selector_Expr:
|
case ^ast.Implicit_Selector_Expr:
|
||||||
push_generic_token(p, .Period, 1)
|
push_generic_token(p, .Period, 1)
|
||||||
push_ident_token(p, v.field.name, 0)
|
push_ident_token(p, v.field.name, 0)
|
||||||
case ^Call_Expr:
|
case ^ast.Call_Expr:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
|
|
||||||
push_format_token(p,
|
push_format_token(p,
|
||||||
@@ -1167,34 +1161,34 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
|
|
||||||
visit_call_exprs(p, v.args, v.ellipsis.kind == .Ellipsis)
|
visit_call_exprs(p, v.args, v.ellipsis.kind == .Ellipsis)
|
||||||
push_generic_token(p, .Close_Paren, 0)
|
push_generic_token(p, .Close_Paren, 0)
|
||||||
case ^Typeid_Type:
|
case ^ast.Typeid_Type:
|
||||||
push_generic_token(p, .Typeid, 1)
|
push_generic_token(p, .Typeid, 1)
|
||||||
|
|
||||||
if v.specialization != nil {
|
if v.specialization != nil {
|
||||||
push_generic_token(p, .Quo, 0)
|
push_generic_token(p, .Quo, 0)
|
||||||
visit_expr(p, v.specialization)
|
visit_expr(p, v.specialization)
|
||||||
}
|
}
|
||||||
case ^Selector_Expr:
|
case ^ast.Selector_Expr:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
push_generic_token(p, v.op.kind, 0)
|
push_generic_token(p, v.op.kind, 0)
|
||||||
visit_expr(p, v.field)
|
visit_expr(p, v.field)
|
||||||
case ^Paren_Expr:
|
case ^ast.Paren_Expr:
|
||||||
push_generic_token(p, .Open_Paren, 1)
|
push_generic_token(p, .Open_Paren, 1)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
push_generic_token(p, .Close_Paren, 0)
|
push_generic_token(p, .Close_Paren, 0)
|
||||||
case ^Index_Expr:
|
case ^ast.Index_Expr:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
push_generic_token(p, .Open_Bracket, 0)
|
push_generic_token(p, .Open_Bracket, 0)
|
||||||
visit_expr(p, v.index)
|
visit_expr(p, v.index)
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
case ^Matrix_Index_Expr:
|
case ^ast.Matrix_Index_Expr:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
push_generic_token(p, .Open_Bracket, 0)
|
push_generic_token(p, .Open_Bracket, 0)
|
||||||
visit_expr(p, v.row_index)
|
visit_expr(p, v.row_index)
|
||||||
push_generic_token(p, .Comma, 0)
|
push_generic_token(p, .Comma, 0)
|
||||||
visit_expr(p, v.column_index)
|
visit_expr(p, v.column_index)
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
case ^Proc_Group:
|
case ^ast.Proc_Group:
|
||||||
push_generic_token(p, v.tok.kind, 1)
|
push_generic_token(p, v.tok.kind, 1)
|
||||||
|
|
||||||
if len(v.args) != 0 && v.pos.line != v.args[len(v.args) - 1].pos.line {
|
if len(v.args) != 0 && v.pos.line != v.args[len(v.args) - 1].pos.line {
|
||||||
@@ -1209,7 +1203,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
push_generic_token(p, .Close_Brace, 0)
|
push_generic_token(p, .Close_Brace, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ^Comp_Lit:
|
case ^ast.Comp_Lit:
|
||||||
if v.type != nil {
|
if v.type != nil {
|
||||||
visit_expr(p, v.type)
|
visit_expr(p, v.type)
|
||||||
}
|
}
|
||||||
@@ -1226,18 +1220,18 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
push_generic_token(p, .Close_Brace, 0)
|
push_generic_token(p, .Close_Brace, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ^Unary_Expr:
|
case ^ast.Unary_Expr:
|
||||||
push_generic_token(p, v.op.kind, 1)
|
push_generic_token(p, v.op.kind, 1)
|
||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
case ^Field_Value:
|
case ^ast.Field_Value:
|
||||||
visit_expr(p, v.field)
|
visit_expr(p, v.field)
|
||||||
push_generic_token(p, .Eq, 1)
|
push_generic_token(p, .Eq, 1)
|
||||||
visit_expr(p, v.value)
|
visit_expr(p, v.value)
|
||||||
case ^Type_Assertion:
|
case ^ast.Type_Assertion:
|
||||||
visit_expr(p, v.expr)
|
visit_expr(p, v.expr)
|
||||||
|
|
||||||
if unary, ok := v.type.derived.(^Unary_Expr); ok && unary.op.text == "?" {
|
if unary, ok := v.type.derived.(^ast.Unary_Expr); ok && unary.op.text == "?" {
|
||||||
push_generic_token(p, .Period, 0)
|
push_generic_token(p, .Period, 0)
|
||||||
visit_expr(p, v.type)
|
visit_expr(p, v.type)
|
||||||
} else {
|
} else {
|
||||||
@@ -1247,13 +1241,13 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
push_generic_token(p, .Close_Paren, 0)
|
push_generic_token(p, .Close_Paren, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ^Pointer_Type:
|
case ^ast.Pointer_Type:
|
||||||
push_generic_token(p, .Pointer, 1)
|
push_generic_token(p, .Pointer, 1)
|
||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.elem)
|
visit_expr(p, v.elem)
|
||||||
case ^Implicit:
|
case ^ast.Implicit:
|
||||||
push_generic_token(p, v.tok.kind, 1)
|
push_generic_token(p, v.tok.kind, 1)
|
||||||
case ^Poly_Type:
|
case ^ast.Poly_Type:
|
||||||
push_generic_token(p, .Dollar, 1)
|
push_generic_token(p, .Dollar, 1)
|
||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.type)
|
visit_expr(p, v.type)
|
||||||
@@ -1263,28 +1257,28 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.specialization)
|
visit_expr(p, v.specialization)
|
||||||
}
|
}
|
||||||
case ^Array_Type:
|
case ^ast.Array_Type:
|
||||||
visit_expr(p, v.tag)
|
visit_expr(p, v.tag)
|
||||||
push_generic_token(p, .Open_Bracket, 1)
|
push_generic_token(p, .Open_Bracket, 1)
|
||||||
visit_expr(p, v.len)
|
visit_expr(p, v.len)
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.elem)
|
visit_expr(p, v.elem)
|
||||||
case ^Map_Type:
|
case ^ast.Map_Type:
|
||||||
push_generic_token(p, .Map, 1)
|
push_generic_token(p, .Map, 1)
|
||||||
push_generic_token(p, .Open_Bracket, 0)
|
push_generic_token(p, .Open_Bracket, 0)
|
||||||
visit_expr(p, v.key)
|
visit_expr(p, v.key)
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
merge_next_token(p)
|
merge_next_token(p)
|
||||||
visit_expr(p, v.value)
|
visit_expr(p, v.value)
|
||||||
case ^Helper_Type:
|
case ^ast.Helper_Type:
|
||||||
visit_expr(p, v.type)
|
visit_expr(p, v.type)
|
||||||
case ^Multi_Pointer_Type:
|
case ^ast.Multi_Pointer_Type:
|
||||||
push_generic_token(p, .Open_Bracket, 1)
|
push_generic_token(p, .Open_Bracket, 1)
|
||||||
push_generic_token(p, .Pointer, 0)
|
push_generic_token(p, .Pointer, 0)
|
||||||
push_generic_token(p, .Close_Bracket, 0)
|
push_generic_token(p, .Close_Bracket, 0)
|
||||||
visit_expr(p, v.elem)
|
visit_expr(p, v.elem)
|
||||||
case ^Matrix_Type:
|
case ^ast.Matrix_Type:
|
||||||
push_generic_token(p, .Matrix, 1)
|
push_generic_token(p, .Matrix, 1)
|
||||||
push_generic_token(p, .Open_Bracket, 0)
|
push_generic_token(p, .Open_Bracket, 0)
|
||||||
visit_expr(p, v.row_count)
|
visit_expr(p, v.row_count)
|
||||||
|
|||||||
@@ -218,10 +218,10 @@ enum BuildPath : u8 {
|
|||||||
|
|
||||||
enum VetFlags : u64 {
|
enum VetFlags : u64 {
|
||||||
VetFlag_NONE = 0,
|
VetFlag_NONE = 0,
|
||||||
VetFlag_Unused = 1u<<0,
|
VetFlag_Unused = 1u<<0, // 1
|
||||||
VetFlag_Shadowing = 1u<<1,
|
VetFlag_Shadowing = 1u<<1, // 2
|
||||||
VetFlag_UsingStmt = 1u<<2,
|
VetFlag_UsingStmt = 1u<<2, // 4
|
||||||
VetFlag_UsingParam = 1u<<3,
|
VetFlag_UsingParam = 1u<<3, // 8
|
||||||
|
|
||||||
VetFlag_Extra = 1u<<16,
|
VetFlag_Extra = 1u<<16,
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1064,7 +1064,7 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
|||||||
auto *fp = &ctx->info->foreigns;
|
auto *fp = &ctx->info->foreigns;
|
||||||
StringHashKey key = string_hash_string(name);
|
StringHashKey key = string_hash_string(name);
|
||||||
Entity **found = string_map_get(fp, key);
|
Entity **found = string_map_get(fp, key);
|
||||||
if (found) {
|
if (found && e != *found) {
|
||||||
Entity *f = *found;
|
Entity *f = *found;
|
||||||
TokenPos pos = f->token.pos;
|
TokenPos pos = f->token.pos;
|
||||||
Type *this_type = base_type(e->type);
|
Type *this_type = base_type(e->type);
|
||||||
@@ -1636,7 +1636,7 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
|||||||
}
|
}
|
||||||
check_close_scope(ctx);
|
check_close_scope(ctx);
|
||||||
|
|
||||||
check_scope_usage(ctx->checker, ctx->scope, check_vet_flags(ctx));
|
check_scope_usage(ctx->checker, ctx->scope, check_vet_flags(body));
|
||||||
|
|
||||||
add_deps_from_child_to_parent(decl);
|
add_deps_from_child_to_parent(decl);
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -3099,7 +3099,7 @@ gb_internal void check_cast(CheckerContext *c, Operand *x, Type *type) {
|
|||||||
update_untyped_expr_type(c, x->expr, final_type, true);
|
update_untyped_expr_type(c, x->expr, final_type, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_vet_flags(c) & VetFlag_Extra) {
|
if (check_vet_flags(x->expr) & VetFlag_Extra) {
|
||||||
if (are_types_identical(x->type, type)) {
|
if (are_types_identical(x->type, type)) {
|
||||||
gbString str = type_to_string(type);
|
gbString str = type_to_string(type);
|
||||||
warning(x->expr, "Unneeded cast to the same type '%s'", str);
|
warning(x->expr, "Unneeded cast to the same type '%s'", str);
|
||||||
@@ -3171,7 +3171,7 @@ gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_vet_flags(c) & VetFlag_Extra) {
|
if (check_vet_flags(node) & VetFlag_Extra) {
|
||||||
if (are_types_identical(o->type, dst_t)) {
|
if (are_types_identical(o->type, dst_t)) {
|
||||||
gbString str = type_to_string(dst_t);
|
gbString str = type_to_string(dst_t);
|
||||||
warning(o->expr, "Unneeded transmute to the same type '%s'", str);
|
warning(o->expr, "Unneeded transmute to the same type '%s'", str);
|
||||||
@@ -10028,7 +10028,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast
|
|||||||
Type *type = type_of_expr(ac->expr);
|
Type *type = type_of_expr(ac->expr);
|
||||||
check_cast(c, o, type_hint);
|
check_cast(c, o, type_hint);
|
||||||
if (is_type_typed(type) && are_types_identical(type, type_hint)) {
|
if (is_type_typed(type) && are_types_identical(type, type_hint)) {
|
||||||
if (check_vet_flags(c) & VetFlag_Extra) {
|
if (check_vet_flags(node) & VetFlag_Extra) {
|
||||||
error(node, "Redundant 'auto_cast' applied to expression");
|
error(node, "Redundant 'auto_cast' applied to expression");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -2464,9 +2464,9 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
|||||||
error(us->token, "Empty 'using' list");
|
error(us->token, "Empty 'using' list");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (check_vet_flags(ctx) & VetFlag_UsingStmt) {
|
if (check_vet_flags(node) & VetFlag_UsingStmt) {
|
||||||
ERROR_BLOCK();
|
ERROR_BLOCK();
|
||||||
error(node, "'using' as a statement is now allowed when '-vet' or '-vet-using' is applied");
|
error(node, "'using' as a statement is now allowed when '-vet' or '-vet-using' is applied %llu %llu", check_vet_flags(ctx), node->file()->vet_flags);
|
||||||
error_line("\t'using' is considered bad practice to use as a statement outside of immediate refactoring\n");
|
error_line("\t'using' is considered bad practice to use as a statement outside of immediate refactoring\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -521,6 +521,28 @@ GB_COMPARE_PROC(entity_variable_pos_cmp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
gb_internal u64 check_vet_flags(CheckerContext *c) {
|
||||||
|
AstFile *file = c->file;
|
||||||
|
if (file == nullptr &&
|
||||||
|
c->curr_proc_decl &&
|
||||||
|
c->curr_proc_decl->proc_lit) {
|
||||||
|
file = c->curr_proc_decl->proc_lit->file();
|
||||||
|
}
|
||||||
|
if (file && file->vet_flags_set) {
|
||||||
|
return file->vet_flags;
|
||||||
|
}
|
||||||
|
return build_context.vet_flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
gb_internal u64 check_vet_flags(Ast *node) {
|
||||||
|
AstFile *file = node->file();
|
||||||
|
if (file && file->vet_flags_set) {
|
||||||
|
return file->vet_flags;
|
||||||
|
}
|
||||||
|
return build_context.vet_flags;
|
||||||
|
}
|
||||||
|
|
||||||
enum VettedEntityKind {
|
enum VettedEntityKind {
|
||||||
VettedEntity_Invalid,
|
VettedEntity_Invalid,
|
||||||
|
|
||||||
|
|||||||
+2
-6
@@ -449,12 +449,8 @@ struct CheckerContext {
|
|||||||
Ast *assignment_lhs_hint;
|
Ast *assignment_lhs_hint;
|
||||||
};
|
};
|
||||||
|
|
||||||
u64 check_vet_flags(CheckerContext *c) {
|
gb_internal u64 check_vet_flags(CheckerContext *c);
|
||||||
if (c->file && c->file->vet_flags_set) {
|
gb_internal u64 check_vet_flags(Ast *node);
|
||||||
return c->file->vet_flags;
|
|
||||||
}
|
|
||||||
return build_context.vet_flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct Checker {
|
struct Checker {
|
||||||
|
|||||||
+14
-9
@@ -5563,7 +5563,9 @@ gb_internal u64 parse_vet_tag(Token token_for_pos, String s) {
|
|||||||
|
|
||||||
while (s.len > 0) {
|
while (s.len > 0) {
|
||||||
String p = string_trim_whitespace(vet_tag_get_token(s, &s));
|
String p = string_trim_whitespace(vet_tag_get_token(s, &s));
|
||||||
if (p.len == 0) break;
|
if (p.len == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_notted = false;
|
bool is_notted = false;
|
||||||
if (p[0] == '!') {
|
if (p[0] == '!') {
|
||||||
@@ -5571,14 +5573,10 @@ gb_internal u64 parse_vet_tag(Token token_for_pos, String s) {
|
|||||||
p = substring(p, 1, p.len);
|
p = substring(p, 1, p.len);
|
||||||
if (p.len == 0) {
|
if (p.len == 0) {
|
||||||
syntax_error(token_for_pos, "Expected a vet flag name after '!'");
|
syntax_error(token_for_pos, "Expected a vet flag name after '!'");
|
||||||
break;
|
return build_context.vet_flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.len == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 flag = get_vet_flag_from_name(p);
|
u64 flag = get_vet_flag_from_name(p);
|
||||||
if (flag != VetFlag_NONE) {
|
if (flag != VetFlag_NONE) {
|
||||||
if (is_notted) {
|
if (is_notted) {
|
||||||
@@ -5595,13 +5593,20 @@ gb_internal u64 parse_vet_tag(Token token_for_pos, String s) {
|
|||||||
error_line("\tusing-stmt\n");
|
error_line("\tusing-stmt\n");
|
||||||
error_line("\tusing-param\n");
|
error_line("\tusing-param\n");
|
||||||
error_line("\textra\n");
|
error_line("\textra\n");
|
||||||
break;
|
return build_context.vet_flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vet_flags == 0 && vet_not_flags != 0) {
|
if (vet_flags == 0 && vet_not_flags == 0) {
|
||||||
vet_flags = VetFlag_All;
|
return build_context.vet_flags;
|
||||||
}
|
}
|
||||||
|
if (vet_flags == 0 && vet_not_flags != 0) {
|
||||||
|
return build_context.vet_flags &~ vet_not_flags;
|
||||||
|
}
|
||||||
|
if (vet_flags != 0 && vet_not_flags == 0) {
|
||||||
|
return vet_flags;
|
||||||
|
}
|
||||||
|
GB_ASSERT(vet_flags != 0 && vet_not_flags != 0);
|
||||||
return vet_flags &~ vet_not_flags;
|
return vet_flags &~ vet_not_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user