Reland "[torque] Add ClassFlag(s) enum"

This reverts commit a0fc5d72fd.

Reason for revert: This now breaks other bot *shrug*.

Original change's description:
> Revert "[torque] Add ClassFlag(s) enum"
> 
> This reverts commit 5343d789f0.
> 
> Reason for revert: breaks roll: https://chromium-review.googlesource.com/c/chromium/src/+/1610023
> 
> Original change's description:
> > [torque] Add ClassFlag(s) enum
> > 
> > This removes the need for passing ever more boolean flags
> > to the class constructor.
> > 
> > Change-Id: I0271e1b96585252183dcf070eb440ebdaf2a270f
> > Bug: v8:7793
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1607760
> > Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
> > Reviewed-by: Daniel Clifford <danno@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#61444}
> 
> TBR=danno@chromium.org,sigurds@chromium.org,tebbi@chromium.org
> 
> Change-Id: I38566d8f4203f9cf1e759a3e915cafa86460e6e4
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1609807
> Reviewed-by: Michael Hablich <hablich@chromium.org>
> Commit-Queue: Michael Hablich <hablich@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61456}

TBR=danno@chromium.org,sigurds@chromium.org,hablich@chromium.org,tebbi@chromium.org

Change-Id: I9edb9a95cd30b6f4c9fd7502eb3a1124e3e8d977
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7793
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1609808
Reviewed-by: Michael Hablich <hablich@chromium.org>
Commit-Queue: Michael Hablich <hablich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61458}
This commit is contained in:
Michael Hablich 2019-05-13 19:01:23 +00:00 committed by Commit Bot
parent 7927b271ee
commit 182f510106
7 changed files with 54 additions and 50 deletions

View File

@ -924,25 +924,18 @@ struct StructDeclaration : TypeDeclaration {
struct ClassDeclaration : TypeDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ClassDeclaration)
ClassDeclaration(SourcePosition pos, Identifier* name, bool is_extern,
bool generate_print, bool generate_verify, bool transient,
ClassDeclaration(SourcePosition pos, Identifier* name, ClassFlags flags,
base::Optional<TypeExpression*> super,
base::Optional<std::string> generates,
std::vector<Declaration*> methods,
std::vector<ClassFieldExpression> fields)
: TypeDeclaration(kKind, pos, name),
is_extern(is_extern),
generate_print(generate_print),
generate_verify(generate_verify),
transient(transient),
flags(flags),
super(super),
generates(std::move(generates)),
methods(std::move(methods)),
fields(std::move(fields)) {}
bool is_extern;
bool generate_print;
bool generate_verify;
bool transient;
ClassFlags flags;
base::Optional<TypeExpression*> super;
base::Optional<std::string> generates;
std::vector<Declaration*> methods;

View File

@ -8,6 +8,8 @@
#include <cstring>
#include <string>
#include "src/base/flags.h"
namespace v8 {
namespace internal {
namespace torque {
@ -59,6 +61,16 @@ inline std::string GetConstexprName(const std::string& name) {
return CONSTEXPR_TYPE_PREFIX + name;
}
enum class ClassFlag {
kNone = 0,
kExtern = 1 << 0,
kGeneratePrint = 1 << 1,
kGenerateVerify = 1 << 2,
kTransient = 1 << 3,
kHasIndexedField = 1 << 4
};
using ClassFlags = base::Flags<ClassFlag>;
} // namespace torque
} // namespace internal
} // namespace v8

View File

@ -656,11 +656,17 @@ class AnnotationSet {
base::Optional<ParseResult> MakeClassDeclaration(
ParseResultIterator* child_results) {
AnnotationSet annotations(child_results, {"@generatePrint", "@noVerifier"});
AnnotationSet annotations(child_results,
{"@generatePrint", "@noVerifier"});
ClassFlags flags = ClassFlag::kNone;
bool generate_print = annotations.Contains("@generatePrint");
if (generate_print) flags |= ClassFlag::kGeneratePrint;
bool generate_verify = !annotations.Contains("@noVerifier");
if (generate_verify) flags |= ClassFlag::kGenerateVerify;
auto is_extern = child_results->NextAs<bool>();
if (is_extern) flags |= ClassFlag::kExtern;
auto transient = child_results->NextAs<bool>();
if (transient) flags |= ClassFlag::kTransient;
auto name = child_results->NextAs<Identifier*>();
if (!IsValidTypeName(name->value)) {
NamingConventionError("Type", name->value, "UpperCamelCase");
@ -682,8 +688,8 @@ base::Optional<ParseResult> MakeClassDeclaration(
});
Declaration* result = MakeNode<ClassDeclaration>(
name, is_extern, generate_print, generate_verify, transient,
std::move(extends), std::move(generates), std::move(methods), fields);
name, flags, std::move(extends), std::move(generates), std::move(methods),
fields);
return ParseResult{result};
}

View File

@ -34,14 +34,11 @@ class TypeOracle : public ContextualClass<TypeOracle> {
}
static ClassType* GetClassType(const Type* parent, const std::string& name,
bool is_extern, bool generate_print,
bool generate_verify, bool transient,
const std::string& generates,
ClassFlags flags, const std::string& generates,
ClassDeclaration* decl,
const TypeAlias* alias) {
ClassType* result = new ClassType(
parent, CurrentNamespace(), name, is_extern, generate_print,
generate_verify, transient, generates, decl, alias);
ClassType* result = new ClassType(parent, CurrentNamespace(), name, flags,
generates, decl, alias);
Get().struct_types_.push_back(std::unique_ptr<ClassType>(result));
return result;
}

View File

@ -130,7 +130,7 @@ const ClassType* TypeVisitor::ComputeType(ClassDeclaration* decl) {
const TypeAlias* alias =
Declarations::LookupTypeAlias(QualifiedName(decl->name->value));
DCHECK_EQ(*alias->delayed_, decl);
if (decl->is_extern) {
if (decl->flags & ClassFlag::kExtern) {
if (!decl->super) {
ReportError("Extern class must extend another type.");
}
@ -150,9 +150,8 @@ const ClassType* TypeVisitor::ComputeType(ClassDeclaration* decl) {
generates = ComputeGeneratesType(decl->generates, enforce_tnode_type);
}
new_class = TypeOracle::GetClassType(
super_type, decl->name->value, decl->is_extern, decl->generate_print,
decl->generate_verify, decl->transient, generates, decl, alias);
new_class = TypeOracle::GetClassType(super_type, decl->name->value,
decl->flags, generates, decl, alias);
} else {
if (decl->super) {
ReportError("Only extern classes can inherit.");
@ -160,10 +159,9 @@ const ClassType* TypeVisitor::ComputeType(ClassDeclaration* decl) {
if (decl->generates) {
ReportError("Only extern classes can specify a generated type.");
}
new_class = TypeOracle::GetClassType(
TypeOracle::GetTaggedType(), decl->name->value, decl->is_extern,
decl->generate_print, decl->generate_verify, decl->transient,
"FixedArray", decl, alias);
new_class =
TypeOracle::GetClassType(TypeOracle::GetTaggedType(), decl->name->value,
decl->flags, "FixedArray", decl, alias);
}
GlobalContext::RegisterClass(decl->name->value, new_class);
return new_class;
@ -226,7 +224,7 @@ void TypeVisitor::VisitClassFieldsAndMethods(
CurrentSourcePosition::Scope position_activator(
field_expression.name_and_type.type->pos);
const Type* field_type = ComputeType(field_expression.name_and_type.type);
if (!class_declaration->is_extern) {
if (!(class_declaration->flags & ClassFlag::kExtern)) {
if (!field_type->IsSubtypeOf(TypeOracle::GetTaggedType())) {
ReportError("non-extern classes do not support untagged fields");
}

View File

@ -292,24 +292,21 @@ std::string StructType::ToExplicitString() const {
constexpr ClassFlags ClassType::kInternalFlags;
ClassType::ClassType(const Type* parent, Namespace* nspace,
const std::string& name, bool is_extern,
bool generate_print, bool generate_verify, bool transient,
const std::string& name, ClassFlags flags,
const std::string& generates, const ClassDeclaration* decl,
const TypeAlias* alias)
: AggregateType(Kind::kClassType, parent, nspace, name),
is_extern_(is_extern),
generate_print_(generate_print),
generate_verify_(generate_verify),
transient_(transient),
size_(0),
has_indexed_field_(false),
flags_(flags & ~(kInternalFlags)),
generates_(generates),
decl_(decl),
alias_(alias) {}
alias_(alias) {
DCHECK_EQ(flags & kInternalFlags, 0);
}
bool ClassType::HasIndexedField() const {
if (!is_finalized_) Finalize();
return has_indexed_field_;
return flags_ & ClassFlag::kHasIndexedField;
}
std::string ClassType::GetGeneratedTNodeTypeNameImpl() const {
@ -341,7 +338,7 @@ void ClassType::Finalize() const {
CurrentSourcePosition::Scope position_activator(decl_->pos);
if (parent()) {
if (const ClassType* super_class = ClassType::DynamicCast(parent())) {
has_indexed_field_ = super_class->HasIndexedField();
if (super_class->HasIndexedField()) flags_ |= ClassFlag::kHasIndexedField;
}
}
TypeVisitor::VisitClassFieldsAndMethods(const_cast<ClassType*>(this),

View File

@ -503,14 +503,20 @@ class TypeAlias;
class ClassType final : public AggregateType {
public:
static constexpr ClassFlags kInternalFlags = ClassFlag::kHasIndexedField;
DECLARE_TYPE_BOILERPLATE(ClassType)
std::string ToExplicitString() const override;
std::string GetGeneratedTypeNameImpl() const override;
std::string GetGeneratedTNodeTypeNameImpl() const override;
bool IsExtern() const { return is_extern_; }
bool ShouldGeneratePrint() const { return generate_print_; }
bool ShouldGenerateVerify() const { return generate_verify_; }
bool IsTransient() const override { return transient_; }
bool IsExtern() const { return flags_ & ClassFlag::kExtern; }
bool ShouldGeneratePrint() const {
return flags_ & ClassFlag::kGeneratePrint;
}
bool ShouldGenerateVerify() const {
return flags_ & ClassFlag::kGenerateVerify;
}
bool IsTransient() const override { return flags_ & ClassFlag::kTransient; }
bool HasIndexedField() const override;
size_t size() const { return size_; }
const ClassType* GetSuperClass() const {
@ -522,7 +528,7 @@ class ClassType final : public AggregateType {
bool AllowInstantiation() const;
const Field& RegisterField(Field field) override {
if (field.index) {
has_indexed_field_ = true;
flags_ |= ClassFlag::kHasIndexedField;
}
return AggregateType::RegisterField(field);
}
@ -532,16 +538,11 @@ class ClassType final : public AggregateType {
friend class TypeOracle;
friend class TypeVisitor;
ClassType(const Type* parent, Namespace* nspace, const std::string& name,
bool is_extern, bool generate_print, bool generate_verify,
bool transient, const std::string& generates,
ClassFlags flags, const std::string& generates,
const ClassDeclaration* decl, const TypeAlias* alias);
bool is_extern_;
bool generate_print_;
bool generate_verify_;
bool transient_;
size_t size_;
mutable bool has_indexed_field_;
mutable ClassFlags flags_;
const std::string generates_;
const ClassDeclaration* decl_;
const TypeAlias* alias_;