Commit 45addf1f authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[torque] Also predeclare generics

This allows generic specializations to appear
before the generic itself.

Bug: v8:7793
Change-Id: I127fb49380a14cdf2a63854117d25fc865a95352
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1599178Reviewed-by: 's avatarSimon Zünd <szuend@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61290}
parent 0dfe759f
......@@ -22,7 +22,7 @@ Namespace* GetOrCreateNamespace(const std::string& name) {
return existing_namespaces.front();
}
void TypeDeclarationVisitor::Predeclare(Declaration* decl) {
void PredeclarationVisitor::Predeclare(Declaration* decl) {
CurrentSourcePosition::Scope scope(decl->pos);
switch (decl->kind) {
#define ENUM_ITEM(name) \
......@@ -32,8 +32,10 @@ void TypeDeclarationVisitor::Predeclare(Declaration* decl) {
#undef ENUM_ITEM
case AstNode::Kind::kNamespaceDeclaration:
return Predeclare(NamespaceDeclaration::cast(decl));
case AstNode::Kind::kGenericDeclaration:
return Predeclare(GenericDeclaration::cast(decl));
default:
// This visitor only processes type declaration nodes.
// Only processes type declaration nodes, namespaces and generics.
break;
}
}
......@@ -204,10 +206,6 @@ void DeclarationVisitor::Visit(StandardDeclaration* decl) {
Visit(decl->callable, signature, decl->body);
}
void DeclarationVisitor::Visit(GenericDeclaration* decl) {
Declarations::DeclareGeneric(decl->callable->name, decl);
}
void DeclarationVisitor::Visit(SpecializationDeclaration* decl) {
if ((decl->body != nullptr) == decl->external) {
std::stringstream stream;
......@@ -382,7 +380,7 @@ Callable* DeclarationVisitor::Specialize(
return callable;
}
void TypeDeclarationVisitor::ResolvePredeclarations() {
void PredeclarationVisitor::ResolvePredeclarations() {
for (auto& p : GlobalContext::AllDeclarables()) {
if (const TypeAlias* alias = TypeAlias::DynamicCast(p.get())) {
CurrentScope::Scope scope_activator(alias->ParentScope());
......
......@@ -20,7 +20,7 @@ namespace torque {
Namespace* GetOrCreateNamespace(const std::string& name);
class TypeDeclarationVisitor {
class PredeclarationVisitor {
public:
static void Predeclare(Ast* ast) {
CurrentScope::Scope current_namespace(GlobalContext::GetDefaultNamespace());
......@@ -37,6 +37,9 @@ class TypeDeclarationVisitor {
static void Predeclare(TypeDeclaration* decl) {
Declarations::PredeclareTypeAlias(decl->name, decl, false);
}
static void Predeclare(GenericDeclaration* decl) {
Declarations::DeclareGeneric(decl->callable->name, decl);
}
};
class DeclarationVisitor {
......@@ -85,7 +88,9 @@ class DeclarationVisitor {
static void Visit(ConstDeclaration* decl);
static void Visit(StandardDeclaration* decl);
static void Visit(GenericDeclaration* decl);
static void Visit(GenericDeclaration* decl) {
// The PredeclarationVisitor already handled this case.
}
static void Visit(SpecializationDeclaration* decl);
static void Visit(ExternConstDeclaration* decl);
static void Visit(CppIncludeDeclaration* decl);
......
......@@ -55,8 +55,8 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
// Two-step process of predeclaration + resolution allows to resolve type
// declarations independent of the order they are given.
TypeDeclarationVisitor::Predeclare(GlobalContext::Get().ast());
TypeDeclarationVisitor::ResolvePredeclarations();
PredeclarationVisitor::Predeclare(GlobalContext::Get().ast());
PredeclarationVisitor::ResolvePredeclarations();
// Process other declarations.
DeclarationVisitor::Visit(GlobalContext::Get().ast());
......
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