[torque] Require "extends" clause for class declarations
Currently it's possible to hit an internal compiler error by declaring a non-extern class that doesn't extend anything. It's not very meanigful for a class to not extend from anything, so the parser should enforce this requirement. Change-Id: I38064f87345d28ce84521261bbfd33d9b1c71334 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2153847 Commit-Queue: Seth Brenith <seth.brenith@microsoft.com> Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#67212}
This commit is contained in:
parent
1568a47c0f
commit
412d56f81a
@ -1175,8 +1175,7 @@ struct ClassBody : AstNode {
|
||||
struct ClassDeclaration : TypeDeclaration {
|
||||
DEFINE_AST_NODE_LEAF_BOILERPLATE(ClassDeclaration)
|
||||
ClassDeclaration(SourcePosition pos, Identifier* name, ClassFlags flags,
|
||||
base::Optional<TypeExpression*> super,
|
||||
base::Optional<std::string> generates,
|
||||
TypeExpression* super, base::Optional<std::string> generates,
|
||||
std::vector<Declaration*> methods,
|
||||
std::vector<ClassFieldExpression> fields,
|
||||
InstanceTypeConstraints instance_type_constraints)
|
||||
@ -1188,7 +1187,7 @@ struct ClassDeclaration : TypeDeclaration {
|
||||
fields(std::move(fields)),
|
||||
instance_type_constraints(std::move(instance_type_constraints)) {}
|
||||
ClassFlags flags;
|
||||
base::Optional<TypeExpression*> super;
|
||||
TypeExpression* super;
|
||||
base::Optional<std::string> generates;
|
||||
std::vector<Declaration*> methods;
|
||||
std::vector<ClassFieldExpression> fields;
|
||||
|
@ -906,8 +906,8 @@ base::Optional<ParseResult> MakeClassDeclaration(
|
||||
if (!IsValidTypeName(name->value)) {
|
||||
NamingConventionError("Type", name, "UpperCamelCase");
|
||||
}
|
||||
auto extends = child_results->NextAs<base::Optional<TypeExpression*>>();
|
||||
if (extends && !BasicTypeExpression::DynamicCast(*extends)) {
|
||||
auto extends = child_results->NextAs<TypeExpression*>();
|
||||
if (!BasicTypeExpression::DynamicCast(extends)) {
|
||||
ReportError("Expected type name in extends clause.");
|
||||
}
|
||||
auto generates = child_results->NextAs<base::Optional<std::string>>();
|
||||
@ -2358,8 +2358,7 @@ struct TorqueGrammar : Grammar {
|
||||
&externalString, Token(";")},
|
||||
AsSingletonVector<Declaration*, MakeExternConstDeclaration>()),
|
||||
Rule({annotations, CheckIf(Token("extern")), CheckIf(Token("transient")),
|
||||
OneOf({"class", "shape"}), &name,
|
||||
Optional<TypeExpression*>(Sequence({Token("extends"), &type})),
|
||||
OneOf({"class", "shape"}), &name, Token("extends"), &type,
|
||||
Optional<std::string>(
|
||||
Sequence({Token("generates"), &externalString})),
|
||||
&optionalClassBody},
|
||||
|
@ -247,7 +247,7 @@ const ClassType* TypeVisitor::ComputeType(
|
||||
ClassFlags flags = decl->flags;
|
||||
bool is_shape = flags & ClassFlag::kIsShape;
|
||||
std::string generates = decl->name->value;
|
||||
const Type* super_type = TypeVisitor::ComputeType(*decl->super);
|
||||
const Type* super_type = TypeVisitor::ComputeType(decl->super);
|
||||
if (is_shape) {
|
||||
if (!(flags & ClassFlag::kExtern)) {
|
||||
ReportError("Shapes must be extern, add \"extern\" to the declaration.");
|
||||
@ -266,9 +266,6 @@ const ClassType* TypeVisitor::ComputeType(
|
||||
// support for type-checks on the C++ side.
|
||||
generates = super_class->name();
|
||||
}
|
||||
if (!decl->super) {
|
||||
ReportError("Extern class must extend another type.");
|
||||
}
|
||||
if (super_type != TypeOracle::GetStrongTaggedType()) {
|
||||
const ClassType* super_class = ClassType::DynamicCast(super_type);
|
||||
if (!super_class) {
|
||||
|
Loading…
Reference in New Issue
Block a user