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

Unified Diff: pkg/compiler/lib/src/kernel/element_map_impl.dart

Issue 2939033002: Towards compiling Hello World! (Closed)
Patch Set: Created 3 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
Index: pkg/compiler/lib/src/kernel/element_map_impl.dart
diff --git a/pkg/compiler/lib/src/kernel/element_map_impl.dart b/pkg/compiler/lib/src/kernel/element_map_impl.dart
index 07dc4f65c4e3c48fb953cc2124373149a4c6e76e..61bc31bf1be3c41c65f55ed370eb7f40854074ec 100644
--- a/pkg/compiler/lib/src/kernel/element_map_impl.dart
+++ b/pkg/compiler/lib/src/kernel/element_map_impl.dart
@@ -141,6 +141,7 @@ class KernelToElementMapImpl extends KernelToElementMapMixin {
@override
ConstantValue getFieldConstantValue(ir.Field field) {
+ // TODO(johnniwinther): Cache the result in [_FieldData].
return getConstantValue(field.initializer, requireConstant: field.isConst);
}
@@ -673,12 +674,23 @@ class KernelToElementMapImpl extends KernelToElementMapMixin {
@override
FieldEntity getField(ir.Field node) => _getField(node);
+ bool hasConstantFieldInitializer(KField field) {
+ _FieldData data = _memberList[field.memberIndex];
+ return getFieldConstantValue(data.node) != null;
+ }
+
TypeVariableEntity getTypeVariable(ir.TypeParameter node) =>
_getTypeVariable(node);
@override
FunctionEntity getMethod(ir.Procedure node) => _getMethod(node);
+ void forEachParameter(KFunction function,
+ void f(DartType type, String name, ConstantValue defaultValue)) {
+ _FunctionData data = _memberList[function.memberIndex];
+ data.forEachParameter(this, f);
+ }
+
@override
MemberEntity getMember(ir.Member node) {
if (node is ir.Field) {
@@ -1066,6 +1078,29 @@ class _FunctionData extends _MemberData {
FunctionType getFunctionType(KernelToElementMapImpl elementMap) {
return _type ??= elementMap.getFunctionType(functionNode);
}
+
+ void forEachParameter(KernelToElementMap elementMap,
+ void f(DartType type, String name, ConstantValue defaultValue)) {
+ void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) {
+ DartType type = elementMap.getDartType(node.type);
+ String name = node.name;
+ ConstantValue defaultValue;
+ if (isOptional) {
+ if (node.initializer != null) {
+ defaultValue = elementMap.getConstantValue(node.initializer);
+ } else {
+ defaultValue = new NullConstantValue();
+ }
+ }
+ f(type, name, defaultValue);
+ }
+
+ for (int i = 0; i < functionNode.positionalParameters.length; i++) {
+ handleParameter(functionNode.positionalParameters[i],
+ isOptional: i < functionNode.requiredParameterCount);
+ }
+ functionNode.namedParameters.forEach(handleParameter);
+ }
}
class _ConstructorData extends _FunctionData {

Powered by Google App Engine
This is Rietveld 408576698