Skip to content

Commit 63aa9b2

Browse files
mlechuc42f
authored andcommitted
Remove use of JuliaSyntax DOTOP_FLAG and is_dotted
These have been removed upstream on the main branch and replaced with a small number of new `Kind`s.
1 parent 5416caa commit 63aa9b2

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

src/JuliaLowering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using JuliaSyntax: highlight, Kind, @KSet_str
1313
using JuliaSyntax: is_leaf, children, numchildren, head, kind, flags, has_flags, numeric_flags
1414
using JuliaSyntax: filename, first_byte, last_byte, byte_range, sourcefile, source_location, span, sourcetext
1515

16-
using JuliaSyntax: is_literal, is_number, is_operator, is_prec_assignment, is_prefix_call, is_infix_op_call, is_postfix_op_call, is_error, is_dotted
16+
using JuliaSyntax: is_literal, is_number, is_operator, is_prec_assignment, is_prefix_call, is_infix_op_call, is_postfix_op_call, is_error
1717

1818
_include("kinds.jl")
1919
_register_kinds()

src/desugaring.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,10 @@ function expand_dotcall(ctx, ex)
690690
]
691691
elseif k == K"comparison"
692692
expand_dotcall(ctx, expand_compare_chain(ctx, ex))
693-
elseif (k == K"&&" || k == K"||") && is_dotted(ex)
693+
elseif k == K".&&" || k == K".||"
694694
@ast ctx ex [K"call"
695695
"broadcasted"::K"top"
696-
(k == K"&&" ? "andand" : "oror")::K"top"
696+
(k == K".&&" ? "andand" : "oror")::K"top"
697697
(expand_dotcall(ctx, arg) for arg in children(ex))...
698698
]
699699
else
@@ -702,8 +702,7 @@ function expand_dotcall(ctx, ex)
702702
end
703703

704704
function expand_fuse_broadcast(ctx, ex)
705-
if kind(ex) == K"="
706-
@assert is_dotted(ex)
705+
if kind(ex) == K".=" || kind(ex) == K".op="
707706
@chk numchildren(ex) == 2
708707
lhs = ex[1]
709708
kl = kind(lhs)
@@ -1293,7 +1292,7 @@ end
12931292

12941293
function expand_update_operator(ctx, ex)
12951294
k = kind(ex)
1296-
dotted = is_dotted(ex)
1295+
dotted = k == K".op="
12971296

12981297
@chk numchildren(ex) == 3
12991298
lhs = ex[1]
@@ -1335,7 +1334,7 @@ function expand_update_operator(ctx, ex)
13351334

13361335
@ast ctx ex [K"block"
13371336
stmts...
1338-
[K"="(syntax_flags=(dotted ? JuliaSyntax.DOTOP_FLAG : nothing))
1337+
[(dotted ? K".=" : K"=")
13391338
lhs
13401339
[(dotted ? K"dotcall" : K"call")
13411340
op
@@ -4172,7 +4171,7 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
41724171
throw(LoweringError(ex, "unimplemented or unsupported atomic declaration"))
41734172
elseif k == K"call"
41744173
expand_call(ctx, ex)
4175-
elseif k == K"dotcall" || ((k == K"&&" || k == K"||") && is_dotted(ex))
4174+
elseif k == K"dotcall" || k == K".&&" || k == K".||" || k == K".="
41764175
expand_forms_2(ctx, expand_fuse_broadcast(ctx, ex))
41774176
elseif k == K"."
41784177
expand_forms_2(ctx, expand_dot(ctx, ex))
@@ -4208,14 +4207,10 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
42084207
adopt_scope(string(k)::K"Identifier", ex)
42094208
children(ex)...
42104209
])
4211-
elseif k == K"op="
4210+
elseif k == K"op=" || k == K".op="
42124211
expand_forms_2(ctx, expand_update_operator(ctx, ex))
42134212
elseif k == K"="
4214-
if is_dotted(ex)
4215-
expand_forms_2(ctx, expand_fuse_broadcast(ctx, ex))
4216-
else
4217-
expand_assignment(ctx, ex)
4218-
end
4213+
expand_assignment(ctx, ex)
42194214
elseif k == K"break"
42204215
numchildren(ex) > 0 ? ex :
42214216
@ast ctx ex [K"break" "loop_exit"::K"symbolic_label"]

src/syntax_graph.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,20 @@ function Base.getproperty(graph::SyntaxGraph, name::Symbol)
137137
end
138138

139139
function sethead!(graph, id::NodeId, h::JuliaSyntax.SyntaxHead)
140-
graph.kind[id] = kind(h)
141-
f = flags(h)
142-
if f != 0
143-
graph.syntax_flags[id] = f
144-
end
140+
sethead!(graph, id, kind(h))
141+
setflags!(graph, id, flags(h))
145142
end
146143

147144
function sethead!(graph, id::NodeId, k::Kind)
148145
graph.kind[id] = k
149146
end
150147

148+
function setflags!(graph, id::NodeId, f::UInt16)
149+
if f != 0
150+
graph.syntax_flags[id] = f
151+
end
152+
end
153+
151154
function _convert_nodes(graph::SyntaxGraph, node::SyntaxNode)
152155
id = newnode!(graph)
153156
sethead!(graph, id, head(node))
@@ -307,6 +310,7 @@ JuliaSyntax.source_line(src::LineNumberNode) = src.line
307310
# The follow somewhat strange cases are for where LineNumberNode is standing in
308311
# for SourceFile because we've only got Expr-based provenance info
309312
JuliaSyntax.sourcefile(src::LineNumberNode) = src
313+
JuliaSyntax.sourcetext(src::LineNumberNode) = SubString("")
310314
JuliaSyntax.source_location(src::LineNumberNode, byte_index::Integer) = (src.line, 0)
311315
JuliaSyntax.source_location(::Type{LineNumberNode}, src::LineNumberNode, byte_index::Integer) = src
312316
JuliaSyntax.filename(src::LineNumberNode) = string(src.file)
@@ -536,13 +540,11 @@ end
536540
JuliaSyntax.sourcefile(ex::SyntaxTree) = sourcefile(sourceref(ex))
537541
JuliaSyntax.byte_range(ex::SyntaxTree) = byte_range(sourceref(ex))
538542

539-
function JuliaSyntax._expr_leaf_val(ex::SyntaxTree)
543+
function JuliaSyntax._expr_leaf_val(ex::SyntaxTree, _...)
540544
name = get(ex, :name_val, nothing)
541-
if !isnothing(name)
542-
Symbol(name)
543-
else
544-
ex.value
545-
end
545+
!isnothing(name) && return Symbol(name)
546+
name = get(ex, :value, nothing)
547+
return name
546548
end
547549

548550
Base.Expr(ex::SyntaxTree) = JuliaSyntax.to_expr(ex)
@@ -603,7 +605,7 @@ macro SyntaxTree(ex_old)
603605
throw(ArgumentError("@SyntaxTree expects a `quote` block or `:`-quoted expression"))
604606
end
605607
# 2. Re-parse the current source file as SyntaxTree instead
606-
fname = String(__source__.file)
608+
fname = isnothing(__source__.file) ? error("No current file") : String(__source__.file)
607609
if occursin(r"REPL\[\d+\]", fname)
608610
# Assume we should look at last history entry in REPL
609611
try

0 commit comments

Comments
 (0)