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

Side by Side Diff: pkg/kernel/lib/ast.dart

Issue 2864573002: dart2js allocation tweaks (Closed)
Patch Set: Created 3 years, 7 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 | « pkg/compiler/lib/src/world.dart ('k') | no next file » | 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) 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 /// ----------------------------------------------------------------------- 5 /// -----------------------------------------------------------------------
6 /// ERROR HANDLING 6 /// ERROR HANDLING
7 /// ----------------------------------------------------------------------- 7 /// -----------------------------------------------------------------------
8 /// 8 ///
9 /// As a rule of thumb, errors that can be detected statically are handled by 9 /// As a rule of thumb, errors that can be detected statically are handled by
10 /// the frontend, typically by translating the erroneous code into a 'throw' or 10 /// the frontend, typically by translating the erroneous code into a 'throw' or
(...skipping 4353 matching lines...) Expand 10 before | Expand all | Expand 10 after
4364 4364
4365 final List<int> source; 4365 final List<int> source;
4366 4366
4367 String cachedText; 4367 String cachedText;
4368 4368
4369 Source(this.lineStarts, this.source); 4369 Source(this.lineStarts, this.source);
4370 4370
4371 /// Return the text corresponding to [line] which is a 1-based line 4371 /// Return the text corresponding to [line] which is a 1-based line
4372 /// number. The returned line contains no line separators. 4372 /// number. The returned line contains no line separators.
4373 String getTextLine(int line) { 4373 String getTextLine(int line) {
4374 _rangeCheck(line, 1, lineStarts.length, "line"); 4374 RangeError.checkValueInInterval(line, 1, lineStarts.length, 'line');
ahe 2017/05/05 05:27:44 Did you change the error message produced by Range
sra1 2017/05/05 05:49:01 No. I also think the RangeError description is con
ahe 2017/05/08 10:25:21 I'm surprised that this change was submitted altho
4375 if (source == null) return null; 4375 if (source == null) return null;
4376 4376
4377 cachedText ??= UTF8.decode(source, allowMalformed: true); 4377 cachedText ??= UTF8.decode(source, allowMalformed: true);
4378 // -1 as line numbers start at 1. 4378 // -1 as line numbers start at 1.
4379 int index = line - 1; 4379 int index = line - 1;
4380 if (index + 1 == lineStarts.length) { 4380 if (index + 1 == lineStarts.length) {
4381 // Last line. 4381 // Last line.
4382 return cachedText.substring(lineStarts[index]); 4382 return cachedText.substring(lineStarts[index]);
4383 } else if (index < lineStarts.length) { 4383 } else if (index < lineStarts.length) {
4384 // We subtract 1 from the next line for two reasons: 4384 // We subtract 1 from the next line for two reasons:
4385 // 1. If the file isn't terminated by a newline, that index is invalid. 4385 // 1. If the file isn't terminated by a newline, that index is invalid.
4386 // 2. To remove the newline at the end of the line. 4386 // 2. To remove the newline at the end of the line.
4387 int endOfLine = lineStarts[index + 1] - 1; 4387 int endOfLine = lineStarts[index + 1] - 1;
4388 if (endOfLine > index && cachedText[endOfLine - 1] == "\r") { 4388 if (endOfLine > index && cachedText[endOfLine - 1] == "\r") {
4389 --endOfLine; // Windows line endings. 4389 --endOfLine; // Windows line endings.
4390 } 4390 }
4391 return cachedText.substring(lineStarts[index], endOfLine); 4391 return cachedText.substring(lineStarts[index], endOfLine);
4392 } 4392 }
4393 // This shouldn't happen: should have been caught by the range check above. 4393 // This shouldn't happen: should have been caught by the range check above.
4394 throw "Internal error"; 4394 throw "Internal error";
4395 } 4395 }
4396 4396
4397 /// Translates an offset to line and column numbers in the given file. 4397 /// Translates an offset to line and column numbers in the given file.
4398 Location getLocation(String file, int offset) { 4398 Location getLocation(String file, int offset) {
4399 _rangeCheck(offset, 0, lineStarts.last, "offset"); 4399 RangeError.checkValueInInterval(offset, 0, lineStarts.last, 'offset');
4400 int low = 0, high = lineStarts.length - 1; 4400 int low = 0, high = lineStarts.length - 1;
4401 while (low < high) { 4401 while (low < high) {
4402 int mid = high - ((high - low) >> 1); // Get middle, rounding up. 4402 int mid = high - ((high - low) >> 1); // Get middle, rounding up.
4403 int pivot = lineStarts[mid]; 4403 int pivot = lineStarts[mid];
4404 if (pivot <= offset) { 4404 if (pivot <= offset) {
4405 low = mid; 4405 low = mid;
4406 } else { 4406 } else {
4407 high = mid - 1; 4407 high = mid - 1;
4408 } 4408 }
4409 } 4409 }
4410 int lineIndex = low; 4410 int lineIndex = low;
4411 int lineStart = lineStarts[lineIndex]; 4411 int lineStart = lineStarts[lineIndex];
4412 int lineNumber = 1 + lineIndex; 4412 int lineNumber = 1 + lineIndex;
4413 int columnNumber = 1 + offset - lineStart; 4413 int columnNumber = 1 + offset - lineStart;
4414 return new Location(file, lineNumber, columnNumber); 4414 return new Location(file, lineNumber, columnNumber);
4415 } 4415 }
4416 } 4416 }
4417 4417
4418 void _rangeCheck(int value, int min, int max, String name) {
4419 RangeError.checkValueInInterval(value, min, max, name,
4420 "The value of '$name' ($value) must be between $min and $max.");
4421 }
4422
4423 /// Returns the [Reference] object for the given member. 4418 /// Returns the [Reference] object for the given member.
4424 /// 4419 ///
4425 /// Returns `null` if the member is `null`. 4420 /// Returns `null` if the member is `null`.
4426 Reference getMemberReference(Member member) { 4421 Reference getMemberReference(Member member) {
4427 return member?.reference; 4422 return member?.reference;
4428 } 4423 }
4429 4424
4430 /// Returns the [Reference] object for the given class. 4425 /// Returns the [Reference] object for the given class.
4431 /// 4426 ///
4432 /// Returns `null` if the class is `null`. 4427 /// Returns `null` if the class is `null`.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4474 /// typedef has not been assigned a canonical name yet. 4469 /// typedef has not been assigned a canonical name yet.
4475 /// 4470 ///
4476 /// Returns `null` if the typedef is `null`. 4471 /// Returns `null` if the typedef is `null`.
4477 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { 4472 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) {
4478 if (typedef_ == null) return null; 4473 if (typedef_ == null) return null;
4479 if (typedef_.canonicalName == null) { 4474 if (typedef_.canonicalName == null) {
4480 throw '$typedef_ has no canonical name'; 4475 throw '$typedef_ has no canonical name';
4481 } 4476 }
4482 return typedef_.canonicalName; 4477 return typedef_.canonicalName;
4483 } 4478 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/world.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698