Skip to content
Permalink
Browse files

[torque] move class tests to unittests

This avoids the generation of fake external classes.

Bug: v8:7793
Change-Id: I9744b299d3ec474d72b298b4f6143f95e345d1d9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1625991
Reviewed-by: Simon Zünd <szuend@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61778}
  • Loading branch information...
tebbi authored and Commit Bot committed May 23, 2019
1 parent b509f21 commit f589d56101783d915f8350fd64dc89c9557022e6
Showing with 204 additions and 148 deletions.
  1. +39 −59 src/torque/implementation-visitor.cc
  2. +0 −71 test/torque/test-torque.tq
  3. +165 −18 test/unittests/torque/torque-unittest.cc
@@ -155,68 +155,48 @@ void ImplementationVisitor::Visit(NamespaceConstant* decl) {

void ImplementationVisitor::Visit(TypeAlias* alias) {
if (alias->IsRedeclaration()) return;
const ClassType* class_type = ClassType::DynamicCast(alias->type());
if (class_type && class_type->IsExtern()) {
// Classes that are in the default namespace are defined in the C++
// world and all of their fields and methods are declared explicitly.
// Internal classes (e.g. ones used for testing that are not in the default
// name space) need to be defined by Torque.
// TODO(danno): This is a pretty cheesy hack for now. There should be a more
// robust mechanism for this, e.g. declaring classes 'extern' or something.
if (class_type->nspace()->IsTestNamespace()) {
const ClassType* super = class_type->GetSuperClass();
std::string class_name{super->GetGeneratedTNodeTypeName()};
header_out() << " class " << class_type->name() << " : public "
<< class_name << " {\n";
header_out() << " public:\n";
header_out() << " DEFINE_FIELD_OFFSET_CONSTANTS(" << class_name
<< "::";
header_out() << (super->IsAbstract() ? "kHeaderSize" : "kSize");
header_out() << ", TORQUE_GENERATED_"
<< CapifyStringWithUnderscores(class_type->name())
<< "_FIELDS)\n";
header_out() << " };\n";
} else if (!class_type->nspace()->IsDefaultNamespace()) {
ReportError(
"extern classes are currently only supported in the default and test "
"namespaces");
}
return;
}
const StructType* struct_type = StructType::DynamicCast(alias->type());
if (!struct_type) return;
const std::string& name = struct_type->name();
header_out() << " struct " << name << " {\n";
for (auto& field : struct_type->fields()) {
header_out() << " " << field.name_and_type.type->GetGeneratedTypeName();
header_out() << " " << field.name_and_type.name << ";\n";
}
header_out() << "\n std::tuple<";
bool first = true;
for (const Type* type : LowerType(struct_type)) {
if (!first) {
header_out() << ", ";
}
first = false;
header_out() << type->GetGeneratedTypeName();
}
header_out() << "> Flatten() const {\n"
<< " return std::tuple_cat(";
first = true;
for (auto& field : struct_type->fields()) {
if (!first) {
header_out() << ", ";
if (const ClassType* class_type = ClassType::DynamicCast(alias->type())) {
if (class_type->IsExtern() && !class_type->nspace()->IsDefaultNamespace()) {
Error(
"extern classes are currently only supported in the default "
"namespace");
}
} else if (const StructType* struct_type =
StructType::DynamicCast(alias->type())) {
const std::string& name = struct_type->name();
header_out() << " struct " << name << " {\n";
for (auto& field : struct_type->fields()) {
header_out() << " "
<< field.name_and_type.type->GetGeneratedTypeName();
header_out() << " " << field.name_and_type.name << ";\n";
}
header_out() << "\n std::tuple<";
bool first = true;
for (const Type* type : LowerType(struct_type)) {
if (!first) {
header_out() << ", ";
}
first = false;
header_out() << type->GetGeneratedTypeName();
}
first = false;
if (field.name_and_type.type->IsStructType()) {
header_out() << field.name_and_type.name << ".Flatten()";
} else {
header_out() << "std::make_tuple(" << field.name_and_type.name << ")";
header_out() << "> Flatten() const {\n"
<< " return std::tuple_cat(";
first = true;
for (auto& field : struct_type->fields()) {
if (!first) {
header_out() << ", ";
}
first = false;
if (field.name_and_type.type->IsStructType()) {
header_out() << field.name_and_type.name << ".Flatten()";
} else {
header_out() << "std::make_tuple(" << field.name_and_type.name << ")";
}
}
header_out() << ");\n";
header_out() << " }\n";
header_out() << " };\n";
}
header_out() << ");\n";
header_out() << " }\n";
header_out() << " };\n";
}

VisitResult ImplementationVisitor::InlineMacro(
@@ -823,59 +823,6 @@ namespace test {
assert(a.b.GetX() == 2);
}

@noVerifier
extern class TestClassWithAllTypes extends JSObject {
a: int8;
b: uint8;
b2: uint8;
b3: uint8;
c: int16;
d: uint16;
e: int32;
f: uint32;
g: RawPtr;
h: intptr;
i: uintptr;
}

// This class should throw alignment errors if @if decorators aren't
// working.
@noVerifier
extern class PreprocessingTest extends JSObject {
@if(FALSE_FOR_TESTING) a: int8;
@if(TRUE_FOR_TESTING) a: int16;
b: int16;
d: int32;
@ifnot(TRUE_FOR_TESTING) e: int8;
@ifnot(FALSE_FOR_TESTING) f: int16;
g: int16;
h: int32;
}

@export
macro TestClassWithAllTypesLoadsAndStores(
t: TestClassWithAllTypes, r: RawPtr, v1: int8, v2: uint8, v3: int16,
v4: uint16) {
t.a = v1;
t.b = v2;
t.c = v3;
t.d = v4;
t.e = 0;
t.f = 0;
t.g = r;
t.h = 0;
t.i = 0;
t.a = t.a;
t.b = t.b;
t.c = t.c;
t.d = t.d;
t.e = t.e;
t.f = t.f;
t.g = t.g;
t.h = t.h;
t.i = t.i;
}

class InternalClass {
Flip() labels NotASmi {
const tmp = Cast<Smi>(this.b) otherwise NotASmi;
@@ -956,24 +903,6 @@ namespace test {
check(array.b == 9);
}

type Baztype = Foo | FooType;

@abstract
@noVerifier
extern class Foo extends JSObject {
fooField: FooType;
}

@noVerifier
extern class Bar extends Foo {
barField: Bartype;
bazfield: Baztype;
}

type Bartype = FooType;

type FooType = Smi | Bar;

@export
macro TestStaticAssert() {
StaticAssert(1 + 2 == 3);

0 comments on commit f589d56

Please sign in to comment.
You can’t perform that action at this time.