Commit 3d2cb0b4 authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

[torque]: Implement Generics for Builtins and Macros

Including specialization, e.g.:

  // Declare parameterized generic
  macro GenericMacroTest<T: type>(param: T): Object {
    return Undefined;
  }

  // Declare specialization of generic
  GenericMacroTest<Object>(param: Object): Object {
    return param;
  }

  ...
  assert(GenericMacroTest<Smi>(0) == Undefined);
  assert(GenericMacroTest<Smi>(1) == Undefined);
  assert(GenericMacroTest<Object>(Null) == Null);
  assert(GenericMacroTest<Object>(False) == False);
  ...

Known issue: specialization doesn't rigorously checked to verify
that specialization signature precisely matches generic declaration.

Change-Id: I9d9d96da4c5c8c9a76550844680e9e133a5edaed
Reviewed-on: https://chromium-review.googlesource.com/1043986
Commit-Queue: Daniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53203}
parent c1928181
......@@ -35,6 +35,7 @@ TAIL: 'tail';
ISNT: 'isnt';
IS: 'is';
LET: 'let';
EXTERN: 'extern';
ASSERT: 'assert';
UNREACHABLE_TOKEN: 'unreachable';
DEBUG_TOKEN: 'debug';
......@@ -118,6 +119,9 @@ DECIMAL_LITERAL
type : CONSTEXPR? IDENTIFIER;
typeList : '(' type? (',' type)* ')';
optionalGenericSpecializationTypeList: ('<' IDENTIFIER (',' IDENTIFIER)* '>')?;
optionalGenericTypeList: ('<' IDENTIFIER ':' 'type' (',' IDENTIFIER ':' 'type')* '>')?;
typeListMaybeVarArgs: '(' type? (',' type)* (',' VARARGS)? ')'
| '(' VARARGS ')';
......@@ -219,7 +223,7 @@ forOfLoop: FOR '(' variableDeclaration 'of' expression forOfRange ')' statementB
argument: expression;
argumentList: '(' argument? (',' argument)* ')';
helperCall: (MIN | MAX | IDENTIFIER) argumentList optionalOtherwise;
helperCall: (MIN | MAX | IDENTIFIER) optionalGenericSpecializationTypeList argumentList optionalOtherwise;
labelReference: IDENTIFIER;
variableDeclaration: LET IDENTIFIER ':' type;
......@@ -265,16 +269,18 @@ generatesDeclaration: 'generates' STRING_LITERAL;
constexprDeclaration: 'constexpr' STRING_LITERAL;
typeDeclaration : 'type' IDENTIFIER extendsDeclaration? generatesDeclaration? constexprDeclaration?';';
externalBuiltin : 'extern' JAVASCRIPT? BUILTIN IDENTIFIER typeList optionalType ';';
externalMacro : 'extern' (IMPLICIT? 'operator' STRING_LITERAL)? MACRO IDENTIFIER typeListMaybeVarArgs optionalType optionalLabelList ';';
externalRuntime : 'extern' RUNTIME IDENTIFIER typeListMaybeVarArgs optionalType ';';
builtinDeclaration : JAVASCRIPT? BUILTIN IDENTIFIER parameterList optionalType helperBody;
macroDeclaration : MACRO IDENTIFIER parameterList optionalType optionalLabelList helperBody;
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;
genericSpecialization: IDENTIFIER optionalGenericSpecializationTypeList parameterList optionalType optionalLabelList helperBody;
macroDeclaration : MACRO IDENTIFIER optionalGenericTypeList parameterList optionalType optionalLabelList helperBody;
constDeclaration : 'const' IDENTIFIER ':' type '=' STRING_LITERAL ';';
declaration
: typeDeclaration
| builtinDeclaration
| genericSpecialization
| macroDeclaration
| externalMacro
| externalBuiltin
......
......@@ -24,6 +24,18 @@ class TorqueBaseListener : public TorqueListener {
void enterTypeList(TorqueParser::TypeListContext* /*ctx*/) override {}
void exitTypeList(TorqueParser::TypeListContext* /*ctx*/) override {}
void enterOptionalGenericSpecializationTypeList(
TorqueParser::OptionalGenericSpecializationTypeListContext* /*ctx*/)
override {}
void exitOptionalGenericSpecializationTypeList(
TorqueParser::OptionalGenericSpecializationTypeListContext* /*ctx*/)
override {}
void enterOptionalGenericTypeList(
TorqueParser::OptionalGenericTypeListContext* /*ctx*/) override {}
void exitOptionalGenericTypeList(
TorqueParser::OptionalGenericTypeListContext* /*ctx*/) override {}
void enterTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* /*ctx*/) override {}
void exitTypeListMaybeVarArgs(
......@@ -291,6 +303,11 @@ class TorqueBaseListener : public TorqueListener {
void exitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* /*ctx*/) override {}
void enterGenericSpecialization(
TorqueParser::GenericSpecializationContext* /*ctx*/) override {}
void exitGenericSpecialization(
TorqueParser::GenericSpecializationContext* /*ctx*/) override {}
void enterMacroDeclaration(
TorqueParser::MacroDeclarationContext* /*ctx*/) override {}
void exitMacroDeclaration(
......
......@@ -26,6 +26,17 @@ class TorqueBaseVisitor : public TorqueVisitor {
return visitChildren(ctx);
}
antlrcpp::Any visitOptionalGenericSpecializationTypeList(
TorqueParser::OptionalGenericSpecializationTypeListContext* ctx)
override {
return visitChildren(ctx);
}
antlrcpp::Any visitOptionalGenericTypeList(
TorqueParser::OptionalGenericTypeListContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* ctx) override {
return visitChildren(ctx);
......@@ -310,6 +321,11 @@ class TorqueBaseVisitor : public TorqueVisitor {
return visitChildren(ctx);
}
antlrcpp::Any visitGenericSpecialization(
TorqueParser::GenericSpecializationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* ctx) override {
return visitChildren(ctx);
......
......@@ -69,7 +69,6 @@ std::vector<std::string> TorqueLexer::_ruleNames = {u8"T__0",
u8"T__17",
u8"T__18",
u8"T__19",
u8"T__20",
u8"MACRO",
u8"BUILTIN",
u8"RUNTIME",
......@@ -96,6 +95,7 @@ std::vector<std::string> TorqueLexer::_ruleNames = {u8"T__0",
u8"ISNT",
u8"IS",
u8"LET",
u8"EXTERN",
u8"ASSERT",
u8"UNREACHABLE_TOKEN",
u8"DEBUG_TOKEN",
......@@ -146,6 +146,7 @@ std::vector<std::string> TorqueLexer::_literalNames = {"",
u8"','",
u8"')'",
u8"':'",
u8"'type'",
u8"'?'",
u8"'||'",
u8"'&&'",
......@@ -159,8 +160,6 @@ std::vector<std::string> TorqueLexer::_literalNames = {"",
u8"'}'",
u8"'extends'",
u8"'generates'",
u8"'type'",
u8"'extern'",
u8"'operator'",
u8"'const'",
u8"'macro'",
......@@ -189,6 +188,7 @@ std::vector<std::string> TorqueLexer::_literalNames = {"",
u8"'isnt'",
u8"'is'",
u8"'let'",
u8"'extern'",
u8"'assert'",
u8"'unreachable'",
u8"'debug'",
......@@ -220,7 +220,6 @@ std::vector<std::string> TorqueLexer::_literalNames = {"",
u8"'!'"};
std::vector<std::string> TorqueLexer::_symbolicNames = {
"",
"",
"",
"",
......@@ -268,6 +267,7 @@ std::vector<std::string> TorqueLexer::_symbolicNames = {
u8"ISNT",
u8"IS",
u8"LET",
u8"EXTERN",
u8"ASSERT",
u8"UNREACHABLE_TOKEN",
u8"DEBUG_TOKEN",
......@@ -367,59 +367,59 @@ TorqueLexer::Initializer::Initializer() {
0x56, 0x9, 0x56, 0x4, 0x57, 0x9, 0x57, 0x3, 0x2,
0x3, 0x2, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3,
0x4, 0x3, 0x5, 0x3, 0x5, 0x3, 0x6, 0x3, 0x6,
0x3, 0x7, 0x3, 0x7, 0x3, 0x7, 0x3, 0x8, 0x3,
0x8, 0x3, 0x8, 0x3, 0x9, 0x3, 0x9, 0x3, 0xa,
0x3, 0xa, 0x3, 0xb, 0x3, 0xb, 0x3, 0xc, 0x3,
0xc, 0x3, 0xd, 0x3, 0xd, 0x3, 0xd, 0x3, 0xe,
0x3, 0xe, 0x3, 0xe, 0x3, 0xe, 0x3, 0xe, 0x3,
0xf, 0x3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x7, 0x6e, 0x2, 0x2, 0x103, 0x104,
0x7, 0x76, 0x2, 0x2, 0x104, 0x105, 0x7, 0x6b, 0x2,
0x2, 0x105, 0x106, 0x7, 0x70, 0x2, 0x2, 0x106, 0x2e,
0x3, 0x2, 0x2, 0x2, 0x107, 0x108, 0x7, 0x74, 0x2,
0x2, 0x108, 0x109, 0x7, 0x77, 0x2, 0x2, 0x109, 0x10a,
0x7, 0x70, 0x2, 0x2, 0x10a, 0x10b, 0x7, 0x76, 0x2,
0x2, 0x10b, 0x10c, 0x7, 0x6b, 0x2, 0x2, 0x10c, 0x10d,
0x7, 0x70, 0x2, 0x2, 0x10d, 0x30, 0x3, 0x2, 0x2,
0x2, 0x10e, 0x10f, 0x7, 0x74, 0x2, 0x2, 0x10f, 0x110,
0x7, 0x77, 0x2, 0x2, 0x110, 0x111, 0x7, 0x70, 0x2,
0x2, 0x111, 0x112, 0x7, 0x76, 0x2, 0x2, 0x112, 0x113,
0x7, 0x6b, 0x2, 0x2, 0x113, 0x114, 0x7, 0x6f, 0x2,
0x7, 0x6f, 0x2, 0x2, 0x10d, 0x10e, 0x7, 0x67, 0x2,
0x2, 0x10e, 0x30, 0x3, 0x2, 0x2, 0x2, 0x10f, 0x110,
0x7, 0x6f, 0x2, 0x2, 0x110, 0x111, 0x7, 0x71, 0x2,
0x2, 0x111, 0x112, 0x7, 0x66, 0x2, 0x2, 0x112, 0x113,
0x7, 0x77, 0x2, 0x2, 0x113, 0x114, 0x7, 0x6e, 0x2,
0x2, 0x114, 0x115, 0x7, 0x67, 0x2, 0x2, 0x115, 0x32,
0x3, 0x2, 0x2, 0x2, 0x116, 0x117, 0x7, 0x6f, 0x2,
0x2, 0x117, 0x118, 0x7, 0x71, 0x2, 0x2, 0x118, 0x119,
0x7, 0x66, 0x2, 0x2, 0x119, 0x11a, 0x7, 0x77, 0x2,
0x2, 0x11a, 0x11b, 0x7, 0x6e, 0x2, 0x2, 0x11b, 0x11c,
0x7, 0x67, 0x2, 0x2, 0x11c, 0x34, 0x3, 0x2, 0x2,
0x2, 0x11d, 0x11e, 0x7, 0x6c, 0x2, 0x2, 0x11e, 0x11f,
0x7, 0x63, 0x2, 0x2, 0x11f, 0x120, 0x7, 0x78, 0x2,
0x2, 0x120, 0x121, 0x7, 0x63, 0x2, 0x2, 0x121, 0x122,
0x7, 0x75, 0x2, 0x2, 0x122, 0x123, 0x7, 0x65, 0x2,
0x2, 0x123, 0x124, 0x7, 0x74, 0x2, 0x2, 0x124, 0x125,
0x7, 0x6b, 0x2, 0x2, 0x125, 0x126, 0x7, 0x72, 0x2,
0x2, 0x126, 0x127, 0x7, 0x76, 0x2, 0x2, 0x127, 0x36,
0x3, 0x2, 0x2, 0x2, 0x128, 0x129, 0x7, 0x6b, 0x2,
0x2, 0x129, 0x12a, 0x7, 0x6f, 0x2, 0x2, 0x12a, 0x12b,
0x7, 0x72, 0x2, 0x2, 0x12b, 0x12c, 0x7, 0x6e, 0x2,
0x2, 0x12c, 0x12d, 0x7, 0x6b, 0x2, 0x2, 0x12d, 0x12e,
0x7, 0x65, 0x2, 0x2, 0x12e, 0x12f, 0x7, 0x6b, 0x2,
0x2, 0x12f, 0x130, 0x7, 0x76, 0x2, 0x2, 0x130, 0x38,
0x3, 0x2, 0x2, 0x2, 0x131, 0x132, 0x7, 0x66, 0x2,
0x2, 0x132, 0x133, 0x7, 0x67, 0x2, 0x2, 0x133, 0x134,
0x7, 0x68, 0x2, 0x2, 0x134, 0x135, 0x7, 0x67, 0x2,
0x2, 0x135, 0x136, 0x7, 0x74, 0x2, 0x2, 0x136, 0x137,
0x7, 0x74, 0x2, 0x2, 0x137, 0x138, 0x7, 0x67, 0x2,
0x2, 0x138, 0x139, 0x7, 0x66, 0x2, 0x2, 0x139, 0x3a,
0x3, 0x2, 0x2, 0x2, 0x13a, 0x13b, 0x7, 0x6b, 0x2,
0x2, 0x13b, 0x13c, 0x7, 0x68, 0x2, 0x2, 0x13c, 0x3c,
0x3, 0x2, 0x2, 0x2, 0x13d, 0x13e, 0x7, 0x65, 0x2,
0x2, 0x13e, 0x13f, 0x7, 0x63, 0x2, 0x2, 0x13f, 0x140,
0x7, 0x75, 0x2, 0x2, 0x140, 0x141, 0x7, 0x76, 0x2,
0x2, 0x141, 0x3e, 0x3, 0x2, 0x2, 0x2, 0x142, 0x143,
0x7, 0x65, 0x2, 0x2, 0x143, 0x144, 0x7, 0x71, 0x2,
0x2, 0x144, 0x145, 0x7, 0x70, 0x2, 0x2, 0x145, 0x146,
0x7, 0x78, 0x2, 0x2, 0x146, 0x147, 0x7, 0x67, 0x2,
0x2, 0x147, 0x148, 0x7, 0x74, 0x2, 0x2, 0x148, 0x149,
0x7, 0x76, 0x2, 0x2, 0x149, 0x40, 0x3, 0x2, 0x2,
0x2, 0x14a, 0x14b, 0x7, 0x68, 0x2, 0x2, 0x14b, 0x14c,
0x7, 0x71, 0x2, 0x2, 0x14c, 0x14d, 0x7, 0x74, 0x2,
0x2, 0x14d, 0x42, 0x3, 0x2, 0x2, 0x2, 0x14e, 0x14f,
0x7, 0x79, 0x2, 0x2, 0x14f, 0x150, 0x7, 0x6a, 0x2,
0x2, 0x150, 0x151, 0x7, 0x6b, 0x2, 0x2, 0x151, 0x152,
0x7, 0x6e, 0x2, 0x2, 0x152, 0x153, 0x7, 0x67, 0x2,
0x3, 0x2, 0x2, 0x2, 0x116, 0x117, 0x7, 0x6c, 0x2,
0x2, 0x117, 0x118, 0x7, 0x63, 0x2, 0x2, 0x118, 0x119,
0x7, 0x78, 0x2, 0x2, 0x119, 0x11a, 0x7, 0x63, 0x2,
0x2, 0x11a, 0x11b, 0x7, 0x75, 0x2, 0x2, 0x11b, 0x11c,
0x7, 0x65, 0x2, 0x2, 0x11c, 0x11d, 0x7, 0x74, 0x2,
0x2, 0x11d, 0x11e, 0x7, 0x6b, 0x2, 0x2, 0x11e, 0x11f,
0x7, 0x72, 0x2, 0x2, 0x11f, 0x120, 0x7, 0x76, 0x2,
0x2, 0x120, 0x34, 0x3, 0x2, 0x2, 0x2, 0x121, 0x122,
0x7, 0x6b, 0x2, 0x2, 0x122, 0x123, 0x7, 0x6f, 0x2,
0x2, 0x123, 0x124, 0x7, 0x72, 0x2, 0x2, 0x124, 0x125,
0x7, 0x6e, 0x2, 0x2, 0x125, 0x126, 0x7, 0x6b, 0x2,
0x2, 0x126, 0x127, 0x7, 0x65, 0x2, 0x2, 0x127, 0x128,
0x7, 0x6b, 0x2, 0x2, 0x128, 0x129, 0x7, 0x76, 0x2,
0x2, 0x129, 0x36, 0x3, 0x2, 0x2, 0x2, 0x12a, 0x12b,
0x7, 0x66, 0x2, 0x2, 0x12b, 0x12c, 0x7, 0x67, 0x2,
0x2, 0x12c, 0x12d, 0x7, 0x68, 0x2, 0x2, 0x12d, 0x12e,
0x7, 0x67, 0x2, 0x2, 0x12e, 0x12f, 0x7, 0x74, 0x2,
0x2, 0x12f, 0x130, 0x7, 0x74, 0x2, 0x2, 0x130, 0x131,
0x7, 0x67, 0x2, 0x2, 0x131, 0x132, 0x7, 0x66, 0x2,
0x2, 0x132, 0x38, 0x3, 0x2, 0x2, 0x2, 0x133, 0x134,
0x7, 0x6b, 0x2, 0x2, 0x134, 0x135, 0x7, 0x68, 0x2,
0x2, 0x135, 0x3a, 0x3, 0x2, 0x2, 0x2, 0x136, 0x137,
0x7, 0x65, 0x2, 0x2, 0x137, 0x138, 0x7, 0x63, 0x2,
0x2, 0x138, 0x139, 0x7, 0x75, 0x2, 0x2, 0x139, 0x13a,
0x7, 0x76, 0x2, 0x2, 0x13a, 0x3c, 0x3, 0x2, 0x2,
0x2, 0x13b, 0x13c, 0x7, 0x65, 0x2, 0x2, 0x13c, 0x13d,
0x7, 0x71, 0x2, 0x2, 0x13d, 0x13e, 0x7, 0x70, 0x2,
0x2, 0x13e, 0x13f, 0x7, 0x78, 0x2, 0x2, 0x13f, 0x140,
0x7, 0x67, 0x2, 0x2, 0x140, 0x141, 0x7, 0x74, 0x2,
0x2, 0x141, 0x142, 0x7, 0x76, 0x2, 0x2, 0x142, 0x3e,
0x3, 0x2, 0x2, 0x2, 0x143, 0x144, 0x7, 0x68, 0x2,
0x2, 0x144, 0x145, 0x7, 0x71, 0x2, 0x2, 0x145, 0x146,
0x7, 0x74, 0x2, 0x2, 0x146, 0x40, 0x3, 0x2, 0x2,
0x2, 0x147, 0x148, 0x7, 0x79, 0x2, 0x2, 0x148, 0x149,
0x7, 0x6a, 0x2, 0x2, 0x149, 0x14a, 0x7, 0x6b, 0x2,
0x2, 0x14a, 0x14b, 0x7, 0x6e, 0x2, 0x2, 0x14b, 0x14c,
0x7, 0x67, 0x2, 0x2, 0x14c, 0x42, 0x3, 0x2, 0x2,
0x2, 0x14d, 0x14e, 0x7, 0x74, 0x2, 0x2, 0x14e, 0x14f,
0x7, 0x67, 0x2, 0x2, 0x14f, 0x150, 0x7, 0x76, 0x2,
0x2, 0x150, 0x151, 0x7, 0x77, 0x2, 0x2, 0x151, 0x152,
0x7, 0x74, 0x2, 0x2, 0x152, 0x153, 0x7, 0x70, 0x2,
0x2, 0x153, 0x44, 0x3, 0x2, 0x2, 0x2, 0x154, 0x155,
0x7, 0x74, 0x2, 0x2, 0x155, 0x156, 0x7, 0x67, 0x2,
0x2, 0x156, 0x157, 0x7, 0x76, 0x2, 0x2, 0x157, 0x158,
0x7, 0x77, 0x2, 0x2, 0x158, 0x159, 0x7, 0x74, 0x2,
0x2, 0x159, 0x15a, 0x7, 0x70, 0x2, 0x2, 0x15a, 0x46,
0x3, 0x2, 0x2, 0x2, 0x15b, 0x15c, 0x7, 0x65, 0x2,
0x2, 0x15c, 0x15d, 0x7, 0x71, 0x2, 0x2, 0x15d, 0x15e,
0x7, 0x70, 0x2, 0x2, 0x15e, 0x15f, 0x7, 0x75, 0x2,
0x2, 0x15f, 0x160, 0x7, 0x76, 0x2, 0x2, 0x160, 0x161,
0x7, 0x67, 0x2, 0x2, 0x161, 0x162, 0x7, 0x7a, 0x2,
0x2, 0x162, 0x163, 0x7, 0x72, 0x2, 0x2, 0x163, 0x164,
0x7, 0x74, 0x2, 0x2, 0x164, 0x48, 0x3, 0x2, 0x2,
0x2, 0x165, 0x166, 0x7, 0x65, 0x2, 0x2, 0x166, 0x167,
0x7, 0x71, 0x2, 0x2, 0x167, 0x168, 0x7, 0x70, 0x2,
0x2, 0x168, 0x169, 0x7, 0x76, 0x2, 0x2, 0x169, 0x16a,
0x7, 0x6b, 0x2, 0x2, 0x16a, 0x16b, 0x7, 0x70, 0x2,
0x2, 0x16b, 0x16c, 0x7, 0x77, 0x2, 0x2, 0x16c, 0x16d,
0x7, 0x67, 0x2, 0x2, 0x16d, 0x4a, 0x3, 0x2, 0x2,
0x2, 0x16e, 0x16f, 0x7, 0x64, 0x2, 0x2, 0x16f, 0x170,
0x7, 0x74, 0x2, 0x2, 0x170, 0x171, 0x7, 0x67, 0x2,
0x2, 0x171, 0x172, 0x7, 0x63, 0x2, 0x2, 0x172, 0x173,
0x7, 0x6d, 0x2, 0x2, 0x173, 0x4c, 0x3, 0x2, 0x2,
0x2, 0x174, 0x175, 0x7, 0x69, 0x2, 0x2, 0x175, 0x176,
0x7, 0x71, 0x2, 0x2, 0x176, 0x177, 0x7, 0x76, 0x2,
0x2, 0x177, 0x178, 0x7, 0x71, 0x2, 0x2, 0x178, 0x4e,
0x3, 0x2, 0x2, 0x2, 0x179, 0x17a, 0x7, 0x71, 0x2,
0x2, 0x17a, 0x17b, 0x7, 0x76, 0x2, 0x2, 0x17b, 0x17c,
0x7, 0x6a, 0x2, 0x2, 0x17c, 0x17d, 0x7, 0x67, 0x2,
0x7, 0x65, 0x2, 0x2, 0x155, 0x156, 0x7, 0x71, 0x2,
0x2, 0x156, 0x157, 0x7, 0x70, 0x2, 0x2, 0x157, 0x158,
0x7, 0x75, 0x2, 0x2, 0x158, 0x159, 0x7, 0x76, 0x2,
0x2, 0x159, 0x15a, 0x7, 0x67, 0x2, 0x2, 0x15a, 0x15b,
0x7, 0x7a, 0x2, 0x2, 0x15b, 0x15c, 0x7, 0x72, 0x2,
0x2, 0x15c, 0x15d, 0x7, 0x74, 0x2, 0x2, 0x15d, 0x46,
0x3, 0x2, 0x2, 0x2, 0x15e, 0x15f, 0x7, 0x65, 0x2,
0x2, 0x15f, 0x160, 0x7, 0x71, 0x2, 0x2, 0x160, 0x161,
0x7, 0x70, 0x2, 0x2, 0x161, 0x162, 0x7, 0x76, 0x2,
0x2, 0x162, 0x163, 0x7, 0x6b, 0x2, 0x2, 0x163, 0x164,
0x7, 0x70, 0x2, 0x2, 0x164, 0x165, 0x7, 0x77, 0x2,
0x2, 0x165, 0x166, 0x7, 0x67, 0x2, 0x2, 0x166, 0x48,
0x3, 0x2, 0x2, 0x2, 0x167, 0x168, 0x7, 0x64, 0x2,
0x2, 0x168, 0x169, 0x7, 0x74, 0x2, 0x2, 0x169, 0x16a,
0x7, 0x67, 0x2, 0x2, 0x16a, 0x16b, 0x7, 0x63, 0x2,
0x2, 0x16b, 0x16c, 0x7, 0x6d, 0x2, 0x2, 0x16c, 0x4a,
0x3, 0x2, 0x2, 0x2, 0x16d, 0x16e, 0x7, 0x69, 0x2,
0x2, 0x16e, 0x16f, 0x7, 0x71, 0x2, 0x2, 0x16f, 0x170,
0x7, 0x76, 0x2, 0x2, 0x170, 0x171, 0x7, 0x71, 0x2,
0x2, 0x171, 0x4c, 0x3, 0x2, 0x2, 0x2, 0x172, 0x173,
0x7, 0x71, 0x2, 0x2, 0x173, 0x174, 0x7, 0x76, 0x2,
0x2, 0x174, 0x175, 0x7, 0x6a, 0x2, 0x2, 0x175, 0x176,
0x7, 0x67, 0x2, 0x2, 0x176, 0x177, 0x7, 0x74, 0x2,
0x2, 0x177, 0x178, 0x7, 0x79, 0x2, 0x2, 0x178, 0x179,
0x7, 0x6b, 0x2, 0x2, 0x179, 0x17a, 0x7, 0x75, 0x2,
0x2, 0x17a, 0x17b, 0x7, 0x67, 0x2, 0x2, 0x17b, 0x4e,
0x3, 0x2, 0x2, 0x2, 0x17c, 0x17d, 0x7, 0x76, 0x2,
0x2, 0x17d, 0x17e, 0x7, 0x74, 0x2, 0x2, 0x17e, 0x17f,
0x7, 0x79, 0x2, 0x2, 0x17f, 0x180, 0x7, 0x6b, 0x2,
0x2, 0x180, 0x181, 0x7, 0x75, 0x2, 0x2, 0x181, 0x182,
0x7, 0x67, 0x2, 0x2, 0x182, 0x50, 0x3, 0x2, 0x2,
0x2, 0x183, 0x184, 0x7, 0x76, 0x2, 0x2, 0x184, 0x185,
0x7, 0x74, 0x2, 0x2, 0x185, 0x186, 0x7, 0x7b, 0x2,
0x2, 0x186, 0x52, 0x3, 0x2, 0x2, 0x2, 0x187, 0x188,
0x7, 0x65, 0x2, 0x2, 0x188, 0x189, 0x7, 0x63, 0x2,
0x2, 0x189, 0x18a, 0x7, 0x76, 0x2, 0x2, 0x18a, 0x18b,
0x7, 0x65, 0x2, 0x2, 0x18b, 0x18c, 0x7, 0x6a, 0x2,
0x2, 0x18c, 0x54, 0x3, 0x2, 0x2, 0x2, 0x18d, 0x18e,
0x7, 0x6e, 0x2, 0x2, 0x18e, 0x18f, 0x7, 0x63, 0x2,
0x2, 0x18f, 0x190, 0x7, 0x64, 0x2, 0x2, 0x190, 0x191,
0x7, 0x67, 0x2, 0x2, 0x191, 0x192, 0x7, 0x6e, 0x2,
0x7, 0x7b, 0x2, 0x2, 0x17f, 0x50, 0x3, 0x2, 0x2,
0x2, 0x180, 0x181, 0x7, 0x65, 0x2, 0x2, 0x181, 0x182,
0x7, 0x63, 0x2, 0x2, 0x182, 0x183, 0x7, 0x76, 0x2,
0x2, 0x183, 0x184, 0x7, 0x65, 0x2, 0x2, 0x184, 0x185,
0x7, 0x6a, 0x2, 0x2, 0x185, 0x52, 0x3, 0x2, 0x2,
0x2, 0x186, 0x187, 0x7, 0x6e, 0x2, 0x2, 0x187, 0x188,
0x7, 0x63, 0x2, 0x2, 0x188, 0x189, 0x7, 0x64, 0x2,
0x2, 0x189, 0x18a, 0x7, 0x67, 0x2, 0x2, 0x18a, 0x18b,
0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x2, 0x2, 0x194, 0x195, 0x7, 0x63, 0x2,
0x2, 0x195, 0x196, 0x7, 0x6b, 0x2, 0x2, 0x196, 0x197,
0x7, 0x6e, 0x2, 0x2, 0x197, 0x58, 0x3, 0x2, 0x2,
0x2, 0x198, 0x199, 0x7, 0x6b, 0x2, 0x2, 0x199, 0x19a,
0x7, 0x75, 0x2, 0x2, 0x19a, 0x19b, 0x7, 0x70, 0x2,
0x2, 0x19b, 0x19c, 0x7, 0x76, 0x2, 0x2, 0x19c, 0x5a,
0x3, 0x2, 0x2, 0x2, 0x19d, 0x19e, 0x7, 0x6b, 0x2,
0x2, 0x19e, 0x19f, 0x7, 0x75, 0x2, 0x2, 0x19f, 0x5c,
0x3, 0x2, 0x2, 0x2, 0x1a0, 0x1a1, 0x7, 0x6e, 0x2,
0x2, 0x1a1, 0x1a2, 0x7, 0x67, 0x2, 0x2, 0x1a2, 0x1a3,
0x7, 0x76, 0x2, 0x2, 0x1a3, 0x5e, 0x3, 0x2, 0x2,
0x2, 0x1a4, 0x1a5, 0x7, 0x67, 0x2, 0x2, 0x1a5, 0x1a6,
0x7, 0x7a, 0x2, 0x2, 0x1a6, 0x1a7, 0x7, 0x76, 0x2,
0x2, 0x1a7, 0x1a8, 0x7, 0x67, 0x2, 0x2, 0x1a8, 0x1a9,
0x7, 0x74, 0x2, 0x2, 0x1a9, 0x1aa, 0x7, 0x70, 0x2,
0x2, 0x1aa, 0x60, 0x3, 0x2, 0x2, 0x2, 0x1ab, 0x1ac,
0x7, 0x63, 0x2, 0x2, 0x1ac, 0x1ad, 0x7, 0x75, 0x2,
0x2, 0x1ad, 0x1ae, 0x7, 0x75, 0x2, 0x2, 0x1ae, 0x1af,
......
......@@ -33,33 +33,33 @@ class TorqueLexer : public antlr4::Lexer {
T__17 = 18,
T__18 = 19,
T__19 = 20,
T__20 = 21,
MACRO = 22,
BUILTIN = 23,
RUNTIME = 24,
MODULE = 25,
JAVASCRIPT = 26,
IMPLICIT = 27,
DEFERRED = 28,
IF = 29,
CAST_KEYWORD = 30,
CONVERT_KEYWORD = 31,
FOR = 32,
WHILE = 33,
RETURN = 34,
CONSTEXPR = 35,
CONTINUE = 36,
BREAK = 37,
GOTO = 38,
OTHERWISE = 39,
TRY = 40,
CATCH = 41,
LABEL = 42,
LABELS = 43,
TAIL = 44,
ISNT = 45,
IS = 46,
LET = 47,
MACRO = 21,
BUILTIN = 22,
RUNTIME = 23,
MODULE = 24,
JAVASCRIPT = 25,
IMPLICIT = 26,
DEFERRED = 27,
IF = 28,
CAST_KEYWORD = 29,
CONVERT_KEYWORD = 30,
FOR = 31,
WHILE = 32,
RETURN = 33,
CONSTEXPR = 34,
CONTINUE = 35,
BREAK = 36,
GOTO = 37,
OTHERWISE = 38,
TRY = 39,
CATCH = 40,
LABEL = 41,
LABELS = 42,
TAIL = 43,
ISNT = 44,
IS = 45,
LET = 46,
EXTERN = 47,
ASSERT = 48,
UNREACHABLE_TOKEN = 49,
DEBUG_TOKEN = 50,
......
......@@ -23,6 +23,16 @@ class TorqueListener : public antlr4::tree::ParseTreeListener {
virtual void enterTypeList(TorqueParser::TypeListContext* ctx) = 0;
virtual void exitTypeList(TorqueParser::TypeListContext* ctx) = 0;
virtual void enterOptionalGenericSpecializationTypeList(
TorqueParser::OptionalGenericSpecializationTypeListContext* ctx) = 0;
virtual void exitOptionalGenericSpecializationTypeList(
TorqueParser::OptionalGenericSpecializationTypeListContext* ctx) = 0;
virtual void enterOptionalGenericTypeList(
TorqueParser::OptionalGenericTypeListContext* ctx) = 0;
virtual void exitOptionalGenericTypeList(
TorqueParser::OptionalGenericTypeListContext* ctx) = 0;
virtual void enterTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* ctx) = 0;
virtual void exitTypeListMaybeVarArgs(
......@@ -274,6 +284,11 @@ class TorqueListener : public antlr4::tree::ParseTreeListener {
virtual void exitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* ctx) = 0;
virtual void enterGenericSpecialization(
TorqueParser::GenericSpecializationContext* ctx) = 0;
virtual void exitGenericSpecialization(
TorqueParser::GenericSpecializationContext* ctx) = 0;
virtual void enterMacroDeclaration(
TorqueParser::MacroDeclarationContext* ctx) = 0;
virtual void exitMacroDeclaration(
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -33,33 +33,33 @@ class TorqueParser : public antlr4::Parser {
T__17 = 18,
T__18 = 19,
T__19 = 20,
T__20 = 21,
MACRO = 22,
BUILTIN = 23,
RUNTIME = 24,
MODULE = 25,
JAVASCRIPT = 26,
IMPLICIT = 27,
DEFERRED = 28,
IF = 29,
CAST_KEYWORD = 30,
CONVERT_KEYWORD = 31,
FOR = 32,
WHILE = 33,
RETURN = 34,
CONSTEXPR = 35,
CONTINUE = 36,
BREAK = 37,
GOTO = 38,
OTHERWISE = 39,
TRY = 40,
CATCH = 41,
LABEL = 42,
LABELS = 43,
TAIL = 44,
ISNT = 45,
IS = 46,
LET = 47,
MACRO = 21,
BUILTIN = 22,
RUNTIME = 23,
MODULE = 24,
JAVASCRIPT = 25,
IMPLICIT = 26,
DEFERRED = 27,
IF = 28,
CAST_KEYWORD = 29,
CONVERT_KEYWORD = 30,
FOR = 31,
WHILE = 32,
RETURN = 33,
CONSTEXPR = 34,
CONTINUE = 35,
BREAK = 36,
GOTO = 37,
OTHERWISE = 38,
TRY = 39,
CATCH = 40,
LABEL = 41,
LABELS = 42,
TAIL = 43,
ISNT = 44,
IS = 45,
LET = 46,
EXTERN = 47,
ASSERT = 48,
UNREACHABLE_TOKEN = 49,
DEBUG_TOKEN = 50,
......@@ -100,70 +100,73 @@ class TorqueParser : public antlr4::Parser {
enum {
RuleType = 0,
RuleTypeList = 1,
RuleTypeListMaybeVarArgs = 2,
RuleLabelParameter = 3,
RuleOptionalType = 4,
RuleOptionalLabelList = 5,
RuleOptionalOtherwise = 6,
RuleParameter = 7,
RuleParameterList = 8,
RuleLabelDeclaration = 9,
RuleExpression = 10,
RuleConditionalExpression = 11,
RuleLogicalORExpression = 12,
RuleLogicalANDExpression = 13,
RuleBitwiseExpression = 14,
RuleEqualityExpression = 15,
RuleRelationalExpression = 16,
RuleShiftExpression = 17,
RuleAdditiveExpression = 18,
RuleMultiplicativeExpression = 19,
RuleUnaryExpression = 20,
RuleLocationExpression = 21,
RuleIncrementDecrement = 22,
RuleAssignment = 23,
RuleAssignmentExpression = 24,
RulePrimaryExpression = 25,
RuleForInitialization = 26,
RuleForLoop = 27,
RuleRangeSpecifier = 28,
RuleForOfRange = 29,
RuleForOfLoop = 30,
RuleArgument = 31,
RuleArgumentList = 32,
RuleHelperCall = 33,
RuleLabelReference = 34,
RuleVariableDeclaration = 35,
RuleVariableDeclarationWithInitialization = 36,
RuleHelperCallStatement = 37,
RuleExpressionStatement = 38,
RuleIfStatement = 39,
RuleWhileLoop = 40,
RuleReturnStatement = 41,
RuleBreakStatement = 42,
RuleContinueStatement = 43,
RuleGotoStatement = 44,
RuleHandlerWithStatement = 45,
RuleTryCatch = 46,
RuleDiagnosticStatement = 47,
RuleStatement = 48,
RuleStatementList = 49,
RuleStatementScope = 50,
RuleStatementBlock = 51,
RuleHelperBody = 52,
RuleExtendsDeclaration = 53,
RuleGeneratesDeclaration = 54,
RuleConstexprDeclaration = 55,
RuleTypeDeclaration = 56,
RuleExternalBuiltin = 57,
RuleExternalMacro = 58,
RuleExternalRuntime = 59,
RuleBuiltinDeclaration = 60,
RuleMacroDeclaration = 61,
RuleConstDeclaration = 62,
RuleDeclaration = 63,
RuleModuleDeclaration = 64,
RuleFile = 65
RuleOptionalGenericSpecializationTypeList = 2,
RuleOptionalGenericTypeList = 3,
RuleTypeListMaybeVarArgs = 4,
RuleLabelParameter = 5,
RuleOptionalType = 6,
RuleOptionalLabelList = 7,
RuleOptionalOtherwise = 8,
RuleParameter = 9,
RuleParameterList = 10,
RuleLabelDeclaration = 11,
RuleExpression = 12,
RuleConditionalExpression = 13,
RuleLogicalORExpression = 14,
RuleLogicalANDExpression = 15,
RuleBitwiseExpression = 16,
RuleEqualityExpression = 17,
RuleRelationalExpression = 18,
RuleShiftExpression = 19,
RuleAdditiveExpression = 20,
RuleMultiplicativeExpression = 21,
RuleUnaryExpression = 22,
RuleLocationExpression = 23,
RuleIncrementDecrement = 24,
RuleAssignment = 25,
RuleAssignmentExpression = 26,
RulePrimaryExpression = 27,
RuleForInitialization = 28,
RuleForLoop = 29,
RuleRangeSpecifier = 30,
RuleForOfRange = 31,
RuleForOfLoop = 32,
RuleArgument = 33,
RuleArgumentList = 34,
RuleHelperCall = 35,
RuleLabelReference = 36,
RuleVariableDeclaration = 37,
RuleVariableDeclarationWithInitialization = 38,
RuleHelperCallStatement = 39,
RuleExpressionStatement = 40,
RuleIfStatement = 41,
RuleWhileLoop = 42,
RuleReturnStatement = 43,
RuleBreakStatement = 44,
RuleContinueStatement = 45,
RuleGotoStatement = 46,
RuleHandlerWithStatement = 47,
RuleTryCatch = 48,
RuleDiagnosticStatement = 49,
RuleStatement = 50,
RuleStatementList = 51,
RuleStatementScope = 52,
RuleStatementBlock = 53,
RuleHelperBody = 54,
RuleExtendsDeclaration = 55,
RuleGeneratesDeclaration = 56,
RuleConstexprDeclaration = 57,
RuleTypeDeclaration = 58,
RuleExternalBuiltin = 59,
RuleExternalMacro = 60,
RuleExternalRuntime = 61,
RuleBuiltinDeclaration = 62,
RuleGenericSpecialization = 63,
RuleMacroDeclaration = 64,
RuleConstDeclaration = 65,
RuleDeclaration = 66,
RuleModuleDeclaration = 67,
RuleFile = 68
};
explicit TorqueParser(antlr4::TokenStream* input);
......@@ -179,6 +182,8 @@ class TorqueParser : public antlr4::Parser {
class TypeContext;
class TypeListContext;
class OptionalGenericSpecializationTypeListContext;
class OptionalGenericTypeListContext;
class TypeListMaybeVarArgsContext;
class LabelParameterContext;
class OptionalTypeContext;
......@@ -238,6 +243,7 @@ class TorqueParser : public antlr4::Parser {
class ExternalMacroContext;
class ExternalRuntimeContext;
class BuiltinDeclarationContext;
class GenericSpecializationContext;
class MacroDeclarationContext;
class ConstDeclarationContext;
class DeclarationContext;
......@@ -274,6 +280,40 @@ class TorqueParser : public antlr4::Parser {
TypeListContext* typeList();
class OptionalGenericSpecializationTypeListContext
: public antlr4::ParserRuleContext {
public:
OptionalGenericSpecializationTypeListContext(
antlr4::ParserRuleContext* parent, size_t invokingState);
size_t getRuleIndex() const override;
std::vector<antlr4::tree::TerminalNode*> IDENTIFIER();
antlr4::tree::TerminalNode* IDENTIFIER(size_t i);
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override;
};
OptionalGenericSpecializationTypeListContext*
optionalGenericSpecializationTypeList();
class OptionalGenericTypeListContext : public antlr4::ParserRuleContext {
public:
OptionalGenericTypeListContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
std::vector<antlr4::tree::TerminalNode*> IDENTIFIER();
antlr4::tree::TerminalNode* IDENTIFIER(size_t i);
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override;
};
OptionalGenericTypeListContext* optionalGenericTypeList();
class TypeListMaybeVarArgsContext : public antlr4::ParserRuleContext {
public:
TypeListMaybeVarArgsContext(antlr4::ParserRuleContext* parent,
......@@ -817,6 +857,8 @@ class TorqueParser : public antlr4::Parser {
public:
HelperCallContext(antlr4::ParserRuleContext* parent, size_t invokingState);
size_t getRuleIndex() const override;
OptionalGenericSpecializationTypeListContext*
optionalGenericSpecializationTypeList();
ArgumentListContext* argumentList();
OptionalOtherwiseContext* optionalOtherwise();
antlr4::tree::TerminalNode* MIN();
......@@ -1220,8 +1262,10 @@ class TorqueParser : public antlr4::Parser {
ExternalBuiltinContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* EXTERN();
antlr4::tree::TerminalNode* BUILTIN();
antlr4::tree::TerminalNode* IDENTIFIER();
OptionalGenericTypeListContext* optionalGenericTypeList();
TypeListContext* typeList();
OptionalTypeContext* optionalType();
antlr4::tree::TerminalNode* JAVASCRIPT();
......@@ -1239,8 +1283,10 @@ class TorqueParser : public antlr4::Parser {
ExternalMacroContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* EXTERN();
antlr4::tree::TerminalNode* MACRO();
antlr4::tree::TerminalNode* IDENTIFIER();
OptionalGenericTypeListContext* optionalGenericTypeList();
TypeListMaybeVarArgsContext* typeListMaybeVarArgs();
OptionalTypeContext* optionalType();
OptionalLabelListContext* optionalLabelList();
......@@ -1260,6 +1306,7 @@ class TorqueParser : public antlr4::Parser {
ExternalRuntimeContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* EXTERN();
antlr4::tree::TerminalNode* RUNTIME();
antlr4::tree::TerminalNode* IDENTIFIER();
TypeListMaybeVarArgsContext* typeListMaybeVarArgs();
......@@ -1280,6 +1327,7 @@ class TorqueParser : public antlr4::Parser {
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* BUILTIN();
antlr4::tree::TerminalNode* IDENTIFIER();
OptionalGenericTypeListContext* optionalGenericTypeList();
ParameterListContext* parameterList();
OptionalTypeContext* optionalType();
HelperBodyContext* helperBody();
......@@ -1293,6 +1341,27 @@ class TorqueParser : public antlr4::Parser {
BuiltinDeclarationContext* builtinDeclaration();
class GenericSpecializationContext : public antlr4::ParserRuleContext {
public:
GenericSpecializationContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* IDENTIFIER();
OptionalGenericSpecializationTypeListContext*
optionalGenericSpecializationTypeList();
ParameterListContext* parameterList();
OptionalTypeContext* optionalType();
OptionalLabelListContext* optionalLabelList();
HelperBodyContext* helperBody();
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override;
};
GenericSpecializationContext* genericSpecialization();
class MacroDeclarationContext : public antlr4::ParserRuleContext {
public:
MacroDeclarationContext(antlr4::ParserRuleContext* parent,
......@@ -1300,6 +1369,7 @@ class TorqueParser : public antlr4::Parser {
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* MACRO();
antlr4::tree::TerminalNode* IDENTIFIER();
OptionalGenericTypeListContext* optionalGenericTypeList();
ParameterListContext* parameterList();
OptionalTypeContext* optionalType();
OptionalLabelListContext* optionalLabelList();
......@@ -1336,6 +1406,7 @@ class TorqueParser : public antlr4::Parser {
size_t getRuleIndex() const override;
TypeDeclarationContext* typeDeclaration();
BuiltinDeclarationContext* builtinDeclaration();
GenericSpecializationContext* genericSpecialization();
MacroDeclarationContext* macroDeclaration();
ExternalMacroContext* externalMacro();
ExternalBuiltinContext* externalBuiltin();
......
......@@ -25,6 +25,12 @@ class TorqueVisitor : public antlr4::tree::AbstractParseTreeVisitor {
virtual antlrcpp::Any visitTypeList(
TorqueParser::TypeListContext* context) = 0;
virtual antlrcpp::Any visitOptionalGenericSpecializationTypeList(
TorqueParser::OptionalGenericSpecializationTypeListContext* context) = 0;
virtual antlrcpp::Any visitOptionalGenericTypeList(
TorqueParser::OptionalGenericTypeListContext* context) = 0;
virtual antlrcpp::Any visitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* context) = 0;
......@@ -201,6 +207,9 @@ class TorqueVisitor : public antlr4::tree::AbstractParseTreeVisitor {
virtual antlrcpp::Any visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* context) = 0;
virtual antlrcpp::Any visitGenericSpecialization(
TorqueParser::GenericSpecializationContext* context) = 0;
virtual antlrcpp::Any visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* context) = 0;
......
......@@ -26,6 +26,24 @@ std::string GetOptionalType(TorqueParser::OptionalTypeContext* context) {
return GetType(context->type());
}
std::vector<std::string> GetTypeVector(
TorqueParser::TypeListContext* type_list) {
std::vector<std::string> result;
for (auto s : type_list->type()) {
result.push_back(GetType(s));
}
return result;
}
std::vector<std::string> GetIdentifierVector(
std::vector<antlr4::tree::TerminalNode*> source) {
std::vector<std::string> result;
for (auto s : source) {
result.push_back(s->getSymbol()->getText());
}
return result;
}
LabelAndTypesVector GetOptionalLabelAndTypeList(
TorqueParser::OptionalLabelListContext* context) {
LabelAndTypesVector labels;
......@@ -34,9 +52,7 @@ LabelAndTypesVector GetOptionalLabelAndTypeList(
LabelAndTypes new_label;
new_label.name = label->IDENTIFIER()->getSymbol()->getText();
if (label->typeList() != nullptr) {
for (auto& type : label->typeList()->type()) {
new_label.types.emplace_back(GetType(type));
}
new_label.types = GetTypeVector(label->typeList());
}
labels.emplace_back(new_label);
}
......@@ -109,10 +125,7 @@ antlrcpp::Any AstGenerator::visitParameterList(
antlrcpp::Any AstGenerator::visitTypeList(
TorqueParser::TypeListContext* context) {
ParameterList result{{}, {}, false, {}};
result.types.reserve(context->type().size());
for (auto* type : context->type()) {
result.types.push_back(GetType(type));
}
result.types = GetTypeVector(context);
return std::move(result);
}
......@@ -139,27 +152,51 @@ antlrcpp::Any AstGenerator::visitModuleDeclaration(
antlrcpp::Any AstGenerator::visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* context) {
return implicit_cast<Declaration*>(RegisterNode(new MacroDeclaration{
auto generic_parameters =
GetIdentifierVector(context->optionalGenericTypeList()->IDENTIFIER());
MacroDeclaration* macro = RegisterNode(new TorqueMacroDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(),
GetOptionalParameterList(context->parameterList()),
GetOptionalType(context->optionalType()),
GetOptionalLabelAndTypeList(context->optionalLabelList()),
context->helperBody()->accept(this).as<Statement*>()}));
GetOptionalLabelAndTypeList(context->optionalLabelList())});
auto 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});
}
return result;
}
antlrcpp::Any AstGenerator::visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* context) {
return implicit_cast<Declaration*>(RegisterNode(new BuiltinDeclaration{
auto generic_parameters =
GetIdentifierVector(context->optionalGenericTypeList()->IDENTIFIER());
Statement* body = context->helperBody()->accept(this).as<Statement*>();
TorqueBuiltinDeclaration* builtin = RegisterNode(new TorqueBuiltinDeclaration{
Pos(context), context->JAVASCRIPT() != nullptr,
context->IDENTIFIER()->getSymbol()->getText(),
std::move(context->parameterList()->accept(this).as<ParameterList>()),
GetOptionalType(context->optionalType()),
context->helperBody()->accept(this).as<Statement*>()}));
GetOptionalType(context->optionalType())});
Declaration* result = nullptr;
if (generic_parameters.size() != 0) {
result = RegisterNode(new GenericDeclaration{Pos(context), builtin,
generic_parameters, body});
} else {
result = RegisterNode(new StandardDeclaration{Pos(context), builtin, body});
}
return result;
}
antlrcpp::Any AstGenerator::visitExternalMacro(
TorqueParser::ExternalMacroContext* context) {
ExternalMacroDeclaration* result = RegisterNode(new ExternalMacroDeclaration{
auto generic_parameters =
GetIdentifierVector(context->optionalGenericTypeList()->IDENTIFIER());
MacroDeclaration* macro = RegisterNode(new ExternalMacroDeclaration{
Pos(context),
context->IDENTIFIER()->getSymbol()->getText(),
context->IMPLICIT() != nullptr,
......@@ -169,29 +206,64 @@ antlrcpp::Any AstGenerator::visitExternalMacro(
GetOptionalType(context->optionalType()),
GetOptionalLabelAndTypeList(context->optionalLabelList())});
if (auto* op = context->STRING_LITERAL())
result->op = StringLiteralUnquote(op->getSymbol()->getText());
return implicit_cast<Declaration*>(result);
macro->op = StringLiteralUnquote(op->getSymbol()->getText());
Declaration* result = nullptr;
if (generic_parameters.size() != 0) {
result = RegisterNode(new GenericDeclaration{Pos(context), macro,
generic_parameters, nullptr});
} else {
result =
RegisterNode(new StandardDeclaration{Pos(context), macro, nullptr});
}
return result;
}
antlrcpp::Any AstGenerator::visitExternalBuiltin(
TorqueParser::ExternalBuiltinContext* context) {
return implicit_cast<Declaration*>(
auto generic_parameters =
GetIdentifierVector(context->optionalGenericTypeList()->IDENTIFIER());
ExternalBuiltinDeclaration* builtin =
RegisterNode(new ExternalBuiltinDeclaration{
Pos(context), context->JAVASCRIPT() != nullptr,
context->IDENTIFIER()->getSymbol()->getText(),
std::move(context->typeList()->accept(this).as<ParameterList>()),
GetOptionalType(context->optionalType())}));
GetOptionalType(context->optionalType())});
Declaration* result = nullptr;
if (generic_parameters.size() != 0) {
result = RegisterNode(new GenericDeclaration{Pos(context), builtin,
generic_parameters, nullptr});
} else {
result =
RegisterNode(new StandardDeclaration{Pos(context), builtin, nullptr});
}
return result;
}
antlrcpp::Any AstGenerator::visitExternalRuntime(
TorqueParser::ExternalRuntimeContext* context) {
return implicit_cast<Declaration*>(
ExternalRuntimeDeclaration* runtime =
RegisterNode(new ExternalRuntimeDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(),
std::move(context->typeListMaybeVarArgs()
->accept(this)
.as<ParameterList>()),
GetOptionalType(context->optionalType())}));
GetOptionalType(context->optionalType())});
return implicit_cast<Declaration*>(
RegisterNode(new StandardDeclaration{Pos(context), runtime, nullptr}));
}
antlrcpp::Any AstGenerator::visitGenericSpecialization(
TorqueParser::GenericSpecializationContext* context) {
auto name = context->IDENTIFIER()->getSymbol()->getText();
auto specialization_parameters = GetIdentifierVector(
context->optionalGenericSpecializationTypeList()->IDENTIFIER());
Statement* body = context->helperBody()->accept(this).as<Statement*>();
return implicit_cast<Declaration*>(RegisterNode(new SpecializationDeclaration{
Pos(context), name, specialization_parameters,
GetOptionalParameterList(context->parameterList()),
GetOptionalType(context->optionalType()),
GetOptionalLabelAndTypeList(context->optionalLabelList()), body}));
}
antlrcpp::Any AstGenerator::visitConstDeclaration(
......@@ -259,7 +331,13 @@ antlrcpp::Any AstGenerator::visitHelperCall(
labels.push_back(label->getSymbol()->getText());
}
CallExpression* result = RegisterNode(new CallExpression{
Pos(context), callee->getSymbol()->getText(), is_operator, {}, labels});
Pos(context),
callee->getSymbol()->getText(),
is_operator,
GetIdentifierVector(
context->optionalGenericSpecializationTypeList()->IDENTIFIER()),
{},
labels});
for (auto* arg : context->argumentList()->argument()) {
result->arguments.push_back(arg->accept(this).as<Expression*>());
}
......@@ -501,7 +579,7 @@ antlrcpp::Any AstGenerator::visitUnaryExpression(
std::vector<Expression*> args;
args.push_back(context->unaryExpression()->accept(this).as<Expression*>());
return implicit_cast<Expression*>(RegisterNode(new CallExpression{
Pos(context), context->op->getText(), true, std::move(args), {}}));
Pos(context), context->op->getText(), true, {}, std::move(args), {}}));
}
antlrcpp::Any AstGenerator::visitMultiplicativeExpression(
......@@ -512,6 +590,7 @@ antlrcpp::Any AstGenerator::visitMultiplicativeExpression(
RegisterNode(new CallExpression{Pos(context),
context->op->getText(),
true,
{},
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}}));
......@@ -527,6 +606,7 @@ antlrcpp::Any AstGenerator::visitAdditiveExpression(
RegisterNode(new CallExpression{Pos(context),
context->op->getText(),
true,
{},
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}}));
......@@ -542,6 +622,7 @@ antlrcpp::Any AstGenerator::visitShiftExpression(
RegisterNode(new CallExpression{Pos(context),
context->op->getText(),
true,
{},
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}}));
......@@ -557,6 +638,7 @@ antlrcpp::Any AstGenerator::visitRelationalExpression(
RegisterNode(new CallExpression{Pos(context),
context->op->getText(),
true,
{},
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}}));
......@@ -572,6 +654,7 @@ antlrcpp::Any AstGenerator::visitEqualityExpression(
RegisterNode(new CallExpression{Pos(context),
context->op->getText(),
true,
{},
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}}));
......@@ -587,6 +670,7 @@ antlrcpp::Any AstGenerator::visitBitwiseExpression(
RegisterNode(new CallExpression{Pos(context),
context->op->getText(),
true,
{},
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}}));
......
......@@ -41,6 +41,9 @@ class AstGenerator : public TorqueBaseVisitor {
antlrcpp::Any visitExternalRuntime(
TorqueParser::ExternalRuntimeContext* context) override;
antlrcpp::Any visitGenericSpecialization(
TorqueParser::GenericSpecializationContext* context) override;
antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) override;
......
......@@ -58,19 +58,25 @@ struct SourcePosition {
#define AST_DECLARATION_NODE_KIND_LIST(V) \
V(TypeDeclaration) \
V(MacroDeclaration) \
V(ExternalMacroDeclaration) \
V(BuiltinDeclaration) \
V(ExternalBuiltinDeclaration) \
V(ExternalRuntimeDeclaration) \
V(StandardDeclaration) \
V(GenericDeclaration) \
V(SpecializationDeclaration) \
V(ConstDeclaration) \
V(DefaultModuleDeclaration) \
V(ExplicitModuleDeclaration)
#define AST_CALLABLE_NODE_KIND_LIST(V) \
V(TorqueMacroDeclaration) \
V(TorqueBuiltinDeclaration) \
V(ExternalMacroDeclaration) \
V(ExternalBuiltinDeclaration) \
V(ExternalRuntimeDeclaration)
#define AST_NODE_KIND_LIST(V) \
AST_EXPRESSION_NODE_KIND_LIST(V) \
AST_STATEMENT_NODE_KIND_LIST(V) \
AST_DECLARATION_NODE_KIND_LIST(V) \
AST_CALLABLE_NODE_KIND_LIST(V) \
V(CatchBlock) \
V(LabelBlock)
......@@ -211,14 +217,17 @@ class Ast {
struct CallExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(CallExpression)
CallExpression(SourcePosition p, std::string c, bool o,
std::vector<Expression*> a, std::vector<std::string> l)
std::vector<std::string> ga, std::vector<Expression*> a,
std::vector<std::string> l)
: Expression(kKind, p),
callee(std::move(c)),
is_operator(o),
generic_arguments(ga),
arguments(std::move(a)),
labels(l) {}
std::string callee;
bool is_operator;
std::vector<std::string> generic_arguments;
std::vector<Expression*> arguments;
std::vector<std::string> labels;
};
......@@ -516,86 +525,112 @@ struct LabelAndTypes {
typedef std::vector<LabelAndTypes> LabelAndTypesVector;
struct MacroDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(MacroDeclaration)
MacroDeclaration(SourcePosition p, std::string n, ParameterList pl,
std::string r, const LabelAndTypesVector& l, Statement* b)
: Declaration(kKind, p),
name(std::move(n)),
parameters(std::move(pl)),
return_type(std::move(r)),
labels(std::move(l)),
body(std::move(b)) {}
std::string name;
struct CallableNodeSignature {
ParameterList parameters;
std::string return_type;
LabelAndTypesVector labels;
Statement* body;
};
struct ExternalMacroDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalMacroDeclaration)
ExternalMacroDeclaration(SourcePosition p, std::string n, bool i,
base::Optional<std::string> o, ParameterList pl,
std::string r, const LabelAndTypesVector& l)
: Declaration(kKind, p),
struct CallableNode : AstNode {
CallableNode(AstNode::Kind kind, SourcePosition p, std::string n,
ParameterList pl, std::string r, const LabelAndTypesVector& l)
: AstNode(kind, p),
name(std::move(n)),
implicit(i),
op(std::move(o)),
parameters(std::move(pl)),
return_type(std::move(r)),
labels(std::move(l)) {}
signature(new CallableNodeSignature{pl, r, l}) {}
DEFINE_AST_NODE_INNER_BOILERPLATE(CallableNode)
std::string name;
std::unique_ptr<CallableNodeSignature> signature;
};
struct MacroDeclaration : CallableNode {
DEFINE_AST_NODE_INNER_BOILERPLATE(MacroDeclaration)
MacroDeclaration(AstNode::Kind kind, SourcePosition p, std::string n, bool i,
base::Optional<std::string> o, ParameterList pl,
std::string r, const LabelAndTypesVector& l)
: CallableNode(kind, p, n, pl, r, l), implicit(i), op(std::move(o)) {}
bool implicit;
base::Optional<std::string> op;
ParameterList parameters;
std::string return_type;
LabelAndTypesVector labels;
};
struct BuiltinDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(BuiltinDeclaration)
BuiltinDeclaration(SourcePosition p, bool j, std::string n, ParameterList pl,
std::string r, Statement* b)
: Declaration(kKind, p),
javascript_linkage(j),
name(std::move(n)),
parameters(std::move(pl)),
return_type(std::move(r)),
body(std::move(b)) {}
struct ExternalMacroDeclaration : MacroDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalMacroDeclaration)
ExternalMacroDeclaration(SourcePosition p, std::string n, bool i,
base::Optional<std::string> o, ParameterList pl,
std::string r, const LabelAndTypesVector& l)
: MacroDeclaration(kKind, p, n, i, o, pl, r, l) {}
};
struct TorqueMacroDeclaration : MacroDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(TorqueMacroDeclaration)
TorqueMacroDeclaration(SourcePosition p, std::string n, ParameterList pl,
std::string r, const LabelAndTypesVector& l)
: MacroDeclaration(kKind, p, n, false, {}, pl, r, l) {}
};
struct BuiltinDeclaration : CallableNode {
BuiltinDeclaration(AstNode::Kind kind, SourcePosition p, bool j,
std::string n, ParameterList pl, std::string r)
: CallableNode(kind, p, n, pl, r, {}), javascript_linkage(j) {}
bool javascript_linkage;
std::string name;
ParameterList parameters;
std::string return_type;
Statement* body;
};
struct ExternalBuiltinDeclaration : Declaration {
struct ExternalBuiltinDeclaration : BuiltinDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalBuiltinDeclaration)
ExternalBuiltinDeclaration(SourcePosition p, bool j, std::string n,
ParameterList pl, std::string r)
: Declaration(kKind, p),
javascript_linkage(j),
name(std::move(n)),
parameters(std::move(pl)),
return_type(std::move(r)) {}
bool javascript_linkage;
std::string name;
ParameterList parameters;
std::string return_type;
: BuiltinDeclaration(kKind, p, j, n, pl, r) {}
};
struct TorqueBuiltinDeclaration : BuiltinDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(TorqueBuiltinDeclaration)
TorqueBuiltinDeclaration(SourcePosition p, bool j, std::string n,
ParameterList pl, std::string r)
: BuiltinDeclaration(kKind, p, j, n, pl, r) {}
};
struct ExternalRuntimeDeclaration : Declaration {
struct ExternalRuntimeDeclaration : CallableNode {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalRuntimeDeclaration)
ExternalRuntimeDeclaration(SourcePosition p, std::string n, ParameterList pl,
std::string r)
: CallableNode(kKind, p, n, pl, r, {}) {}
};
struct StandardDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(StandardDeclaration)
StandardDeclaration(SourcePosition p, CallableNode* c, Statement* b)
: Declaration(kKind, p), callable(c), body(b) {}
CallableNode* callable;
Statement* body;
};
struct GenericDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(GenericDeclaration)
GenericDeclaration(SourcePosition p, CallableNode* c,
std::vector<std::string> gp, Statement* b)
: Declaration(kKind, p),
callable(c),
generic_parameters(std::move(gp)),
body(b) {}
CallableNode* callable;
std::vector<std::string> generic_parameters;
Statement* body;
};
struct SpecializationDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(SpecializationDeclaration)
SpecializationDeclaration(SourcePosition p, std::string n,
std::vector<std::string> gp, ParameterList pl,
std::string r, LabelAndTypesVector l, Statement* b)
: Declaration(kKind, p),
name(std::move(n)),
parameters(std::move(pl)),
return_type(std::move(r)) {}
generic_parameters(gp),
signature(new CallableNodeSignature{pl, r, l}),
body(std::move(b)) {}
DEFINE_AST_NODE_INNER_BOILERPLATE(SpecializationDeclaration)
std::string name;
ParameterList parameters;
std::string return_type;
std::vector<std::string> generic_parameters;
std::unique_ptr<CallableNodeSignature> signature;
Statement* body;
};
struct ConstDeclaration : Declaration {
......
......@@ -9,6 +9,7 @@
#include <string>
#include "src/base/logging.h"
#include "src/torque/ast.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
......@@ -30,6 +31,8 @@ class Declarable {
kMacroList,
kBuiltin,
kRuntimeFunction,
kGeneric,
kTypeAlias,
kLabel,
kConstant
};
......@@ -39,6 +42,8 @@ class Declarable {
bool IsMacro() const { return kind() == kMacro; }
bool IsBuiltin() const { return kind() == kBuiltin; }
bool IsRuntimeFunction() const { return kind() == kRuntimeFunction; }
bool IsGeneric() const { return kind() == kGeneric; }
bool IsTypeAlias() const { return kind() == kTypeAlias; }
bool IsParameter() const { return kind() == kParameter; }
bool IsLabel() const { return kind() == kLabel; }
bool IsVariable() const { return kind() == kVariable; }
......@@ -296,9 +301,44 @@ class RuntimeFunction : public Callable {
: Callable(Declarable::kRuntimeFunction, name, signature) {}
};
class Generic : public Declarable {
public:
DECLARE_DECLARABLE_BOILERPLATE(Generic, generic);
GenericDeclaration* declaration() const { return declaration_; }
Module* module() const { return module_; }
private:
friend class Declarations;
Generic(const std::string& name, Module* module,
GenericDeclaration* declaration)
: Declarable(Declarable::kGeneric),
module_(module),
declaration_(declaration) {}
Module* module_;
GenericDeclaration* declaration_;
};
typedef std::pair<Generic*, TypeVector> SpecializationKey;
class TypeAlias : public Declarable {
public:
DECLARE_DECLARABLE_BOILERPLATE(TypeAlias, instantiated_type);
const Type* type() const { return type_; }
private:
friend class Declarations;
TypeAlias(const std::string& name, const Type* type)
: Declarable(Declarable::kTypeAlias), type_(type) {}
const Type* type_;
};
inline std::ostream& operator<<(std::ostream& os, const Callable& m) {
os << "macro " << m.signature().return_type << " " << m.name()
<< m.signature().parameter_types;
os << "callable " << m.name() << "(" << m.signature().parameter_types
<< "): " << m.signature().return_type;
return os;
}
......
......@@ -44,25 +44,27 @@ void DeclarationVisitor::Visit(Declaration* decl) {
}
}
void DeclarationVisitor::Visit(BuiltinDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of builtin " << decl->name;
void DeclarationVisitor::Visit(CallableNode* decl, const Signature& signature,
Statement* body) {
switch (decl->kind) {
#define ENUM_ITEM(name) \
case AstNode::Kind::k##name: \
return Visit(name::cast(decl), signature, body);
AST_CALLABLE_NODE_KIND_LIST(ENUM_ITEM)
#undef ENUM_ITEM
default:
UNIMPLEMENTED();
}
}
Builtin* DeclarationVisitor::BuiltinDeclarationCommon(
BuiltinDeclaration* decl, const Signature& signature) {
const bool javascript = decl->javascript_linkage;
const bool varargs = decl->parameters.has_varargs;
const bool varargs = decl->signature->parameters.has_varargs;
Builtin::Kind kind = !javascript ? Builtin::kStub
: varargs ? Builtin::kVarArgsJavaScript
: Builtin::kFixedArgsJavaScript;
Signature signature =
MakeSignature(decl->pos, decl->parameters, decl->return_type, {});
Builtin* builtin =
declarations()->DeclareBuiltin(decl->pos, decl->name, kind, signature);
CurrentCallableActivator activator(global_context_, builtin, decl);
DeclareParameterList(decl->pos, signature, {});
if (signature.types().size() == 0 ||
!(signature.types()[0]->name() == CONTEXT_TYPE_STRING)) {
std::stringstream stream;
......@@ -71,9 +73,6 @@ void DeclarationVisitor::Visit(BuiltinDeclaration* decl) {
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
if (global_context_.verbose()) {
std::cout << decl->name << " with signature " << signature << std::endl;
}
if (varargs && !javascript) {
std::stringstream stream;
......@@ -82,6 +81,7 @@ void DeclarationVisitor::Visit(BuiltinDeclaration* decl) {
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
if (javascript) {
if (signature.types().size() < 2 ||
!(signature.types()[1]->name() == OBJECT_TYPE_STRING)) {
......@@ -93,34 +93,142 @@ void DeclarationVisitor::Visit(BuiltinDeclaration* decl) {
}
}
if (varargs) {
std::string generated_name = GetGeneratedCallableName(
decl->name, declarations()->GetCurrentSpecializationTypeNamesVector());
return declarations()->DeclareBuiltin(decl->pos, generated_name, kind,
signature);
}
void DeclarationVisitor::Visit(ExternalRuntimeDeclaration* decl,
const Signature& signature, Statement* body) {
if (global_context_.verbose()) {
std::cout << "found declaration of external runtime " << decl->name
<< " with signature ";
}
if (signature.parameter_types.types.size() == 0 ||
!(signature.parameter_types.types[0]->name() == CONTEXT_TYPE_STRING)) {
std::stringstream stream;
stream << "first parameter to runtime " << decl->name
<< " is not a context but should be at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
declarations()->DeclareRuntimeFunction(decl->pos, decl->name, signature);
}
void DeclarationVisitor::Visit(ExternalMacroDeclaration* decl,
const Signature& signature, Statement* body) {
if (global_context_.verbose()) {
std::cout << "found declaration of external macro " << decl->name
<< " with signature ";
}
std::string generated_name = GetGeneratedCallableName(
decl->name, declarations()->GetCurrentSpecializationTypeNamesVector());
declarations()->DeclareMacro(decl->pos, generated_name, signature);
if (decl->op) {
OperationHandler handler(
{decl->name, signature.parameter_types, signature.return_type});
auto i = global_context_.op_handlers_.find(*decl->op);
if (i == global_context_.op_handlers_.end()) {
global_context_.op_handlers_[*decl->op] = std::vector<OperationHandler>();
i = global_context_.op_handlers_.find(*decl->op);
}
i->second.push_back(handler);
}
if (decl->implicit) {
if (!decl->op || *decl->op != "convert<>") {
std::stringstream s;
s << "implicit can only be used with cast<> operator at "
<< PositionAsString(decl->pos) << "\n";
ReportError(s.str());
}
const TypeVector& parameter_types = signature.parameter_types.types;
if (parameter_types.size() != 1 || signature.parameter_types.var_args) {
std::stringstream s;
s << "implicit cast operators doesn't only have a single parameter at "
<< PositionAsString(decl->pos) << "\n";
ReportError(s.str());
}
GetTypeOracle().RegisterImplicitConversion(signature.return_type,
parameter_types[0]);
}
}
void DeclarationVisitor::Visit(TorqueBuiltinDeclaration* decl,
const Signature& signature, Statement* body) {
Builtin* builtin = BuiltinDeclarationCommon(decl, signature);
CurrentCallableActivator activator(global_context_, builtin, decl);
DeclareSignature(decl->pos, builtin->signature());
if (builtin->signature().parameter_types.var_args) {
declarations()->DeclareConstant(
decl->pos, decl->parameters.arguments_variable,
decl->pos, decl->signature->parameters.arguments_variable,
GetTypeOracle().GetArgumentsType(), "arguments");
}
defined_builtins_.push_back(builtin);
Visit(decl->body);
torque_builtins_.push_back(builtin);
Visit(body);
}
void DeclarationVisitor::Visit(MacroDeclaration* decl) {
Signature signature = MakeSignature(decl->pos, decl->parameters,
decl->return_type, decl->labels);
void DeclarationVisitor::Visit(TorqueMacroDeclaration* decl,
const Signature& signature, Statement* body) {
std::string generated_name = GetGeneratedCallableName(
decl->name, declarations()->GetCurrentSpecializationTypeNamesVector());
Macro* macro =
declarations()->DeclareMacro(decl->pos, generated_name, signature);
Macro* macro = declarations()->DeclareMacro(decl->pos, decl->name, signature);
CurrentCallableActivator activator(global_context_, macro, decl);
DeclareParameterList(decl->pos, signature, decl->labels);
DeclareSignature(decl->pos, signature);
if (!signature.return_type->IsVoidOrNever()) {
declarations()->DeclareVariable(decl->pos, kReturnValueVariable,
signature.return_type);
}
PushControlSplit();
Visit(decl->body);
Visit(body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(decl, changed_vars);
global_context_.AddControlSplitChangedVariables(
decl, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void DeclarationVisitor::Visit(StandardDeclaration* decl) {
Signature signature =
MakeSignature(decl->callable, decl->callable->signature.get());
Visit(decl->callable, signature, decl->body);
}
void DeclarationVisitor::Visit(GenericDeclaration* decl) {
declarations()->DeclareGeneric(decl->pos, decl->callable->name,
CurrentModule(), decl);
}
void DeclarationVisitor::Visit(SpecializationDeclaration* decl) {
Generic* generic = declarations()->LookupGeneric(decl->pos, decl->name);
SpecializationKey key = {generic,
GetTypeVector(decl->pos, decl->generic_parameters)};
CallableNode* callable = generic->declaration()->callable;
// Ensure that the specialized signature matches the generic signature.
if (callable->signature->parameters.names.size() !=
decl->signature->parameters.names.size()) {
std::stringstream stream;
stream << "specialization parameter count doesn't match generic "
"declaration at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
if (callable->signature->labels.size() != decl->signature->labels.size()) {
std::stringstream stream;
stream << "specialization label count doesn't match generic "
"declaration at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
QueueGenericSpecialization(key, callable, decl->signature.get(), decl->body);
}
void DeclarationVisitor::Visit(ReturnStatement* stmt) {
......@@ -144,7 +252,9 @@ void DeclarationVisitor::Visit(ForOfLoopStatement* stmt) {
PushControlSplit();
Visit(stmt->body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void DeclarationVisitor::Visit(TryCatchStatement* stmt) {
......@@ -195,6 +305,57 @@ void DeclarationVisitor::Visit(TryCatchStatement* stmt) {
}
}
void DeclarationVisitor::Visit(CallExpression* expr) {
if (expr->generic_arguments.size() != 0) {
Generic* generic = declarations()->LookupGeneric(expr->pos, expr->callee);
TypeVector specialization_types;
for (auto t : expr->generic_arguments) {
specialization_types.push_back(declarations()->LookupType(expr->pos, t));
}
CallableNode* callable = generic->declaration()->callable;
QueueGenericSpecialization({generic, specialization_types}, callable,
callable->signature.get(),
generic->declaration()->body);
}
for (Expression* arg : expr->arguments) Visit(arg);
}
void DeclarationVisitor::Specialize(const SpecializationKey& key,
CallableNode* callable,
const CallableNodeSignature* signature,
Statement* body) {
Generic* generic = key.first;
SourcePosition pos = generic->declaration()->pos;
size_t generic_parameter_count =
generic->declaration()->generic_parameters.size();
if (generic_parameter_count != key.second.size()) {
std::stringstream stream;
stream << "number of template parameters ("
<< std::to_string(key.second.size())
<< ") to intantiation of generic " << callable->name
<< " doesnt match the generic's declaration ("
<< std::to_string(generic_parameter_count) << ") at "
<< PositionAsString(pos);
ReportError(stream.str());
}
{
// Manually activate the specialized generic's scope when defining the
// generic parameter specializations.
Declarations::GenericScopeActivator scope(declarations(), key);
size_t i = 0;
for (auto type : key.second) {
std::string generic_type_name =
generic->declaration()->generic_parameters[i++];
declarations()->DeclareTypeAlias(pos, generic_type_name, type);
}
}
Visit(callable, MakeSignature(callable, signature), body);
}
} // namespace torque
} // namespace internal
} // namespace v8
......@@ -27,18 +27,19 @@ class DeclarationVisitor : public FileVisitor {
scope_(declarations(), global_context.ast()->default_module()) {
}
void Visit(Ast* ast) { Visit(ast->default_module()); }
void Visit(Ast* ast) {
Visit(ast->default_module());
DrainSpecializationQueue();
}
void Visit(Expression* expr);
void Visit(Statement* stmt);
void Visit(Declaration* decl);
void Visit(ModuleDeclaration* decl) {
Module* saved_module = module_;
module_ = decl->GetModule();
ScopedModuleActivator activator(this, decl->GetModule());
Declarations::NodeScopeActivator scope(declarations(), decl);
for (Declaration* child : decl->declarations) Visit(child);
module_ = saved_module;
}
void Visit(DefaultModuleDeclaration* decl) {
decl->SetModule(global_context_.GetDefaultModule());
......@@ -52,9 +53,7 @@ class DeclarationVisitor : public FileVisitor {
void Visit(IdentifierExpression* expr) {}
void Visit(NumberLiteralExpression* expr) {}
void Visit(StringLiteralExpression* expr) {}
void Visit(CallExpression* expr) {
for (Expression* arg : expr->arguments) Visit(arg);
}
void Visit(CallExpression* expr);
void Visit(ElementAccessExpression* expr) {
Visit(expr->array);
Visit(expr->index);
......@@ -85,124 +84,35 @@ class DeclarationVisitor : public FileVisitor {
}
}
void Visit(ExternalBuiltinDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of external builtin " << decl->name
<< " with signature ";
}
Signature signature =
MakeSignature(decl->pos, decl->parameters, decl->return_type, {});
if (signature.parameter_types.types.size() == 0 ||
!(signature.parameter_types.types[0]->name() == CONTEXT_TYPE_STRING)) {
std::stringstream stream;
stream << "first parameter to builtin " << decl->name
<< " is not a context but should be at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
const bool javascript = decl->javascript_linkage;
const bool varargs = decl->parameters.has_varargs;
if (varargs && !javascript) {
std::stringstream stream;
stream << "builtin " << decl->name
<< " with rest parameters must be a JavaScript builtin at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
if (javascript) {
if (signature.types().size() < 2 ||
!(signature.types()[1]->name() == OBJECT_TYPE_STRING)) {
std::stringstream stream;
stream << "second parameter to javascript builtin " << decl->name
<< " is not a receiver type but should be at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
}
Builtin::Kind kind = !javascript ? Builtin::kStub
: varargs ? Builtin::kVarArgsJavaScript
: Builtin::kFixedArgsJavaScript;
declarations()->DeclareBuiltin(decl->pos, decl->name, kind, signature);
}
void Visit(ExternalRuntimeDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of external runtime " << decl->name
<< " with signature ";
}
const Type* return_type =
declarations()->LookupType(decl->pos, decl->return_type);
TypeVector parameter_types =
GetTypeVector(decl->pos, decl->parameters.types);
if (parameter_types.size() == 0 ||
!(parameter_types[0]->name() == CONTEXT_TYPE_STRING)) {
std::stringstream stream;
stream << "first parameter to runtime " << decl->name
<< " is not a context but should be at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
Builtin* BuiltinDeclarationCommon(BuiltinDeclaration* decl,
const Signature& signature);
Signature signature{{},
{parameter_types, decl->parameters.has_varargs},
return_type,
{}};
declarations()->DeclareRuntimeFunction(decl->pos, decl->name,
std::move(signature));
void Visit(ExternalBuiltinDeclaration* decl, const Signature& signature,
Statement* body) {
BuiltinDeclarationCommon(decl, signature);
}
void Visit(ExternalMacroDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of external macro " << decl->name
<< " with signature ";
}
void Visit(ExternalRuntimeDeclaration* decl, const Signature& sig,
Statement* body);
void Visit(ExternalMacroDeclaration* decl, const Signature& sig,
Statement* body);
void Visit(TorqueBuiltinDeclaration* decl, const Signature& signature,
Statement* body);
void Visit(TorqueMacroDeclaration* decl, const Signature& signature,
Statement* body);
Signature signature = MakeSignature(decl->pos, decl->parameters,
decl->return_type, decl->labels);
declarations()->DeclareMacro(decl->pos, decl->name, signature);
if (decl->op) {
OperationHandler handler(
{decl->name, signature.parameter_types, signature.return_type});
auto i = global_context_.op_handlers_.find(*decl->op);
if (i == global_context_.op_handlers_.end()) {
global_context_.op_handlers_[*decl->op] =
std::vector<OperationHandler>();
i = global_context_.op_handlers_.find(*decl->op);
}
i->second.push_back(handler);
}
void Visit(CallableNode* decl, const Signature& signature, Statement* body);
if (decl->implicit) {
if (!decl->op || *decl->op != "convert<>") {
std::stringstream s;
s << "implicit can only be used with cast<> operator at "
<< PositionAsString(decl->pos) << "\n";
ReportError(s.str());
}
const TypeVector& parameter_types = signature.parameter_types.types;
if (parameter_types.size() != 1 || signature.parameter_types.var_args) {
std::stringstream s;
s << "implicit cast operators doesn't only have a single parameter at "
<< PositionAsString(decl->pos) << "\n";
ReportError(s.str());
}
GetTypeOracle().RegisterImplicitConversion(signature.return_type,
parameter_types[0]);
}
}
void Visit(BuiltinDeclaration* decl);
void Visit(MacroDeclaration* decl);
void Visit(StandardDeclaration* decl);
void Visit(GenericDeclaration* decl);
void Visit(SpecializationDeclaration* decl);
void Visit(ReturnStatement* stmt);
void Visit(DebugStatement* stmt) {}
void Visit(AssertStatement* stmt) {
#if defined(DEBUG)
DeclareExpressionForBranch(stmt->expression);
#endif
}
void Visit(VarDeclarationStatement* stmt) {
......@@ -271,7 +181,9 @@ class DeclarationVisitor : public FileVisitor {
Visit(expr->if_true);
Visit(expr->if_false);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(expr, changed_vars);
global_context_.AddControlSplitChangedVariables(
expr, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void Visit(IfStatement* stmt) {
......@@ -283,7 +195,9 @@ class DeclarationVisitor : public FileVisitor {
if (stmt->if_false) Visit(*stmt->if_false);
if (!stmt->is_constexpr) {
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
}
......@@ -293,7 +207,9 @@ class DeclarationVisitor : public FileVisitor {
PushControlSplit();
Visit(stmt->body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void Visit(ForOfLoopStatement* stmt);
......@@ -316,7 +232,9 @@ class DeclarationVisitor : public FileVisitor {
Visit(stmt->body);
Visit(stmt->action);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void Visit(IncrementDecrementExpression* expr) {
......@@ -334,7 +252,7 @@ class DeclarationVisitor : public FileVisitor {
"\n"
"#define BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) "
"\\\n";
for (auto builtin : defined_builtins_) {
for (auto builtin : torque_builtins_) {
int firstParameterIndex = 1;
bool declareParameters = true;
if (builtin->IsStub()) {
......@@ -421,30 +339,31 @@ class DeclarationVisitor : public FileVisitor {
return was_live_in_preceeding_split;
}
void DeclareParameterList(SourcePosition pos, const Signature& signature,
base::Optional<LabelAndTypesVector> labels) {
void DeclareSignature(SourcePosition pos, const Signature& signature) {
auto name_iterator = signature.parameter_names.begin();
for (auto t : signature.types()) {
const std::string& name(*name_iterator++);
declarations()->DeclareParameter(pos, name,
GetParameterVariableFromName(name), t);
}
if (labels) {
for (auto label : *labels) {
auto label_params = GetTypeVector(pos, label.types);
Label* new_label = declarations()->DeclareLabel(pos, label.name);
size_t i = 0;
for (auto var_type : label_params) {
std::string var_name = label.name + std::to_string(i++);
new_label->AddVariable(
declarations()->DeclareVariable(pos, var_name, var_type));
}
for (auto& label : signature.labels) {
auto label_params = label.types;
Label* new_label = declarations()->DeclareLabel(pos, label.name);
size_t i = 0;
for (auto var_type : label_params) {
std::string var_name = label.name + std::to_string(i++);
new_label->AddVariable(
declarations()->DeclareVariable(pos, var_name, var_type));
}
}
}
void Specialize(const SpecializationKey& key, CallableNode* callable,
const CallableNodeSignature* signature,
Statement* body) override;
Declarations::NodeScopeActivator scope_;
std::vector<Builtin*> defined_builtins_;
std::vector<Builtin*> torque_builtins_;
std::vector<LiveAndChanged> live_and_changed_variables_;
};
......
......@@ -10,10 +10,25 @@ namespace internal {
namespace torque {
Scope* Declarations::GetNodeScope(const AstNode* node) {
auto i = node_scopes_.find(node);
if (i != node_scopes_.end()) return i->second;
std::pair<const AstNode*, TypeVector> key(
node, current_generic_specialization_ == nullptr
? TypeVector()
: current_generic_specialization_->second);
auto i = scopes_.find(key);
if (i != scopes_.end()) return i->second;
Scope* result = chain_.NewScope();
node_scopes_[node] = result;
scopes_[key] = result;
return result;
}
Scope* Declarations::GetGenericScope(Generic* generic,
const TypeVector& types) {
std::pair<const AstNode*, TypeVector> key(generic->declaration()->callable,
types);
auto i = scopes_.find(key);
if (i != scopes_.end()) return i->second;
Scope* result = chain_.NewScope();
scopes_[key] = result;
return result;
}
......@@ -32,13 +47,16 @@ void Declarations::CheckAlreadyDeclared(SourcePosition pos,
const Type* Declarations::LookupType(SourcePosition pos,
const std::string& name) {
Declarable* raw = Lookup(pos, name);
if (!raw->IsType()) {
std::stringstream s;
s << "declaration \"" << name << "\" is not a Type at "
<< PositionAsString(pos);
ReportError(s.str());
if (raw->IsType()) {
return Type::cast(raw);
} else if (raw->IsTypeAlias()) {
return TypeAlias::cast(raw)->type();
}
return Type::cast(raw);
std::stringstream s;
s << "declaration \"" << name << "\" is not a Type at "
<< PositionAsString(pos);
ReportError(s.str());
return nullptr;
}
Value* Declarations::LookupValue(SourcePosition pos, const std::string& name) {
......@@ -98,6 +116,21 @@ Builtin* Declarations::LookupBuiltin(SourcePosition pos,
return nullptr;
}
Generic* Declarations::LookupGeneric(const SourcePosition& pos,
const std::string& name) {
Declarable* declarable = Lookup(name);
if (declarable != nullptr) {
if (declarable->IsGeneric()) {
return Generic::cast(declarable);
}
ReportError(name + " referenced at " + PositionAsString(pos) +
" is not a generic");
}
ReportError(std::string("generic ") + name + " referenced at " +
PositionAsString(pos) + " is not defined");
return nullptr;
}
const Type* Declarations::DeclareType(SourcePosition pos,
const std::string& name,
const std::string& generated,
......@@ -126,6 +159,13 @@ const Type* Declarations::DeclareType(SourcePosition pos,
return result;
}
void Declarations::DeclareTypeAlias(SourcePosition pos, const std::string& name,
const Type* aliased_type) {
CheckAlreadyDeclared(pos, name, "aliased type");
TypeAlias* result = new TypeAlias(name, aliased_type);
Declare(name, std::unique_ptr<TypeAlias>(result));
}
Label* Declarations::DeclareLabel(SourcePosition pos, const std::string& name) {
CheckAlreadyDeclared(pos, name, "label");
Label* result = new Label(name);
......@@ -218,6 +258,24 @@ void Declarations::DeclareConstant(SourcePosition pos, const std::string& name,
Declare(name, std::unique_ptr<Declarable>(result));
}
Generic* Declarations::DeclareGeneric(SourcePosition pos,
const std::string& name, Module* module,
GenericDeclaration* generic) {
CheckAlreadyDeclared(pos, name, "generic");
Generic* result = new Generic(name, module, generic);
Declare(name, std::unique_ptr<Generic>(result));
generic_declaration_scopes_[result] = GetScopeChainSnapshot();
return result;
}
TypeVector Declarations::GetCurrentSpecializationTypeNamesVector() {
TypeVector result;
if (current_generic_specialization_ != nullptr) {
result = current_generic_specialization_->second;
}
return result;
}
} // namespace torque
} // namespace internal
} // namespace v8
......@@ -17,7 +17,9 @@ namespace torque {
class Declarations {
public:
explicit Declarations(SourceFileMap* source_file_map)
: source_file_map_(source_file_map), unique_declaration_number_(0) {}
: source_file_map_(source_file_map),
unique_declaration_number_(0),
current_generic_specialization_(nullptr) {}
Declarable* Lookup(const std::string& name) { return chain_.Lookup(name); }
......@@ -42,17 +44,22 @@ class Declarations {
Label* LookupLabel(SourcePosition pos, const std::string& name);
Generic* LookupGeneric(const SourcePosition& pos, const std::string& name);
const Type* DeclareType(SourcePosition pos, const std::string& name,
const std::string& generated,
const std::string* parent = nullptr);
void DeclareTypeAlias(SourcePosition pos, const std::string& name,
const Type* aliased_type);
Label* DeclareLabel(SourcePosition pos, const std::string& name);
Macro* DeclareMacro(SourcePosition pos, const std::string& name,
const Signature& signature);
Builtin* DeclareBuiltin(SourcePosition pos, const std::string& name,
Builtin::Kind kind, const Signature& signature);
const Builtin::Kind kind, const Signature& signature);
RuntimeFunction* DeclareRuntimeFunction(SourcePosition pos,
const std::string& name,
......@@ -70,6 +77,13 @@ class Declarations {
void DeclareConstant(SourcePosition pos, const std::string& name,
const Type* type, const std::string& value);
Generic* DeclareGeneric(SourcePosition pos, const std::string& name,
Module* module, GenericDeclaration* generic);
TypeVector GetCurrentSpecializationTypeNamesVector();
ScopeChain::Snapshot GetScopeChainSnapshot() { return chain_.TaskSnapshot(); }
std::set<const Variable*> GetLiveVariables() {
return chain_.GetLiveVariables();
}
......@@ -78,12 +92,17 @@ class Declarations {
return source_file_map_->PositionAsString(pos);
}
Statement* next_body() const { return next_body_; }
void PrintScopeChain() { chain_.Print(); }
class NodeScopeActivator;
class GenericScopeActivator;
class ScopedGenericInstantiation;
private:
Scope* GetNodeScope(const AstNode* node);
Scope* GetGenericScope(Generic* generic, const TypeVector& types);
void Declare(const std::string& name, std::unique_ptr<Declarable> d) {
Declarable* ptr = d.get();
......@@ -99,8 +118,11 @@ class Declarations {
SourceFileMap* source_file_map_;
int unique_declaration_number_;
ScopeChain chain_;
const SpecializationKey* current_generic_specialization_;
Statement* next_body_;
std::vector<std::unique_ptr<Declarable>> declarables_;
std::map<const AstNode*, Scope*> node_scopes_;
std::map<std::pair<const AstNode*, TypeVector>, Scope*> scopes_;
std::map<Generic*, ScopeChain::Snapshot> generic_declaration_scopes_;
};
class Declarations::NodeScopeActivator {
......@@ -112,6 +134,33 @@ class Declarations::NodeScopeActivator {
Scope::Activator activator_;
};
class Declarations::GenericScopeActivator {
public:
GenericScopeActivator(Declarations* declarations,
const SpecializationKey& key)
: activator_(declarations->GetGenericScope(key.first, key.second)) {}
private:
Scope::Activator activator_;
};
class Declarations::ScopedGenericInstantiation {
public:
ScopedGenericInstantiation(Declarations* declarations,
const SpecializationKey& key)
: declarations_(declarations),
restorer_(declarations->generic_declaration_scopes_[key.first]) {
declarations->current_generic_specialization_ = &key;
}
~ScopedGenericInstantiation() {
declarations_->current_generic_specialization_ = nullptr;
}
private:
Declarations* declarations_;
ScopeChain::ScopedSnapshotRestorer restorer_;
};
} // namespace torque
} // namespace internal
} // namespace v8
......
......@@ -10,23 +10,33 @@ namespace v8 {
namespace internal {
namespace torque {
Signature FileVisitor::MakeSignature(SourcePosition pos,
const ParameterList& parameters,
const std::string& return_type,
const LabelAndTypesVector& labels) {
Signature FileVisitor::MakeSignature(CallableNode* decl,
const CallableNodeSignature* signature) {
Declarations::NodeScopeActivator scope(declarations(), decl);
LabelDeclarationVector definition_vector;
for (auto label : labels) {
LabelDeclaration def = {label.name, GetTypeVector(pos, label.types)};
for (auto label : signature->labels) {
LabelDeclaration def = {label.name, GetTypeVector(decl->pos, label.types)};
definition_vector.push_back(def);
}
Signature result{
parameters.names,
{GetTypeVector(pos, parameters.types), parameters.has_varargs},
declarations()->LookupType(pos, return_type),
signature->parameters.names,
{GetTypeVector(decl->pos, signature->parameters.types),
signature->parameters.has_varargs},
declarations()->LookupType(decl->pos, signature->return_type),
definition_vector};
return result;
}
std::string FileVisitor::GetGeneratedCallableName(
const std::string& name, const TypeVector& specialized_types) {
std::string result = name;
for (auto type : specialized_types) {
result += std::to_string(type->name().size());
result += type->name();
}
return result;
}
Callable* FileVisitor::LookupCall(SourcePosition pos, const std::string& name,
const TypeVector& parameter_types) {
Callable* result = nullptr;
......@@ -57,6 +67,12 @@ Callable* FileVisitor::LookupCall(SourcePosition pos, const std::string& name,
<< PositionAsString(pos);
ReportError(stream.str());
}
} else {
std::stringstream stream;
stream << "can't call " << name << " because it's not callable"
<< ": call parameters were (" << parameter_types << ") at "
<< PositionAsString(pos);
ReportError(stream.str());
}
size_t caller_size = parameter_types.size();
......@@ -64,7 +80,7 @@ Callable* FileVisitor::LookupCall(SourcePosition pos, const std::string& name,
if (caller_size != callee_size &&
!result->signature().parameter_types.var_args) {
std::stringstream stream;
stream << "parameter count mismatch calling " << *result << ": expected "
stream << "parameter count mismatch calling " << *result << " - expected "
<< std::to_string(callee_size) << ", found "
<< std::to_string(caller_size);
ReportError(stream.str());
......@@ -73,6 +89,30 @@ Callable* FileVisitor::LookupCall(SourcePosition pos, const std::string& name,
return result;
}
void FileVisitor::QueueGenericSpecialization(
SpecializationKey key, CallableNode* callable,
const CallableNodeSignature* signature, Statement* body) {
pending_specializations_.push_back({key, callable, signature, body,
declarations()->GetScopeChainSnapshot()});
}
void FileVisitor::DrainSpecializationQueue() {
while (pending_specializations_.size() != 0) {
PendingSpecialization specialization(pending_specializations_.front());
pending_specializations_.pop_front();
if (completed_specializations_.find(specialization.key) ==
completed_specializations_.end()) {
Declarations::ScopedGenericInstantiation instantiation(
declarations(), specialization.key);
FileVisitor::ScopedModuleActivator activator(
this, specialization.key.first->module());
Specialize(specialization.key, specialization.callable,
specialization.signature, specialization.body);
completed_specializations_.insert(specialization.key);
}
}
}
} // namespace torque
} // namespace internal
} // namespace v8
......@@ -5,6 +5,7 @@
#ifndef V8_TORQUE_FILE_VISITOR_H_
#define V8_TORQUE_FILE_VISITOR_H_
#include <deque>
#include <string>
#include "src/torque/ast.h"
......@@ -37,6 +38,21 @@ class FileVisitor {
Ast* ast() { return global_context_.ast(); }
Declarations* declarations() { return global_context_.declarations(); }
void DrainSpecializationQueue();
class ScopedModuleActivator {
public:
ScopedModuleActivator(FileVisitor* visitor, Module* module)
: visitor_(visitor), saved_module_(visitor->CurrentModule()) {
visitor->module_ = module;
}
~ScopedModuleActivator() { visitor_->module_ = saved_module_; }
private:
FileVisitor* visitor_;
Module* saved_module_;
};
protected:
static constexpr const char* kTrueLabelName = "_True";
static constexpr const char* kFalseLabelName = "_False";
......@@ -47,6 +63,7 @@ class FileVisitor {
Module* CurrentModule() const { return module_; }
friend class ScopedModuleActivator;
TypeOracle& GetTypeOracle() { return global_context_.GetTypeOracle(); }
std::string GetParameterVariableFromName(const std::string& name) {
......@@ -60,12 +77,32 @@ class FileVisitor {
Callable* LookupCall(SourcePosition pos, const std::string& name,
const TypeVector& parameter_types);
Signature MakeSignature(SourcePosition pos, const ParameterList& parameters,
const std::string& return_type,
const LabelAndTypesVector& labels);
Signature MakeSignature(CallableNode* decl,
const CallableNodeSignature* signature);
std::string GetGeneratedCallableName(const std::string& name,
const TypeVector& specialized_types);
struct PendingSpecialization {
SpecializationKey key;
CallableNode* callable;
const CallableNodeSignature* signature;
Statement* body;
ScopeChain::Snapshot snapshot;
};
void QueueGenericSpecialization(SpecializationKey, CallableNode* callable,
const CallableNodeSignature* signature,
Statement* body);
virtual void Specialize(const SpecializationKey&, CallableNode* callable,
const CallableNodeSignature* signature,
Statement* body) = 0;
GlobalContext& global_context_;
Declarations* declarations_;
std::deque<PendingSpecialization> pending_specializations_;
std::set<SpecializationKey> completed_specializations_;
Callable* current_callable_;
Module* module_;
};
......
......@@ -81,19 +81,25 @@ class GlobalContext {
bool verbose() const { return verbose_; }
void AddControlSplitChangedVariables(const AstNode* node,
const TypeVector& specialization_types,
const std::set<const Variable*>& vars) {
control_split_changed_variables_[node] = vars;
auto key = std::make_pair(node, specialization_types);
control_split_changed_variables_[key] = vars;
}
const std::set<const Variable*>& GetControlSplitChangedVariables(
const AstNode* node) {
assert(control_split_changed_variables_.find(node) !=
const AstNode* node, const TypeVector& specialization_types) {
auto key = std::make_pair(node, specialization_types);
assert(control_split_changed_variables_.find(key) !=
control_split_changed_variables_.end());
return control_split_changed_variables_.find(node)->second;
return control_split_changed_variables_.find(key)->second;
}
void MarkVariableChanged(const AstNode* node, Variable* var) {
control_split_changed_variables_[node].insert(var);
void MarkVariableChanged(const AstNode* node,
const TypeVector& specialization_types,
Variable* var) {
auto key = std::make_pair(node, specialization_types);
control_split_changed_variables_[key].insert(var);
}
friend class CurrentCallableActivator;
......@@ -120,12 +126,12 @@ class GlobalContext {
bool verbose_;
int next_label_number_;
Declarations declarations_;
Callable* current_callable_;
std::vector<std::pair<Label*, Label*>> break_continue_stack_;
TypeOracle type_oracle_;
std::map<std::string, std::unique_ptr<Module>> modules_;
Module* default_module_;
std::vector<std::pair<Label*, Label*>> break_continue_stack_;
Callable* current_callable_;
std::map<const AstNode*, std::set<const Variable*>>
std::map<std::pair<const AstNode*, TypeVector>, std::set<const Variable*>>
control_split_changed_variables_;
Ast ast_;
};
......@@ -133,14 +139,18 @@ class GlobalContext {
class CurrentCallableActivator {
public:
CurrentCallableActivator(GlobalContext& context, Callable* callable,
Declaration* decl)
CallableNode* decl)
: context_(context), scope_activator_(context.declarations(), decl) {
remembered_callable_ = context_.current_callable_;
context_.current_callable_ = callable;
}
~CurrentCallableActivator() { context_.current_callable_ = nullptr; }
~CurrentCallableActivator() {
context_.current_callable_ = remembered_callable_;
}
private:
GlobalContext& context_;
Callable* remembered_callable_;
Declarations::NodeScopeActivator scope_activator_;
};
......
......@@ -49,6 +49,19 @@ void ImplementationVisitor::Visit(Declaration* decl) {
}
}
void ImplementationVisitor::Visit(CallableNode* decl,
const Signature& signature, Statement* body) {
switch (decl->kind) {
#define ENUM_ITEM(name) \
case AstNode::Kind::k##name: \
return Visit(name::cast(decl), signature, body);
AST_CALLABLE_NODE_KIND_LIST(ENUM_ITEM)
#undef ENUM_ITEM
default:
UNIMPLEMENTED();
}
}
void ImplementationVisitor::Visit(ModuleDeclaration* decl) {
Module* module = decl->GetModule();
......@@ -120,6 +133,8 @@ void ImplementationVisitor::Visit(ModuleDeclaration* decl) {
for (auto& child : decl->declarations) Visit(child);
module_ = saved_module;
DrainSpecializationQueue();
source << "} // namepsace internal" << std::endl
<< "} // namespace v8" << std::endl
<< "" << std::endl;
......@@ -131,11 +146,13 @@ void ImplementationVisitor::Visit(ModuleDeclaration* decl) {
header << "#endif // " << headerDefine << std::endl;
}
void ImplementationVisitor::Visit(MacroDeclaration* decl) {
Signature signature = MakeSignature(decl->pos, decl->parameters,
decl->return_type, decl->labels);
void ImplementationVisitor::Visit(TorqueMacroDeclaration* decl,
const Signature& sig, Statement* body) {
Signature signature = MakeSignature(decl, decl->signature.get());
std::string name = GetGeneratedCallableName(
decl->name, declarations()->GetCurrentSpecializationTypeNamesVector());
const TypeVector& list = signature.types();
Macro* macro = declarations()->LookupMacro(decl->pos, decl->name, list);
Macro* macro = declarations()->LookupMacro(decl->pos, name, list);
CurrentCallableActivator activator(global_context_, macro, decl);
......@@ -167,7 +184,7 @@ void ImplementationVisitor::Visit(MacroDeclaration* decl) {
Label* macro_end = declarations()->DeclareLabel(decl->pos, "macro_end");
GenerateLabelDefinition(macro_end, decl);
const Type* result = Visit(decl->body);
const Type* result = Visit(body);
if (result->IsNever()) {
if (!macro->signature().return_type->IsNever() && !macro->HasReturns()) {
std::stringstream s;
......@@ -206,15 +223,18 @@ void ImplementationVisitor::Visit(MacroDeclaration* decl) {
source_out() << "}" << std::endl << std::endl;
}
void ImplementationVisitor::Visit(BuiltinDeclaration* decl) {
source_out() << "TF_BUILTIN(" << decl->name << ", "
void ImplementationVisitor::Visit(TorqueBuiltinDeclaration* decl,
const Signature& signature, Statement* body) {
std::string name = GetGeneratedCallableName(
decl->name, declarations()->GetCurrentSpecializationTypeNamesVector());
source_out() << "TF_BUILTIN(" << name << ", "
<< GetDSLAssemblerName(CurrentModule()) << ") {" << std::endl;
Builtin* builtin = declarations()->LookupBuiltin(decl->pos, decl->name);
Builtin* builtin = declarations()->LookupBuiltin(decl->pos, name);
CurrentCallableActivator activator(global_context_, builtin, decl);
// Context
const Value* val =
declarations()->LookupValue(decl->pos, decl->parameters.names[0]);
const Value* val = declarations()->LookupValue(
decl->pos, decl->signature->parameters.names[0]);
GenerateIndent();
source_out() << "TNode<Context> " << val->GetValueForDeclaration()
<< " = UncheckedCast<Context>(Parameter("
......@@ -225,9 +245,9 @@ void ImplementationVisitor::Visit(BuiltinDeclaration* decl) {
size_t first = 1;
if (builtin->IsVarArgsJavaScript()) {
assert(decl->parameters.has_varargs);
assert(decl->signature->parameters.has_varargs);
Constant* arguments = Constant::cast(declarations()->LookupValue(
decl->pos, decl->parameters.arguments_variable));
decl->pos, decl->signature->parameters.arguments_variable));
std::string arguments_name = arguments->GetValueForDeclaration();
GenerateIndent();
source_out()
......@@ -237,8 +257,8 @@ void ImplementationVisitor::Visit(BuiltinDeclaration* decl) {
source_out() << "CodeStubArguments arguments_impl(this, "
"ChangeInt32ToIntPtr(argc));"
<< std::endl;
const Value* receiver =
declarations()->LookupValue(decl->pos, decl->parameters.names[1]);
const Value* receiver = declarations()->LookupValue(
decl->pos, decl->signature->parameters.names[1]);
GenerateIndent();
source_out() << "TNode<Object> " << receiver->GetValueForDeclaration()
<< " = arguments_impl.GetReceiver();" << std::endl;
......@@ -252,8 +272,8 @@ void ImplementationVisitor::Visit(BuiltinDeclaration* decl) {
first = 2;
}
GenerateParameterList(decl->pos, decl->parameters.names, first);
Visit(decl->body);
GenerateParameterList(decl->pos, decl->signature->parameters.names, first);
Visit(body);
source_out() << "}" << std::endl << std::endl;
}
......@@ -1082,7 +1102,8 @@ VisitResult ImplementationVisitor::GenerateOperation(
void ImplementationVisitor::GenerateChangedVarsFromControlSplit(AstNode* node) {
const std::set<const Variable*>& changed_vars =
global_context_.GetControlSplitChangedVariables(node);
global_context_.GetControlSplitChangedVariables(
node, declarations()->GetCurrentSpecializationTypeNamesVector());
source_out() << "{";
bool first = true;
for (auto v : changed_vars) {
......@@ -1206,7 +1227,9 @@ Variable* ImplementationVisitor::GenerateVariableDeclaration(
// assumed that it changes along all control split paths because it's no
// longer possible to run the control-flow anlaysis in the declaration pass
// over the variable.
global_context_.MarkVariableChanged(node, variable);
global_context_.MarkVariableChanged(
node, declarations()->GetCurrentSpecializationTypeNamesVector(),
variable);
}
GenerateIndent();
......@@ -1376,9 +1399,33 @@ VisitResult ImplementationVisitor::GenerateCall(
return VisitResult(result_type, result_variable_name);
}
void ImplementationVisitor::Visit(StandardDeclaration* decl) {
Visit(decl->callable, {}, decl->body);
}
void ImplementationVisitor::Visit(SpecializationDeclaration* decl) {
Generic* generic = declarations()->LookupGeneric(decl->pos, decl->name);
TypeVector specialization_types =
GetTypeVector(decl->pos, decl->generic_parameters);
CallableNode* callable = generic->declaration()->callable;
QueueGenericSpecialization({generic, specialization_types}, callable,
decl->signature.get(), decl->body);
}
VisitResult ImplementationVisitor::Visit(CallExpression* expr,
bool is_tailcall) {
Arguments arguments;
std::string name = expr->callee;
if (expr->generic_arguments.size() != 0) {
Generic* generic = declarations()->LookupGeneric(expr->pos, expr->callee);
TypeVector specialization_types =
GetTypeVector(expr->pos, expr->generic_arguments);
name = GetGeneratedCallableName(name, specialization_types);
CallableNode* callable = generic->declaration()->callable;
QueueGenericSpecialization({generic, specialization_types}, callable,
callable->signature.get(),
generic->declaration()->body);
}
for (Expression* arg : expr->arguments)
arguments.parameters.push_back(Visit(arg));
arguments.labels = LabelsFromIdentifiers(expr->pos, expr->labels);
......@@ -1388,10 +1435,9 @@ VisitResult ImplementationVisitor::Visit(CallExpression* expr,
s << "can't tail call an operator" << PositionAsString(expr->pos);
ReportError(s.str());
}
return GenerateOperation(expr->pos, expr->callee, arguments);
return GenerateOperation(expr->pos, name, arguments);
}
VisitResult result =
GenerateCall(expr->pos, expr->callee, arguments, is_tailcall);
VisitResult result = GenerateCall(expr->pos, name, arguments, is_tailcall);
if (!result.type()->IsVoidOrNever()) {
GenerateIndent();
source_out() << "USE(" << result.variable() << ");" << std::endl;
......
......@@ -96,13 +96,23 @@ class ImplementationVisitor : public FileVisitor {
void Visit(ExplicitModuleDeclaration* decl) {
Visit(implicit_cast<ModuleDeclaration*>(decl));
}
void Visit(MacroDeclaration* decl);
void Visit(BuiltinDeclaration* decl);
void Visit(TypeDeclaration* decl) {}
void Visit(ConstDeclaration* decl) {}
void Visit(ExternalMacroDeclaration* decl) {}
void Visit(ExternalBuiltinDeclaration* decl) {}
void Visit(ExternalRuntimeDeclaration* decl) {}
void Visit(StandardDeclaration* decl);
void Visit(GenericDeclaration* decl) {}
void Visit(SpecializationDeclaration* decl);
void Visit(TorqueMacroDeclaration* decl, const Signature& signature,
Statement* body);
void Visit(TorqueBuiltinDeclaration* decl, const Signature& signature,
Statement* body);
void Visit(ExternalMacroDeclaration* decl, const Signature& signature,
Statement* body) {}
void Visit(ExternalBuiltinDeclaration* decl, const Signature& signature,
Statement* body) {}
void Visit(ExternalRuntimeDeclaration* decl, const Signature& signature,
Statement* body) {}
void Visit(CallableNode* decl, const Signature& signature, Statement* body);
VisitResult Visit(CallExpression* expr, bool is_tail = false);
const Type* Visit(TailCallStatement* stmt);
......@@ -217,6 +227,13 @@ class ImplementationVisitor : public FileVisitor {
const Type* destination_type,
VisitResult source);
void Specialize(const SpecializationKey& key, CallableNode* callable,
const CallableNodeSignature* signature,
Statement* body) override {
Declarations::GenericScopeActivator scope(declarations(), key);
Visit(callable, MakeSignature(callable, signature), body);
}
std::string NewTempVariable();
std::string GenerateNewTempVariable(const Type* type);
......
......@@ -118,8 +118,30 @@ class ScopeChain {
}
}
struct Snapshot {
ScopeChain* chain;
std::vector<Scope*> current_scopes;
};
Snapshot TaskSnapshot() { return {this, current_scopes_}; }
class ScopedSnapshotRestorer {
public:
explicit ScopedSnapshotRestorer(const Snapshot& snapshot)
: chain_(snapshot.chain) {
saved_ = chain_->current_scopes_;
chain_->current_scopes_ = snapshot.current_scopes;
}
~ScopedSnapshotRestorer() { chain_->current_scopes_ = saved_; }
private:
ScopeChain* chain_;
std::vector<Scope*> saved_;
};
private:
friend class Scope;
friend class ScopedSnapshotRestorer;
int GetNextScopeNumber() { return next_scope_number_++; }
......
......@@ -101,6 +101,29 @@ TEST(TestPartiallyUnusedLabel) {
ft.CheckCall(ft.true_value());
}
TEST(TestBuiltinSpecialization) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester asm_tester(isolate, 0);
TestBuiltinsFromDSLAssembler m(asm_tester.state());
{
Node* temp = m.SmiConstant(0);
m.TestBuiltinSpecialization(m.UncheckedCast<Context>(temp));
m.Return(m.UndefinedConstant());
}
FunctionTester ft(asm_tester.GenerateCode(), 0);
}
TEST(TestMacroSpecialization) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester asm_tester(isolate, 0);
TestBuiltinsFromDSLAssembler m(asm_tester.state());
{
m.TestMacroSpecialization();
m.Return(m.UndefinedConstant());
}
FunctionTester ft(asm_tester.GenerateCode(), 0);
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -3,108 +3,159 @@
// found in the LICENSE file.
module test {
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
if constexpr ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS)) {
return true;
}
else {
return false;
}
}
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
if constexpr ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS)) {
return true;
} else {
return false;
macro ElementsKindTestHelper2(kind: constexpr ElementsKind): bool {
return ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS));
}
}
macro ElementsKindTestHelper2(kind: constexpr ElementsKind): bool {
return ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS));
}
macro ElementsKindTestHelper3(kind: constexpr ElementsKind): constexpr bool {
return ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS));
}
macro ElementsKindTestHelper3(kind: constexpr ElementsKind): constexpr bool {
return ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS));
}
macro LabelTestHelper1(): never
labels Label1 {
goto Label1;
}
macro LabelTestHelper1(): never
labels Label1 {
goto Label1;
}
macro LabelTestHelper2(): never
labels Label2(Smi) {
goto Label2(42);
}
macro LabelTestHelper2(): never
labels Label2(Smi) {
goto Label2(42);
}
macro LabelTestHelper3(): never
labels Label3(String, Smi) {
goto Label3('foo', 7);
}
macro LabelTestHelper3(): never
labels Label3(String, Smi) {
goto Label3('foo', 7);
}
macro TestConstexpr1() {
assert(convert<bool>(IsFastElementsKind(PACKED_SMI_ELEMENTS)));
}
macro TestConstexpr1() {
assert(convert<bool>(IsFastElementsKind(PACKED_SMI_ELEMENTS)));
}
macro TestConstexprIf() {
assert(ElementsKindTestHelper1(UINT8_ELEMENTS));
assert(ElementsKindTestHelper1(UINT16_ELEMENTS));
assert(!ElementsKindTestHelper1(UINT32_ELEMENTS));
}
macro TestConstexprIf() {
assert(ElementsKindTestHelper1(UINT8_ELEMENTS));
assert(ElementsKindTestHelper1(UINT16_ELEMENTS));
assert(!ElementsKindTestHelper1(UINT32_ELEMENTS));
}
macro TestConstexprReturn() {
assert(convert<bool>(ElementsKindTestHelper3(UINT8_ELEMENTS)));
assert(convert<bool>(ElementsKindTestHelper3(UINT16_ELEMENTS)));
assert(!convert<bool>(ElementsKindTestHelper3(UINT32_ELEMENTS)));
assert(convert<bool>(!ElementsKindTestHelper3(UINT32_ELEMENTS)));
}
macro TestConstexprReturn() {
assert(convert<bool>(ElementsKindTestHelper3(UINT8_ELEMENTS)));
assert(convert<bool>(ElementsKindTestHelper3(UINT16_ELEMENTS)));
assert(!convert<bool>(ElementsKindTestHelper3(UINT32_ELEMENTS)));
assert(convert<bool>(!ElementsKindTestHelper3(UINT32_ELEMENTS)));
}
macro TestGotoLabel(): Boolean {
try {
LabelTestHelper1() otherwise Label1;
}
label Label1 {
return True;
}
}
macro TestGotoLabel(): Boolean {
try {
LabelTestHelper1() otherwise Label1;
macro TestGotoLabelWithOneParameter(): Boolean {
try {
LabelTestHelper2() otherwise Label2;
}
label Label2(smi: Smi) {
assert(smi == 42);
return True;
}
}
label Label1 {
return True;
macro TestGotoLabelWithTwoParameters(): Boolean {
try {
LabelTestHelper3() otherwise Label3;
}
label Label3(str: String, smi: Smi) {
assert(str == 'foo');
assert(smi == 7);
return True;
}
}
}
macro TestGotoLabelWithOneParameter(): Boolean {
try {
LabelTestHelper2() otherwise Label2;
builtin GenericBuiltinTest<T: type>(c: Context, param: T): Object {
return Null;
}
label Label2(smi: Smi) {
assert(smi == 42);
return True;
GenericBuiltinTest<Object>(c: Context, param: Object): Object {
return param;
}
}
macro TestGotoLabelWithTwoParameters(): Boolean {
try {
LabelTestHelper3() otherwise Label3;
macro TestBuiltinSpecialization(c: Context) {
assert(GenericBuiltinTest<Smi>(c, 0) == Null);
assert(GenericBuiltinTest<Smi>(c, 1) == Null);
assert(GenericBuiltinTest<Object>(c, Undefined) == Undefined);
assert(GenericBuiltinTest<Object>(c, Undefined) == Undefined);
}
label Label3(str: String, smi: Smi) {
assert(str == 'foo');
assert(smi == 7);
return True;
macro LabelTestHelper4(flag: constexpr bool): never labels Label4, Label5 {
if constexpr (flag) goto Label4;
else
goto Label5;
}
}
macro LabelTestHelper4(flag: constexpr bool): never labels Label4, Label5 {
if constexpr (flag) goto Label4;
else goto Label5;
}
macro CallLabelTestHelper4(flag: constexpr bool): bool {
try {
LabelTestHelper4(flag) otherwise Label4, Label5;
}
label Label4 {
return true;
}
label Label5 {
return false;
}
}
macro CallLabelTestHelper4(flag: constexpr bool): bool {
try {
LabelTestHelper4(flag) otherwise Label4, Label5;
macro TestPartiallyUnusedLabel(): Boolean {
let r1: bool = CallLabelTestHelper4(true);
let r2: bool = CallLabelTestHelper4(false);
if (r1 && !r2)
return True;
else
return False;
}
label Label4 {
return true;
macro GenericMacroTest<T: type>(param: T): Object {
return Undefined;
}
label Label5 {
return false;
GenericMacroTest<Object>(param2: Object): Object {
return param2;
}
}
macro TestPartiallyUnusedLabel(): Boolean {
let r1: bool = CallLabelTestHelper4(true);
let r2: bool = CallLabelTestHelper4(false);
macro GenericMacroTestWithLabels<T: type>(param: T): Object labels X {
return Undefined;
}
if (r1 && !r2) return True;
else return False;
}
GenericMacroTestWithLabels<Object>(param2: Object): Object labels Y {
return param2;
}
macro TestMacroSpecialization() {
try {
if (True == False) goto Fail; // Silence warnings in release build
assert(GenericMacroTest<Smi>(0) == Undefined);
assert(GenericMacroTest<Smi>(1) == Undefined);
assert(GenericMacroTest<Object>(Null) == Null);
assert(GenericMacroTest<Object>(False) == False);
assert(GenericMacroTest<Object>(True) == True);
assert(GenericMacroTestWithLabels<Smi>(0) otherwise Fail == Undefined);
assert(GenericMacroTestWithLabels<Smi>(0) otherwise Fail == Undefined);
assert(GenericMacroTestWithLabels<Object>(Null) otherwise Fail == Null);
assert(GenericMacroTestWithLabels<Object>(False) otherwise Fail == False);
}
label Fail {
unreachable;
}
}
}
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