Skip to content

Commit 84288b7

Browse files
asteriteRX14
authored andcommittedJan 17, 2018
Compiler: add more locations (#5597)
1 parent bba4985 commit 84288b7

File tree

17 files changed

+112
-69
lines changed

17 files changed

+112
-69
lines changed
 

Diff for: ‎spec/compiler/codegen/debug_spec.cr

+22
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,26 @@ describe "Code gen: debug" do
128128
A
129129
), debug: Crystal::Debug::All)
130130
end
131+
132+
it "has debug info in closure inside if (#5593)" do
133+
codegen(%(
134+
require "prelude"
135+
136+
def foo
137+
if true && true
138+
yield 1
139+
end
140+
end
141+
142+
def bar(&block)
143+
block
144+
end
145+
146+
foo do |i|
147+
bar do
148+
i
149+
end
150+
end
151+
), debug: Crystal::Debug::All)
152+
end
131153
end

Diff for: ‎src/compiler/crystal/codegen/asm.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Crystal::CodeGenVisitor
1919
constraints << "," unless constraints.empty?
2020

2121
inputs.each_with_index do |input, i|
22-
input.exp.accept self
22+
accept input.exp
2323
input_types << llvm_type(input.exp.type)
2424
input_values << @last
2525
constraints << "," if i > 0
@@ -45,7 +45,7 @@ class Crystal::CodeGenVisitor
4545
asm_value = call value, input_values
4646

4747
if ptrof
48-
ptrof.accept self
48+
accept ptrof
4949
store asm_value, @last
5050
end
5151

Diff for: ‎src/compiler/crystal/codegen/call.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class Crystal::CodeGenVisitor
293293
end
294294

295295
def codegen_call_with_block_as_fun_literal(node, fun_literal, self_type, call_args)
296-
fun_literal.accept self
296+
accept fun_literal
297297
call_args.push @last
298298

299299
target_def = node.target_def

Diff for: ‎src/compiler/crystal/codegen/codegen.cr

+24-16
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module Crystal
6262

6363
def codegen(node, single_module = false, debug = Debug::Default)
6464
visitor = CodeGenVisitor.new self, node, single_module: single_module, debug: debug
65-
node.accept visitor
65+
visitor.accept node
6666
visitor.process_finished_hooks
6767
visitor.finish
6868

@@ -381,7 +381,7 @@ module Crystal
381381

382382
emit_vars_debug_info(vars) if @debug.variables?
383383
end
384-
node.node.accept self
384+
accept node.node
385385
@last = llvm_nil
386386
end
387387

@@ -450,7 +450,7 @@ module Crystal
450450
type = node.type.as(TupleInstanceType)
451451
@last = allocate_tuple(type) do |tuple_type, i|
452452
exp = node.elements[i]
453-
exp.accept self
453+
accept exp
454454
{exp.type, @last}
455455
end
456456
end
@@ -462,7 +462,7 @@ module Crystal
462462
type = node.type.as(NamedTupleInstanceType)
463463
struct_type = alloca llvm_type(type)
464464
node.entries.each do |entry|
465-
entry.value.accept self
465+
accept entry.value
466466
index = type.name_index(entry.key).not_nil!
467467
assign aggregate_index(struct_type, index), type.entries[index].type, entry.value.type, @last
468468
end
@@ -490,7 +490,7 @@ module Crystal
490490
const = node_exp.target_const.not_nil!
491491
read_const_pointer(const)
492492
when ReadInstanceVar
493-
node_exp.obj.accept self
493+
accept node_exp.obj
494494
instance_var_ptr (node_exp.obj.type), node_exp.name, @last
495495
when Call
496496
# lib external var
@@ -637,7 +637,9 @@ module Crystal
637637
end
638638

639639
def visit(node : ClassDef)
640-
node.hook_expansions.try &.each &.accept self
640+
node.hook_expansions.try &.each do |hook|
641+
accept hook
642+
end
641643
accept node.body
642644
@last = llvm_nil
643645
false
@@ -651,7 +653,7 @@ module Crystal
651653

652654
def visit(node : LibDef)
653655
@in_lib = true
654-
node.body.accept self
656+
accept node.body
655657
@in_lib = false
656658
@last = llvm_nil
657659
false
@@ -665,7 +667,7 @@ module Crystal
665667
def visit(node : EnumDef)
666668
node.members.each do |member|
667669
if member.is_a?(Assign)
668-
member.accept self
670+
accept member
669671
end
670672
end
671673

@@ -704,32 +706,36 @@ module Crystal
704706
end
705707

706708
def visit(node : Include)
707-
node.hook_expansions.try &.each &.accept self
709+
node.hook_expansions.try &.each do |hook|
710+
accept hook
711+
end
708712

709713
@last = llvm_nil
710714
false
711715
end
712716

713717
def visit(node : Extend)
714-
node.hook_expansions.try &.each &.accept self
718+
node.hook_expansions.try &.each do |hook|
719+
accept hook
720+
end
715721

716722
@last = llvm_nil
717723
false
718724
end
719725

720726
def visit(node : If)
721727
if node.truthy?
722-
node.cond.accept self
723-
node.then.accept self
728+
accept node.cond
729+
accept node.then
724730
if @needs_value && (node_type = node.type?) && (then_type = node.then.type?)
725731
@last = upcast(@last, node_type, then_type)
726732
end
727733
return false
728734
end
729735

730736
if node.falsey?
731-
node.cond.accept self
732-
node.else.accept self
737+
accept node.cond
738+
accept node.else
733739
if @needs_value && (node_type = node.type?) && (else_type = node.else.type?)
734740
@last = upcast(@last, node_type, else_type)
735741
end
@@ -1306,7 +1312,9 @@ module Crystal
13061312
end
13071313

13081314
def visit(node : Def)
1309-
node.hook_expansions.try &.each &.accept self
1315+
node.hook_expansions.try &.each do |hook|
1316+
accept hook
1317+
end
13101318

13111319
@last = llvm_nil
13121320
false
@@ -1826,7 +1834,7 @@ module Crystal
18261834
context.vars["self"] = LLVMVar.new(type_ptr, real_type)
18271835
alloca_vars init.meta_vars
18281836

1829-
init.value.accept self
1837+
accept init.value
18301838

18311839
ivar_ptr = instance_var_ptr real_type, init.name, type_ptr
18321840
assign ivar_ptr, ivar.type, init.value.type, @last

Diff for: ‎src/compiler/crystal/codegen/exception.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class Crystal::CodeGenVisitor
205205
next unless target_ensure
206206

207207
with_context(exception_handler.context) do
208-
target_ensure.accept self
208+
accept target_ensure
209209
end
210210
end
211211
end

Diff for: ‎src/compiler/crystal/codegen/primitives.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class Crystal::CodeGenVisitor
504504
if (extra = node.extra)
505505
existing_value = context.vars["value"]?
506506
context.vars["value"] = LLVMVar.new(call_arg, node.type, true)
507-
request_value { extra.accept self }
507+
request_value { accept extra }
508508
call_arg = @last
509509
context.vars["value"] = existing_value if existing_value
510510
end

Diff for: ‎src/compiler/crystal/macros/interpreter.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module Crystal
149149
@last.to_s(str)
150150
end
151151
end
152-
end)
152+
end).at(node)
153153
false
154154
end
155155

Diff for: ‎src/compiler/crystal/semantic/ast.cr

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ module Crystal
195195
a_def.always_inline = always_inline?
196196
a_def.returns_twice = returns_twice?
197197
a_def.naked = naked?
198+
a_def.new = new?
198199
a_def
199200
end
200201

Diff for: ‎src/compiler/crystal/semantic/call.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ class Crystal::Call
799799
wrong_number_of "block arguments", block.args.size, fun_args.size
800800
end
801801

802-
a_def = Def.new("->", fun_args, block.body)
802+
a_def = Def.new("->", fun_args, block.body).at(block)
803803
a_def.captured_block = true
804804

805805
fun_literal = ProcLiteral.new(a_def).at(self)

Diff for: ‎src/compiler/crystal/semantic/default_arguments.cr

+10-10
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ class Crystal::Def
8787
new_name = name
8888
end
8989

90-
expansion = Def.new(new_name, new_args, nil, receiver.clone, block_arg.clone, return_type.clone, macro_def?, yields)
90+
expansion = Def.new(new_name, new_args, nil, receiver.clone, block_arg.clone, return_type.clone, macro_def?, yields).at(self)
9191
expansion.args.each { |arg| arg.default_value = nil }
9292
expansion.calls_super = calls_super?
9393
expansion.calls_initialize = calls_initialize?
9494
expansion.calls_previous_def = calls_previous_def?
9595
expansion.uses_block_arg = uses_block_arg?
9696
expansion.yields = yields
97-
expansion.location = location
9897
expansion.raises = raises?
9998
expansion.free_vars = free_vars
10099
if owner = self.owner?
@@ -122,10 +121,10 @@ class Crystal::Def
122121
if default_value.is_a?(MagicConstant)
123122
expansion.args.push arg.clone
124123
else
125-
new_body << Assign.new(Var.new(arg.name), default_value)
124+
new_body << Assign.new(Var.new(arg.name).at(arg), default_value).at(arg)
126125

127126
if restriction = arg.restriction
128-
new_body << TypeRestriction.new(Var.new(arg.name), restriction).at(arg)
127+
new_body << TypeRestriction.new(Var.new(arg.name).at(arg), restriction).at(arg)
129128
end
130129
end
131130
end
@@ -135,10 +134,11 @@ class Crystal::Def
135134
if splat_names && splat_index
136135
tuple_args = [] of ASTNode
137136
splat_size.times do |i|
138-
tuple_args << Var.new(splat_names[i])
137+
tuple_args << Var.new(splat_names[i]).at(self)
139138
end
140-
tuple = TupleLiteral.new(tuple_args).at(args[splat_index])
141-
new_body << Assign.new(Var.new(args[splat_index].name), tuple)
139+
splat_arg = args[splat_index]
140+
tuple = TupleLiteral.new(tuple_args).at(splat_arg)
141+
new_body << Assign.new(Var.new(splat_arg.name).at(splat_arg), tuple).at(splat_arg)
142142
end
143143

144144
# Double splat argument
@@ -151,7 +151,7 @@ class Crystal::Def
151151
named_tuple_entries << NamedTupleLiteral::Entry.new(named_arg, Var.new(named_arg))
152152
end
153153
named_tuple = NamedTupleLiteral.new(named_tuple_entries).at(double_splat)
154-
new_body << Assign.new(Var.new(double_splat.name), named_tuple)
154+
new_body << Assign.new(Var.new(double_splat.name).at(double_splat), named_tuple).at(double_splat)
155155
end
156156

157157
new_body.push body
@@ -182,8 +182,8 @@ class Crystal::Def
182182
new_args.push Var.new(arg.name)
183183
expansion.args.push arg.clone
184184
else
185-
body << Assign.new(Var.new(arg.name), default_value.clone)
186-
new_args.push Var.new(arg.name)
185+
body << Assign.new(Var.new(arg.name).at(arg), default_value.clone).at(arg)
186+
new_args.push Var.new(arg.name).at(arg)
187187
end
188188
end
189189
end

0 commit comments

Comments
 (0)
Please sign in to comment.