mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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:
@@ -78,10 +78,10 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
|
||||
return Success();
|
||||
case StatementKind::If: {
|
||||
auto& if_stmt = cast<If>(*statement);
|
||||
RETURN_IF_ERROR(
|
||||
CARBON_RETURN_IF_ERROR(
|
||||
ResolveControlFlow(&if_stmt.then_block(), loop, function));
|
||||
if (if_stmt.else_block().has_value()) {
|
||||
RETURN_IF_ERROR(
|
||||
CARBON_RETURN_IF_ERROR(
|
||||
ResolveControlFlow(*if_stmt.else_block(), loop, function));
|
||||
}
|
||||
return Success();
|
||||
@@ -89,25 +89,26 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
|
||||
case StatementKind::Block: {
|
||||
auto& block = cast<Block>(*statement);
|
||||
for (auto* block_statement : block.statements()) {
|
||||
RETURN_IF_ERROR(ResolveControlFlow(block_statement, loop, function));
|
||||
CARBON_RETURN_IF_ERROR(
|
||||
ResolveControlFlow(block_statement, loop, function));
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
case StatementKind::While:
|
||||
RETURN_IF_ERROR(ResolveControlFlow(&cast<While>(*statement).body(),
|
||||
statement, function));
|
||||
CARBON_RETURN_IF_ERROR(ResolveControlFlow(&cast<While>(*statement).body(),
|
||||
statement, function));
|
||||
return Success();
|
||||
case StatementKind::Match: {
|
||||
auto& match = cast<Match>(*statement);
|
||||
for (Match::Clause& clause : match.clauses()) {
|
||||
RETURN_IF_ERROR(
|
||||
CARBON_RETURN_IF_ERROR(
|
||||
ResolveControlFlow(&clause.statement(), loop, function));
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
case StatementKind::Continuation:
|
||||
RETURN_IF_ERROR(ResolveControlFlow(&cast<Continuation>(*statement).body(),
|
||||
std::nullopt, std::nullopt));
|
||||
CARBON_RETURN_IF_ERROR(ResolveControlFlow(
|
||||
&cast<Continuation>(*statement).body(), std::nullopt, std::nullopt));
|
||||
return Success();
|
||||
case StatementKind::ExpressionStatement:
|
||||
case StatementKind::Assign:
|
||||
@@ -124,7 +125,7 @@ auto ResolveControlFlow(Nonnull<Declaration*> declaration) -> ErrorOr<Success> {
|
||||
auto& function = cast<FunctionDeclaration>(*declaration);
|
||||
if (function.body().has_value()) {
|
||||
FunctionData data = {.declaration = &function};
|
||||
RETURN_IF_ERROR(
|
||||
CARBON_RETURN_IF_ERROR(
|
||||
ResolveControlFlow(*function.body(), std::nullopt, &data));
|
||||
}
|
||||
break;
|
||||
@@ -132,21 +133,21 @@ auto ResolveControlFlow(Nonnull<Declaration*> declaration) -> ErrorOr<Success> {
|
||||
case DeclarationKind::ClassDeclaration: {
|
||||
auto& class_decl = cast<ClassDeclaration>(*declaration);
|
||||
for (Nonnull<Declaration*> member : class_decl.members()) {
|
||||
RETURN_IF_ERROR(ResolveControlFlow(member));
|
||||
CARBON_RETURN_IF_ERROR(ResolveControlFlow(member));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::InterfaceDeclaration: {
|
||||
auto& iface_decl = cast<InterfaceDeclaration>(*declaration);
|
||||
for (Nonnull<Declaration*> member : iface_decl.members()) {
|
||||
RETURN_IF_ERROR(ResolveControlFlow(member));
|
||||
CARBON_RETURN_IF_ERROR(ResolveControlFlow(member));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::ImplDeclaration: {
|
||||
auto& impl_decl = cast<ImplDeclaration>(*declaration);
|
||||
for (Nonnull<Declaration*> member : impl_decl.members()) {
|
||||
RETURN_IF_ERROR(ResolveControlFlow(member));
|
||||
CARBON_RETURN_IF_ERROR(ResolveControlFlow(member));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -161,7 +162,7 @@ auto ResolveControlFlow(Nonnull<Declaration*> declaration) -> ErrorOr<Success> {
|
||||
|
||||
auto ResolveControlFlow(AST& ast) -> ErrorOr<Success> {
|
||||
for (auto declaration : ast.declarations) {
|
||||
RETURN_IF_ERROR(ResolveControlFlow(declaration));
|
||||
CARBON_RETURN_IF_ERROR(ResolveControlFlow(declaration));
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user