Skip to content

Commit

Permalink
rm @inline i dunno what this even does tbh
Browse files Browse the repository at this point in the history
  • Loading branch information
domluna committed Dec 24, 2023
1 parent bf427e6 commit 67c81d2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/JuliaFormatter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end

abstract type AbstractStyle end

@inline options(s::AbstractStyle) = NamedTuple()
options(s::AbstractStyle) = NamedTuple()

struct NoopStyle <: AbstractStyle end

Expand Down
76 changes: 38 additions & 38 deletions src/fst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,39 +174,39 @@ function FST(
)
end

@inline function Base.setindex!(fst::FST, node::FST, ind::Int)
function Base.setindex!(fst::FST, node::FST, ind::Int)
nodes = fst.nodes::Vector{FST}
fst.len -= nodes[ind].len
nodes[ind] = node
fst.len += node.len
end
@inline Base.getindex(fst::FST, inds...) = (fst.nodes::Vector{FST})[inds...]
@inline Base.lastindex(fst::FST) = length(fst.nodes::Vector{FST})
@inline Base.firstindex(fst::FST) = 1
@inline Base.length(fst::FST) = fst.len
@inline function Base.iterate(fst::FST, state = 1)
Base.getindex(fst::FST, inds...) = (fst.nodes::Vector{FST})[inds...]
Base.lastindex(fst::FST) = length(fst.nodes::Vector{FST})
Base.firstindex(fst::FST) = 1
Base.length(fst::FST) = fst.len
function Base.iterate(fst::FST, state = 1)
nodes = fst.nodes::Vector{FST}
if state > length(nodes::Vector{FST})
return nothing
end
return nodes[state], state + 1
end

@inline function Base.insert!(fst::FST, ind::Int, node::FST)
function Base.insert!(fst::FST, ind::Int, node::FST)
insert!(fst.nodes::Vector{FST}, ind, node)
fst.len += node.len
return
end

@inline Newline(; length = 0, nest_behavior = AllowNest) =
Newline(; length = 0, nest_behavior = AllowNest) =
FST(NEWLINE, -1, -1, 0, length, "\n", nothing, nothing, nest_behavior, 0, -1, nothing)
@inline Semicolon() =
Semicolon() =
FST(SEMICOLON, -1, -1, 0, 1, ";", nothing, nothing, AllowNest, 0, -1, nothing)
@inline TrailingComma() =
TrailingComma() =
FST(TRAILINGCOMMA, -1, -1, 0, 0, "", nothing, nothing, AllowNest, 0, -1, nothing)
@inline TrailingSemicolon() =
TrailingSemicolon() =
FST(TRAILINGSEMICOLON, -1, -1, 0, 0, "", nothing, nothing, AllowNest, 0, -1, nothing)
@inline InverseTrailingSemicolon() = FST(
InverseTrailingSemicolon() = FST(
INVERSETRAILINGSEMICOLON,
-1,
-1,
Expand All @@ -220,36 +220,36 @@ end
-1,
nothing,
)
@inline Whitespace(n) =
Whitespace(n) =
FST(WHITESPACE, -1, -1, 0, n, " "^n, nothing, nothing, AllowNest, 0, -1, nothing)
@inline Placeholder(n) =
Placeholder(n) =
FST(PLACEHOLDER, -1, -1, 0, n, " "^n, nothing, nothing, AllowNest, 0, -1, nothing)
@inline Notcode(startline, endline) =
Notcode(startline, endline) =
FST(NOTCODE, startline, endline, 0, 0, "", nothing, nothing, AllowNest, 0, -1, nothing)
@inline InlineComment(line) =
InlineComment(line) =
FST(INLINECOMMENT, line, line, 0, 0, "", nothing, nothing, AllowNest, 0, -1, nothing)

@inline must_nest(fst::FST) = fst.nest_behavior === AlwaysNest
@inline cant_nest(fst::FST) = fst.nest_behavior === NeverNest
@inline can_nest(fst::FST) = fst.nest_behavior === AllowNest
must_nest(fst::FST) = fst.nest_behavior === AlwaysNest
cant_nest(fst::FST) = fst.nest_behavior === NeverNest
can_nest(fst::FST) = fst.nest_behavior === AllowNest

@inline is_leaf(cst::CSTParser.EXPR) = cst.args === nothing
@inline is_leaf(fst::FST) = fst.nodes === nothing
is_leaf(cst::CSTParser.EXPR) = cst.args === nothing
is_leaf(fst::FST) = fst.nodes === nothing

@inline is_punc(cst::CSTParser.EXPR) = CSTParser.ispunctuation(cst)
@inline is_punc(fst::FST) = fst.typ === PUNCTUATION
is_punc(cst::CSTParser.EXPR) = CSTParser.ispunctuation(cst)
is_punc(fst::FST) = fst.typ === PUNCTUATION

@inline is_end(x::CSTParser.EXPR) = x.head === :END && x.val == "end"
@inline is_end(x::FST) = x.typ === KEYWORD && x.val == "end"
is_end(x::CSTParser.EXPR) = x.head === :END && x.val == "end"
is_end(x::FST) = x.typ === KEYWORD && x.val == "end"

@inline is_colon(x::FST) = x.typ === OPERATOR && x.val == ":"
is_colon(x::FST) = x.typ === OPERATOR && x.val == ":"

@inline is_comma(fst::FST) = fst.typ === TRAILINGCOMMA || (is_punc(fst) && fst.val == ",")
@inline is_comment(fst::FST) = fst.typ === INLINECOMMENT || fst.typ === NOTCODE
is_comma(fst::FST) = fst.typ === TRAILINGCOMMA || (is_punc(fst) && fst.val == ",")
is_comment(fst::FST) = fst.typ === INLINECOMMENT || fst.typ === NOTCODE

@inline is_circumflex_accent(x::CSTParser.EXPR) =
is_circumflex_accent(x::CSTParser.EXPR) =
CSTParser.isoperator(x) && endswith(CSTParser.valof(x)::String, "^")
@inline is_fwdfwd_slash(x::CSTParser.EXPR) =
is_fwdfwd_slash(x::CSTParser.EXPR) =
CSTParser.isoperator(x) && endswith(CSTParser.valof(x)::String, "//")

# TODO: fix this
Expand All @@ -264,7 +264,7 @@ function is_multiline(fst::FST)
)
end

@inline is_macrocall(fst::FST) = fst.typ === MacroCall || fst.typ === MacroBlock
is_macrocall(fst::FST) = fst.typ === MacroCall || fst.typ === MacroBlock

function is_macrodoc(cst::CSTParser.EXPR)
cst.head === :macrocall &&
Expand Down Expand Up @@ -430,7 +430,7 @@ function get_args(args::Nothing)
return CSTParser.EXPR[]
end

@inline n_args(x) = length(get_args(x))
n_args(x) = length(get_args(x))

"""
add_node!(
Expand Down Expand Up @@ -693,7 +693,7 @@ function add_node!(
nothing
end

@inline function is_prev_newline(fst::FST)
function is_prev_newline(fst::FST)
if fst.typ === NEWLINE
return true
elseif is_leaf(fst) || length(fst.nodes::Vector) == 0
Expand All @@ -707,7 +707,7 @@ end
Returns the length to any node type in `ntyps` based off the `start` index.
"""
@inline function length_to(fst::FST, ntyps; start::Int = 1)
function length_to(fst::FST, ntyps; start::Int = 1)
fst.typ in ntyps && return 0, true
is_leaf(fst) && return length(fst), false
len = 0
Expand All @@ -720,14 +720,14 @@ Returns the length to any node type in `ntyps` based off the `start` index.
return len, false
end

@inline is_closer(fst::FST) =
is_closer(fst::FST) =
fst.typ === PUNCTUATION && (fst.val == "}" || fst.val == ")" || fst.val == "]")
@inline is_closer(cst::CSTParser.EXPR) =
is_closer(cst::CSTParser.EXPR) =
cst.head === :RBRACE || cst.head === :RPAREN || cst.head === :RSQUARE

@inline is_opener(fst::FST) =
is_opener(fst::FST) =
fst.typ === PUNCTUATION && (fst.val == "{" || fst.val == "(" || fst.val == "[")
@inline is_opener(cst::CSTParser.EXPR) =
is_opener(cst::CSTParser.EXPR) =
cst.head === :LBRACE || cst.head === :LPAREN || cst.head === :LSQUARE

function is_iterable(x::CSTParser.EXPR)
Expand Down
8 changes: 4 additions & 4 deletions src/state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mutable struct State
end
State(doc, opts) = State(doc, 0, 1, 0, true, opts)

@inline nspaces(s::State) = s.indent
@inline hascomment(d::Document, line::Integer) = haskey(d.comments, line)
nspaces(s::State) = s.indent
hascomment(d::Document, line::Integer) = haskey(d.comments, line)

"""
has_semicolon(d::Document, line::Integer)
Expand All @@ -24,12 +24,12 @@ function has_semicolon(d::Document, line::Integer)
return length(d.semicolons[line]) > 0
end

@inline function cursor_loc(s::State, offset::Integer)
function cursor_loc(s::State, offset::Integer)
l = s.doc.range_to_line[offset:offset]
r = s.doc.line_to_range[l]
return (l, offset - first(r) + 1, length(r))
end
@inline cursor_loc(s::State) = cursor_loc(s, s.offset)
cursor_loc(s::State) = cursor_loc(s, s.offset)

function on_same_line(s::State, offset1::Int, offset2::Int)
l = s.doc.range_to_line[offset1:offset1]
Expand Down
18 changes: 9 additions & 9 deletions src/styles/blue/nest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ function n_tuple!(bs::BlueStyle, fst::FST, s::State)
nest!(style, nodes, s, fst.indent, extra_margin = extra_margin)
end
end
@inline n_call!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_curly!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_macrocall!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_ref!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_braces!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_vect!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_parameters!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_invisbrackets!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
@inline n_bracescat!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_call!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_curly!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_macrocall!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_ref!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_braces!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_vect!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_parameters!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_invisbrackets!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)
n_bracescat!(bs::BlueStyle, fst::FST, s::State) = n_tuple!(bs, fst, s)

function n_conditionalopcall!(bs::BlueStyle, fst::FST, s::State)
style = getstyle(bs)
Expand Down
10 changes: 5 additions & 5 deletions src/styles/default/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ end
p_file(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
p_file(DefaultStyle(style), cst, s)

@inline function p_nonstdidentifier(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
function p_nonstdidentifier(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
style = getstyle(ds)
t = FST(NonStdIdentifier, cst, nspaces(s))
for a in cst.args::Vector{CSTParser.EXPR}
Expand All @@ -186,15 +186,15 @@ end
p_nonstdidentifier(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
p_nonstdidentifier(DefaultStyle(style), cst, s)

@inline function p_identifier(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
function p_identifier(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
loc = cursor_loc(s)
s.offset += length(cst.val::AbstractString) + (cst.fullspan - cst.span)
FST(IDENTIFIER, loc[2], loc[1], loc[1], cst.val::AbstractString)
end
p_identifier(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
p_identifier(DefaultStyle(style), cst, s)

@inline function p_operator(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
function p_operator(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
loc = cursor_loc(s)
s.offset += length(cst.val::AbstractString) + (cst.fullspan - cst.span)

Expand All @@ -205,15 +205,15 @@ end
p_operator(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
p_operator(DefaultStyle(style), cst, s)

@inline function p_keyword(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
function p_keyword(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
loc = cursor_loc(s)
s.offset += cst.fullspan
FST(KEYWORD, loc[2], loc[1], loc[1], cst.val::AbstractString)
end
p_keyword(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
p_keyword(DefaultStyle(style), cst, s)

@inline function p_punctuation(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
function p_punctuation(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
loc = cursor_loc(s)
s.offset += cst.fullspan
val = if cst.val === nothing && cst.head === :DOT
Expand Down
32 changes: 16 additions & 16 deletions src/styles/yas/nest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ function n_call!(ys::YASStyle, fst::FST, s::State)
end
end
end
@inline n_curly!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
@inline n_ref!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
@inline n_macrocall!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
@inline n_typedcomprehension!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
@inline n_typedvcat!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
n_curly!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
n_ref!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
n_macrocall!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
n_typedcomprehension!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)
n_typedvcat!(ys::YASStyle, fst::FST, s::State) = n_call!(ys, fst, s)

function n_tuple!(ys::YASStyle, fst::FST, s::State)
style = getstyle(ys)
Expand Down Expand Up @@ -89,13 +89,13 @@ function n_tuple!(ys::YASStyle, fst::FST, s::State)
end
end
end
@inline n_braces!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
@inline n_vect!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
@inline n_parameters!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
@inline n_invisbrackets!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
@inline n_comprehension!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
@inline n_vcat!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
@inline n_bracescat!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
n_braces!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
n_vect!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
n_parameters!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
n_invisbrackets!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
n_comprehension!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
n_vcat!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)
n_bracescat!(ys::YASStyle, fst::FST, s::State) = n_tuple!(ys, fst, s)

function n_generator!(ys::YASStyle, fst::FST, s::State)
style = getstyle(ys)
Expand Down Expand Up @@ -123,8 +123,8 @@ function n_generator!(ys::YASStyle, fst::FST, s::State)
end
end
end
@inline n_filter!(ys::YASStyle, fst::FST, s::State) = n_generator!(ys, fst, s)
@inline n_flatten!(ys::YASStyle, fst::FST, s::State) = n_generator!(ys, fst, s)
n_filter!(ys::YASStyle, fst::FST, s::State) = n_generator!(ys, fst, s)
n_flatten!(ys::YASStyle, fst::FST, s::State) = n_generator!(ys, fst, s)

function n_whereopcall!(ys::YASStyle, fst::FST, s::State)
style = getstyle(ys)
Expand Down Expand Up @@ -173,8 +173,8 @@ function n_using!(ys::YASStyle, fst::FST, s::State)
end
end
end
@inline n_export!(ys::YASStyle, fst::FST, s::State) = n_using!(ys, fst, s)
@inline n_import!(ys::YASStyle, fst::FST, s::State) = n_using!(ys, fst, s)
n_export!(ys::YASStyle, fst::FST, s::State) = n_using!(ys, fst, s)
n_import!(ys::YASStyle, fst::FST, s::State) = n_using!(ys, fst, s)

function n_chainopcall!(ys::YASStyle, fst::FST, s::State)
style = getstyle(ys)
Expand Down

0 comments on commit 67c81d2

Please sign in to comment.