Skip to content

Commit

Permalink
WIP: Tests for functionloc. Remove shortform-function-loc from parser
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f committed Mar 17, 2020
1 parent 6971dd8 commit cfcfc5d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
25 changes: 7 additions & 18 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -733,31 +733,20 @@
`(block ,linenode ,@(cdr blk))
`(block ,linenode ,blk)))

(define (short-form-function-loc ex lno)
(if (eventually-call? (cadr ex))
`(= ,(cadr ex) ,(add-line-number (caddr ex) `(line ,lno ,current-filename)))
ex))

(define (parse-assignment s down)
(let* ((ex (down s))
(t (peek-token s)))
(if (not (is-prec-assignment? t))
ex
(begin
(take-token s)
(cond ((or (eq? t '~) (eq? t '|.~|)) ;; ~ is the only non-syntactic assignment-precedence operators
(if (and space-sensitive (ts:space? s)
(not (space-before-next-token? s)))
(begin (ts:put-back! s t (ts:space? s))
ex)
(list 'call t ex (parse-assignment s down))))
((eq? t '=)
;; insert line/file for short-form function defs, otherwise leave alone
(let ((lno (input-port-line (ts:port s))))
(short-form-function-loc
(list t ex (parse-assignment s down)) lno)))
(else
(list t ex (parse-assignment s down))))))))
(if (or (eq? t '~) (eq? t '|.~|)) ;; ~ is the only non-syntactic assignment-precedence operators
(if (and space-sensitive (ts:space? s)
(not (space-before-next-token? s)))
(begin (ts:put-back! s t (ts:space? s))
ex)
(list 'call t ex (parse-assignment s down))))
(list t ex (parse-assignment s down))))))

; parse-comma is needed for commas outside parens, for example a = b,c
(define (parse-comma s)
Expand Down
38 changes: 21 additions & 17 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ function get_bt_frames(functionname, bt)
end

# same-file inline
eval(Expr(:function, Expr(:call, :test_inline_1),
Expr(:block, Expr(:line, 99, Symbol("backtrace.jl")),
Expr(:block, Expr(:line, 42),
Expr(:meta, :push_loc, Symbol("backtrace.jl"), :inlfunc),
Expr(:line, 37),
Expr(:call, :throw, "foo"),
Expr(:meta, :pop_loc),
Expr(:line, 99)))))
eval(Expr(:block,
Expr(:line, 101, Symbol("backtrace.jl")),
Expr(:function, Expr(:call, :test_inline_1),
Expr(:block, Expr(:line, 99, Symbol("backtrace.jl")),
Expr(:block, Expr(:line, 42),
Expr(:meta, :push_loc, Symbol("backtrace.jl"), :inlfunc),
Expr(:line, 37),
Expr(:call, :throw, "foo"),
Expr(:meta, :pop_loc),
Expr(:line, 99))))))

@test functionloc(test_inline_1) == ("backtrace.jl", 99)
@test functionloc(test_inline_1) == ("backtrace.jl", 101)
try
test_inline_1()
error("unexpected")
Expand All @@ -42,15 +44,17 @@ end

# different-file inline
const absfilepath = Sys.iswindows() ? "C:\\foo\\bar\\baz.jl" : "/foo/bar/baz.jl"
eval(Expr(:function, Expr(:call, :test_inline_2),
Expr(:block, Expr(:line, 81, Symbol("backtrace.jl")),
Expr(:block, Expr(:meta, :push_loc, Symbol(absfilepath)),
Expr(:line, 111),
Expr(:call, :throw, "foo"),
Expr(:meta, :pop_loc),
Expr(:line, 99)))))
eval(Expr(:block,
Expr(:line, 101, Symbol("backtrace.jl")),
Expr(:function, Expr(:call, :test_inline_2),
Expr(:block, Expr(:line, 81, Symbol("backtrace.jl")),
Expr(:block, Expr(:meta, :push_loc, Symbol(absfilepath)),
Expr(:line, 111),
Expr(:call, :throw, "foo"),
Expr(:meta, :pop_loc),
Expr(:line, 99))))))

@test functionloc(test_inline_2) == ("backtrace.jl", 81)
@test functionloc(test_inline_2) == ("backtrace.jl", 101)
try
test_inline_2()
error("unexpected")
Expand Down
5 changes: 3 additions & 2 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ let rts = return_types(TLayout)
end

# issue #15447
f15447_line = @__LINE__() + 1
@noinline function f15447(s, a)
if s
return a
Expand All @@ -296,15 +297,15 @@ end
return nb
end
end
@test functionloc(f15447)[2] > 0
@test functionloc(f15447)[2] == f15447_line

# issue #14346
@noinline function f14346(id, mask, limit)
if id <= limit && mask[id]
return true
end
end
@test functionloc(f14346)[2] == @__LINE__() - 4
@test functionloc(f14346)[2] == @__LINE__() - 5

# issue #15714
# show variable names for slots and suppress spurious type warnings
Expand Down

0 comments on commit cfcfc5d

Please sign in to comment.