Commit 6b2c305c authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] allow templates without body

Change-Id: Ie61c8fa51c7c13ab74c4c97ed6803be7f879a549
Reviewed-on: https://chromium-review.googlesource.com/1069088
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53293}
parent 6e91806b
...@@ -296,10 +296,7 @@ extern macro ExtractFixedArray( ...@@ -296,10 +296,7 @@ extern macro ExtractFixedArray(
extern builtin ExtractFastJSArray(Context, JSArray, Smi, Smi): JSArray; extern builtin ExtractFastJSArray(Context, JSArray, Smi, Smi): JSArray;
macro LoadElementNoHole<T : type>(a: JSArray, index: Smi): Object macro LoadElementNoHole<T : type>(a: JSArray, index: Smi): Object labels IfHole;
labels IfHole {
unreachable;
}
LoadElementNoHole<FixedArray>(a: JSArray, index: Smi): Object LoadElementNoHole<FixedArray>(a: JSArray, index: Smi): Object
labels IfHole { labels IfHole {
......
...@@ -275,9 +275,9 @@ typeAliasDeclaration : 'type' IDENTIFIER '=' type ';'; ...@@ -275,9 +275,9 @@ typeAliasDeclaration : 'type' IDENTIFIER '=' type ';';
externalBuiltin : EXTERN JAVASCRIPT? BUILTIN IDENTIFIER optionalGenericTypeList '(' typeList ')' optionalType ';'; externalBuiltin : EXTERN JAVASCRIPT? BUILTIN IDENTIFIER optionalGenericTypeList '(' typeList ')' optionalType ';';
externalMacro : EXTERN (IMPLICIT? 'operator' STRING_LITERAL)? MACRO IDENTIFIER optionalGenericTypeList typeListMaybeVarArgs optionalType optionalLabelList ';'; externalMacro : EXTERN (IMPLICIT? 'operator' STRING_LITERAL)? MACRO IDENTIFIER optionalGenericTypeList typeListMaybeVarArgs optionalType optionalLabelList ';';
externalRuntime : EXTERN RUNTIME IDENTIFIER typeListMaybeVarArgs optionalType ';'; externalRuntime : EXTERN RUNTIME IDENTIFIER typeListMaybeVarArgs optionalType ';';
builtinDeclaration : JAVASCRIPT? BUILTIN IDENTIFIER optionalGenericTypeList parameterList optionalType helperBody; builtinDeclaration : JAVASCRIPT? BUILTIN IDENTIFIER optionalGenericTypeList parameterList optionalType (helperBody | ';');
genericSpecialization: IDENTIFIER genericSpecializationTypeList parameterList optionalType optionalLabelList helperBody; genericSpecialization: IDENTIFIER genericSpecializationTypeList parameterList optionalType optionalLabelList helperBody;
macroDeclaration : MACRO IDENTIFIER optionalGenericTypeList parameterList optionalType optionalLabelList helperBody; macroDeclaration : MACRO IDENTIFIER optionalGenericTypeList parameterList optionalType optionalLabelList (helperBody | ';');
constDeclaration : 'const' IDENTIFIER ':' type '=' STRING_LITERAL ';'; constDeclaration : 'const' IDENTIFIER ':' type '=' STRING_LITERAL ';';
declaration declaration
......
This diff is collapsed.
...@@ -169,13 +169,16 @@ antlrcpp::Any AstGenerator::visitMacroDeclaration( ...@@ -169,13 +169,16 @@ antlrcpp::Any AstGenerator::visitMacroDeclaration(
GetOptionalParameterList(context->parameterList()), GetOptionalParameterList(context->parameterList()),
GetOptionalType(context->optionalType()), GetOptionalType(context->optionalType()),
GetOptionalLabelAndTypeList(context->optionalLabelList())}); GetOptionalLabelAndTypeList(context->optionalLabelList())});
auto body = context->helperBody()->accept(this).as<Statement*>(); base::Optional<Statement*> body;
if (context->helperBody())
body = context->helperBody()->accept(this).as<Statement*>();
Declaration* result = nullptr; Declaration* result = nullptr;
if (generic_parameters.size() != 0) { if (generic_parameters.size() != 0) {
result = RegisterNode( result = RegisterNode(
new GenericDeclaration{Pos(context), macro, generic_parameters, body}); new GenericDeclaration{Pos(context), macro, generic_parameters, body});
} else { } else {
result = RegisterNode(new StandardDeclaration{Pos(context), macro, body}); if (!body) ReportError("A non-generic declaration needs a body.");
result = RegisterNode(new StandardDeclaration{Pos(context), macro, *body});
} }
return result; return result;
} }
...@@ -184,7 +187,9 @@ antlrcpp::Any AstGenerator::visitBuiltinDeclaration( ...@@ -184,7 +187,9 @@ antlrcpp::Any AstGenerator::visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* context) { TorqueParser::BuiltinDeclarationContext* context) {
auto generic_parameters = auto generic_parameters =
GetIdentifierVector(context->optionalGenericTypeList()->IDENTIFIER()); GetIdentifierVector(context->optionalGenericTypeList()->IDENTIFIER());
Statement* body = context->helperBody()->accept(this).as<Statement*>(); base::Optional<Statement*> body;
if (context->helperBody())
body = context->helperBody()->accept(this).as<Statement*>();
TorqueBuiltinDeclaration* builtin = RegisterNode(new TorqueBuiltinDeclaration{ TorqueBuiltinDeclaration* builtin = RegisterNode(new TorqueBuiltinDeclaration{
Pos(context), context->JAVASCRIPT() != nullptr, Pos(context), context->JAVASCRIPT() != nullptr,
...@@ -197,7 +202,9 @@ antlrcpp::Any AstGenerator::visitBuiltinDeclaration( ...@@ -197,7 +202,9 @@ antlrcpp::Any AstGenerator::visitBuiltinDeclaration(
result = RegisterNode(new GenericDeclaration{Pos(context), builtin, result = RegisterNode(new GenericDeclaration{Pos(context), builtin,
generic_parameters, body}); generic_parameters, body});
} else { } else {
result = RegisterNode(new StandardDeclaration{Pos(context), builtin, body}); if (!body) ReportError("A non-generic declaration needs a body.");
result =
RegisterNode(new StandardDeclaration{Pos(context), builtin, *body});
} }
return result; return result;
} }
......
...@@ -651,14 +651,15 @@ struct StandardDeclaration : Declaration { ...@@ -651,14 +651,15 @@ struct StandardDeclaration : Declaration {
struct GenericDeclaration : Declaration { struct GenericDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(GenericDeclaration) DEFINE_AST_NODE_LEAF_BOILERPLATE(GenericDeclaration)
GenericDeclaration(SourcePosition p, CallableNode* c, GenericDeclaration(SourcePosition p, CallableNode* c,
std::vector<std::string> gp, Statement* b) std::vector<std::string> gp,
base::Optional<Statement*> b = base::nullopt)
: Declaration(kKind, p), : Declaration(kKind, p),
callable(c), callable(c),
generic_parameters(std::move(gp)), generic_parameters(std::move(gp)),
body(b) {} body(b) {}
CallableNode* callable; CallableNode* callable;
std::vector<std::string> generic_parameters; std::vector<std::string> generic_parameters;
Statement* body; base::Optional<Statement*> body;
}; };
struct SpecializationDeclaration : Declaration { struct SpecializationDeclaration : Declaration {
......
...@@ -228,7 +228,8 @@ void DeclarationVisitor::Visit(SpecializationDeclaration* decl) { ...@@ -228,7 +228,8 @@ void DeclarationVisitor::Visit(SpecializationDeclaration* decl) {
} }
} }
SpecializeGeneric({key, callable, decl->signature.get(), decl->body}); SpecializeGeneric(
{key, callable, decl->signature.get(), decl->body, decl->pos});
} }
void DeclarationVisitor::Visit(ReturnStatement* stmt) { void DeclarationVisitor::Visit(ReturnStatement* stmt) {
......
...@@ -88,12 +88,14 @@ Callable* FileVisitor::LookupCall(const std::string& name, ...@@ -88,12 +88,14 @@ Callable* FileVisitor::LookupCall(const std::string& name,
void FileVisitor::QueueGenericSpecialization( void FileVisitor::QueueGenericSpecialization(
const SpecializationKey& key, CallableNode* callable, const SpecializationKey& key, CallableNode* callable,
const CallableNodeSignature* signature, Statement* body) { const CallableNodeSignature* signature, base::Optional<Statement*> body) {
pending_specializations_.push_back({key, callable, signature, body}); pending_specializations_.push_back(
{key, callable, signature, body, CurrentSourcePosition::Get()});
} }
void FileVisitor::SpecializeGeneric( void FileVisitor::SpecializeGeneric(
const PendingSpecialization& specialization) { const PendingSpecialization& specialization) {
CurrentSourcePosition::Scope scope(specialization.request_position);
if (completed_specializations_.find(specialization.key) != if (completed_specializations_.find(specialization.key) !=
completed_specializations_.end()) { completed_specializations_.end()) {
std::stringstream stream; std::stringstream stream;
...@@ -102,12 +104,19 @@ void FileVisitor::SpecializeGeneric( ...@@ -102,12 +104,19 @@ void FileVisitor::SpecializeGeneric(
<< " with types <" << specialization.key.second << ">"; << " with types <" << specialization.key.second << ">";
ReportError(stream.str()); ReportError(stream.str());
} }
if (!specialization.body) {
std::stringstream stream;
stream << "missing specialization of "
<< specialization.key.first->declaration()->callable->name
<< " with types <" << specialization.key.second << ">";
ReportError(stream.str());
}
Declarations::ScopedGenericSpecializationKey instantiation( Declarations::ScopedGenericSpecializationKey instantiation(
declarations(), specialization.key); declarations(), specialization.key);
FileVisitor::ScopedModuleActivator activator( FileVisitor::ScopedModuleActivator activator(
this, specialization.key.first->module()); this, specialization.key.first->module());
Specialize(specialization.key, specialization.callable, Specialize(specialization.key, specialization.callable,
specialization.signature, specialization.body); specialization.signature, *specialization.body);
completed_specializations_.insert(specialization.key); completed_specializations_.insert(specialization.key);
} }
......
...@@ -81,13 +81,14 @@ class FileVisitor { ...@@ -81,13 +81,14 @@ class FileVisitor {
SpecializationKey key; SpecializationKey key;
CallableNode* callable; CallableNode* callable;
const CallableNodeSignature* signature; const CallableNodeSignature* signature;
Statement* body; base::Optional<Statement*> body;
SourcePosition request_position;
}; };
void QueueGenericSpecialization(const SpecializationKey& key, void QueueGenericSpecialization(const SpecializationKey& key,
CallableNode* callable, CallableNode* callable,
const CallableNodeSignature* signature, const CallableNodeSignature* signature,
Statement* body); base::Optional<Statement*> body);
void SpecializeGeneric(const PendingSpecialization& specialization); void SpecializeGeneric(const PendingSpecialization& specialization);
......
...@@ -1459,7 +1459,8 @@ void ImplementationVisitor::Visit(SpecializationDeclaration* decl) { ...@@ -1459,7 +1459,8 @@ void ImplementationVisitor::Visit(SpecializationDeclaration* decl) {
SpecializeGeneric({{generic, specialization_types}, SpecializeGeneric({{generic, specialization_types},
callable, callable,
decl->signature.get(), decl->signature.get(),
decl->body}); decl->body,
decl->pos});
} }
VisitResult ImplementationVisitor::Visit(CallExpression* expr, VisitResult ImplementationVisitor::Visit(CallExpression* expr,
......
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