Commit b3d9c0d4 authored by Seth Brenith's avatar Seth Brenith Committed by V8 LUCI CQ

[torque] Format generated files better

This is mostly just whitespace tweaks, plus removing a redundant
public access specifier.

Bug: v8:7793
Change-Id: Ic8b3efe4f707108d29dc2dfd55c46d9a47c48058
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3199603Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#77195}
parent 25210647
...@@ -38,6 +38,9 @@ void Function::PrintDeclarationHeader(std::ostream& stream, ...@@ -38,6 +38,9 @@ void Function::PrintDeclarationHeader(std::ostream& stream,
} }
void Function::PrintDeclaration(std::ostream& stream, int indentation) const { void Function::PrintDeclaration(std::ostream& stream, int indentation) const {
if (indentation == kAutomaticIndentation) {
indentation = owning_class_ ? 2 : 0;
}
PrintDeclarationHeader(stream, indentation); PrintDeclarationHeader(stream, indentation);
stream << ";\n"; stream << ";\n";
} }
...@@ -120,7 +123,7 @@ void File::BeginIncludeGuard(const std::string& name) { ...@@ -120,7 +123,7 @@ void File::BeginIncludeGuard(const std::string& name) {
s() << "#ifndef " << name s() << "#ifndef " << name
<< "\n" << "\n"
"#define " "#define "
<< name << "\n"; << name << "\n\n";
} }
void File::EndIncludeGuard(const std::string& name) { void File::EndIncludeGuard(const std::string& name) {
......
...@@ -149,13 +149,15 @@ class Function { ...@@ -149,13 +149,15 @@ class Function {
return names; return names;
} }
void PrintDeclaration(std::ostream& stream, int indentation = 0) const; static constexpr int kAutomaticIndentation = -1;
void PrintDeclaration(std::ostream& stream,
int indentation = kAutomaticIndentation) const;
void PrintDefinition(std::ostream& stream, void PrintDefinition(std::ostream& stream,
const std::function<void(std::ostream&)>& builder, const std::function<void(std::ostream&)>& builder,
int indentation = 0) const; int indentation = 0) const;
void PrintInlineDefinition(std::ostream& stream, void PrintInlineDefinition(std::ostream& stream,
const std::function<void(std::ostream&)>& builder, const std::function<void(std::ostream&)>& builder,
int indentation = 0) const; int indentation = 2) const;
void PrintBeginDefinition(std::ostream& stream, int indentation = 0) const; void PrintBeginDefinition(std::ostream& stream, int indentation = 0) const;
void PrintEndDefinition(std::ostream& stream, int indentation = 0) const; void PrintEndDefinition(std::ostream& stream, int indentation = 0) const;
......
...@@ -106,6 +106,7 @@ void ImplementationVisitor::BeginGeneratedFiles() { ...@@ -106,6 +106,7 @@ void ImplementationVisitor::BeginGeneratedFiles() {
file << "\n"; file << "\n";
streams.csa_cc.BeginNamespace("v8", "internal"); streams.csa_cc.BeginNamespace("v8", "internal");
streams.csa_ccfile << "\n";
} }
// Output beginning of CSA .h file. // Output beginning of CSA .h file.
{ {
...@@ -118,6 +119,7 @@ void ImplementationVisitor::BeginGeneratedFiles() { ...@@ -118,6 +119,7 @@ void ImplementationVisitor::BeginGeneratedFiles() {
file << "\n"; file << "\n";
streams.csa_header.BeginNamespace("v8", "internal"); streams.csa_header.BeginNamespace("v8", "internal");
streams.csa_headerfile << "\n";
} }
// Output beginning of class definition .cc file. // Output beginning of class definition .cc file.
{ {
...@@ -131,6 +133,7 @@ void ImplementationVisitor::BeginGeneratedFiles() { ...@@ -131,6 +133,7 @@ void ImplementationVisitor::BeginGeneratedFiles() {
} }
streams.class_definition_cc.BeginNamespace("v8", "internal"); streams.class_definition_cc.BeginNamespace("v8", "internal");
streams.class_definition_ccfile << "\n";
} }
} }
} }
...@@ -149,6 +152,7 @@ void ImplementationVisitor::EndGeneratedFiles() { ...@@ -149,6 +152,7 @@ void ImplementationVisitor::EndGeneratedFiles() {
UnderlinifyPath(SourceFileMap::PathFromV8Root(file)) + "_CSA_H_"; UnderlinifyPath(SourceFileMap::PathFromV8Root(file)) + "_CSA_H_";
streams.csa_header.EndNamespace("v8", "internal"); streams.csa_header.EndNamespace("v8", "internal");
streams.csa_headerfile << "\n";
streams.csa_header.EndIncludeGuard(header_define); streams.csa_header.EndIncludeGuard(header_define);
} }
...@@ -394,6 +398,7 @@ void ImplementationVisitor::VisitMacroCommon(Macro* macro) { ...@@ -394,6 +398,7 @@ void ImplementationVisitor::VisitMacroCommon(Macro* macro) {
cpp::Function f = GenerateMacroFunctionDeclaration(macro); cpp::Function f = GenerateMacroFunctionDeclaration(macro);
f.PrintDeclaration(csa_headerfile()); f.PrintDeclaration(csa_headerfile());
csa_headerfile() << "\n";
cpp::File csa_cc(csa_ccfile()); cpp::File csa_cc(csa_ccfile());
...@@ -530,7 +535,6 @@ void ImplementationVisitor::VisitMacroCommon(Macro* macro) { ...@@ -530,7 +535,6 @@ void ImplementationVisitor::VisitMacroCommon(Macro* macro) {
f.PrintEndDefinition(csa_ccfile()); f.PrintEndDefinition(csa_ccfile());
include_guard.reset(); include_guard.reset();
csa_ccfile() << "\n";
} }
void ImplementationVisitor::Visit(TorqueMacro* macro) { void ImplementationVisitor::Visit(TorqueMacro* macro) {
...@@ -4025,18 +4029,21 @@ void CppClassGenerator::GenerateClass() { ...@@ -4025,18 +4029,21 @@ void CppClassGenerator::GenerateClass() {
f.AddParameter("HeapObject", "o"); f.AddParameter("HeapObject", "o");
f.PrintDeclaration(hdr_); f.PrintDeclaration(hdr_);
hdr_ << "\n";
f.PrintDefinition(impl_, [&](std::ostream& stream) { f.PrintDefinition(impl_, [&](std::ostream& stream) {
stream << " return o.Is" << name_ << "();"; stream << " return o.Is" << name_ << "();\n";
}); });
} }
hdr_ << "// Definition" << PositionAsString(Position()) << "\n"; hdr_ << "// Definition " << PositionAsString(Position()) << "\n";
hdr_ << template_decl() << "\n"; hdr_ << template_decl() << "\n";
hdr_ << "class " << gen_name_ << " : public P {\n"; hdr_ << "class " << gen_name_ << " : public P {\n";
hdr_ << " static_assert(std::is_same<" << name_ << ", D>::value,\n" hdr_ << " static_assert(\n"
<< " \"Use this class as direct base for " << name_ << ".\");\n"; << " std::is_same<" << name_ << ", D>::value,\n"
hdr_ << " static_assert(std::is_same<" << super_->name() << ", P>::value,\n" << " \"Use this class as direct base for " << name_ << ".\");\n";
<< " \"Pass in " << super_->name() hdr_ << " static_assert(\n"
<< " as second template parameter for " << gen_name_ << ".\");\n"; << " std::is_same<" << super_->name() << ", P>::value,\n"
<< " \"Pass in " << super_->name()
<< " as second template parameter for " << gen_name_ << ".\");\n\n";
hdr_ << " public: \n"; hdr_ << " public: \n";
hdr_ << " using Super = P;\n"; hdr_ << " using Super = P;\n";
hdr_ << " using TorqueGeneratedClass = " << gen_name_ << "<D,P>;\n\n"; hdr_ << " using TorqueGeneratedClass = " << gen_name_ << "<D,P>;\n\n";
...@@ -4059,7 +4066,7 @@ void CppClassGenerator::GenerateClass() { ...@@ -4059,7 +4066,7 @@ void CppClassGenerator::GenerateClass() {
cpp::Class c(std::move(templateArgs), gen_name_); cpp::Class c(std::move(templateArgs), gen_name_);
if (type_->ShouldGeneratePrint()) { if (type_->ShouldGeneratePrint()) {
hdr_ << "\n DECL_PRINTER(" << name_ << ")\n"; hdr_ << " DECL_PRINTER(" << name_ << ")\n\n";
} }
if (type_->ShouldGenerateVerify()) { if (type_->ShouldGenerateVerify()) {
...@@ -4078,7 +4085,10 @@ void CppClassGenerator::GenerateClass() { ...@@ -4078,7 +4085,10 @@ void CppClassGenerator::GenerateClass() {
impl_ << " TorqueGeneratedClassVerifiers::" << name_ << "Verify(" << name_ impl_ << " TorqueGeneratedClassVerifiers::" << name_ << "Verify(" << name_
<< "::cast(*this), " << "::cast(*this), "
"isolate);\n"; "isolate);\n";
impl_ << "}\n"; impl_ << "}\n\n";
}
if (type_->ShouldGenerateVerify()) {
impl_ << "\n";
} }
hdr_ << "\n"; hdr_ << "\n";
...@@ -4105,7 +4115,7 @@ void CppClassGenerator::GenerateClass() { ...@@ -4105,7 +4115,7 @@ void CppClassGenerator::GenerateClass() {
{ {
cpp::Function f = cpp::Function f =
cpp::Function::DefaultGetter("int", &c, "AllocatedSize"); cpp::Function::DefaultGetter("int", &c, "AllocatedSize");
f.PrintDeclaration(hdr_, 2); f.PrintDeclaration(hdr_);
f.PrintDefinition(inl_, [&](std::ostream& stream) { f.PrintDefinition(inl_, [&](std::ostream& stream) {
stream << " auto slice = " stream << " auto slice = "
...@@ -4201,12 +4211,12 @@ void CppClassGenerator::GenerateClassCasts() { ...@@ -4201,12 +4211,12 @@ void CppClassGenerator::GenerateClassCasts() {
// V8_INLINE static D cast(Object) // V8_INLINE static D cast(Object)
f.PrintInlineDefinition(hdr_, [](std::ostream& stream) { f.PrintInlineDefinition(hdr_, [](std::ostream& stream) {
stream << " return D(object.ptr());\n"; stream << " return D(object.ptr());\n";
}); });
// V8_INLINE static D unchecked_cast(Object) // V8_INLINE static D unchecked_cast(Object)
f.SetName("unchecked_cast"); f.SetName("unchecked_cast");
f.PrintInlineDefinition(hdr_, [](std::ostream& stream) { f.PrintInlineDefinition(hdr_, [](std::ostream& stream) {
stream << " return bit_cast<D>(object);\n"; stream << " return bit_cast<D>(object);\n";
}); });
} }
...@@ -4222,14 +4232,13 @@ void CppClassGenerator::GenerateClassConstructors() { ...@@ -4222,14 +4232,13 @@ void CppClassGenerator::GenerateClassConstructors() {
DCHECK(typecheck_type); DCHECK(typecheck_type);
} }
hdr_ << " public:\n";
hdr_ << " template <class DAlias = D>\n"; hdr_ << " template <class DAlias = D>\n";
hdr_ << " constexpr " << gen_name_ << "() : P() {\n"; hdr_ << " constexpr " << gen_name_ << "() : P() {\n";
hdr_ << " static_assert(std::is_base_of<" << gen_name_ << ", \n"; hdr_ << " static_assert(\n";
hdr_ << " DAlias>::value,\n"; hdr_ << " std::is_base_of<" << gen_name_ << ", DAlias>::value,\n";
hdr_ << " \"class " << gen_name_ << " should be used as direct base for " hdr_ << " \"class " << gen_name_
<< name_ << ".\");\n"; << " should be used as direct base for " << name_ << ".\");\n";
hdr_ << " }\n"; hdr_ << " }\n\n";
hdr_ << " protected:\n"; hdr_ << " protected:\n";
hdr_ << " inline explicit " << gen_name_ << "(Address ptr);\n"; hdr_ << " inline explicit " << gen_name_ << "(Address ptr);\n";
...@@ -4241,7 +4250,7 @@ void CppClassGenerator::GenerateClassConstructors() { ...@@ -4241,7 +4250,7 @@ void CppClassGenerator::GenerateClassConstructors() {
inl_ << "template<class D, class P>\n"; inl_ << "template<class D, class P>\n";
inl_ << "inline " << gen_name_T_ << "::" << gen_name_ << "(Address ptr)\n"; inl_ << "inline " << gen_name_T_ << "::" << gen_name_ << "(Address ptr)\n";
inl_ << " : P(ptr) {\n"; inl_ << " : P(ptr) {\n";
inl_ << " SLOW_DCHECK(Is" << typecheck_type->name() inl_ << " SLOW_DCHECK(Is" << typecheck_type->name()
<< "_NonInline(*this));\n"; << "_NonInline(*this));\n";
inl_ << "}\n"; inl_ << "}\n";
...@@ -4249,7 +4258,7 @@ void CppClassGenerator::GenerateClassConstructors() { ...@@ -4249,7 +4258,7 @@ void CppClassGenerator::GenerateClassConstructors() {
inl_ << "template<class D, class P>\n"; inl_ << "template<class D, class P>\n";
inl_ << "inline " << gen_name_T_ << "::" << gen_name_ inl_ << "inline " << gen_name_T_ << "::" << gen_name_
<< "(Address ptr, HeapObject::AllowInlineSmiStorage allow_smi)\n"; << "(Address ptr, HeapObject::AllowInlineSmiStorage allow_smi)\n";
inl_ << " : P(ptr, allow_smi) {\n"; inl_ << " : P(ptr, allow_smi) {\n";
inl_ << " SLOW_DCHECK(" inl_ << " SLOW_DCHECK("
<< "(allow_smi == HeapObject::AllowInlineSmiStorage::kAllowBeingASmi" << "(allow_smi == HeapObject::AllowInlineSmiStorage::kAllowBeingASmi"
" && this->IsSmi()) || Is" " && this->IsSmi()) || Is"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment