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

Unified Diff: lib/src/compiler/code_generator.dart

Issue 2061373003: implement user-defined nSM, Object members on functions (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix comment Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | lib/src/compiler/side_effect_analysis.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index d0bdf2043190b9a91a642c7f84ea0751b1be688b..51b7fe5ca628002ef2d74ce10ed2a1f21489289f 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -255,6 +255,10 @@ class CodeGenerator extends GeneralizingAstVisitor
_collectElements(unit, nodes);
}
_loader = new ElementLoader(nodes);
+ if (compilationUnits.isNotEmpty) {
+ _constField = new ConstFieldVisitor(types,
+ dummySource: compilationUnits.first.element.source);
+ }
// Add implicit dart:core dependency so it is first.
emitLibraryName(dartCoreLibrary);
@@ -267,7 +271,7 @@ class CodeGenerator extends GeneralizingAstVisitor
// NOTE: declarations are not necessarily emitted in this order.
// Order will be changed as needed so the resulting code can execute.
// This is done by forward declaring items.
- compilationUnits.forEach(visitCompilationUnit);
+ compilationUnits.forEach(_finishDeclarationsInUnit);
// Declare imports
_finishImports(items);
@@ -439,10 +443,12 @@ class CodeGenerator extends GeneralizingAstVisitor
_loader.declareBeforeUse(e, _emitDeclaration);
}
- @override
- void visitCompilationUnit(CompilationUnit unit) {
- _constField = new ConstFieldVisitor(types, unit.element.source);
-
+ void _finishDeclarationsInUnit(CompilationUnit unit) {
+ // NOTE: this method isn't the right place to initialize
+ // per-compilation-unit state. Declarations can be visited out of order,
+ // this is only to catch things that haven't been emitted yet.
+ //
+ // See _emitDeclaration.
for (var declaration in unit.declarations) {
var element = declaration.element;
if (element != null) {
@@ -4242,11 +4248,23 @@ class CodeGenerator extends GeneralizingAstVisitor
// Check if the target could be `null`, is dynamic, or may be an extension
// native type. In all of those cases we need defensive code generation.
var type = getStaticType(target);
+
return isNullable(target) ||
+ _targetIsFunction(target) ||
type.isDynamic ||
(_extensionTypes.hasNativeSubtype(type) && target is! SuperExpression);
}
+ bool _targetIsFunction(Expression expr) {
+ Element element = null;
+ if (expr is PropertyAccess) {
vsm 2016/06/16 23:41:13 Is this sufficient? I.e., what about FunctionExpr
Jennifer Messerly 2016/06/16 23:44:14 I think those should be handled by isNullable (I s
+ element = expr.propertyName.staticElement;
+ } else if (expr is Identifier) {
+ element = expr.staticElement;
+ }
+ return element is FunctionElement || element is MethodElement;
+ }
+
/// Shared code for [PrefixedIdentifier] and [PropertyAccess].
JS.Expression _emitAccess(
Expression target, SimpleIdentifier memberId, DartType resultType) {
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | lib/src/compiler/side_effect_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698