Commit 41578273 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[torque] Emit source position comments to generated files

Change-Id: I36d230fa3e51eb27109a8dd2adc0e7802fc77a7d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3177221Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77007}
parent e5c2de47
...@@ -14,6 +14,8 @@ void Function::PrintDeclarationHeader(std::ostream& stream, ...@@ -14,6 +14,8 @@ void Function::PrintDeclarationHeader(std::ostream& stream,
if (!description_.empty()) { if (!description_.empty()) {
stream << std::string(indentation, ' ') << "// " << description_ << "\n"; stream << std::string(indentation, ' ') << "// " << description_ << "\n";
} }
stream << std::string(indentation, ' ') << "// " << PositionAsString(pos_)
<< "\n";
stream << std::string(indentation, ' '); stream << std::string(indentation, ' ');
if (IsExport()) stream << "V8_EXPORT_PRIVATE "; if (IsExport()) stream << "V8_EXPORT_PRIVATE ";
if (IsV8Inline()) if (IsV8Inline())
...@@ -63,6 +65,8 @@ void Function::PrintInlineDefinition( ...@@ -63,6 +65,8 @@ void Function::PrintInlineDefinition(
void Function::PrintBeginDefinition(std::ostream& stream, void Function::PrintBeginDefinition(std::ostream& stream,
int indentation) const { int indentation) const {
stream << std::string(indentation, ' ') << "// " << PositionAsString(pos_)
<< "\n";
std::string scope; std::string scope;
if (owning_class_) { if (owning_class_) {
scope = owning_class_->GetName(); scope = owning_class_->GetName();
......
...@@ -71,9 +71,13 @@ class Function { ...@@ -71,9 +71,13 @@ class Function {
}; };
explicit Function(std::string name) explicit Function(std::string name)
: owning_class_(nullptr), name_(std::move(name)) {} : pos_(CurrentSourcePosition::Get()),
owning_class_(nullptr),
name_(std::move(name)) {}
Function(Class* owning_class, std::string name) Function(Class* owning_class, std::string name)
: owning_class_(owning_class), name_(std::move(name)) {} : pos_(CurrentSourcePosition::Get()),
owning_class_(owning_class),
name_(std::move(name)) {}
~Function() = default; ~Function() = default;
static Function DefaultGetter(std::string return_type, Class* owner, static Function DefaultGetter(std::string return_type, Class* owner,
...@@ -159,6 +163,7 @@ class Function { ...@@ -159,6 +163,7 @@ class Function {
void PrintDeclarationHeader(std::ostream& stream, int indentation) const; void PrintDeclarationHeader(std::ostream& stream, int indentation) const;
private: private:
SourcePosition pos_;
Class* owning_class_; Class* owning_class_;
std::string description_; std::string description_;
std::string name_; std::string name_;
......
...@@ -3726,6 +3726,7 @@ class MacroFieldOffsetsGenerator : public FieldOffsetsGenerator { ...@@ -3726,6 +3726,7 @@ class MacroFieldOffsetsGenerator : public FieldOffsetsGenerator {
<< "_FIELDS(V) \\\n"; << "_FIELDS(V) \\\n";
} }
void WriteField(const Field& f, const std::string& size_string) override { void WriteField(const Field& f, const std::string& size_string) override {
out_ << "/* " << PositionAsString(f.pos) << " */ \\\n";
out_ << "V(k" << CamelifyString(f.name_and_type.name) << "Offset, " out_ << "V(k" << CamelifyString(f.name_and_type.name) << "Offset, "
<< size_string << ") \\\n"; << size_string << ") \\\n";
} }
...@@ -3868,7 +3869,9 @@ class ClassFieldOffsetGenerator : public FieldOffsetsGenerator { ...@@ -3868,7 +3869,9 @@ class ClassFieldOffsetGenerator : public FieldOffsetsGenerator {
previous_field_end_((parent && parent->IsShape()) ? "P::kSize" previous_field_end_((parent && parent->IsShape()) ? "P::kSize"
: "P::kHeaderSize"), : "P::kHeaderSize"),
gen_name_(gen_name) {} gen_name_(gen_name) {}
void WriteField(const Field& f, const std::string& size_string) override { void WriteField(const Field& f, const std::string& size_string) override {
hdr_ << " // " << PositionAsString(f.pos) << "\n";
std::string field = "k" + CamelifyString(f.name_and_type.name) + "Offset"; std::string field = "k" + CamelifyString(f.name_and_type.name) + "Offset";
std::string field_end = field + "End"; std::string field_end = field + "End";
hdr_ << " static constexpr int " << field << " = " << previous_field_end_ hdr_ << " static constexpr int " << field << " = " << previous_field_end_
...@@ -3877,6 +3880,7 @@ class ClassFieldOffsetGenerator : public FieldOffsetsGenerator { ...@@ -3877,6 +3880,7 @@ class ClassFieldOffsetGenerator : public FieldOffsetsGenerator {
<< size_string << " - 1;\n"; << size_string << " - 1;\n";
previous_field_end_ = field_end + " + 1"; previous_field_end_ = field_end + " + 1";
} }
void WriteFieldOffsetGetter(const Field& f) override { void WriteFieldOffsetGetter(const Field& f) override {
// A static constexpr int is more convenient than a getter if the offset is // A static constexpr int is more convenient than a getter if the offset is
// known. // known.
...@@ -3929,6 +3933,8 @@ class CppClassGenerator { ...@@ -3929,6 +3933,8 @@ class CppClassGenerator {
void GenerateClass(); void GenerateClass();
private: private:
SourcePosition Position();
void GenerateClassConstructors(); void GenerateClassConstructors();
// Generates getter and setter runtime member functions for the given class // Generates getter and setter runtime member functions for the given class
...@@ -4001,7 +4007,7 @@ void CppClassGenerator::GenerateClass() { ...@@ -4001,7 +4007,7 @@ void CppClassGenerator::GenerateClass() {
stream << " return o.Is" << name_ << "();"; stream << " return o.Is" << name_ << "();";
}); });
} }
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(std::is_same<" << name_ << ", D>::value,\n"
...@@ -4016,6 +4022,7 @@ void CppClassGenerator::GenerateClass() { ...@@ -4016,6 +4022,7 @@ void CppClassGenerator::GenerateClass() {
hdr_ << " protected: // not extern or @export\n"; hdr_ << " protected: // not extern or @export\n";
} }
for (const Field& f : type_->fields()) { for (const Field& f : type_->fields()) {
CurrentSourcePosition::Scope scope(f.pos);
std::vector<const Field*> struct_fields; std::vector<const Field*> struct_fields;
GenerateFieldAccessors(f, struct_fields); GenerateFieldAccessors(f, struct_fields);
} }
...@@ -4181,6 +4188,8 @@ void CppClassGenerator::GenerateClassCasts() { ...@@ -4181,6 +4188,8 @@ void CppClassGenerator::GenerateClassCasts() {
}); });
} }
SourcePosition CppClassGenerator::Position() { return type_->GetPosition(); }
void CppClassGenerator::GenerateClassConstructors() { void CppClassGenerator::GenerateClassConstructors() {
const ClassType* typecheck_type = type_; const ClassType* typecheck_type = type_;
while (typecheck_type->IsShape()) { while (typecheck_type->IsShape()) {
...@@ -4619,6 +4628,7 @@ void ImplementationVisitor::GenerateClassDefinitions( ...@@ -4619,6 +4628,7 @@ void ImplementationVisitor::GenerateClassDefinitions(
// Emit forward declarations. // Emit forward declarations.
for (const ClassType* type : TypeOracle::GetClasses()) { for (const ClassType* type : TypeOracle::GetClasses()) {
CurrentSourcePosition::Scope position_activator(type->GetPosition());
auto& streams = GlobalContext::GeneratedPerFile(type->AttributedToFile()); auto& streams = GlobalContext::GeneratedPerFile(type->AttributedToFile());
std::ostream& header = streams.class_definition_headerfile; std::ostream& header = streams.class_definition_headerfile;
std::string name = type->GenerateCppClassDefinitions() std::string name = type->GenerateCppClassDefinitions()
...@@ -4629,6 +4639,7 @@ void ImplementationVisitor::GenerateClassDefinitions( ...@@ -4629,6 +4639,7 @@ void ImplementationVisitor::GenerateClassDefinitions(
} }
for (const ClassType* type : TypeOracle::GetClasses()) { for (const ClassType* type : TypeOracle::GetClasses()) {
CurrentSourcePosition::Scope position_activator(type->GetPosition());
auto& streams = GlobalContext::GeneratedPerFile(type->AttributedToFile()); auto& streams = GlobalContext::GeneratedPerFile(type->AttributedToFile());
std::ostream& header = streams.class_definition_headerfile; std::ostream& header = streams.class_definition_headerfile;
std::ostream& inline_header = streams.class_definition_inline_headerfile; std::ostream& inline_header = streams.class_definition_inline_headerfile;
...@@ -4730,6 +4741,7 @@ void ImplementationVisitor::GenerateClassDefinitions( ...@@ -4730,6 +4741,7 @@ void ImplementationVisitor::GenerateClassDefinitions(
} }
for (const StructType* type : structs_used_in_classes) { for (const StructType* type : structs_used_in_classes) {
CurrentSourcePosition::Scope position_activator(type->GetPosition());
std::ostream& header = std::ostream& header =
GlobalContext::GeneratedPerFile(type->GetPosition().source) GlobalContext::GeneratedPerFile(type->GetPosition().source)
.class_definition_headerfile; .class_definition_headerfile;
...@@ -5294,6 +5306,7 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler( ...@@ -5294,6 +5306,7 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler(
for (auto& declarable : GlobalContext::AllDeclarables()) { for (auto& declarable : GlobalContext::AllDeclarables()) {
TorqueMacro* macro = TorqueMacro::DynamicCast(declarable.get()); TorqueMacro* macro = TorqueMacro::DynamicCast(declarable.get());
if (!(macro && macro->IsExportedToCSA())) continue; if (!(macro && macro->IsExportedToCSA())) continue;
CurrentSourcePosition::Scope position_activator(macro->Position());
cpp::Class assembler("TorqueGeneratedExportedMacrosAssembler"); cpp::Class assembler("TorqueGeneratedExportedMacrosAssembler");
std::vector<std::string> generated_parameter_names; std::vector<std::string> generated_parameter_names;
......
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