Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now injecting the instrumentation into macro, but still in a simple way
- Loading branch information
Yacine Petitprez
committed
May 2, 2018
1 parent
1a36be4
commit af5246d
Showing
5 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/bin/sh | ||
crystal src/coverage/cli.cr -- spec/main.cr --use-require="./src/coverage/runtime" -p | ||
crystal src/coverage/cli.cr -- spec/template.cr --use-require="./src/coverage/runtime" -p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def code | ||
{% unless true %} | ||
{% if false %} | ||
puts "This will not be called" | ||
{% else %} | ||
puts "This will be called" | ||
{% end %} | ||
{% end %} | ||
end | ||
|
||
def for_loop | ||
{% for x in ["a", "b", "c"] %} | ||
puts {{x}} | ||
{% end %} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Crystal::Location | ||
def clone(filename = nil, line_number = nil, column_number = nil) | ||
Crystal::Location.new(filename || @filename, line_number || @line_number, column_number || @column_number) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module MacroUtils | ||
def propagate_location_in_macro(node : Crystal::ASTNode, location : Nil) | ||
return nil | ||
end | ||
|
||
def propagate_location_in_macro(node : Crystal::Nop, location : Crystal::Location) | ||
return location | ||
end | ||
|
||
def propagate_location_in_macro(node : Crystal::MacroIf, location : Crystal::Location) | ||
location = location.clone | ||
|
||
node.then.location = location | ||
location = propagate_location_in_macro(node.then, location) | ||
|
||
node.else.location = location | ||
location = propagate_location_in_macro(node.else, location) | ||
return location | ||
end | ||
|
||
def propagate_location_in_macro(node : Crystal::MacroFor, location : Crystal::Location) | ||
location = location.clone | ||
|
||
node.body.location = location | ||
location = propagate_location_in_macro(node.body, location) | ||
|
||
return location | ||
end | ||
|
||
def propagate_location_in_macro(node : Crystal::MacroLiteral, location : Crystal::Location) | ||
node.location = location | ||
|
||
new_loc = location.clone line_number: location.line_number + node.to_s.count('\n') | ||
|
||
return new_loc | ||
end | ||
|
||
def propagate_location_in_macro(node : Crystal::Expressions, location) | ||
new_loc = location.clone | ||
|
||
node.expressions.each do |e| | ||
e.location = new_loc | ||
new_loc = propagate_location_in_macro(e, new_loc) | ||
end | ||
|
||
return new_loc | ||
end | ||
|
||
def propagate_location_in_macro(node : Crystal::ASTNode, location : Crystal::Location) | ||
return location | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters