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

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

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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.cc » ('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( 16 LocalVariable* v =
17 TokenPosition::kNoSource, 17 new LocalVariable(TokenPosition::kNoSource, 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()));
21 AstNode* ll = new LoadLocalNode(TokenPosition::kNoSource, v); 20 AstNode* ll = new LoadLocalNode(TokenPosition::kNoSource, v);
22 EXPECT(ll->IsLoadLocalNode()); 21 EXPECT(ll->IsLoadLocalNode());
23 EXPECT(!ll->IsLiteralNode()); 22 EXPECT(!ll->IsLiteralNode());
24 LoadLocalNode* lln = ll->AsLoadLocalNode(); 23 LoadLocalNode* lln = ll->AsLoadLocalNode();
25 EXPECT(NULL != lln); 24 EXPECT(NULL != lln);
26 v->set_index(1); 25 v->set_index(1);
27 EXPECT_EQ(1, v->index()); 26 EXPECT_EQ(1, v->index());
28 27
29 LocalVariable* p = new LocalVariable( 28 LocalVariable* p =
30 TokenPosition::kNoSource, 29 new LocalVariable(TokenPosition::kNoSource, 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()));
34 EXPECT(!p->HasIndex()); 32 EXPECT(!p->HasIndex());
35 p->set_index(-1); 33 p->set_index(-1);
36 EXPECT(p->HasIndex()); 34 EXPECT(p->HasIndex());
37 EXPECT_EQ(-1, p->index()); 35 EXPECT_EQ(-1, p->index());
38 36
39 ReturnNode* r = new ReturnNode(TokenPosition::kNoSource, lln); 37 ReturnNode* r = new ReturnNode(TokenPosition::kNoSource, lln);
40 EXPECT_EQ(lln, r->value()); 38 EXPECT_EQ(lln, r->value());
41 39
42 LiteralNode* l = new LiteralNode(TokenPosition::kNoSource, 40 LiteralNode* l =
43 Smi::ZoneHandle(Smi::New(3))); 41 new LiteralNode(TokenPosition::kNoSource, Smi::ZoneHandle(Smi::New(3)));
44 EXPECT(l->literal().IsSmi()); 42 EXPECT(l->literal().IsSmi());
45 EXPECT_EQ(Smi::New(3), l->literal().raw()); 43 EXPECT_EQ(Smi::New(3), l->literal().raw());
46 44
47 BinaryOpNode* b = 45 BinaryOpNode* b =
48 new BinaryOpNode(TokenPosition::kNoSource, Token::kADD, l, lln); 46 new BinaryOpNode(TokenPosition::kNoSource, Token::kADD, l, lln);
49 EXPECT_EQ(Token::kADD, b->kind()); 47 EXPECT_EQ(Token::kADD, b->kind());
50 EXPECT_EQ(l, b->left()); 48 EXPECT_EQ(l, b->left());
51 EXPECT_EQ(lln, b->right()); 49 EXPECT_EQ(lln, b->right());
52 50
53 UnaryOpNode* u = 51 UnaryOpNode* u = new UnaryOpNode(TokenPosition::kNoSource, Token::kNEGATE, b);
54 new UnaryOpNode(TokenPosition::kNoSource, Token::kNEGATE, b);
55 EXPECT_EQ(Token::kNEGATE, u->kind()); 52 EXPECT_EQ(Token::kNEGATE, u->kind());
56 EXPECT_EQ(b, u->operand()); 53 EXPECT_EQ(b, u->operand());
57 54
58 SequenceNode* sequence_node = 55 SequenceNode* sequence_node =
59 new SequenceNode(TokenPosition(1), new LocalScope(NULL, 0, 0)); 56 new SequenceNode(TokenPosition(1), new LocalScope(NULL, 0, 0));
60 LiteralNode* literal_node = 57 LiteralNode* literal_node =
61 new LiteralNode(TokenPosition(2), Smi::ZoneHandle(Smi::New(3))); 58 new LiteralNode(TokenPosition(2), Smi::ZoneHandle(Smi::New(3)));
62 ReturnNode* return_node = 59 ReturnNode* return_node = new ReturnNode(TokenPosition(3), literal_node);
63 new ReturnNode(TokenPosition(3), literal_node);
64 sequence_node->Add(return_node); 60 sequence_node->Add(return_node);
65 GrowableArray<AstNode*> nodes; 61 GrowableArray<AstNode*> nodes;
66 sequence_node->CollectAllNodes(&nodes); 62 sequence_node->CollectAllNodes(&nodes);
67 EXPECT_EQ(3, nodes.length()); 63 EXPECT_EQ(3, nodes.length());
68 } 64 }
69 65
70 } // namespace dart 66 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ast_printer_test.cc ('k') | runtime/vm/ast_transformer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698