| 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 "vm/assembler.h" | 5 #include "vm/assembler.h" |
| 6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 const Script& script = Script::Handle( | 2057 const Script& script = Script::Handle( |
| 2058 Script::New(url, source, RawScript::kScriptTag)); | 2058 Script::New(url, source, RawScript::kScriptTag)); |
| 2059 script.SetLocationOffset(line_offset, col_offset); | 2059 script.SetLocationOffset(line_offset, col_offset); |
| 2060 | 2060 |
| 2061 String& str = String::Handle(); | 2061 String& str = String::Handle(); |
| 2062 str = script.GetLine(first_dart_line); | 2062 str = script.GetLine(first_dart_line); |
| 2063 EXPECT_STREQ("main() {", str.ToCString()); | 2063 EXPECT_STREQ("main() {", str.ToCString()); |
| 2064 str = script.GetLine(last_dart_line); | 2064 str = script.GetLine(last_dart_line); |
| 2065 EXPECT_STREQ(" }", str.ToCString()); | 2065 EXPECT_STREQ(" }", str.ToCString()); |
| 2066 | 2066 |
| 2067 script.Tokenize(String::Handle(String::New("ABC"))); |
| 2068 // Tokens: 0: kIDENT, 1: kLPAREN, 2: kRPAREN, 3: kLBRACE, 4: kNEWLINE, |
| 2069 // 5: kRETURN, 6: kSTRING, 7: kSEMICOLON, 8: kNEWLINE, |
| 2070 // 9: kRBRACE, 10: kNEWLINE |
| 2067 | 2071 |
| 2068 script.Tokenize(String::Handle(String::New("ABC"))); | |
| 2069 intptr_t line, col; | 2072 intptr_t line, col; |
| 2073 intptr_t fast_line; |
| 2070 script.GetTokenLocation(0, &line, &col); | 2074 script.GetTokenLocation(0, &line, &col); |
| 2071 EXPECT_EQ(first_dart_line, line); | 2075 EXPECT_EQ(first_dart_line, line); |
| 2072 EXPECT_EQ(col, col_offset + 1); | 2076 EXPECT_EQ(col, col_offset + 1); |
| 2073 | 2077 |
| 2074 script.GetTokenLocation(4, &line, &col); // Token 'return' | 2078 // We allow asking for only the line number, which only scans the token stream |
| 2079 // instead of rescanning the script. |
| 2080 script.GetTokenLocation(0, &fast_line, NULL); |
| 2081 EXPECT_EQ(line, fast_line); |
| 2082 |
| 2083 script.GetTokenLocation(5, &line, &col); // Token 'return' |
| 2075 EXPECT_EQ(4, line); // 'return' is in line 4. | 2084 EXPECT_EQ(4, line); // 'return' is in line 4. |
| 2076 EXPECT_EQ(5, col); // Four spaces before 'return'. | 2085 EXPECT_EQ(5, col); // Four spaces before 'return'. |
| 2077 | 2086 |
| 2087 // We allow asking for only the line number, which only scans the token stream |
| 2088 // instead of rescanning the script. |
| 2089 script.GetTokenLocation(5, &fast_line, NULL); |
| 2090 EXPECT_EQ(line, fast_line); |
| 2091 |
| 2078 intptr_t first_idx, last_idx; | 2092 intptr_t first_idx, last_idx; |
| 2079 script.TokenRangeAtLine(3, &first_idx, &last_idx); | 2093 script.TokenRangeAtLine(3, &first_idx, &last_idx); |
| 2080 EXPECT_EQ(0, first_idx); // Token 'main' is first token. | 2094 EXPECT_EQ(0, first_idx); // Token 'main' is first token. |
| 2081 EXPECT_EQ(3, last_idx); // Token { is last token. | 2095 EXPECT_EQ(3, last_idx); // Token { is last token. |
| 2096 script.TokenRangeAtLine(4, &first_idx, &last_idx); |
| 2097 EXPECT_EQ(5, first_idx); // Token 'return' is first token. |
| 2098 EXPECT_EQ(7, last_idx); // Token ; is last token. |
| 2082 script.TokenRangeAtLine(5, &first_idx, &last_idx); | 2099 script.TokenRangeAtLine(5, &first_idx, &last_idx); |
| 2083 EXPECT_EQ(9, first_idx); // Token } is first and only token. | 2100 EXPECT_EQ(9, first_idx); // Token } is first and only token. |
| 2084 EXPECT_EQ(9, last_idx); | 2101 EXPECT_EQ(9, last_idx); |
| 2102 script.TokenRangeAtLine(1, &first_idx, &last_idx); |
| 2103 EXPECT_EQ(0, first_idx); |
| 2104 EXPECT_EQ(3, last_idx); |
| 2105 script.TokenRangeAtLine(6, &first_idx, &last_idx); |
| 2106 EXPECT_EQ(-1, first_idx); |
| 2107 EXPECT_EQ(-1, last_idx); |
| 2108 script.TokenRangeAtLine(1000, &first_idx, &last_idx); |
| 2109 EXPECT_EQ(-1, first_idx); |
| 2110 EXPECT_EQ(-1, last_idx); |
| 2085 } | 2111 } |
| 2086 | 2112 |
| 2087 | 2113 |
| 2088 TEST_CASE(Context) { | 2114 TEST_CASE(Context) { |
| 2089 const int kNumVariables = 5; | 2115 const int kNumVariables = 5; |
| 2090 const Context& parent_context = Context::Handle(Context::New(0)); | 2116 const Context& parent_context = Context::Handle(Context::New(0)); |
| 2091 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); | 2117 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); |
| 2092 const Context& context = Context::Handle(Context::New(kNumVariables)); | 2118 const Context& context = Context::Handle(Context::New(kNumVariables)); |
| 2093 context.set_parent(parent_context); | 2119 context.set_parent(parent_context); |
| 2094 const Context& check_parent_context = Context::Handle(context.parent()); | 2120 const Context& check_parent_context = Context::Handle(context.parent()); |
| (...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3450 cls = Object::dynamic_class(); | 3476 cls = Object::dynamic_class(); |
| 3451 array = cls.fields(); | 3477 array = cls.fields(); |
| 3452 EXPECT(!array.IsNull()); | 3478 EXPECT(!array.IsNull()); |
| 3453 EXPECT(array.IsArray()); | 3479 EXPECT(array.IsArray()); |
| 3454 array = cls.functions(); | 3480 array = cls.functions(); |
| 3455 EXPECT(!array.IsNull()); | 3481 EXPECT(!array.IsNull()); |
| 3456 EXPECT(array.IsArray()); | 3482 EXPECT(array.IsArray()); |
| 3457 } | 3483 } |
| 3458 | 3484 |
| 3459 } // namespace dart | 3485 } // namespace dart |
| OLD | NEW |