| OLD | NEW | 
|---|
| 1 // Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 import 'package:compiler/src/elements/elements.dart'; | 5 import 'package:compiler/src/elements/elements.dart'; | 
| 6 import 'package:compiler/src/resolution/access_semantics.dart'; | 6 import 'package:compiler/src/resolution/access_semantics.dart'; | 
| 7 import 'package:compiler/src/resolution/send_structure.dart'; | 7 import 'package:compiler/src/resolution/send_structure.dart'; | 
| 8 import 'package:compiler/src/resolution/tree_elements.dart'; | 8 import 'package:compiler/src/resolution/tree_elements.dart'; | 
| 9 import 'package:compiler/src/tree/nodes.dart' as ast; | 9 import 'package:compiler/src/tree/nodes.dart' as ast; | 
| 10 import 'package:kernel/ast.dart' as ir; | 10 import 'package:kernel/ast.dart' as ir; | 
| 11 | 11 | 
| 12 enum IdKind { element, node, local_variable, local_function } | 12 enum IdKind { | 
|  | 13   element, | 
|  | 14   node, | 
|  | 15 } | 
| 13 | 16 | 
| 14 /// Id for a code point or element with type inference information. | 17 /// Id for a code point or element with type inference information. | 
| 15 abstract class Id { | 18 abstract class Id { | 
| 16   IdKind get kind; | 19   IdKind get kind; | 
| 17 } | 20 } | 
| 18 | 21 | 
| 19 /// Id for an element with type inference information. | 22 /// Id for an element with type inference information. | 
| 20 // TODO(johnniwinther): Support local variables, functions and parameters. | 23 // TODO(johnniwinther): Support local variables, functions and parameters. | 
| 21 class ElementId implements Id { | 24 class ElementId implements Id { | 
| 22   final String className; | 25   final String className; | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 78     } | 81     } | 
| 79     String className = element.enclosingClass?.name; | 82     String className = element.enclosingClass?.name; | 
| 80     return new ElementId.internal(memberName, className); | 83     return new ElementId.internal(memberName, className); | 
| 81   } | 84   } | 
| 82 | 85 | 
| 83   NodeId computeAccessId(ast.Send node, AccessSemantics access) { | 86   NodeId computeAccessId(ast.Send node, AccessSemantics access) { | 
| 84     switch (access.kind) { | 87     switch (access.kind) { | 
| 85       case AccessKind.DYNAMIC_PROPERTY: | 88       case AccessKind.DYNAMIC_PROPERTY: | 
| 86         return new NodeId(node.selector.getBeginToken().charOffset); | 89         return new NodeId(node.selector.getBeginToken().charOffset); | 
| 87       default: | 90       default: | 
| 88         return new NodeId(node.getBeginToken().charOffset); | 91         return null; | 
| 89     } | 92     } | 
| 90   } | 93   } | 
| 91 | 94 | 
| 92   NodeId computeNodeId(ast.Node node, AstElement element) { | 95   NodeId computeNodeId(ast.Node node, AstElement element) { | 
| 93     if (element != null && element.isLocal) { | 96     if (element != null && element.isLocal) { | 
| 94       return new NodeId(node.getBeginToken().charOffset); | 97       return new NodeId(node.getBeginToken().charOffset); | 
| 95     } else if (node is ast.Send) { | 98     } else if (node is ast.Send) { | 
| 96       dynamic sendStructure = elements.getSendStructure(node); | 99       dynamic sendStructure = elements.getSendStructure(node); | 
| 97       if (sendStructure == null) return null; | 100       if (sendStructure == null) return null; | 
| 98       switch (sendStructure.kind) { | 101       switch (sendStructure.kind) { | 
| 99         case SendStructureKind.GET: | 102         case SendStructureKind.GET: | 
| 100         case SendStructureKind.INVOKE: | 103         case SendStructureKind.INVOKE: | 
| 101         case SendStructureKind.INCOMPATIBLE_INVOKE: |  | 
| 102           return computeAccessId(node, sendStructure.semantics); | 104           return computeAccessId(node, sendStructure.semantics); | 
| 103         default: | 105         default: | 
| 104           return new NodeId(node.getBeginToken().charOffset); |  | 
| 105       } | 106       } | 
| 106     } | 107     } | 
| 107     return new NodeId(node.getBeginToken().charOffset); | 108     return null; | 
| 108   } | 109   } | 
| 109 } | 110 } | 
| 110 | 111 | 
| 111 /// Visitor that finds the AST node or element corresponding to an [Id]. | 112 /// Visitor that finds the AST node or element corresponding to an [Id]. | 
| 112 class AstIdFinder extends ast.Visitor with AstEnumeratorMixin { | 113 class AstIdFinder extends ast.Visitor with AstEnumeratorMixin { | 
| 113   Id soughtId; | 114   Id soughtId; | 
| 114   var /*AstElement|ast.Node*/ found; | 115   var /*AstElement|ast.Node*/ found; | 
| 115   final TreeElements elements; | 116   final TreeElements elements; | 
| 116 | 117 | 
| 117   AstIdFinder(this.elements); | 118   AstIdFinder(this.elements); | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 195     if (node.enclosingClass != null) { | 196     if (node.enclosingClass != null) { | 
| 196       className = node.enclosingClass.name; | 197       className = node.enclosingClass.name; | 
| 197     } | 198     } | 
| 198     String memberName = node.name.name; | 199     String memberName = node.name.name; | 
| 199     if (node is ir.Procedure && node.kind == ir.ProcedureKind.Setter) { | 200     if (node is ir.Procedure && node.kind == ir.ProcedureKind.Setter) { | 
| 200       memberName += '='; | 201       memberName += '='; | 
| 201     } | 202     } | 
| 202     return new ElementId.internal(memberName, className); | 203     return new ElementId.internal(memberName, className); | 
| 203   } | 204   } | 
| 204 | 205 | 
| 205   Id computeNodeId(ir.Node node) { | 206   Id computeNodeId(ir.TreeNode node) { | 
| 206     if (node is ir.MethodInvocation) { | 207     if (node is ir.MethodInvocation) { | 
| 207       assert(node.fileOffset != ir.TreeNode.noOffset); | 208       assert(node.fileOffset != ir.TreeNode.noOffset); | 
| 208       return new NodeId(node.fileOffset); | 209       return new NodeId(node.fileOffset); | 
| 209     } else if (node is ir.PropertyGet) { | 210     } else if (node is ir.PropertyGet) { | 
| 210       assert(node.fileOffset != ir.TreeNode.noOffset); | 211       assert(node.fileOffset != ir.TreeNode.noOffset); | 
| 211       return new NodeId(node.fileOffset); | 212       return new NodeId(node.fileOffset); | 
|  | 213     } else if (node is ir.VariableDeclaration) { | 
|  | 214       assert(node.fileOffset != ir.TreeNode.noOffset); | 
|  | 215       return new NodeId(node.fileOffset); | 
|  | 216     } else if (node is ir.FunctionDeclaration) { | 
|  | 217       assert(node.fileOffset != ir.TreeNode.noOffset); | 
|  | 218       return new NodeId(node.fileOffset); | 
| 212     } | 219     } | 
| 213     return null; | 220     return null; | 
| 214   } | 221   } | 
| 215 } | 222 } | 
| 216 | 223 | 
| 217 /// Visitor that finds the IR node corresponding to an [Id]. | 224 /// Visitor that finds the IR node corresponding to an [Id]. | 
| 218 class IrIdFinder extends ir.Visitor with IrEnumeratorMixin { | 225 class IrIdFinder extends ir.Visitor with IrEnumeratorMixin { | 
| 219   Id soughtId; | 226   Id soughtId; | 
| 220   ir.Node found; | 227   ir.Node found; | 
| 221 | 228 | 
| 222   /// Visits the subtree of [root] returns the [ir.Node] corresponding to [id]. | 229   /// Visits the subtree of [root] returns the [ir.Node] corresponding to [id]. | 
| 223   ir.Node find(ir.Node root, Id id) { | 230   ir.Node find(ir.Node root, Id id) { | 
| 224     soughtId = id; | 231     soughtId = id; | 
| 225     root.accept(this); | 232     root.accept(this); | 
| 226     var result = found; | 233     var result = found; | 
| 227     found = null; | 234     found = null; | 
| 228     return result; | 235     return result; | 
| 229   } | 236   } | 
| 230 | 237 | 
| 231   defaultNode(ir.Node node) { | 238   defaultTreeNode(ir.TreeNode node) { | 
| 232     if (found == null) { | 239     if (found == null) { | 
| 233       Id id = computeNodeId(node); | 240       Id id = computeNodeId(node); | 
| 234       if (id == soughtId) { | 241       if (id == soughtId) { | 
| 235         found = node; | 242         found = node; | 
| 236         return; | 243         return; | 
| 237       } | 244       } | 
| 238       node.visitChildren(this); | 245       node.visitChildren(this); | 
| 239     } | 246     } | 
| 240   } | 247   } | 
| 241 | 248 | 
| 242   defaultMember(ir.Member node) { | 249   defaultMember(ir.Member node) { | 
| 243     if (found == null) { | 250     if (found == null) { | 
| 244       Id id = computeElementId(node); | 251       Id id = computeElementId(node); | 
| 245       if (id == soughtId) { | 252       if (id == soughtId) { | 
| 246         found = node; | 253         found = node; | 
| 247         return; | 254         return; | 
| 248       } | 255       } | 
| 249       defaultNode(node); | 256       defaultTreeNode(node); | 
| 250     } | 257     } | 
| 251   } | 258   } | 
| 252 } | 259 } | 
| OLD | NEW | 
|---|