Handle getters/setters and try in kernel_impact.

R=het@google.com

Review URL: https://codereview.chromium.org/2375613003 .
This commit is contained in:
Johnni Winther 2016-09-30 10:03:01 +02:00
parent ee42a0524a
commit 3fb04e3495
2 changed files with 66 additions and 5 deletions

View file

@ -29,7 +29,7 @@ ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) {
Kernel kernel = backend.kernelTask.kernel;
KernelImpactBuilder builder =
new KernelImpactBuilder(resolvedAst, compiler, kernel);
if (element.isFunction) {
if (element.isFunction || element.isGetter || element.isSetter) {
ir.Procedure function = kernel.functions[element];
if (function == null) {
print("FOUND NULL FUNCTION: $element");
@ -39,7 +39,7 @@ ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) {
} else {
ir.Field field = kernel.fields[element];
if (field == null) {
print("FOUND NULL FUNCTION: $element");
print("FOUND NULL FIELD: $element");
} else {
return builder.buildField(field);
}
@ -93,8 +93,7 @@ class KernelImpactBuilder extends ir.Visitor {
}
ResolutionImpact buildProcedure(ir.Procedure procedure) {
if (procedure.kind == ir.ProcedureKind.Method ||
procedure.kind == ir.ProcedureKind.Operator) {
if (procedure.kind != ir.ProcedureKind.Factory) {
checkFunctionTypes(procedure.function);
visitNode(procedure.function.body);
switch (procedure.function.asyncMarker) {
@ -279,6 +278,13 @@ class KernelImpactBuilder extends ir.Visitor {
}
}
@override
void visitStaticSet(ir.StaticSet node) {
visitNode(node.value);
Element element = astAdapter.getElement(node.target).declaration;
impactBuilder.registerStaticUse(new StaticUse.staticSet(element));
}
@override
void visitMethodInvocation(ir.MethodInvocation invocation) {
var receiver = invocation.receiver;
@ -384,6 +390,32 @@ class KernelImpactBuilder extends ir.Visitor {
impactBuilder.registerDynamicUse(new DynamicUse(Selectors.moveNext, null));
}
@override
void visitTryCatch(ir.TryCatch node) {
visitNode(node.body);
visitNodes(node.catches);
}
@override
void visitCatch(ir.Catch node) {
impactBuilder.registerFeature(Feature.CATCH_STATEMENT);
visitNode(node.exception);
if (node.stackTrace != null) {
impactBuilder.registerFeature(Feature.STACK_TRACE_IN_CATCH);
}
if (node.guard is! ir.DynamicType) {
impactBuilder.registerTypeUse(
new TypeUse.catchType(astAdapter.getDartType(node.guard)));
}
visitNode(node.body);
}
@override
void visitTryFinally(ir.TryFinally node) {
visitNode(node.body);
visitNode(node.finalizer);
}
// TODO(johnniwinther): Make this throw and visit child nodes explicitly
// instead to ensure that we don't visit unwanted parts of the ir.
@override

View file

@ -76,10 +76,18 @@ main() {
testForInTyped(null);
testAsyncForIn(null);
testAsyncForInTyped(null);
testTryCatch();
testTryCatchOn();
testTryCatchStackTrace();
testTryFinally();
testTopLevelInvoke();
testTopLevelInvokeTyped();
testTopLevelFunctionTyped();
testTopLevelFunctionGet();
testTopLevelGetterGet();
testTopLevelGetterGetTyped();
testTopLevelSetterSet();
testTopLevelSetterSetTyped();
testTopLevelField();
testTopLevelFieldLazy();
testTopLevelFieldConst();
@ -88,6 +96,7 @@ main() {
testTopLevelFieldGeneric1();
testTopLevelFieldGeneric2();
testTopLevelFieldGeneric3();
testTopLevelFieldWrite();
testDynamicInvoke(null);
testDynamicGet(null);
testDynamicSet(null);
@ -189,6 +198,18 @@ testAsyncForIn(o) async {
testAsyncForInTyped(o) async {
await for (int e in o) {}
}
testTryCatch() {
try {} catch (e) {}
}
testTryCatchOn() {
try {} on String catch (e) {}
}
testTryCatchStackTrace() {
try {} catch (e, s) {}
}
testTryFinally() {
try {} finally {}
}
topLevelFunction1(a) {}
topLevelFunction2(a, [b, c]) {}
topLevelFunction3(a, {b, c}) {}
@ -231,6 +252,14 @@ testTopLevelFunctionTyped() {
topLevelFunctionTyped4(null);
}
testTopLevelFunctionGet() => topLevelFunction1;
get topLevelGetter => 0;
testTopLevelGetterGet() => topLevelGetter;
int get topLevelGetterTyped => 0;
testTopLevelGetterGetTyped() => topLevelGetterTyped;
set topLevelSetter(_) {}
testTopLevelSetterSet() => topLevelSetter = 0;
void set topLevelSetterTyped(int value) {}
testTopLevelSetterSetTyped() => topLevelSetterTyped = 0;
var topLevelField;
testTopLevelField() => topLevelField;
@ -248,7 +277,7 @@ GenericClass<dynamic, dynamic> topLevelFieldGeneric2;
testTopLevelFieldGeneric2() => topLevelFieldGeneric2;
GenericClass<int, String> topLevelFieldGeneric3;
testTopLevelFieldGeneric3() => topLevelFieldGeneric3;
testTopLevelFieldWrite() => topLevelField = 3;
testDynamicInvoke(o) {
o.f1(0);
o.f2(1);