| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 abstract class TreeElements { | 5 abstract class TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 DartType getType(TypeAnnotation annotation); | 8 DartType getType(TypeAnnotation annotation); |
| 9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
| 10 } | 10 } |
| 11 | 11 |
| 12 class TreeElementMapping implements TreeElements { | 12 class TreeElementMapping implements TreeElements { |
| 13 final Element currentElement; | 13 final Element currentElement; |
| 14 final Map<Node, Element> map; | 14 final Map<Node, Element> map; |
| 15 final Map<Node, Selector> selectors; | 15 final Map<Node, Selector> selectors; |
| 16 final Map<TypeAnnotation, DartType> types; | 16 final Map<TypeAnnotation, DartType> types; |
| 17 final Set<Element> checkedParameters; | 17 final Set<Element> checkedParameters; |
| 18 | 18 |
| 19 TreeElementMapping([Element this.currentElement]) | 19 TreeElementMapping([Element this.currentElement]) |
| 20 : map = new LinkedHashMap<Node, Element>(), | 20 : map = new LinkedHashMap<Node, Element>(), |
| 21 selectors = new LinkedHashMap<Node, Selector>(), | 21 selectors = new LinkedHashMap<Node, Selector>(), |
| 22 types = new LinkedHashMap<TypeAnnotation, DartType>(), | 22 types = new LinkedHashMap<TypeAnnotation, DartType>(), |
| 23 checkedParameters = new Set<Element>(); | 23 checkedParameters = new Set<Element>(); |
| 24 | 24 |
| 25 operator []=(Node node, Element element) { | 25 operator []=(Node node, Element element) { |
| 26 assert(invariant(node, () { | 26 assert(invariant(node, () { |
| 27 if (node is FunctionExpression && node.modifiers != null) { | 27 if (node is FunctionExpression) { |
| 28 return !node.modifiers.isExternal(); | 28 return !node.modifiers.isExternal(); |
| 29 } | 29 } |
| 30 return true; | 30 return true; |
| 31 })); | 31 })); |
| 32 assert(invariant(node, () { | 32 assert(invariant(node, () { |
| 33 if (!element.isErroneous() && currentElement != null && element.isPatch) { | 33 if (!element.isErroneous() && currentElement != null && element.isPatch) { |
| 34 return currentElement.getImplementationLibrary().isPatch; | 34 return currentElement.getImplementationLibrary().isPatch; |
| 35 } | 35 } |
| 36 return true; | 36 return true; |
| 37 })); | 37 })); |
| (...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 | 1235 |
| 1236 visitFunctionExpression(FunctionExpression node) { | 1236 visitFunctionExpression(FunctionExpression node) { |
| 1237 visit(node.returnType); | 1237 visit(node.returnType); |
| 1238 SourceString name; | 1238 SourceString name; |
| 1239 if (node.name === null) { | 1239 if (node.name === null) { |
| 1240 name = const SourceString(""); | 1240 name = const SourceString(""); |
| 1241 } else { | 1241 } else { |
| 1242 name = node.name.asIdentifier().source; | 1242 name = node.name.asIdentifier().source; |
| 1243 } | 1243 } |
| 1244 FunctionElement enclosing = new FunctionElement.node( | 1244 FunctionElement enclosing = new FunctionElement.node( |
| 1245 name, node, ElementKind.FUNCTION, new Modifiers.empty(), | 1245 name, node, ElementKind.FUNCTION, Modifiers.EMPTY, |
| 1246 scope.element); | 1246 scope.element); |
| 1247 setupFunction(node, enclosing); | 1247 setupFunction(node, enclosing); |
| 1248 defineElement(node, enclosing, doAddToScope: node.name !== null); | 1248 defineElement(node, enclosing, doAddToScope: node.name !== null); |
| 1249 | 1249 |
| 1250 // Run the body in a fresh statement scope. | 1250 // Run the body in a fresh statement scope. |
| 1251 StatementScope oldScope = statementScope; | 1251 StatementScope oldScope = statementScope; |
| 1252 statementScope = new StatementScope(); | 1252 statementScope = new StatementScope(); |
| 1253 visit(node.body); | 1253 visit(node.body); |
| 1254 statementScope = oldScope; | 1254 statementScope = oldScope; |
| 1255 | 1255 |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2298 SynthesizedConstructorElement constructor = | 2298 SynthesizedConstructorElement constructor = |
| 2299 new SynthesizedConstructorElement(element); | 2299 new SynthesizedConstructorElement(element); |
| 2300 element.addToScope(constructor, compiler); | 2300 element.addToScope(constructor, compiler); |
| 2301 DartType returnType = compiler.types.voidType; | 2301 DartType returnType = compiler.types.voidType; |
| 2302 constructor.type = new FunctionType(returnType, const EmptyLink<DartType>(), | 2302 constructor.type = new FunctionType(returnType, const EmptyLink<DartType>(), |
| 2303 constructor); | 2303 constructor); |
| 2304 constructor.cachedNode = | 2304 constructor.cachedNode = |
| 2305 new FunctionExpression(new Identifier(element.position()), | 2305 new FunctionExpression(new Identifier(element.position()), |
| 2306 new NodeList.empty(), | 2306 new NodeList.empty(), |
| 2307 new Block(new NodeList.empty()), | 2307 new Block(new NodeList.empty()), |
| 2308 null, null, null, null); | 2308 null, Modifiers.EMPTY, null, null); |
| 2309 } | 2309 } |
| 2310 | 2310 |
| 2311 isBlackListed(DartType type) { | 2311 isBlackListed(DartType type) { |
| 2312 LibraryElement lib = element.getLibrary(); | 2312 LibraryElement lib = element.getLibrary(); |
| 2313 return | 2313 return |
| 2314 lib !== compiler.coreLibrary && | 2314 lib !== compiler.coreLibrary && |
| 2315 lib !== compiler.coreImplLibrary && | 2315 lib !== compiler.coreImplLibrary && |
| 2316 lib !== compiler.jsHelperLibrary && | 2316 lib !== compiler.jsHelperLibrary && |
| 2317 (type.element === compiler.dynamicClass || | 2317 (type.element === compiler.dynamicClass || |
| 2318 type.element === compiler.boolClass || | 2318 type.element === compiler.boolClass || |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 if (result === null) { | 2660 if (result === null) { |
| 2661 String fullConstructorName = cls.name.slowToString(); | 2661 String fullConstructorName = cls.name.slowToString(); |
| 2662 if (constructorName !== const SourceString('')) { | 2662 if (constructorName !== const SourceString('')) { |
| 2663 fullConstructorName = '$fullConstructorName' | 2663 fullConstructorName = '$fullConstructorName' |
| 2664 '.${constructorName.slowToString()}'; | 2664 '.${constructorName.slowToString()}'; |
| 2665 } | 2665 } |
| 2666 return failOrReturnErroneousElement(cls, diagnosticNode, | 2666 return failOrReturnErroneousElement(cls, diagnosticNode, |
| 2667 new SourceString(fullConstructorName), | 2667 new SourceString(fullConstructorName), |
| 2668 MessageKind.CANNOT_FIND_CONSTRUCTOR, | 2668 MessageKind.CANNOT_FIND_CONSTRUCTOR, |
| 2669 [fullConstructorName]); | 2669 [fullConstructorName]); |
| 2670 } else if (inConstContext && | 2670 } else if (inConstContext && !result.modifiers.isConst()) { |
| 2671 (result.modifiers == null || !result.modifiers.isConst())) { | |
| 2672 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 2671 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 2673 } | 2672 } |
| 2674 return result; | 2673 return result; |
| 2675 } | 2674 } |
| 2676 | 2675 |
| 2677 visitNewExpression(NewExpression node) { | 2676 visitNewExpression(NewExpression node) { |
| 2678 Node selector = node.send.selector; | 2677 Node selector = node.send.selector; |
| 2679 Element e = visit(selector); | 2678 Element e = visit(selector); |
| 2680 if (!Elements.isUnresolved(e) && e.kind === ElementKind.CLASS) { | 2679 if (!Elements.isUnresolved(e) && e.kind === ElementKind.CLASS) { |
| 2681 ClassElement cls = e; | 2680 ClassElement cls = e; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 | 2879 |
| 2881 Element localLookup(SourceString name) => library.find(name); | 2880 Element localLookup(SourceString name) => library.find(name); |
| 2882 Element lookup(SourceString name) => localLookup(name); | 2881 Element lookup(SourceString name) => localLookup(name); |
| 2883 Element lexicalLookup(SourceString name) => localLookup(name); | 2882 Element lexicalLookup(SourceString name) => localLookup(name); |
| 2884 | 2883 |
| 2885 Element add(Element newElement) { | 2884 Element add(Element newElement) { |
| 2886 throw "Cannot add an element in the top scope"; | 2885 throw "Cannot add an element in the top scope"; |
| 2887 } | 2886 } |
| 2888 String toString() => '$element'; | 2887 String toString() => '$element'; |
| 2889 } | 2888 } |
| OLD | NEW |