Skip to content

Commit

Permalink
fix worked around issue in call where targets don't have the correct …
Browse files Browse the repository at this point in the history
…parent
  • Loading branch information
baroquebobcat committed Aug 3, 2016
1 parent 3036f21 commit 5cf516f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
22 changes: 17 additions & 5 deletions mirah-parser/src/mirah/lang/ast/call.mirah
Expand Up @@ -28,8 +28,12 @@ class FunctionalCall < NodeImpl
child block: Block
end

def target:Node
@target ||= ImplicitSelf.new(position)
def target: Node
@target ||= begin
s = ImplicitSelf.new(position)
s.setParent self
s
end
end

def typeref: TypeRef
Expand All @@ -53,11 +57,19 @@ class VCall < NodeImpl
TypeRefImpl.new(name.identifier, false, false, name.position)
end

def target:Node
@target ||= ImplicitSelf.new(position)
def target: Node
@target ||= begin
s = ImplicitSelf.new(position)
s.setParent self
s
end
end
def parameters
@parameters ||= NodeList.new(position)
@parameters ||= begin
p = NodeList.new(position)
p.setParent self
p
end
end

def block: Block
Expand Down
26 changes: 26 additions & 0 deletions mirah-parser/test/test_ast.rb
@@ -0,0 +1,26 @@
require 'test/unit'
require 'java'

$CLASSPATH << 'build/mirah-parser.jar'

class TestAst < Test::Unit::TestCase
java_import 'mirahparser.lang.ast.VCall'
java_import 'mirahparser.lang.ast.FunctionalCall'
java_import 'mirahparser.lang.ast.PositionImpl'
java_import 'mirahparser.lang.ast.StringCodeSource'
java_import 'mirahparser.lang.ast.SimpleString'

def test_vcall_target_has_parent
call = VCall.new some_position
assert_equal call, call.target.parent
end

def test_functional_call_target_has_parent
call = FunctionalCall.new some_position
assert_equal call, call.target.parent
end

def some_position
PositionImpl.new(StringCodeSource.new('blah', 'codegoeshere'), 0, 0, 0, 1, 0, 1)
end
end
3 changes: 0 additions & 3 deletions src/org/mirah/typer/better_closures.mirah
Expand Up @@ -230,9 +230,6 @@ class BetterClosureBuilder
block.position, target,
SimpleString.new("new"),
binding_locals, nil)
@typer.workaroundASTBug new_node



if block.parent.kind_of?(CallSite)
parent = CallSite(block.parent)
Expand Down
6 changes: 0 additions & 6 deletions src/org/mirah/typer/closures/binding_adjuster.mirah
Expand Up @@ -114,7 +114,6 @@ class BindingAdjuster < NodeScanner
binding_klass.body.insert(0, attr_def)

binding_new_call = Call.new(node.position, Constant.new(SimpleString.new(name)), SimpleString.new("new"), [], nil)
@builder.typer.workaroundASTBug binding_new_call

assign_binding_dot_new = LocalAssignment.new(
node.position,
Expand Down Expand Up @@ -173,7 +172,6 @@ class BindingAdjuster < NodeScanner
SimpleString.new("#{arg}_set"),
[LocalAccess.new(node.position, SimpleString.new(arg))],
nil)
@builder.typer.workaroundASTBug addition
# insert after binding class & binding instantiation
# if we were less lazy, we'd find the binding construction, and insert after
NodeList(node).insert 2, addition
Expand Down Expand Up @@ -247,8 +245,6 @@ class BindingAdjuster < NodeScanner
[new_value],
nil)

@builder.typer.workaroundASTBug replacement

replaceSelf(local, replacement)
local.value.setParent replacement

Expand All @@ -272,8 +268,6 @@ class BindingAdjuster < NodeScanner
[],
nil)

@builder.typer.workaroundASTBug replacement

replaceSelf(local, replacement)

@builder.typer.learnType replacement.target, @binding_type
Expand Down
10 changes: 1 addition & 9 deletions src/org/mirah/typer/typer.mirah
Expand Up @@ -171,7 +171,6 @@ class Typer < SimpleNodeVisitor

def visitVCall(call, expression)
@@log.fine "visitVCall #{call}"
workaroundASTBug call

# This might be a local, method call, or primitive access,
# so try them all.
Expand All @@ -193,7 +192,6 @@ class Typer < SimpleNodeVisitor
end

def visitFunctionalCall(call, expression)
workaroundASTBug call
parameters = inferParameterTypes call
@futures[call] = callMethodType(call, parameters)

Expand Down Expand Up @@ -548,7 +546,7 @@ class Typer < SimpleNodeVisitor
Identifier(constant.name.clone),
nil, nil)
fcall.setParent(constant.parent)
workaroundASTBug fcall

methodType = callMethodType fcall, Collections.emptyList
targetType = infer(fcall.target)
@futures[fcall] = methodType
Expand Down Expand Up @@ -1555,12 +1553,6 @@ class Typer < SimpleNodeVisitor
end
end

# FIXME: there's a bug in the AST that doesn't set the
# calls target correctly
def workaroundASTBug(call: CallSite)
call.target.setParent(call)
end

def sourceContent node: Node
return "<source non-existent>" unless node
sourceContent node.position
Expand Down

0 comments on commit 5cf516f

Please sign in to comment.