mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
LibJS: Add to_string definitions to CodeGenerationError and ParserError
This commit is contained in:
parent
f7458b3e17
commit
93ad25fbe5
5 changed files with 30 additions and 0 deletions
17
Userland/Libraries/LibJS/Bytecode/CodeGenerationError.cpp
Normal file
17
Userland/Libraries/LibJS/Bytecode/CodeGenerationError.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/AST.h>
|
||||||
|
#include <LibJS/Bytecode/CodeGenerationError.h>
|
||||||
|
|
||||||
|
namespace JS::Bytecode {
|
||||||
|
|
||||||
|
ErrorOr<String> CodeGenerationError::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("CodeGenerationError in {}: {}", failing_node ? failing_node->class_name() : "<unknown node>", reason_literal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ struct CodeGenerationError {
|
||||||
ASTNode const* failing_node { nullptr };
|
ASTNode const* failing_node { nullptr };
|
||||||
StringView reason_literal;
|
StringView reason_literal;
|
||||||
|
|
||||||
|
ErrorOr<String> to_string() const;
|
||||||
DeprecatedString to_deprecated_string();
|
DeprecatedString to_deprecated_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ set(SOURCES
|
||||||
AST.cpp
|
AST.cpp
|
||||||
Bytecode/ASTCodegen.cpp
|
Bytecode/ASTCodegen.cpp
|
||||||
Bytecode/BasicBlock.cpp
|
Bytecode/BasicBlock.cpp
|
||||||
|
Bytecode/CodeGenerationError.cpp
|
||||||
Bytecode/Executable.cpp
|
Bytecode/Executable.cpp
|
||||||
Bytecode/Generator.cpp
|
Bytecode/Generator.cpp
|
||||||
Bytecode/IdentifierTable.cpp
|
Bytecode/IdentifierTable.cpp
|
||||||
|
|
|
@ -12,6 +12,13 @@
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
|
ErrorOr<String> ParserError::to_string() const
|
||||||
|
{
|
||||||
|
if (!position.has_value())
|
||||||
|
return String::from_deprecated_string(message);
|
||||||
|
return String::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column);
|
||||||
|
}
|
||||||
|
|
||||||
DeprecatedString ParserError::to_deprecated_string() const
|
DeprecatedString ParserError::to_deprecated_string() const
|
||||||
{
|
{
|
||||||
if (!position.has_value())
|
if (!position.has_value())
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
|
#include <AK/Error.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibJS/SourceRange.h>
|
#include <LibJS/SourceRange.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
@ -17,6 +19,7 @@ struct ParserError {
|
||||||
DeprecatedString message;
|
DeprecatedString message;
|
||||||
Optional<Position> position;
|
Optional<Position> position;
|
||||||
|
|
||||||
|
ErrorOr<String> to_string() const;
|
||||||
DeprecatedString to_deprecated_string() const;
|
DeprecatedString to_deprecated_string() const;
|
||||||
DeprecatedString source_location_hint(StringView source, char const spacer = ' ', char const indicator = '^') const;
|
DeprecatedString source_location_hint(StringView source, char const spacer = ' ', char const indicator = '^') const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue