Commit 3e41a47c authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque] Change syntax for "external constants"

This CL changes the syntax for external constants to better reflect
for what they are actually used.

Drive-by change: Ran the format tool on base.tq.

R=danno@chromium.org, tebbi@chromium.org

Bug: v8:7793
Change-Id: Ie49c28b9c95a05846a2d9801f01b11e5a58d72d9
Reviewed-on: https://chromium-review.googlesource.com/1111706Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Simon Zünd <szuend@google.com>
Cr-Commit-Position: refs/heads/master@{#53963}
parent f3b5721c
This diff is collapsed.
......@@ -277,7 +277,7 @@ externalRuntime : EXTERN RUNTIME IDENTIFIER typeListMaybeVarArgs optionalType ';
builtinDeclaration : JAVASCRIPT? BUILTIN IDENTIFIER optionalGenericTypeList parameterList optionalType (helperBody | ';');
genericSpecialization: IDENTIFIER genericSpecializationTypeList parameterList optionalType optionalLabelList helperBody;
macroDeclaration : ('operator' STRING_LITERAL)? MACRO IDENTIFIER optionalGenericTypeList parameterList optionalType optionalLabelList (helperBody | ';');
constDeclaration : 'const' IDENTIFIER ':' type '=' STRING_LITERAL ';';
externConstDeclaration : 'const' IDENTIFIER ':' type generatesDeclaration ';';
declaration
: typeDeclaration
......@@ -288,7 +288,7 @@ declaration
| externalMacro
| externalBuiltin
| externalRuntime
| constDeclaration;
| externConstDeclaration;
moduleDeclaration : MODULE IDENTIFIER '{' declaration* '}';
......
......@@ -318,10 +318,10 @@ class TorqueBaseListener : public TorqueListener {
void exitMacroDeclaration(
TorqueParser::MacroDeclarationContext* /*ctx*/) override {}
void enterConstDeclaration(
TorqueParser::ConstDeclarationContext* /*ctx*/) override {}
void exitConstDeclaration(
TorqueParser::ConstDeclarationContext* /*ctx*/) override {}
void enterExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* /*ctx*/) override {}
void exitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* /*ctx*/) override {}
void enterDeclaration(TorqueParser::DeclarationContext* /*ctx*/) override {}
void exitDeclaration(TorqueParser::DeclarationContext* /*ctx*/) override {}
......
......@@ -336,8 +336,8 @@ class TorqueBaseVisitor : public TorqueVisitor {
return visitChildren(ctx);
}
antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* ctx) override {
antlrcpp::Any visitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* ctx) override {
return visitChildren(ctx);
}
......
......@@ -301,10 +301,10 @@ class TorqueListener : public antlr4::tree::ParseTreeListener {
virtual void exitMacroDeclaration(
TorqueParser::MacroDeclarationContext* ctx) = 0;
virtual void enterConstDeclaration(
TorqueParser::ConstDeclarationContext* ctx) = 0;
virtual void exitConstDeclaration(
TorqueParser::ConstDeclarationContext* ctx) = 0;
virtual void enterExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* ctx) = 0;
virtual void exitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* ctx) = 0;
virtual void enterDeclaration(TorqueParser::DeclarationContext* ctx) = 0;
virtual void exitDeclaration(TorqueParser::DeclarationContext* ctx) = 0;
......
This diff is collapsed.
......@@ -162,7 +162,7 @@ class TorqueParser : public antlr4::Parser {
RuleBuiltinDeclaration = 63,
RuleGenericSpecialization = 64,
RuleMacroDeclaration = 65,
RuleConstDeclaration = 66,
RuleExternConstDeclaration = 66,
RuleDeclaration = 67,
RuleModuleDeclaration = 68,
RuleFile = 69
......@@ -245,7 +245,7 @@ class TorqueParser : public antlr4::Parser {
class BuiltinDeclarationContext;
class GenericSpecializationContext;
class MacroDeclarationContext;
class ConstDeclarationContext;
class ExternConstDeclarationContext;
class DeclarationContext;
class ModuleDeclarationContext;
class FileContext;
......@@ -1397,14 +1397,14 @@ class TorqueParser : public antlr4::Parser {
MacroDeclarationContext* macroDeclaration();
class ConstDeclarationContext : public antlr4::ParserRuleContext {
class ExternConstDeclarationContext : public antlr4::ParserRuleContext {
public:
ConstDeclarationContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
ExternConstDeclarationContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* IDENTIFIER();
TypeContext* type();
antlr4::tree::TerminalNode* STRING_LITERAL();
GeneratesDeclarationContext* generatesDeclaration();
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
......@@ -1412,7 +1412,7 @@ class TorqueParser : public antlr4::Parser {
antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override;
};
ConstDeclarationContext* constDeclaration();
ExternConstDeclarationContext* externConstDeclaration();
class DeclarationContext : public antlr4::ParserRuleContext {
public:
......@@ -1426,7 +1426,7 @@ class TorqueParser : public antlr4::Parser {
ExternalMacroContext* externalMacro();
ExternalBuiltinContext* externalBuiltin();
ExternalRuntimeContext* externalRuntime();
ConstDeclarationContext* constDeclaration();
ExternConstDeclarationContext* externConstDeclaration();
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
......
......@@ -216,8 +216,8 @@ class TorqueVisitor : public antlr4::tree::AbstractParseTreeVisitor {
virtual antlrcpp::Any visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* context) = 0;
virtual antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) = 0;
virtual antlrcpp::Any visitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* context) = 0;
virtual antlrcpp::Any visitDeclaration(
TorqueParser::DeclarationContext* context) = 0;
......
......@@ -291,13 +291,15 @@ antlrcpp::Any AstGenerator::visitGenericSpecialization(
context->helperBody()->accept(this).as<Statement*>()}));
}
antlrcpp::Any AstGenerator::visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) {
return implicit_cast<Declaration*>(RegisterNode(new ConstDeclaration{
antlrcpp::Any AstGenerator::visitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* context) {
return implicit_cast<Declaration*>(RegisterNode(new ExternConstDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(),
GetType(context->type()),
StringLiteralUnquote(
context->STRING_LITERAL()->getSymbol()->getText())}));
StringLiteralUnquote(context->generatesDeclaration()
->STRING_LITERAL()
->getSymbol()
->getText())}));
}
antlrcpp::Any AstGenerator::visitTypeDeclaration(
......
......@@ -44,8 +44,8 @@ class AstGenerator : public TorqueBaseVisitor {
antlrcpp::Any visitGenericSpecialization(
TorqueParser::GenericSpecializationContext* context) override;
antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) override;
antlrcpp::Any visitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* context) override;
antlrcpp::Any visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* context) override;
......
......@@ -68,7 +68,7 @@ DECLARE_CONTEXTUAL_VARIABLE(CurrentSourcePosition, SourcePosition)
V(StandardDeclaration) \
V(GenericDeclaration) \
V(SpecializationDeclaration) \
V(ConstDeclaration) \
V(ExternConstDeclaration) \
V(DefaultModuleDeclaration) \
V(ExplicitModuleDeclaration)
......@@ -664,10 +664,10 @@ struct SpecializationDeclaration : Declaration {
Statement* body;
};
struct ConstDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ConstDeclaration)
ConstDeclaration(SourcePosition p, std::string n, TypeExpression* t,
std::string l)
struct ExternConstDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternConstDeclaration)
ExternConstDeclaration(SourcePosition p, std::string n, TypeExpression* t,
std::string l)
: Declaration(kKind, p),
name(std::move(n)),
type(t),
......
......@@ -108,7 +108,9 @@ class DeclarationVisitor : public FileVisitor {
void Visit(VarDeclarationStatement* stmt);
void Visit(ConstDeclaration* decl) {
void Visit(ExternConstDeclaration* decl) {
// TODO(szuend): When module-wide const bindings are available, only
// constexpr types should be allowed here.
declarations()->DeclareConstant(
decl->name, declarations()->GetType(decl->type), decl->literal);
}
......
......@@ -92,7 +92,7 @@ class ImplementationVisitor : public FileVisitor {
}
void Visit(TypeDeclaration* decl) {}
void Visit(TypeAliasDeclaration* decl) {}
void Visit(ConstDeclaration* decl) {}
void Visit(ExternConstDeclaration* decl) {}
void Visit(StandardDeclaration* decl);
void Visit(GenericDeclaration* decl) {}
void Visit(SpecializationDeclaration* decl);
......
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