Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/typeprof/core/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def self.create_node(raw_node, lenv, use_result = true, allow_meta = false)
when :splat_node then SplatNode.new(raw_node, lenv)
when :for_node then ForNode.new(raw_node, lenv)
when :alias_global_variable_node then AliasGlobalVariableNode.new(raw_node, lenv)
when :pre_execution_node then PreExecutionNode.new(raw_node, lenv)
when :post_execution_node then PostExecutionNode.new(raw_node, lenv)
when :flip_flop_node then FlipFlopNode.new(raw_node, lenv)
when :shareable_constant_node then create_node(raw_node.write, lenv)
Expand Down
7 changes: 6 additions & 1 deletion lib/typeprof/core/ast/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ def install0(genv)

post_stmts = []

# BEGIN runs before the surrounding statements, END after them
@stmts.each do |stmt|
next if stmt.nil?
stmt.install(genv) if stmt.is_a?(PreExecutionNode)
end

@stmts.each do |stmt|
next if stmt.is_a?(PreExecutionNode)

if stmt.is_a?(PostExecutionNode)
post_stmts << stmt
Expand Down
8 changes: 7 additions & 1 deletion lib/typeprof/core/ast/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def install0(genv)
end
end

class PostExecutionNode < Node
class ExecutionBaseNode < Node
def initialize(raw_node, lenv)
super(raw_node, lenv)
@body = raw_node.statements ? AST.create_node(raw_node.statements, lenv) : DummyNilNode.new(TypeProf::CodeRange.new(code_range.last, code_range.last), lenv)
Expand All @@ -273,6 +273,12 @@ def install0(genv)
end
end

class PreExecutionNode < ExecutionBaseNode
end

class PostExecutionNode < ExecutionBaseNode
end

class ClassVariableWriteNode < Node
def initialize(raw_node, rhs, lenv)
super(raw_node, lenv)
Expand Down
24 changes: 24 additions & 0 deletions scenario/misc/pre-exec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## update
def check(x)
end

def check2(x)
end

y = "str"

BEGIN {
def hello = "hello"
x = 1
y = 1
}

check(x)
check2(y)

## assert
class Object
def check: (Integer) -> nil
def check2: (String) -> nil
def hello: -> String
end
Loading