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

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

Issue 2423313002: Emulate compiling a source file in the context of an existing library. Add --debugger-compile flag … (Closed)
Patch Set: Code review comments. Created 4 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) 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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } else { 618 } else {
619 return js.statement('# = #;', [_emitTopLevelName(element), body]); 619 return js.statement('# = #;', [_emitTopLevelName(element), body]);
620 } 620 }
621 } 621 }
622 622
623 @override 623 @override
624 JS.Expression visitTypeName(TypeName node) { 624 JS.Expression visitTypeName(TypeName node) {
625 if (node.type == null) { 625 if (node.type == null) {
626 // TODO(jmesserly): if the type fails to resolve, should we generate code 626 // TODO(jmesserly): if the type fails to resolve, should we generate code
627 // that throws instead? 627 // that throws instead?
628 assert(options.unsafeForceCompile); 628 assert(options.unsafeForceCompile || options.replCompile);
629 return js.call('dart.dynamic'); 629 return js.call('dart.dynamic');
630 } 630 }
631 return _emitType(node.type); 631 return _emitType(node.type);
632 } 632 }
633 633
634 @override 634 @override
635 JS.Statement visitClassTypeAlias(ClassTypeAlias node) { 635 JS.Statement visitClassTypeAlias(ClassTypeAlias node) {
636 ClassElement element = node.element; 636 ClassElement element = node.element;
637 637
638 // Forward all generative constructors from the base class. 638 // Forward all generative constructors from the base class.
(...skipping 2419 matching lines...) Expand 10 before | Expand all | Expand 10 after
3058 if (target != null && isDynamicInvoke(target)) { 3058 if (target != null && isDynamicInvoke(target)) {
3059 if (_inWhitelistCode(lhs)) { 3059 if (_inWhitelistCode(lhs)) {
3060 var vars = <JS.MetaLetVariable, JS.Expression>{}; 3060 var vars = <JS.MetaLetVariable, JS.Expression>{};
3061 var l = _visit(_bindValue(vars, 'l', target)); 3061 var l = _visit(_bindValue(vars, 'l', target));
3062 var name = _emitMemberName(id.name); 3062 var name = _emitMemberName(id.name);
3063 return new JS.MetaLet(vars, [ 3063 return new JS.MetaLet(vars, [
3064 js.call('(#[(#[dart._extensionType]) ? dartx[#] : #] = #)', 3064 js.call('(#[(#[dart._extensionType]) ? dartx[#] : #] = #)',
3065 [l, l, name, name, _visit(rhs)]) 3065 [l, l, name, name, _visit(rhs)])
3066 ]); 3066 ]);
3067 } 3067 }
3068 return js.call('dart.dput(#, #, #)', 3068 return js.call('dart.#(#, #, #)', [
3069 [_visit(target), _emitMemberName(id.name), _visit(rhs)]); 3069 _emitDynamicOperationName('dput'),
3070 _visit(target),
3071 _emitMemberName(id.name),
3072 _visit(rhs)
3073 ]);
3070 } 3074 }
3071 3075
3072 var accessor = id.staticElement; 3076 var accessor = id.staticElement;
3073 var element = 3077 var element =
3074 accessor is PropertyAccessorElement ? accessor.variable : accessor; 3078 accessor is PropertyAccessorElement ? accessor.variable : accessor;
3075 3079
3076 if (element is ClassMemberElement && element is! ConstructorElement) { 3080 if (element is ClassMemberElement && element is! ConstructorElement) {
3077 bool isStatic = element.isStatic; 3081 bool isStatic = element.isStatic;
3078 if (isStatic) { 3082 if (isStatic) {
3079 if (element is FieldElement) { 3083 if (element is FieldElement) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
3344 var vars = <JS.MetaLetVariable, JS.Expression>{}; 3348 var vars = <JS.MetaLetVariable, JS.Expression>{};
3345 var l = _visit(_bindValue(vars, 'l', target)); 3349 var l = _visit(_bindValue(vars, 'l', target));
3346 jsTarget = new JS.MetaLet(vars, [ 3350 jsTarget = new JS.MetaLet(vars, [
3347 js.call('(#[(#[dart._extensionType]) ? dartx[#] : #]).bind(#)', 3351 js.call('(#[(#[dart._extensionType]) ? dartx[#] : #]).bind(#)',
3348 [l, l, memberName, memberName, l]) 3352 [l, l, memberName, memberName, l])
3349 ]); 3353 ]);
3350 if (typeArgs != null) jsTarget = new JS.Call(jsTarget, typeArgs); 3354 if (typeArgs != null) jsTarget = new JS.Call(jsTarget, typeArgs);
3351 return new JS.Call(jsTarget, args); 3355 return new JS.Call(jsTarget, args);
3352 } 3356 }
3353 if (typeArgs != null) { 3357 if (typeArgs != null) {
3354 return js.call('dart.dgsend(#, #, #, #)', 3358 return js.call('dart.#(#, #, #, #)', [
3355 [jsTarget, new JS.ArrayInitializer(typeArgs), memberName, args]); 3359 _emitDynamicOperationName('dgsend'),
3360 jsTarget,
3361 new JS.ArrayInitializer(typeArgs),
3362 memberName,
3363 args
3364 ]);
3356 } else { 3365 } else {
3357 return js.call('dart.dsend(#, #, #)', [jsTarget, memberName, args]); 3366 return js.call('dart.#(#, #, #)',
3367 [_emitDynamicOperationName('dsend'), jsTarget, memberName, args]);
3358 } 3368 }
3359 } 3369 }
3360 if (_isObjectMemberCall(target, name)) { 3370 if (_isObjectMemberCall(target, name)) {
3361 assert(typeArgs == null); // Object methods don't take type args. 3371 assert(typeArgs == null); // Object methods don't take type args.
3362 return js.call('dart.#(#, #)', [name, jsTarget, args]); 3372 return js.call('dart.#(#, #)', [name, jsTarget, args]);
3363 } 3373 }
3364 3374
3365 jsTarget = new JS.PropertyAccess(jsTarget, memberName); 3375 jsTarget = new JS.PropertyAccess(jsTarget, memberName);
3366 if (typeArgs != null) jsTarget = new JS.Call(jsTarget, typeArgs); 3376 if (typeArgs != null) jsTarget = new JS.Call(jsTarget, typeArgs);
3367 3377
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
4628 type = member.type; 4638 type = member.type;
4629 } else if (member is VariableElement) { 4639 } else if (member is VariableElement) {
4630 type = member.type; 4640 type = member.type;
4631 } 4641 }
4632 4642
4633 // TODO(jmesserly): handle explicitly passed type args. 4643 // TODO(jmesserly): handle explicitly passed type args.
4634 if (type == null) return null; 4644 if (type == null) return null;
4635 return _emitFunctionTypeArguments(type, instantiated); 4645 return _emitFunctionTypeArguments(type, instantiated);
4636 } 4646 }
4637 4647
4648 JS.LiteralString _emitDynamicOperationName(String name) =>
4649 js.string(options.replCompile ? '${name}Repl' : name);
4650
4638 JS.Expression _emitAccessInternal(Expression target, Element member, 4651 JS.Expression _emitAccessInternal(Expression target, Element member,
4639 String memberName, List<JS.Expression> typeArgs) { 4652 String memberName, List<JS.Expression> typeArgs) {
4640 bool isStatic = member is ClassMemberElement && member.isStatic; 4653 bool isStatic = member is ClassMemberElement && member.isStatic;
4641 var name = _emitMemberName(memberName, 4654 var name = _emitMemberName(memberName,
4642 type: getStaticType(target), isStatic: isStatic); 4655 type: getStaticType(target), isStatic: isStatic);
4643 if (isDynamicInvoke(target)) { 4656 if (isDynamicInvoke(target)) {
4644 if (_inWhitelistCode(target)) { 4657 if (_inWhitelistCode(target)) {
4645 var vars = <JS.MetaLetVariable, JS.Expression>{}; 4658 var vars = <JS.MetaLetVariable, JS.Expression>{};
4646 var l = _visit(_bindValue(vars, 'l', target)); 4659 var l = _visit(_bindValue(vars, 'l', target));
4647 return new JS.MetaLet(vars, [ 4660 return new JS.MetaLet(vars, [
4648 js.call('(#[dart._extensionType]) ? #[dartx[#]] : #.#', 4661 js.call('(#[dart._extensionType]) ? #[dartx[#]] : #.#',
4649 [l, l, name, l, name]) 4662 [l, l, name, l, name])
4650 ]); 4663 ]);
4651 } 4664 }
4652 return js.call('dart.dload(#, #)', [_visit(target), name]); 4665 return js.call('dart.#(#, #)',
4666 [_emitDynamicOperationName('dload'), _visit(target), name]);
4653 } 4667 }
4654 4668
4655 var jsTarget = _visit(target); 4669 var jsTarget = _visit(target);
4656 bool isSuper = jsTarget is JS.Super; 4670 bool isSuper = jsTarget is JS.Super;
4657 4671
4658 if (isSuper && member is FieldElement && !member.isSynthetic) { 4672 if (isSuper && member is FieldElement && !member.isSynthetic) {
4659 // If super.x is actually a field, then x is an instance property since 4673 // If super.x is actually a field, then x is an instance property since
4660 // subclasses cannot override x. 4674 // subclasses cannot override x.
4661 jsTarget = new JS.This(); 4675 jsTarget = new JS.This();
4662 } 4676 }
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
5496 } 5510 }
5497 5511
5498 bool isLibraryPrefix(Expression node) => 5512 bool isLibraryPrefix(Expression node) =>
5499 node is SimpleIdentifier && node.staticElement is PrefixElement; 5513 node is SimpleIdentifier && node.staticElement is PrefixElement;
5500 5514
5501 LibraryElement _getLibrary(AnalysisContext c, String uri) => 5515 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
5502 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 5516 c.computeLibraryElement(c.sourceFactory.forUri(uri));
5503 5517
5504 bool _isDartRuntime(LibraryElement l) => 5518 bool _isDartRuntime(LibraryElement l) =>
5505 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 5519 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | pkg/dev_compiler/lib/src/compiler/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698