| 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 #library('elements'); | 5 #library('elements'); |
| 6 | 6 |
| 7 #import('../tree/tree.dart'); | 7 #import('../tree/tree.dart'); |
| 8 #import('../scanner/scannerlib.dart'); | 8 #import('../scanner/scannerlib.dart'); |
| 9 #import('../leg.dart'); // TODO(karlklose): we only need type. | 9 #import('../leg.dart'); // TODO(karlklose): we only need type. |
| 10 #import('../util/util.dart'); | 10 #import('../util/util.dart'); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 207 |
| 208 Element getOutermostEnclosingMemberOrTopLevel() { | 208 Element getOutermostEnclosingMemberOrTopLevel() { |
| 209 for (Element e = this; e !== null; e = e.enclosingElement) { | 209 for (Element e = this; e !== null; e = e.enclosingElement) { |
| 210 if (e.isMember() || e.isTopLevel()) { | 210 if (e.isMember() || e.isTopLevel()) { |
| 211 return e; | 211 return e; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 return null; | 214 return null; |
| 215 } | 215 } |
| 216 | 216 |
| 217 /** |
| 218 * Creates the scope for this element. The scope of the |
| 219 * enclosing element will be the parent scope. |
| 220 */ |
| 221 Scope buildScope() => buildEnclosingScope(); |
| 222 |
| 223 /** |
| 224 * Creates the scope for the enclosing element. |
| 225 */ |
| 226 Scope buildEnclosingScope() => enclosingElement.buildScope(); |
| 227 |
| 217 String toString() { | 228 String toString() { |
| 218 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an | 229 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an |
| 219 // invariant for all element types? | 230 // invariant for all element types? |
| 220 var nameText = name !== null ? name.slowToString() : '?'; | 231 var nameText = name !== null ? name.slowToString() : '?'; |
| 221 if (enclosingElement !== null && !isTopLevel()) { | 232 if (enclosingElement !== null && !isTopLevel()) { |
| 222 String holderName = enclosingElement.name !== null | 233 String holderName = enclosingElement.name !== null |
| 223 ? enclosingElement.name.slowToString() | 234 ? enclosingElement.name.slowToString() |
| 224 : '${enclosingElement.kind}?'; | 235 : '${enclosingElement.kind}?'; |
| 225 return '$kind($holderName#${nameText})'; | 236 return '$kind($holderName#${nameText})'; |
| 226 } else { | 237 } else { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 */ | 398 */ |
| 388 String getLibraryOrScriptName() { | 399 String getLibraryOrScriptName() { |
| 389 if (libraryTag !== null) { | 400 if (libraryTag !== null) { |
| 390 return libraryTag.argument.dartString.slowToString(); | 401 return libraryTag.argument.dartString.slowToString(); |
| 391 } else { | 402 } else { |
| 392 // Use the file name as script name. | 403 // Use the file name as script name. |
| 393 var path = script.uri.path; | 404 var path = script.uri.path; |
| 394 return path.substring(path.lastIndexOf('/') + 1); | 405 return path.substring(path.lastIndexOf('/') + 1); |
| 395 } | 406 } |
| 396 } | 407 } |
| 408 |
| 409 Scope buildEnclosingScope() => new TopScope(this); |
| 397 } | 410 } |
| 398 | 411 |
| 399 class PrefixElement extends Element { | 412 class PrefixElement extends Element { |
| 400 Map<SourceString, Element> imported; | 413 Map<SourceString, Element> imported; |
| 401 Token firstPosition; | 414 Token firstPosition; |
| 402 final CompilationUnitElement patchSource; | 415 final CompilationUnitElement patchSource; |
| 403 | 416 |
| 404 PrefixElement(SourceString prefix, Element enclosing, this.firstPosition, | 417 PrefixElement(SourceString prefix, Element enclosing, this.firstPosition, |
| 405 [this.patchSource]) | 418 [this.patchSource]) |
| 406 : imported = new Map<SourceString, Element>(), | 419 : imported = new Map<SourceString, Element>(), |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 // It contains the node, and the type. A [VariableElement] always | 511 // It contains the node, and the type. A [VariableElement] always |
| 499 // references its [VariableListElement]. It forwards its | 512 // references its [VariableListElement]. It forwards its |
| 500 // [computeType] and [parseNode] methods to this element. | 513 // [computeType] and [parseNode] methods to this element. |
| 501 class VariableListElement extends Element { | 514 class VariableListElement extends Element { |
| 502 VariableDefinitions cachedNode; | 515 VariableDefinitions cachedNode; |
| 503 Type type; | 516 Type type; |
| 504 final Modifiers modifiers; | 517 final Modifiers modifiers; |
| 505 | 518 |
| 506 /** | 519 /** |
| 507 * Function signature for a variable with a function type. The signature is | 520 * Function signature for a variable with a function type. The signature is |
| 508 * kept to provide full information about parameter names through the the | 521 * kept to provide full information about parameter names through the mirror |
| 509 * mirror system. | 522 * system. |
| 510 */ | 523 */ |
| 511 FunctionSignature functionSignature; | 524 FunctionSignature functionSignature; |
| 512 | 525 |
| 513 VariableListElement(ElementKind kind, | 526 VariableListElement(ElementKind kind, |
| 514 Modifiers this.modifiers, | 527 Modifiers this.modifiers, |
| 515 Element enclosing) | 528 Element enclosing) |
| 516 : super(null, kind, enclosing); | 529 : super(null, kind, enclosing); |
| 517 | 530 |
| 518 VariableListElement.node(VariableDefinitions node, | 531 VariableListElement.node(VariableDefinitions node, |
| 519 ElementKind kind, | 532 ElementKind kind, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 getter.modifiers.nodes, | 619 getter.modifiers.nodes, |
| 607 getter.modifiers.flags | Modifiers.FLAG_ABSTRACT); | 620 getter.modifiers.flags | Modifiers.FLAG_ABSTRACT); |
| 608 } else { | 621 } else { |
| 609 return new Modifiers.withFlags( | 622 return new Modifiers.withFlags( |
| 610 setter.modifiers.nodes, | 623 setter.modifiers.nodes, |
| 611 setter.modifiers.flags | Modifiers.FLAG_ABSTRACT); | 624 setter.modifiers.flags | Modifiers.FLAG_ABSTRACT); |
| 612 } | 625 } |
| 613 } | 626 } |
| 614 } | 627 } |
| 615 | 628 |
| 629 // TODO(johnniwinther): [FunctionSignature] should be merged with |
| 630 // [FunctionType]. |
| 616 class FunctionSignature { | 631 class FunctionSignature { |
| 617 Link<Element> requiredParameters; | 632 Link<Element> requiredParameters; |
| 618 Link<Element> optionalParameters; | 633 Link<Element> optionalParameters; |
| 619 Type returnType; | 634 Type returnType; |
| 620 int requiredParameterCount; | 635 int requiredParameterCount; |
| 621 int optionalParameterCount; | 636 int optionalParameterCount; |
| 622 FunctionSignature(this.requiredParameters, | 637 FunctionSignature(this.requiredParameters, |
| 623 this.optionalParameters, | 638 this.optionalParameters, |
| 624 this.requiredParameterCount, | 639 this.requiredParameterCount, |
| 625 this.optionalParameterCount, | 640 this.optionalParameterCount, |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 for (ClassElement s = this; s != null; s = s.superclass) { | 1009 for (ClassElement s = this; s != null; s = s.superclass) { |
| 995 if (s === cls) return true; | 1010 if (s === cls) return true; |
| 996 } | 1011 } |
| 997 return false; | 1012 return false; |
| 998 } | 1013 } |
| 999 | 1014 |
| 1000 bool isInterface() => false; | 1015 bool isInterface() => false; |
| 1001 bool isNative() => nativeName != null; | 1016 bool isNative() => nativeName != null; |
| 1002 SourceString nativeName; | 1017 SourceString nativeName; |
| 1003 int hashCode() => id; | 1018 int hashCode() => id; |
| 1019 |
| 1020 Scope buildScope() => |
| 1021 new ClassScope(enclosingElement.buildScope(), this); |
| 1004 } | 1022 } |
| 1005 | 1023 |
| 1006 class Elements { | 1024 class Elements { |
| 1007 static bool isLocal(Element element) { | 1025 static bool isLocal(Element element) { |
| 1008 return ((element !== null) | 1026 return ((element !== null) |
| 1009 && !element.isInstanceMember() | 1027 && !element.isInstanceMember() |
| 1010 && !isStaticOrTopLevelField(element) | 1028 && !isStaticOrTopLevelField(element) |
| 1011 && !isStaticOrTopLevelFunction(element) | 1029 && !isStaticOrTopLevelFunction(element) |
| 1012 && (element.kind === ElementKind.VARIABLE || | 1030 && (element.kind === ElementKind.VARIABLE || |
| 1013 element.kind === ElementKind.PARAMETER || | 1031 element.kind === ElementKind.PARAMETER || |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 final Node node; | 1200 final Node node; |
| 1183 Type bound; | 1201 Type bound; |
| 1184 Type type; | 1202 Type type; |
| 1185 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1203 TypeVariableElement(name, Element enclosing, this.node, this.type, |
| 1186 [this.bound]) | 1204 [this.bound]) |
| 1187 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1205 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1188 Type computeType(compiler) => type; | 1206 Type computeType(compiler) => type; |
| 1189 Node parseNode(compiler) => node; | 1207 Node parseNode(compiler) => node; |
| 1190 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1208 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1191 } | 1209 } |
| OLD | NEW |