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) { ...@@ -22,7 +22,7 @@ Namespace* GetOrCreateNamespace(const std::string& name) {
return existing_namespaces.front(); return existing_namespaces.front();
} }
void TypeDeclarationVisitor::Predeclare(Declaration* decl) { void PredeclarationVisitor::Predeclare(Declaration* decl) {
CurrentSourcePosition::Scope scope(decl->pos); CurrentSourcePosition::Scope scope(decl->pos);
switch (decl->kind) { switch (decl->kind) {
#define ENUM_ITEM(name) \ #define ENUM_ITEM(name) \
...@@ -32,8 +32,10 @@ void TypeDeclarationVisitor::Predeclare(Declaration* decl) { ...@@ -32,8 +32,10 @@ void TypeDeclarationVisitor::Predeclare(Declaration* decl) {
#undef ENUM_ITEM #undef ENUM_ITEM
case AstNode::Kind::kNamespaceDeclaration: case AstNode::Kind::kNamespaceDeclaration:
return Predeclare(NamespaceDeclaration::cast(decl)); return Predeclare(NamespaceDeclaration::cast(decl));
case AstNode::Kind::kGenericDeclaration:
return Predeclare(GenericDeclaration::cast(decl));
default: default:
// This visitor only processes type declaration nodes. // Only processes type declaration nodes, namespaces and generics.
break; break;
} }
} }
...@@ -204,10 +206,6 @@ void DeclarationVisitor::Visit(StandardDeclaration* decl) { ...@@ -204,10 +206,6 @@ void DeclarationVisitor::Visit(StandardDeclaration* decl) {
Visit(decl->callable, signature, decl->body); Visit(decl->callable, signature, decl->body);
} }
void DeclarationVisitor::Visit(GenericDeclaration* decl) {
Declarations::DeclareGeneric(decl->callable->name, decl);
}
void DeclarationVisitor::Visit(SpecializationDeclaration* decl) { void DeclarationVisitor::Visit(SpecializationDeclaration* decl) {
if ((decl->body != nullptr) == decl->external) { if ((decl->body != nullptr) == decl->external) {
std::stringstream stream; std::stringstream stream;
...@@ -382,7 +380,7 @@ Callable* DeclarationVisitor::Specialize( ...@@ -382,7 +380,7 @@ Callable* DeclarationVisitor::Specialize(
return callable; return callable;
} }
void TypeDeclarationVisitor::ResolvePredeclarations() { void PredeclarationVisitor::ResolvePredeclarations() {
for (auto& p : GlobalContext::AllDeclarables()) { for (auto& p : GlobalContext::AllDeclarables()) {
if (const TypeAlias* alias = TypeAlias::DynamicCast(p.get())) { if (const TypeAlias* alias = TypeAlias::DynamicCast(p.get())) {
CurrentScope::Scope scope_activator(alias->ParentScope()); CurrentScope::Scope scope_activator(alias->ParentScope());
......
...@@ -20,7 +20,7 @@ namespace torque { ...@@ -20,7 +20,7 @@ namespace torque {
Namespace* GetOrCreateNamespace(const std::string& name); Namespace* GetOrCreateNamespace(const std::string& name);
class TypeDeclarationVisitor { class PredeclarationVisitor {
public: public:
static void Predeclare(Ast* ast) { static void Predeclare(Ast* ast) {
CurrentScope::Scope current_namespace(GlobalContext::GetDefaultNamespace()); CurrentScope::Scope current_namespace(GlobalContext::GetDefaultNamespace());
...@@ -37,6 +37,9 @@ class TypeDeclarationVisitor { ...@@ -37,6 +37,9 @@ class TypeDeclarationVisitor {
static void Predeclare(TypeDeclaration* decl) { static void Predeclare(TypeDeclaration* decl) {
Declarations::PredeclareTypeAlias(decl->name, decl, false); Declarations::PredeclareTypeAlias(decl->name, decl, false);
} }
static void Predeclare(GenericDeclaration* decl) {
Declarations::DeclareGeneric(decl->callable->name, decl);
}
}; };
class DeclarationVisitor { class DeclarationVisitor {
...@@ -85,7 +88,9 @@ class DeclarationVisitor { ...@@ -85,7 +88,9 @@ class DeclarationVisitor {
static void Visit(ConstDeclaration* decl); static void Visit(ConstDeclaration* decl);
static void Visit(StandardDeclaration* 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(SpecializationDeclaration* decl);
static void Visit(ExternConstDeclaration* decl); static void Visit(ExternConstDeclaration* decl);
static void Visit(CppIncludeDeclaration* decl); static void Visit(CppIncludeDeclaration* decl);
......
...@@ -55,8 +55,8 @@ void CompileCurrentAst(TorqueCompilerOptions options) { ...@@ -55,8 +55,8 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
// Two-step process of predeclaration + resolution allows to resolve type // Two-step process of predeclaration + resolution allows to resolve type
// declarations independent of the order they are given. // declarations independent of the order they are given.
TypeDeclarationVisitor::Predeclare(GlobalContext::Get().ast()); PredeclarationVisitor::Predeclare(GlobalContext::Get().ast());
TypeDeclarationVisitor::ResolvePredeclarations(); PredeclarationVisitor::ResolvePredeclarations();
// Process other declarations. // Process other declarations.
DeclarationVisitor::Visit(GlobalContext::Get().ast()); 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