| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 12 matching lines...) Expand all Loading... |
| 23 const ElementKind('generative_constructor'); | 23 const ElementKind('generative_constructor'); |
| 24 static final ElementKind FIELD = const ElementKind('field'); | 24 static final ElementKind FIELD = const ElementKind('field'); |
| 25 static final ElementKind VARIABLE_LIST = const ElementKind('variable_list'); | 25 static final ElementKind VARIABLE_LIST = const ElementKind('variable_list'); |
| 26 static final ElementKind FIELD_LIST = const ElementKind('field_list'); | 26 static final ElementKind FIELD_LIST = const ElementKind('field_list'); |
| 27 static final ElementKind GENERATIVE_CONSTRUCTOR_BODY = | 27 static final ElementKind GENERATIVE_CONSTRUCTOR_BODY = |
| 28 const ElementKind('generative_constructor_body'); | 28 const ElementKind('generative_constructor_body'); |
| 29 static final ElementKind COMPILATION_UNIT = | 29 static final ElementKind COMPILATION_UNIT = |
| 30 const ElementKind('compilation_unit'); | 30 const ElementKind('compilation_unit'); |
| 31 static final ElementKind GETTER = const ElementKind('getter'); | 31 static final ElementKind GETTER = const ElementKind('getter'); |
| 32 static final ElementKind SETTER = const ElementKind('setter'); | 32 static final ElementKind SETTER = const ElementKind('setter'); |
| 33 static final ElementKind ABSTRACT_FIELD = const ElementKind('abstract_field'); |
| 33 | 34 |
| 34 toString() => id; | 35 toString() => id; |
| 35 } | 36 } |
| 36 | 37 |
| 37 class Element implements Hashable { | 38 class Element implements Hashable { |
| 38 final SourceString name; | 39 final SourceString name; |
| 39 final ElementKind kind; | 40 final ElementKind kind; |
| 40 final Element enclosingElement; | 41 final Element enclosingElement; |
| 41 Modifiers get modifiers() => null; | 42 Modifiers get modifiers() => null; |
| 42 | 43 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 201 |
| 201 Type computeType(Compiler compiler) { | 202 Type computeType(Compiler compiler) { |
| 202 return compiler.types.dynamicType; | 203 return compiler.types.dynamicType; |
| 203 } | 204 } |
| 204 | 205 |
| 205 parseNode(DiagnosticListener listener) { | 206 parseNode(DiagnosticListener listener) { |
| 206 throw "internal error: ForeignElement has no node"; | 207 throw "internal error: ForeignElement has no node"; |
| 207 } | 208 } |
| 208 } | 209 } |
| 209 | 210 |
| 211 class AbstractFieldElement extends Element { |
| 212 FunctionElement getter; |
| 213 FunctionElement setter; |
| 214 AbstractFieldElement(SourceString name, Element enclosing) |
| 215 : super(name, ElementKind.ABSTRACT_FIELD, enclosing); |
| 216 |
| 217 Type computeType(Compiler compiler) { |
| 218 throw "internal error: AbstractFieldElement has no type"; |
| 219 } |
| 220 |
| 221 Node parseNode(DiagnosticListener listener) { |
| 222 throw "internal error: AbstractFieldElement has no node"; |
| 223 } |
| 224 } |
| 225 |
| 210 /** | 226 /** |
| 211 * TODO(ngeoffray): Remove this method in favor of using the universe. | 227 * TODO(ngeoffray): Remove this method in favor of using the universe. |
| 212 * | 228 * |
| 213 * Return the type referred to by the type annotation. This method | 229 * Return the type referred to by the type annotation. This method |
| 214 * accepts annotations with 'typeName == null' to indicate a missing | 230 * accepts annotations with 'typeName == null' to indicate a missing |
| 215 * annotation. | 231 * annotation. |
| 216 */ | 232 */ |
| 217 Type getType(TypeAnnotation typeAnnotation, compiler, types) { | 233 Type getType(TypeAnnotation typeAnnotation, compiler, types) { |
| 218 if (typeAnnotation == null || typeAnnotation.typeName == null) { | 234 if (typeAnnotation == null || typeAnnotation.typeName == null) { |
| 219 return types.dynamicType; | 235 return types.dynamicType; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 ClassElement(SourceString name, CompilationUnitElement enclosing) | 414 ClassElement(SourceString name, CompilationUnitElement enclosing) |
| 399 : localMembers = new Map<SourceString, Element>(), | 415 : localMembers = new Map<SourceString, Element>(), |
| 400 constructors = new Map<SourceString, Element>(), | 416 constructors = new Map<SourceString, Element>(), |
| 401 super(name, ElementKind.CLASS, enclosing); | 417 super(name, ElementKind.CLASS, enclosing); |
| 402 | 418 |
| 403 void addMember(Element element, DiagnosticListener listener) { | 419 void addMember(Element element, DiagnosticListener listener) { |
| 404 members = members.prepend(element); | 420 members = members.prepend(element); |
| 405 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR || | 421 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR || |
| 406 element.modifiers.isFactory()) { | 422 element.modifiers.isFactory()) { |
| 407 constructors[element.name] = element; | 423 constructors[element.name] = element; |
| 424 } else if (element.kind == ElementKind.GETTER |
| 425 || element.kind == ElementKind.SETTER) { |
| 426 Element existing = localMembers[element.name]; |
| 427 if (existing != null) { |
| 428 if (existing.kind !== ElementKind.ABSTRACT_FIELD) { |
| 429 listener.cancel('duplicate definition of $name', element: element); |
| 430 listener.cancel('existing definition', element: existing); |
| 431 } else { |
| 432 AbstractFieldElement field = existing; |
| 433 if (element.kind == ElementKind.GETTER) { |
| 434 if (field.getter != null) { |
| 435 listener.cancel('duplicate definition of getter ${element.name}', |
| 436 element: element); |
| 437 listener.cancel('existing definition', element: field.getter); |
| 438 } else { |
| 439 field.getter = element; |
| 440 } |
| 441 } else { |
| 442 if (field.setter != null) { |
| 443 listener.cancel('duplicate definition of setter ${element.name}', |
| 444 element: element); |
| 445 listener.cancel('existing definition', element: field.setter); |
| 446 } else { |
| 447 field.setter = element; |
| 448 } |
| 449 } |
| 450 } |
| 451 } else { |
| 452 AbstractFieldElement field = |
| 453 new AbstractFieldElement(element.name, this); |
| 454 localMembers[element.name] = field; |
| 455 if (element.kind == ElementKind.GETTER) { |
| 456 field.getter = element; |
| 457 } else { |
| 458 field.setter = element; |
| 459 } |
| 460 } |
| 408 } else { | 461 } else { |
| 409 localMembers[element.name] = element; | 462 localMembers[element.name] = element; |
| 410 } | 463 } |
| 411 } | 464 } |
| 412 | 465 |
| 413 Type computeType(compiler) { | 466 Type computeType(compiler) { |
| 414 if (type === null) { | 467 if (type === null) { |
| 415 type = new SimpleType(name, this); | 468 type = new SimpleType(name, this); |
| 416 } | 469 } |
| 417 return type; | 470 return type; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 ClassElement get superclass() { | 518 ClassElement get superclass() { |
| 466 assert(isResolved); | 519 assert(isResolved); |
| 467 return supertype === null ? null : supertype.element; | 520 return supertype === null ? null : supertype.element; |
| 468 } | 521 } |
| 469 } | 522 } |
| 470 | 523 |
| 471 class Elements { | 524 class Elements { |
| 472 static bool isInstanceField(Element element) { | 525 static bool isInstanceField(Element element) { |
| 473 return (element !== null) | 526 return (element !== null) |
| 474 && element.isInstanceMember() | 527 && element.isInstanceMember() |
| 475 && (element.kind === ElementKind.FIELD); | 528 && (element.kind === ElementKind.FIELD |
| 529 || element.kind === ElementKind.GETTER |
| 530 || element.kind === ElementKind.SETTER); |
| 476 } | 531 } |
| 477 | 532 |
| 478 static bool isStaticOrTopLevelField(Element element) { | 533 static bool isStaticOrTopLevelField(Element element) { |
| 479 return (element != null) | 534 return (element != null) |
| 480 && !element.isInstanceMember() | 535 && !element.isInstanceMember() |
| 481 && (element.kind === ElementKind.FIELD); | 536 && (element.kind === ElementKind.FIELD |
| 537 || element.kind === ElementKind.GETTER |
| 538 || element.kind === ElementKind.SETTER); |
| 482 } | 539 } |
| 483 | 540 |
| 484 static bool isInstanceMethod(Element element) { | 541 static bool isInstanceMethod(Element element) { |
| 485 return (element != null) | 542 return (element != null) |
| 486 && element.isInstanceMember() | 543 && element.isInstanceMember() |
| 487 && (element.kind === ElementKind.FUNCTION); | 544 && (element.kind === ElementKind.FUNCTION); |
| 488 } | 545 } |
| 489 | 546 |
| 490 static bool isClosureSend(Send send, TreeElements elements) { | 547 static bool isClosureSend(Send send, TreeElements elements) { |
| 491 if (send.isPropertyAccess) return false; | 548 if (send.isPropertyAccess) return false; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 else if (str === '>=') str = 'ge'; | 581 else if (str === '>=') str = 'ge'; |
| 525 else if (str === '>') str = 'gt'; | 582 else if (str === '>') str = 'gt'; |
| 526 else if (str === '<=') str = 'le'; | 583 else if (str === '<=') str = 'le'; |
| 527 else if (str === '<') str = 'lt'; | 584 else if (str === '<') str = 'lt'; |
| 528 else if (str === '&' || str === '&=') str = 'and'; | 585 else if (str === '&' || str === '&=') str = 'and'; |
| 529 else if (str === '^' || str === '^=') str = 'xor'; | 586 else if (str === '^' || str === '^=') str = 'xor'; |
| 530 else if (str === '|' || str === '|=') str = 'or'; | 587 else if (str === '|' || str === '|=') str = 'or'; |
| 531 return new SourceString('$receiver\$$str'); | 588 return new SourceString('$receiver\$$str'); |
| 532 } | 589 } |
| 533 } | 590 } |
| OLD | NEW |