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

[torque] Protect against a confusing error case

I noticed a case where Torque can generate an invalid .inc file, and I
think that it's worth adding a check that can emit an error during
run_torque rather than letting the developer hit a C++ compilation
failure later.

Example error message, if you add @export to StrongDescriptorArray:

Torque Error: Exported class StrongDescriptorArray cannot be in the same
              file as its parent extern class DescriptorArray

Bug: v8:7793
Change-Id: Ia69124a4177bd7a53f95442249fae88cb16e354a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3015655Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#75662}
parent 8cbb823e
......@@ -4135,6 +4135,23 @@ void CppClassGenerator::GenerateClass() {
hdr_ << "};\n\n";
if (type_->ShouldGenerateFullClassDefinition()) {
// If this class extends from another class which is defined in the same tq
// file, and that other class doesn't generate a full class definition, then
// the resulting .inc file would be uncompilable due to ordering
// requirements: the generated file must go before the hand-written
// definition of the base class, but it must also go after that same
// hand-written definition.
base::Optional<const ClassType*> parent = type_->parent()->ClassSupertype();
while (parent) {
if ((*parent)->GenerateCppClassDefinitions() &&
!(*parent)->ShouldGenerateFullClassDefinition() &&
(*parent)->AttributedToFile() == type_->AttributedToFile()) {
Error("Exported ", *type_,
" cannot be in the same file as its parent extern ", **parent);
}
parent = (*parent)->parent()->ClassSupertype();
}
GenerateClassExport(type_, hdr_, inl_);
}
}
......
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