Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1414913002: Introduce .isMalformed (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address review Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 part of ssa; 5 part of ssa;
6 6
7 class SsaFunctionCompiler implements FunctionCompiler { 7 class SsaFunctionCompiler implements FunctionCompiler {
8 final SsaCodeGeneratorTask generator; 8 final SsaCodeGeneratorTask generator;
9 final SsaBuilderTask builder; 9 final SsaBuilderTask builder;
10 final SsaOptimizerTask optimizer; 10 final SsaOptimizerTask optimizer;
(...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 List<FunctionElement> constructors, 2015 List<FunctionElement> constructors,
2016 Map<Element, HInstruction> fieldValues) { 2016 Map<Element, HInstruction> fieldValues) {
2017 assert(invariant(constructor, constructor.isImplementation)); 2017 assert(invariant(constructor, constructor.isImplementation));
2018 if (constructor.isSynthesized) { 2018 if (constructor.isSynthesized) {
2019 List<HInstruction> arguments = <HInstruction>[]; 2019 List<HInstruction> arguments = <HInstruction>[];
2020 HInstruction compileArgument(ParameterElement parameter) { 2020 HInstruction compileArgument(ParameterElement parameter) {
2021 return localsHandler.readLocal(parameter); 2021 return localsHandler.readLocal(parameter);
2022 } 2022 }
2023 2023
2024 Element target = constructor.definingConstructor.implementation; 2024 Element target = constructor.definingConstructor.implementation;
2025 bool match = !target.isErroneous && 2025 bool match = !target.isMalformed &&
2026 CallStructure.addForwardingElementArgumentsToList( 2026 CallStructure.addForwardingElementArgumentsToList(
2027 constructor, 2027 constructor,
2028 arguments, 2028 arguments,
2029 target, 2029 target,
2030 compileArgument, 2030 compileArgument,
2031 handleConstantForOptionalParameter); 2031 handleConstantForOptionalParameter);
2032 if (!match) { 2032 if (!match) {
2033 if (compiler.elementHasCompileTimeError(constructor)) { 2033 if (compiler.elementHasCompileTimeError(constructor)) {
2034 return; 2034 return;
2035 } 2035 }
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
3468 3468
3469 /// Generate read access of an unresolved static or top level entity. 3469 /// Generate read access of an unresolved static or top level entity.
3470 void generateStaticUnresolvedGet(ast.Send node, Element element) { 3470 void generateStaticUnresolvedGet(ast.Send node, Element element) {
3471 if (element is ErroneousElement) { 3471 if (element is ErroneousElement) {
3472 SourceInformation sourceInformation = 3472 SourceInformation sourceInformation =
3473 sourceInformationBuilder.buildGet(node); 3473 sourceInformationBuilder.buildGet(node);
3474 // An erroneous element indicates an unresolved static getter. 3474 // An erroneous element indicates an unresolved static getter.
3475 handleInvalidStaticGet(node, element); 3475 handleInvalidStaticGet(node, element);
3476 } else { 3476 } else {
3477 // This happens when [element] has parse errors. 3477 // This happens when [element] has parse errors.
3478 assert(invariant(node, element == null || element.isErroneous)); 3478 assert(invariant(node, element == null || element.isMalformed));
3479 // TODO(ahe): Do something like the above, that is, emit a runtime 3479 // TODO(ahe): Do something like the above, that is, emit a runtime
3480 // error. 3480 // error.
3481 stack.add(graph.addConstantNull(compiler)); 3481 stack.add(graph.addConstantNull(compiler));
3482 } 3482 }
3483 } 3483 }
3484 3484
3485 /// Read a static or top level [field] of constant value. 3485 /// Read a static or top level [field] of constant value.
3486 void generateStaticConstGet( 3486 void generateStaticConstGet(
3487 ast.Send node, 3487 ast.Send node,
3488 FieldElement field, 3488 FieldElement field,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
3757 if (Elements.isStaticOrTopLevelField(element)) { 3757 if (Elements.isStaticOrTopLevelField(element)) {
3758 if (element.isSetter) { 3758 if (element.isSetter) {
3759 pushInvokeStatic(location, element, <HInstruction>[value]); 3759 pushInvokeStatic(location, element, <HInstruction>[value]);
3760 pop(); 3760 pop();
3761 } else { 3761 } else {
3762 VariableElement field = element; 3762 VariableElement field = element;
3763 value = potentiallyCheckOrTrustType(value, field.type); 3763 value = potentiallyCheckOrTrustType(value, field.type);
3764 addWithPosition(new HStaticStore(element, value), location); 3764 addWithPosition(new HStaticStore(element, value), location);
3765 } 3765 }
3766 stack.add(value); 3766 stack.add(value);
3767 } else if (Elements.isErroneous(element)) { 3767 } else if (Elements.isError(element)) {
3768 if (element is ErroneousElement) { 3768 generateNoSuchSetter(location, element, send == null ? null : value);
3769 generateNoSuchSetter(location, element, send == null ? null : value); 3769 } else if (Elements.isMalformed(element)) {
3770 } else { 3770 // TODO(ahe): Do something like [generateWrongArgumentCountError].
3771 // TODO(ahe): Do something like [generateWrongArgumentCountError]. 3771 stack.add(graph.addConstantNull(compiler));
3772 stack.add(graph.addConstantNull(compiler));
3773 }
3774 } else { 3772 } else {
3775 stack.add(value); 3773 stack.add(value);
3776 LocalElement local = element; 3774 LocalElement local = element;
3777 // If the value does not already have a name, give it here. 3775 // If the value does not already have a name, give it here.
3778 if (value.sourceElement == null) { 3776 if (value.sourceElement == null) {
3779 value.sourceElement = local; 3777 value.sourceElement = local;
3780 } 3778 }
3781 HInstruction checkedOrTrusted = 3779 HInstruction checkedOrTrusted =
3782 potentiallyCheckOrTrustType(value, local.type); 3780 potentiallyCheckOrTrustType(value, local.type);
3783 if (!identical(checkedOrTrusted, value)) { 3781 if (!identical(checkedOrTrusted, value)) {
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
5129 var inputs = <HInstruction>[]; 5127 var inputs = <HInstruction>[];
5130 if (constructor.isGenerativeConstructor && 5128 if (constructor.isGenerativeConstructor &&
5131 Elements.isNativeOrExtendsNative(constructor.enclosingClass) && 5129 Elements.isNativeOrExtendsNative(constructor.enclosingClass) &&
5132 !constructor.isJsInterop) { 5130 !constructor.isJsInterop) {
5133 // Native class generative constructors take a pre-constructed object. 5131 // Native class generative constructors take a pre-constructed object.
5134 inputs.add(graph.addConstantNull(compiler)); 5132 inputs.add(graph.addConstantNull(compiler));
5135 } 5133 }
5136 // TODO(5347): Try to avoid the need for calling [implementation] before 5134 // TODO(5347): Try to avoid the need for calling [implementation] before
5137 // calling [makeStaticArgumentList]. 5135 // calling [makeStaticArgumentList].
5138 constructorImplementation = constructor.implementation; 5136 constructorImplementation = constructor.implementation;
5139 if (constructorImplementation.isErroneous || 5137 if (constructorImplementation.isMalformed ||
5140 !callStructure.signatureApplies( 5138 !callStructure.signatureApplies(
5141 constructorImplementation.functionSignature)) { 5139 constructorImplementation.functionSignature)) {
5142 generateWrongArgumentCountError(send, constructor, send.arguments); 5140 generateWrongArgumentCountError(send, constructor, send.arguments);
5143 return; 5141 return;
5144 } 5142 }
5145 inputs.addAll(makeStaticArgumentList(callStructure, 5143 inputs.addAll(makeStaticArgumentList(callStructure,
5146 send.arguments, 5144 send.arguments,
5147 constructorImplementation)); 5145 constructorImplementation));
5148 5146
5149 TypeMask elementType = computeType(constructor); 5147 TypeMask elementType = computeType(constructor);
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
5717 5715
5718 @override 5716 @override
5719 void bulkHandleNode(ast.Node node, String message, _) { 5717 void bulkHandleNode(ast.Node node, String message, _) {
5720 internalError(node, "Unexpected bulk handled node: $node"); 5718 internalError(node, "Unexpected bulk handled node: $node");
5721 } 5719 }
5722 5720
5723 @override 5721 @override
5724 void bulkHandleNew(ast.NewExpression node, [_]) { 5722 void bulkHandleNew(ast.NewExpression node, [_]) {
5725 Element element = elements[node.send]; 5723 Element element = elements[node.send];
5726 final bool isSymbolConstructor = element == compiler.symbolConstructor; 5724 final bool isSymbolConstructor = element == compiler.symbolConstructor;
5727 if (!Elements.isErroneous(element)) { 5725 if (!Elements.isMalformed(element)) {
5728 ConstructorElement function = element; 5726 ConstructorElement function = element;
5729 element = function.effectiveTarget; 5727 element = function.effectiveTarget;
5730 } 5728 }
5731 if (Elements.isErroneous(element)) { 5729 if (Elements.isError(element)) {
5732 if (element is !ErroneousElement) {
5733 // TODO(ahe): Do something like [generateWrongArgumentCountError].
5734 stack.add(graph.addConstantNull(compiler));
5735 return;
5736 }
5737 ErroneousElement error = element; 5730 ErroneousElement error = element;
5738 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR) { 5731 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR) {
5739 generateThrowNoSuchMethod( 5732 generateThrowNoSuchMethod(
5740 node.send, 5733 node.send,
5741 noSuchMethodTargetSymbolString(error, 'constructor'), 5734 noSuchMethodTargetSymbolString(error, 'constructor'),
5742 argumentNodes: node.send.arguments); 5735 argumentNodes: node.send.arguments);
5743 } else { 5736 } else {
5744 MessageTemplate template = MessageTemplate.TEMPLATES[error.messageKind]; 5737 MessageTemplate template = MessageTemplate.TEMPLATES[error.messageKind];
5745 Message message = template.message(error.messageArguments); 5738 Message message = template.message(error.messageArguments);
5746 generateRuntimeError(node.send, message.toString()); 5739 generateRuntimeError(node.send, message.toString());
5747 } 5740 }
5741 } else if (Elements.isMalformed(element)) {
5742 // TODO(ahe): Do something like [generateWrongArgumentCountError].
5743 stack.add(graph.addConstantNull(compiler));
5748 } else if (node.isConst) { 5744 } else if (node.isConst) {
5749 stack.add(addConstant(node)); 5745 stack.add(addConstant(node));
5750 if (isSymbolConstructor) { 5746 if (isSymbolConstructor) {
5751 ConstructedConstantValue symbol = getConstantForNode(node); 5747 ConstructedConstantValue symbol = getConstantForNode(node);
5752 StringConstantValue stringConstant = symbol.fields.values.single; 5748 StringConstantValue stringConstant = symbol.fields.values.single;
5753 String nameString = stringConstant.toDartString().slowToString(); 5749 String nameString = stringConstant.toDartString().slowToString();
5754 registry?.registerConstSymbol(nameString); 5750 registry?.registerConstSymbol(nameString);
5755 } 5751 }
5756 } else { 5752 } else {
5757 handleNewSend(node); 5753 handleNewSend(node);
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
6874 pushCheckNull(receiver); 6870 pushCheckNull(receiver);
6875 }, 6871 },
6876 () => stack.add(receiver), 6872 () => stack.add(receiver),
6877 () => generateAssignment(receiver)); 6873 () => generateAssignment(receiver));
6878 } else { 6874 } else {
6879 generateAssignment(generateInstanceSendReceiver(node)); 6875 generateAssignment(generateInstanceSendReceiver(node));
6880 } 6876 }
6881 return; 6877 return;
6882 } 6878 }
6883 6879
6884 if (getter.isErroneous) { 6880 if (getter.isMalformed) {
6885 generateStaticUnresolvedGet(node, getter); 6881 generateStaticUnresolvedGet(node, getter);
6886 } else if (getter.isField) { 6882 } else if (getter.isField) {
6887 generateStaticFieldGet(node, getter); 6883 generateStaticFieldGet(node, getter);
6888 } else if (getter.isGetter) { 6884 } else if (getter.isGetter) {
6889 generateStaticGetterGet(node, getter); 6885 generateStaticGetterGet(node, getter);
6890 } else if (getter.isFunction) { 6886 } else if (getter.isFunction) {
6891 generateStaticFunctionGet(node, getter); 6887 generateStaticFunctionGet(node, getter);
6892 } else if (getter.isLocal) { 6888 } else if (getter.isLocal) {
6893 handleLocalGet(node, getter); 6889 handleLocalGet(node, getter);
6894 } else { 6890 } else {
(...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after
9145 if (unaliased is TypedefType) throw 'unable to unalias $type'; 9141 if (unaliased is TypedefType) throw 'unable to unalias $type';
9146 unaliased.accept(this, builder); 9142 unaliased.accept(this, builder);
9147 } 9143 }
9148 9144
9149 void visitDynamicType(DynamicType type, SsaBuilder builder) { 9145 void visitDynamicType(DynamicType type, SsaBuilder builder) {
9150 JavaScriptBackend backend = builder.compiler.backend; 9146 JavaScriptBackend backend = builder.compiler.backend;
9151 ClassElement cls = backend.findHelper('DynamicRuntimeType'); 9147 ClassElement cls = backend.findHelper('DynamicRuntimeType');
9152 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 9148 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
9153 } 9149 }
9154 } 9150 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/type_resolver.dart ('k') | pkg/compiler/lib/src/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698