mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 19:11:09 +01:00
Prefix most macro names with CARBON_ (#1232)
I'm doing this to avoid macro name conflicts, following https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros: "If you do export a macro from a header, it must have a globally unique name. To achieve this, it must be named with a prefix consisting of your project's namespace name (but upper case)." Commands run: ``` sed -i 's/\(DCHECK\|CHECK\|FATAL\|MAKE_UNIQUE_NAME\|MAKE_UNIQUE_NAME_IMPL\|RAW_EXITING_STREAM\|RETURN_IF_ERROR\|RETURN_IF_ERROR_IMPL\|ASSIGN_OR_RETURN\|ASSIGN_OR_RETURN_IMPL\|DIAGNOSTIC_KIND\|RETURN_IF_STACK_LIMITED\)(/CARBON_\1(/g' $(git ls-files *.cpp *.h *.lpp *.ypp *.def ':!third_party') sed -i 's/#undef DIAGNOSTIC_KIND/#undef CARBON_DIAGNOSTIC_KIND/' toolchain/diagnostics/diagnostic_registry.def ``` Note this isn't *quite* everything, but it's intended to be a large pass at everything: ``` ╚╡git grep '#define ' *.cpp *.h *.lpp *.ypp *.def ':!third_party' | grep -v '#define CARBON' | grep -v _H_ explorer/syntax/lexer.lpp: #define YY_USER_ACTION \ explorer/syntax/lexer.lpp: #define SIMPLE_TOKEN(name) \ explorer/syntax/lexer.lpp: #define ARG_TOKEN(name, arg) \ explorer/syntax/parse_and_lex_context.h:#define YY_DECL \ migrate_cpp/cpp_refactoring/var_decl.cpp:#define ABSTRACT_TYPE(Class, Base) migrate_cpp/cpp_refactoring/var_decl.cpp:#define TYPE(Class, Base) \ ``` We may in particular want to do a pass to clean up #ifdef guards and make them be CARBON_ rooted.
This commit is contained in:
@@ -144,7 +144,7 @@ class TokenizedBuffer::Lexer {
|
||||
default:
|
||||
// If we find a non-whitespace character without exhausting the
|
||||
// buffer, return true to continue lexing.
|
||||
CHECK(!IsSpace(source_text.front()));
|
||||
CARBON_CHECK(!IsSpace(source_text.front()));
|
||||
if (whitespace_start != source_text.begin()) {
|
||||
NoteWhitespace();
|
||||
}
|
||||
@@ -176,7 +176,8 @@ class TokenizedBuffer::Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(source_text.empty()) << "Cannot reach here w/o finishing the text!";
|
||||
CARBON_CHECK(source_text.empty())
|
||||
<< "Cannot reach here w/o finishing the text!";
|
||||
// Update the line length as this is also the end of a line.
|
||||
current_line_info_->length = current_column_;
|
||||
return false;
|
||||
@@ -218,8 +219,8 @@ class TokenizedBuffer::Lexer {
|
||||
buffer_.literal_int_storage_.size();
|
||||
buffer_.literal_int_storage_.push_back(std::move(value.mantissa));
|
||||
buffer_.literal_int_storage_.push_back(std::move(value.exponent));
|
||||
CHECK(buffer_.GetRealLiteral(token).IsDecimal() ==
|
||||
(value.radix == LexedNumericLiteral::Radix::Decimal));
|
||||
CARBON_CHECK(buffer_.GetRealLiteral(token).IsDecimal() ==
|
||||
(value.radix == LexedNumericLiteral::Radix::Decimal));
|
||||
return token;
|
||||
},
|
||||
[&](LexedNumericLiteral::UnrecoverableError) {
|
||||
@@ -415,7 +416,8 @@ class TokenizedBuffer::Lexer {
|
||||
"Closing symbol does not match most recent opening symbol.");
|
||||
token_emitter_.Emit(opening_token, MismatchedClosing);
|
||||
|
||||
CHECK(!buffer_.tokens().empty()) << "Must have a prior opening token!";
|
||||
CARBON_CHECK(!buffer_.tokens().empty())
|
||||
<< "Must have a prior opening token!";
|
||||
Token prev_token = buffer_.tokens().end()[-1];
|
||||
|
||||
// TODO: do a smarter backwards scan for where to put the closing
|
||||
@@ -455,7 +457,8 @@ class TokenizedBuffer::Lexer {
|
||||
// Take the valid characters off the front of the source buffer.
|
||||
llvm::StringRef identifier_text =
|
||||
source_text.take_while([](char c) { return IsAlnum(c) || c == '_'; });
|
||||
CHECK(!identifier_text.empty()) << "Must have at least one character!";
|
||||
CARBON_CHECK(!identifier_text.empty())
|
||||
<< "Must have at least one character!";
|
||||
int identifier_column = current_column_;
|
||||
current_column_ += identifier_text.size();
|
||||
source_text = source_text.drop_front(identifier_text.size());
|
||||
@@ -567,7 +570,7 @@ auto TokenizedBuffer::Lex(SourceBuffer& source, DiagnosticConsumer& consumer)
|
||||
if (!result) {
|
||||
result = lexer.LexError(source_text);
|
||||
}
|
||||
CHECK(result) << "No token was lexed.";
|
||||
CARBON_CHECK(result) << "No token was lexed.";
|
||||
}
|
||||
|
||||
// The end-of-file token is always considered to be whitespace.
|
||||
@@ -620,7 +623,7 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef {
|
||||
int64_t token_start = line_info.start + token_info.column;
|
||||
llvm::Optional<LexedNumericLiteral> relexed_token =
|
||||
LexedNumericLiteral::Lex(source_->text().substr(token_start));
|
||||
CHECK(relexed_token) << "Could not reform numeric literal token.";
|
||||
CARBON_CHECK(relexed_token) << "Could not reform numeric literal token.";
|
||||
return relexed_token->text();
|
||||
}
|
||||
|
||||
@@ -631,7 +634,7 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef {
|
||||
int64_t token_start = line_info.start + token_info.column;
|
||||
llvm::Optional<LexedStringLiteral> relexed_token =
|
||||
LexedStringLiteral::Lex(source_->text().substr(token_start));
|
||||
CHECK(relexed_token) << "Could not reform string literal token.";
|
||||
CARBON_CHECK(relexed_token) << "Could not reform string literal token.";
|
||||
return relexed_token->text();
|
||||
}
|
||||
|
||||
@@ -649,14 +652,14 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef {
|
||||
return llvm::StringRef();
|
||||
}
|
||||
|
||||
CHECK(token_info.kind == TokenKind::Identifier())
|
||||
CARBON_CHECK(token_info.kind == TokenKind::Identifier())
|
||||
<< "Only identifiers have stored text!";
|
||||
return GetIdentifierText(token_info.id);
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetIdentifier(Token token) const -> Identifier {
|
||||
auto& token_info = GetTokenInfo(token);
|
||||
CHECK(token_info.kind == TokenKind::Identifier())
|
||||
CARBON_CHECK(token_info.kind == TokenKind::Identifier())
|
||||
<< "The token must be an identifier!";
|
||||
return token_info.id;
|
||||
}
|
||||
@@ -664,14 +667,14 @@ auto TokenizedBuffer::GetIdentifier(Token token) const -> Identifier {
|
||||
auto TokenizedBuffer::GetIntegerLiteral(Token token) const
|
||||
-> const llvm::APInt& {
|
||||
auto& token_info = GetTokenInfo(token);
|
||||
CHECK(token_info.kind == TokenKind::IntegerLiteral())
|
||||
CARBON_CHECK(token_info.kind == TokenKind::IntegerLiteral())
|
||||
<< "The token must be an integer literal!";
|
||||
return literal_int_storage_[token_info.literal_index];
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetRealLiteral(Token token) const -> RealLiteralValue {
|
||||
auto& token_info = GetTokenInfo(token);
|
||||
CHECK(token_info.kind == TokenKind::RealLiteral())
|
||||
CARBON_CHECK(token_info.kind == TokenKind::RealLiteral())
|
||||
<< "The token must be a real literal!";
|
||||
|
||||
// Note that every real literal is at least three characters long, so we can
|
||||
@@ -687,7 +690,7 @@ auto TokenizedBuffer::GetRealLiteral(Token token) const -> RealLiteralValue {
|
||||
|
||||
auto TokenizedBuffer::GetStringLiteral(Token token) const -> llvm::StringRef {
|
||||
auto& token_info = GetTokenInfo(token);
|
||||
CHECK(token_info.kind == TokenKind::StringLiteral())
|
||||
CARBON_CHECK(token_info.kind == TokenKind::StringLiteral())
|
||||
<< "The token must be a string literal!";
|
||||
return literal_string_storage_[token_info.literal_index];
|
||||
}
|
||||
@@ -695,7 +698,7 @@ auto TokenizedBuffer::GetStringLiteral(Token token) const -> llvm::StringRef {
|
||||
auto TokenizedBuffer::GetTypeLiteralSize(Token token) const
|
||||
-> const llvm::APInt& {
|
||||
auto& token_info = GetTokenInfo(token);
|
||||
CHECK(token_info.kind.IsSizedTypeLiteral())
|
||||
CARBON_CHECK(token_info.kind.IsSizedTypeLiteral())
|
||||
<< "The token must be a sized type literal!";
|
||||
return literal_int_storage_[token_info.literal_index];
|
||||
}
|
||||
@@ -703,7 +706,7 @@ auto TokenizedBuffer::GetTypeLiteralSize(Token token) const
|
||||
auto TokenizedBuffer::GetMatchedClosingToken(Token opening_token) const
|
||||
-> Token {
|
||||
auto& opening_token_info = GetTokenInfo(opening_token);
|
||||
CHECK(opening_token_info.kind.IsOpeningSymbol())
|
||||
CARBON_CHECK(opening_token_info.kind.IsOpeningSymbol())
|
||||
<< "The token must be an opening group symbol!";
|
||||
return opening_token_info.closing_token;
|
||||
}
|
||||
@@ -711,7 +714,7 @@ auto TokenizedBuffer::GetMatchedClosingToken(Token opening_token) const
|
||||
auto TokenizedBuffer::GetMatchedOpeningToken(Token closing_token) const
|
||||
-> Token {
|
||||
auto& closing_token_info = GetTokenInfo(closing_token);
|
||||
CHECK(closing_token_info.kind.IsClosingSymbol())
|
||||
CARBON_CHECK(closing_token_info.kind.IsClosingSymbol())
|
||||
<< "The token must be an closing group symbol!";
|
||||
return closing_token_info.opening_token;
|
||||
}
|
||||
@@ -756,7 +759,7 @@ auto TokenizedBuffer::PrintWidths::Widen(const PrintWidths& widths) -> void {
|
||||
//
|
||||
// This routine requires its argument to be *non-negative*.
|
||||
static auto ComputeDecimalPrintedWidth(int number) -> int {
|
||||
CHECK(number >= 0) << "Negative numbers are not supported.";
|
||||
CARBON_CHECK(number >= 0) << "Negative numbers are not supported.";
|
||||
if (number == 0) {
|
||||
return 1;
|
||||
}
|
||||
@@ -887,7 +890,7 @@ auto TokenizedBuffer::TokenIterator::Print(llvm::raw_ostream& output) const
|
||||
|
||||
auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
|
||||
const char* loc) -> DiagnosticLocation {
|
||||
CHECK(StringRefContainsPointer(buffer_->source_->text(), loc))
|
||||
CARBON_CHECK(StringRefContainsPointer(buffer_->source_->text(), loc))
|
||||
<< "location not within buffer";
|
||||
int64_t offset = loc - buffer_->source_->text().begin();
|
||||
|
||||
@@ -901,7 +904,7 @@ auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
|
||||
line_it == buffer_->line_infos_.end();
|
||||
|
||||
// Step back one line to find the line containing the given position.
|
||||
CHECK(line_it != buffer_->line_infos_.begin())
|
||||
CARBON_CHECK(line_it != buffer_->line_infos_.begin())
|
||||
<< "location precedes the start of the first line";
|
||||
--line_it;
|
||||
int line_number = line_it - buffer_->line_infos_.begin();
|
||||
|
||||
Reference in New Issue
Block a user