OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/assert.h" | 5 #include "vm/assert.h" |
6 #include "vm/ast.h" | 6 #include "vm/ast.h" |
7 #include "vm/heap.h" | 7 #include "vm/heap.h" |
8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
11 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 static const intptr_t kPos = 1; // Dummy token index in non-existing source. | 15 static const intptr_t kPos = 1; // Dummy token index in non-existing source. |
16 | 16 |
17 | 17 |
18 TEST_CASE(Ast) { | 18 TEST_CASE(Ast) { |
19 const intptr_t kPos = 1; // Dummy token index in non-existing source. | 19 const intptr_t kPos = 1; // Dummy token index in non-existing source. |
20 LocalVariable* v = new LocalVariable(kPos, | 20 LocalVariable* v = new LocalVariable(kPos, |
21 String::ZoneHandle(String::New("v")), | 21 String::ZoneHandle(String::New("v")), |
22 Type::ZoneHandle(Type::VarType())); | 22 Type::ZoneHandle(Type::DynamicType())); |
23 AstNode* ll = new LoadLocalNode(kPos, *v); | 23 AstNode* ll = new LoadLocalNode(kPos, *v); |
24 EXPECT(ll->IsLoadLocalNode()); | 24 EXPECT(ll->IsLoadLocalNode()); |
25 EXPECT(!ll->IsLiteralNode()); | 25 EXPECT(!ll->IsLiteralNode()); |
26 LoadLocalNode* lln = ll->AsLoadLocalNode(); | 26 LoadLocalNode* lln = ll->AsLoadLocalNode(); |
27 EXPECT(NULL != lln); | 27 EXPECT(NULL != lln); |
28 v->set_index(1); | 28 v->set_index(1); |
29 EXPECT_EQ(1, v->index()); | 29 EXPECT_EQ(1, v->index()); |
30 | 30 |
31 LocalVariable* p = new LocalVariable(kPos, | 31 LocalVariable* p = new LocalVariable(kPos, |
32 String::ZoneHandle(String::New("p")), | 32 String::ZoneHandle(String::New("p")), |
33 Type::ZoneHandle(Type::VarType())); | 33 Type::ZoneHandle(Type::DynamicType())); |
34 EXPECT(!p->HasIndex()); | 34 EXPECT(!p->HasIndex()); |
35 p->set_index(-1); | 35 p->set_index(-1); |
36 EXPECT(p->HasIndex()); | 36 EXPECT(p->HasIndex()); |
37 EXPECT_EQ(-1, p->index()); | 37 EXPECT_EQ(-1, p->index()); |
38 | 38 |
39 ReturnNode* r = new ReturnNode(kPos, lln); | 39 ReturnNode* r = new ReturnNode(kPos, lln); |
40 EXPECT_EQ(lln, r->value()); | 40 EXPECT_EQ(lln, r->value()); |
41 | 41 |
42 LiteralNode* l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))); | 42 LiteralNode* l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))); |
43 EXPECT(l->literal().IsSmi()); | 43 EXPECT(l->literal().IsSmi()); |
(...skipping 11 matching lines...) Expand all Loading... |
55 SequenceNode* sequence_node = new SequenceNode(1, new LocalScope(NULL, 0, 0)); | 55 SequenceNode* sequence_node = new SequenceNode(1, new LocalScope(NULL, 0, 0)); |
56 LiteralNode* literal_node = new LiteralNode(2, Smi::ZoneHandle(Smi::New(3))); | 56 LiteralNode* literal_node = new LiteralNode(2, Smi::ZoneHandle(Smi::New(3))); |
57 ReturnNode* return_node = new ReturnNode(3, literal_node); | 57 ReturnNode* return_node = new ReturnNode(3, literal_node); |
58 sequence_node->Add(return_node); | 58 sequence_node->Add(return_node); |
59 GrowableArray<AstNode*> nodes; | 59 GrowableArray<AstNode*> nodes; |
60 sequence_node->CollectAllNodes(&nodes); | 60 sequence_node->CollectAllNodes(&nodes); |
61 EXPECT_EQ(3, nodes.length()); | 61 EXPECT_EQ(3, nodes.length()); |
62 } | 62 } |
63 | 63 |
64 } // namespace dart | 64 } // namespace dart |
OLD | NEW |