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

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

Issue 2503803004: fix #27784 and fix #27785, fromEnvironment constants in DDC (Closed)
Patch Set: allow trailing opts Created 4 years, 1 month 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
Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
index 89bbabc1d0c553611a3a8f21e5adf1839c99bf85..61289f56551347d76246385dcbbce17d2053c1b1 100644
--- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
+++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
@@ -125,7 +125,7 @@ class CodeGenerator extends GeneralizingAstVisitor
final ClassElement objectClass;
final ClassElement stringClass;
- ConstFieldVisitor _constField;
+ ConstFieldVisitor _constants;
/// The current function body being compiled.
FunctionBody _currentFunction;
@@ -276,7 +276,7 @@ class CodeGenerator extends GeneralizingAstVisitor
}
_loader = new ElementLoader(nodes);
if (compilationUnits.isNotEmpty) {
- _constField = new ConstFieldVisitor(types,
+ _constants = new ConstFieldVisitor(context,
dummySource: compilationUnits.first.element.source);
}
@@ -2120,7 +2120,7 @@ class CodeGenerator extends GeneralizingAstVisitor
for (var declaration in fieldDecls) {
for (var fieldNode in declaration.fields.variables) {
var element = fieldNode.element;
- if (_constField.isFieldInitConstant(fieldNode)) {
+ if (_constants.isFieldInitConstant(fieldNode)) {
unsetFields[element as FieldElement] = fieldNode;
} else {
fields[element as FieldElement] = _visitInitializer(fieldNode);
@@ -3767,7 +3767,7 @@ class CodeGenerator extends GeneralizingAstVisitor
bool isLoaded = _loader.finishCheckingReferences();
bool eagerInit =
- isLoaded && (field.isConst || _constField.isFieldInitConstant(field));
+ isLoaded && (field.isConst || _constants.isFieldInitConstant(field));
var fieldName = field.name.name;
if (eagerInit &&
@@ -3796,7 +3796,7 @@ class CodeGenerator extends GeneralizingAstVisitor
bool eagerInit;
JS.Expression jsInit;
- if (field.isConst || _constField.isFieldInitConstant(field)) {
+ if (field.isConst || _constants.isFieldInitConstant(field)) {
// If the field is constant, try and generate it at the top level.
_loader.startTopLevel(element);
jsInit = _visitInitializer(field);
@@ -3961,6 +3961,35 @@ class CodeGenerator extends GeneralizingAstVisitor
var constructor = node.constructorName;
var name = constructor.name;
var type = constructor.type.type;
+ if (node.isConst &&
+ element?.name == 'fromEnvironment' &&
+ element.library.isDartCore) {
+ var value = node.accept(_constants.constantVisitor);
+
+ if (value == null || value.isNull) {
+ return new JS.LiteralNull();
+ }
+ if (value.isUnknown) {
+ return type == types.boolType
+ ? js.boolean(false)
vsm 2016/11/16 19:16:22 Can you add a comment explaining this case? When
Jennifer Messerly 2016/11/16 20:11:48 Sure, as best as I can. Unfortunately behavior of
+ : new JS.LiteralNull();
+ }
+ if (value.type == types.boolType) {
+ var boolValue = value.toBoolValue();
+ return boolValue != null ? js.boolean(boolValue) : new JS.LiteralNull();
+ }
+ if (value.type == types.intType) {
+ var intValue = value.toIntValue();
+ return intValue != null ? js.number(intValue) : new JS.LiteralNull();
+ }
+ if (value.type == types.stringType) {
+ var stringValue = value.toStringValue();
+ return stringValue != null
+ ? js.escapedString(stringValue)
+ : new JS.LiteralNull();
+ }
+ throw new StateError('failed to evaluate $node');
+ }
return _emitInstanceCreationExpression(
element, type, name, node.argumentList, node.isConst);
}

Powered by Google App Engine
This is Rietveld 408576698