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(
extern builtin ExtractFastJSArray(Context, JSArray, Smi, Smi): JSArray;
macro LoadElementNoHole<T : type>(a: JSArray, index: Smi): Object
labels IfHole {
unreachable;
}
macro LoadElementNoHole<T : type>(a: JSArray, index: Smi): Object labels IfHole;
LoadElementNoHole<FixedArray>(a: JSArray, index: Smi): Object
labels IfHole {
......
......@@ -275,9 +275,9 @@ typeAliasDeclaration : 'type' IDENTIFIER '=' type ';';
externalBuiltin : EXTERN JAVASCRIPT? BUILTIN IDENTIFIER optionalGenericTypeList '(' typeList ')' optionalType ';';
externalMacro : EXTERN (IMPLICIT? 'operator' STRING_LITERAL)? MACRO IDENTIFIER optionalGenericTypeList typeListMaybeVarArgs optionalType optionalLabelList ';';
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;
macroDeclaration : MACRO IDENTIFIER optionalGenericTypeList parameterList optionalType optionalLabelList helperBody;
macroDeclaration : MACRO IDENTIFIER optionalGenericTypeList parameterList optionalType optionalLabelList (helperBody | ';');
constDeclaration : 'const' IDENTIFIER ':' type '=' STRING_LITERAL ';';
declaration
......
This diff is collapsed.
......@@ -169,13 +169,16 @@ antlrcpp::Any AstGenerator::visitMacroDeclaration(
GetOptionalParameterList(context->parameterList()),
GetOptionalType(context->optionalType()),
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;
if (generic_parameters.size() != 0) {
result = RegisterNode(
new GenericDeclaration{Pos(context), macro, generic_parameters, body});
} 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;
}
......@@ -184,7 +187,9 @@ antlrcpp::Any AstGenerator::visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* context) {
auto generic_parameters =
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{
Pos(context), context->JAVASCRIPT() != nullptr,
......@@ -197,7 +202,9 @@ antlrcpp::Any AstGenerator::visitBuiltinDeclaration(
result = RegisterNode(new GenericDeclaration{Pos(context), builtin,
generic_parameters, body});
} 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;
}
......
......@@ -651,14 +651,15 @@ struct StandardDeclaration : Declaration {
struct GenericDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(GenericDeclaration)
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),
callable(c),
generic_parameters(std::move(gp)),
body(b) {}
CallableNode* callable;
std::vector<std::string> generic_parameters;
Statement* body;
base::Optional<Statement*> body;
};
struct SpecializationDeclaration : Declaration {
......
......@@ -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) {
......
......@@ -88,12 +88,14 @@ Callable* FileVisitor::LookupCall(const std::string& name,
void FileVisitor::QueueGenericSpecialization(
const SpecializationKey& key, CallableNode* callable,
const CallableNodeSignature* signature, Statement* body) {
pending_specializations_.push_back({key, callable, signature, body});
const CallableNodeSignature* signature, base::Optional<Statement*> body) {
pending_specializations_.push_back(
{key, callable, signature, body, CurrentSourcePosition::Get()});
}
void FileVisitor::SpecializeGeneric(
const PendingSpecialization& specialization) {
CurrentSourcePosition::Scope scope(specialization.request_position);
if (completed_specializations_.find(specialization.key) !=
completed_specializations_.end()) {
std::stringstream stream;
......@@ -102,12 +104,19 @@ void FileVisitor::SpecializeGeneric(
<< " with types <" << specialization.key.second << ">";
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(), specialization.key);
FileVisitor::ScopedModuleActivator activator(
this, specialization.key.first->module());
Specialize(specialization.key, specialization.callable,
specialization.signature, specialization.body);
specialization.signature, *specialization.body);
completed_specializations_.insert(specialization.key);
}
......
......@@ -81,13 +81,14 @@ class FileVisitor {
SpecializationKey key;
CallableNode* callable;
const CallableNodeSignature* signature;
Statement* body;
base::Optional<Statement*> body;
SourcePosition request_position;
};
void QueueGenericSpecialization(const SpecializationKey& key,
CallableNode* callable,
const CallableNodeSignature* signature,
Statement* body);
base::Optional<Statement*> body);
void SpecializeGeneric(const PendingSpecialization& specialization);
......
......@@ -1459,7 +1459,8 @@ void ImplementationVisitor::Visit(SpecializationDeclaration* decl) {
SpecializeGeneric({{generic, specialization_types},
callable,
decl->signature.get(),
decl->body});
decl->body,
decl->pos});
}
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