Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 import 'package:kernel/frontend/accessors.dart' | 6 import 'package:kernel/frontend/accessors.dart' |
| 7 show | 7 show |
| 8 Accessor, | 8 Accessor, |
| 9 IndexAccessor, | 9 IndexAccessor, |
| 10 NullAwarePropertyAccessor, | 10 NullAwarePropertyAccessor, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 return node; | 207 return node; |
| 208 } | 208 } |
| 209 | 209 |
| 210 ir.Node associateNode(ir.Node node, Node ast) { | 210 ir.Node associateNode(ir.Node node, Node ast) { |
| 211 kernel.nodeToAst[node] = ast; | 211 kernel.nodeToAst[node] = ast; |
| 212 return node; | 212 return node; |
| 213 } | 213 } |
| 214 | 214 |
| 215 bool isVoidContext = false; | 215 bool isVoidContext = false; |
| 216 | 216 |
| 217 /// If non-null, reference to a deferred library that a subsequent getter is | |
| 218 /// using. | |
| 219 ir.DeferredImport _deferredLibrary; | |
| 220 | |
| 217 KernelVisitor(this.currentElement, this.elements, this.kernel); | 221 KernelVisitor(this.currentElement, this.elements, this.kernel); |
| 218 | 222 |
| 219 KernelVisitor get sendVisitor => this; | 223 KernelVisitor get sendVisitor => this; |
| 220 | 224 |
| 221 KernelVisitor get declVisitor => this; | 225 KernelVisitor get declVisitor => this; |
| 222 | 226 |
| 223 ir.TreeNode visitForValue(Expression node) { | 227 ir.TreeNode visitForValue(Expression node) { |
| 224 bool wasVoidContext = isVoidContext; | 228 bool wasVoidContext = isVoidContext; |
| 225 isVoidContext = false; | 229 isVoidContext = false; |
| 226 try { | 230 try { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 | 360 |
| 357 @override | 361 @override |
| 358 ir.Expression handleError(Node node) => new ir.InvalidExpression(); | 362 ir.Expression handleError(Node node) => new ir.InvalidExpression(); |
| 359 | 363 |
| 360 @override | 364 @override |
| 361 void apply(Node node, _) { | 365 void apply(Node node, _) { |
| 362 throw new UnsupportedError("apply"); | 366 throw new UnsupportedError("apply"); |
| 363 } | 367 } |
| 364 | 368 |
| 365 @override | 369 @override |
| 366 void previsitDeferredAccess(Send node, PrefixElement prefix, _) {} | 370 void previsitDeferredAccess(Send node, PrefixElement prefix, _) { |
| 371 // This is visited before any element access, and if it is deferred, | |
| 372 // prefix.isDeferred = true. | |
| 373 if (prefix != null && prefix.isDeferred) { | |
| 374 _deferredLibrary = new ir.DeferredImport( | |
| 375 kernel.libraries[prefix.deferredImport.importedLibrary], prefix.name); | |
| 376 } else { | |
| 377 _deferredLibrary = null; | |
| 378 } | |
| 379 } | |
| 367 | 380 |
| 368 @override | 381 @override |
| 369 internalError(Spannable spannable, String message) { | 382 internalError(Spannable spannable, String message) { |
| 370 kernel.internalError(spannable, message); | 383 kernel.internalError(spannable, message); |
| 371 } | 384 } |
| 372 | 385 |
| 373 @override | 386 @override |
| 374 applyParameters(NodeList parameters, _) { | 387 applyParameters(NodeList parameters, _) { |
| 375 throw new UnsupportedError("applyParameters"); | 388 throw new UnsupportedError("applyParameters"); |
| 376 } | 389 } |
| (...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1987 } | 2000 } |
| 1988 | 2001 |
| 1989 @override | 2002 @override |
| 1990 visitStaticFieldDeclaration(VariableDefinitions node, Node definition, | 2003 visitStaticFieldDeclaration(VariableDefinitions node, Node definition, |
| 1991 FieldElement field, Node initializer, _) { | 2004 FieldElement field, Node initializer, _) { |
| 1992 // Shouldn't be called, handled by fieldToIr. | 2005 // Shouldn't be called, handled by fieldToIr. |
| 1993 return internalError(node, "StaticFieldDeclaration"); | 2006 return internalError(node, "StaticFieldDeclaration"); |
| 1994 } | 2007 } |
| 1995 | 2008 |
| 1996 ir.Expression buildStaticGet(Element element) { | 2009 ir.Expression buildStaticGet(Element element) { |
| 1997 return buildStaticAccessor(element).buildSimpleRead(); | 2010 var expression = buildStaticAccessor(element).buildSimpleRead(); |
| 2011 if (_deferredLibrary != null) { | |
| 2012 ir.Let let = new ir.Let( | |
| 2013 makeOrReuseVariable(new ir.CheckLibraryIsLoaded(_deferredLibrary)), | |
| 2014 expression); | |
| 2015 return let; | |
| 2016 } | |
| 2017 return expression; | |
| 1998 } | 2018 } |
| 1999 | 2019 |
| 2000 @override | 2020 @override |
| 2001 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) { | 2021 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) { |
| 2002 return associateNode(buildStaticGet(field), node); | 2022 return associateNode(buildStaticGet(field), node); |
| 2003 } | 2023 } |
| 2004 | 2024 |
| 2005 @override | 2025 @override |
| 2006 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field, | 2026 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field, |
| 2007 NodeList arguments, CallStructure callStructure, _) { | 2027 NodeList arguments, CallStructure callStructure, _) { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2225 | 2245 |
| 2226 @override | 2246 @override |
| 2227 IrFunction visitStaticGetterDeclaration( | 2247 IrFunction visitStaticGetterDeclaration( |
| 2228 FunctionExpression node, MethodElement getter, Node body, _) { | 2248 FunctionExpression node, MethodElement getter, Node body, _) { |
| 2229 return buildIrFunction(ir.ProcedureKind.Getter, getter, body); | 2249 return buildIrFunction(ir.ProcedureKind.Getter, getter, body); |
| 2230 } | 2250 } |
| 2231 | 2251 |
| 2232 @override | 2252 @override |
| 2233 ir.Expression handleStaticGetterGet(Send node, FunctionElement getter, _) { | 2253 ir.Expression handleStaticGetterGet(Send node, FunctionElement getter, _) { |
| 2234 if (getter.isDeferredLoaderGetter) { | 2254 if (getter.isDeferredLoaderGetter) { |
| 2235 // TODO(ahe): Support deferred load. | 2255 // This is the LoadLibrary call. |
| 2236 return new ir.InvalidExpression(); | 2256 var deferredLibrary = new ir.DeferredImport( |
|
sra1
2017/02/14 03:14:06
I would expect there to be a single shared Deferre
Emily Fortuna
2017/02/14 20:56:28
Changed to PutIfAbsent. I'm not convinced this is
| |
| 2257 kernel.libraries[getter.prefix.deferredImport.importedLibrary], | |
| 2258 getter.prefix.name); | |
| 2259 assert(deferredLibrary != null); | |
| 2260 return new ir.LoadLibrary(deferredLibrary); | |
| 2237 } | 2261 } |
| 2238 return buildStaticGet(getter); | 2262 var expression = buildStaticGet(getter); |
| 2263 return expression; | |
| 2239 } | 2264 } |
| 2240 | 2265 |
| 2241 @override | 2266 @override |
| 2242 ir.Expression handleStaticGetterInvoke(Send node, FunctionElement getter, | 2267 ir.Expression handleStaticGetterInvoke(Send node, FunctionElement getter, |
| 2243 NodeList arguments, CallStructure callStructure, _) { | 2268 NodeList arguments, CallStructure callStructure, _) { |
| 2269 var expression; | |
| 2244 if (getter.isDeferredLoaderGetter) { | 2270 if (getter.isDeferredLoaderGetter) { |
| 2245 // TODO(ahe): Support deferred load. | 2271 var deferredLibrary = new ir.DeferredImport( |
| 2246 return new ir.InvalidExpression(); | 2272 kernel.libraries[getter.prefix.deferredImport.importedLibrary], |
| 2273 getter.prefix.name); | |
| 2274 assert(deferredLibrary != null); | |
| 2275 expression = new ir.LoadLibrary(deferredLibrary); | |
|
sra1
2017/02/14 03:14:06
This code is the same as above.
I'd put it in a se
Emily Fortuna
2017/02/14 20:56:28
done. See above.
| |
| 2276 } else { | |
| 2277 expression = buildStaticGet(getter); | |
| 2247 } | 2278 } |
| 2248 return associateNode( | 2279 return associateNode(buildCall(expression, callStructure, arguments), node); |
| 2249 buildCall(buildStaticGet(getter), callStructure, arguments), node); | |
| 2250 } | 2280 } |
| 2251 | 2281 |
| 2252 @override | 2282 @override |
| 2253 ir.Expression handleStaticGetterSet( | 2283 ir.Expression handleStaticGetterSet( |
| 2254 SendSet node, FunctionElement getter, Node rhs, _) { | 2284 SendSet node, FunctionElement getter, Node rhs, _) { |
| 2255 return buildStaticAccessor(getter) | 2285 return buildStaticAccessor(getter) |
| 2256 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2286 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
| 2257 } | 2287 } |
| 2258 | 2288 |
| 2259 @override | 2289 @override |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2809 return new IrFunction.constructor( | 2839 return new IrFunction.constructor( |
| 2810 node, <ir.Initializer>[new ir.InvalidInitializer()]); | 2840 node, <ir.Initializer>[new ir.InvalidInitializer()]); |
| 2811 } else { | 2841 } else { |
| 2812 node.body = new ir.InvalidStatement()..parent = node; | 2842 node.body = new ir.InvalidStatement()..parent = node; |
| 2813 return new IrFunction.procedure(ir.ProcedureKind.Method, node); | 2843 return new IrFunction.procedure(ir.ProcedureKind.Method, node); |
| 2814 } | 2844 } |
| 2815 } else if (currentElement.isSynthesized) { | 2845 } else if (currentElement.isSynthesized) { |
| 2816 if (currentElement.isGenerativeConstructor) { | 2846 if (currentElement.isGenerativeConstructor) { |
| 2817 return buildGenerativeConstructor(currentElement, null, null); | 2847 return buildGenerativeConstructor(currentElement, null, null); |
| 2818 } else { | 2848 } else { |
| 2819 return internalError(currentElement, "Unhandled synthetic function."); | 2849 return internalError(currentElement, |
| 2850 "Unhandled synthetic function."); | |
| 2820 } | 2851 } |
| 2821 } else { | 2852 } else { |
| 2822 Node node = currentElement.node; | 2853 Node node = currentElement.node; |
| 2823 if (node.isErroneous) { | 2854 if (node.isErroneous) { |
| 2824 return internalError(currentElement, "Unexpected syntax error."); | 2855 return internalError(currentElement, "Unexpected syntax error."); |
| 2825 } else { | 2856 } else { |
| 2826 return node.accept(this); | 2857 return node.accept(this); |
| 2827 } | 2858 } |
| 2828 } | 2859 } |
| 2829 }); | 2860 }); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2867 : this(null, true, node, initializers); | 2898 : this(null, true, node, initializers); |
| 2868 | 2899 |
| 2869 accept(ir.Visitor v) => throw "unsupported"; | 2900 accept(ir.Visitor v) => throw "unsupported"; |
| 2870 | 2901 |
| 2871 visitChildren(ir.Visitor v) => throw "unsupported"; | 2902 visitChildren(ir.Visitor v) => throw "unsupported"; |
| 2872 | 2903 |
| 2873 String toString() { | 2904 String toString() { |
| 2874 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 2905 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
| 2875 } | 2906 } |
| 2876 } | 2907 } |
| OLD | NEW |