Bug 1862692 - Part 6: Use Use 1-origin column number types in EitherParser::computeLineAndColumn. r=iain

Differential Revision: https://phabricator.services.mozilla.com/D193019
This commit is contained in:
Tooru Fujisawa 2023-11-09 11:41:06 +00:00
Родитель 156095dd2d
Коммит 8f457ff891
7 изменённых файлов: 32 добавлений и 35 удалений

Просмотреть файл

@ -18,7 +18,7 @@
#include "frontend/Stencil.h"
#include "gc/GCContext.h"
#include "gc/Tracer.h"
#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin, JS::LimitedColumnNumberZeroOrigin
#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin, JS::LimitedColumnNumberOneOrigin
#include "js/friend/ErrorMessages.h" // JSMSG_*
#include "js/Modules.h" // JS::GetModulePrivate, JS::ModuleDynamicImportHook
#include "vm/EqualityOperations.h" // js::SameValue
@ -1724,7 +1724,7 @@ bool ModuleBuilder::processImport(frontend::BinaryNode* importNode) {
for (ParseNode* item : specList->contents()) {
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
eitherParser_.computeLineAndColumn(item->pn_pos.begin, &line, &column);
StencilModuleEntry entry;
@ -1742,7 +1742,7 @@ bool ModuleBuilder::processImport(frontend::BinaryNode* importNode) {
markUsedByStencil(importName);
entry = StencilModuleEntry::importEntry(
moduleRequestIndex, localName, importName, line,
JS::ColumnNumberOneOrigin(column.oneOriginValue()));
JS::ColumnNumberOneOrigin(column));
} else {
MOZ_ASSERT(item->isKind(ParseNodeKind::ImportNamespaceSpec));
auto* spec = &item->as<UnaryNode>();
@ -1754,7 +1754,7 @@ bool ModuleBuilder::processImport(frontend::BinaryNode* importNode) {
markUsedByStencil(localName);
entry = StencilModuleEntry::importNamespaceEntry(
moduleRequestIndex, localName, line,
JS::ColumnNumberOneOrigin(column.oneOriginValue()));
JS::ColumnNumberOneOrigin(column));
}
if (!importEntries_.put(localName, entry)) {
@ -1969,7 +1969,7 @@ bool ModuleBuilder::processExportFrom(frontend::BinaryNode* exportNode) {
for (ParseNode* spec : specList->contents()) {
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
eitherParser_.computeLineAndColumn(spec->pn_pos.begin, &line, &column);
StencilModuleEntry entry;
@ -1985,7 +1985,7 @@ bool ModuleBuilder::processExportFrom(frontend::BinaryNode* exportNode) {
markUsedByStencil(exportName);
entry = StencilModuleEntry::exportFromEntry(
moduleRequestIndex, importName, exportName, line,
JS::ColumnNumberOneOrigin(column.oneOriginValue()));
JS::ColumnNumberOneOrigin(column));
} else if (spec->isKind(ParseNodeKind::ExportNamespaceSpec)) {
auto* exportNameNode = &spec->as<UnaryNode>().kid()->as<NameNode>();
@ -1994,13 +1994,12 @@ bool ModuleBuilder::processExportFrom(frontend::BinaryNode* exportNode) {
markUsedByStencil(exportName);
entry = StencilModuleEntry::exportNamespaceFromEntry(
moduleRequestIndex, exportName, line,
JS::ColumnNumberOneOrigin(column.oneOriginValue()));
JS::ColumnNumberOneOrigin(column));
} else {
MOZ_ASSERT(spec->isKind(ParseNodeKind::ExportBatchSpecStmt));
entry = StencilModuleEntry::exportBatchFromEntry(
moduleRequestIndex, line,
JS::ColumnNumberOneOrigin(column.oneOriginValue()));
moduleRequestIndex, line, JS::ColumnNumberOneOrigin(column));
}
if (!exportEntries_.append(entry)) {
@ -2035,7 +2034,7 @@ bool ModuleBuilder::appendExportEntry(
frontend::TaggedParserAtomIndex exportName,
frontend::TaggedParserAtomIndex localName, frontend::ParseNode* node) {
uint32_t line = 0;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
if (node) {
eitherParser_.computeLineAndColumn(node->pn_pos.begin, &line, &column);
}
@ -2043,8 +2042,7 @@ bool ModuleBuilder::appendExportEntry(
markUsedByStencil(localName);
markUsedByStencil(exportName);
auto entry = frontend::StencilModuleEntry::exportAsEntry(
localName, exportName, line,
JS::ColumnNumberOneOrigin(column.oneOriginValue()));
localName, exportName, line, JS::ColumnNumberOneOrigin(column));
if (!exportEntries_.append(entry)) {
return false;
}
@ -2083,11 +2081,11 @@ bool ModuleBuilder::maybeAppendRequestedModule(
}
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
eitherParser_.computeLineAndColumn(node->pn_pos.begin, &line, &column);
auto entry = frontend::StencilModuleEntry::requestedModule(
moduleRequest, line, JS::ColumnNumberOneOrigin(column.oneOriginValue()));
moduleRequest, line, JS::ColumnNumberOneOrigin(column));
if (!requestedModules_.append(entry)) {
js::ReportOutOfMemory(fc_);

Просмотреть файл

@ -19,7 +19,7 @@
#include "frontend/ModuleSharedContext.h"
#include "frontend/ParseNode.h"
#include "frontend/Parser.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin, JS::LimitedColumnNumberOneOrigin
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/friend/StackLimits.h" // js::AutoCheckRecursionLimit
#include "js/PropertyAndElement.h" // JS_DefineFunction
@ -727,7 +727,7 @@ bool NodeBuilder::newNodeLoc(TokenPos* pos, MutableHandleValue dst) {
dst.setObject(*loc);
uint32_t startLineNum, endLineNum;
JS::LimitedColumnNumberZeroOrigin startColumnIndex, endColumnIndex;
JS::LimitedColumnNumberOneOrigin startColumnIndex, endColumnIndex;
parser->tokenStream.computeLineAndColumn(pos->begin, &startLineNum,
&startColumnIndex);
parser->tokenStream.computeLineAndColumn(pos->end, &endLineNum,

Просмотреть файл

@ -19,7 +19,7 @@
#include <utility>
#include "frontend/Parser.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberOneOrigin
namespace js::frontend {
@ -41,7 +41,7 @@ class EitherParser final {
}
void computeLineAndColumn(uint32_t offset, uint32_t* line,
JS::LimitedColumnNumberZeroOrigin* column) const {
JS::LimitedColumnNumberOneOrigin* column) const {
return parser.match([offset, line, column](auto* parser) -> void {
parser->tokenStream.computeLineAndColumn(offset, line, column);
});

Просмотреть файл

@ -45,7 +45,7 @@
#include "frontend/ScriptIndex.h" // ScriptIndex
#include "frontend/TokenStream.h" // IsKeyword, ReservedWordTokenKind, ReservedWordToCharZ, DeprecatedContent, *TokenStream*, CharBuffer, TokenKindToDesc
#include "irregexp/RegExpAPI.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin, JS::ColumnNumberZeroOrigin, JS::ColumnNumberOneOrigin
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin, JS::LimitedColumnNumberOneOrigin, JS::ColumnNumberOneOrigin
#include "js/ErrorReport.h" // JSErrorBase
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/HashTable.h"
@ -469,7 +469,7 @@ void GeneralParser<ParseHandler, Unit>::reportMissingClosing(
}
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
tokenStream.computeLineAndColumn(openedPos, &line, &column);
const size_t MaxWidth = sizeof("4294967295");
@ -511,7 +511,7 @@ void GeneralParser<ParseHandler, Unit>::reportRedeclarationHelper(
}
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
tokenStream.computeLineAndColumn(prevPos, &line, &column);
const size_t MaxWidth = sizeof("4294967295");
@ -2587,7 +2587,7 @@ template <class ParseHandler, typename Unit>
void GeneralParser<ParseHandler, Unit>::setFunctionStartAtPosition(
FunctionBox* funbox, TokenPos pos) const {
uint32_t startLine;
JS::LimitedColumnNumberZeroOrigin startColumn;
JS::LimitedColumnNumberOneOrigin startColumn;
tokenStream.computeLineAndColumn(pos.begin, &startLine, &startColumn);
// NOTE: `Debugger::CallData::findScripts` relies on sourceStart and
@ -11096,7 +11096,7 @@ Parser<FullParseHandler, Unit>::newRegExp() {
uint32_t offset = anyChars.currentToken().pos.begin;
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
tokenStream.computeLineAndColumn(offset, &line, &column);
if (!handler_.reuseRegexpSyntaxParse()) {
@ -11142,7 +11142,7 @@ Parser<SyntaxParseHandler, Unit>::newRegExp() {
uint32_t offset = anyChars.currentToken().pos.begin;
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
tokenStream.computeLineAndColumn(offset, &line, &column);
mozilla::Range<const char16_t> source(chars.begin(), chars.length());

Просмотреть файл

@ -20,8 +20,8 @@
#include "frontend/ParserAtom.h" // TaggedParserAtomIndex
#include "frontend/ScopeIndex.h" // ScopeIndex
#include "frontend/ScriptIndex.h" // ScriptIndex
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "vm/FunctionFlags.h" // js::FunctionFlags
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin, JS::LimitedColumnNumberOneOrigin
#include "vm/FunctionFlags.h" // js::FunctionFlags
#include "vm/GeneratorAndAsyncKind.h" // js::GeneratorKind, js::FunctionAsyncKind
#include "vm/Scope.h"
#include "vm/ScopeKind.h"
@ -628,11 +628,11 @@ class FunctionBox : public SuspendableContext {
bool useAsmOrInsideUseAsm() const { return useAsm; }
void setStart(uint32_t offset, uint32_t line,
JS::LimitedColumnNumberZeroOrigin column) {
JS::LimitedColumnNumberOneOrigin column) {
MOZ_ASSERT(!isScriptExtraFieldCopiedToStencil);
extent_.sourceStart = offset;
extent_.lineno = line;
extent_.column = column;
extent_.column = JS::LimitedColumnNumberZeroOrigin(column);
}
void setEnd(uint32_t end) {

Просмотреть файл

@ -853,12 +853,12 @@ GeneralTokenStreamChars<Unit, AnyCharsAccess>::computeColumn(
template <typename Unit, class AnyCharsAccess>
void GeneralTokenStreamChars<Unit, AnyCharsAccess>::computeLineAndColumn(
uint32_t offset, uint32_t* line,
JS::LimitedColumnNumberZeroOrigin* column) const {
JS::LimitedColumnNumberOneOrigin* column) const {
const TokenStreamAnyChars& anyChars = anyCharsAccess();
auto lineToken = anyChars.lineToken(offset);
*line = anyChars.lineNumber(lineToken);
*column = computeColumn(lineToken, offset);
*column = JS::LimitedColumnNumberOneOrigin(computeColumn(lineToken, offset));
}
template <class AnyCharsAccess>
@ -913,7 +913,7 @@ MOZ_COLD void TokenStreamChars<Utf8Unit, AnyCharsAccess>::internalEncodingError(
ptr[-1] = '\0';
uint32_t line;
JS::LimitedColumnNumberZeroOrigin column;
JS::LimitedColumnNumberOneOrigin column;
computeLineAndColumn(offset, &line, &column);
if (!notes->addNoteASCII(anyChars.fc, anyChars.getFilename().c_str(), 0,

Просмотреть файл

@ -1987,7 +1987,7 @@ class GeneralTokenStreamChars : public SpecializedTokenStreamCharsBase<Unit> {
JS::LimitedColumnNumberZeroOrigin computeColumn(LineToken lineToken,
uint32_t offset) const;
void computeLineAndColumn(uint32_t offset, uint32_t* line,
JS::LimitedColumnNumberZeroOrigin* column) const;
JS::LimitedColumnNumberOneOrigin* column) const;
/**
* Fill in |err| completely, except for line-of-context information.
@ -1998,10 +1998,9 @@ class GeneralTokenStreamChars : public SpecializedTokenStreamCharsBase<Unit> {
[[nodiscard]] bool fillExceptingContext(ErrorMetadata* err,
uint32_t offset) const {
if (anyCharsAccess().fillExceptingContext(err, offset)) {
JS::LimitedColumnNumberZeroOrigin columnNumber;
JS::LimitedColumnNumberOneOrigin columnNumber;
computeLineAndColumn(offset, &err->lineNumber, &columnNumber);
err->columnNumber =
JS::ColumnNumberOneOrigin(columnNumber.oneOriginValue());
err->columnNumber = JS::ColumnNumberOneOrigin(columnNumber);
return true;
}
return false;