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:
Jon Meow
2022-05-06 15:30:25 -07:00
committed by GitHub
parent c4fecf720f
commit af694b97cb
57 changed files with 869 additions and 779 deletions
+23 -21
View File
@@ -58,7 +58,7 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
}
}
default:
FATAL() << "expected Witness, not " << *witness;
CARBON_FATAL() << "expected Witness, not " << *witness;
}
}
switch (v->kind()) {
@@ -121,7 +121,7 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
class_type.witnesses());
}
default:
FATAL() << "field access not allowed for value " << *v;
CARBON_FATAL() << "field access not allowed for value " << *v;
}
}
@@ -130,7 +130,7 @@ auto Value::GetField(Nonnull<Arena*> arena, const FieldPath& path,
-> ErrorOr<Nonnull<const Value*>> {
Nonnull<const Value*> value(this);
for (const FieldPath::Component& field : path.components_) {
ASSIGN_OR_RETURN(value, GetMember(arena, value, field, source_loc));
CARBON_ASSIGN_OR_RETURN(value, GetMember(arena, value, field, source_loc));
}
return value;
}
@@ -155,9 +155,9 @@ static auto SetFieldImpl(
return RuntimeError(source_loc)
<< "field " << (*path_begin).name() << " not in " << *value;
}
ASSIGN_OR_RETURN(it->value,
SetFieldImpl(arena, it->value, path_begin + 1, path_end,
field_value, source_loc));
CARBON_ASSIGN_OR_RETURN(
it->value, SetFieldImpl(arena, it->value, path_begin + 1, path_end,
field_value, source_loc));
return arena->New<StructValue>(elements);
}
case Value::Kind::NominalClassValue: {
@@ -173,13 +173,13 @@ static auto SetFieldImpl(
return RuntimeError(source_loc) << "index " << (*path_begin).name()
<< " out of range in " << *value;
}
ASSIGN_OR_RETURN(elements[index],
SetFieldImpl(arena, elements[index], path_begin + 1,
path_end, field_value, source_loc));
CARBON_ASSIGN_OR_RETURN(
elements[index], SetFieldImpl(arena, elements[index], path_begin + 1,
path_end, field_value, source_loc));
return arena->New<TupleValue>(elements);
}
default:
FATAL() << "field access not allowed for value " << *value;
CARBON_FATAL() << "field access not allowed for value " << *value;
}
}
@@ -400,13 +400,13 @@ void Value::Print(llvm::raw_ostream& out) const {
}
ContinuationValue::StackFragment::~StackFragment() {
CHECK(reversed_todo_.empty())
CARBON_CHECK(reversed_todo_.empty())
<< "All StackFragments must be empty before the Carbon program ends.";
}
void ContinuationValue::StackFragment::StoreReversed(
std::vector<std::unique_ptr<Action>> reversed_todo) {
CHECK(reversed_todo_.empty());
CARBON_CHECK(reversed_todo_.empty());
reversed_todo_ = std::move(reversed_todo);
}
@@ -545,14 +545,14 @@ auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2) -> bool {
case Value::Kind::BindingPlaceholderValue:
case Value::Kind::ContinuationValue:
case Value::Kind::ParameterizedEntityName:
FATAL() << "TypeEqual used to compare non-type values\n"
<< *t1 << "\n"
<< *t2;
CARBON_FATAL() << "TypeEqual used to compare non-type values\n"
<< *t1 << "\n"
<< *t2;
case Value::Kind::Witness:
FATAL() << "TypeEqual: unexpected Witness";
CARBON_FATAL() << "TypeEqual: unexpected Witness";
break;
case Value::Kind::AutoType:
FATAL() << "TypeEqual: unexpected AutoType";
CARBON_FATAL() << "TypeEqual: unexpected AutoType";
break;
}
}
@@ -604,9 +604,10 @@ auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2) -> bool {
case Value::Kind::StructValue: {
const auto& struct_v1 = cast<StructValue>(*v1);
const auto& struct_v2 = cast<StructValue>(*v2);
CHECK(struct_v1.elements().size() == struct_v2.elements().size());
CARBON_CHECK(struct_v1.elements().size() == struct_v2.elements().size());
for (size_t i = 0; i < struct_v1.elements().size(); ++i) {
CHECK(struct_v1.elements()[i].name == struct_v2.elements()[i].name);
CARBON_CHECK(struct_v1.elements()[i].name ==
struct_v2.elements()[i].name);
if (!ValueEqual(struct_v1.elements()[i].value,
struct_v2.elements()[i].value)) {
return false;
@@ -621,7 +622,7 @@ auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2) -> bool {
GetName(cast<ParameterizedEntityName>(v1)->declaration());
std::optional<std::string> name2 =
GetName(cast<ParameterizedEntityName>(v2)->declaration());
CHECK(name1.has_value() && name2.has_value())
CARBON_CHECK(name1.has_value() && name2.has_value())
<< "parameterized name refers to unnamed declaration";
return *name1 == *name2;
}
@@ -654,7 +655,8 @@ auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2) -> bool {
case Value::Kind::LValue:
// TODO: support pointer comparisons once we have a clearer distinction
// between pointers and lvalues.
FATAL() << "ValueEqual does not support this kind of value: " << *v1;
CARBON_FATAL() << "ValueEqual does not support this kind of value: "
<< *v1;
}
}