Commit ed6b11d5 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] a new self-contained parser for torque

Bug: v8:7793
Change-Id: I208edf856f0283d840358f3c11bab97af0397056
Reviewed-on: https://chromium-review.googlesource.com/1095192Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54574}
parent 0ff83e97
......@@ -3143,24 +3143,7 @@ if (current_toolchain == v8_snapshot_toolchain) {
v8_executable("torque") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
defines = [ "ANTLR4CPP_STATIC" ]
include_dirs = [
"third_party/antlr4/runtime/Cpp/runtime/src",
"src/torque",
]
sources = [
"src/torque/TorqueBaseVisitor.cpp",
"src/torque/TorqueBaseVisitor.h",
"src/torque/TorqueLexer.cpp",
"src/torque/TorqueLexer.h",
"src/torque/TorqueParser.cpp",
"src/torque/TorqueParser.h",
"src/torque/TorqueVisitor.cpp",
"src/torque/TorqueVisitor.h",
"src/torque/ast-generator.cc",
"src/torque/ast-generator.h",
"src/torque/ast.h",
"src/torque/contextual.h",
"src/torque/declarable.cc",
......@@ -3169,6 +3152,8 @@ if (current_toolchain == v8_snapshot_toolchain) {
"src/torque/declaration-visitor.h",
"src/torque/declarations.cc",
"src/torque/declarations.h",
"src/torque/earley-parser.cc",
"src/torque/earley-parser.h",
"src/torque/file-visitor.cc",
"src/torque/file-visitor.h",
"src/torque/global-context.h",
......@@ -3176,6 +3161,9 @@ if (current_toolchain == v8_snapshot_toolchain) {
"src/torque/implementation-visitor.h",
"src/torque/scope.cc",
"src/torque/scope.h",
"src/torque/source-positions.h",
"src/torque/torque-parser.cc",
"src/torque/torque-parser.h",
"src/torque/torque.cc",
"src/torque/type-oracle.h",
"src/torque/types.cc",
......@@ -3186,19 +3174,10 @@ if (current_toolchain == v8_snapshot_toolchain) {
deps = [
":v8_libbase",
"third_party/antlr4:antlr4",
"//build/win:default_exe_manifest",
]
remove_configs = [
"//build/config/compiler:no_rtti",
"//build/config/compiler:no_exceptions",
]
configs = [
"//build/config/compiler:rtti",
"//build/config/compiler:exceptions",
"third_party/antlr4:antlr-compatibility",
":external_config",
":internal_config_base",
]
......
......@@ -113,6 +113,12 @@ V8_INLINE Dest bit_cast(Source const& source) {
TypeName(const TypeName&) = delete; \
DISALLOW_ASSIGN(TypeName)
// Explicitly declare all copy/move constructors and assignments as deleted.
#define DISALLOW_COPY_AND_MOVE_AND_ASSIGN(TypeName) \
TypeName(TypeName&&) = delete; \
TypeName& operator=(TypeName&&) = delete; \
DISALLOW_COPY_AND_ASSIGN(TypeName)
// Explicitly declare all implicit constructors as deleted, namely the
// default constructor, copy constructor and operator= functions.
// This is especially useful for classes containing only static methods.
......
......@@ -280,8 +280,14 @@ extern operator '|' macro Word32Or(uint32, uint32): uint32;
extern operator '+' macro NumberAdd(Number, Number): Number;
extern operator '-' macro NumberSub(Number, Number): Number;
extern operator 'min' macro NumberMin(Number, Number): Number;
extern operator 'max' macro NumberMax(Number, Number): Number;
extern macro NumberMin(Number, Number): Number;
extern macro NumberMax(Number, Number): Number;
macro min(x: Number, y : Number) : Number {
return NumberMin(x,y);
}
macro max(x: Number, y : Number) : Number {
return NumberMax(x,y);
}
extern operator '!' macro ConstexprBoolNot(constexpr bool): constexpr bool;
extern operator '!' macro Word32BinaryNot(bool): bool;
......@@ -709,7 +715,9 @@ extern macro Typeof(Object): Object;
// Return true iff number is NaN.
macro NumberIsNaN(number: Number): bool {
if (TaggedIsSmi(number)) return false;
if (TaggedIsSmi(number)) {
return false;
}
let value: float64 = convert<float64>(unsafe_cast<HeapNumber>(number));
return value != value;
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
grammar Torque;
options {
language=Cpp;
}
// parser rules start with lowercase letters, lexer rules with uppercase
MACRO: 'macro';
BUILTIN: 'builtin';
RUNTIME: 'runtime';
MODULE: 'module';
JAVASCRIPT: 'javascript';
DEFERRED: 'deferred';
IF: 'if';
FOR: 'for';
WHILE: 'while';
RETURN: 'return';
CONSTEXPR: 'constexpr';
CONTINUE: 'continue';
BREAK: 'break';
GOTO: 'goto';
OTHERWISE: 'otherwise';
TRY: 'try';
LABEL: 'label';
LABELS: 'labels';
TAIL: 'tail';
ISNT: 'isnt';
IS: 'is';
LET: 'let';
CONST: 'const';
EXTERN: 'extern';
ASSERT_TOKEN: 'assert';
CHECK_TOKEN: 'check';
UNREACHABLE_TOKEN: 'unreachable';
DEBUG_TOKEN: 'debug';
ASSIGNMENT: '=';
ASSIGNMENT_OPERATOR
: '*='
| '/='
| '%='
| '+='
| '-='
| '<<='
| '>>='
| '>>>='
| '&='
| '^='
| '|='
;
EQUAL: '==';
PLUS: '+';
MINUS: '-';
MULTIPLY: '*';
DIVIDE: '/';
MODULO: '%';
BIT_OR: '|';
BIT_AND: '&';
BIT_NOT: '~';
MAX: 'max';
MIN: 'min';
NOT_EQUAL: '!=';
LESS_THAN: '<';
LESS_THAN_EQUAL: '<=';
GREATER_THAN: '>';
GREATER_THAN_EQUAL: '>=';
SHIFT_LEFT: '<<';
SHIFT_RIGHT: '>>';
SHIFT_RIGHT_ARITHMETIC: '>>>';
VARARGS: '...';
EQUALITY_OPERATOR: EQUAL | NOT_EQUAL;
INCREMENT: '++';
DECREMENT: '--';
NOT: '!';
STRING_LITERAL : ('"' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) * '"')
| ('\'' ( ESCAPE | ~('\'' | '\\' | '\n' | '\r') ) * '\'');
fragment ESCAPE : '\\' ( '\'' | '\\' | '"' | 'n' | 'r' );
IDENTIFIER : [A-Za-z][0-9A-Za-z_]* ;
WS : [ \t\r\n\f]+ -> channel(HIDDEN);
BLOCK_COMMENT
: '/*' .*? ('*/' | EOF) -> channel(HIDDEN)
;
LINE_COMMENT
: '//' ~[\r\n]* -> channel(HIDDEN)
;
fragment DECIMAL_DIGIT
: [0-9]
;
fragment DECIMAL_INTEGER_LITERAL
: '0'
| [1-9] DECIMAL_DIGIT*
;
fragment EXPONENT_PART
: [eE] [+-]? DECIMAL_DIGIT+
;
DECIMAL_LITERAL
: MINUS? DECIMAL_INTEGER_LITERAL '.' DECIMAL_DIGIT* EXPONENT_PART?
| MINUS? '.' DECIMAL_DIGIT+ EXPONENT_PART?
| MINUS? DECIMAL_INTEGER_LITERAL EXPONENT_PART?
| MINUS? '0x' [0-9a-fA-F]+
;
type : CONSTEXPR? IDENTIFIER
| BUILTIN '(' typeList ')' '=>' type
| type BIT_OR type
| '(' type ')'
;
typeList : (type (',' type)*)?;
genericSpecializationTypeList: '<' typeList '>';
optionalGenericTypeList: ('<' IDENTIFIER ':' 'type' (',' IDENTIFIER ':' 'type')* '>')?;
typeListMaybeVarArgs: '(' type? (',' type)* (',' VARARGS)? ')'
| '(' VARARGS ')';
labelParameter: IDENTIFIER ( '(' typeList ')' )?;
optionalType: (':' type)?;
optionalLabelList: (LABELS labelParameter (',' labelParameter)*)?;
optionalOtherwise: (OTHERWISE IDENTIFIER (',' IDENTIFIER)*)?;
parameter: IDENTIFIER ':' type?;
parameterList
: '(' parameter? (',' parameter)* ')'
| '(' parameter ',' parameter ',' VARARGS IDENTIFIER ')';
labelDeclaration: IDENTIFIER parameterList?;
expression
: conditionalExpression;
conditionalExpression
: logicalORExpression
| conditionalExpression '?' logicalORExpression ':' logicalORExpression;
logicalORExpression
: logicalANDExpression
| logicalORExpression '||' logicalANDExpression;
logicalANDExpression
: bitwiseExpression
| logicalANDExpression '&&' bitwiseExpression;
bitwiseExpression
: equalityExpression
| bitwiseExpression op=(BIT_AND | BIT_OR) equalityExpression;
equalityExpression
: relationalExpression
| equalityExpression
op=(EQUAL | NOT_EQUAL)
relationalExpression;
relationalExpression
: shiftExpression
| relationalExpression
op=(LESS_THAN | LESS_THAN_EQUAL | GREATER_THAN | GREATER_THAN_EQUAL)
shiftExpression;
shiftExpression
: additiveExpression
| shiftExpression op=(SHIFT_RIGHT | SHIFT_LEFT | SHIFT_RIGHT_ARITHMETIC) additiveExpression;
additiveExpression
: multiplicativeExpression
| additiveExpression op=(PLUS | MINUS) multiplicativeExpression;
multiplicativeExpression
: unaryExpression
| multiplicativeExpression op=(MULTIPLY | DIVIDE | MODULO) unaryExpression;
unaryExpression
: assignmentExpression
| op=(PLUS | MINUS | BIT_NOT | NOT) unaryExpression;
locationExpression
: IDENTIFIER
| locationExpression '.' IDENTIFIER
| primaryExpression '.' IDENTIFIER
| locationExpression '[' expression ']'
| primaryExpression '[' expression ']';
incrementDecrement
: INCREMENT locationExpression
| DECREMENT locationExpression
| locationExpression op=INCREMENT
| locationExpression op=DECREMENT
;
assignment
: incrementDecrement
| locationExpression ((ASSIGNMENT | ASSIGNMENT_OPERATOR) expression)?;
assignmentExpression
: functionPointerExpression
| assignment;
structExpression
: IDENTIFIER '{' (expression (',' expression)*)? '}';
functionPointerExpression
: primaryExpression
| IDENTIFIER genericSpecializationTypeList?
;
primaryExpression
: helperCall
| structExpression
| DECIMAL_LITERAL
| STRING_LITERAL
| ('(' expression ')')
;
forInitialization : variableDeclarationWithInitialization?;
forLoop: FOR '(' forInitialization ';' expression ';' assignment ')' statementBlock;
rangeSpecifier: '[' begin=expression? ':' end=expression? ']';
forOfRange: rangeSpecifier?;
forOfLoop: FOR '(' variableDeclaration 'of' expression forOfRange ')' statementBlock;
argument: expression;
argumentList: '(' argument? (',' argument)* ')';
helperCall: (MIN | MAX | IDENTIFIER) genericSpecializationTypeList? argumentList optionalOtherwise;
labelReference: IDENTIFIER;
variableDeclaration: (LET | CONST) IDENTIFIER ':' type;
variableDeclarationWithInitialization: variableDeclaration (ASSIGNMENT expression)?;
helperCallStatement: (TAIL)? helperCall;
expressionStatement: assignment;
ifStatement: IF CONSTEXPR? '(' expression ')' statementBlock ('else' statementBlock)?;
whileLoop: WHILE '(' expression ')' statementBlock;
returnStatement: RETURN expression?;
breakStatement: BREAK;
continueStatement: CONTINUE;
gotoStatement: GOTO labelReference argumentList?;
handlerWithStatement: LABEL labelDeclaration statementBlock;
tryLabelStatement: TRY statementBlock handlerWithStatement+;
diagnosticStatement: ((ASSERT_TOKEN | CHECK_TOKEN) '(' expression ')') | UNREACHABLE_TOKEN | DEBUG_TOKEN;
statement : variableDeclarationWithInitialization ';'
| helperCallStatement ';'
| expressionStatement ';'
| returnStatement ';'
| breakStatement ';'
| continueStatement ';'
| gotoStatement ';'
| ifStatement
| diagnosticStatement ';'
| whileLoop
| forOfLoop
| forLoop
| tryLabelStatement
;
statementList : statement*;
statementScope : DEFERRED? '{' statementList '}';
statementBlock
: statement
| statementScope;
helperBody : statementScope;
fieldDeclaration: IDENTIFIER ':' type ';';
fieldListDeclaration: fieldDeclaration*;
extendsDeclaration: 'extends' IDENTIFIER;
generatesDeclaration: 'generates' STRING_LITERAL;
constexprDeclaration: 'constexpr' STRING_LITERAL;
typeDeclaration : 'type' IDENTIFIER extendsDeclaration? generatesDeclaration? constexprDeclaration?';';
typeAliasDeclaration : 'type' IDENTIFIER '=' type ';';
externalBuiltin : EXTERN JAVASCRIPT? BUILTIN IDENTIFIER optionalGenericTypeList '(' typeList ')' optionalType ';';
externalMacro : EXTERN ('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 genericSpecializationTypeList parameterList optionalType optionalLabelList helperBody;
macroDeclaration : ('operator' STRING_LITERAL)? MACRO IDENTIFIER optionalGenericTypeList parameterList optionalType optionalLabelList (helperBody | ';');
externConstDeclaration : CONST IDENTIFIER ':' type generatesDeclaration ';';
constDeclaration: CONST IDENTIFIER ':' type ASSIGNMENT expression ';';
structDeclaration : 'struct' IDENTIFIER '{' fieldListDeclaration '}';
declaration
: structDeclaration
| typeDeclaration
| typeAliasDeclaration
| builtinDeclaration
| genericSpecialization
| macroDeclaration
| externalMacro
| externalBuiltin
| externalRuntime
| externConstDeclaration
| constDeclaration;
moduleDeclaration : MODULE IDENTIFIER '{' declaration* '}';
file: (moduleDeclaration | declaration)*;
This diff is collapsed.
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
T__5=6
T__6=7
T__7=8
T__8=9
T__9=10
T__10=11
T__11=12
T__12=13
T__13=14
T__14=15
T__15=16
T__16=17
T__17=18
T__18=19
T__19=20
T__20=21
MACRO=22
BUILTIN=23
RUNTIME=24
MODULE=25
JAVASCRIPT=26
DEFERRED=27
IF=28
FOR=29
WHILE=30
RETURN=31
CONSTEXPR=32
CONTINUE=33
BREAK=34
GOTO=35
OTHERWISE=36
TRY=37
LABEL=38
LABELS=39
TAIL=40
ISNT=41
IS=42
LET=43
CONST=44
EXTERN=45
ASSERT_TOKEN=46
CHECK_TOKEN=47
UNREACHABLE_TOKEN=48
DEBUG_TOKEN=49
ASSIGNMENT=50
ASSIGNMENT_OPERATOR=51
EQUAL=52
PLUS=53
MINUS=54
MULTIPLY=55
DIVIDE=56
MODULO=57
BIT_OR=58
BIT_AND=59
BIT_NOT=60
MAX=61
MIN=62
NOT_EQUAL=63
LESS_THAN=64
LESS_THAN_EQUAL=65
GREATER_THAN=66
GREATER_THAN_EQUAL=67
SHIFT_LEFT=68
SHIFT_RIGHT=69
SHIFT_RIGHT_ARITHMETIC=70
VARARGS=71
EQUALITY_OPERATOR=72
INCREMENT=73
DECREMENT=74
NOT=75
STRING_LITERAL=76
IDENTIFIER=77
WS=78
BLOCK_COMMENT=79
LINE_COMMENT=80
DECIMAL_LITERAL=81
'('=1
')'=2
'=>'=3
','=4
':'=5
'type'=6
'?'=7
'||'=8
'&&'=9
'.'=10
'['=11
']'=12
'{'=13
'}'=14
';'=15
'of'=16
'else'=17
'extends'=18
'generates'=19
'operator'=20
'struct'=21
'macro'=22
'builtin'=23
'runtime'=24
'module'=25
'javascript'=26
'deferred'=27
'if'=28
'for'=29
'while'=30
'return'=31
'constexpr'=32
'continue'=33
'break'=34
'goto'=35
'otherwise'=36
'try'=37
'label'=38
'labels'=39
'tail'=40
'isnt'=41
'is'=42
'let'=43
'const'=44
'extern'=45
'assert'=46
'check'=47
'unreachable'=48
'debug'=49
'='=50
'=='=52
'+'=53
'-'=54
'*'=55
'/'=56
'%'=57
'|'=58
'&'=59
'~'=60
'max'=61
'min'=62
'!='=63
'<'=64
'<='=65
'>'=66
'>='=67
'<<'=68
'>>'=69
'>>>'=70
'...'=71
'++'=73
'--'=74
'!'=75
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Generated from Torque.g4 by ANTLR 4.7.1
#include "TorqueBaseListener.h"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TORQUE_TORQUELEXER_H_
#define V8_TORQUE_TORQUELEXER_H_
// Generated from Torque.g4 by ANTLR 4.7.1
#pragma once
#include "./antlr4-runtime.h"
class TorqueLexer : public antlr4::Lexer {
public:
enum {
T__0 = 1,
T__1 = 2,
T__2 = 3,
T__3 = 4,
T__4 = 5,
T__5 = 6,
T__6 = 7,
T__7 = 8,
T__8 = 9,
T__9 = 10,
T__10 = 11,
T__11 = 12,
T__12 = 13,
T__13 = 14,
T__14 = 15,
T__15 = 16,
T__16 = 17,
T__17 = 18,
T__18 = 19,
T__19 = 20,
T__20 = 21,
MACRO = 22,
BUILTIN = 23,
RUNTIME = 24,
MODULE = 25,
JAVASCRIPT = 26,
DEFERRED = 27,
IF = 28,
FOR = 29,
WHILE = 30,
RETURN = 31,
CONSTEXPR = 32,
CONTINUE = 33,
BREAK = 34,
GOTO = 35,
OTHERWISE = 36,
TRY = 37,
LABEL = 38,
LABELS = 39,
TAIL = 40,
ISNT = 41,
IS = 42,
LET = 43,
CONST = 44,
EXTERN = 45,
ASSERT_TOKEN = 46,
CHECK_TOKEN = 47,
UNREACHABLE_TOKEN = 48,
DEBUG_TOKEN = 49,
ASSIGNMENT = 50,
ASSIGNMENT_OPERATOR = 51,
EQUAL = 52,
PLUS = 53,
MINUS = 54,
MULTIPLY = 55,
DIVIDE = 56,
MODULO = 57,
BIT_OR = 58,
BIT_AND = 59,
BIT_NOT = 60,
MAX = 61,
MIN = 62,
NOT_EQUAL = 63,
LESS_THAN = 64,
LESS_THAN_EQUAL = 65,
GREATER_THAN = 66,
GREATER_THAN_EQUAL = 67,
SHIFT_LEFT = 68,
SHIFT_RIGHT = 69,
SHIFT_RIGHT_ARITHMETIC = 70,
VARARGS = 71,
EQUALITY_OPERATOR = 72,
INCREMENT = 73,
DECREMENT = 74,
NOT = 75,
STRING_LITERAL = 76,
IDENTIFIER = 77,
WS = 78,
BLOCK_COMMENT = 79,
LINE_COMMENT = 80,
DECIMAL_LITERAL = 81
};
explicit TorqueLexer(antlr4::CharStream* input);
~TorqueLexer();
std::string getGrammarFileName() const override;
const std::vector<std::string>& getRuleNames() const override;
const std::vector<std::string>& getChannelNames() const override;
const std::vector<std::string>& getModeNames() const override;
const std::vector<std::string>& getTokenNames()
const override; // deprecated, use vocabulary instead
antlr4::dfa::Vocabulary& getVocabulary() const override;
const std::vector<uint16_t> getSerializedATN() const override;
const antlr4::atn::ATN& getATN() const override;
private:
static std::vector<antlr4::dfa::DFA> _decisionToDFA;
static antlr4::atn::PredictionContextCache _sharedContextCache;
static std::vector<std::string> _ruleNames;
static std::vector<std::string> _tokenNames;
static std::vector<std::string> _channelNames;
static std::vector<std::string> _modeNames;
static std::vector<std::string> _literalNames;
static std::vector<std::string> _symbolicNames;
static antlr4::dfa::Vocabulary _vocabulary;
static antlr4::atn::ATN _atn;
static std::vector<uint16_t> _serializedATN;
// Individual action functions triggered by action() above.
// Individual semantic predicate functions triggered by sempred() above.
struct Initializer {
Initializer();
};
static Initializer _init;
};
#endif // V8_TORQUE_TORQUELEXER_H_
This diff is collapsed.
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
T__5=6
T__6=7
T__7=8
T__8=9
T__9=10
T__10=11
T__11=12
T__12=13
T__13=14
T__14=15
T__15=16
T__16=17
T__17=18
T__18=19
T__19=20
T__20=21
MACRO=22
BUILTIN=23
RUNTIME=24
MODULE=25
JAVASCRIPT=26
DEFERRED=27
IF=28
FOR=29
WHILE=30
RETURN=31
CONSTEXPR=32
CONTINUE=33
BREAK=34
GOTO=35
OTHERWISE=36
TRY=37
LABEL=38
LABELS=39
TAIL=40
ISNT=41
IS=42
LET=43
CONST=44
EXTERN=45
ASSERT_TOKEN=46
CHECK_TOKEN=47
UNREACHABLE_TOKEN=48
DEBUG_TOKEN=49
ASSIGNMENT=50
ASSIGNMENT_OPERATOR=51
EQUAL=52
PLUS=53
MINUS=54
MULTIPLY=55
DIVIDE=56
MODULO=57
BIT_OR=58
BIT_AND=59
BIT_NOT=60
MAX=61
MIN=62
NOT_EQUAL=63
LESS_THAN=64
LESS_THAN_EQUAL=65
GREATER_THAN=66
GREATER_THAN_EQUAL=67
SHIFT_LEFT=68
SHIFT_RIGHT=69
SHIFT_RIGHT_ARITHMETIC=70
VARARGS=71
EQUALITY_OPERATOR=72
INCREMENT=73
DECREMENT=74
NOT=75
STRING_LITERAL=76
IDENTIFIER=77
WS=78
BLOCK_COMMENT=79
LINE_COMMENT=80
DECIMAL_LITERAL=81
'('=1
')'=2
'=>'=3
','=4
':'=5
'type'=6
'?'=7
'||'=8
'&&'=9
'.'=10
'['=11
']'=12
'{'=13
'}'=14
';'=15
'of'=16
'else'=17
'extends'=18
'generates'=19
'operator'=20
'struct'=21
'macro'=22
'builtin'=23
'runtime'=24
'module'=25
'javascript'=26
'deferred'=27
'if'=28
'for'=29
'while'=30
'return'=31
'constexpr'=32
'continue'=33
'break'=34
'goto'=35
'otherwise'=36
'try'=37
'label'=38
'labels'=39
'tail'=40
'isnt'=41
'is'=42
'let'=43
'const'=44
'extern'=45
'assert'=46
'check'=47
'unreachable'=48
'debug'=49
'='=50
'=='=52
'+'=53
'-'=54
'*'=55
'/'=56
'%'=57
'|'=58
'&'=59
'~'=60
'max'=61
'min'=62
'!='=63
'<'=64
'<='=65
'>'=66
'>='=67
'<<'=68
'>>'=69
'>>>'=70
'...'=71
'++'=73
'--'=74
'!'=75
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Generated from Torque.g4 by ANTLR 4.7.1
#include "TorqueListener.h"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Generated from Torque.g4 by ANTLR 4.7.1
#include "TorqueVisitor.h"
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TORQUE_TORQUEVISITOR_H_
#define V8_TORQUE_TORQUEVISITOR_H_
// Generated from Torque.g4 by ANTLR 4.7.1
#pragma once
#include "./antlr4-runtime.h"
#include "TorqueParser.h"
/**
* This class defines an abstract visitor for a parse tree
* produced by TorqueParser.
*/
class TorqueVisitor : public antlr4::tree::AbstractParseTreeVisitor {
public:
/**
* Visit parse trees produced by TorqueParser.
*/
virtual antlrcpp::Any visitType(TorqueParser::TypeContext* context) = 0;
virtual antlrcpp::Any visitTypeList(
TorqueParser::TypeListContext* context) = 0;
virtual antlrcpp::Any visitGenericSpecializationTypeList(
TorqueParser::GenericSpecializationTypeListContext* context) = 0;
virtual antlrcpp::Any visitOptionalGenericTypeList(
TorqueParser::OptionalGenericTypeListContext* context) = 0;
virtual antlrcpp::Any visitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* context) = 0;
virtual antlrcpp::Any visitLabelParameter(
TorqueParser::LabelParameterContext* context) = 0;
virtual antlrcpp::Any visitOptionalType(
TorqueParser::OptionalTypeContext* context) = 0;
virtual antlrcpp::Any visitOptionalLabelList(
TorqueParser::OptionalLabelListContext* context) = 0;
virtual antlrcpp::Any visitOptionalOtherwise(
TorqueParser::OptionalOtherwiseContext* context) = 0;
virtual antlrcpp::Any visitParameter(
TorqueParser::ParameterContext* context) = 0;
virtual antlrcpp::Any visitParameterList(
TorqueParser::ParameterListContext* context) = 0;
virtual antlrcpp::Any visitLabelDeclaration(
TorqueParser::LabelDeclarationContext* context) = 0;
virtual antlrcpp::Any visitExpression(
TorqueParser::ExpressionContext* context) = 0;
virtual antlrcpp::Any visitConditionalExpression(
TorqueParser::ConditionalExpressionContext* context) = 0;
virtual antlrcpp::Any visitLogicalORExpression(
TorqueParser::LogicalORExpressionContext* context) = 0;
virtual antlrcpp::Any visitLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* context) = 0;
virtual antlrcpp::Any visitBitwiseExpression(
TorqueParser::BitwiseExpressionContext* context) = 0;
virtual antlrcpp::Any visitEqualityExpression(
TorqueParser::EqualityExpressionContext* context) = 0;
virtual antlrcpp::Any visitRelationalExpression(
TorqueParser::RelationalExpressionContext* context) = 0;
virtual antlrcpp::Any visitShiftExpression(
TorqueParser::ShiftExpressionContext* context) = 0;
virtual antlrcpp::Any visitAdditiveExpression(
TorqueParser::AdditiveExpressionContext* context) = 0;
virtual antlrcpp::Any visitMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* context) = 0;
virtual antlrcpp::Any visitUnaryExpression(
TorqueParser::UnaryExpressionContext* context) = 0;
virtual antlrcpp::Any visitLocationExpression(
TorqueParser::LocationExpressionContext* context) = 0;
virtual antlrcpp::Any visitIncrementDecrement(
TorqueParser::IncrementDecrementContext* context) = 0;
virtual antlrcpp::Any visitAssignment(
TorqueParser::AssignmentContext* context) = 0;
virtual antlrcpp::Any visitAssignmentExpression(
TorqueParser::AssignmentExpressionContext* context) = 0;
virtual antlrcpp::Any visitStructExpression(
TorqueParser::StructExpressionContext* context) = 0;
virtual antlrcpp::Any visitFunctionPointerExpression(
TorqueParser::FunctionPointerExpressionContext* context) = 0;
virtual antlrcpp::Any visitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* context) = 0;
virtual antlrcpp::Any visitForInitialization(
TorqueParser::ForInitializationContext* context) = 0;
virtual antlrcpp::Any visitForLoop(TorqueParser::ForLoopContext* context) = 0;
virtual antlrcpp::Any visitRangeSpecifier(
TorqueParser::RangeSpecifierContext* context) = 0;
virtual antlrcpp::Any visitForOfRange(
TorqueParser::ForOfRangeContext* context) = 0;
virtual antlrcpp::Any visitForOfLoop(
TorqueParser::ForOfLoopContext* context) = 0;
virtual antlrcpp::Any visitArgument(
TorqueParser::ArgumentContext* context) = 0;
virtual antlrcpp::Any visitArgumentList(
TorqueParser::ArgumentListContext* context) = 0;
virtual antlrcpp::Any visitHelperCall(
TorqueParser::HelperCallContext* context) = 0;
virtual antlrcpp::Any visitLabelReference(
TorqueParser::LabelReferenceContext* context) = 0;
virtual antlrcpp::Any visitVariableDeclaration(
TorqueParser::VariableDeclarationContext* context) = 0;
virtual antlrcpp::Any visitVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* context) = 0;
virtual antlrcpp::Any visitHelperCallStatement(
TorqueParser::HelperCallStatementContext* context) = 0;
virtual antlrcpp::Any visitExpressionStatement(
TorqueParser::ExpressionStatementContext* context) = 0;
virtual antlrcpp::Any visitIfStatement(
TorqueParser::IfStatementContext* context) = 0;
virtual antlrcpp::Any visitWhileLoop(
TorqueParser::WhileLoopContext* context) = 0;
virtual antlrcpp::Any visitReturnStatement(
TorqueParser::ReturnStatementContext* context) = 0;
virtual antlrcpp::Any visitBreakStatement(
TorqueParser::BreakStatementContext* context) = 0;
virtual antlrcpp::Any visitContinueStatement(
TorqueParser::ContinueStatementContext* context) = 0;
virtual antlrcpp::Any visitGotoStatement(
TorqueParser::GotoStatementContext* context) = 0;
virtual antlrcpp::Any visitHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* context) = 0;
virtual antlrcpp::Any visitTryLabelStatement(
TorqueParser::TryLabelStatementContext* context) = 0;
virtual antlrcpp::Any visitDiagnosticStatement(
TorqueParser::DiagnosticStatementContext* context) = 0;
virtual antlrcpp::Any visitStatement(
TorqueParser::StatementContext* context) = 0;
virtual antlrcpp::Any visitStatementList(
TorqueParser::StatementListContext* context) = 0;
virtual antlrcpp::Any visitStatementScope(
TorqueParser::StatementScopeContext* context) = 0;
virtual antlrcpp::Any visitStatementBlock(
TorqueParser::StatementBlockContext* context) = 0;
virtual antlrcpp::Any visitHelperBody(
TorqueParser::HelperBodyContext* context) = 0;
virtual antlrcpp::Any visitFieldDeclaration(
TorqueParser::FieldDeclarationContext* context) = 0;
virtual antlrcpp::Any visitFieldListDeclaration(
TorqueParser::FieldListDeclarationContext* context) = 0;
virtual antlrcpp::Any visitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* context) = 0;
virtual antlrcpp::Any visitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* context) = 0;
virtual antlrcpp::Any visitConstexprDeclaration(
TorqueParser::ConstexprDeclarationContext* context) = 0;
virtual antlrcpp::Any visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* context) = 0;
virtual antlrcpp::Any visitTypeAliasDeclaration(
TorqueParser::TypeAliasDeclarationContext* context) = 0;
virtual antlrcpp::Any visitExternalBuiltin(
TorqueParser::ExternalBuiltinContext* context) = 0;
virtual antlrcpp::Any visitExternalMacro(
TorqueParser::ExternalMacroContext* context) = 0;
virtual antlrcpp::Any visitExternalRuntime(
TorqueParser::ExternalRuntimeContext* context) = 0;
virtual antlrcpp::Any visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* context) = 0;
virtual antlrcpp::Any visitGenericSpecialization(
TorqueParser::GenericSpecializationContext* context) = 0;
virtual antlrcpp::Any visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* context) = 0;
virtual antlrcpp::Any visitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* context) = 0;
virtual antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) = 0;
virtual antlrcpp::Any visitStructDeclaration(
TorqueParser::StructDeclarationContext* context) = 0;
virtual antlrcpp::Any visitDeclaration(
TorqueParser::DeclarationContext* context) = 0;
virtual antlrcpp::Any visitModuleDeclaration(
TorqueParser::ModuleDeclarationContext* context) = 0;
virtual antlrcpp::Any visitFile(TorqueParser::FileContext* context) = 0;
};
#endif // V8_TORQUE_TORQUEVISITOR_H_
This diff is collapsed.
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TORQUE_AST_GENERATOR_H_
#define V8_TORQUE_AST_GENERATOR_H_
#include "src/torque/TorqueBaseVisitor.h"
#include "src/torque/ast.h"
#include "src/torque/global-context.h"
namespace v8 {
namespace internal {
namespace torque {
class AstGenerator : public TorqueBaseVisitor {
public:
antlrcpp::Any visitParameterList(
TorqueParser::ParameterListContext* context) override;
antlrcpp::Any visitTypeList(TorqueParser::TypeListContext* context) override;
antlrcpp::Any visitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* context) override;
antlrcpp::Any visitModuleDeclaration(
TorqueParser::ModuleDeclarationContext* context) override;
antlrcpp::Any visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* context) override;
antlrcpp::Any visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* context) override;
antlrcpp::Any visitExternalMacro(
TorqueParser::ExternalMacroContext* context) override;
antlrcpp::Any visitExternalBuiltin(
TorqueParser::ExternalBuiltinContext* context) override;
antlrcpp::Any visitExternalRuntime(
TorqueParser::ExternalRuntimeContext* context) override;
antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) override;
antlrcpp::Any visitGenericSpecialization(
TorqueParser::GenericSpecializationContext* context) override;
antlrcpp::Any visitExternConstDeclaration(
TorqueParser::ExternConstDeclarationContext* context) override;
antlrcpp::Any visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* context) override;
antlrcpp::Any visitTypeAliasDeclaration(
TorqueParser::TypeAliasDeclarationContext* context) override;
antlrcpp::Any visitVariableDeclaration(
TorqueParser::VariableDeclarationContext* context) override;
antlrcpp::Any visitVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* context)
override;
antlrcpp::Any visitHelperCall(
TorqueParser::HelperCallContext* context) override;
antlrcpp::Any visitHelperCallStatement(
TorqueParser::HelperCallStatementContext* context) override;
antlrcpp::Any visitStructExpression(
TorqueParser::StructExpressionContext* context) override;
antlrcpp::Any visitConditionalExpression(
TorqueParser::ConditionalExpressionContext* context) override;
antlrcpp::Any visitLogicalORExpression(
TorqueParser::LogicalORExpressionContext* context) override;
antlrcpp::Any visitLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* context) override;
antlrcpp::Any visitBitwiseExpression(
TorqueParser::BitwiseExpressionContext* context) override;
antlrcpp::Any visitEqualityExpression(
TorqueParser::EqualityExpressionContext* context) override;
antlrcpp::Any visitRelationalExpression(
TorqueParser::RelationalExpressionContext* context) override;
antlrcpp::Any visitShiftExpression(
TorqueParser::ShiftExpressionContext* context) override;
antlrcpp::Any visitAdditiveExpression(
TorqueParser::AdditiveExpressionContext* context) override;
antlrcpp::Any visitMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* context) override;
antlrcpp::Any visitUnaryExpression(
TorqueParser::UnaryExpressionContext* context) override;
antlrcpp::Any visitLocationExpression(
TorqueParser::LocationExpressionContext* locationExpression) override;
antlrcpp::Any visitIncrementDecrement(
TorqueParser::IncrementDecrementContext* context) override;
antlrcpp::Any visitAssignment(
TorqueParser::AssignmentContext* context) override;
antlrcpp::Any visitFunctionPointerExpression(
TorqueParser::FunctionPointerExpressionContext* context) override;
antlrcpp::Any visitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* context) override;
antlrcpp::Any visitTryLabelStatement(
TorqueParser::TryLabelStatementContext* context) override;
antlrcpp::Any visitStatementScope(
TorqueParser::StatementScopeContext* context) override;
antlrcpp::Any visitExpressionStatement(
TorqueParser::ExpressionStatementContext* context) override;
antlrcpp::Any visitReturnStatement(
TorqueParser::ReturnStatementContext* context) override;
antlrcpp::Any visitGotoStatement(
TorqueParser::GotoStatementContext* context) override;
antlrcpp::Any visitIfStatement(
TorqueParser::IfStatementContext* context) override;
antlrcpp::Any visitWhileLoop(
TorqueParser::WhileLoopContext* context) override;
antlrcpp::Any visitBreakStatement(
TorqueParser::BreakStatementContext* context) override;
antlrcpp::Any visitContinueStatement(
TorqueParser::ContinueStatementContext* context) override;
antlrcpp::Any visitForLoop(TorqueParser::ForLoopContext* context) override;
antlrcpp::Any visitForOfLoop(
TorqueParser::ForOfLoopContext* context) override;
antlrcpp::Any visitDiagnosticStatement(
TorqueParser::DiagnosticStatementContext* context) override;
antlrcpp::Any visitStructDeclaration(
TorqueParser::StructDeclarationContext* context) override;
antlrcpp::Any aggregateResult(antlrcpp::Any aggregate,
const antlrcpp::Any& nextResult) override {
if (aggregate.isNull())
return std::move(const_cast<antlrcpp::Any&>(nextResult));
if (nextResult.isNull()) return aggregate;
UNREACHABLE();
return {};
}
template <class T>
T* RegisterNode(T* node) {
ast_.AddNode(std::unique_ptr<AstNode>(node));
return node;
}
LabelAndTypesVector GetOptionalLabelAndTypeList(
TorqueParser::OptionalLabelListContext* context);
TypeExpression* GetType(TorqueParser::TypeContext* context);
TypeExpression* GetOptionalType(TorqueParser::OptionalTypeContext* context);
std::vector<TypeExpression*> GetTypeVector(
TorqueParser::TypeListContext* type_list);
ParameterList GetOptionalParameterList(
TorqueParser::ParameterListContext* context);
Statement* GetOptionalHelperBody(TorqueParser::HelperBodyContext* context);
void visitSourceFile(SourceFileContext* context);
SourcePosition Pos(antlr4::ParserRuleContext* context);
Ast GetAst() && { return std::move(ast_); }
private:
Ast ast_;
SourceId current_source_file_;
SourceFileContext* source_file_context_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_AST_GENERATOR_H_
This diff is collapsed.
......@@ -85,7 +85,7 @@ const Type* Declarations::GetType(TypeExpression* type_expression) {
} else {
auto* function_type_exp = FunctionTypeExpression::cast(type_expression);
TypeVector argument_types;
for (TypeExpression* type_exp : function_type_exp->parameters.types) {
for (TypeExpression* type_exp : function_type_exp->parameters) {
argument_types.push_back(GetType(type_exp));
}
return TypeOracle::GetFunctionPointerType(
......
This diff is collapsed.
This diff is collapsed.
......@@ -13,8 +13,6 @@
#include "src/torque/types.h"
#include "src/torque/utils.h"
#include "src/torque/TorqueBaseVisitor.h"
namespace v8 {
namespace internal {
namespace torque {
......
......@@ -5,8 +5,6 @@
#ifndef V8_TORQUE_GLOBAL_CONTEXT_H_
#define V8_TORQUE_GLOBAL_CONTEXT_H_
#include "src/torque/TorqueLexer.h"
#include "src/torque/TorqueParser.h"
#include "src/torque/declarable.h"
#include "src/torque/declarations.h"
#include "src/torque/scope.h"
......@@ -38,15 +36,6 @@ class Module {
std::stringstream source_stream_;
};
struct SourceFileContext {
std::string name;
std::unique_ptr<antlr4::ANTLRFileStream> stream;
std::unique_ptr<TorqueLexer> lexer;
std::unique_ptr<antlr4::CommonTokenStream> tokens;
std::unique_ptr<TorqueParser> parser;
TorqueParser::FileContext* file;
};
class GlobalContext {
public:
explicit GlobalContext(Ast ast)
......
......@@ -115,9 +115,6 @@ class ImplementationVisitor : public FileVisitor {
VisitResult Visit(LogicalOrExpression* expr);
VisitResult Visit(LogicalAndExpression* expr);
LocationReference GetLocationReference(
TorqueParser::LocationExpressionContext* locationExpression);
VisitResult Visit(IncrementDecrementExpression* expr);
VisitResult Visit(AssignmentExpression* expr);
VisitResult Visit(StringLiteralExpression* expr);
......
......@@ -5,9 +5,9 @@
#ifndef V8_TORQUE_SCOPE_H_
#define V8_TORQUE_SCOPE_H_
#include <map>
#include <string>
#include "./antlr4-runtime.h"
#include "src/torque/ast.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TORQUE_SOURCE_POSITIONS_H_
#define V8_TORQUE_SOURCE_POSITIONS_H_
#include "src/torque/contextual.h"
namespace v8 {
namespace internal {
namespace torque {
class SourceId {
private:
explicit SourceId(int id) : id_(id) {}
int id_;
friend class SourceFileMap;
};
struct SourcePosition {
SourceId source;
int line;
int column;
};
DECLARE_CONTEXTUAL_VARIABLE(CurrentSourceFile, SourceId)
DECLARE_CONTEXTUAL_VARIABLE(CurrentSourcePosition, SourcePosition)
class SourceFileMap : public ContextualClass<SourceFileMap> {
public:
SourceFileMap() {}
static const std::string& GetSource(SourceId source) {
return Get().sources_[source.id_];
}
static SourceId AddSource(std::string path) {
Get().sources_.push_back(std::move(path));
return SourceId(static_cast<int>(Get().sources_.size()) - 1);
}
private:
std::vector<std::string> sources_;
};
inline std::string PositionAsString(SourcePosition pos) {
return SourceFileMap::GetSource(pos.source) + ":" +
std::to_string(pos.line + 1) + ":" + std::to_string(pos.column + 1);
}
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_SOURCE_POSITIONS_H_
This diff is collapsed.
......@@ -2,6 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Generated from Torque.g4 by ANTLR 4.7.1
#ifndef V8_TORQUE_TORQUE_PARSER_H_
#define V8_TORQUE_TORQUE_PARSER_H_
#include "TorqueBaseVisitor.h"
#include "src/torque/ast.h"
namespace v8 {
namespace internal {
namespace torque {
DECLARE_CONTEXTUAL_VARIABLE(CurrentAst, Ast);
// Adds the parsed input to {CurrentAst}
void ParseTorque(const std::string& input);
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_TORQUE_PARSER_H_
This diff is collapsed.
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fstream>
#include <iostream>
#include "src/torque/declarable.h"
......
......@@ -14,13 +14,71 @@ namespace v8 {
namespace internal {
namespace torque {
std::string StringLiteralUnquote(const std::string& s) {
DCHECK(('"' == s.front() && '"' == s.back()) ||
('\'' == s.front() && '\'' == s.back()));
std::stringstream result;
for (size_t i = 1; i < s.length() - 1; ++i) {
if (s[i] == '\\') {
switch (s[++i]) {
case 'n':
result << '\n';
break;
case 'r':
result << '\r';
break;
case 't':
result << '\t';
break;
case '\'':
case '"':
case '\\':
result << s[i];
break;
default:
UNREACHABLE();
}
} else {
result << s[i];
}
}
return result.str();
}
std::string StringLiteralQuote(const std::string& s) {
std::stringstream result;
result << '"';
for (size_t i = 0; i < s.length() - 1; ++i) {
switch (s[i]) {
case '\n':
result << "\\n";
break;
case '\r':
result << "\\r";
break;
case '\t':
result << "\\t";
break;
case '\'':
case '"':
case '\\':
result << "\\" << s[i];
break;
default:
result << s[i];
}
}
result << '"';
return result.str();
}
std::string CurrentPositionAsString() {
return PositionAsString(CurrentSourcePosition::Get());
}
[[noreturn]] void ReportError(const std::string& error) {
std::cerr << CurrentPositionAsString() << ": Torque error: " << error << "\n";
throw(-1);
std::abort();
}
std::string CamelifyString(const std::string& underscore_string) {
......
This diff is collapsed.
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