| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/compiler.h" | 5 #include "vm/compiler.h" |
| 6 #include "vm/dart_api_impl.h" | 6 #include "vm/dart_api_impl.h" |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 for (intptr_t i = 0; i < blocks_->length(); i++) { | 159 for (intptr_t i = 0; i < blocks_->length(); i++) { |
| 160 BlockEntryInstr* entry = (*blocks_)[i]; | 160 BlockEntryInstr* entry = (*blocks_)[i]; |
| 161 THR_Print("B%" Pd ":\n", entry->block_id()); | 161 THR_Print("B%" Pd ":\n", entry->block_id()); |
| 162 DumpInstruction(entry); | 162 DumpInstruction(entry); |
| 163 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 163 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 164 DumpInstruction(it.Current()); | 164 DumpInstruction(it.Current()); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Fails if any of the IR nodes has a token position of Token::kNoSourcePos. | 169 // Fails if any of the IR nodes has a token position of |
| 170 // TokenDescriptor::kNoSourcePos. |
| 170 void EnsureSourcePositions() { | 171 void EnsureSourcePositions() { |
| 171 for (intptr_t i = 0; i < blocks_->length(); i++) { | 172 for (intptr_t i = 0; i < blocks_->length(); i++) { |
| 172 BlockEntryInstr* entry = (*blocks_)[i]; | 173 BlockEntryInstr* entry = (*blocks_)[i]; |
| 173 DUMP_ASSERT(entry->token_pos() != Token::kNoSourcePos); | 174 DUMP_ASSERT(entry->token_pos() != TokenDescriptor::kNoSource); |
| 174 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 175 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 175 Instruction* instr = it.Current(); | 176 Instruction* instr = it.Current(); |
| 176 DUMP_ASSERT(instr->token_pos() != Token::kNoSourcePos); | 177 DUMP_ASSERT(instr->token_pos() != TokenDescriptor::kNoSource); |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 | 181 |
| 181 private: | 182 private: |
| 182 void DumpInstruction(Instruction* instr) { | 183 void DumpInstruction(Instruction* instr) { |
| 183 intptr_t token_pos = instr->token_pos(); | 184 TokenDescriptor token_pos = instr->token_pos(); |
| 184 bool synthetic = false; | 185 bool synthetic = false; |
| 185 if (Token::IsSynthetic(token_pos)) { | 186 if (token_pos.IsSynthetic()) { |
| 186 synthetic = true; | 187 synthetic = true; |
| 187 token_pos = Token::FromSynthetic(token_pos); | 188 token_pos = TokenDescriptor::FromSynthetic(token_pos); |
| 188 } | 189 } |
| 189 if (token_pos < 0) { | 190 if (token_pos.IsClassifying()) { |
| 190 const char* token_pos_string = | 191 const char* token_pos_string = token_pos.ToCString(); |
| 191 ClassifyingTokenPositions::ToCString(token_pos); | |
| 192 THR_Print("%12s -- %s\n", token_pos_string, instr->ToCString()); | 192 THR_Print("%12s -- %s\n", token_pos_string, instr->ToCString()); |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 intptr_t token_line = -1; | 195 intptr_t token_line = -1; |
| 196 intptr_t token_column = -1; | 196 intptr_t token_column = -1; |
| 197 root_script_.GetTokenLocation(token_pos, | 197 root_script_.GetTokenLocation(token_pos, |
| 198 &token_line, | 198 &token_line, |
| 199 &token_column, | 199 &token_column, |
| 200 NULL); | 200 NULL); |
| 201 if (synthetic) { | 201 if (synthetic) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 221 } | 221 } |
| 222 | 222 |
| 223 ZoneGrowableArray<Instruction*>* FindInstructionsAt( | 223 ZoneGrowableArray<Instruction*>* FindInstructionsAt( |
| 224 intptr_t line, intptr_t column) { | 224 intptr_t line, intptr_t column) { |
| 225 ZoneGrowableArray<Instruction*>* instructions = | 225 ZoneGrowableArray<Instruction*>* instructions = |
| 226 new ZoneGrowableArray<Instruction*>(); | 226 new ZoneGrowableArray<Instruction*>(); |
| 227 for (intptr_t i = 0; i < blocks_->length(); i++) { | 227 for (intptr_t i = 0; i < blocks_->length(); i++) { |
| 228 BlockEntryInstr* entry = (*blocks_)[i]; | 228 BlockEntryInstr* entry = (*blocks_)[i]; |
| 229 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 229 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 230 Instruction* instr = it.Current(); | 230 Instruction* instr = it.Current(); |
| 231 intptr_t token_pos = instr->token_pos(); | 231 TokenDescriptor token_pos = instr->token_pos(); |
| 232 if (Token::IsSynthetic(token_pos)) { | 232 if (token_pos.IsSynthetic()) { |
| 233 token_pos = Token::FromSynthetic(token_pos); | 233 token_pos = TokenDescriptor::FromSynthetic(token_pos); |
| 234 } | 234 } |
| 235 if (token_pos < 0) { | 235 if (!token_pos.IsReal()) { |
| 236 continue; | 236 continue; |
| 237 } | 237 } |
| 238 intptr_t token_line = -1; | 238 intptr_t token_line = -1; |
| 239 intptr_t token_column = -1; | 239 intptr_t token_column = -1; |
| 240 root_script_.GetTokenLocation(token_pos, | 240 root_script_.GetTokenLocation(token_pos, |
| 241 &token_line, | 241 &token_line, |
| 242 &token_column, | 242 &token_column, |
| 243 NULL); | 243 NULL); |
| 244 if (token_line == line) { | 244 if (token_line == line) { |
| 245 if ((column < 0) || (column == token_column)) { | 245 if ((column < 0) || (column == token_column)) { |
| 246 instructions->Add(instr); | 246 instructions->Add(instr); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 return instructions; | 251 return instructions; |
| 252 } | 252 } |
| 253 | 253 |
| 254 ZoneGrowableArray<Instruction*>* FindInstructionsAt(intptr_t token_pos) { | 254 ZoneGrowableArray<Instruction*>* FindInstructionsAt(intptr_t token_pos) { |
| 255 ZoneGrowableArray<Instruction*>* instructions = | 255 ZoneGrowableArray<Instruction*>* instructions = |
| 256 new ZoneGrowableArray<Instruction*>(); | 256 new ZoneGrowableArray<Instruction*>(); |
| 257 for (intptr_t i = 0; i < blocks_->length(); i++) { | 257 for (intptr_t i = 0; i < blocks_->length(); i++) { |
| 258 BlockEntryInstr* entry = (*blocks_)[i]; | 258 BlockEntryInstr* entry = (*blocks_)[i]; |
| 259 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 259 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 260 Instruction* instr = it.Current(); | 260 Instruction* instr = it.Current(); |
| 261 if (instr->token_pos() == token_pos) { | 261 if (instr->token_pos().value() == token_pos) { |
| 262 instructions->Add(instr); | 262 instructions->Add(instr); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 return instructions; | 266 return instructions; |
| 267 } | 267 } |
| 268 | 268 |
| 269 RawFunction* GetFunction(const Library& lib, const char* name) { | 269 RawFunction* GetFunction(const Library& lib, const char* name) { |
| 270 const Function& result = Function::Handle(lib.LookupFunctionAllowPrivate( | 270 const Function& result = Function::Handle(lib.LookupFunctionAllowPrivate( |
| 271 String::Handle(String::New(name)))); | 271 String::Handle(String::New(name)))); |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 " foo(new Future.value(33));\n" | 773 " foo(new Future.value(33));\n" |
| 774 "}\n"; | 774 "}\n"; |
| 775 | 775 |
| 776 SourcePositionTest spt(thread, kScript); | 776 SourcePositionTest spt(thread, kScript); |
| 777 spt.BuildGraphFor("foo"); | 777 spt.BuildGraphFor("foo"); |
| 778 spt.EnsureSourcePositions(); | 778 spt.EnsureSourcePositions(); |
| 779 spt.Dump(); | 779 spt.Dump(); |
| 780 } | 780 } |
| 781 | 781 |
| 782 | 782 |
| 783 static bool SyntheticRoundTripTest(intptr_t token_pos) { | 783 static bool SyntheticRoundTripTest(TokenDescriptor token_pos) { |
| 784 return Token::FromSynthetic(Token::ToSynthetic(token_pos)) == token_pos; | 784 const TokenDescriptor synthetic_token_pos = |
| 785 TokenDescriptor::ToSynthetic(token_pos); |
| 786 return TokenDescriptor::FromSynthetic(synthetic_token_pos) == token_pos; |
| 785 } | 787 } |
| 786 | 788 |
| 787 | 789 |
| 788 UNIT_TEST_CASE(SourcePosition_SyntheticTokens) { | 790 UNIT_TEST_CASE(SourcePosition_SyntheticTokens) { |
| 789 EXPECT(Token::kNoSourcePos == -1); | 791 EXPECT(TokenDescriptor::kNoSourcePos == -1); |
| 790 EXPECT(Token::kMinSourcePos == 0); | 792 EXPECT(TokenDescriptor::kMinSourcePos == 0); |
| 791 EXPECT(Token::kMaxSourcePos > 0); | 793 EXPECT(TokenDescriptor::kMaxSourcePos > 0); |
| 792 | 794 EXPECT(TokenDescriptor::kMaxSourcePos > TokenDescriptor::kMinSourcePos); |
| 793 EXPECT(!Token::IsSynthetic(0)); | 795 EXPECT(TokenDescriptor::kMinSource.value() == TokenDescriptor::kMinSourcePos); |
| 794 EXPECT(Token::IsSynthetic(Token::ToSynthetic(0))); | 796 EXPECT(TokenDescriptor::kMaxSource.value() == TokenDescriptor::kMaxSourcePos); |
| 795 EXPECT(Token::IsSynthetic(Token::ToSynthetic(9))); | 797 EXPECT(!TokenDescriptor(0).IsSynthetic()); |
| 796 EXPECT(!Token::IsSynthetic(Token::FromSynthetic(-1))); | 798 EXPECT(TokenDescriptor::ToSynthetic(TokenDescriptor(0)).IsSynthetic()); |
| 797 EXPECT(!Token::IsSynthetic(ClassifyingTokenPositions::kPrivate)); | 799 EXPECT(TokenDescriptor::ToSynthetic(TokenDescriptor(9)).IsSynthetic()); |
| 798 EXPECT(!Token::IsSynthetic(ClassifyingTokenPositions::kLast)); | 800 EXPECT(!TokenDescriptor::FromSynthetic(TokenDescriptor(-1)).IsSynthetic()); |
| 799 | 801 EXPECT(!TokenDescriptor::kNoSource.IsSynthetic()); |
| 800 EXPECT(SyntheticRoundTripTest(0)); | 802 EXPECT(!TokenDescriptor::kLast.IsSynthetic()); |
| 801 EXPECT(SyntheticRoundTripTest(Token::kMaxSourcePos)); | 803 EXPECT(SyntheticRoundTripTest(TokenDescriptor(0))); |
| 802 EXPECT(SyntheticRoundTripTest(Token::kMinSourcePos)); | 804 EXPECT(SyntheticRoundTripTest(TokenDescriptor::kMaxSource)); |
| 805 EXPECT(SyntheticRoundTripTest(TokenDescriptor::kMinSource)); |
| 803 } | 806 } |
| 804 | 807 |
| 805 } // namespace dart | 808 } // namespace dart |
| 806 | 809 |
| OLD | NEW |