Index: runtime/vm/flow_graph_builder_test.cc |
diff --git a/runtime/vm/flow_graph_builder_test.cc b/runtime/vm/flow_graph_builder_test.cc |
index 91a13b250cb69dcdc5b28a35ffc294c97a3822b9..85e0ff9bfcf95024433d3e3dd9e31b80c32f5fa0 100644 |
--- a/runtime/vm/flow_graph_builder_test.cc |
+++ b/runtime/vm/flow_graph_builder_test.cc |
@@ -95,6 +95,26 @@ class SourcePositionTest : public ValueObject { |
DUMP_ASSERT(count > 0); |
} |
+ // Expect to find an instance call at |line| and |column|. |
+ void InstanceCallAt(intptr_t line, |
rmacnak
2016/01/14 00:28:08
Nit: the argument order here is different from Sta
Cutch
2016/01/14 15:25:10
Done.
|
+ intptr_t column, |
+ const char* needle) { |
+ ZoneGrowableArray<Instruction*>* instructions = |
+ FindInstructionsAt(line, column); |
+ intptr_t count = 0; |
+ for (intptr_t i = 0; i < instructions->length(); i++) { |
+ Instruction* instr = instructions->At(i); |
+ EXPECT(instr != NULL); |
+ if (instr->IsInstanceCall()) { |
+ const char* haystack = instr->ToCString(); |
+ if (strstr(haystack, needle) != NULL) { |
+ count++; |
+ } |
+ } |
+ } |
+ DUMP_ASSERT(count > 0); |
+ } |
+ |
// Expect to find at least one static call at |line| and |column|. The |
// static call will have |needle| in its |ToCString| representation. |
void StaticCallAt(const char* needle, |
@@ -146,6 +166,18 @@ class SourcePositionTest : public ValueObject { |
} |
} |
+ // Fails if any of the IR nodes has a token position of Scanner::kNoSourcePos. |
+ void EnsureSourcePositions() { |
+ for (intptr_t i = 0; i < blocks_->length(); i++) { |
+ BlockEntryInstr* entry = (*blocks_)[i]; |
+ DUMP_ASSERT(entry->token_pos() != Scanner::kNoSourcePos); |
+ for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
+ Instruction* instr = it.Current(); |
+ DUMP_ASSERT(instr->token_pos() != Scanner::kNoSourcePos); |
+ } |
+ } |
+ } |
+ |
private: |
void DumpInstruction(Instruction* instr) { |
const intptr_t token_pos = instr->token_pos(); |
@@ -267,6 +299,8 @@ TEST_CASE(SourcePosition_InstanceCalls) { |
spt.InstanceCallAt(4, 13, Token::kADD); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 3); |
spt.FuzzyInstructionMatchAt("Return", 5, 3); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -294,6 +328,8 @@ TEST_CASE(SourcePosition_If) { |
spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); |
spt.FuzzyInstructionMatchAt("Return", 7, 3); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -323,6 +359,8 @@ TEST_CASE(SourcePosition_ForLoop) { |
spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); |
spt.FuzzyInstructionMatchAt("Return", 7, 3); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -370,6 +408,8 @@ TEST_CASE(SourcePosition_While) { |
spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); |
spt.FuzzyInstructionMatchAt("Return", 10, 3); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -408,6 +448,8 @@ TEST_CASE(SourcePosition_WhileContinueBreak) { |
spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); |
spt.FuzzyInstructionMatchAt("Return", 10, 3); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -445,6 +487,8 @@ TEST_CASE(SourcePosition_LoadIndexed) { |
spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); |
spt.FuzzyInstructionMatchAt("Return", 6, 1); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -487,6 +531,8 @@ TEST_CASE(SourcePosition_StoreIndexed) { |
spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); |
spt.FuzzyInstructionMatchAt("Return", 6, 1); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -535,6 +581,8 @@ TEST_CASE(SourcePosition_BitwiseOperations) { |
spt.FuzzyInstructionMatchAt("LoadLocal(z", 9, 10); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 9, 3); |
spt.FuzzyInstructionMatchAt("Return", 9, 3); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -563,6 +611,8 @@ TEST_CASE(SourcePosition_IfElse) { |
spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 12); |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 5); |
spt.FuzzyInstructionMatchAt("Return", 7, 5); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -607,6 +657,8 @@ TEST_CASE(SourcePosition_Switch) { |
spt.FuzzyInstructionMatchAt("Constant(#5", 7, 21); // '5' |
spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 14); |
spt.FuzzyInstructionMatchAt("Return", 7, 14); |
+ |
+ spt.EnsureSourcePositions(); |
} |
@@ -657,6 +709,58 @@ TEST_CASE(SourcePosition_TryCatchFinally) { |
spt.FuzzyInstructionMatchAt("Constant(#99", 10, 12); // '9' |
spt.FuzzyInstructionMatchAt("Return", 10, 5); // 'r' |
+ |
+ spt.EnsureSourcePositions(); |
+} |
+ |
+ |
+TEST_CASE(SourcePosition_InstanceFields) { |
+ const char* kScript = |
+ "class A {" |
rmacnak
2016/01/14 00:28:08
missing new line...
Cutch
2016/01/14 15:25:10
Done.
|
+ " var x;\n" |
+ " var y;\n" |
+ "}\n" |
+ "main() {\n" |
+ " var z = new A();\n" |
+ " z.x = 99;\n" |
+ " z.y = z.x;\n" |
+ " return z.y;\n" |
+ "}\n"; |
+ |
+ SourcePositionTest spt(thread, kScript); |
+ spt.BuildGraphFor("main"); |
+ spt.FuzzyInstructionMatchAt("AllocateObject(A)", 5, 15); // 'A' |
rmacnak
2016/01/14 00:28:08
...Making these lines short by 1.
Cutch
2016/01/14 15:25:10
Done.
|
+ spt.FuzzyInstructionMatchAt("StaticCall", 5, 15); // 'A' |
+ spt.FuzzyInstructionMatchAt("StoreLocal(z", 5, 9); // '=' |
+ spt.InstanceCallAt(6, 5, "set:x"); // 'x' |
+ spt.InstanceCallAt(7, 11, "get:x"); // 'x' |
+ spt.InstanceCallAt(7, 5, "set:y"); // 'y' |
+ |
+ spt.InstanceCallAt(8, 12, "get:y"); // 'y' |
+ spt.FuzzyInstructionMatchAt("DebugStepCheck", 8, 3); |
+ spt.FuzzyInstructionMatchAt("Return", 8, 3); |
+ |
+ spt.EnsureSourcePositions(); |
+} |
+ |
+ |
+TEST_CASE(SourcePosition_Await) { |
+ const char* kScript = |
+ "import 'dart:async';\n" |
+ "var x = 5;\n" |
+ "var y = 5;\n" |
+ "foo(Future f1, Future f2) async {\n" |
+ " await f1;\n" |
+ " await f2;\n" |
+ " return 55;\n" |
+ "}\n" |
+ "main() {\n" |
+ " foo(new Future.value(33));\n" |
+ "}\n"; |
+ |
+ SourcePositionTest spt(thread, kScript); |
+ spt.BuildGraphFor("foo"); |
rmacnak
2016/01/14 00:28:08
This doesn't actually test 'await'. All that trans
Cutch
2016/01/14 15:25:10
Correct, I've renamed this to be SourcePosition_As
|
+ spt.EnsureSourcePositions(); |
} |
} // namespace dart |