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 /** | 5 /** |
6 * Top level generator object for writing code and keeping track of | 6 * Top level generator object for writing code and keeping track of |
7 * dependencies. | 7 * dependencies. |
8 * | 8 * |
9 * Should have two compilation models, but only one implemented so far. | 9 * Should have two compilation models, but only one implemented so far. |
10 * | 10 * |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 | 533 |
534 _writeField(FieldMember field) { | 534 _writeField(FieldMember field) { |
535 // Generate declarations for static top-level fields with no value. | 535 // Generate declarations for static top-level fields with no value. |
536 if (field.declaringType.isTop && !field.isNative && field.value == null) { | 536 if (field.declaringType.isTop && !field.isNative && field.value == null) { |
537 writer.writeln('var ${field.jsname};'); | 537 writer.writeln('var ${field.jsname};'); |
538 } | 538 } |
539 | 539 |
540 // generate code for instance fields | 540 // generate code for instance fields |
541 if (field._provideGetter && | 541 if (field._provideGetter && |
542 !field.declaringType.isConcreteGeneric) { | 542 !field.declaringType.isConcreteGeneric) { |
543 _writePrototypePatch(field.declaringType, 'get\$${field.jsname}', | 543 _writePrototypePatch(field.declaringType, field.jsnameOfGetter, |
544 'function() { return this.${field.jsname}; }', writer); | 544 'function() { return this.${field.jsname}; }', writer); |
545 } | 545 } |
546 if (field._provideSetter && | 546 if (field._provideSetter && |
547 !field.declaringType.isConcreteGeneric) { | 547 !field.declaringType.isConcreteGeneric) { |
548 _writePrototypePatch(field.declaringType, 'set\$${field.jsname}', | 548 _writePrototypePatch(field.declaringType, field.jsnameOfSetter, |
549 'function(value) { return this.${field.jsname} = value; }', writer); | 549 'function(value) { return this.${field.jsname} = value; }', writer); |
550 } | 550 } |
551 | 551 |
552 // TODO(jimhug): Currently choose not to initialize fields on objects, but | 552 // TODO(jimhug): Currently choose not to initialize fields on objects, but |
553 // instead to rely on uninitialized === null in our generated code. | 553 // instead to rely on uninitialized === null in our generated code. |
554 // Investigate the perf pros and cons of this. | 554 // Investigate the perf pros and cons of this. |
555 } | 555 } |
556 | 556 |
557 _writeProperty(PropertyMember property) { | 557 _writeProperty(PropertyMember property) { |
558 if (property.getter != null) _writeMethod(property.getter); | 558 if (property.getter != null) _writeMethod(property.getter); |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 usesBind = true; | 967 usesBind = true; |
968 } | 968 } |
969 } | 969 } |
970 | 970 |
971 if (usesBind) world.gen.corejs.ensureBind(); | 971 if (usesBind) world.gen.corejs.ensureBind(); |
972 } | 972 } |
973 | 973 |
974 static bool _maybeGenerateBoundGetter(MethodMember m, CodeWriter defWriter) { | 974 static bool _maybeGenerateBoundGetter(MethodMember m, CodeWriter defWriter) { |
975 if (m._provideGetter) { | 975 if (m._provideGetter) { |
976 String suffix = world.gen._writePrototypePatch(m.declaringType, | 976 String suffix = world.gen._writePrototypePatch(m.declaringType, |
977 'get\$${m.jsname}', 'function() {', defWriter, false); | 977 m.jsnameOfGetter, 'function() {', defWriter, false); |
978 if (m.parameters.some((p) => p.isOptional)) { | 978 if (m.parameters.some((p) => p.isOptional)) { |
979 defWriter.writeln('var f = this.${m.jsname}.bind(this);'); | 979 defWriter.writeln('var f = this.${m.jsname}.bind(this);'); |
980 defWriter.writeln('f.\$optional = this.${m.jsname}.\$optional;'); | 980 defWriter.writeln('f.\$optional = this.${m.jsname}.\$optional;'); |
981 defWriter.writeln('return f;'); | 981 defWriter.writeln('return f;'); |
982 } else { | 982 } else { |
983 defWriter.writeln('return this.${m.jsname}.bind(this);'); | 983 defWriter.writeln('return this.${m.jsname}.bind(this);'); |
984 } | 984 } |
985 defWriter.exitBlock(suffix); | 985 defWriter.exitBlock(suffix); |
986 return true; | 986 return true; |
987 } | 987 } |
(...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 return true; | 2536 return true; |
2537 } | 2537 } |
2538 | 2538 |
2539 } | 2539 } |
2540 | 2540 |
2541 class ReturnKind { | 2541 class ReturnKind { |
2542 static final int IGNORE = 1; | 2542 static final int IGNORE = 1; |
2543 static final int POST = 2; | 2543 static final int POST = 2; |
2544 static final int PRE = 3; | 2544 static final int PRE = 3; |
2545 } | 2545 } |
OLD | NEW |