Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / frontend / EitherParser.h
blobc085c0fe8a4276f3c8b2b0e81b7ce593ff942912
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * A variant-like class abstracting operations on a Parser with a given
9 * ParseHandler but unspecified character type.
12 #ifndef frontend_EitherParser_h
13 #define frontend_EitherParser_h
15 #include "mozilla/Utf8.h"
16 #include "mozilla/Variant.h"
18 #include <type_traits>
19 #include <utility>
21 #include "frontend/Parser.h"
22 #include "js/ColumnNumber.h" // JS::LimitedColumnNumberOneOrigin
24 namespace js::frontend {
26 class EitherParser final {
27 // Leave this as a variant, to promote good form until 8-bit parser
28 // integration.
29 mozilla::Variant<Parser<FullParseHandler, char16_t>* const,
30 Parser<FullParseHandler, mozilla::Utf8Unit>* const>
31 parser;
33 public:
34 template <class Parser>
35 explicit EitherParser(Parser* parser) : parser(parser) {}
37 const ErrorReporter& errorReporter() const {
38 return parser.match([](auto* parser) -> const frontend::ErrorReporter& {
39 return parser->tokenStream;
40 });
43 void computeLineAndColumn(uint32_t offset, uint32_t* line,
44 JS::LimitedColumnNumberOneOrigin* column) const {
45 return parser.match([offset, line, column](auto* parser) -> void {
46 parser->tokenStream.computeLineAndColumn(offset, line, column);
47 });
50 ParserAtomsTable& parserAtoms() {
51 auto& base = parser.match(
52 [](auto* parser) -> frontend::ParserSharedBase& { return *parser; });
53 return base.parserAtoms();
57 } /* namespace js::frontend */
59 #endif /* frontend_EitherParser_h */