mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Switch executable semantics to use ErrorBuilder directly and relocate macros (#1184)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// 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_COMMON_ERROR_BUILDERS_H_
|
||||
#define EXECUTABLE_SEMANTICS_COMMON_ERROR_BUILDERS_H_
|
||||
|
||||
#include "common/error.h"
|
||||
#include "executable_semantics/common/source_location.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
// Builds an Error instance with the specified message. This should be used for
|
||||
// non-recoverable errors with user input.
|
||||
//
|
||||
// For example:
|
||||
// return ProgramError(line_num) << "Line is bad!";
|
||||
// return ProgramError() << "Application is bad!";
|
||||
//
|
||||
// Where possible, try to identify the error as a compilation or runtime error.
|
||||
// Use CHECK/FATAL for internal errors. The generic program error option is
|
||||
// provided as a fallback for cases that don't fit those classifications.
|
||||
|
||||
inline auto CompilationError(SourceLocation loc) -> ErrorBuilder {
|
||||
ErrorBuilder builder;
|
||||
(void)(builder << "COMPILATION ERROR: " << loc << ": ");
|
||||
return builder;
|
||||
}
|
||||
|
||||
inline auto ProgramError(SourceLocation loc) -> ErrorBuilder {
|
||||
ErrorBuilder builder;
|
||||
(void)(builder << "PROGRAM ERROR: " << loc << ": ");
|
||||
return builder;
|
||||
}
|
||||
|
||||
inline auto RuntimeError(SourceLocation loc) -> ErrorBuilder {
|
||||
ErrorBuilder builder;
|
||||
(void)(builder << "RUNTIME ERROR: " << loc << ": ");
|
||||
return builder;
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
#endif // EXECUTABLE_SEMANTICS_COMMON_ERROR_BUILDERS_H_
|
||||
Reference in New Issue
Block a user