| 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 class Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 | 909 |
| 910 final Map<FunctionElement, TreeElements> constructorElements = | 910 final Map<FunctionElement, TreeElements> constructorElements = |
| 911 compiler.resolver.constructorElements; | 911 compiler.resolver.constructorElements; |
| 912 List<FunctionElement> constructors = new List<FunctionElement>(); | 912 List<FunctionElement> constructors = new List<FunctionElement>(); |
| 913 | 913 |
| 914 // Analyze the constructor and all referenced constructors and collect | 914 // Analyze the constructor and all referenced constructors and collect |
| 915 // initializers and constructor bodies. | 915 // initializers and constructor bodies. |
| 916 inlineInitializers(functionElement, constructors, fieldValues); | 916 inlineInitializers(functionElement, constructors, fieldValues); |
| 917 | 917 |
| 918 // Call the JavaScript constructor with the fields as argument. | 918 // Call the JavaScript constructor with the fields as argument. |
| 919 // TODO(floitsch,karlklose): move this code to ClassElement and share with | |
| 920 // the emitter. | |
| 921 List<HInstruction> constructorArguments = <HInstruction>[]; | 919 List<HInstruction> constructorArguments = <HInstruction>[]; |
| 922 ClassElement element = classElement; | 920 classElement.forEachInstanceField( |
| 923 while (element != null) { | 921 includeBackendMembers: true, |
| 924 for (Element member in element.members) { | 922 includeSuperMembers: true, |
| 925 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { | 923 f: (ClassElement enclosingClass, Element member) { |
| 926 HInstruction value = fieldValues[member]; | 924 HInstruction value = fieldValues[member]; |
| 927 if (value === null) { | 925 if (value === null) { |
| 928 // The field has no value in the initializer list. Initialize it | 926 // The field has no value in the initializer list. Initialize it |
| 929 // with the declaration-site constant (if any). | 927 // with the declaration-site constant (if any). |
| 930 Constant fieldValue = | 928 Constant fieldValue = compiler.constantHandler.compileVariable(member); |
| 931 compiler.constantHandler.compileVariable(member); | 929 value = graph.addConstant(fieldValue); |
| 932 value = graph.addConstant(fieldValue); | |
| 933 } | |
| 934 constructorArguments.add(value); | |
| 935 } | |
| 936 } | 930 } |
| 937 element = element.superclass; | 931 constructorArguments.add(value); |
| 938 } | 932 }); |
| 933 |
| 939 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); | 934 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); |
| 940 add(newObject); | 935 add(newObject); |
| 941 // Generate calls to the constructor bodies. | 936 // Generate calls to the constructor bodies. |
| 942 for (int index = constructors.length - 1; index >= 0; index--) { | 937 for (int index = constructors.length - 1; index >= 0; index--) { |
| 943 FunctionElement constructor = constructors[index]; | 938 FunctionElement constructor = constructors[index]; |
| 944 // TODO(floitsch): find better way to detect that constructor body is | 939 // TODO(floitsch): find better way to detect that constructor body is |
| 945 // empty. | 940 // empty. |
| 946 if (constructor is SynthesizedConstructorElement) continue; | 941 if (constructor is SynthesizedConstructorElement) continue; |
| 947 ConstructorBodyElement body = getConstructorBody(classElement, | 942 ConstructorBodyElement body = getConstructorBody(classElement, |
| 948 constructor); | 943 constructor); |
| (...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2962 false, | 2957 false, |
| 2963 <HInstruction>[target, input])); | 2958 <HInstruction>[target, input])); |
| 2964 return builder.pop(); | 2959 return builder.pop(); |
| 2965 } | 2960 } |
| 2966 | 2961 |
| 2967 HInstruction result() { | 2962 HInstruction result() { |
| 2968 flushLiterals(); | 2963 flushLiterals(); |
| 2969 return prefix; | 2964 return prefix; |
| 2970 } | 2965 } |
| 2971 } | 2966 } |
| OLD | NEW |