| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/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 TEST_CASE(Ast) { | 15 TEST_CASE(Ast) { |
| 16 LocalVariable* v = new LocalVariable( | 16 LocalVariable* v = new LocalVariable( |
| 17 TokenPosition::kNoSource, | 17 TokenPosition::kNoSource, |
| 18 TokenPosition::kNoSource, |
| 18 String::ZoneHandle(Symbols::New(thread, "v")), | 19 String::ZoneHandle(Symbols::New(thread, "v")), |
| 19 Type::ZoneHandle(Type::DynamicType())); | 20 Type::ZoneHandle(Type::DynamicType())); |
| 20 AstNode* ll = new LoadLocalNode(TokenPosition::kNoSource, v); | 21 AstNode* ll = new LoadLocalNode(TokenPosition::kNoSource, v); |
| 21 EXPECT(ll->IsLoadLocalNode()); | 22 EXPECT(ll->IsLoadLocalNode()); |
| 22 EXPECT(!ll->IsLiteralNode()); | 23 EXPECT(!ll->IsLiteralNode()); |
| 23 LoadLocalNode* lln = ll->AsLoadLocalNode(); | 24 LoadLocalNode* lln = ll->AsLoadLocalNode(); |
| 24 EXPECT(NULL != lln); | 25 EXPECT(NULL != lln); |
| 25 v->set_index(1); | 26 v->set_index(1); |
| 26 EXPECT_EQ(1, v->index()); | 27 EXPECT_EQ(1, v->index()); |
| 27 | 28 |
| 28 LocalVariable* p = new LocalVariable( | 29 LocalVariable* p = new LocalVariable( |
| 29 TokenPosition::kNoSource, | 30 TokenPosition::kNoSource, |
| 31 TokenPosition::kNoSource, |
| 30 String::ZoneHandle(Symbols::New(thread, "p")), | 32 String::ZoneHandle(Symbols::New(thread, "p")), |
| 31 Type::ZoneHandle(Type::DynamicType())); | 33 Type::ZoneHandle(Type::DynamicType())); |
| 32 EXPECT(!p->HasIndex()); | 34 EXPECT(!p->HasIndex()); |
| 33 p->set_index(-1); | 35 p->set_index(-1); |
| 34 EXPECT(p->HasIndex()); | 36 EXPECT(p->HasIndex()); |
| 35 EXPECT_EQ(-1, p->index()); | 37 EXPECT_EQ(-1, p->index()); |
| 36 | 38 |
| 37 ReturnNode* r = new ReturnNode(TokenPosition::kNoSource, lln); | 39 ReturnNode* r = new ReturnNode(TokenPosition::kNoSource, lln); |
| 38 EXPECT_EQ(lln, r->value()); | 40 EXPECT_EQ(lln, r->value()); |
| 39 | 41 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 59 new LiteralNode(TokenPosition(2), Smi::ZoneHandle(Smi::New(3))); | 61 new LiteralNode(TokenPosition(2), Smi::ZoneHandle(Smi::New(3))); |
| 60 ReturnNode* return_node = | 62 ReturnNode* return_node = |
| 61 new ReturnNode(TokenPosition(3), literal_node); | 63 new ReturnNode(TokenPosition(3), literal_node); |
| 62 sequence_node->Add(return_node); | 64 sequence_node->Add(return_node); |
| 63 GrowableArray<AstNode*> nodes; | 65 GrowableArray<AstNode*> nodes; |
| 64 sequence_node->CollectAllNodes(&nodes); | 66 sequence_node->CollectAllNodes(&nodes); |
| 65 EXPECT_EQ(3, nodes.length()); | 67 EXPECT_EQ(3, nodes.length()); |
| 66 } | 68 } |
| 67 | 69 |
| 68 } // namespace dart | 70 } // namespace dart |
| OLD | NEW |