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

Side by Side Diff: runtime/vm/ast_test.cc

Issue 1589643002: Source positions for constructors and lots of async machinery (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/ast_printer_test.cc ('k') | runtime/vm/ast_transformer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(Scanner::kNoSourcePos, 16 LocalVariable* v = new LocalVariable(Token::kNoSourcePos,
17 String::ZoneHandle(Symbols::New("v")), 17 String::ZoneHandle(Symbols::New("v")),
18 Type::ZoneHandle(Type::DynamicType())); 18 Type::ZoneHandle(Type::DynamicType()));
19 AstNode* ll = new LoadLocalNode(Scanner::kNoSourcePos, v); 19 AstNode* ll = new LoadLocalNode(Token::kNoSourcePos, v);
20 EXPECT(ll->IsLoadLocalNode()); 20 EXPECT(ll->IsLoadLocalNode());
21 EXPECT(!ll->IsLiteralNode()); 21 EXPECT(!ll->IsLiteralNode());
22 LoadLocalNode* lln = ll->AsLoadLocalNode(); 22 LoadLocalNode* lln = ll->AsLoadLocalNode();
23 EXPECT(NULL != lln); 23 EXPECT(NULL != lln);
24 v->set_index(1); 24 v->set_index(1);
25 EXPECT_EQ(1, v->index()); 25 EXPECT_EQ(1, v->index());
26 26
27 LocalVariable* p = new LocalVariable(Scanner::kNoSourcePos, 27 LocalVariable* p = new LocalVariable(Token::kNoSourcePos,
28 String::ZoneHandle(Symbols::New("p")), 28 String::ZoneHandle(Symbols::New("p")),
29 Type::ZoneHandle(Type::DynamicType())); 29 Type::ZoneHandle(Type::DynamicType()));
30 EXPECT(!p->HasIndex()); 30 EXPECT(!p->HasIndex());
31 p->set_index(-1); 31 p->set_index(-1);
32 EXPECT(p->HasIndex()); 32 EXPECT(p->HasIndex());
33 EXPECT_EQ(-1, p->index()); 33 EXPECT_EQ(-1, p->index());
34 34
35 ReturnNode* r = new ReturnNode(Scanner::kNoSourcePos, lln); 35 ReturnNode* r = new ReturnNode(Token::kNoSourcePos, lln);
36 EXPECT_EQ(lln, r->value()); 36 EXPECT_EQ(lln, r->value());
37 37
38 LiteralNode* l = 38 LiteralNode* l =
39 new LiteralNode(Scanner::kNoSourcePos, Smi::ZoneHandle(Smi::New(3))); 39 new LiteralNode(Token::kNoSourcePos, Smi::ZoneHandle(Smi::New(3)));
40 EXPECT(l->literal().IsSmi()); 40 EXPECT(l->literal().IsSmi());
41 EXPECT_EQ(Smi::New(3), l->literal().raw()); 41 EXPECT_EQ(Smi::New(3), l->literal().raw());
42 42
43 BinaryOpNode* b = 43 BinaryOpNode* b =
44 new BinaryOpNode(Scanner::kNoSourcePos, Token::kADD, l, lln); 44 new BinaryOpNode(Token::kNoSourcePos, Token::kADD, l, lln);
45 EXPECT_EQ(Token::kADD, b->kind()); 45 EXPECT_EQ(Token::kADD, b->kind());
46 EXPECT_EQ(l, b->left()); 46 EXPECT_EQ(l, b->left());
47 EXPECT_EQ(lln, b->right()); 47 EXPECT_EQ(lln, b->right());
48 48
49 UnaryOpNode* u = 49 UnaryOpNode* u =
50 new UnaryOpNode(Scanner::kNoSourcePos, Token::kNEGATE, b); 50 new UnaryOpNode(Token::kNoSourcePos, Token::kNEGATE, b);
51 EXPECT_EQ(Token::kNEGATE, u->kind()); 51 EXPECT_EQ(Token::kNEGATE, u->kind());
52 EXPECT_EQ(b, u->operand()); 52 EXPECT_EQ(b, u->operand());
53 53
54 SequenceNode* sequence_node = new SequenceNode(1, new LocalScope(NULL, 0, 0)); 54 SequenceNode* sequence_node = new SequenceNode(1, new LocalScope(NULL, 0, 0));
55 LiteralNode* literal_node = new LiteralNode(2, Smi::ZoneHandle(Smi::New(3))); 55 LiteralNode* literal_node = new LiteralNode(2, Smi::ZoneHandle(Smi::New(3)));
56 ReturnNode* return_node = new ReturnNode(3, literal_node); 56 ReturnNode* return_node = new ReturnNode(3, literal_node);
57 sequence_node->Add(return_node); 57 sequence_node->Add(return_node);
58 GrowableArray<AstNode*> nodes; 58 GrowableArray<AstNode*> nodes;
59 sequence_node->CollectAllNodes(&nodes); 59 sequence_node->CollectAllNodes(&nodes);
60 EXPECT_EQ(3, nodes.length()); 60 EXPECT_EQ(3, nodes.length());
61 } 61 }
62 62
63 } // namespace dart 63 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ast_printer_test.cc ('k') | runtime/vm/ast_transformer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698