mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1504947 - Change fake-column computations to work from (LineToken, uint32_t offset) inputs. r=tcampbell
--HG-- extra : rebase_source : b2518ff4566613388ad61c7c31ad1cf4036ce326
This commit is contained in:
parent
ee08a32df3
commit
e33ca05b5d
@ -469,18 +469,6 @@ TokenStreamAnyChars::SourceCoords::lineToken(uint32_t offset) const {
|
||||
return LineToken(indexFromOffset(offset), offset);
|
||||
}
|
||||
|
||||
uint32_t TokenStreamAnyChars::SourceCoords::columnIndex(uint32_t offset) const {
|
||||
return columnFromIndexAndOffset(indexFromOffset(offset), offset);
|
||||
}
|
||||
|
||||
void TokenStreamAnyChars::SourceCoords::lineNumAndColumnIndex(
|
||||
uint32_t offset, uint32_t* lineNum, uint32_t* column) const {
|
||||
LineToken token = lineToken(offset);
|
||||
uint32_t index = token.index;
|
||||
*lineNum = lineNumberFromIndex(index);
|
||||
*column = columnFromIndexAndOffset(index, offset);
|
||||
}
|
||||
|
||||
TokenStreamAnyChars::TokenStreamAnyChars(JSContext* cx,
|
||||
const ReadOnlyCompileOptions& options,
|
||||
StrictModeGetter* smg)
|
||||
@ -1340,7 +1328,7 @@ bool TokenStreamAnyChars::fillExcludingContext(ErrorMetadata* err,
|
||||
|
||||
// Otherwise use this TokenStreamAnyChars's location information.
|
||||
err->filename = filename_;
|
||||
srcCoords.lineNumAndColumnIndex(offset, &err->lineNumber, &err->columnNumber);
|
||||
lineAndColumnAt(offset, &err->lineNumber, &err->columnNumber);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1350,11 +1338,6 @@ bool TokenStreamSpecific<Unit, AnyCharsAccess>::hasTokenizationStarted() const {
|
||||
return anyChars.isCurrentTokenType(TokenKind::Eof) && !anyChars.isEOF();
|
||||
}
|
||||
|
||||
void TokenStreamAnyChars::lineAndColumnAt(size_t offset, uint32_t* line,
|
||||
uint32_t* column) const {
|
||||
srcCoords.lineNumAndColumnIndex(offset, line, column);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void SourceUnits<char16_t>::computeWindowOffsetAndLength(
|
||||
const char16_t* encodedWindow, size_t encodedTokenOffset,
|
||||
|
@ -843,11 +843,21 @@ class TokenStreamAnyChars : public TokenStreamShared {
|
||||
*/
|
||||
class LineToken {
|
||||
uint32_t index;
|
||||
#ifdef DEBUG
|
||||
uint32_t offset_; // stored for consistency-of-use assertions
|
||||
#endif
|
||||
|
||||
friend class SourceCoords;
|
||||
|
||||
public:
|
||||
explicit LineToken(uint32_t index, uint32_t offset) : index(index) {}
|
||||
explicit LineToken(uint32_t index, uint32_t offset)
|
||||
: index(index)
|
||||
#ifdef DEBUG
|
||||
,
|
||||
offset_(offset)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
bool isFirstLine() const { return index == 0; }
|
||||
|
||||
@ -871,9 +881,24 @@ class TokenStreamAnyChars : public TokenStreamShared {
|
||||
return lineNumberFromIndex(lineToken.index);
|
||||
}
|
||||
|
||||
uint32_t columnIndex(uint32_t offset) const;
|
||||
void lineNumAndColumnIndex(uint32_t offset, uint32_t* lineNum,
|
||||
uint32_t* column) const;
|
||||
/**
|
||||
* Compute the offset *in code units* of |offset| from the start of the
|
||||
* line containing it, plus any contribution from |initialColumnNumber|
|
||||
* passed to the |SourceCoords| constructor.
|
||||
*
|
||||
* This is only really a "column". A subsequent patch in this stack
|
||||
* removes it, computing a multi-unit-aware column number elsewhere in
|
||||
* Unit-sensitive manner.
|
||||
*/
|
||||
uint32_t columnIndex(LineToken lineToken, uint32_t offset) const {
|
||||
MOZ_ASSERT(lineToken.offset_ == offset, "use a consistent token");
|
||||
|
||||
uint32_t lineStartOffset = lineStartOffsets_[lineToken.index];
|
||||
MOZ_RELEASE_ASSERT(offset >= lineStartOffset);
|
||||
|
||||
uint32_t relative = offset - lineStartOffset;
|
||||
return (lineToken.isFirstLine() ? initialColumn_ : 0) + relative;
|
||||
}
|
||||
};
|
||||
|
||||
SourceCoords srcCoords;
|
||||
@ -890,6 +915,18 @@ class TokenStreamAnyChars : public TokenStreamShared {
|
||||
return srcCoords.lineNumber(lineToken);
|
||||
}
|
||||
|
||||
uint32_t columnIndex(LineToken lineToken, uint32_t offset) const {
|
||||
return srcCoords.columnIndex(lineToken, offset);
|
||||
}
|
||||
|
||||
// A helper function if you want an offset's line *and* "column" info.
|
||||
void lineAndColumnAt(uint32_t offset, uint32_t* lineNum,
|
||||
uint32_t* column) const {
|
||||
LineToken token = srcCoords.lineToken(offset);
|
||||
*lineNum = srcCoords.lineNumber(token);
|
||||
*column = srcCoords.columnIndex(token, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in |err|, excepting line-of-context-related fields. If the token
|
||||
* stream has location information, use that and return true. If it does
|
||||
@ -944,8 +981,6 @@ class TokenStreamAnyChars : public TokenStreamShared {
|
||||
|
||||
// ErrorReporter API Helpers
|
||||
|
||||
void lineAndColumnAt(size_t offset, uint32_t* line, uint32_t* column) const;
|
||||
|
||||
// This is just straight up duplicated from TokenStreamSpecific's inheritance
|
||||
// of ErrorReporter's reportErrorNoOffset. varargs delenda est.
|
||||
void reportErrorNoOffset(unsigned errorNumber, ...);
|
||||
@ -1929,12 +1964,7 @@ class GeneralTokenStreamChars : public SpecializedTokenStreamCharsBase<Unit> {
|
||||
|
||||
void computeLineAndColumn(uint32_t offset, uint32_t* line,
|
||||
uint32_t* column) const {
|
||||
const TokenStreamAnyChars& anyChars = anyCharsAccess();
|
||||
|
||||
auto lineToken = anyChars.lineToken(offset);
|
||||
*line = anyChars.lineNumber(lineToken);
|
||||
|
||||
anyCharsAccess().srcCoords.lineNumAndColumnIndex(offset, line, column);
|
||||
anyCharsAccess().lineAndColumnAt(offset, line, column);
|
||||
}
|
||||
|
||||
void newSimpleToken(TokenKind kind, TokenStart start,
|
||||
@ -2469,7 +2499,9 @@ class MOZ_STACK_CLASS TokenStreamSpecific
|
||||
}
|
||||
|
||||
uint32_t columnAt(size_t offset) const final {
|
||||
return anyCharsAccess().srcCoords.columnIndex(offset);
|
||||
const TokenStreamAnyChars& anyChars = anyCharsAccess();
|
||||
auto lineToken = anyChars.lineToken(offset);
|
||||
return anyChars.columnIndex(lineToken, offset);
|
||||
}
|
||||
|
||||
bool hasTokenizationStarted() const final;
|
||||
|
Loading…
Reference in New Issue
Block a user