mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 11:11:04 +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:
@@ -37,7 +37,7 @@ auto ParseTree::postorder() const -> llvm::iterator_range<PostorderIterator> {
|
||||
|
||||
auto ParseTree::postorder(Node n) const
|
||||
-> llvm::iterator_range<PostorderIterator> {
|
||||
CHECK(n.is_valid());
|
||||
CARBON_CHECK(n.is_valid());
|
||||
// The postorder ends after this node, the root, and begins at the start of
|
||||
// its subtree.
|
||||
int end_index = n.index_ + 1;
|
||||
@@ -48,7 +48,7 @@ auto ParseTree::postorder(Node n) const
|
||||
|
||||
auto ParseTree::children(Node n) const
|
||||
-> llvm::iterator_range<SiblingIterator> {
|
||||
CHECK(n.is_valid());
|
||||
CARBON_CHECK(n.is_valid());
|
||||
int end_index = n.index_ - node_impls_[n.index_].subtree_size;
|
||||
return {SiblingIterator(*this, Node(n.index_ - 1)),
|
||||
SiblingIterator(*this, Node(end_index))};
|
||||
@@ -61,22 +61,22 @@ auto ParseTree::roots() const -> llvm::iterator_range<SiblingIterator> {
|
||||
}
|
||||
|
||||
auto ParseTree::node_has_error(Node n) const -> bool {
|
||||
CHECK(n.is_valid());
|
||||
CARBON_CHECK(n.is_valid());
|
||||
return node_impls_[n.index_].has_error;
|
||||
}
|
||||
|
||||
auto ParseTree::node_kind(Node n) const -> ParseNodeKind {
|
||||
CHECK(n.is_valid());
|
||||
CARBON_CHECK(n.is_valid());
|
||||
return node_impls_[n.index_].kind;
|
||||
}
|
||||
|
||||
auto ParseTree::node_token(Node n) const -> TokenizedBuffer::Token {
|
||||
CHECK(n.is_valid());
|
||||
CARBON_CHECK(n.is_valid());
|
||||
return node_impls_[n.index_].token;
|
||||
}
|
||||
|
||||
auto ParseTree::GetNodeText(Node n) const -> llvm::StringRef {
|
||||
CHECK(n.is_valid());
|
||||
CARBON_CHECK(n.is_valid());
|
||||
return tokens_->GetTokenText(node_impls_[n.index_].token);
|
||||
}
|
||||
|
||||
@@ -126,12 +126,12 @@ auto ParseTree::Print(llvm::raw_ostream& output) const -> void {
|
||||
}
|
||||
|
||||
// This node is finished, so close it up.
|
||||
CHECK(n_impl.subtree_size == 1)
|
||||
CARBON_CHECK(n_impl.subtree_size == 1)
|
||||
<< "Subtree size must always be a positive integer!";
|
||||
output << "}";
|
||||
|
||||
int next_depth = node_stack.empty() ? 0 : node_stack.back().second;
|
||||
CHECK(next_depth <= depth) << "Cannot have the next depth increase!";
|
||||
CARBON_CHECK(next_depth <= depth) << "Cannot have the next depth increase!";
|
||||
for (int close_children_count : llvm::seq(0, depth - next_depth)) {
|
||||
(void)close_children_count;
|
||||
output << "]}";
|
||||
|
||||
Reference in New Issue
Block a user