Chromium Code Reviews| Index: dart/frog/analyze.dart |
| =================================================================== |
| --- dart/frog/analyze.dart (revision 3892) |
| +++ dart/frog/analyze.dart (working copy) |
| @@ -25,6 +25,7 @@ |
| * enclosing type to advise future code generation and analysis. |
| */ |
| bool hasTypeParams = false; |
| + bool visitingInitializers = false; |
| MethodAnalyzer(this.method, this.body); |
| @@ -46,7 +47,20 @@ |
| _frame = new CallFrame(this, method, thisValue, args, context); |
| _bindArguments(_frame.args); |
| - body.visit(this); |
| + |
| + final declaredInitializers = method.definition.dynamic.initializers; |
|
kasperl
2012/02/03 15:39:20
Add a comment here that explains how this is dealt
ngeoffray
2012/02/06 11:50:31
Done.
|
| + var initializerCall = null; |
| + if (declaredInitializers != null) { |
| + visitingInitializers = true; |
| + for (var init in declaredInitializers) { |
| + if (init is CallExpression) { |
|
kasperl
2012/02/03 15:39:20
How bad would it be to add an optional parameter t
ngeoffray
2012/02/06 11:50:31
Done.
|
| + init.visit(this);; |
|
kasperl
2012/02/03 15:39:20
;; -> ;
ngeoffray
2012/02/06 11:50:31
Done.
|
| + } |
| + } |
| + visitingInitializers = false; |
| + } |
| + |
| + if (body != null) body.visit(this); |
| } |
| /* Checks whether or not a particular TypeReference Node includes references |
| @@ -394,6 +408,27 @@ |
| return _frame._makeValue(world.functionType, node); |
| } |
| + analyzeThisOrSuperConstructorCall(CallExpression node, |
|
kasperl
2012/02/03 15:39:20
analyzeInitializerConstructorCall instead? In this
ngeoffray
2012/02/06 11:50:31
Done.
|
| + Expression receiver, |
| + String name) { |
| + var type = _frame.method.declaringType; |
| + if (receiver is SuperExpression) { |
| + type = type.parent; |
| + } |
| + var member = type.getConstructor(name); |
| + if (member !== null) { |
| + return member.invoke(_frame, node, _frame.makeThisValue(node), |
| + _visitArgs(node.arguments)); |
| + } else { |
| + world.warning('cannot find "$name"', node.span); |
|
kasperl
2012/02/03 15:39:20
How does this look if name is the empty string? Ma
ngeoffray
2012/02/06 11:50:31
Done.
|
| + return _frame._makeValue(world.varType, node); |
| + } |
| + } |
| + |
| + bool isThisOrSuper(Expression node) { |
| + return node is ThisExpression || node is SuperExpression; |
| + } |
| + |
| Value visitCallExpression(CallExpression node) { |
| var target; |
| var position = node.target; |
| @@ -402,7 +437,13 @@ |
| DotExpression dot = node.target; |
| target = dot.self.visit(this); |
| name = dot.name.name; |
| - position = dot.name; |
| + if (isThisOrSuper(dot.self) && visitingInitializers) { |
| + return analyzeThisOrSuperConstructorCall(node, dot.self, name); |
| + } else { |
| + position = dot.name; |
| + } |
| + } else if (isThisOrSuper(node.target) && visitingInitializers) { |
| + return analyzeThisOrSuperConstructorCall(node, node.target, ''); |
| } else if (node.target is VarExpression) { |
| VarExpression varExpr = node.target; |
| name = varExpr.name.name; |