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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2977943002: fix #30138, synethic nodes causing crash generating source maps (Closed)
Patch Set: fix Created 3 years, 5 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 } 576 }
577 } 577 }
578 578
579 @override 579 @override
580 visitCompilationUnit(CompilationUnit unit) { 580 visitCompilationUnit(CompilationUnit unit) {
581 // NOTE: this method isn't the right place to initialize 581 // NOTE: this method isn't the right place to initialize
582 // per-compilation-unit state. Declarations can be visited out of order, 582 // per-compilation-unit state. Declarations can be visited out of order,
583 // this is only to catch things that haven't been emitted yet. 583 // this is only to catch things that haven't been emitted yet.
584 // 584 //
585 // See _emitTypeDeclaration. 585 // See _emitTypeDeclaration.
586 var library = unit.element.library; 586 _currentElements.add(unit.element);
587 bool internalSdk = isSdkInternalRuntime(library); 587 var isInternalSdk = isSdkInternalRuntime(currentLibrary);
588 _currentElements.add(library);
589 List<VariableDeclaration> fields; 588 List<VariableDeclaration> fields;
590 for (var declaration in unit.declarations) { 589 for (var declaration in unit.declarations) {
591 if (declaration is TopLevelVariableDeclaration) { 590 if (declaration is TopLevelVariableDeclaration) {
592 inferNullableTypes(declaration); 591 inferNullableTypes(declaration);
593 if (internalSdk && declaration.variables.isFinal) { 592 if (isInternalSdk && declaration.variables.isFinal) {
594 _emitInternalSdkFields(declaration.variables.variables); 593 _emitInternalSdkFields(declaration.variables.variables);
595 } else { 594 } else {
596 (fields ??= []).addAll(declaration.variables.variables); 595 (fields ??= []).addAll(declaration.variables.variables);
597 } 596 }
598 continue; 597 continue;
599 } 598 }
600 599
601 if (fields != null) { 600 if (fields != null) {
602 _emitTopLevelFields(fields); 601 _emitTopLevelFields(fields);
603 fields = null; 602 fields = null;
604 } 603 }
605 604
606 var element = declaration.element; 605 var element = declaration.element;
607 if (element is TypeDefiningElement) { 606 if (element is TypeDefiningElement) {
608 _emitTypeDeclaration(element); 607 _emitTypeDeclaration(element);
609 continue; 608 continue;
610 } 609 }
611 610
612 inferNullableTypes(declaration); 611 inferNullableTypes(declaration);
613 var item = _visit(declaration); 612 var item = _visit(declaration);
614 if (internalSdk && element is FunctionElement) { 613 if (isInternalSdk && element is FunctionElement) {
615 _internalSdkFunctions.add(item); 614 _internalSdkFunctions.add(item);
616 } else { 615 } else {
617 _moduleItems.add(item); 616 _moduleItems.add(item);
618 } 617 }
619 } 618 }
620 619
621 if (fields != null) _emitTopLevelFields(fields); 620 if (fields != null) _emitTopLevelFields(fields);
622 621
623 _currentElements.removeLast(); 622 _currentElements.removeLast();
624 } 623 }
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 } else { 2353 } else {
2355 value = new JS.LiteralNull(); 2354 value = new JS.LiteralNull();
2356 } 2355 }
2357 fields[element] = value; 2356 fields[element] = value;
2358 }); 2357 });
2359 2358
2360 var body = <JS.Statement>[]; 2359 var body = <JS.Statement>[];
2361 fields.forEach((FieldElement e, JS.Expression initialValue) { 2360 fields.forEach((FieldElement e, JS.Expression initialValue) {
2362 JS.Expression access = 2361 JS.Expression access =
2363 _classProperties.virtualFields[e] ?? _declareMemberName(e.getter); 2362 _classProperties.virtualFields[e] ?? _declareMemberName(e.getter);
2364 body.add(js.statement('this.# = #;', [access, initialValue])); 2363 body.add(initialValue
2364 .toAssignExpression(js.call('this.#', [access]))
2365 .toStatement());
2365 }); 2366 });
2366 2367
2367 return _statement(body); 2368 return _statement(body);
2368 } 2369 }
2369 2370
2370 FormalParameterList _parametersOf(node) { 2371 FormalParameterList _parametersOf(node) {
2371 // TODO(jmesserly): clean this up. If we can model ES6 spread/rest args, we 2372 // TODO(jmesserly): clean this up. If we can model ES6 spread/rest args, we
2372 // could handle argument initializers more consistently in a separate 2373 // could handle argument initializers more consistently in a separate
2373 // lowering pass. 2374 // lowering pass.
2374 if (node is ConstructorDeclaration) return node.parameters; 2375 if (node is ConstructorDeclaration) return node.parameters;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 fn = _emitNativeFunctionBody(node); 2464 fn = _emitNativeFunctionBody(node);
2464 } else { 2465 } else {
2465 fn = _emitFunctionBody(node.element, node.parameters, node.body); 2466 fn = _emitFunctionBody(node.element, node.parameters, node.body);
2466 } 2467 }
2467 2468
2468 return annotate( 2469 return annotate(
2469 new JS.Method(_declareMemberName(node.element), fn, 2470 new JS.Method(_declareMemberName(node.element), fn,
2470 isGetter: node.isGetter, 2471 isGetter: node.isGetter,
2471 isSetter: node.isSetter, 2472 isSetter: node.isSetter,
2472 isStatic: node.isStatic), 2473 isStatic: node.isStatic),
2473 node, 2474 null, // don't annotate as this breaks stepping for one-line functions.
2474 node.element); 2475 node.element);
2475 } 2476 }
2476 2477
2477 /// Transform the function so the last parameter is always returned. 2478 /// Transform the function so the last parameter is always returned.
2478 /// 2479 ///
2479 /// This is useful for indexed set methods, which otherwise would not have 2480 /// This is useful for indexed set methods, which otherwise would not have
2480 /// the right return value in JS. 2481 /// the right return value in JS.
2481 JS.Block _alwaysReturnLastParameter(JS.Block body, JS.Parameter lastParam) { 2482 JS.Block _alwaysReturnLastParameter(JS.Block body, JS.Parameter lastParam) {
2482 JS.Statement blockBody = body; 2483 JS.Statement blockBody = body;
2483 if (JS.Return.foundIn(body)) { 2484 if (JS.Return.foundIn(body)) {
(...skipping 3491 matching lines...) Expand 10 before | Expand all | Expand 10 after
5975 if (targetIdentifier.staticElement is! PrefixElement) return false; 5976 if (targetIdentifier.staticElement is! PrefixElement) return false;
5976 var prefix = targetIdentifier.staticElement as PrefixElement; 5977 var prefix = targetIdentifier.staticElement as PrefixElement;
5977 5978
5978 // The library the prefix is referring to must come from a deferred import. 5979 // The library the prefix is referring to must come from a deferred import.
5979 var containingLibrary = resolutionMap 5980 var containingLibrary = resolutionMap
5980 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5981 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5981 .library; 5982 .library;
5982 var imports = containingLibrary.getImportsWithPrefix(prefix); 5983 var imports = containingLibrary.getImportsWithPrefix(prefix);
5983 return imports.length == 1 && imports[0].isDeferred; 5984 return imports.length == 1 && imports[0].isDeferred;
5984 } 5985 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698