Skip to content

Commit

Permalink
ast,fmt,parser: fix attribute alignment & remove unneeded code (#19826)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-conigliaro committed Nov 10, 2023
1 parent ab4c1f4 commit 7087b53
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion vlib/v/ast/ast.v
Expand Up @@ -324,7 +324,6 @@ pub:
comments []Comment
i int
has_default_expr bool
attrs_has_at bool // TODO: remove in next stage
attrs []Attr
is_pub bool
default_val string
Expand Down
7 changes: 4 additions & 3 deletions vlib/v/fmt/struct.v
Expand Up @@ -145,8 +145,9 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool) {
f.mark_types_import_as_used(field.typ)
attrs_len := inline_attrs_len(field.attrs)
has_attrs := field.attrs.len > 0
has_at := if has_attrs { field.attrs[0].has_at } else { false }
// TODO: this will get removed in next stage
if has_attrs && !field.attrs_has_at {
if has_attrs && !has_at {
f.write(strings.repeat(` `, field_align.max_type_len - field_types[i].len))
f.single_line_attrs(field.attrs, same_line: true)
}
Expand All @@ -168,8 +169,8 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool) {
inc_indent = false
}
}
if has_attrs && field.attrs_has_at {
// TODO: calculate correct padding
if has_attrs && has_at {
f.write(strings.repeat(` `, field_align.max_type_len - field_types[i].len))
f.single_line_attrs(field.attrs, same_line: true)
}
// Handle comments after field type
Expand Down
3 changes: 0 additions & 3 deletions vlib/v/parser/struct.v
Expand Up @@ -295,9 +295,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
has_default_expr = true
comments << p.eat_comments()
}
mut has_at := false // TODO: remove in next stage
if p.tok.kind == .at {
has_at = true
p.inside_struct_attr_decl = true
// attrs are stored in `p.attrs`
p.attributes()
Expand All @@ -318,7 +316,6 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
i: i
default_expr: default_expr
has_default_expr: has_default_expr
attrs_has_at: has_at
attrs: p.attrs
is_pub: is_embed || is_field_pub
is_mut: is_embed || is_field_mut
Expand Down

0 comments on commit 7087b53

Please sign in to comment.