mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 22:02:51 +01:00
Switch executable semantics to use ErrorBuilder directly and relocate macros (#1184)
This commit is contained in:
@@ -22,7 +22,7 @@ cc_library(
|
||||
"ast_rtti.h",
|
||||
],
|
||||
deps = [
|
||||
":source_location",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
@@ -77,11 +77,11 @@ cc_library(
|
||||
deps = [
|
||||
":ast_node",
|
||||
":pattern",
|
||||
":source_location",
|
||||
":value_category",
|
||||
"//common:check",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:nonnull",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
@@ -97,12 +97,12 @@ cc_library(
|
||||
":impl_binding",
|
||||
":pattern",
|
||||
":return_term",
|
||||
":source_location",
|
||||
":statement",
|
||||
":static_scope",
|
||||
":value_category",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:nonnull",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
@@ -112,10 +112,10 @@ cc_library(
|
||||
hdrs = ["return_term.h"],
|
||||
deps = [
|
||||
":expression",
|
||||
":source_location",
|
||||
"//common:check",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:nonnull",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
@@ -127,13 +127,13 @@ cc_library(
|
||||
deps = [
|
||||
":ast_node",
|
||||
":paren_contents",
|
||||
":source_location",
|
||||
":static_scope",
|
||||
":value_category",
|
||||
"//common:indirect_value",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:arena",
|
||||
"//executable_semantics/common:error",
|
||||
"//executable_semantics/common:error_builders",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
@@ -159,8 +159,8 @@ cc_library(
|
||||
name = "paren_contents",
|
||||
hdrs = ["paren_contents.h"],
|
||||
deps = [
|
||||
":source_location",
|
||||
"//executable_semantics/common:error",
|
||||
"//executable_semantics/common:error_builders",
|
||||
"//executable_semantics/common:source_location",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -171,12 +171,12 @@ cc_library(
|
||||
deps = [
|
||||
":ast_node",
|
||||
":expression",
|
||||
":source_location",
|
||||
":static_scope",
|
||||
":value_category",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:arena",
|
||||
"//executable_semantics/common:error",
|
||||
"//executable_semantics/common:error_builders",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
@@ -200,25 +200,16 @@ cc_library(
|
||||
hdrs = ["static_scope.h"],
|
||||
deps = [
|
||||
":ast_node",
|
||||
":source_location",
|
||||
":value_category",
|
||||
"//common:check",
|
||||
"//common:error",
|
||||
"//executable_semantics/common:error",
|
||||
"//executable_semantics/common:error_builders",
|
||||
"//executable_semantics/common:nonnull",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "source_location",
|
||||
hdrs = ["source_location.h"],
|
||||
deps = [
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:nonnull",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "statement",
|
||||
srcs = ["statement.cpp"],
|
||||
@@ -228,12 +219,12 @@ cc_library(
|
||||
":expression",
|
||||
":pattern",
|
||||
":return_term",
|
||||
":source_location",
|
||||
":static_scope",
|
||||
":value_category",
|
||||
"//common:check",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:arena",
|
||||
"//executable_semantics/common:source_location",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define EXECUTABLE_SEMANTICS_AST_AST_NODE_H_
|
||||
|
||||
#include "executable_semantics/ast/ast_rtti.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -175,14 +175,14 @@ auto FunctionDeclaration::Create(
|
||||
case AstNodeKind::BindingPattern: {
|
||||
Nonnull<BindingPattern*> bp = &cast<BindingPattern>(*param);
|
||||
if (me_pattern.has_value() || bp->name() != "me") {
|
||||
return FATAL_COMPILATION_ERROR(source_loc)
|
||||
return CompilationError(source_loc)
|
||||
<< "illegal binding pattern in implicit parameter list";
|
||||
}
|
||||
me_pattern = bp;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return FATAL_COMPILATION_ERROR(source_loc)
|
||||
return CompilationError(source_loc)
|
||||
<< "illegal AST node in implicit parameter list";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
#include "executable_semantics/ast/impl_binding.h"
|
||||
#include "executable_semantics/ast/pattern.h"
|
||||
#include "executable_semantics/ast/return_term.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/ast/statement.h"
|
||||
#include "executable_semantics/ast/static_scope.h"
|
||||
#include "executable_semantics/ast/value_category.h"
|
||||
#include "executable_semantics/common/nonnull.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <optional>
|
||||
|
||||
#include "executable_semantics/common/arena.h"
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "executable_semantics/common/error_builders.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
@@ -26,8 +26,7 @@ auto IntrinsicExpression::FindIntrinsic(std::string_view name,
|
||||
name.remove_prefix(std::strlen("__intrinsic_"));
|
||||
auto it = intrinsic_map.find(name);
|
||||
if (it == intrinsic_map.end()) {
|
||||
return FATAL_COMPILATION_ERROR(source_loc)
|
||||
<< "Unknown intrinsic '" << name << "'";
|
||||
return CompilationError(source_loc) << "Unknown intrinsic '" << name << "'";
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/ast/ast_node.h"
|
||||
#include "executable_semantics/ast/paren_contents.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/ast/static_scope.h"
|
||||
#include "executable_semantics/ast/value_category.h"
|
||||
#include "executable_semantics/common/arena.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "executable_semantics/common/error_builders.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "executable_semantics/common/arena.h"
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "executable_semantics/common/error_builders.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
|
||||
@@ -151,7 +151,7 @@ auto TuplePatternFromParenContents(Nonnull<Arena*> arena,
|
||||
auto AlternativePattern::RequireFieldAccess(Nonnull<Expression*> alternative)
|
||||
-> ErrorOr<Nonnull<FieldAccessExpression*>> {
|
||||
if (alternative->kind() != ExpressionKind::FieldAccessExpression) {
|
||||
return FATAL_PROGRAM_ERROR(alternative->source_loc())
|
||||
return ProgramError(alternative->source_loc())
|
||||
<< "Alternative pattern must have the form of a field access.";
|
||||
}
|
||||
return &cast<FieldAccessExpression>(*alternative);
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "executable_semantics/ast/ast_node.h"
|
||||
#include "executable_semantics/ast/ast_rtti.h"
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/ast/static_scope.h"
|
||||
#include "executable_semantics/ast/value_category.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include "common/check.h"
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/common/nonnull.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#ifndef EXECUTABLE_SEMANTICS_AST_SOURCE_LOCATION_H_
|
||||
#define EXECUTABLE_SEMANTICS_AST_SOURCE_LOCATION_H_
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/common/nonnull.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
class SourceLocation {
|
||||
public:
|
||||
// The filename should be eternal or arena-allocated to eliminate copies.
|
||||
constexpr SourceLocation(const char* filename, int line_num)
|
||||
: filename_(filename), line_num_(line_num) {}
|
||||
SourceLocation(Nonnull<const std::string*> filename, int line_num)
|
||||
: filename_(filename->c_str()), line_num_(line_num) {}
|
||||
|
||||
SourceLocation(const SourceLocation&) = default;
|
||||
SourceLocation(SourceLocation&&) = default;
|
||||
auto operator=(const SourceLocation&) -> SourceLocation& = default;
|
||||
auto operator=(SourceLocation&&) -> SourceLocation& = default;
|
||||
|
||||
auto operator==(SourceLocation other) const -> bool {
|
||||
return filename_ == other.filename_ && line_num_ == other.line_num_;
|
||||
}
|
||||
|
||||
void Print(llvm::raw_ostream& out) const {
|
||||
out << filename_ << ":" << line_num_;
|
||||
}
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
private:
|
||||
std::string_view filename_;
|
||||
int line_num_;
|
||||
};
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
#endif // EXECUTABLE_SEMANTICS_AST_SOURCE_LOCATION_H_
|
||||
@@ -13,10 +13,10 @@
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "executable_semantics/ast/pattern.h"
|
||||
#include "executable_semantics/ast/return_term.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/ast/static_scope.h"
|
||||
#include "executable_semantics/ast/value_category.h"
|
||||
#include "executable_semantics/common/arena.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "executable_semantics/ast/static_scope.h"
|
||||
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "executable_semantics/common/error_builders.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
namespace Carbon {
|
||||
@@ -13,7 +13,7 @@ auto StaticScope::Add(std::string name, ValueNodeView entity)
|
||||
-> ErrorOr<Success> {
|
||||
auto [it, success] = declared_names_.insert({name, entity});
|
||||
if (!success && it->second != entity) {
|
||||
return FATAL_COMPILATION_ERROR(entity.base().source_loc())
|
||||
return CompilationError(entity.base().source_loc())
|
||||
<< "Duplicate name `" << name << "` also found at "
|
||||
<< it->second.base().source_loc();
|
||||
}
|
||||
@@ -26,8 +26,7 @@ auto StaticScope::Resolve(const std::string& name,
|
||||
ASSIGN_OR_RETURN(std::optional<ValueNodeView> result,
|
||||
TryResolve(name, source_loc));
|
||||
if (!result) {
|
||||
return FATAL_COMPILATION_ERROR(source_loc)
|
||||
<< "could not resolve '" << name << "'";
|
||||
return CompilationError(source_loc) << "could not resolve '" << name << "'";
|
||||
}
|
||||
return *result;
|
||||
}
|
||||
@@ -45,7 +44,7 @@ auto StaticScope::TryResolve(const std::string& name,
|
||||
parent->TryResolve(name, source_loc));
|
||||
if (parent_result.has_value() && result.has_value() &&
|
||||
*parent_result != *result) {
|
||||
return FATAL_COMPILATION_ERROR(source_loc)
|
||||
return CompilationError(source_loc)
|
||||
<< "'" << name << "' is ambiguous between "
|
||||
<< result->base().source_loc() << " and "
|
||||
<< parent_result->base().source_loc();
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include "common/check.h"
|
||||
#include "common/error.h"
|
||||
#include "executable_semantics/ast/ast_node.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/ast/value_category.h"
|
||||
#include "executable_semantics/common/nonnull.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
Reference in New Issue
Block a user