Torque: Implement a DSL for CSA

An overview of motivation behind Torque and some of its principles
can be found here: https://bit.ly/2qAI5Ep

Note that there is quite a bit of work left to do in order to get
Torque production-ready for any non-trivial amount of code, but
landing the prototype as-is will allow for much faster iteration.

Bugs will be filed for all of the big-ticket items that are not
landing blockers but called out in this patch as important to fix.

Cq-Include-Trybots: luci.v8.try:v8_linux_nosnap_rel;luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ib07af70966d5133dc57344928885478b9c6b8b73
Reviewed-on: https://chromium-review.googlesource.com/845682
Commit-Queue: Daniel Clifford <danno@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52618}
This commit is contained in:
Daniel Clifford 2018-04-16 02:24:22 -07:00
parent c1401045e3
commit a3353da846
45 changed files with 16927 additions and 19 deletions

436
BUILD.gn
View File

@ -190,7 +190,10 @@ v8_toolset_for_shell = "host"
config("internal_config") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
include_dirs = [ "." ]
include_dirs = [
".",
"$target_gen_dir",
]
if (is_component_build) {
defines = [ "BUILDING_V8_SHARED" ]
@ -200,7 +203,10 @@ config("internal_config") {
config("internal_config_base") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
include_dirs = [ "." ]
include_dirs = [
".",
"$target_gen_dir",
]
}
# This config should be applied to code using the libplatform.
@ -827,6 +833,42 @@ action("postmortem-metadata") {
rebase_path(sources, root_build_dir)
}
action("run_torque") {
visibility = [
":*",
"tools/gcmole/:*",
]
deps = [
":torque($v8_snapshot_toolchain)",
]
script = "tools/run.py"
inputs = [
"src/builtins/base.tq",
"src/builtins/array.tq",
]
outputs = [
"$target_gen_dir/builtin-definitions-from-dsl.h",
"$target_gen_dir/builtins-array-from-dsl-gen.cc",
"$target_gen_dir/builtins-array-from-dsl-gen.h",
"$target_gen_dir/builtins-base-from-dsl-gen.cc",
"$target_gen_dir/builtins-base-from-dsl-gen.h",
]
args = [
"./" + rebase_path(get_label_info(":torque($v8_snapshot_toolchain)",
"root_out_dir") + "/torque",
root_build_dir),
"-o",
rebase_path("$target_gen_dir", root_build_dir),
rebase_path("src/builtins/base.tq", root_build_dir),
rebase_path("src/builtins/array.tq", root_build_dir),
]
}
# Template to generate different V8 snapshots based on different runtime flags.
# Can be invoked with run_mksnapshot(<name>). The target will resolve to
# run_mksnapshot_<name>. If <name> is "default", no file suffixes will be used.
@ -1130,10 +1172,14 @@ v8_source_set("v8_initializers") {
]
deps = [
":run_torque",
":v8_base",
]
sources = [
"$target_gen_dir/builtins-array-from-dsl-gen.cc",
"$target_gen_dir/builtins-base-from-dsl-gen.cc",
### gcmole(all) ###
"src/builtins/builtins-arguments-gen.cc",
"src/builtins/builtins-arguments-gen.h",
@ -1314,6 +1360,7 @@ v8_source_set("v8_base") {
split_count = 2
sources = [
"$target_gen_dir/builtin-definitions-from-dsl.h",
"//base/trace_event/common/trace_event_common.h",
### gcmole(all) ###
@ -2597,6 +2644,7 @@ v8_source_set("v8_base") {
defines = []
deps = [
":run_torque",
":v8_headers",
":v8_libbase",
":v8_libsampler",
@ -2924,6 +2972,382 @@ if (v8_use_snapshot && current_toolchain == v8_snapshot_toolchain) {
}
}
config("antlr-compatibility") {
if (!is_clang && !is_win) {
cflags = [
# Avoid warnings in generated Antlr code
"-Wno-unused-but-set-variable",
]
}
}
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/declarable.h",
"src/torque/declaration-visitor.cc",
"src/torque/declaration-visitor.h",
"src/torque/file-visitor.cc",
"src/torque/file-visitor.h",
"src/torque/global-context.h",
"src/torque/implementation-visitor.cc",
"src/torque/implementation-visitor.h",
"src/torque/scope.cc",
"src/torque/scope.h",
"src/torque/torque.cc",
"src/torque/type-oracle.h",
"src/torque/types.cc",
"src/torque/types.h",
"src/torque/utils.cc",
"src/torque/utils.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRErrorListener.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRFileStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRFileStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRInputStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ANTLRInputStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/BailErrorStrategy.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/BailErrorStrategy.h",
"third_party/antlr4/runtime/Cpp/runtime/src/BaseErrorListener.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/BaseErrorListener.h",
"third_party/antlr4/runtime/Cpp/runtime/src/BufferedTokenStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/BufferedTokenStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/CharStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/CharStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/CommonToken.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/CommonToken.h",
"third_party/antlr4/runtime/Cpp/runtime/src/CommonTokenFactory.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/CommonTokenFactory.h",
"third_party/antlr4/runtime/Cpp/runtime/src/CommonTokenStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/CommonTokenStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ConsoleErrorListener.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ConsoleErrorListener.h",
"third_party/antlr4/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/DefaultErrorStrategy.h",
"third_party/antlr4/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/DiagnosticErrorListener.h",
"third_party/antlr4/runtime/Cpp/runtime/src/Exceptions.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/Exceptions.h",
"third_party/antlr4/runtime/Cpp/runtime/src/FailedPredicateException.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/FailedPredicateException.h",
"third_party/antlr4/runtime/Cpp/runtime/src/InputMismatchException.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/InputMismatchException.h",
"third_party/antlr4/runtime/Cpp/runtime/src/IntStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/IntStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/InterpreterRuleContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/InterpreterRuleContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/Lexer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/Lexer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/LexerInterpreter.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/LexerInterpreter.h",
"third_party/antlr4/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/LexerNoViableAltException.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ListTokenSource.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ListTokenSource.h",
"third_party/antlr4/runtime/Cpp/runtime/src/NoViableAltException.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/NoViableAltException.h",
"third_party/antlr4/runtime/Cpp/runtime/src/Parser.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/Parser.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ParserInterpreter.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ParserInterpreter.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ParserRuleContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ParserRuleContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/ProxyErrorListener.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/ProxyErrorListener.h",
"third_party/antlr4/runtime/Cpp/runtime/src/RecognitionException.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/RecognitionException.h",
"third_party/antlr4/runtime/Cpp/runtime/src/Recognizer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/Recognizer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/RuleContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/RuleContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/RuleContextWithAltNum.h",
"third_party/antlr4/runtime/Cpp/runtime/src/RuntimeMetaData.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/RuntimeMetaData.h",
"third_party/antlr4/runtime/Cpp/runtime/src/Token.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/Token.h",
"third_party/antlr4/runtime/Cpp/runtime/src/TokenFactory.h",
"third_party/antlr4/runtime/Cpp/runtime/src/TokenSource.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/TokenSource.h",
"third_party/antlr4/runtime/Cpp/runtime/src/TokenStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/TokenStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/TokenStreamRewriter.h",
"third_party/antlr4/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/UnbufferedCharStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/UnbufferedTokenStream.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/UnbufferedTokenStream.h",
"third_party/antlr4/runtime/Cpp/runtime/src/Vocabulary.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/Vocabulary.h",
"third_party/antlr4/runtime/Cpp/runtime/src/WritableToken.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/WritableToken.h",
"third_party/antlr4/runtime/Cpp/runtime/src/antlr4-common.h",
"third_party/antlr4/runtime/Cpp/runtime/src/antlr4-runtime.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATN.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATN.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNConfig.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNConfig.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNConfigSet.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNDeserializer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNSerializer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNSimulator.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ATNType.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ActionTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ActionTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/AmbiguityInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/AmbiguityInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/AtomTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/AtomTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BasicState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BasicState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BlockEndState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BlockEndState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BlockStartState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/BlockStartState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/DecisionEventInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/DecisionEventInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/DecisionInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/DecisionInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/DecisionState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/DecisionState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/EpsilonTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ErrorInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ErrorInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LL1Analyzer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerATNConfig.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerActionType.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerChannelAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerCustomAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerModeAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerMoreAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerSkipAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LexerTypeAction.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LoopEndState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/LoopEndState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/NotSetTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ParseInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ParseInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredicateTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredictionContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredictionContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredictionMode.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/PredictionMode.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RangeTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RangeTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RuleStartState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RuleStartState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RuleStopState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RuleStopState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RuleTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/RuleTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/SemanticContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/SemanticContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/SetTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/SetTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/StarBlockStartState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/StarLoopbackState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/TokensStartState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/TokensStartState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/Transition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/Transition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/atn/WildcardTransition.h",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/DFA.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/DFA.h",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/DFASerializer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/DFAState.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/DFAState.h",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/Interval.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/Interval.h",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/IntervalSet.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/IntervalSet.h",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/MurmurHash.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/MurmurHash.h",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/Predicate.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/misc/Predicate.h",
"third_party/antlr4/runtime/Cpp/runtime/src/support/Any.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/support/Any.h",
"third_party/antlr4/runtime/Cpp/runtime/src/support/Arrays.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/support/Arrays.h",
"third_party/antlr4/runtime/Cpp/runtime/src/support/BitSet.h",
"third_party/antlr4/runtime/Cpp/runtime/src/support/CPPUtils.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/support/CPPUtils.h",
"third_party/antlr4/runtime/Cpp/runtime/src/support/Declarations.h",
"third_party/antlr4/runtime/Cpp/runtime/src/support/StringUtils.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/support/StringUtils.h",
"third_party/antlr4/runtime/Cpp/runtime/src/support/guid.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/support/guid.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ErrorNode.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ErrorNode.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTree.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTree.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTreeListener.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTreeListener.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTreeProperty.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/TerminalNode.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/TerminalNode.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/Trees.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/Trees.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/Chunk.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/Chunk.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/TagChunk.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/TextChunk.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPath.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathElement.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathElement.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.h",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.cpp",
"third_party/antlr4/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.h",
]
deps = [
":v8_libbase",
"//build/config:exe_and_shlib_deps",
"//build/win:default_exe_manifest",
]
remove_configs = [
"//build/config/compiler:no_rtti",
"//build/config/compiler:no_exceptions",
]
configs = [
":external_config",
":internal_config_base",
"//build/config/compiler:rtti",
"//build/config/compiler:exceptions",
":antlr-compatibility",
]
}
}
###############################################################################
# Public targets
#
@ -3301,6 +3725,10 @@ v8_source_set("wasm_module_runner") {
"test/common/wasm/wasm-module-runner.h",
]
deps = [
":run_torque",
]
configs = [
":external_config",
":internal_config_base",
@ -3374,6 +3802,10 @@ v8_source_set("lib_wasm_fuzzer_common") {
"test/fuzzer/wasm-fuzzer-common.h",
]
deps = [
":run_torque",
]
configs = [
":external_config",
":internal_config_base",

View File

@ -1653,7 +1653,12 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallFunction(proto, "unshift", Builtins::kArrayUnshift, 1, false);
SimpleInstallFunction(proto, "slice", Builtins::kArrayPrototypeSlice, 2,
false);
SimpleInstallFunction(proto, "splice", Builtins::kArraySplice, 2, false);
if (FLAG_enable_experimental_builtins) {
SimpleInstallFunction(proto, "splice", Builtins::kArraySpliceTorque, 2,
false);
} else {
SimpleInstallFunction(proto, "splice", Builtins::kArraySplice, 2, false);
}
SimpleInstallFunction(proto, "includes", Builtins::kArrayIncludes, 1,
false);
SimpleInstallFunction(proto, "indexOf", Builtins::kArrayIndexOf, 1, false);

297
src/builtins/array.tq Normal file
View File

@ -0,0 +1,297 @@
// 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.
module array {
macro FastArraySplice(
context: Context, args: Arguments, o: Object,
originalLengthNumber: Number, actualStartNumber: Number, insertCount: Smi,
actualDeleteCountNumber: Number): Object
labels Bailout {
let originalLength: Smi = cast<Smi>(originalLengthNumber) otherwise Bailout;
let actualStart: Smi = cast<Smi>(actualStartNumber) otherwise Bailout;
let actualDeleteCount: Smi =
cast<Smi>(actualDeleteCountNumber) otherwise Bailout;
let lengthDelta: Smi = insertCount - actualDeleteCount;
let newLength: Smi = originalLength + lengthDelta;
let a: JSArray = cast<JSArray>(o) otherwise Bailout;
let map: Map = a.map;
if (!IsPrototypeInitialArrayPrototype(context, map)) goto Bailout;
if (IsNoElementsProtectorCellInvalid()) goto Bailout;
if (IsSpeciesProtectorCellInvalid()) goto Bailout;
// Fast path only works on fast elements kind and with writable length.
let elementsKind: int32 = EnsureArrayPushable(map) otherwise Bailout;
if (!IsFastElementsKind(elementsKind)) goto Bailout;
// For now, only support non-double fast elements
if (!IsFastSmiOrTaggedElementsKind(elementsKind)) goto Bailout;
if (IsFastSmiElementsKind(elementsKind)) {
for (let e: Object of args [2: ]) {
if (TaggedIsNotSmi(e)) goto Bailout;
}
}
// Make sure that the length hasn't been changed by side-effect.
let length: Smi = cast<Smi>(a.length) otherwise Bailout;
if (originalLength != length) goto Bailout;
let deletedResult: JSArray =
ExtractFastJSArray(context, a, actualStart, actualDeleteCount);
if (newLength == 0) {
a.elements = kEmptyFixedArray;
a.length = 0;
return deletedResult;
}
let elements: FixedArray = cast<FixedArray>(a.elements) otherwise Bailout;
let elementsMap: Map = elements.map;
// If the source is a COW array or the spliced array is larger then the
// source array, then allocate a new FixedArray to hold the result.
let newElements: FixedArray = elements;
if ((elementsMap == kCOWMap) || (lengthDelta > 0)) {
newElements = ExtractFixedArray(
elements, 0, actualStart, newLength, kAllFixedArrays);
newElements.map = elementsMap;
a.elements = newElements;
}
// Copy over inserted elements.
let k: Smi = actualStart;
if (insertCount > 0) {
for (let e: Object of args [2: ]) {
newElements[k++] = e;
}
}
// Copy over elements after deleted elements.
let count: Smi = length - actualStart - actualDeleteCount;
while (count > 0) {
let e: Object = elements[k - lengthDelta];
newElements[k++] = e;
count--;
}
// Fill rest of spliced FixedArray with the hole, but only if the
// destination FixedArray is the original array's, since otherwise the array
// is pre-filled with holes.
if (elements == newElements) {
let limit: Smi = elements.length;
while (k < limit) {
newElements[k++] = hole;
}
}
// Update the array's length after all the FixedArray shuffling is done.
a.length = newLength;
return deletedResult;
}
// https://tc39.github.io/ecma262/#sec-array.prototype.splice
javascript builtin ArraySpliceTorque(
context: Context, receiver: Object, ...arguments): Object {
// 1. Let O be ? ToObject(this value).
let o: Object = ToObject(context, receiver);
// 2. Let len be ? ToLength(? Get(O, "length")).
let len: Number =
ToLength_Inline(context, GetProperty(context, o, 'length'));
// 3. Let relativeStart be ? ToInteger(start).
let start: Object = arguments[0];
let relativeStart: Number = ToInteger_Inline(context, start);
// 4. If relativeStart < 0, let actualStart be max((len + relativeStart),
// 0);
// else let actualStart be min(relativeStart, len).
let actualStart: Number = relativeStart < 0 ?
max((len + relativeStart), 0) :
min(relativeStart, len);
let insertCount: Smi;
let actualDeleteCount: Number;
// 5. If the Number of actual arguments is 0, then
if (arguments.length == 0) {
// a. Let insertCount be 0.
insertCount = 0;
// b. Let actualDeleteCount be 0.
actualDeleteCount = 0;
// 6. Else if the Number of actual arguments is 1, then
} else if (arguments.length == 1) {
// a. Let insertCount be 0.
insertCount = 0;
// b. Let actualDeleteCount be len - actualStart.
actualDeleteCount = len - actualStart;
// 7. Else,
} else {
// a. Let insertCount be the Number of actual arguments minus 2.
insertCount = convert<Smi>(arguments.length) - 2;
// b. Let dc be ? ToInteger(deleteCount).
let deleteCount: Object = arguments[1];
let dc: Number = ToInteger_Inline(context, deleteCount);
// c. Let actualDeleteCount be min(max(dc, 0), len - actualStart).
actualDeleteCount = min(max(dc, 0), len - actualStart);
}
// 8. If len + insertCount - actualDeleteCount > 2^53-1, throw a
// Bailout exception.
if (len + insertCount - actualDeleteCount > kMaxSafeInteger) {
ThrowRangeError(context, kInvalidArrayLengthMessage);
}
try {
return FastArraySplice(
context, arguments, o, len, actualStart, insertCount,
actualDeleteCount) otherwise Bailout;
}
label Bailout {}
// If the fast case fails, just continue with the slow, correct,
// spec-compliant case.
// 9. Let A be ? ArraySpeciesCreate(O, actualDeleteCount).
let a: Object = ArraySpeciesCreate(context, o, actualDeleteCount);
// 10. Let k be 0.
let k: Number = 0;
// 11. Repeat, while k < actualDeleteCount
while (k < actualDeleteCount) {
// a. Let from be ! ToString(actualStart + k).
let from: String = ToString_Inline(context, actualStart + k);
// b. Let fromPresent be ? HasProperty(O, from).
let fromPresent: Oddball =
HasPropertyObject(o, from, context, kHasProperty);
// c. If fromPresent is true, then
if (fromPresent == true) {
// i. Let fromValue be ? Get(O, from).
let fromValue: Object = GetProperty(context, o, from);
// ii. Perform ? CreateDataPropertyOrThrow(A, ! ToString(k), fromValue).
CreateDataProperty(context, a, ToString_Inline(context, k), fromValue);
}
// d. Increment k by 1.
k = k + 1;
}
// 12. Perform ? Set(A, "length", actualDeleteCount, true).
SetProperty(context, a, 'length', actualDeleteCount, strict);
// 13. Let items be a List whose elements are, in left-to-right order,
// the portion of the actual argument list starting with the third
// argument. The list is empty if fewer than three arguments were
// passed.
// 14. Let itemCount be the Number of elements in items.
let itemCount: Number = insertCount;
// 15. If itemCount < actualDeleteCount, then
if (itemCount < actualDeleteCount) {
// a. Let k be actualStart.
let k: Number = actualStart;
// b. Repeat, while k < (len - actualDeleteCount)
while (k < (len - actualDeleteCount)) {
// i. Let from be ! ToString(k + actualDeleteCount).
let from: String = ToString_Inline(context, k + actualDeleteCount);
// ii. Let to be ! ToString(k + itemCount).
let to: String = ToString_Inline(context, k + itemCount);
// iii. Let fromPresent be ? HasProperty(O, from).
let fromPresent: Oddball =
HasPropertyObject(o, from, context, kHasProperty);
// iv. If fromPresent is true, then
if (fromPresent == true) {
// 1. Let fromValue be ? Get(O, from).
let fromValue: Object = GetProperty(context, o, from);
// 2. Perform ? Set(O, to, fromValue, true).
SetProperty(context, o, to, fromValue, strict);
// v. Else fromPresent is false,
} else {
// 1. Perform ? DeletePropertyOrThrow(O, to).
DeleteProperty(context, o, to, strict);
}
// vi. Increase k by 1.
k = k + 1;
}
// c. Let k be len.
k = len;
// d. Repeat, while k > (len - actualDeleteCount + itemCount)
while (k > (len - actualDeleteCount + itemCount)) {
// i. Perform ? DeletePropertyOrThrow(O, ! ToString(k - 1)).
DeleteProperty(context, o, ToString_Inline(context, k - 1), strict);
// ii. Decrease k by 1.
k = k - 1;
}
// 16. Else if itemCount > actualDeleteCount, then
} else if (itemCount > actualDeleteCount) {
// a. Let k be (len - actualDeleteCount).
let k: Number = len - actualDeleteCount;
// b. Repeat, while k > actualStart
while (k > actualStart) {
// i. Let from be ! ToString(k + actualDeleteCount - 1).
let from: String = ToString_Inline(context, k + actualDeleteCount - 1);
// ii. Let to be ! ToString(k + itemCount - 1).
let to: String = ToString_Inline(context, k + itemCount - 1);
// iii. Let fromPresent be ? HasProperty(O, from).
let fromPresent: Oddball =
HasPropertyObject(o, from, context, kHasProperty);
// iv. If fromPresent is true, then
if (fromPresent == true) {
// 1. Let fromValue be ? Get(O, from).
let fromValue: Object = GetProperty(context, o, from);
// 2. Perform ? Set(O, to, fromValue, true).
SetProperty(context, o, to, fromValue, strict);
// v. Else fromPresent is false,
} else {
// 1. Perform ? DeletePropertyOrThrow(O, to).
DeleteProperty(context, o, to, strict);
}
// vi. Decrease k by 1.
k = k - 1;
}
}
// 17. Let k be actualStart.
k = actualStart;
// 18. Repeat, while items is not empty
// a. Remove the first element from items and let E be the value of that
// element.
if (arguments.length > 2) {
for (let e: Object of arguments [2: ]) {
// b. Perform ? Set(O, ! ToString(k), E, true).
SetProperty(context, o, ToString_Inline(context, k), e, strict);
// c. Increase k by 1.
k = k + 1;
}
}
// 19. Perform ? Set(O, "length", len - actualDeleteCount + itemCount,
// true).
SetProperty(
context, o, 'length', len - actualDeleteCount + itemCount, strict);
return a;
}
}

251
src/builtins/base.tq Normal file
View File

@ -0,0 +1,251 @@
// 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.
type Arguments generates 'CodeStubArguments*';
type void generates 'void';
type never generates 'void';
type Object generates 'TNode<Object>';
type int32 generates 'TNode<Int32T>';
type intptr generates 'TNode<IntPtrT>';
type float64 generates 'TNode<Float64T>';
type bit generates 'TNode<BoolT>';
type int31 extends int32 generates 'TNode<Int32T>';
type Number extends Object generates 'TNode<Number>';
type Smi extends Number generates 'TNode<Smi>';
type HeapObject extends Object generates 'TNode<HeapObject>';
type Context extends HeapObject generates 'TNode<Context>';
type String extends HeapObject generates 'TNode<String>';
type Oddball extends HeapObject generates 'TNode<Oddball>';
type Boolean extends Oddball generates 'TNode<Oddball>';
type JSArray extends Object generates 'TNode<JSArray>';
type Callable extends HeapObject generates 'TNode<Object>';
type JSFunction extends Callable;
type Map extends Object generates 'TNode<Map>';
type FixedArrayBase extends Object generates 'TNode<FixedArrayBase>';
type FixedArray extends FixedArrayBase generates 'TNode<FixedArray>';
type FixedDoubleArray extends FixedArrayBase generates
'TNode<FixedDoubleArray>';
type const_int32 generates 'int32_t';
type const_int31 extends const_int32 generates 'int32_t';
type const_float64 generates 'double';
type InstanceType extends int32 generates 'TNode<Int32T>';
type ElementsKind generates 'ElementsKind';
type LanguageMode extends Smi;
type ExtractFixedArrayFlags;
type CompareOperator;
type MessageTemplate;
type HasPropertyFlag generates 'HasPropertyLookupMode';
const PACKED_SMI_ELEMENTS: ElementsKind = 'PACKED_SMI_ELEMENTS';
const HOLEY_SMI_ELEMENTS: ElementsKind = 'HOLEY_SMI_ELEMENTS';
const PACKED_ELEMENTS: ElementsKind = 'PACKED_ELEMENTS';
const HOLEY_ELEMENTS: ElementsKind = 'HOLEY_ELEMENTS';
const PACKED_DOUBLE_ELEMENTS: ElementsKind = 'PACKED_DOUBLE_ELEMENTS';
const HOLEY_DOUBLE_ELEMENTS: ElementsKind = 'HOLEY_DOUBLE_ELEMENTS';
const kOperationLessThan: CompareOperator = 'Operation::kLessThan';
const kOperationLessThanEqual: CompareOperator = 'Operation::kLessThanEqual';
const kOperationGreaterThan: CompareOperator = 'Operation::kGreaterThan';
const kOperationGreaterThanEqual: CompareOperator =
'Operation::kGreaterThanEqual';
const kAllFixedArrays: ExtractFixedArrayFlags =
'ExtractFixedArrayFlag::kAllFixedArrays';
const kCOWMap: Map = 'LoadRoot(Heap::kFixedCOWArrayMapRootIndex)';
const kEmptyFixedArray: FixedArrayBase =
'UncheckedCast<FixedArrayBase>(LoadRoot(Heap::kEmptyFixedArrayRootIndex))';
const kInvalidArrayLengthMessage: MessageTemplate =
'MessageTemplate::kInvalidArrayLength';
const kHasProperty: HasPropertyFlag = 'kHasProperty';
const kMaxSafeInteger: const_float64 = 'kMaxSafeInteger';
const hole: Object = 'TheHoleConstant()';
const null: Oddball = 'NullConstant()';
const undefined: Oddball = 'UndefinedConstant()';
const true: Boolean = 'TrueConstant()';
const false: Boolean = 'FalseConstant()';
const yes: bit = 'Int32TrueConstant()';
const no: bit = 'Int32FalseConstant()';
const receiver: Object = 'receiver';
const strict: LanguageMode =
'SmiConstant(static_cast<int>(LanguageMode::kStrict))';
const sloppy: LanguageMode =
'SmiConstant(static_cast<int>(LanguageMode::kSloppy))';
extern macro Print(Object);
extern macro Print(String, Object);
extern macro DebugBreak();
extern macro ToInteger_Inline(Context, Object): Number;
extern macro ToLength_Inline(Context, Object): Number;
extern macro ToString_Inline(Context, Object): String;
extern macro GetProperty(Context, Object, Object): Object;
extern macro HasProperty(HeapObject, Object, Context, HasPropertyFlag): Oddball;
extern macro ThrowRangeError(Context, MessageTemplate): never;
extern macro ArraySpeciesCreate(Context, Object, Number): Object;
extern macro EnsureArrayPushable(Map): int32 labels Bailout;
extern builtin ToObject(Context, Object): Object;
extern runtime CreateDataProperty(Context, Object, Object, Object);
extern runtime SetProperty(Context, Object, Object, Object, LanguageMode);
extern runtime DeleteProperty(Context, Object, Object, LanguageMode);
extern runtime StringEqual(Context, String, String): Oddball;
extern operator '==' macro Word32Equal(int32, int32): bit;
extern operator '!=' macro Word32NotEqual(int32, int32): bit;
extern operator '<' macro Int32LessThan(int32, int32): bit;
extern operator '>' macro Int32GreaterThan(int32, int32): bit;
extern operator '<=' macro Int32LessThanOrEqual(int32, int32): bit;
extern operator '>=' macro Int32GreaterThanOrEqual(int32, int32): bit;
extern operator '==' macro WordEqual(Smi, Smi): bit;
extern operator '!=' macro WordNotEqual(Smi, Smi): bit;
extern operator '<' macro SmiLessThan(Smi, Smi): bit;
extern operator '<=' macro SmiLessThanOrEqual(Smi, Smi): bit;
extern operator '>' macro SmiGreaterThan(Smi, Smi): bit;
extern operator '>=' macro SmiGreaterThanOrEqual(Smi, Smi): bit;
extern macro SmiAbove(Smi, Smi): bit;
extern operator '==' macro WordEqual(intptr, intptr): bit;
extern operator '!=' macro WordNotEqual(intptr, intptr): bit;
extern operator '<' macro IntPtrLessThan(intptr, intptr): bit;
extern operator '>' macro IntPtrGreaterThan(intptr, intptr): bit;
extern operator '<=' macro IntPtrLessThanOrEqual(intptr, intptr): bit;
extern operator '>=' macro IntPtrGreaterThanOrEqual(intptr, intptr): bit;
extern operator
'<' macro BranchIfNumberLessThan(Number, Number): never labels True, False;
extern operator
'<=' macro BranchIfNumberLessThanOrEqual(Number, Number): never labels True,
False;
extern operator
'>' macro BranchIfNumberGreaterThan(Number, Number): never labels True, False;
extern operator '>=' macro BranchIfNumberGreaterThanOrEqual(Number, Number):
never labels True,
False;
extern operator '==' macro WordEqual(Object, Object): bit;
extern operator '!=' macro WordNotEqual(Object, Object): bit;
extern operator '+' macro SmiAdd(Smi, Smi): Smi;
extern operator '-' macro SmiSub(Smi, Smi): Smi;
extern operator '+' macro IntPtrAdd(intptr, intptr): intptr;
extern operator '-' macro IntPtrSub(intptr, intptr): intptr;
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 operator '!' macro Word32BinaryNot(bit): bit;
extern operator '.map' macro LoadMap(Object): Map;
extern operator '.map=' macro StoreMap(Object, Map);
extern operator '.instanceType' macro LoadInstanceType(Object): InstanceType;
extern operator '.length' macro LoadStringLengthAsWord(String): intptr;
extern operator '.length' macro GetArgumentsLength(Arguments): intptr;
extern operator '[]' macro GetArgumentValue(Arguments, intptr): Object;
extern operator '[]' macro GetArgumentValue(Arguments, Smi): Object;
extern operator 'is<Smi>' macro TaggedIsSmi(Object): bit;
extern operator 'isnt<Smi>' macro TaggedIsNotSmi(Object): bit;
extern operator
'cast<>' macro TaggedToHeapObject(Object): HeapObject labels CastError;
extern operator 'cast<>' macro TaggedToSmi(Object): Smi labels CastError;
extern operator
'cast<>' macro TaggedToJSArray(Object): JSArray labels CastError;
extern operator
'cast<>' macro TaggedToCallable(Object): Callable labels CastError;
extern operator 'cast<>' macro ConvertFixedArrayBaseToFixedArray(
FixedArrayBase): FixedArray labels CastError;
extern operator 'cast<>' macro ConvertFixedArrayBaseToFixedDoubleArray(
FixedArrayBase): FixedDoubleArray labels CastError;
extern implicit operator
'convert<>' macro AllocateHeapNumberWithValue(const_float64): Number;
extern implicit operator 'convert<>' macro IntPtrConstant(const_int31): intptr;
extern implicit operator 'convert<>' macro IntPtrConstant(const_int32): intptr;
extern implicit operator 'convert<>' macro Int32Constant(const_int31): int32;
extern implicit operator 'convert<>' macro Int32Constant(const_int32): int32;
extern implicit operator 'convert<>' macro SmiConstant(const_int31): Smi;
extern implicit operator 'convert<>' macro NumberConstant(const_int31): Number;
extern implicit operator 'convert<>' macro NumberConstant(const_int32): Number;
extern operator 'convert<>' macro ChangeInt32ToTagged(int32): Number;
extern operator 'convert<>' macro TruncateWordToWord32(intptr): int32;
extern operator 'convert<>' macro SmiTag(intptr): Smi;
extern operator 'convert<>' macro SmiUntag(Smi): intptr;
extern macro BranchIfFastJSArray(Object, Context): never labels True, False;
extern macro BranchIfNotFastJSArray(Object, Context): never labels True, False;
extern macro IsPrototypeInitialArrayPrototype(Context, Map): bit;
extern macro IsNoElementsProtectorCellInvalid(): bit;
extern macro IsSpeciesProtectorCellInvalid(): bit;
extern operator '.elements_kind' macro LoadMapElementsKind(Map): int32;
extern operator '.elements' macro LoadElements(Object): FixedArrayBase;
extern operator '.elements=' macro StoreElements(Object, FixedArrayBase);
extern operator '.length' macro LoadJSArrayLength(JSArray): Number;
extern operator '.length=' macro StoreJSArrayLength(JSArray, Smi);
extern operator '.length' macro LoadFixedArrayBaseLength(FixedArrayBase): Smi;
extern operator '[]' macro LoadFixedArrayElement(FixedArray, intptr): Object;
extern operator '[]' macro LoadFixedArrayElement(FixedArray, Smi): Object;
extern operator
'[]=' macro StoreFixedArrayElement(FixedArray, intptr, Object): void;
extern operator
'[]=' macro StoreFixedArrayElementSmi(FixedArray, Smi, Object): void;
extern macro IsFastElementsKind(int32): bit;
extern macro IsFastSmiOrTaggedElementsKind(int32): bit;
extern macro IsFastSmiElementsKind(int32): bit;
extern macro AllocateFixedArray(ElementsKind, Smi): FixedArray;
extern macro AllocateFixedArray(ElementsKind, Smi, Map): FixedArray;
extern macro CopyFixedArrayElements(
ElementsKind, FixedArray, ElementsKind, FixedArray, intptr, intptr,
intptr): void;
extern macro CopyFixedArrayElements(
ElementsKind, FixedArray, ElementsKind, FixedArray, Smi, Smi, Smi): void;
extern macro AllocateJSArray(ElementsKind, Map, intptr, Smi): JSArray;
extern macro AllocateJSArray(ElementsKind, Map, Smi, Smi): JSArray;
extern macro Call(Context, Callable, Object, ...): Object;
extern macro ExtractFixedArray(
FixedArray, Smi, Smi, Smi, ExtractFixedArrayFlags): FixedArray;
extern builtin ExtractFastJSArray(Context, JSArray, Smi, Smi): JSArray;
macro HasPropertyObject(
o: Object, p: Object, c: Context, f: HasPropertyFlag): Oddball {
try {
return HasProperty(cast<HeapObject>(o) otherwise CastError, p, c, f);
}
label CastError {
return false;
}
}

View File

@ -20,7 +20,7 @@ using Node = compiler::Node;
ArrayBuiltinsAssembler::ArrayBuiltinsAssembler(
compiler::CodeAssemblerState* state)
: CodeStubAssembler(state),
: BaseBuiltinsFromDSLAssembler(state),
k_(this, MachineRepresentation::kTagged),
a_(this, MachineRepresentation::kTagged),
to_(this, MachineRepresentation::kTagged, SmiConstant(0)),

View File

@ -5,12 +5,12 @@
#ifndef V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
#define V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
#include "src/code-stub-assembler.h"
#include "./builtins-base-from-dsl-gen.h"
namespace v8 {
namespace internal {
class ArrayBuiltinsAssembler : public CodeStubAssembler {
class ArrayBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
public:
explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state);

View File

@ -5,6 +5,9 @@
#ifndef V8_BUILTINS_BUILTINS_DEFINITIONS_H_
#define V8_BUILTINS_BUILTINS_DEFINITIONS_H_
// include generated header
#include "builtin-definitions-from-dsl.h" //NOLINT
namespace v8 {
namespace internal {
@ -1257,6 +1260,7 @@ namespace internal {
#ifdef V8_INTL_SUPPORT
#define BUILTIN_LIST(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
BUILTIN_LIST_BASE(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
\
TFS(StringToLowerCaseIntl, kString) \
/* ES #sec-string.prototype.tolowercase */ \
@ -1268,18 +1272,19 @@ namespace internal {
/* ecma402 #sec-intl.numberformat.prototype.formattoparts */ \
CPP(NumberFormatPrototypeFormatToParts)
#else
#define BUILTIN_LIST(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
BUILTIN_LIST_BASE(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
\
/* no-op fallback version */ \
CPP(StringPrototypeNormalize) \
/* same as toLowercase; fallback version */ \
CPP(StringPrototypeToLocaleLowerCase) \
/* same as toUppercase; fallback version */ \
CPP(StringPrototypeToLocaleUpperCase) \
/* (obsolete) Unibrow version */ \
CPP(StringPrototypeToLowerCase) \
/* (obsolete) Unibrow version */ \
#define BUILTIN_LIST(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
BUILTIN_LIST_BASE(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
\
/* no-op fallback version */ \
CPP(StringPrototypeNormalize) \
/* same as toLowercase; fallback version */ \
CPP(StringPrototypeToLocaleLowerCase) \
/* same as toUppercase; fallback version */ \
CPP(StringPrototypeToLocaleUpperCase) \
/* (obsolete) Unibrow version */ \
CPP(StringPrototypeToLowerCase) \
/* (obsolete) Unibrow version */ \
CPP(StringPrototypeToUpperCase)
#endif // V8_INTL_SUPPORT

278
src/torque/Torque.g4 Normal file
View File

@ -0,0 +1,278 @@
// 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';
IMPLICIT: 'implicit';
DEFERRED: 'deferred';
IF: 'if';
CAST_KEYWORD: 'cast';
CONVERT_KEYWORD: 'convert';
FOR: 'for';
WHILE: 'while';
RETURN: 'return';
CONTINUE: 'continue';
BREAK: 'break';
GOTO: 'goto';
OTHERWISE: 'otherwise';
TRY: 'try';
CATCH: 'catch';
LABEL: 'label';
LABELS: 'labels';
TAIL: 'tail';
ISNT: 'isnt';
IS: 'is';
LET: 'let';
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 : '\\' ( '\'' | '\\' );
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
: DECIMAL_INTEGER_LITERAL '.' DECIMAL_DIGIT* EXPONENT_PART?
| '.' DECIMAL_DIGIT+ EXPONENT_PART?
| DECIMAL_INTEGER_LITERAL EXPONENT_PART?
;
type : IDENTIFIER;
typeList : '(' type? (',' type)* ')';
typeListMaybeVarArgs: '(' type? (',' type)* (',' VARARGS)? ')'
| '(' VARARGS ')';
labelParameter: IDENTIFIER typeList?;
optionalType: (':' type)?;
optionalLabelList: (LABELS labelParameter (',' labelParameter)*)?;
poptionalOtherwise: (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
| locationExpression '[' expression ']';
incrementDecrement
: INCREMENT locationExpression
| DECREMENT locationExpression
| locationExpression op=INCREMENT
| locationExpression op=DECREMENT
;
assignment
: incrementDecrement
| locationExpression ((ASSIGNMENT | ASSIGNMENT_OPERATOR) expression)?;
assignmentExpression
: primaryExpression
| assignment;
primaryExpression
: helperCall
| DECIMAL_LITERAL
| STRING_LITERAL
| CAST_KEYWORD '<' type '>' '(' expression ')' OTHERWISE IDENTIFIER
| CONVERT_KEYWORD '<' type '>' '(' expression ')'
| ('(' 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) argumentList optionalOtherwise;
labelReference: IDENTIFIER;
variableDeclaration: LET IDENTIFIER ':' type;
variableDeclarationWithInitialization: variableDeclaration ('=' expression)?;
helperCallStatement: (TAIL)? helperCall;
expressionStatement: assignment;
ifStatement: IF '(' expression ')' statementBlock ('else' statementBlock)?;
whileLoop: WHILE '(' expression ')' statementBlock;
returnStatement: RETURN expression?;
breakStatement: BREAK;
continueStatement: CONTINUE;
gotoStatement: GOTO labelReference argumentList?;
handlerWithStatement: (CATCH IDENTIFIER | LABEL labelDeclaration) statementBlock;
tryCatch: TRY statementBlock handlerWithStatement+;
statement : variableDeclarationWithInitialization ';'
| helperCallStatement ';'
| expressionStatement ';'
| returnStatement ';'
| breakStatement ';'
| continueStatement ';'
| gotoStatement ';'
| ifStatement
| whileLoop
| forOfLoop
| forLoop
| tryCatch
;
statementList : statement*;
statementScope : DEFERRED? '{' statementList '}';
statementBlock
: statement
| statementScope;
helperBody : statementScope;
generatesDeclaration: 'generates' STRING_LITERAL;
extendsDeclaration: 'extends' IDENTIFIER;
typeDeclaration : 'type' IDENTIFIER extendsDeclaration? generatesDeclaration? ';';
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;
constDeclaration : 'const' IDENTIFIER ':' type '=' STRING_LITERAL ';';
declaration
: typeDeclaration
| builtinDeclaration
| macroDeclaration
| externalMacro
| externalBuiltin
| externalRuntime
| constDeclaration;
moduleDeclaration : MODULE IDENTIFIER '{' declaration* '}';
file: (moduleDeclaration | declaration)*;

View File

@ -0,0 +1,7 @@
// 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"

View File

@ -0,0 +1,311 @@
// 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_TORQUEBASELISTENER_H_
#define V8_TORQUE_TORQUEBASELISTENER_H_
// Generated from Torque.g4 by ANTLR 4.7.1
#pragma once
#include "./antlr4-runtime.h"
#include "TorqueListener.h"
/**
* This class provides an empty implementation of TorqueListener,
* which can be extended to create a listener which only needs to handle a
* subset of the available methods.
*/
class TorqueBaseListener : public TorqueListener {
public:
void enterType(TorqueParser::TypeContext* /*ctx*/) override {}
void exitType(TorqueParser::TypeContext* /*ctx*/) override {}
void enterTypeList(TorqueParser::TypeListContext* /*ctx*/) override {}
void exitTypeList(TorqueParser::TypeListContext* /*ctx*/) override {}
void enterTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* /*ctx*/) override {}
void exitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* /*ctx*/) override {}
void enterLabelParameter(
TorqueParser::LabelParameterContext* /*ctx*/) override {}
void exitLabelParameter(
TorqueParser::LabelParameterContext* /*ctx*/) override {}
void enterOptionalType(TorqueParser::OptionalTypeContext* /*ctx*/) override {}
void exitOptionalType(TorqueParser::OptionalTypeContext* /*ctx*/) override {}
void enterOptionalLabelList(
TorqueParser::OptionalLabelListContext* /*ctx*/) override {}
void exitOptionalLabelList(
TorqueParser::OptionalLabelListContext* /*ctx*/) override {}
void enterOptionalOtherwise(
TorqueParser::OptionalOtherwiseContext* /*ctx*/) override {}
void exitOptionalOtherwise(
TorqueParser::OptionalOtherwiseContext* /*ctx*/) override {}
void enterParameter(TorqueParser::ParameterContext* /*ctx*/) override {}
void exitParameter(TorqueParser::ParameterContext* /*ctx*/) override {}
void enterParameterList(
TorqueParser::ParameterListContext* /*ctx*/) override {}
void exitParameterList(TorqueParser::ParameterListContext* /*ctx*/) override {
}
void enterLabelDeclaration(
TorqueParser::LabelDeclarationContext* /*ctx*/) override {}
void exitLabelDeclaration(
TorqueParser::LabelDeclarationContext* /*ctx*/) override {}
void enterExpression(TorqueParser::ExpressionContext* /*ctx*/) override {}
void exitExpression(TorqueParser::ExpressionContext* /*ctx*/) override {}
void enterConditionalExpression(
TorqueParser::ConditionalExpressionContext* /*ctx*/) override {}
void exitConditionalExpression(
TorqueParser::ConditionalExpressionContext* /*ctx*/) override {}
void enterLogicalORExpression(
TorqueParser::LogicalORExpressionContext* /*ctx*/) override {}
void exitLogicalORExpression(
TorqueParser::LogicalORExpressionContext* /*ctx*/) override {}
void enterLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* /*ctx*/) override {}
void exitLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* /*ctx*/) override {}
void enterBitwiseExpression(
TorqueParser::BitwiseExpressionContext* /*ctx*/) override {}
void exitBitwiseExpression(
TorqueParser::BitwiseExpressionContext* /*ctx*/) override {}
void enterEqualityExpression(
TorqueParser::EqualityExpressionContext* /*ctx*/) override {}
void exitEqualityExpression(
TorqueParser::EqualityExpressionContext* /*ctx*/) override {}
void enterRelationalExpression(
TorqueParser::RelationalExpressionContext* /*ctx*/) override {}
void exitRelationalExpression(
TorqueParser::RelationalExpressionContext* /*ctx*/) override {}
void enterShiftExpression(
TorqueParser::ShiftExpressionContext* /*ctx*/) override {}
void exitShiftExpression(
TorqueParser::ShiftExpressionContext* /*ctx*/) override {}
void enterAdditiveExpression(
TorqueParser::AdditiveExpressionContext* /*ctx*/) override {}
void exitAdditiveExpression(
TorqueParser::AdditiveExpressionContext* /*ctx*/) override {}
void enterMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* /*ctx*/) override {}
void exitMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* /*ctx*/) override {}
void enterUnaryExpression(
TorqueParser::UnaryExpressionContext* /*ctx*/) override {}
void exitUnaryExpression(
TorqueParser::UnaryExpressionContext* /*ctx*/) override {}
void enterLocationExpression(
TorqueParser::LocationExpressionContext* /*ctx*/) override {}
void exitLocationExpression(
TorqueParser::LocationExpressionContext* /*ctx*/) override {}
void enterIncrementDecrement(
TorqueParser::IncrementDecrementContext* /*ctx*/) override {}
void exitIncrementDecrement(
TorqueParser::IncrementDecrementContext* /*ctx*/) override {}
void enterAssignment(TorqueParser::AssignmentContext* /*ctx*/) override {}
void exitAssignment(TorqueParser::AssignmentContext* /*ctx*/) override {}
void enterAssignmentExpression(
TorqueParser::AssignmentExpressionContext* /*ctx*/) override {}
void exitAssignmentExpression(
TorqueParser::AssignmentExpressionContext* /*ctx*/) override {}
void enterPrimaryExpression(
TorqueParser::PrimaryExpressionContext* /*ctx*/) override {}
void exitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* /*ctx*/) override {}
void enterForInitialization(
TorqueParser::ForInitializationContext* /*ctx*/) override {}
void exitForInitialization(
TorqueParser::ForInitializationContext* /*ctx*/) override {}
void enterForLoop(TorqueParser::ForLoopContext* /*ctx*/) override {}
void exitForLoop(TorqueParser::ForLoopContext* /*ctx*/) override {}
void enterRangeSpecifier(
TorqueParser::RangeSpecifierContext* /*ctx*/) override {}
void exitRangeSpecifier(
TorqueParser::RangeSpecifierContext* /*ctx*/) override {}
void enterForOfRange(TorqueParser::ForOfRangeContext* /*ctx*/) override {}
void exitForOfRange(TorqueParser::ForOfRangeContext* /*ctx*/) override {}
void enterForOfLoop(TorqueParser::ForOfLoopContext* /*ctx*/) override {}
void exitForOfLoop(TorqueParser::ForOfLoopContext* /*ctx*/) override {}
void enterArgument(TorqueParser::ArgumentContext* /*ctx*/) override {}
void exitArgument(TorqueParser::ArgumentContext* /*ctx*/) override {}
void enterArgumentList(TorqueParser::ArgumentListContext* /*ctx*/) override {}
void exitArgumentList(TorqueParser::ArgumentListContext* /*ctx*/) override {}
void enterHelperCall(TorqueParser::HelperCallContext* /*ctx*/) override {}
void exitHelperCall(TorqueParser::HelperCallContext* /*ctx*/) override {}
void enterLabelReference(
TorqueParser::LabelReferenceContext* /*ctx*/) override {}
void exitLabelReference(
TorqueParser::LabelReferenceContext* /*ctx*/) override {}
void enterVariableDeclaration(
TorqueParser::VariableDeclarationContext* /*ctx*/) override {}
void exitVariableDeclaration(
TorqueParser::VariableDeclarationContext* /*ctx*/) override {}
void enterVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* /*ctx*/)
override {}
void exitVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* /*ctx*/)
override {}
void enterHelperCallStatement(
TorqueParser::HelperCallStatementContext* /*ctx*/) override {}
void exitHelperCallStatement(
TorqueParser::HelperCallStatementContext* /*ctx*/) override {}
void enterExpressionStatement(
TorqueParser::ExpressionStatementContext* /*ctx*/) override {}
void exitExpressionStatement(
TorqueParser::ExpressionStatementContext* /*ctx*/) override {}
void enterIfStatement(TorqueParser::IfStatementContext* /*ctx*/) override {}
void exitIfStatement(TorqueParser::IfStatementContext* /*ctx*/) override {}
void enterWhileLoop(TorqueParser::WhileLoopContext* /*ctx*/) override {}
void exitWhileLoop(TorqueParser::WhileLoopContext* /*ctx*/) override {}
void enterReturnStatement(
TorqueParser::ReturnStatementContext* /*ctx*/) override {}
void exitReturnStatement(
TorqueParser::ReturnStatementContext* /*ctx*/) override {}
void enterBreakStatement(
TorqueParser::BreakStatementContext* /*ctx*/) override {}
void exitBreakStatement(
TorqueParser::BreakStatementContext* /*ctx*/) override {}
void enterContinueStatement(
TorqueParser::ContinueStatementContext* /*ctx*/) override {}
void exitContinueStatement(
TorqueParser::ContinueStatementContext* /*ctx*/) override {}
void enterGotoStatement(
TorqueParser::GotoStatementContext* /*ctx*/) override {}
void exitGotoStatement(TorqueParser::GotoStatementContext* /*ctx*/) override {
}
void enterHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* /*ctx*/) override {}
void exitHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* /*ctx*/) override {}
void enterTryCatch(TorqueParser::TryCatchContext* /*ctx*/) override {}
void exitTryCatch(TorqueParser::TryCatchContext* /*ctx*/) override {}
void enterStatement(TorqueParser::StatementContext* /*ctx*/) override {}
void exitStatement(TorqueParser::StatementContext* /*ctx*/) override {}
void enterStatementList(
TorqueParser::StatementListContext* /*ctx*/) override {}
void exitStatementList(TorqueParser::StatementListContext* /*ctx*/) override {
}
void enterStatementScope(
TorqueParser::StatementScopeContext* /*ctx*/) override {}
void exitStatementScope(
TorqueParser::StatementScopeContext* /*ctx*/) override {}
void enterStatementBlock(
TorqueParser::StatementBlockContext* /*ctx*/) override {}
void exitStatementBlock(
TorqueParser::StatementBlockContext* /*ctx*/) override {}
void enterHelperBody(TorqueParser::HelperBodyContext* /*ctx*/) override {}
void exitHelperBody(TorqueParser::HelperBodyContext* /*ctx*/) override {}
void enterGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* /*ctx*/) override {}
void exitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* /*ctx*/) override {}
void enterExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* /*ctx*/) override {}
void exitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* /*ctx*/) override {}
void enterTypeDeclaration(
TorqueParser::TypeDeclarationContext* /*ctx*/) override {}
void exitTypeDeclaration(
TorqueParser::TypeDeclarationContext* /*ctx*/) override {}
void enterExternalBuiltin(
TorqueParser::ExternalBuiltinContext* /*ctx*/) override {}
void exitExternalBuiltin(
TorqueParser::ExternalBuiltinContext* /*ctx*/) override {}
void enterExternalMacro(
TorqueParser::ExternalMacroContext* /*ctx*/) override {}
void exitExternalMacro(TorqueParser::ExternalMacroContext* /*ctx*/) override {
}
void enterExternalRuntime(
TorqueParser::ExternalRuntimeContext* /*ctx*/) override {}
void exitExternalRuntime(
TorqueParser::ExternalRuntimeContext* /*ctx*/) override {}
void enterBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* /*ctx*/) override {}
void exitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* /*ctx*/) override {}
void enterMacroDeclaration(
TorqueParser::MacroDeclarationContext* /*ctx*/) override {}
void exitMacroDeclaration(
TorqueParser::MacroDeclarationContext* /*ctx*/) override {}
void enterConstDeclaration(
TorqueParser::ConstDeclarationContext* /*ctx*/) override {}
void exitConstDeclaration(
TorqueParser::ConstDeclarationContext* /*ctx*/) override {}
void enterDeclaration(TorqueParser::DeclarationContext* /*ctx*/) override {}
void exitDeclaration(TorqueParser::DeclarationContext* /*ctx*/) override {}
void enterModuleDeclaration(
TorqueParser::ModuleDeclarationContext* /*ctx*/) override {}
void exitModuleDeclaration(
TorqueParser::ModuleDeclarationContext* /*ctx*/) override {}
void enterFile(TorqueParser::FileContext* /*ctx*/) override {}
void exitFile(TorqueParser::FileContext* /*ctx*/) override {}
void enterEveryRule(antlr4::ParserRuleContext* /*ctx*/) override {}
void exitEveryRule(antlr4::ParserRuleContext* /*ctx*/) override {}
void visitTerminal(antlr4::tree::TerminalNode* /*node*/) override {}
void visitErrorNode(antlr4::tree::ErrorNode* /*node*/) override {}
};
#endif // V8_TORQUE_TORQUEBASELISTENER_H_

View File

@ -0,0 +1,7 @@
// 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 "TorqueBaseVisitor.h"

View File

@ -0,0 +1,328 @@
// 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_TORQUEBASEVISITOR_H_
#define V8_TORQUE_TORQUEBASEVISITOR_H_
// Generated from Torque.g4 by ANTLR 4.7.1
#pragma once
#include "./antlr4-runtime.h"
#include "TorqueVisitor.h"
/**
* This class provides an empty implementation of TorqueVisitor, which can be
* extended to create a visitor which only needs to handle a subset of the
* available methods.
*/
class TorqueBaseVisitor : public TorqueVisitor {
public:
antlrcpp::Any visitType(TorqueParser::TypeContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitTypeList(TorqueParser::TypeListContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitLabelParameter(
TorqueParser::LabelParameterContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitOptionalType(
TorqueParser::OptionalTypeContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitOptionalLabelList(
TorqueParser::OptionalLabelListContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitOptionalOtherwise(
TorqueParser::OptionalOtherwiseContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitParameter(TorqueParser::ParameterContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitParameterList(
TorqueParser::ParameterListContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitLabelDeclaration(
TorqueParser::LabelDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitExpression(TorqueParser::ExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitConditionalExpression(
TorqueParser::ConditionalExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitLogicalORExpression(
TorqueParser::LogicalORExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitBitwiseExpression(
TorqueParser::BitwiseExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitEqualityExpression(
TorqueParser::EqualityExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitRelationalExpression(
TorqueParser::RelationalExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitShiftExpression(
TorqueParser::ShiftExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitAdditiveExpression(
TorqueParser::AdditiveExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitUnaryExpression(
TorqueParser::UnaryExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitLocationExpression(
TorqueParser::LocationExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitIncrementDecrement(
TorqueParser::IncrementDecrementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitAssignment(TorqueParser::AssignmentContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitAssignmentExpression(
TorqueParser::AssignmentExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitForInitialization(
TorqueParser::ForInitializationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitForLoop(TorqueParser::ForLoopContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitRangeSpecifier(
TorqueParser::RangeSpecifierContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitForOfRange(TorqueParser::ForOfRangeContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitForOfLoop(TorqueParser::ForOfLoopContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitArgument(TorqueParser::ArgumentContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitArgumentList(
TorqueParser::ArgumentListContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitHelperCall(TorqueParser::HelperCallContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitLabelReference(
TorqueParser::LabelReferenceContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitVariableDeclaration(
TorqueParser::VariableDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* ctx)
override {
return visitChildren(ctx);
}
antlrcpp::Any visitHelperCallStatement(
TorqueParser::HelperCallStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitExpressionStatement(
TorqueParser::ExpressionStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitIfStatement(
TorqueParser::IfStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitWhileLoop(TorqueParser::WhileLoopContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitReturnStatement(
TorqueParser::ReturnStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitBreakStatement(
TorqueParser::BreakStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitContinueStatement(
TorqueParser::ContinueStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitGotoStatement(
TorqueParser::GotoStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitTryCatch(TorqueParser::TryCatchContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitStatement(TorqueParser::StatementContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitStatementList(
TorqueParser::StatementListContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitStatementScope(
TorqueParser::StatementScopeContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitStatementBlock(
TorqueParser::StatementBlockContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitHelperBody(TorqueParser::HelperBodyContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitExternalBuiltin(
TorqueParser::ExternalBuiltinContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitExternalMacro(
TorqueParser::ExternalMacroContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitExternalRuntime(
TorqueParser::ExternalRuntimeContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitDeclaration(
TorqueParser::DeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitModuleDeclaration(
TorqueParser::ModuleDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitFile(TorqueParser::FileContext* ctx) override {
return visitChildren(ctx);
}
};
#endif // V8_TORQUE_TORQUEBASEVISITOR_H_

925
src/torque/TorqueLexer.cpp Normal file
View File

@ -0,0 +1,925 @@
// 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 "TorqueLexer.h"
using namespace antlr4;
TorqueLexer::TorqueLexer(CharStream* input) : Lexer(input) {
_interpreter = new atn::LexerATNSimulator(this, _atn, _decisionToDFA,
_sharedContextCache);
}
TorqueLexer::~TorqueLexer() { delete _interpreter; }
std::string TorqueLexer::getGrammarFileName() const { return "Torque.g4"; }
const std::vector<std::string>& TorqueLexer::getRuleNames() const {
return _ruleNames;
}
const std::vector<std::string>& TorqueLexer::getChannelNames() const {
return _channelNames;
}
const std::vector<std::string>& TorqueLexer::getModeNames() const {
return _modeNames;
}
const std::vector<std::string>& TorqueLexer::getTokenNames() const {
return _tokenNames;
}
dfa::Vocabulary& TorqueLexer::getVocabulary() const { return _vocabulary; }
const std::vector<uint16_t> TorqueLexer::getSerializedATN() const {
return _serializedATN;
}
const atn::ATN& TorqueLexer::getATN() const { return _atn; }
// Static vars and initialization.
std::vector<dfa::DFA> TorqueLexer::_decisionToDFA;
atn::PredictionContextCache TorqueLexer::_sharedContextCache;
// We own the ATN which in turn owns the ATN states.
atn::ATN TorqueLexer::_atn;
std::vector<uint16_t> TorqueLexer::_serializedATN;
std::vector<std::string> TorqueLexer::_ruleNames = {u8"T__0",
u8"T__1",
u8"T__2",
u8"T__3",
u8"T__4",
u8"T__5",
u8"T__6",
u8"T__7",
u8"T__8",
u8"T__9",
u8"T__10",
u8"T__11",
u8"T__12",
u8"T__13",
u8"T__14",
u8"T__15",
u8"T__16",
u8"T__17",
u8"T__18",
u8"T__19",
u8"T__20",
u8"MACRO",
u8"BUILTIN",
u8"RUNTIME",
u8"MODULE",
u8"JAVASCRIPT",
u8"IMPLICIT",
u8"DEFERRED",
u8"IF",
u8"CAST_KEYWORD",
u8"CONVERT_KEYWORD",
u8"FOR",
u8"WHILE",
u8"RETURN",
u8"CONTINUE",
u8"BREAK",
u8"GOTO",
u8"OTHERWISE",
u8"TRY",
u8"CATCH",
u8"LABEL",
u8"LABELS",
u8"TAIL",
u8"ISNT",
u8"IS",
u8"LET",
u8"ASSIGNMENT",
u8"ASSIGNMENT_OPERATOR",
u8"EQUAL",
u8"PLUS",
u8"MINUS",
u8"MULTIPLY",
u8"DIVIDE",
u8"MODULO",
u8"BIT_OR",
u8"BIT_AND",
u8"BIT_NOT",
u8"MAX",
u8"MIN",
u8"NOT_EQUAL",
u8"LESS_THAN",
u8"LESS_THAN_EQUAL",
u8"GREATER_THAN",
u8"GREATER_THAN_EQUAL",
u8"SHIFT_LEFT",
u8"SHIFT_RIGHT",
u8"SHIFT_RIGHT_ARITHMETIC",
u8"VARARGS",
u8"EQUALITY_OPERATOR",
u8"INCREMENT",
u8"DECREMENT",
u8"NOT",
u8"STRING_LITERAL",
u8"ESCAPE",
u8"IDENTIFIER",
u8"WS",
u8"BLOCK_COMMENT",
u8"LINE_COMMENT",
u8"DECIMAL_DIGIT",
u8"DECIMAL_INTEGER_LITERAL",
u8"EXPONENT_PART",
u8"DECIMAL_LITERAL"};
std::vector<std::string> TorqueLexer::_channelNames = {"DEFAULT_TOKEN_CHANNEL",
"HIDDEN"};
std::vector<std::string> TorqueLexer::_modeNames = {u8"DEFAULT_MODE"};
std::vector<std::string> TorqueLexer::_literalNames = {"",
u8"'('",
u8"','",
u8"')'",
u8"':'",
u8"'?'",
u8"'||'",
u8"'&&'",
u8"'.'",
u8"'['",
u8"']'",
u8"';'",
u8"'of'",
u8"'else'",
u8"'{'",
u8"'}'",
u8"'generates'",
u8"'extends'",
u8"'type'",
u8"'extern'",
u8"'operator'",
u8"'const'",
u8"'macro'",
u8"'builtin'",
u8"'runtime'",
u8"'module'",
u8"'javascript'",
u8"'implicit'",
u8"'deferred'",
u8"'if'",
u8"'cast'",
u8"'convert'",
u8"'for'",
u8"'while'",
u8"'return'",
u8"'continue'",
u8"'break'",
u8"'goto'",
u8"'otherwise'",
u8"'try'",
u8"'catch'",
u8"'label'",
u8"'labels'",
u8"'tail'",
u8"'isnt'",
u8"'is'",
u8"'let'",
u8"'='",
"",
u8"'=='",
u8"'+'",
u8"'-'",
u8"'*'",
u8"'/'",
u8"'%'",
u8"'|'",
u8"'&'",
u8"'~'",
u8"'max'",
u8"'min'",
u8"'!='",
u8"'<'",
u8"'<='",
u8"'>'",
u8"'>='",
u8"'<<'",
u8"'>>'",
u8"'>>>'",
u8"'...'",
"",
u8"'++'",
u8"'--'",
u8"'!'"};
std::vector<std::string> TorqueLexer::_symbolicNames = {
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
u8"MACRO",
u8"BUILTIN",
u8"RUNTIME",
u8"MODULE",
u8"JAVASCRIPT",
u8"IMPLICIT",
u8"DEFERRED",
u8"IF",
u8"CAST_KEYWORD",
u8"CONVERT_KEYWORD",
u8"FOR",
u8"WHILE",
u8"RETURN",
u8"CONTINUE",
u8"BREAK",
u8"GOTO",
u8"OTHERWISE",
u8"TRY",
u8"CATCH",
u8"LABEL",
u8"LABELS",
u8"TAIL",
u8"ISNT",
u8"IS",
u8"LET",
u8"ASSIGNMENT",
u8"ASSIGNMENT_OPERATOR",
u8"EQUAL",
u8"PLUS",
u8"MINUS",
u8"MULTIPLY",
u8"DIVIDE",
u8"MODULO",
u8"BIT_OR",
u8"BIT_AND",
u8"BIT_NOT",
u8"MAX",
u8"MIN",
u8"NOT_EQUAL",
u8"LESS_THAN",
u8"LESS_THAN_EQUAL",
u8"GREATER_THAN",
u8"GREATER_THAN_EQUAL",
u8"SHIFT_LEFT",
u8"SHIFT_RIGHT",
u8"SHIFT_RIGHT_ARITHMETIC",
u8"VARARGS",
u8"EQUALITY_OPERATOR",
u8"INCREMENT",
u8"DECREMENT",
u8"NOT",
u8"STRING_LITERAL",
u8"IDENTIFIER",
u8"WS",
u8"BLOCK_COMMENT",
u8"LINE_COMMENT",
u8"DECIMAL_LITERAL"};
dfa::Vocabulary TorqueLexer::_vocabulary(_literalNames, _symbolicNames);
std::vector<std::string> TorqueLexer::_tokenNames;
TorqueLexer::Initializer::Initializer() {
// This code could be in a static initializer lambda, but VS doesn't allow
// access to private class members from there.
for (size_t i = 0; i < _symbolicNames.size(); ++i) {
std::string name = _vocabulary.getLiteralName(i);
if (name.empty()) {
name = _vocabulary.getSymbolicName(i);
}
if (name.empty()) {
_tokenNames.push_back("<INVALID>");
} else {
_tokenNames.push_back(name);
}
}
_serializedATN = {
0x3, 0x608b, 0xa72a, 0x8133, 0xb9ed, 0x417c, 0x3be7, 0x7786, 0x5964,
0x2, 0x50, 0x266, 0x8, 0x1, 0x4, 0x2, 0x9, 0x2,
0x4, 0x3, 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x3, 0x53, 0x3, 0x53, 0x3, 0x53, 0x7, 0x53, 0x250,
0xa, 0x53, 0xc, 0x53, 0xe, 0x53, 0x253, 0xb, 0x53,
0x3, 0x53, 0x5, 0x53, 0x256, 0xa, 0x53, 0x3, 0x53,
0x3, 0x53, 0x6, 0x53, 0x25a, 0xa, 0x53, 0xd, 0x53,
0xe, 0x53, 0x25b, 0x3, 0x53, 0x5, 0x53, 0x25f, 0xa,
0x53, 0x3, 0x53, 0x3, 0x53, 0x5, 0x53, 0x263, 0xa,
0x53, 0x5, 0x53, 0x265, 0xa, 0x53, 0x3, 0x222, 0x2,
0x54, 0x3, 0x3, 0x5, 0x4, 0x7, 0x5, 0x9, 0x6,
0xb, 0x7, 0xd, 0x8, 0xf, 0x9, 0x11, 0xa, 0x13,
0xb, 0x15, 0xc, 0x17, 0xd, 0x19, 0xe, 0x1b, 0xf,
0x1d, 0x10, 0x1f, 0x11, 0x21, 0x12, 0x23, 0x13, 0x25,
0x14, 0x27, 0x15, 0x29, 0x16, 0x2b, 0x17, 0x2d, 0x18,
0x2f, 0x19, 0x31, 0x1a, 0x33, 0x1b, 0x35, 0x1c, 0x37,
0x1d, 0x39, 0x1e, 0x3b, 0x1f, 0x3d, 0x20, 0x3f, 0x21,
0x41, 0x22, 0x43, 0x23, 0x45, 0x24, 0x47, 0x25, 0x49,
0x26, 0x4b, 0x27, 0x4d, 0x28, 0x4f, 0x29, 0x51, 0x2a,
0x53, 0x2b, 0x55, 0x2c, 0x57, 0x2d, 0x59, 0x2e, 0x5b,
0x2f, 0x5d, 0x30, 0x5f, 0x31, 0x61, 0x32, 0x63, 0x33,
0x65, 0x34, 0x67, 0x35, 0x69, 0x36, 0x6b, 0x37, 0x6d,
0x38, 0x6f, 0x39, 0x71, 0x3a, 0x73, 0x3b, 0x75, 0x3c,
0x77, 0x3d, 0x79, 0x3e, 0x7b, 0x3f, 0x7d, 0x40, 0x7f,
0x41, 0x81, 0x42, 0x83, 0x43, 0x85, 0x44, 0x87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
0x2, 0x2, 0xfd, 0x2e, 0x3, 0x2, 0x2, 0x2, 0xfe,
0xff, 0x7, 0x64, 0x2, 0x2, 0xff, 0x100, 0x7, 0x77,
0x2, 0x2, 0x100, 0x101, 0x7, 0x6b, 0x2, 0x2, 0x101,
0x102, 0x7, 0x6e, 0x2, 0x2, 0x102, 0x103, 0x7, 0x76,
0x2, 0x2, 0x103, 0x104, 0x7, 0x6b, 0x2, 0x2, 0x104,
0x105, 0x7, 0x70, 0x2, 0x2, 0x105, 0x30, 0x3, 0x2,
0x2, 0x2, 0x106, 0x107, 0x7, 0x74, 0x2, 0x2, 0x107,
0x108, 0x7, 0x77, 0x2, 0x2, 0x108, 0x109, 0x7, 0x70,
0x2, 0x2, 0x109, 0x10a, 0x7, 0x76, 0x2, 0x2, 0x10a,
0x10b, 0x7, 0x6b, 0x2, 0x2, 0x10b, 0x10c, 0x7, 0x6f,
0x2, 0x2, 0x10c, 0x10d, 0x7, 0x67, 0x2, 0x2, 0x10d,
0x32, 0x3, 0x2, 0x2, 0x2, 0x10e, 0x10f, 0x7, 0x6f,
0x2, 0x2, 0x10f, 0x110, 0x7, 0x71, 0x2, 0x2, 0x110,
0x111, 0x7, 0x66, 0x2, 0x2, 0x111, 0x112, 0x7, 0x77,
0x2, 0x2, 0x112, 0x113, 0x7, 0x6e, 0x2, 0x2, 0x113,
0x114, 0x7, 0x67, 0x2, 0x2, 0x114, 0x34, 0x3, 0x2,
0x2, 0x2, 0x115, 0x116, 0x7, 0x6c, 0x2, 0x2, 0x116,
0x117, 0x7, 0x63, 0x2, 0x2, 0x117, 0x118, 0x7, 0x78,
0x2, 0x2, 0x118, 0x119, 0x7, 0x63, 0x2, 0x2, 0x119,
0x11a, 0x7, 0x75, 0x2, 0x2, 0x11a, 0x11b, 0x7, 0x65,
0x2, 0x2, 0x11b, 0x11c, 0x7, 0x74, 0x2, 0x2, 0x11c,
0x11d, 0x7, 0x6b, 0x2, 0x2, 0x11d, 0x11e, 0x7, 0x72,
0x2, 0x2, 0x11e, 0x11f, 0x7, 0x76, 0x2, 0x2, 0x11f,
0x36, 0x3, 0x2, 0x2, 0x2, 0x120, 0x121, 0x7, 0x6b,
0x2, 0x2, 0x121, 0x122, 0x7, 0x6f, 0x2, 0x2, 0x122,
0x123, 0x7, 0x72, 0x2, 0x2, 0x123, 0x124, 0x7, 0x6e,
0x2, 0x2, 0x124, 0x125, 0x7, 0x6b, 0x2, 0x2, 0x125,
0x126, 0x7, 0x65, 0x2, 0x2, 0x126, 0x127, 0x7, 0x6b,
0x2, 0x2, 0x127, 0x128, 0x7, 0x76, 0x2, 0x2, 0x128,
0x38, 0x3, 0x2, 0x2, 0x2, 0x129, 0x12a, 0x7, 0x66,
0x2, 0x2, 0x12a, 0x12b, 0x7, 0x67, 0x2, 0x2, 0x12b,
0x12c, 0x7, 0x68, 0x2, 0x2, 0x12c, 0x12d, 0x7, 0x67,
0x2, 0x2, 0x12d, 0x12e, 0x7, 0x74, 0x2, 0x2, 0x12e,
0x12f, 0x7, 0x74, 0x2, 0x2, 0x12f, 0x130, 0x7, 0x67,
0x2, 0x2, 0x130, 0x131, 0x7, 0x66, 0x2, 0x2, 0x131,
0x3a, 0x3, 0x2, 0x2, 0x2, 0x132, 0x133, 0x7, 0x6b,
0x2, 0x2, 0x133, 0x134, 0x7, 0x68, 0x2, 0x2, 0x134,
0x3c, 0x3, 0x2, 0x2, 0x2, 0x135, 0x136, 0x7, 0x65,
0x2, 0x2, 0x136, 0x137, 0x7, 0x63, 0x2, 0x2, 0x137,
0x138, 0x7, 0x75, 0x2, 0x2, 0x138, 0x139, 0x7, 0x76,
0x2, 0x2, 0x139, 0x3e, 0x3, 0x2, 0x2, 0x2, 0x13a,
0x13b, 0x7, 0x65, 0x2, 0x2, 0x13b, 0x13c, 0x7, 0x71,
0x2, 0x2, 0x13c, 0x13d, 0x7, 0x70, 0x2, 0x2, 0x13d,
0x13e, 0x7, 0x78, 0x2, 0x2, 0x13e, 0x13f, 0x7, 0x67,
0x2, 0x2, 0x13f, 0x140, 0x7, 0x74, 0x2, 0x2, 0x140,
0x141, 0x7, 0x76, 0x2, 0x2, 0x141, 0x40, 0x3, 0x2,
0x2, 0x2, 0x142, 0x143, 0x7, 0x68, 0x2, 0x2, 0x143,
0x144, 0x7, 0x71, 0x2, 0x2, 0x144, 0x145, 0x7, 0x74,
0x2, 0x2, 0x145, 0x42, 0x3, 0x2, 0x2, 0x2, 0x146,
0x147, 0x7, 0x79, 0x2, 0x2, 0x147, 0x148, 0x7, 0x6a,
0x2, 0x2, 0x148, 0x149, 0x7, 0x6b, 0x2, 0x2, 0x149,
0x14a, 0x7, 0x6e, 0x2, 0x2, 0x14a, 0x14b, 0x7, 0x67,
0x2, 0x2, 0x14b, 0x44, 0x3, 0x2, 0x2, 0x2, 0x14c,
0x14d, 0x7, 0x74, 0x2, 0x2, 0x14d, 0x14e, 0x7, 0x67,
0x2, 0x2, 0x14e, 0x14f, 0x7, 0x76, 0x2, 0x2, 0x14f,
0x150, 0x7, 0x77, 0x2, 0x2, 0x150, 0x151, 0x7, 0x74,
0x2, 0x2, 0x151, 0x152, 0x7, 0x70, 0x2, 0x2, 0x152,
0x46, 0x3, 0x2, 0x2, 0x2, 0x153, 0x154, 0x7, 0x65,
0x2, 0x2, 0x154, 0x155, 0x7, 0x71, 0x2, 0x2, 0x155,
0x156, 0x7, 0x70, 0x2, 0x2, 0x156, 0x157, 0x7, 0x76,
0x2, 0x2, 0x157, 0x158, 0x7, 0x6b, 0x2, 0x2, 0x158,
0x159, 0x7, 0x70, 0x2, 0x2, 0x159, 0x15a, 0x7, 0x77,
0x2, 0x2, 0x15a, 0x15b, 0x7, 0x67, 0x2, 0x2, 0x15b,
0x48, 0x3, 0x2, 0x2, 0x2, 0x15c, 0x15d, 0x7, 0x64,
0x2, 0x2, 0x15d, 0x15e, 0x7, 0x74, 0x2, 0x2, 0x15e,
0x15f, 0x7, 0x67, 0x2, 0x2, 0x15f, 0x160, 0x7, 0x63,
0x2, 0x2, 0x160, 0x161, 0x7, 0x6d, 0x2, 0x2, 0x161,
0x4a, 0x3, 0x2, 0x2, 0x2, 0x162, 0x163, 0x7, 0x69,
0x2, 0x2, 0x163, 0x164, 0x7, 0x71, 0x2, 0x2, 0x164,
0x165, 0x7, 0x76, 0x2, 0x2, 0x165, 0x166, 0x7, 0x71,
0x2, 0x2, 0x166, 0x4c, 0x3, 0x2, 0x2, 0x2, 0x167,
0x168, 0x7, 0x71, 0x2, 0x2, 0x168, 0x169, 0x7, 0x76,
0x2, 0x2, 0x169, 0x16a, 0x7, 0x6a, 0x2, 0x2, 0x16a,
0x16b, 0x7, 0x67, 0x2, 0x2, 0x16b, 0x16c, 0x7, 0x74,
0x2, 0x2, 0x16c, 0x16d, 0x7, 0x79, 0x2, 0x2, 0x16d,
0x16e, 0x7, 0x6b, 0x2, 0x2, 0x16e, 0x16f, 0x7, 0x75,
0x2, 0x2, 0x16f, 0x170, 0x7, 0x67, 0x2, 0x2, 0x170,
0x4e, 0x3, 0x2, 0x2, 0x2, 0x171, 0x172, 0x7, 0x76,
0x2, 0x2, 0x172, 0x173, 0x7, 0x74, 0x2, 0x2, 0x173,
0x174, 0x7, 0x7b, 0x2, 0x2, 0x174, 0x50, 0x3, 0x2,
0x2, 0x2, 0x175, 0x176, 0x7, 0x65, 0x2, 0x2, 0x176,
0x177, 0x7, 0x63, 0x2, 0x2, 0x177, 0x178, 0x7, 0x76,
0x2, 0x2, 0x178, 0x179, 0x7, 0x65, 0x2, 0x2, 0x179,
0x17a, 0x7, 0x6a, 0x2, 0x2, 0x17a, 0x52, 0x3, 0x2,
0x2, 0x2, 0x17b, 0x17c, 0x7, 0x6e, 0x2, 0x2, 0x17c,
0x17d, 0x7, 0x63, 0x2, 0x2, 0x17d, 0x17e, 0x7, 0x64,
0x2, 0x2, 0x17e, 0x17f, 0x7, 0x67, 0x2, 0x2, 0x17f,
0x180, 0x7, 0x6e, 0x2, 0x2, 0x180, 0x54, 0x3, 0x2,
0x2, 0x2, 0x181, 0x182, 0x7, 0x6e, 0x2, 0x2, 0x182,
0x183, 0x7, 0x63, 0x2, 0x2, 0x183, 0x184, 0x7, 0x64,
0x2, 0x2, 0x184, 0x185, 0x7, 0x67, 0x2, 0x2, 0x185,
0x186, 0x7, 0x6e, 0x2, 0x2, 0x186, 0x187, 0x7, 0x75,
0x2, 0x2, 0x187, 0x56, 0x3, 0x2, 0x2, 0x2, 0x188,
0x189, 0x7, 0x76, 0x2, 0x2, 0x189, 0x18a, 0x7, 0x63,
0x2, 0x2, 0x18a, 0x18b, 0x7, 0x6b, 0x2, 0x2, 0x18b,
0x18c, 0x7, 0x6e, 0x2, 0x2, 0x18c, 0x58, 0x3, 0x2,
0x2, 0x2, 0x18d, 0x18e, 0x7, 0x6b, 0x2, 0x2, 0x18e,
0x18f, 0x7, 0x75, 0x2, 0x2, 0x18f, 0x190, 0x7, 0x70,
0x2, 0x2, 0x190, 0x191, 0x7, 0x76, 0x2, 0x2, 0x191,
0x5a, 0x3, 0x2, 0x2, 0x2, 0x192, 0x193, 0x7, 0x6b,
0x2, 0x2, 0x193, 0x194, 0x7, 0x75, 0x2, 0x2, 0x194,
0x5c, 0x3, 0x2, 0x2, 0x2, 0x195, 0x196, 0x7, 0x6e,
0x2, 0x2, 0x196, 0x197, 0x7, 0x67, 0x2, 0x2, 0x197,
0x198, 0x7, 0x76, 0x2, 0x2, 0x198, 0x5e, 0x3, 0x2,
0x2, 0x2, 0x199, 0x19a, 0x7, 0x3f, 0x2, 0x2, 0x19a,
0x60, 0x3, 0x2, 0x2, 0x2, 0x19b, 0x19c, 0x7, 0x2c,
0x2, 0x2, 0x19c, 0x1b6, 0x7, 0x3f, 0x2, 0x2, 0x19d,
0x19e, 0x7, 0x31, 0x2, 0x2, 0x19e, 0x1b6, 0x7, 0x3f,
0x2, 0x2, 0x19f, 0x1a0, 0x7, 0x27, 0x2, 0x2, 0x1a0,
0x1b6, 0x7, 0x3f, 0x2, 0x2, 0x1a1, 0x1a2, 0x7,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20c, 0x20d, 0x9, 0x3,
0x2, 0x2, 0x20d, 0x96, 0x3, 0x2, 0x2, 0x2, 0x20e,
0x212, 0x9, 0x4, 0x2, 0x2, 0x20f, 0x211, 0x9, 0x5,
0x2, 0x2, 0x210, 0x20f, 0x3, 0x2, 0x2, 0x2, 0x211,
0x214, 0x3, 0x2, 0x2, 0x2, 0x212, 0x210, 0x3, 0x2,
0x2, 0x2, 0x212, 0x213, 0x3, 0x2, 0x2, 0x2, 0x213,
0x98, 0x3, 0x2, 0x2, 0x2, 0x214, 0x212, 0x3, 0x2,
0x2, 0x2, 0x215, 0x217, 0x9, 0x6, 0x2, 0x2, 0x216,
0x215, 0x3, 0x2, 0x2, 0x2, 0x217, 0x218, 0x3, 0x2,
0x2, 0x2, 0x218, 0x216, 0x3, 0x2, 0x2, 0x2, 0x218,
0x219, 0x3, 0x2, 0x2, 0x2, 0x219, 0x21a, 0x3, 0x2,
0x2, 0x2, 0x21a, 0x21b, 0x8, 0x4d, 0x2, 0x2, 0x21b,
0x9a, 0x3, 0x2, 0x2, 0x2, 0x21c, 0x21d, 0x7, 0x31,
0x2, 0x2, 0x21d, 0x21e, 0x7, 0x2c, 0x2, 0x2, 0x21e,
0x222, 0x3, 0x2, 0x2, 0x2, 0x21f, 0x221, 0xb, 0x2,
0x2, 0x2, 0x220, 0x21f, 0x3, 0x2, 0x2, 0x2, 0x221,
0x224, 0x3, 0x2, 0x2, 0x2, 0x222, 0x223, 0x3, 0x2,
0x2, 0x2, 0x222, 0x220, 0x3, 0x2, 0x2, 0x2, 0x223,
0x228, 0x3, 0x2, 0x2, 0x2, 0x224, 0x222, 0x3, 0x2,
0x2, 0x2, 0x225, 0x226, 0x7, 0x2c, 0x2, 0x2, 0x226,
0x229, 0x7, 0x31, 0x2, 0x2, 0x227, 0x229, 0x7, 0x2,
0x2, 0x3, 0x228, 0x225, 0x3, 0x2, 0x2, 0x2, 0x228,
0x227, 0x3, 0x2, 0x2, 0x2, 0x229, 0x22a, 0x3, 0x2,
0x2, 0x2, 0x22a, 0x22b, 0x8, 0x4e, 0x2, 0x2, 0x22b,
0x9c, 0x3, 0x2, 0x2, 0x2, 0x22c, 0x22d, 0x7, 0x31,
0x2, 0x2, 0x22d, 0x22e, 0x7, 0x31, 0x2, 0x2, 0x22e,
0x232, 0x3, 0x2, 0x2, 0x2, 0x22f, 0x231, 0xa, 0x7,
0x2, 0x2, 0x230, 0x22f, 0x3, 0x2, 0x2, 0x2, 0x231,
0x234, 0x3, 0x2, 0x2, 0x2, 0x232, 0x230, 0x3, 0x2,
0x2, 0x2, 0x232, 0x233, 0x3, 0x2, 0x2, 0x2, 0x233,
0x235, 0x3, 0x2, 0x2, 0x2, 0x234, 0x232, 0x3, 0x2,
0x2, 0x2, 0x235, 0x236, 0x8, 0x4f, 0x2, 0x2, 0x236,
0x9e, 0x3, 0x2, 0x2, 0x2, 0x237, 0x238, 0x9, 0x8,
0x2, 0x2, 0x238, 0xa0, 0x3, 0x2, 0x2, 0x2, 0x239,
0x242, 0x7, 0x32, 0x2, 0x2, 0x23a, 0x23e, 0x9, 0x9,
0x2, 0x2, 0x23b, 0x23d, 0x5, 0x9f, 0x50, 0x2, 0x23c,
0x23b, 0x3, 0x2, 0x2, 0x2, 0x23d, 0x240, 0x3, 0x2,
0x2, 0x2, 0x23e, 0x23c, 0x3, 0x2, 0x2, 0x2, 0x23e,
0x23f, 0x3, 0x2, 0x2, 0x2, 0x23f, 0x242, 0x3, 0x2,
0x2, 0x2, 0x240, 0x23e, 0x3, 0x2, 0x2, 0x2, 0x241,
0x239, 0x3, 0x2, 0x2, 0x2, 0x241, 0x23a, 0x3, 0x2,
0x2, 0x2, 0x242, 0xa2, 0x3, 0x2, 0x2, 0x2, 0x243,
0x245, 0x9, 0xa, 0x2, 0x2, 0x244, 0x246, 0x9, 0xb,
0x2, 0x2, 0x245, 0x244, 0x3, 0x2, 0x2, 0x2, 0x245,
0x246, 0x3, 0x2, 0x2, 0x2, 0x246, 0x248, 0x3, 0x2,
0x2, 0x2, 0x247, 0x249, 0x5, 0x9f, 0x50, 0x2, 0x248,
0x247, 0x3, 0x2, 0x2, 0x2, 0x249, 0x24a, 0x3, 0x2,
0x2, 0x2, 0x24a, 0x248, 0x3, 0x2, 0x2, 0x2, 0x24a,
0x24b, 0x3, 0x2, 0x2, 0x2, 0x24b, 0xa4, 0x3, 0x2,
0x2, 0x2, 0x24c, 0x24d, 0x5, 0xa1, 0x51, 0x2, 0x24d,
0x251, 0x7, 0x30, 0x2, 0x2, 0x24e, 0x250, 0x5, 0x9f,
0x50, 0x2, 0x24f, 0x24e, 0x3, 0x2, 0x2, 0x2, 0x250,
0x253, 0x3, 0x2, 0x2, 0x2, 0x251, 0x24f, 0x3, 0x2,
0x2, 0x2, 0x251, 0x252, 0x3, 0x2, 0x2, 0x2, 0x252,
0x255, 0x3, 0x2, 0x2, 0x2, 0x253, 0x251, 0x3, 0x2,
0x2, 0x2, 0x254, 0x256, 0x5, 0xa3, 0x52, 0x2, 0x255,
0x254, 0x3, 0x2, 0x2, 0x2, 0x255, 0x256, 0x3, 0x2,
0x2, 0x2, 0x256, 0x265, 0x3, 0x2, 0x2, 0x2, 0x257,
0x259, 0x7, 0x30, 0x2, 0x2, 0x258, 0x25a, 0x5, 0x9f,
0x50, 0x2, 0x259, 0x258, 0x3, 0x2, 0x2, 0x2, 0x25a,
0x25b, 0x3, 0x2, 0x2, 0x2, 0x25b, 0x259, 0x3, 0x2,
0x2, 0x2, 0x25b, 0x25c, 0x3, 0x2, 0x2, 0x2, 0x25c,
0x25e, 0x3, 0x2, 0x2, 0x2, 0x25d, 0x25f, 0x5, 0xa3,
0x52, 0x2, 0x25e, 0x25d, 0x3, 0x2, 0x2, 0x2, 0x25e,
0x25f, 0x3, 0x2, 0x2, 0x2, 0x25f, 0x265, 0x3, 0x2,
0x2, 0x2, 0x260, 0x262, 0x5, 0xa1, 0x51, 0x2, 0x261,
0x263, 0x5, 0xa3, 0x52, 0x2, 0x262, 0x261, 0x3, 0x2,
0x2, 0x2, 0x262, 0x263, 0x3, 0x2, 0x2, 0x2, 0x263,
0x265, 0x3, 0x2, 0x2, 0x2, 0x264, 0x24c, 0x3, 0x2,
0x2, 0x2, 0x264, 0x257, 0x3, 0x2, 0x2, 0x2, 0x264,
0x260, 0x3, 0x2, 0x2, 0x2, 0x265, 0xa6, 0x3, 0x2,
0x2, 0x2, 0x19, 0x2, 0x1b5, 0x1ef, 0x1fc, 0x1fe, 0x204,
0x206, 0x209, 0x212, 0x218, 0x222, 0x228, 0x232, 0x23e, 0x241,
0x245, 0x24a, 0x251, 0x255, 0x25b, 0x25e, 0x262, 0x264, 0x3,
0x2, 0x3, 0x2,
};
atn::ATNDeserializer deserializer;
_atn = deserializer.deserialize(_serializedATN);
size_t count = _atn.getNumberOfDecisions();
_decisionToDFA.reserve(count);
for (size_t i = 0; i < count; i++) {
_decisionToDFA.emplace_back(_atn.getDecisionState(i), i);
}
}
TorqueLexer::Initializer TorqueLexer::_init;

135
src/torque/TorqueLexer.h Normal file
View File

@ -0,0 +1,135 @@
// 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,
IMPLICIT = 27,
DEFERRED = 28,
IF = 29,
CAST_KEYWORD = 30,
CONVERT_KEYWORD = 31,
FOR = 32,
WHILE = 33,
RETURN = 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,
ASSIGNMENT = 47,
ASSIGNMENT_OPERATOR = 48,
EQUAL = 49,
PLUS = 50,
MINUS = 51,
MULTIPLY = 52,
DIVIDE = 53,
MODULO = 54,
BIT_OR = 55,
BIT_AND = 56,
BIT_NOT = 57,
MAX = 58,
MIN = 59,
NOT_EQUAL = 60,
LESS_THAN = 61,
LESS_THAN_EQUAL = 62,
GREATER_THAN = 63,
GREATER_THAN_EQUAL = 64,
SHIFT_LEFT = 65,
SHIFT_RIGHT = 66,
SHIFT_RIGHT_ARITHMETIC = 67,
VARARGS = 68,
EQUALITY_OPERATOR = 69,
INCREMENT = 70,
DECREMENT = 71,
NOT = 72,
STRING_LITERAL = 73,
IDENTIFIER = 74,
WS = 75,
BLOCK_COMMENT = 76,
LINE_COMMENT = 77,
DECIMAL_LITERAL = 78
};
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_

View File

@ -0,0 +1,7 @@
// 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"

289
src/torque/TorqueListener.h Normal file
View File

@ -0,0 +1,289 @@
// 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_TORQUELISTENER_H_
#define V8_TORQUE_TORQUELISTENER_H_
// Generated from Torque.g4 by ANTLR 4.7.1
#pragma once
#include "./antlr4-runtime.h"
#include "TorqueParser.h"
/**
* This interface defines an abstract listener for a parse tree produced by
* TorqueParser.
*/
class TorqueListener : public antlr4::tree::ParseTreeListener {
public:
virtual void enterType(TorqueParser::TypeContext* ctx) = 0;
virtual void exitType(TorqueParser::TypeContext* ctx) = 0;
virtual void enterTypeList(TorqueParser::TypeListContext* ctx) = 0;
virtual void exitTypeList(TorqueParser::TypeListContext* ctx) = 0;
virtual void enterTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* ctx) = 0;
virtual void exitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* ctx) = 0;
virtual void enterLabelParameter(
TorqueParser::LabelParameterContext* ctx) = 0;
virtual void exitLabelParameter(TorqueParser::LabelParameterContext* ctx) = 0;
virtual void enterOptionalType(TorqueParser::OptionalTypeContext* ctx) = 0;
virtual void exitOptionalType(TorqueParser::OptionalTypeContext* ctx) = 0;
virtual void enterOptionalLabelList(
TorqueParser::OptionalLabelListContext* ctx) = 0;
virtual void exitOptionalLabelList(
TorqueParser::OptionalLabelListContext* ctx) = 0;
virtual void enterOptionalOtherwise(
TorqueParser::OptionalOtherwiseContext* ctx) = 0;
virtual void exitOptionalOtherwise(
TorqueParser::OptionalOtherwiseContext* ctx) = 0;
virtual void enterParameter(TorqueParser::ParameterContext* ctx) = 0;
virtual void exitParameter(TorqueParser::ParameterContext* ctx) = 0;
virtual void enterParameterList(TorqueParser::ParameterListContext* ctx) = 0;
virtual void exitParameterList(TorqueParser::ParameterListContext* ctx) = 0;
virtual void enterLabelDeclaration(
TorqueParser::LabelDeclarationContext* ctx) = 0;
virtual void exitLabelDeclaration(
TorqueParser::LabelDeclarationContext* ctx) = 0;
virtual void enterExpression(TorqueParser::ExpressionContext* ctx) = 0;
virtual void exitExpression(TorqueParser::ExpressionContext* ctx) = 0;
virtual void enterConditionalExpression(
TorqueParser::ConditionalExpressionContext* ctx) = 0;
virtual void exitConditionalExpression(
TorqueParser::ConditionalExpressionContext* ctx) = 0;
virtual void enterLogicalORExpression(
TorqueParser::LogicalORExpressionContext* ctx) = 0;
virtual void exitLogicalORExpression(
TorqueParser::LogicalORExpressionContext* ctx) = 0;
virtual void enterLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* ctx) = 0;
virtual void exitLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* ctx) = 0;
virtual void enterBitwiseExpression(
TorqueParser::BitwiseExpressionContext* ctx) = 0;
virtual void exitBitwiseExpression(
TorqueParser::BitwiseExpressionContext* ctx) = 0;
virtual void enterEqualityExpression(
TorqueParser::EqualityExpressionContext* ctx) = 0;
virtual void exitEqualityExpression(
TorqueParser::EqualityExpressionContext* ctx) = 0;
virtual void enterRelationalExpression(
TorqueParser::RelationalExpressionContext* ctx) = 0;
virtual void exitRelationalExpression(
TorqueParser::RelationalExpressionContext* ctx) = 0;
virtual void enterShiftExpression(
TorqueParser::ShiftExpressionContext* ctx) = 0;
virtual void exitShiftExpression(
TorqueParser::ShiftExpressionContext* ctx) = 0;
virtual void enterAdditiveExpression(
TorqueParser::AdditiveExpressionContext* ctx) = 0;
virtual void exitAdditiveExpression(
TorqueParser::AdditiveExpressionContext* ctx) = 0;
virtual void enterMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* ctx) = 0;
virtual void exitMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* ctx) = 0;
virtual void enterUnaryExpression(
TorqueParser::UnaryExpressionContext* ctx) = 0;
virtual void exitUnaryExpression(
TorqueParser::UnaryExpressionContext* ctx) = 0;
virtual void enterLocationExpression(
TorqueParser::LocationExpressionContext* ctx) = 0;
virtual void exitLocationExpression(
TorqueParser::LocationExpressionContext* ctx) = 0;
virtual void enterIncrementDecrement(
TorqueParser::IncrementDecrementContext* ctx) = 0;
virtual void exitIncrementDecrement(
TorqueParser::IncrementDecrementContext* ctx) = 0;
virtual void enterAssignment(TorqueParser::AssignmentContext* ctx) = 0;
virtual void exitAssignment(TorqueParser::AssignmentContext* ctx) = 0;
virtual void enterAssignmentExpression(
TorqueParser::AssignmentExpressionContext* ctx) = 0;
virtual void exitAssignmentExpression(
TorqueParser::AssignmentExpressionContext* ctx) = 0;
virtual void enterPrimaryExpression(
TorqueParser::PrimaryExpressionContext* ctx) = 0;
virtual void exitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* ctx) = 0;
virtual void enterForInitialization(
TorqueParser::ForInitializationContext* ctx) = 0;
virtual void exitForInitialization(
TorqueParser::ForInitializationContext* ctx) = 0;
virtual void enterForLoop(TorqueParser::ForLoopContext* ctx) = 0;
virtual void exitForLoop(TorqueParser::ForLoopContext* ctx) = 0;
virtual void enterRangeSpecifier(
TorqueParser::RangeSpecifierContext* ctx) = 0;
virtual void exitRangeSpecifier(TorqueParser::RangeSpecifierContext* ctx) = 0;
virtual void enterForOfRange(TorqueParser::ForOfRangeContext* ctx) = 0;
virtual void exitForOfRange(TorqueParser::ForOfRangeContext* ctx) = 0;
virtual void enterForOfLoop(TorqueParser::ForOfLoopContext* ctx) = 0;
virtual void exitForOfLoop(TorqueParser::ForOfLoopContext* ctx) = 0;
virtual void enterArgument(TorqueParser::ArgumentContext* ctx) = 0;
virtual void exitArgument(TorqueParser::ArgumentContext* ctx) = 0;
virtual void enterArgumentList(TorqueParser::ArgumentListContext* ctx) = 0;
virtual void exitArgumentList(TorqueParser::ArgumentListContext* ctx) = 0;
virtual void enterHelperCall(TorqueParser::HelperCallContext* ctx) = 0;
virtual void exitHelperCall(TorqueParser::HelperCallContext* ctx) = 0;
virtual void enterLabelReference(
TorqueParser::LabelReferenceContext* ctx) = 0;
virtual void exitLabelReference(TorqueParser::LabelReferenceContext* ctx) = 0;
virtual void enterVariableDeclaration(
TorqueParser::VariableDeclarationContext* ctx) = 0;
virtual void exitVariableDeclaration(
TorqueParser::VariableDeclarationContext* ctx) = 0;
virtual void enterVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* ctx) = 0;
virtual void exitVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* ctx) = 0;
virtual void enterHelperCallStatement(
TorqueParser::HelperCallStatementContext* ctx) = 0;
virtual void exitHelperCallStatement(
TorqueParser::HelperCallStatementContext* ctx) = 0;
virtual void enterExpressionStatement(
TorqueParser::ExpressionStatementContext* ctx) = 0;
virtual void exitExpressionStatement(
TorqueParser::ExpressionStatementContext* ctx) = 0;
virtual void enterIfStatement(TorqueParser::IfStatementContext* ctx) = 0;
virtual void exitIfStatement(TorqueParser::IfStatementContext* ctx) = 0;
virtual void enterWhileLoop(TorqueParser::WhileLoopContext* ctx) = 0;
virtual void exitWhileLoop(TorqueParser::WhileLoopContext* ctx) = 0;
virtual void enterReturnStatement(
TorqueParser::ReturnStatementContext* ctx) = 0;
virtual void exitReturnStatement(
TorqueParser::ReturnStatementContext* ctx) = 0;
virtual void enterBreakStatement(
TorqueParser::BreakStatementContext* ctx) = 0;
virtual void exitBreakStatement(TorqueParser::BreakStatementContext* ctx) = 0;
virtual void enterContinueStatement(
TorqueParser::ContinueStatementContext* ctx) = 0;
virtual void exitContinueStatement(
TorqueParser::ContinueStatementContext* ctx) = 0;
virtual void enterGotoStatement(TorqueParser::GotoStatementContext* ctx) = 0;
virtual void exitGotoStatement(TorqueParser::GotoStatementContext* ctx) = 0;
virtual void enterHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* ctx) = 0;
virtual void exitHandlerWithStatement(
TorqueParser::HandlerWithStatementContext* ctx) = 0;
virtual void enterTryCatch(TorqueParser::TryCatchContext* ctx) = 0;
virtual void exitTryCatch(TorqueParser::TryCatchContext* ctx) = 0;
virtual void enterStatement(TorqueParser::StatementContext* ctx) = 0;
virtual void exitStatement(TorqueParser::StatementContext* ctx) = 0;
virtual void enterStatementList(TorqueParser::StatementListContext* ctx) = 0;
virtual void exitStatementList(TorqueParser::StatementListContext* ctx) = 0;
virtual void enterStatementScope(
TorqueParser::StatementScopeContext* ctx) = 0;
virtual void exitStatementScope(TorqueParser::StatementScopeContext* ctx) = 0;
virtual void enterStatementBlock(
TorqueParser::StatementBlockContext* ctx) = 0;
virtual void exitStatementBlock(TorqueParser::StatementBlockContext* ctx) = 0;
virtual void enterHelperBody(TorqueParser::HelperBodyContext* ctx) = 0;
virtual void exitHelperBody(TorqueParser::HelperBodyContext* ctx) = 0;
virtual void enterGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* ctx) = 0;
virtual void exitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* ctx) = 0;
virtual void enterExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) = 0;
virtual void exitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) = 0;
virtual void enterTypeDeclaration(
TorqueParser::TypeDeclarationContext* ctx) = 0;
virtual void exitTypeDeclaration(
TorqueParser::TypeDeclarationContext* ctx) = 0;
virtual void enterExternalBuiltin(
TorqueParser::ExternalBuiltinContext* ctx) = 0;
virtual void exitExternalBuiltin(
TorqueParser::ExternalBuiltinContext* ctx) = 0;
virtual void enterExternalMacro(TorqueParser::ExternalMacroContext* ctx) = 0;
virtual void exitExternalMacro(TorqueParser::ExternalMacroContext* ctx) = 0;
virtual void enterExternalRuntime(
TorqueParser::ExternalRuntimeContext* ctx) = 0;
virtual void exitExternalRuntime(
TorqueParser::ExternalRuntimeContext* ctx) = 0;
virtual void enterBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* ctx) = 0;
virtual void exitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* ctx) = 0;
virtual void enterMacroDeclaration(
TorqueParser::MacroDeclarationContext* ctx) = 0;
virtual void exitMacroDeclaration(
TorqueParser::MacroDeclarationContext* ctx) = 0;
virtual void enterConstDeclaration(
TorqueParser::ConstDeclarationContext* ctx) = 0;
virtual void exitConstDeclaration(
TorqueParser::ConstDeclarationContext* ctx) = 0;
virtual void enterDeclaration(TorqueParser::DeclarationContext* ctx) = 0;
virtual void exitDeclaration(TorqueParser::DeclarationContext* ctx) = 0;
virtual void enterModuleDeclaration(
TorqueParser::ModuleDeclarationContext* ctx) = 0;
virtual void exitModuleDeclaration(
TorqueParser::ModuleDeclarationContext* ctx) = 0;
virtual void enterFile(TorqueParser::FileContext* ctx) = 0;
virtual void exitFile(TorqueParser::FileContext* ctx) = 0;
};
#endif // V8_TORQUE_TORQUELISTENER_H_

6868
src/torque/TorqueParser.cpp Normal file

File diff suppressed because it is too large Load Diff

1384
src/torque/TorqueParser.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
// 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"

213
src/torque/TorqueVisitor.h Normal file
View File

@ -0,0 +1,213 @@
// 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 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 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 visitTryCatch(
TorqueParser::TryCatchContext* 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 visitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* context) = 0;
virtual antlrcpp::Any visitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* context) = 0;
virtual antlrcpp::Any visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* 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 visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* context) = 0;
virtual antlrcpp::Any visitConstDeclaration(
TorqueParser::ConstDeclarationContext* 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_

605
src/torque/ast-generator.cc Normal file
View File

@ -0,0 +1,605 @@
// 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.
#include <string>
#include "src/base/template-utils.h"
#include "src/torque/ast-generator.h"
namespace v8 {
namespace internal {
namespace torque {
namespace {
std::string GetOptionalType(TorqueParser::OptionalTypeContext* context) {
if (!context->type()) return "void";
return context->type()->IDENTIFIER()->getSymbol()->getText();
}
LabelAndTypesVector GetOptionalLabelAndTypeList(
TorqueParser::OptionalLabelListContext* context) {
LabelAndTypesVector labels;
for (auto label : context->labelParameter()) {
LabelAndTypes new_label;
new_label.name = label->IDENTIFIER()->getSymbol()->getText();
if (label->typeList() != nullptr) {
for (auto& type : label->typeList()->type()) {
new_label.types.push_back(type->IDENTIFIER()->getSymbol()->getText());
}
}
labels.push_back(new_label);
}
return labels;
}
std::string StringLiteralUnquote(const std::string& s) {
assert('"' == s.front() || '\'' == s.front());
assert('"' == s.back() || '\'' == 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();
}
} // namespace
antlrcpp::Any AstGenerator::visitParameterList(
TorqueParser::ParameterListContext* context) {
ParameterList result{{}, {}, context->VARARGS(), {}};
if (context->VARARGS()) {
result.arguments_variable = context->IDENTIFIER()->getSymbol()->getText();
}
for (auto* parameter : context->parameter()) {
parameter->accept(this);
result.names.push_back(parameter->IDENTIFIER()->getSymbol()->getText());
result.types.push_back(
parameter->type()->IDENTIFIER()->getSymbol()->getText());
}
return std::move(result);
}
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(type->IDENTIFIER()->getSymbol()->getText());
}
return std::move(result);
}
antlrcpp::Any AstGenerator::visitTypeListMaybeVarArgs(
TorqueParser::TypeListMaybeVarArgsContext* context) {
ParameterList result{{}, {}, context->VARARGS(), {}};
result.types.reserve(context->type().size());
for (auto* type : context->type()) {
result.types.push_back(type->IDENTIFIER()->getSymbol()->getText());
}
return std::move(result);
}
antlrcpp::Any AstGenerator::visitModuleDeclaration(
TorqueParser::ModuleDeclarationContext* context) {
ModuleDeclaration* result = new ExplicitModuleDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(), {}};
for (auto* declaration : context->declaration()) {
result->declarations.push_back(
declaration->accept(this).as<Declaration*>());
}
return base::implicit_cast<Declaration*>(result);
}
antlrcpp::Any AstGenerator::visitMacroDeclaration(
TorqueParser::MacroDeclarationContext* context) {
return base::implicit_cast<Declaration*>(new MacroDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(),
std::move(context->parameterList()->accept(this).as<ParameterList>()),
GetOptionalType(context->optionalType()),
GetOptionalLabelAndTypeList(context->optionalLabelList()),
context->helperBody()->accept(this).as<Statement*>()});
}
antlrcpp::Any AstGenerator::visitBuiltinDeclaration(
TorqueParser::BuiltinDeclarationContext* context) {
return base::implicit_cast<Declaration*>(new BuiltinDeclaration{
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*>()});
}
antlrcpp::Any AstGenerator::visitExternalMacro(
TorqueParser::ExternalMacroContext* context) {
ExternalMacroDeclaration* result = new ExternalMacroDeclaration{
Pos(context),
context->IDENTIFIER()->getSymbol()->getText(),
context->IMPLICIT() != nullptr,
{},
std::move(
context->typeListMaybeVarArgs()->accept(this).as<ParameterList>()),
GetOptionalType(context->optionalType()),
GetOptionalLabelAndTypeList(context->optionalLabelList())};
if (auto* op = context->STRING_LITERAL())
result->op = StringLiteralUnquote(op->getSymbol()->getText());
return base::implicit_cast<Declaration*>(result);
}
antlrcpp::Any AstGenerator::visitExternalBuiltin(
TorqueParser::ExternalBuiltinContext* context) {
return base::implicit_cast<Declaration*>(new ExternalBuiltinDeclaration{
Pos(context), context->JAVASCRIPT() != nullptr,
context->IDENTIFIER()->getSymbol()->getText(),
std::move(context->typeList()->accept(this).as<ParameterList>()),
GetOptionalType(context->optionalType())});
}
antlrcpp::Any AstGenerator::visitExternalRuntime(
TorqueParser::ExternalRuntimeContext* context) {
return base::implicit_cast<Declaration*>(new ExternalRuntimeDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(),
std::move(
context->typeListMaybeVarArgs()->accept(this).as<ParameterList>()),
GetOptionalType(context->optionalType())});
}
antlrcpp::Any AstGenerator::visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) {
return base::implicit_cast<Declaration*>(new ConstDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(),
context->type()->IDENTIFIER()->getSymbol()->getText(),
StringLiteralUnquote(context->STRING_LITERAL()->getSymbol()->getText())});
}
antlrcpp::Any AstGenerator::visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* context) {
TypeDeclaration* result = new TypeDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(), {}, {}};
if (context->extendsDeclaration())
result->extends =
context->extendsDeclaration()->IDENTIFIER()->getSymbol()->getText();
if (context->generatesDeclaration()) {
result->generates = StringLiteralUnquote(context->generatesDeclaration()
->STRING_LITERAL()
->getSymbol()
->getText());
}
return base::implicit_cast<Declaration*>(result);
}
antlrcpp::Any AstGenerator::visitVariableDeclaration(
TorqueParser::VariableDeclarationContext* context) {
return new VarDeclarationStatement{
Pos(context),
context->IDENTIFIER()->getSymbol()->getText(),
context->type()->IDENTIFIER()->getSymbol()->getText(),
{}};
}
antlrcpp::Any AstGenerator::visitVariableDeclarationWithInitialization(
TorqueParser::VariableDeclarationWithInitializationContext* context) {
VarDeclarationStatement* result =
VarDeclarationStatement::cast(context->variableDeclaration()
->accept(this)
.as<VarDeclarationStatement*>());
result->pos = Pos(context);
if (context->expression())
result->initializer = context->expression()->accept(this).as<Expression*>();
return base::implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitHelperCall(
TorqueParser::HelperCallContext* context) {
antlr4::tree::TerminalNode* callee;
bool is_operator = context->MIN() || context->MAX();
if (context->MIN()) callee = context->MIN();
if (context->MAX()) callee = context->MAX();
if (context->IDENTIFIER()) callee = context->IDENTIFIER();
std::vector<std::string> labels;
for (auto label : context->optionalOtherwise()->IDENTIFIER()) {
labels.push_back(label->getSymbol()->getText());
}
CallExpression* result = new CallExpression{
Pos(context), callee->getSymbol()->getText(), is_operator, {}, labels};
for (auto* arg : context->argumentList()->argument()) {
result->arguments.push_back(arg->accept(this).as<Expression*>());
}
return base::implicit_cast<Expression*>(result);
}
antlrcpp::Any AstGenerator::visitHelperCallStatement(
TorqueParser::HelperCallStatementContext* context) {
Statement* result;
if (context->TAIL()) {
result = new TailCallStatement{
Pos(context),
CallExpression::cast(
context->helperCall()->accept(this).as<Expression*>())};
} else {
result = new ExpressionStatement{
Pos(context), context->helperCall()->accept(this).as<Expression*>()};
}
return result;
}
antlrcpp::Any AstGenerator::visitStatementScope(
TorqueParser::StatementScopeContext* context) {
BlockStatement* result =
new BlockStatement{Pos(context), context->DEFERRED() != nullptr, {}};
for (auto* child : context->statementList()->statement()) {
result->statements.push_back(child->accept(this).as<Statement*>());
}
return base::implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitExpressionStatement(
TorqueParser::ExpressionStatementContext* context) {
return base::implicit_cast<Statement*>(new ExpressionStatement{
Pos(context), context->assignment()->accept(this).as<Expression*>()});
}
antlrcpp::Any AstGenerator::visitReturnStatement(
TorqueParser::ReturnStatementContext* context) {
return base::implicit_cast<Statement*>(new ReturnStatement{
Pos(context), context->expression()->accept(this).as<Expression*>()});
}
antlrcpp::Any AstGenerator::visitBreakStatement(
TorqueParser::BreakStatementContext* context) {
return base::implicit_cast<Statement*>(new BreakStatement{Pos(context)});
}
antlrcpp::Any AstGenerator::visitContinueStatement(
TorqueParser::ContinueStatementContext* context) {
return base::implicit_cast<Statement*>(new ContinueStatement{Pos(context)});
}
antlrcpp::Any AstGenerator::visitGotoStatement(
TorqueParser::GotoStatementContext* context) {
GotoStatement* result = new GotoStatement{Pos(context), {}, {}};
if (context->labelReference())
result->label =
context->labelReference()->IDENTIFIER()->getSymbol()->getText();
if (context->argumentList() != nullptr) {
for (auto a : context->argumentList()->argument()) {
result->arguments.push_back(a->accept(this).as<Expression*>());
}
}
return base::implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitIfStatement(
TorqueParser::IfStatementContext* context) {
IfStatement* result = new IfStatement{
Pos(context),
std::move(context->expression()->accept(this).as<Expression*>()),
std::move(context->statementBlock(0)->accept(this).as<Statement*>()),
{}};
if (context->statementBlock(1))
result->if_false =
std::move(context->statementBlock(1)->accept(this).as<Statement*>());
return base::implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitWhileLoop(
TorqueParser::WhileLoopContext* context) {
return base::implicit_cast<Statement*>(new WhileStatement{
Pos(context), context->expression()->accept(this).as<Expression*>(),
context->statementBlock()->accept(this).as<Statement*>()});
}
antlrcpp::Any AstGenerator::visitForLoop(
TorqueParser::ForLoopContext* context) {
ForLoopStatement* result = new ForLoopStatement{
Pos(context),
{},
context->expression()->accept(this).as<Expression*>(),
context->assignment()->accept(this).as<Expression*>(),
context->statementBlock()->accept(this).as<Statement*>()};
if (auto* init = context->forInitialization()
->variableDeclarationWithInitialization()) {
result->var_declaration =
VarDeclarationStatement::cast(init->accept(this).as<Statement*>());
}
return base::implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitForOfLoop(
TorqueParser::ForOfLoopContext* context) {
ForOfLoopStatement* result = new ForOfLoopStatement{
Pos(context),
context->variableDeclaration()
->accept(this)
.as<VarDeclarationStatement*>(),
context->expression()->accept(this).as<Expression*>(),
{},
{},
context->statementBlock()->accept(this).as<Statement*>()};
if (auto* range = context->forOfRange()->rangeSpecifier()) {
if (auto* begin = range->begin) {
result->begin = begin->accept(this).as<Expression*>();
}
if (auto* end = range->end) {
result->end = end->accept(this).as<Expression*>();
}
}
return base::implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitTryCatch(
TorqueParser::TryCatchContext* context) {
TryCatchStatement* result = new TryCatchStatement{
Pos(context),
context->statementBlock()->accept(this).as<Statement*>(),
{}};
for (auto* handler : context->handlerWithStatement()) {
if (handler->CATCH() != nullptr) {
CatchBlock* catch_block = new CatchBlock{
Pos(handler->statementBlock()),
{},
handler->statementBlock()->accept(this).as<Statement*>()};
catch_block->caught = handler->IDENTIFIER()->getSymbol()->getText();
result->catch_blocks.push_back(catch_block);
} else {
handler->labelDeclaration()->accept(this);
auto parameter_list = handler->labelDeclaration()->parameterList();
ParameterList label_parameters = parameter_list == nullptr
? ParameterList()
: handler->labelDeclaration()
->parameterList()
->accept(this)
.as<ParameterList>();
LabelBlock* label_block = new LabelBlock{
Pos(handler->statementBlock()),
handler->labelDeclaration()->IDENTIFIER()->getSymbol()->getText(),
label_parameters,
handler->statementBlock()->accept(this).as<Statement*>()};
result->label_blocks.push_back(label_block);
}
}
return base::implicit_cast<Statement*>(result);
}
antlrcpp::Any AstGenerator::visitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* context) {
if (auto* e = context->helperCall()) return e->accept(this);
if (auto* e = context->DECIMAL_LITERAL())
return base::implicit_cast<Expression*>(
new NumberLiteralExpression{Pos(context), e->getSymbol()->getText()});
if (auto* e = context->STRING_LITERAL())
return base::implicit_cast<Expression*>(
new StringLiteralExpression{Pos(context), e->getSymbol()->getText()});
if (context->CONVERT_KEYWORD())
return base::implicit_cast<Expression*>(new ConvertExpression{
Pos(context), context->type()->IDENTIFIER()->getSymbol()->getText(),
context->expression()->accept(this).as<Expression*>()});
if (context->CAST_KEYWORD())
return base::implicit_cast<Expression*>(new CastExpression{
Pos(context), context->type()->IDENTIFIER()->getSymbol()->getText(),
context->IDENTIFIER()->getSymbol()->getText(),
context->expression()->accept(this).as<Expression*>()});
return context->expression()->accept(this);
}
antlrcpp::Any AstGenerator::visitAssignment(
TorqueParser::AssignmentContext* context) {
if (auto* e = context->incrementDecrement()) return e->accept(this);
LocationExpression* location = LocationExpression::cast(
context->locationExpression()->accept(this).as<Expression*>());
if (auto* e = context->expression()) {
AssignmentExpression* result = new AssignmentExpression{
Pos(context), location, {}, e->accept(this).as<Expression*>()};
if (auto* op_node = context->ASSIGNMENT_OPERATOR()) {
std::string op = op_node->getSymbol()->getText();
result->op = op.substr(0, op.length() - 1);
}
return base::implicit_cast<Expression*>(result);
}
return base::implicit_cast<Expression*>(location);
}
antlrcpp::Any AstGenerator::visitIncrementDecrement(
TorqueParser::IncrementDecrementContext* context) {
bool postfix = context->op;
return base::implicit_cast<Expression*>(new IncrementDecrementExpression{
Pos(context),
LocationExpression::cast(
context->locationExpression()->accept(this).as<Expression*>()),
context->INCREMENT() ? IncrementDecrementOperator::kIncrement
: IncrementDecrementOperator::kDecrement,
postfix});
}
antlrcpp::Any AstGenerator::visitLocationExpression(
TorqueParser::LocationExpressionContext* context) {
if (auto* l = context->locationExpression()) {
Expression* location = l->accept(this).as<Expression*>();
if (auto* e = context->expression()) {
return base::implicit_cast<Expression*>(new ElementAccessExpression{
Pos(context), location, e->accept(this).as<Expression*>()});
}
return base::implicit_cast<Expression*>(new FieldAccessExpression{
Pos(context), location, context->IDENTIFIER()->getSymbol()->getText()});
}
return base::implicit_cast<Expression*>(new IdentifierExpression{
Pos(context), context->IDENTIFIER()->getSymbol()->getText()});
}
antlrcpp::Any AstGenerator::visitUnaryExpression(
TorqueParser::UnaryExpressionContext* context) {
if (auto* e = context->assignmentExpression()) return e->accept(this);
std::vector<Expression*> args;
args.push_back(context->unaryExpression()->accept(this).as<Expression*>());
return base::implicit_cast<Expression*>(new CallExpression{
Pos(context), context->op->getText(), true, std::move(args), {}});
}
antlrcpp::Any AstGenerator::visitMultiplicativeExpression(
TorqueParser::MultiplicativeExpressionContext* context) {
auto* right = context->unaryExpression();
if (auto* left = context->multiplicativeExpression()) {
return base::implicit_cast<Expression*>(
new CallExpression{Pos(context),
context->op->getText(),
true,
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitAdditiveExpression(
TorqueParser::AdditiveExpressionContext* context) {
auto* right = context->multiplicativeExpression();
if (auto* left = context->additiveExpression()) {
return base::implicit_cast<Expression*>(
new CallExpression{Pos(context),
context->op->getText(),
true,
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitShiftExpression(
TorqueParser::ShiftExpressionContext* context) {
auto* right = context->additiveExpression();
if (auto* left = context->shiftExpression()) {
return base::implicit_cast<Expression*>(
new CallExpression{Pos(context),
context->op->getText(),
true,
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitRelationalExpression(
TorqueParser::RelationalExpressionContext* context) {
auto* right = context->shiftExpression();
if (auto* left = context->relationalExpression()) {
return base::implicit_cast<Expression*>(
new CallExpression{Pos(context),
context->op->getText(),
true,
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitEqualityExpression(
TorqueParser::EqualityExpressionContext* context) {
auto* right = context->relationalExpression();
if (auto* left = context->equalityExpression()) {
return base::implicit_cast<Expression*>(
new CallExpression{Pos(context),
context->op->getText(),
true,
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitBitwiseExpression(
TorqueParser::BitwiseExpressionContext* context) {
auto* right = context->equalityExpression();
if (auto* left = context->bitwiseExpression()) {
return base::implicit_cast<Expression*>(
new CallExpression{Pos(context),
context->op->getText(),
true,
{left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()},
{}});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitLogicalANDExpression(
TorqueParser::LogicalANDExpressionContext* context) {
auto* right = context->bitwiseExpression();
if (auto* left = context->logicalANDExpression()) {
return base::implicit_cast<Expression*>(new LogicalAndExpression{
Pos(context), left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitLogicalORExpression(
TorqueParser::LogicalORExpressionContext* context) {
auto* right = context->logicalANDExpression();
if (auto* left = context->logicalORExpression()) {
return base::implicit_cast<Expression*>(new LogicalOrExpression{
Pos(context), left->accept(this).as<Expression*>(),
right->accept(this).as<Expression*>()});
}
return right->accept(this);
}
antlrcpp::Any AstGenerator::visitConditionalExpression(
TorqueParser::ConditionalExpressionContext* context) {
if (auto* condition = context->conditionalExpression()) {
return base::implicit_cast<Expression*>(new ConditionalExpression{
Pos(context), condition->accept(this).as<Expression*>(),
context->logicalORExpression(0)->accept(this).as<Expression*>(),
context->logicalORExpression(1)->accept(this).as<Expression*>()});
}
return context->logicalORExpression(0)->accept(this);
}
void AstGenerator::visitSourceFile(SourceFileContext* context) {
source_file_context_ = context;
current_source_file_ = ast_.AddSource(context->name);
for (auto* declaration : context->file->children) {
ast_.declarations().push_back(declaration->accept(this).as<Declaration*>());
}
source_file_context_ = nullptr;
}
SourcePosition AstGenerator::Pos(antlr4::ParserRuleContext* context) {
antlr4::misc::Interval i = context->getSourceInterval();
auto token = source_file_context_->tokens->get(i.a);
int line = static_cast<int>(token->getLine());
int column = static_cast<int>(token->getCharPositionInLine());
return SourcePosition{current_source_file_, line, column};
}
} // namespace torque
} // namespace internal
} // namespace v8

161
src/torque/ast-generator.h Normal file
View File

@ -0,0 +1,161 @@
// 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 visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* 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 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 visitPrimaryExpression(
TorqueParser::PrimaryExpressionContext* context) override;
antlrcpp::Any visitTryCatch(TorqueParser::TryCatchContext* 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 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 {};
}
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_

590
src/torque/ast.h Normal file
View File

@ -0,0 +1,590 @@
// 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_H_
#define V8_TORQUE_AST_H_
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "src/base/optional.h"
namespace v8 {
namespace internal {
namespace torque {
enum class SourceId : int {};
struct SourcePosition {
SourceId source;
int line;
int column;
};
#define AST_EXPRESSION_NODE_KIND_LIST(V) \
V(CallExpression) \
V(LogicalOrExpression) \
V(LogicalAndExpression) \
V(ConditionalExpression) \
V(IdentifierExpression) \
V(StringLiteralExpression) \
V(NumberLiteralExpression) \
V(FieldAccessExpression) \
V(ElementAccessExpression) \
V(AssignmentExpression) \
V(IncrementDecrementExpression) \
V(CastExpression) \
V(ConvertExpression)
#define AST_STATEMENT_NODE_KIND_LIST(V) \
V(BlockStatement) \
V(ExpressionStatement) \
V(IfStatement) \
V(WhileStatement) \
V(ForLoopStatement) \
V(ForOfLoopStatement) \
V(BreakStatement) \
V(ContinueStatement) \
V(ReturnStatement) \
V(TailCallStatement) \
V(VarDeclarationStatement) \
V(GotoStatement) \
V(TryCatchStatement)
#define AST_DECLARATION_NODE_KIND_LIST(V) \
V(TypeDeclaration) \
V(MacroDeclaration) \
V(ExternalMacroDeclaration) \
V(BuiltinDeclaration) \
V(ExternalBuiltinDeclaration) \
V(ExternalRuntimeDeclaration) \
V(ConstDeclaration) \
V(DefaultModuleDeclaration) \
V(ExplicitModuleDeclaration)
#define AST_NODE_KIND_LIST(V) \
AST_EXPRESSION_NODE_KIND_LIST(V) \
AST_STATEMENT_NODE_KIND_LIST(V) \
AST_DECLARATION_NODE_KIND_LIST(V) \
V(CatchBlock) \
V(LabelBlock)
struct AstNode {
public:
enum class Kind {
#define ENUM_ITEM(name) k##name,
AST_NODE_KIND_LIST(ENUM_ITEM)
#undef ENUM_ITEM
};
AstNode(Kind k, SourcePosition p) : kind(k), pos(p) {}
const Kind kind;
SourcePosition pos;
};
struct AstNodeClassCheck {
template <class T>
static bool IsInstanceOf(AstNode* node);
};
// Boilerplate for most derived classes.
#define DEFINE_AST_NODE_LEAF_BOILERPLATE(T) \
static const Kind kKind = Kind::k##T; \
static T* cast(AstNode* node) { \
if (node->kind != kKind) return nullptr; \
return static_cast<T*>(node); \
}
// Boilerplate for classes with subclasses.
#define DEFINE_AST_NODE_INNER_BOILERPLATE(T) \
template <class F> \
static T* cast(F* node) { \
DCHECK(AstNodeClassCheck::IsInstanceOf<T>(node)); \
return static_cast<T*>(node); \
}
struct Expression : AstNode {
Expression(Kind k, SourcePosition p) : AstNode(k, p) {}
DEFINE_AST_NODE_INNER_BOILERPLATE(Expression)
};
struct LocationExpression : Expression {
LocationExpression(Kind k, SourcePosition p) : Expression(k, p) {}
DEFINE_AST_NODE_INNER_BOILERPLATE(LocationExpression)
};
struct Declaration : AstNode {
Declaration(Kind k, SourcePosition p) : AstNode(k, p) {}
DEFINE_AST_NODE_INNER_BOILERPLATE(Declaration)
};
struct Statement : AstNode {
Statement(Kind k, SourcePosition p) : AstNode(k, p) {}
DEFINE_AST_NODE_INNER_BOILERPLATE(Statement)
};
class Module;
struct ModuleDeclaration : Declaration {
ModuleDeclaration(AstNode::Kind kind, SourcePosition p,
std::vector<Declaration*> d)
: Declaration(kind, p), module(nullptr), declarations(std::move(d)) {}
virtual bool IsDefault() const = 0;
// virtual std::string GetName() const = 0;
void SetModule(Module* m) { module = m; }
Module* GetModule() const { return module; }
Module* module;
std::vector<Declaration*> declarations;
};
struct DefaultModuleDeclaration : ModuleDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(DefaultModuleDeclaration)
DefaultModuleDeclaration(SourcePosition p, std::vector<Declaration*> d)
: ModuleDeclaration(kKind, p, d) {}
bool IsDefault() const override { return true; }
};
struct ExplicitModuleDeclaration : ModuleDeclaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExplicitModuleDeclaration)
ExplicitModuleDeclaration(SourcePosition p, std::string n,
std::vector<Declaration*> d)
: ModuleDeclaration(kKind, p, d), name(std::move(n)) {}
bool IsDefault() const override { return false; }
std::string name;
};
class Ast {
public:
Ast() : default_module_{SourcePosition(), {}} {}
std::vector<Declaration*>& declarations() {
return default_module_.declarations;
}
const std::vector<Declaration*>& declarations() const {
return default_module_.declarations;
}
SourceId AddSource(std::string path) {
sources_.push_back(std::move(path));
return static_cast<SourceId>(sources_.size() - 1);
}
const std::string& GetSource(SourceId id) const {
return sources_[static_cast<int>(id)];
}
std::string PositionAsString(SourcePosition pos) {
return GetSource(pos.source) + ":" + std::to_string(pos.line) + ":" +
std::to_string(pos.column);
}
DefaultModuleDeclaration* GetDefaultModule() { return &default_module_; }
private:
DefaultModuleDeclaration default_module_;
std::vector<std::string> sources_;
};
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)
: Expression(kKind, p),
callee(std::move(c)),
is_operator(o),
arguments(std::move(a)),
labels(l) {}
std::string callee;
bool is_operator;
std::vector<Expression*> arguments;
std::vector<std::string> labels;
};
struct LogicalOrExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(LogicalOrExpression)
LogicalOrExpression(SourcePosition p, Expression* l, Expression* r)
: Expression(kKind, p), left(l), right(r) {}
Expression* left;
Expression* right;
};
struct LogicalAndExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(LogicalAndExpression)
LogicalAndExpression(SourcePosition p, Expression* l, Expression* r)
: Expression(kKind, p), left(l), right(r) {}
Expression* left;
Expression* right;
};
struct ConditionalExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ConditionalExpression)
ConditionalExpression(SourcePosition p, Expression* c, Expression* t,
Expression* f)
: Expression(kKind, p), condition(c), if_true(t), if_false(f) {}
Expression* condition;
Expression* if_true;
Expression* if_false;
};
struct IdentifierExpression : LocationExpression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(IdentifierExpression)
IdentifierExpression(SourcePosition p, std::string n)
: LocationExpression(kKind, p), name(std::move(n)) {}
std::string name;
};
struct StringLiteralExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(StringLiteralExpression)
StringLiteralExpression(SourcePosition p, std::string l)
: Expression(kKind, p), literal(std::move(l)) {}
std::string literal;
};
struct NumberLiteralExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(NumberLiteralExpression)
NumberLiteralExpression(SourcePosition p, std::string n)
: Expression(kKind, p), number(std::move(n)) {}
std::string number;
};
struct CastExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(CastExpression)
CastExpression(SourcePosition p, std::string t, std::string o, Expression* v)
: Expression(kKind, p), type(std::move(t)), otherwise(o), value(v) {}
std::string type;
std::string otherwise;
Expression* value;
};
struct ConvertExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ConvertExpression)
ConvertExpression(SourcePosition p, std::string t, Expression* v)
: Expression(kKind, p), type(std::move(t)), value(v) {}
std::string type;
Expression* value;
};
struct ElementAccessExpression : LocationExpression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ElementAccessExpression)
ElementAccessExpression(SourcePosition p, Expression* a, Expression* i)
: LocationExpression(kKind, p), array(a), index(i) {}
Expression* array;
Expression* index;
};
struct FieldAccessExpression : LocationExpression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(FieldAccessExpression)
FieldAccessExpression(SourcePosition p, Expression* o, std::string f)
: LocationExpression(kKind, p), object(o), field(std::move(f)) {}
Expression* object;
std::string field;
};
struct AssignmentExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(AssignmentExpression)
AssignmentExpression(SourcePosition p, LocationExpression* l,
base::Optional<std::string> o, Expression* v)
: Expression(kKind, p), location(l), op(std::move(o)), value(v) {}
LocationExpression* location;
base::Optional<std::string> op;
Expression* value;
};
enum class IncrementDecrementOperator { kIncrement, kDecrement };
struct IncrementDecrementExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(IncrementDecrementExpression)
IncrementDecrementExpression(SourcePosition p, LocationExpression* l,
IncrementDecrementOperator o, bool pf)
: Expression(kKind, p), location(l), op(o), postfix(pf) {}
LocationExpression* location;
IncrementDecrementOperator op;
bool postfix;
};
struct ExpressionStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExpressionStatement)
ExpressionStatement(SourcePosition p, Expression* e)
: Statement(kKind, p), expression(e) {}
Expression* expression;
};
struct IfStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(IfStatement)
IfStatement(SourcePosition p, Expression* c, Statement* t,
base::Optional<Statement*> f)
: Statement(kKind, p), condition(c), if_true(t), if_false(f) {}
Expression* condition;
Statement* if_true;
base::Optional<Statement*> if_false;
};
struct WhileStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(WhileStatement)
WhileStatement(SourcePosition p, Expression* c, Statement* b)
: Statement(kKind, p), condition(c), body(b) {}
Expression* condition;
Statement* body;
};
struct ReturnStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ReturnStatement)
ReturnStatement(SourcePosition p, base::Optional<Expression*> v)
: Statement(kKind, p), value(v) {}
base::Optional<Expression*> value;
};
struct TailCallStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(TailCallStatement)
TailCallStatement(SourcePosition p, CallExpression* c)
: Statement(kKind, p), call(c) {}
CallExpression* call;
};
struct VarDeclarationStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(VarDeclarationStatement)
VarDeclarationStatement(SourcePosition p, std::string n, std::string t,
base::Optional<Expression*> i)
: Statement(kKind, p),
name(std::move(n)),
type(std::move(t)),
initializer(std::move(i)) {}
std::string name;
std::string type;
base::Optional<Expression*> initializer;
};
struct BreakStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(BreakStatement)
explicit BreakStatement(SourcePosition p) : Statement(kKind, p) {}
};
struct ContinueStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ContinueStatement)
explicit ContinueStatement(SourcePosition p) : Statement(kKind, p) {}
};
struct GotoStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(GotoStatement)
GotoStatement(SourcePosition p, std::string l,
const std::vector<Expression*>& a)
: Statement(kKind, p), label(std::move(l)), arguments(std::move(a)) {}
std::string label;
std::vector<Expression*> arguments;
};
struct ForLoopStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ForLoopStatement)
ForLoopStatement(SourcePosition p, base::Optional<VarDeclarationStatement*> d,
Expression* t, Expression* a, Statement* b)
: Statement(kKind, p),
var_declaration(d),
test(std::move(t)),
action(std::move(a)),
body(std::move(b)) {}
base::Optional<VarDeclarationStatement*> var_declaration;
Expression* test;
Expression* action;
Statement* body;
};
struct ForOfLoopStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ForOfLoopStatement)
ForOfLoopStatement(SourcePosition p, VarDeclarationStatement* d,
Expression* i, base::Optional<Expression*> bg,
base::Optional<Expression*> e, Statement* bd)
: Statement(kKind, p),
var_declaration(d),
iterable(std::move(i)),
begin(std::move(bg)),
end(std::move(e)),
body(std::move(bd)) {}
VarDeclarationStatement* var_declaration;
Expression* iterable;
base::Optional<Expression*> begin;
base::Optional<Expression*> end;
Statement* body;
};
struct CatchBlock : AstNode {
DEFINE_AST_NODE_LEAF_BOILERPLATE(CatchBlock)
CatchBlock(SourcePosition p, const std::string& c, Statement* b)
: AstNode(kKind, p), caught(std::move(c)), body(std::move(b)) {}
std::string caught;
Statement* body;
};
struct ParameterList {
std::vector<std::string> names;
std::vector<std::string> types;
bool has_varargs;
std::string arguments_variable;
};
struct LabelBlock : AstNode {
DEFINE_AST_NODE_LEAF_BOILERPLATE(LabelBlock)
LabelBlock(SourcePosition p, const std::string& l,
const ParameterList& p_list, Statement* b)
: AstNode(kKind, p),
label(std::move(l)),
parameters(p_list),
body(std::move(b)) {}
std::string label;
ParameterList parameters;
Statement* body;
};
struct TryCatchStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(TryCatchStatement)
TryCatchStatement(SourcePosition p, Statement* t, std::vector<CatchBlock*> c)
: Statement(kKind, p), try_block(std::move(t)), catch_blocks(c) {}
Statement* try_block;
std::vector<CatchBlock*> catch_blocks;
std::vector<LabelBlock*> label_blocks;
};
struct BlockStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(BlockStatement)
BlockStatement(SourcePosition p, bool d, std::vector<Statement*> s)
: Statement(kKind, p), deferred(d), statements(std::move(s)) {}
bool deferred;
std::vector<Statement*> statements;
};
struct TypeDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(TypeDeclaration)
TypeDeclaration(SourcePosition p, std::string n,
base::Optional<std::string> e, base::Optional<std::string> g)
: Declaration(kKind, p),
name(std::move(n)),
extends(std::move(e)),
generates(std::move(g)) {}
std::string name;
base::Optional<std::string> extends;
base::Optional<std::string> generates;
};
struct LabelAndTypes {
std::string name;
std::vector<std::string> types;
};
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;
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),
name(std::move(n)),
implicit(i),
op(std::move(o)),
parameters(std::move(pl)),
return_type(std::move(r)),
labels(std::move(l)) {}
std::string name;
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)) {}
bool javascript_linkage;
std::string name;
ParameterList parameters;
std::string return_type;
Statement* body;
};
struct ExternalBuiltinDeclaration : Declaration {
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;
};
struct ExternalRuntimeDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalRuntimeDeclaration)
ExternalRuntimeDeclaration(SourcePosition p, std::string n, ParameterList pl,
std::string r)
: Declaration(kKind, p),
name(std::move(n)),
parameters(std::move(pl)),
return_type(std::move(r)) {}
std::string name;
ParameterList parameters;
std::string return_type;
};
struct ConstDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ConstDeclaration)
ConstDeclaration(SourcePosition p, std::string n, std::string t,
std::string l)
: Declaration(kKind, p),
name(std::move(n)),
type(std::move(t)),
literal(std::move(l)) {}
std::string name;
std::string type;
std::string literal;
};
#define ENUM_ITEM(name) \
case AstNode::Kind::k##name: \
return std::is_base_of<T, name>::value; \
break;
template <class T>
bool AstNodeClassCheck::IsInstanceOf(AstNode* node) {
switch (node->kind) {
AST_NODE_KIND_LIST(ENUM_ITEM)
default:
UNIMPLEMENTED();
}
return true;
}
#undef ENUM_ITEM
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_AST_H_

268
src/torque/declarable.h Normal file
View File

@ -0,0 +1,268 @@
// Copyright 2017 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_DECLARABLE_H_
#define V8_TORQUE_DECLARABLE_H_
#include <string>
#include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
class Scope;
class Declarable {
public:
virtual ~Declarable() {}
enum Kind {
kVariable = 0,
kParameter,
kMacro,
kMacroList,
kBuiltin,
kRuntime,
kLabel,
kConstant
};
explicit Declarable(Kind kind) : kind_(kind) {}
Kind kind() const { return kind_; }
bool IsMacro() const { return kind() == kMacro; }
bool IsBuiltin() const { return kind() == kBuiltin; }
bool IsRuntime() const { return kind() == kRuntime; }
bool IsParameter() const { return kind() == kParameter; }
bool IsLabel() const { return kind() == kLabel; }
bool IsVariable() const { return kind() == kVariable; }
bool IsMacroList() const { return kind() == kMacroList; }
bool IsConstant() const { return kind() == kConstant; }
bool IsValue() const {
return IsVariable() || IsConstant() || IsParameter() || IsLabel();
}
virtual const char* type_name() const { return "<<unknown>>"; }
private:
Kind kind_;
};
#define DECLARE_DECLARABLE_BOILERPLATE(x, y) \
static x* cast(Declarable* declarable) { \
assert(declarable->Is##x()); \
return static_cast<x*>(declarable); \
} \
static const x* cast(const Declarable* declarable) { \
assert(declarable->Is##x()); \
return static_cast<const x*>(declarable); \
} \
const char* type_name() const override { return #y; }
class Value : public Declarable {
public:
Value(Kind kind, Type type, const std::string& name)
: Declarable(kind), type_(type), name_(name) {}
const std::string& name() const { return name_; }
virtual bool IsConst() const { return true; }
virtual std::string GetValueForDeclaration() const = 0;
virtual std::string GetValueForRead() const {
return GetValueForDeclaration();
}
virtual std::string GetValueForWrite() const { UNREACHABLE(); }
DECLARE_DECLARABLE_BOILERPLATE(Value, value);
Type type() const { return type_; }
private:
Type type_;
std::string name_;
};
class Parameter : public Value {
public:
Parameter(const std::string& name, Type type, const std::string& var_name)
: Value(Declarable::kParameter, type, name), var_name_(var_name) {}
DECLARE_DECLARABLE_BOILERPLATE(Parameter, parameter);
std::string GetValueForDeclaration() const override { return var_name_; }
private:
std::string var_name_;
};
class Variable : public Value {
public:
Variable(const std::string& name, const std::string& value, Type type)
: Value(Declarable::kVariable, type, name),
value_(value),
defined_(false) {}
DECLARE_DECLARABLE_BOILERPLATE(Variable, variable);
bool IsConst() const override { return false; }
std::string GetValueForDeclaration() const override { return value_; }
std::string GetValueForRead() const override { return value_ + "->value()"; }
std::string GetValueForWrite() const override {
return std::string("*") + value_;
}
void Define() { defined_ = true; }
bool IsDefined() const { return defined_; }
private:
std::string value_;
bool defined_;
};
class Label : public Value {
public:
explicit Label(const std::string& name) : Label(name, {}) {}
Label(const std::string& name, const std::vector<Variable*>& parameters)
: Value(Declarable::kLabel, Type(),
"label_" + name + "_" + std::to_string(next_id_++)),
source_name_(name),
parameters_(parameters),
used_(false) {}
std::string GetSourceName() const { return source_name_; }
std::string GetValueForDeclaration() const override { return name(); }
Variable* GetParameter(size_t i) const { return parameters_[i]; }
size_t GetParameterCount() const { return parameters_.size(); }
const std::vector<Variable*>& GetParameters() const { return parameters_; }
DECLARE_DECLARABLE_BOILERPLATE(Label, label);
void MarkUsed() { used_ = true; }
bool IsUsed() const { return used_; }
private:
std::string source_name_;
std::vector<Variable*> parameters_;
static size_t next_id_;
bool used_;
};
class Constant : public Value {
public:
explicit Constant(const std::string& name, Type type,
const std::string& value)
: Value(Declarable::kConstant, type, name), value_(value) {}
DECLARE_DECLARABLE_BOILERPLATE(Constant, constant);
std::string GetValueForDeclaration() const override { return value_; }
private:
std::string value_;
};
class Callable : public Declarable {
public:
Callable(Declarable::Kind kind, const std::string& name, Scope* scope,
const Signature& signature)
: Declarable(kind),
name_(name),
scope_(scope),
signature_(signature),
returns_(0) {}
static Callable* cast(Declarable* declarable) {
assert(declarable->IsMacro() || declarable->IsBuiltin() ||
declarable->IsRuntime());
return static_cast<Callable*>(declarable);
}
static const Callable* cast(const Declarable* declarable) {
assert(declarable->IsMacro() || declarable->IsBuiltin() ||
declarable->IsRuntime());
return static_cast<const Callable*>(declarable);
}
Scope* scope() const { return scope_; }
const std::string& name() const { return name_; }
const Signature& signature() const { return signature_; }
const NameVector& parameter_names() const {
return signature_.parameter_names;
}
bool HasReturnValue() const {
return !signature_.return_type.IsVoidOrNever();
}
void IncrementReturns() { ++returns_; }
bool HasReturns() const { return returns_; }
private:
std::string name_;
Scope* scope_;
Signature signature_;
size_t returns_;
};
class Macro : public Callable {
public:
Macro(const std::string& name, Scope* scope, const Signature& signature)
: Macro(Declarable::kMacro, name, scope, signature) {}
DECLARE_DECLARABLE_BOILERPLATE(Macro, macro);
void AddLabel(const LabelDeclaration& label) { labels_.push_back(label); }
const LabelDeclarationVector& GetLabels() { return labels_; }
protected:
Macro(Declarable::Kind type, const std::string& name, Scope* scope,
const Signature& signature)
: Callable(type, name, scope, signature) {}
private:
LabelDeclarationVector labels_;
};
class MacroList : public Declarable {
public:
MacroList() : Declarable(Declarable::kMacroList) {}
DECLARE_DECLARABLE_BOILERPLATE(MacroList, macro_list);
const std::vector<Macro*>& list() { return list_; }
void AddMacro(Macro* macro) { list_.push_back(macro); }
private:
std::vector<Macro*> list_;
};
class Builtin : public Callable {
public:
Builtin(const std::string& name, bool java_script, Scope* scope,
const Signature& signature)
: Callable(Declarable::kBuiltin, name, scope, signature),
java_script_(java_script) {}
DECLARE_DECLARABLE_BOILERPLATE(Builtin, builtin);
bool IsJavaScript() const { return java_script_; }
private:
bool java_script_;
};
class Runtime : public Callable {
public:
Runtime(const std::string& name, Scope* scope, const Signature& signature)
: Callable(Declarable::kRuntime, name, scope, signature) {}
DECLARE_DECLARABLE_BOILERPLATE(Runtime, runtime);
};
inline std::ostream& operator<<(std::ostream& os, const Callable& m) {
os << "macro " << m.signature().return_type << " " << m.name()
<< m.signature().parameter_types;
return os;
}
inline std::ostream& operator<<(std::ostream& os, const Variable& v) {
os << "variable " << v.name() << ": " << v.type();
return os;
}
inline std::ostream& operator<<(std::ostream& os, const Builtin& b) {
os << "builtin " << b.signature().return_type << " " << b.name()
<< b.signature().parameter_types;
return os;
}
inline std::ostream& operator<<(std::ostream& os, const Runtime& b) {
os << "runtime " << b.signature().return_type << " " << b.name()
<< b.signature().parameter_types;
return os;
}
#undef DECLARE_DECLARABLE_BOILERPLATE
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_DECLARABLE_H_

View File

@ -0,0 +1,209 @@
// Copyright 2017 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.
#include "src/torque/declaration-visitor.h"
namespace v8 {
namespace internal {
namespace torque {
void DeclarationVisitor::Visit(Expression* expr) {
switch (expr->kind) {
#define ENUM_ITEM(name) \
case AstNode::Kind::k##name: \
return Visit(name::cast(expr));
AST_EXPRESSION_NODE_KIND_LIST(ENUM_ITEM)
#undef ENUM_ITEM
default:
UNIMPLEMENTED();
}
}
void DeclarationVisitor::Visit(Statement* stmt) {
switch (stmt->kind) {
#define ENUM_ITEM(name) \
case AstNode::Kind::k##name: \
return Visit(name::cast(stmt));
AST_STATEMENT_NODE_KIND_LIST(ENUM_ITEM)
#undef ENUM_ITEM
default:
UNIMPLEMENTED();
}
}
void DeclarationVisitor::Visit(Declaration* decl) {
switch (decl->kind) {
#define ENUM_ITEM(name) \
case AstNode::Kind::k##name: \
return Visit(name::cast(decl));
AST_DECLARATION_NODE_KIND_LIST(ENUM_ITEM)
#undef ENUM_ITEM
default:
UNIMPLEMENTED();
}
}
void DeclarationVisitor::Visit(BuiltinDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of builtin " << decl->name;
}
Scope* enclosing_scope = TopScope();
Signature signature = MakeSignature(decl->parameters, decl->return_type, {});
Scope* new_scope = new Scope(global_context_);
Scope::Activator s(new_scope);
if (signature.types().size() == 0 ||
!signature.types()[0].Is(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());
}
if (global_context_.verbose()) {
std::cout << decl->name << " with signature " << signature << std::endl;
}
bool java_script = decl->javascript_linkage;
bool varargs = decl->parameters.has_varargs;
if (java_script != varargs) {
if (java_script) {
std::stringstream stream;
stream << "JavaScript builtin " << decl->name
<< " must have rest parameters at " << PositionAsString(decl->pos);
ReportError(stream.str());
} else {
std::stringstream stream;
stream << "builtin " << decl->name
<< " with rest parameters must be a JavaScript builtin at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
}
if (java_script && varargs) {
if (signature.types().size() < 2 ||
!signature.types()[1].Is(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());
}
}
if (varargs) {
TopScope()->DeclareConstant(decl->pos, decl->parameters.arguments_variable,
GetTypeOracle().GetArgumentsType(),
"arguments");
}
Builtin* builtin = enclosing_scope->DeclareBuiltin(
decl->pos, decl->name, java_script, new_scope, signature);
defined_builtins_.push_back(builtin);
DeclareParameterList(decl->pos, signature);
CurrentCallActivator activator(global_context_, builtin);
Visit(decl->body);
}
void DeclarationVisitor::Visit(MacroDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of macro " << decl->name;
}
Scope* enclosing_scope = TopScope();
Scope* new_scope = new Scope(global_context_);
Scope::Activator s(new_scope);
PushControlSplit();
Signature signature =
MakeSignature(decl->parameters, decl->return_type, decl->labels);
if (!signature.return_type.IsVoidOrNever()) {
TopScope()->DeclareVariable(decl->pos, kReturnValueVariable,
signature.return_type);
}
if (global_context_.verbose()) {
std::cout << " resulting in signature " << signature << "\n";
}
Macro* macro = enclosing_scope->DeclareMacro(decl->pos, decl->name, new_scope,
signature);
DeclareParameterList(decl->pos, signature);
CurrentCallActivator activator(global_context_, macro);
Visit(decl->body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(decl, changed_vars);
}
void DeclarationVisitor::Visit(ReturnStatement* stmt) {
const Callable* callable = global_context_.GetCurrentCallable();
if (callable->IsMacro() && callable->HasReturnValue()) {
MarkVariableModified(
Variable::cast(LookupValue(stmt->pos, kReturnValueVariable)));
}
}
void DeclarationVisitor::Visit(ForOfLoopStatement* stmt) {
// Scope for for iteration variable
Scope::Activator s(global_context_, stmt);
Visit(stmt->var_declaration);
Visit(stmt->iterable);
if (stmt->begin) Visit(*stmt->begin);
if (stmt->end) Visit(*stmt->end);
PushControlSplit();
Visit(stmt->body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
}
void DeclarationVisitor::Visit(TryCatchStatement* stmt) {
// Activate a new scope to declare catch handler labels, they should not be
// visible outside the catch.
{
Scope::Activator s(global_context_, stmt);
// Declare catch labels
for (LabelBlock* block : stmt->label_blocks) {
std::vector<Variable*> parameters;
{
Scope::Activator s(global_context_, block->body);
if (block->parameters.has_varargs) {
std::stringstream stream;
stream << "cannot use ... for label parameters at "
<< PositionAsString(stmt->pos);
ReportError(stream.str());
}
size_t i = 0;
for (auto p : block->parameters.names) {
parameters.push_back(TopScope()->DeclareVariable(
stmt->pos, p,
GetTypeOracle().GetType(block->parameters.types[i])));
++i;
}
}
Label* shared_label = new Label(block->label, parameters);
TopScope()->DeclareLabel(stmt->pos, block->label, shared_label);
if (global_context_.verbose()) {
std::cout << " declaring catch for exception " << block->label << "\n";
}
}
// Try catch not supported yet
DCHECK_EQ(stmt->catch_blocks.size(), 0);
Visit(stmt->try_block);
}
for (CatchBlock* block : stmt->catch_blocks) {
Visit(block->body);
}
}
} // namespace torque
} // namespace internal
} // namespace v8

View File

@ -0,0 +1,405 @@
// Copyright 2017 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_DECLARATION_VISITOR_H_
#define V8_TORQUE_DECLARATION_VISITOR_H_
#include <set>
#include <string>
#include "src/torque/file-visitor.h"
#include "src/torque/global-context.h"
#include "src/torque/scope.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
class DeclarationVisitor : public FileVisitor {
public:
explicit DeclarationVisitor(GlobalContext& global_context)
: FileVisitor(global_context) {
GetTypeOracle().RegisterTypeImpl(EXCEPTION_TYPE_STRING, "Label*", nullptr);
}
void Visit(Ast* ast) { Visit(ast->GetDefaultModule()); }
void Visit(Expression* expr);
void Visit(Statement* stmt);
void Visit(Declaration* decl);
void Visit(ModuleDeclaration* decl) {
Module* saved_module = module_;
module_ = decl->GetModule();
Scope::Activator activator(module_->scope());
for (Declaration* child : decl->declarations) Visit(child);
module_ = saved_module;
}
void Visit(DefaultModuleDeclaration* decl) {
decl->SetModule(global_context_.GetDefaultModule());
Visit(base::implicit_cast<ModuleDeclaration*>(decl));
}
void Visit(ExplicitModuleDeclaration* decl) {
decl->SetModule(global_context_.GetModule(decl->name));
Visit(base::implicit_cast<ModuleDeclaration*>(decl));
}
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(ElementAccessExpression* expr) {
Visit(expr->array);
Visit(expr->index);
}
void Visit(FieldAccessExpression* expr) { Visit(expr->object); }
void Visit(CastExpression* expr) { Visit(expr->value); }
void Visit(ConvertExpression* expr) { Visit(expr->value); }
void Visit(BlockStatement* expr) {
Scope::Activator s(global_context_, expr);
for (Statement* stmt : expr->statements) Visit(stmt);
}
void Visit(ExpressionStatement* stmt) { Visit(stmt->expression); }
void Visit(TailCallStatement* stmt) { Visit(stmt->call); }
void Visit(TypeDeclaration* decl) {
std::string generates_class_name =
decl->generates ? *decl->generates : decl->name;
GetTypeOracle().RegisterTypeImpl(decl->name, generates_class_name,
decl->extends ? &*decl->extends : nullptr);
}
void Visit(ExternalBuiltinDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of external builtin " << decl->name
<< " with signature ";
}
Signature signature =
MakeSignature(decl->parameters, decl->return_type, {});
if (signature.parameter_types.types.size() == 0 ||
!signature.parameter_types.types[0].Is(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());
}
if (decl->javascript_linkage != decl->parameters.has_varargs) {
if (decl->javascript_linkage) {
std::stringstream stream;
stream << "JavaScript builtin " << decl->name
<< " must have rest parameters at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
} else {
std::stringstream stream;
stream << "builtin " << decl->name
<< " with rest parameters must be a JavaScript builtin at "
<< PositionAsString(decl->pos);
ReportError(stream.str());
}
}
if (decl->javascript_linkage && decl->parameters.has_varargs) {
if (signature.types().size() < 2 ||
!signature.types()[1].Is(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());
}
}
TopScope()->DeclareBuiltin(decl->pos, decl->name, decl->javascript_linkage,
nullptr, signature);
}
void Visit(ExternalRuntimeDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of external runtime " << decl->name
<< " with signature ";
}
Type return_type = GetType(decl->return_type);
TypeVector parameter_types = GetTypeVector(decl->parameters.types);
if (parameter_types.size() == 0 ||
!parameter_types[0].Is(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());
}
Signature signature{{},
{parameter_types, decl->parameters.has_varargs},
return_type,
{},
{}};
TopScope()->DeclareRuntime(decl->pos, decl->name, nullptr,
std::move(signature));
}
void Visit(ExternalMacroDeclaration* decl) {
if (global_context_.verbose()) {
std::cout << "found declaration of external macro " << decl->name
<< " with signature ";
}
Signature signature =
MakeSignature(decl->parameters, decl->return_type, decl->labels);
TopScope()->DeclareMacro(decl->pos, decl->name, nullptr, 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 Visit(BuiltinDeclaration* decl);
void Visit(MacroDeclaration* decl);
void Visit(ReturnStatement* stmt);
void Visit(VarDeclarationStatement* stmt) {
std::string variable_name = stmt->name;
Type type = GetType(stmt->type);
TopScope()->DeclareVariable(stmt->pos, variable_name, type);
if (global_context_.verbose()) {
std::cout << "declared variable " << variable_name << " with type "
<< type << "\n";
}
if (stmt->initializer) {
Visit(*stmt->initializer);
if (global_context_.verbose()) {
std::cout << "variable has initialization expression at "
<< PositionAsString(stmt->pos) << "\n";
}
}
}
void Visit(ConstDeclaration* decl) {
TopScope()->DeclareConstant(decl->pos, decl->name, GetType(decl->type),
decl->literal);
}
void Visit(LogicalOrExpression* expr) {
{
Scope::Activator s(global_context_, expr->left);
TopScope()->DeclareLabel(expr->pos, kFalseLabelName);
Visit(expr->left);
}
Visit(expr->right);
}
void Visit(LogicalAndExpression* expr) {
{
Scope::Activator s(global_context_, expr->left);
TopScope()->DeclareLabel(expr->pos, kTrueLabelName);
Visit(expr->left);
}
Visit(expr->right);
}
void DeclareExpressionForBranch(Expression* node) {
Scope::Activator s(global_context_, node);
// Conditional expressions can either explicitly return a bit
// type, or they can be backed by macros that don't return but
// take a true and false label. By declaring the labels before
// visiting the conditional expression, those label-based
// macro conditionals will be able to find them through normal
// label lookups.
TopScope()->DeclareLabel(node->pos, kTrueLabelName);
TopScope()->DeclareLabel(node->pos, kFalseLabelName);
Visit(node);
}
void Visit(ConditionalExpression* expr) {
DeclareExpressionForBranch(expr->condition);
PushControlSplit();
Visit(expr->if_true);
Visit(expr->if_false);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(expr, changed_vars);
}
void Visit(IfStatement* stmt) {
PushControlSplit();
DeclareExpressionForBranch(stmt->condition);
Visit(stmt->if_true);
if (stmt->if_false) Visit(*stmt->if_false);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
}
void Visit(WhileStatement* stmt) {
Scope::Activator s(global_context_, stmt);
DeclareExpressionForBranch(stmt->condition);
PushControlSplit();
Visit(stmt->body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
}
void Visit(ForOfLoopStatement* stmt);
void Visit(AssignmentExpression* expr) {
MarkLocationModified(expr->location);
Visit(expr->location);
Visit(expr->value);
}
void Visit(BreakStatement* stmt) {}
void Visit(ContinueStatement* stmt) {}
void Visit(GotoStatement* expr) {}
void Visit(ForLoopStatement* stmt) {
Scope::Activator s(global_context_, stmt);
if (stmt->var_declaration) Visit(*stmt->var_declaration);
PushControlSplit();
DeclareExpressionForBranch(stmt->test);
Visit(stmt->body);
Visit(stmt->action);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
}
void Visit(IncrementDecrementExpression* expr) {
MarkLocationModified(expr->location);
Visit(expr->location);
}
void Visit(TryCatchStatement* stmt);
void GenerateHeader(std::string& file_name) {
std::stringstream new_contents_stream;
new_contents_stream
<< "#ifndef V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n"
"#define V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n"
"\n"
"#define BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) "
"\\\n";
for (auto builtin : defined_builtins_) {
bool first = true;
if (builtin->IsJavaScript()) {
new_contents_stream
<< "TFJ(" << builtin->name()
<< ", SharedFunctionInfo::kDontAdaptArgumentsSentinel";
} else {
new_contents_stream << "TFS(" << builtin->name();
for (auto parameter : builtin->parameter_names()) {
if (first) {
first = false;
} else {
new_contents_stream << ", k" << CamelifyString(parameter);
}
}
}
new_contents_stream << ") \\\n";
}
new_contents_stream
<< "\n"
"#endif // V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n";
std::string new_contents(new_contents_stream.str());
ReplaceFileContentsIfDifferent(file_name, new_contents);
}
private:
struct LiveAndChanged {
std::set<const Variable*> live;
std::set<const Variable*> changed;
};
void PushControlSplit() {
LiveAndChanged live_and_changed;
live_and_changed.live = global_context_.GetLiveTypeVariables();
live_and_changed_variables_.push_back(live_and_changed);
}
std::set<const Variable*> PopControlSplit() {
auto result = live_and_changed_variables_.back().changed;
live_and_changed_variables_.pop_back();
return result;
}
void MarkLocationModified(Expression* location) {
if (IdentifierExpression* id = IdentifierExpression::cast(location)) {
const Value* value = LookupValue(id->pos, id->name);
if (value->IsVariable()) {
const Variable* variable = Variable::cast(value);
bool was_live = MarkVariableModified(variable);
if (was_live && global_context_.verbose()) {
std::cout << *variable << " was modified in control split at "
<< PositionAsString(id->pos) << "\n";
}
}
}
}
bool MarkVariableModified(const Variable* variable) {
auto e = live_and_changed_variables_.rend();
auto c = live_and_changed_variables_.rbegin();
bool was_live_in_preceeding_split = false;
while (c != e) {
if (c->live.find(variable) != c->live.end()) {
c->changed.insert(variable);
was_live_in_preceeding_split = true;
}
c++;
}
return was_live_in_preceeding_split;
}
void DeclareParameterList(SourcePosition pos, const Signature& signature) {
auto name_iterator = signature.parameter_names.begin();
for (auto t : signature.types()) {
const std::string& name(*name_iterator++);
TopScope()->DeclareParameter(pos, name,
GetParameterVariableFromName(name), t);
}
size_t i = 0;
for (auto definition : signature.label_defintions) {
TopScope()->DeclareLabel(pos, definition.name, signature.labels[i++]);
}
}
std::vector<Builtin*> defined_builtins_;
std::vector<LiveAndChanged> live_and_changed_variables_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_DECLARATION_VISITOR_H_

View File

@ -0,0 +1,42 @@
// Copyright 2017 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.
#include "src/torque/file-visitor.h"
#include "src/torque/declarable.h"
namespace v8 {
namespace internal {
namespace torque {
Signature FileVisitor::MakeSignature(const ParameterList& parameters,
const std::string& return_type,
const LabelAndTypesVector& labels) {
LabelDeclarationVector definition_vector;
for (auto label : labels) {
LabelDeclaration def = {label.name, GetTypeVector(label.types)};
definition_vector.push_back(def);
}
Signature result{parameters.names,
{GetTypeVector(parameters.types), parameters.has_varargs},
GetType(return_type),
definition_vector,
{}};
for (auto label : labels) {
auto label_params = GetTypeVector(label.types);
std::vector<Variable*> vars;
size_t i = 0;
for (auto var_type : label_params) {
std::string name = label.name + std::to_string(i++);
Variable* var = new Variable(label.name, name, var_type);
vars.push_back(var);
}
result.labels.push_back(new Label(label.name, vars));
}
return result;
}
} // namespace torque
} // namespace internal
} // namespace v8

168
src/torque/file-visitor.h Normal file
View File

@ -0,0 +1,168 @@
// Copyright 2017 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_FILE_VISITOR_H_
#define V8_TORQUE_FILE_VISITOR_H_
#include <string>
#include "src/torque/ast.h"
#include "src/torque/global-context.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
#include "src/torque/TorqueBaseVisitor.h"
namespace v8 {
namespace internal {
namespace torque {
class FileVisitor {
public:
explicit FileVisitor(GlobalContext& global_context)
: global_context_(global_context),
module_(global_context.GetDefaultModule()) {
global_context_.PushScope(module_->scope());
}
Type GetType(const std::string& s) { return GetTypeOracle().GetType(s); }
TypeVector GetTypeVector(const std::vector<std::string>& v) {
TypeVector result;
for (const std::string& s : v) {
result.push_back(GetType(s));
}
return result;
}
Scope* TopScope() { return global_context_.TopScope(); }
Ast* ast() { return global_context_.ast(); }
protected:
static constexpr const char* kTrueLabelName = "True";
static constexpr const char* kFalseLabelName = "False";
static constexpr const char* kReturnValueVariable = "return";
static constexpr const char* kConditionValueVariable = "condition";
static constexpr const char* kBreakLabelName = "break";
static constexpr const char* kDoneLabelName = "done";
static constexpr const char* kContinueLabelName = "continue";
static constexpr const char* kForIndexValueVariable = "for_index";
Module* CurrentModule() const { return module_; }
TypeOracle& GetTypeOracle() { return global_context_.GetTypeOracle(); }
bool IsValueDeclared(const std::string& id) {
return global_context_.Lookup(id) != nullptr;
}
Value* LookupValue(SourcePosition pos, const std::string& id) {
Declarable* declarable = global_context_.Lookup(id);
if (declarable != nullptr) {
if (declarable->IsValue()) {
return Value::cast(declarable);
}
ReportError(id + " referenced at " + PositionAsString(pos) +
" is not a variable, parameter or verbatim");
}
ReportError(std::string("identifier ") + id + " referenced at " +
PositionAsString(pos) + " is not defined");
return nullptr;
}
Callable* LookupCall(SourcePosition pos, const std::string& name,
const TypeVector& parameter_types) {
Callable* result = nullptr;
Declarable* declarable = global_context_.Lookup(name);
if (declarable != nullptr) {
if (declarable->IsBuiltin()) {
result = Builtin::cast(declarable);
} else if (declarable->IsRuntime()) {
result = Runtime::cast(declarable);
} else if (declarable->IsMacroList()) {
for (auto m : MacroList::cast(declarable)->list()) {
if (GetTypeOracle().IsCompatibleSignature(
m->signature().parameter_types, parameter_types)) {
result = m;
break;
}
}
}
}
if (result == nullptr) {
std::stringstream stream;
stream << "cannot find macro, builtin or runtime call " << name
<< " matching parameter types " << parameter_types;
ReportError(stream.str());
}
size_t caller_size = parameter_types.size();
size_t callee_size = result->signature().types().size();
if (caller_size != callee_size &&
!result->signature().parameter_types.var_args) {
std::stringstream stream;
stream << "parameter count mismatch calling " << *result << ": expected "
<< std::to_string(callee_size) << ", found "
<< std::to_string(caller_size);
ReportError(stream.str());
}
return result;
}
Macro* LookupMacro(SourcePosition pos, const std::string& name,
const TypeVector& types) {
Declarable* declarable = global_context_.Lookup(name);
if (declarable != nullptr) {
if (declarable->IsMacroList()) {
for (auto m : MacroList::cast(declarable)->list()) {
if (m->signature().parameter_types.types == types &&
!m->signature().parameter_types.var_args) {
return m;
}
}
}
}
std::stringstream stream;
stream << "macro " << name << " with parameter types " << types
<< " referenced at " << PositionAsString(pos) << " is not defined";
ReportError(stream.str());
return nullptr;
}
Builtin* LookupBuiltin(const SourcePosition& pos, const std::string& name) {
Declarable* declarable = global_context_.Lookup(name);
if (declarable != nullptr) {
if (declarable->IsBuiltin()) {
return Builtin::cast(declarable);
}
ReportError(name + " referenced at " + PositionAsString(pos) +
" is not a builtin");
}
ReportError(std::string("builtin ") + name + " referenced at " +
PositionAsString(pos) + " is not defined");
return nullptr;
}
std::string GetParameterVariableFromName(const std::string& name) {
return std::string("p_") + name;
}
std::string PositionAsString(SourcePosition pos) {
return global_context_.PositionAsString(pos);
}
Signature MakeSignature(const ParameterList& parameters,
const std::string& return_type,
const LabelAndTypesVector& exceptions);
GlobalContext& global_context_;
Callable* current_callable_;
Module* module_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_FILE_VISITOR_H_

191
src/torque/global-context.h Normal file
View File

@ -0,0 +1,191 @@
// Copyright 2017 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_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/scope.h"
#include "src/torque/type-oracle.h"
namespace v8 {
namespace internal {
namespace torque {
class GlobalContext;
class Scope;
class TypeOracle;
class Module {
public:
Module(const std::string& name, GlobalContext& context)
: name_(name), scope_(context) {}
const std::string& name() const { return name_; }
std::ostream& source_stream() { return source_stream_; }
std::ostream& header_stream() { return header_stream_; }
std::string source() { return source_stream_.str(); }
std::string header() { return header_stream_.str(); }
Scope* scope() { return &scope_; }
private:
std::string name_;
Scope scope_;
std::stringstream header_stream_;
std::stringstream source_stream_;
};
class OperationHandler {
public:
std::string macro_name;
ParameterTypes parameter_types;
Type result_type;
};
struct SourceFileContext {
std::string name;
antlr4::ANTLRFileStream* stream;
TorqueLexer* lexer;
antlr4::CommonTokenStream* tokens;
TorqueParser* parser;
TorqueParser::FileContext* file;
std::string sourceFileAndLineNumber(antlr4::ParserRuleContext* context) {
antlr4::misc::Interval i = context->getSourceInterval();
auto token = tokens->get(i.a);
size_t line = token->getLine();
size_t pos = token->getCharPositionInLine();
return name + ":" + std::to_string(line) + ":" + std::to_string(pos);
}
};
class GlobalContext {
public:
explicit GlobalContext(Ast ast)
: verbose_(false),
next_scope_number_(0),
next_label_number_(0),
default_module_(GetModule("base")),
ast_(std::move(ast)) {}
Module* GetDefaultModule() { return default_module_; }
Module* GetModule(const std::string& name) {
auto i = modules_.find(name);
if (i != modules_.end()) {
return i->second;
}
Module* module = new Module(name, *this);
modules_[name] = module;
return module;
}
int GetNextScopeNumber() { return next_scope_number_++; }
int GetNextLabelNumber() { return next_label_number_++; }
const std::map<std::string, Module*>& GetModules() const { return modules_; }
Scope* GetParserRuleContextScope(const AstNode* context) {
auto i = context_scopes_.find(context);
if (i != context_scopes_.end()) return i->second;
Scope* new_scope = new Scope(*this);
context_scopes_[context] = new_scope;
return new_scope;
}
Scope* TopScope() const { return scopes_.back(); }
Declarable* Lookup(const std::string& name) const {
auto e = scopes_.rend();
auto c = scopes_.rbegin();
while (c != e) {
Declarable* result = (*c)->Lookup(name);
if (result != nullptr) return result;
++c;
}
return nullptr;
}
void PushScope(Scope* scope) { scopes_.push_back(scope); }
void PopScope() { scopes_.pop_back(); }
std::set<const Variable*> GetLiveTypeVariables() {
std::set<const Variable*> result;
for (auto scope : scopes_) {
scope->AddLiveVariables(result);
}
return result;
}
void SetVerbose() { verbose_ = true; }
bool verbose() const { return verbose_; }
void AddControlSplitChangedVariables(const AstNode* node,
const std::set<const Variable*>& vars) {
control_split_changed_variables_[node] = vars;
}
const std::set<const Variable*>& GetControlSplitChangedVariables(
const AstNode* node) {
assert(control_split_changed_variables_.find(node) !=
control_split_changed_variables_.end());
return control_split_changed_variables_.find(node)->second;
}
void MarkVariableChanged(const AstNode* node, Variable* var) {
control_split_changed_variables_[node].insert(var);
}
friend class CurrentCallActivator;
TypeOracle& GetTypeOracle() { return type_oracle_; }
Callable* GetCurrentCallable() const { return current_callable_; }
std::map<std::string, std::vector<OperationHandler>> op_handlers_;
void PrintScopeChain() {
for (auto s : scopes_) {
s->Print();
}
}
std::string PositionAsString(SourcePosition pos) {
return ast_.PositionAsString(pos);
}
Ast* ast() { return &ast_; }
private:
bool verbose_;
int next_scope_number_;
int next_label_number_;
std::map<std::string, Module*> modules_;
Module* default_module_;
std::vector<Scope*> scopes_;
TypeOracle type_oracle_;
Callable* current_callable_;
std::map<const AstNode*, std::set<const Variable*>>
control_split_changed_variables_;
std::map<const AstNode*, Scope*> context_scopes_;
Ast ast_;
};
class CurrentCallActivator {
public:
CurrentCallActivator(GlobalContext& context, Callable* callable)
: context_(context) {
context_.current_callable_ = callable;
}
~CurrentCallActivator() { context_.current_callable_ = nullptr; }
private:
GlobalContext& context_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_GLOBAL_CONTEXT_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,241 @@
// Copyright 2017 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_IMPLEMENTATION_VISITOR_H_
#define V8_TORQUE_IMPLEMENTATION_VISITOR_H_
#include <string>
#include "src/torque/ast.h"
#include "src/torque/file-visitor.h"
#include "src/torque/global-context.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
struct LocationReference {
LocationReference(Value* v, VisitResult b, VisitResult i)
: value(v), base(b), index(i) {}
Value* value;
VisitResult base;
VisitResult index;
};
class ImplementationVisitor : public FileVisitor {
public:
explicit ImplementationVisitor(GlobalContext& global_context)
: FileVisitor(global_context), indent_(0), next_temp_(0) {}
void Visit(Ast* ast) { Visit(ast->GetDefaultModule()); }
VisitResult Visit(Expression* expr);
Type Visit(Statement* stmt);
void Visit(Declaration* decl);
LocationReference GetLocationReference(LocationExpression* location);
LocationReference GetLocationReference(IdentifierExpression* expr) {
return LocationReference(LookupValue(expr->pos, expr->name), {}, {});
}
LocationReference GetLocationReference(FieldAccessExpression* expr) {
return LocationReference({}, Visit(expr->object), {});
}
LocationReference GetLocationReference(ElementAccessExpression* expr) {
return LocationReference({}, Visit(expr->array), Visit(expr->index));
}
VisitResult GenerateFetchFromLocation(LocationExpression* location,
LocationReference reference);
VisitResult GenerateFetchFromLocation(IdentifierExpression* expr,
LocationReference reference) {
Value* value = reference.value;
if (value->IsVariable() && !Variable::cast(value)->IsDefined()) {
std::stringstream s;
s << "\"" << value->name() << "\" is used before it is defined at "
<< PositionAsString(expr->pos);
ReportError(s.str());
}
return VisitResult({value->type(), value->GetValueForRead()});
}
VisitResult GenerateFetchFromLocation(FieldAccessExpression* expr,
LocationReference reference) {
Arguments arguments;
arguments.parameters = {reference.base};
return GenerateOperation(expr->pos, std::string(".") + expr->field,
arguments);
}
VisitResult GenerateFetchFromLocation(ElementAccessExpression* expr,
LocationReference reference) {
Arguments arguments;
arguments.parameters = {reference.base, reference.index};
return GenerateOperation(expr->pos, "[]", arguments);
}
VisitResult Visit(IdentifierExpression* expr) {
return GenerateFetchFromLocation(expr, GetLocationReference(expr));
}
VisitResult Visit(FieldAccessExpression* expr) {
return GenerateFetchFromLocation(expr, GetLocationReference(expr));
}
VisitResult Visit(ElementAccessExpression* expr) {
return GenerateFetchFromLocation(expr, GetLocationReference(expr));
}
VisitResult Visit(CastExpression* expr);
VisitResult Visit(ConvertExpression* expr);
void Visit(ModuleDeclaration* decl);
void Visit(DefaultModuleDeclaration* decl) {
Visit(base::implicit_cast<ModuleDeclaration*>(decl));
}
void Visit(ExplicitModuleDeclaration* decl) {
Visit(base::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) {}
VisitResult Visit(CallExpression* expr, bool is_tail = false);
Type Visit(TailCallStatement* stmt);
VisitResult Visit(ConditionalExpression* expr);
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);
VisitResult Visit(NumberLiteralExpression* expr);
Type Visit(TryCatchStatement* stmt);
Type Visit(ReturnStatement* stmt);
Type Visit(GotoStatement* stmt);
Type Visit(IfStatement* stmt);
Type Visit(WhileStatement* stmt);
Type Visit(BreakStatement* stmt);
Type Visit(ContinueStatement* stmt);
Type Visit(ForLoopStatement* stmt);
Type Visit(VarDeclarationStatement* stmt);
Type Visit(ForOfLoopStatement* stmt);
Type Visit(BlockStatement* block);
Type Visit(ExpressionStatement* stmt);
Label* GetLabel(SourcePosition pos, const std::string& label);
void GenerateImplementation(const std::string& dir, Module* module);
private:
std::string GetBaseAssemblerName(Module* module);
std::string GetDSLAssemblerName(Module* module);
void GenerateIndent();
class ScopedIndent {
public:
explicit ScopedIndent(ImplementationVisitor* visitor, bool new_lines = true)
: new_lines_(new_lines), visitor_(visitor) {
if (new_lines) visitor->GenerateIndent();
visitor->source_out() << "{";
if (new_lines) visitor->source_out() << std::endl;
visitor->indent_++;
}
~ScopedIndent() {
visitor_->indent_--;
visitor_->GenerateIndent();
visitor_->source_out() << "}";
if (new_lines_) visitor_->source_out() << std::endl;
}
private:
bool new_lines_;
ImplementationVisitor* visitor_;
};
void GenerateChangedVarsFromControlSplit(AstNode* node);
Type GetCommonType(SourcePosition pos, Type left, Type right);
VisitResult GenerateCopy(const VisitResult& to_copy);
void GenerateAssignToVariable(SourcePosition pos, Variable* var,
VisitResult value);
void GenerateAssignToLocation(LocationExpression* location,
const LocationReference& reference,
VisitResult assignment_value);
Variable* GenerateVariableDeclaration(
AstNode* node, const std::string& name, const base::Optional<Type>& type,
const base::Optional<VisitResult>& initialization = {});
void GenerateParameter(SourcePosition pos, const std::string& parameter_name);
void GenerateParameterList(SourcePosition pos, const NameVector& list,
size_t first = 0);
VisitResult GenerateCall(SourcePosition pos, const std::string& callable_name,
const Arguments& parameters, bool tail_call);
bool GenerateLabeledStatementBlocks(
const std::vector<Statement*>& blocks,
const std::vector<Label*>& statement_labels, Label* merge_label);
void GenerateBranch(const VisitResult& condition, Label* true_label,
Label* false_label);
bool GenerateExpressionBranch(Expression* expression,
const std::vector<Label*>& statement_labels,
const std::vector<Statement*>& statement_blocks,
Label* merge_label);
void GenerateMacroFunctionDeclaration(std::ostream& o, SourcePosition pos,
const std::string& macro_prefix,
Macro* macro);
VisitResult GenerateOperation(SourcePosition pos,
const std::string& operation,
Arguments arguments,
base::Optional<Type> return_type = {});
VisitResult GenerateImplicitConvert(SourcePosition pos, Type destination_type,
VisitResult source);
std::string NewTempVariable();
std::string GenerateNewTempVariable(Type type);
void GenerateLabelDefinition(Label* label, AstNode* node = nullptr);
void GenerateLabelBind(Label* label);
void GenerateLabelGoto(Label* label);
std::vector<Label*> LabelsFromIdentifiers(
SourcePosition pos, const std::vector<std::string>& names);
std::ostream& source_out() { return module_->source_stream(); }
std::ostream& header_out() { return module_->header_stream(); }
size_t indent_;
int32_t next_temp_;
std::ostream* current_source_out_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_IMPLEMENTATION_VISITOR_H_

151
src/torque/scope.cc Normal file
View File

@ -0,0 +1,151 @@
// Copyright 2017 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.
#include <fstream>
#include <iostream>
#include <string>
#include "src/torque/global-context.h"
#include "src/torque/scope.h"
namespace v8 {
namespace internal {
namespace torque {
Scope::Scope(GlobalContext& global_context)
: global_context_(global_context),
scope_number_(global_context.GetNextScopeNumber()) {}
Macro* Scope::DeclareMacro(SourcePosition pos, const std::string& name,
Scope* scope, const Signature& signature) {
auto i = lookup_.find(name);
if (i == lookup_.end()) {
lookup_[name] = new MacroList();
i = lookup_.find(name);
} else if (i->second->kind() != Declarable::kMacroList) {
std::stringstream s;
s << "cannot redeclare " << name << " as a non-macro at "
<< global_context_.PositionAsString(pos);
ReportError(s.str());
}
MacroList* macro_list = MacroList::cast(i->second);
for (auto macro : macro_list->list()) {
if (signature.parameter_types.types ==
macro->signature().parameter_types.types &&
signature.parameter_types.var_args ==
macro->signature().parameter_types.var_args) {
std::stringstream s;
s << "cannot redeclare " << name
<< " as a macro with identical parameter list "
<< signature.parameter_types << global_context_.PositionAsString(pos);
ReportError(s.str());
}
}
Macro* result = new Macro(name, scope, signature);
macro_list->AddMacro(result);
if (global_context_.verbose()) {
std::cout << "declared " << *result << "\n";
}
return result;
}
Builtin* Scope::DeclareBuiltin(SourcePosition pos, const std::string& name,
bool java_script, Scope* scope,
const Signature& signature) {
CheckAlreadyDeclared(pos, name, "builtin");
Builtin* result = new Builtin(name, java_script, scope, signature);
lookup_[name] = result;
if (global_context_.verbose()) {
std::cout << "declared " << *result << "\n";
}
return result;
}
Runtime* Scope::DeclareRuntime(SourcePosition pos, const std::string& name,
Scope* scope, const Signature& signature) {
CheckAlreadyDeclared(pos, name, "runtime");
Runtime* result = new Runtime(name, scope, signature);
lookup_[name] = result;
if (global_context_.verbose()) {
std::cout << "declared " << *result << "\n";
}
return result;
}
Variable* Scope::DeclareVariable(SourcePosition pos, const std::string& var,
Type type) {
std::string name(std::string("v") + "_" + var +
std::to_string(scope_number_));
CheckAlreadyDeclared(pos, var, "variable");
Variable* result = new Variable(var, name, type);
lookup_[var] = result;
if (global_context_.verbose()) {
std::cout << "declared " << var << " (type " << type << ")\n";
}
return result;
}
Parameter* Scope::DeclareParameter(SourcePosition pos, const std::string& name,
const std::string& var_name, Type type) {
CheckAlreadyDeclared(pos, name, "parameter");
Parameter* result = new Parameter(name, type, var_name);
lookup_[name] = result;
return result;
}
Label* Scope::DeclareLabel(SourcePosition pos, const std::string& name,
Label* already_defined) {
CheckAlreadyDeclared(pos, name, "label");
Label* result =
already_defined == nullptr ? new Label(name) : already_defined;
lookup_[name] = result;
return result;
}
void Scope::DeclareConstant(SourcePosition pos, const std::string& name,
Type type, const std::string& value) {
CheckAlreadyDeclared(pos, name, "constant, parameter or arguments");
lookup_[name] = new Constant(name, type, value);
}
void Scope::AddLiveVariables(std::set<const Variable*>& set) {
for (auto current : lookup_) {
if (current.second->IsVariable()) {
set.insert(Variable::cast(current.second));
}
}
}
void Scope::CheckAlreadyDeclared(SourcePosition pos, const std::string& name,
const char* new_type) {
auto i = lookup_.find(name);
if (i != lookup_.end()) {
std::stringstream s;
s << "cannot redeclare " << name << " (type " << new_type << ") at "
<< global_context_.PositionAsString(pos)
<< " (it's already declared as a " << i->second->type_name() << ")\n";
ReportError(s.str());
}
}
void Scope::Print() {
std::cout << "scope #" << std::to_string(scope_number_) << "\n";
for (auto i : lookup_) {
std::cout << i.first << ": " << i.second << "\n";
}
}
Scope::Activator::Activator(Scope* scope) : scope_(scope) {
scope->global_context().PushScope(scope);
}
Scope::Activator::Activator(GlobalContext& global_context, const AstNode* node)
: Activator(global_context.GetParserRuleContextScope(node)) {}
Scope::Activator::~Activator() { scope_->global_context().PopScope(); }
} // namespace torque
} // namespace internal
} // namespace v8

106
src/torque/scope.h Normal file
View File

@ -0,0 +1,106 @@
// Copyright 2017 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_SCOPE_H_
#define V8_TORQUE_SCOPE_H_
#include <string>
#include "./antlr4-runtime.h"
#include "src/torque/ast.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
class Builtin;
class Callable;
class Declarable;
class GlobalContext;
class Macro;
class Parameter;
class Runtime;
class Variable;
class Scope {
public:
explicit Scope(GlobalContext& global_context);
Macro* DeclareMacro(SourcePosition pos, const std::string& name, Scope* scope,
const Signature& signature);
Builtin* DeclareBuiltin(SourcePosition pos, const std::string& name,
bool java_script, Scope* scope,
const Signature& signature);
Runtime* DeclareRuntime(SourcePosition pos, const std::string& name,
Scope* scope, const Signature& signature);
Variable* DeclareVariable(SourcePosition pos, const std::string& var,
Type type);
Parameter* DeclareParameter(SourcePosition pos, const std::string& name,
const std::string& mangled_name, Type type);
Label* DeclareLabel(SourcePosition pos, const std::string& name,
Label* already_defined = nullptr);
void DeclareConstant(SourcePosition pos, const std::string& name, Type type,
const std::string& value);
Declarable* Lookup(const std::string& name) {
auto i = lookup_.find(name);
if (i == lookup_.end()) {
return nullptr;
}
return i->second;
}
void Stream(std::ostream& stream) const {
stream << "scope " << std::to_string(scope_number_) << " {";
for (auto c : lookup_) {
stream << c.first << ",";
}
stream << "}";
}
GlobalContext& global_context() const { return global_context_; }
void AddLiveVariables(std::set<const Variable*>& set);
void Print();
class Activator;
private:
void CheckAlreadyDeclared(SourcePosition pos, const std::string& name,
const char* new_type);
GlobalContext& global_context_;
int scope_number_;
std::map<std::string, Declarable*> lookup_;
};
class Scope::Activator {
public:
explicit Activator(GlobalContext& global_context, const AstNode* node);
explicit Activator(Scope* scope);
~Activator();
private:
Scope* scope_;
};
inline std::ostream& operator<<(std::ostream& os, const Scope& scope) {
scope.Stream(os);
return os;
}
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_SCOPE_H_

108
src/torque/torque.cc Normal file
View File

@ -0,0 +1,108 @@
// Copyright 2017 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.
#include <iostream>
#include "./antlr4-runtime.h"
#include "src/torque/TorqueBaseVisitor.h"
#include "src/torque/TorqueLexer.h"
#include "src/torque/ast-generator.h"
#include "src/torque/declarable.h"
#include "src/torque/declaration-visitor.h"
#include "src/torque/global-context.h"
#include "src/torque/implementation-visitor.h"
#include "src/torque/scope.h"
#include "src/torque/type-oracle.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
size_t Label::next_id_ = 0;
class FailedParseErrorStrategy : public antlr4::DefaultErrorStrategy {
public:
FailedParseErrorStrategy() : DefaultErrorStrategy(), failed_(false) {}
void reportError(antlr4::Parser* recognizer,
const antlr4::RecognitionException& e) override {
antlr4::DefaultErrorStrategy::reportError(recognizer, e);
failed_ = true;
}
bool FailedParse() const { return failed_; }
public:
bool failed_;
};
int WrappedMain(int argc, const char** argv) {
std::string output_directory;
std::vector<SourceFileContext> file_contexts;
AstGenerator ast_generator;
SourceFileContext context;
size_t lexer_errors = 0;
auto error_strategy = std::make_shared<FailedParseErrorStrategy>();
bool verbose = false;
for (int i = 1; i < argc; ++i) {
// Check for options
if (!strcmp("-o", argv[i])) {
output_directory = argv[++i];
continue;
}
if (!strcmp("-v", argv[i])) {
verbose = true;
continue;
}
// Otherwise it's a .tq
// file, parse it and
// remember the syntax tree
context.name = argv[i];
context.stream = new antlr4::ANTLRFileStream(context.name.c_str());
context.lexer = new TorqueLexer(context.stream);
context.tokens = new antlr4::CommonTokenStream(context.lexer);
context.tokens->fill();
lexer_errors += context.lexer->getNumberOfSyntaxErrors();
context.parser = new TorqueParser(context.tokens);
context.parser->setErrorHandler(error_strategy);
context.file = context.parser->file();
ast_generator.visitSourceFile(&context);
}
if (lexer_errors != 0 || error_strategy->FailedParse()) {
return -1;
}
GlobalContext global_context(std::move(ast_generator).GetAst());
if (verbose) global_context.SetVerbose();
if (output_directory.length() != 0) {
{
DeclarationVisitor visitor(global_context);
visitor.Visit(global_context.ast());
std::string output_header_path = output_directory;
output_header_path += "/builtin-definitions-from-dsl.h";
visitor.GenerateHeader(output_header_path);
}
ImplementationVisitor visitor(global_context);
visitor.Visit(global_context.ast());
for (auto& module : global_context.GetModules()) {
visitor.GenerateImplementation(output_directory, module.second);
}
}
return 0;
}
} // namespace torque
} // namespace internal
} // namespace v8
int main(int argc, const char** argv) {
return v8::internal::torque::WrappedMain(argc, argv);
}

110
src/torque/type-oracle.h Normal file
View File

@ -0,0 +1,110 @@
// Copyright 2017 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_TYPE_ORACLE_H_
#define V8_TORQUE_TYPE_ORACLE_H_
#include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
class TypeOracle {
public:
void RegisterTypeImpl(const std::string& name, const std::string& generated,
const std::string* parent = nullptr) {
TypeImpl* parent_class = nullptr;
if (type_imples_.find(name) != type_imples_.end()) {
ReportError(std::string("cannot redefine type class ") + name);
}
if (parent != nullptr) {
auto i = type_imples_.find(*parent);
if (i == type_imples_.end()) {
std::stringstream s;
s << "cannot find parent type class " << *parent << " for " << name;
ReportError(s.str());
}
parent_class = i->second;
}
TypeImpl* new_class = new TypeImpl(parent_class, name, generated);
type_imples_[name] = new_class;
}
void RegisterImplicitConversion(Type to, Type from) {
implicit_conversions_.push_back(std::make_pair(to, from));
}
Type GetType(const std::string& type_name) {
auto i = type_imples_.find(type_name);
if (i == type_imples_.end()) {
std::stringstream s;
s << "no type class found for type " << type_name;
ReportError(s.str());
}
return Type(i->second);
}
Type GetArgumentsType() { return GetType(ARGUMENTS_TYPE_STRING); }
Type GetTaggedType() { return GetType(TAGGED_TYPE_STRING); }
Type GetExceptionType() { return GetType(EXCEPTION_TYPE_STRING); }
Type GetBranchType() { return GetType(BRANCH_TYPE_STRING); }
Type GetBitType() { return GetType(BIT_TYPE_STRING); }
Type GetVoidType() { return GetType(VOID_TYPE_STRING); }
Type GetObjectType() { return GetType(OBJECT_TYPE_STRING); }
Type GetStringType() { return GetType(STRING_TYPE_STRING); }
Type GetIntPtrType() { return GetType(INTPTR_TYPE_STRING); }
Type GetNeverType() { return GetType(NEVER_TYPE_STRING); }
Type GetConstInt31Type() { return GetType(CONST_INT31_TYPE_STRING); }
bool IsException(Type from) { return GetExceptionType().IsSubclass(from); }
bool IsAssignableFrom(Type to, Type from) {
if (to.IsSubclass(from)) return true;
return IsImplicitlyConverableFrom(to, from);
}
bool IsImplicitlyConverableFrom(Type to, Type from) {
for (auto& conversion : implicit_conversions_) {
if (conversion.first == to && conversion.second == from) {
return true;
}
}
return false;
}
bool IsCompatibleSignature(const ParameterTypes& to, const TypeVector& from) {
auto i = to.types.begin();
for (auto current : from) {
if (i == to.types.end()) {
if (!to.var_args) return false;
if (!IsAssignableFrom(GetObjectType(), current)) return false;
} else {
if (!IsAssignableFrom(*i++, current)) return false;
}
}
return true;
}
private:
std::map<std::string, TypeImpl*> type_imples_;
std::vector<std::pair<Type, Type>> implicit_conversions_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_TYPE_ORACLE_H_

57
src/torque/types.cc Normal file
View File

@ -0,0 +1,57 @@
// Copyright 2017 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.
#include <fstream>
#include <iostream>
#include "src/torque/types.h"
namespace v8 {
namespace internal {
namespace torque {
std::ostream& operator<<(std::ostream& os, const Signature& sig) {
os << "(";
for (size_t i = 0; i < sig.parameter_names.size(); ++i) {
if (i > 0) os << ", ";
if (!sig.parameter_names.empty()) os << sig.parameter_names[i] << ": ";
os << sig.parameter_types.types[i];
}
if (sig.parameter_types.var_args) {
if (sig.parameter_names.size()) os << ", ";
os << "...";
}
os << ")";
if (!sig.return_type.IsVoid()) {
os << ": " << sig.return_type;
}
for (size_t i = 0; i < sig.labels.size(); ++i) {
os << (i == 0 ? " labels " : ", ") << sig.labels[i];
}
return os;
}
std::ostream& operator<<(std::ostream& os, const TypeVector& types) {
for (size_t i = 0; i < types.size(); ++i) {
if (i > 0) os << ", ";
os << types[i];
}
return os;
}
std::ostream& operator<<(std::ostream& os, const ParameterTypes& p) {
for (size_t i = 0; i < p.types.size(); ++i) {
if (i > 0) os << ", ";
os << p.types[i];
}
if (p.var_args) {
if (p.types.size() > 0) os << ", ";
os << "...";
}
return os;
}
} // namespace torque
} // namespace internal
} // namespace v8

178
src/torque/types.h Normal file
View File

@ -0,0 +1,178 @@
// Copyright 2017 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_TYPES_H_
#define V8_TORQUE_TYPES_H_
#include <string>
#include <vector>
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
static const char* const NEVER_TYPE_STRING = "never";
static const char* const BRANCH_TYPE_STRING = "branch";
static const char* const BIT_TYPE_STRING = "bit";
static const char* const VOID_TYPE_STRING = "void";
static const char* const ARGUMENTS_TYPE_STRING = "Arguments";
static const char* const TAGGED_TYPE_STRING = "tagged";
static const char* const CONTEXT_TYPE_STRING = "Context";
static const char* const EXCEPTION_TYPE_STRING = "Exception";
static const char* const OBJECT_TYPE_STRING = "Object";
static const char* const STRING_TYPE_STRING = "String";
static const char* const INTPTR_TYPE_STRING = "intptr";
static const char* const CONST_INT31_TYPE_STRING = "const_int31";
static const char* const CONST_INT32_TYPE_STRING = "const_int32";
static const char* const CONST_FLOAT64_TYPE_STRING = "const_float64";
class Label;
struct Type;
class TypeImpl {
public:
TypeImpl(TypeImpl* parent, const std::string& name,
const std::string& generated_type)
: parent_(parent), name_(name), generated_type_(generated_type) {}
TypeImpl* parent() const { return parent_; }
const std::string& name() const { return name_; }
const std::string& generated_type() const { return generated_type_; }
private:
TypeImpl* parent_;
std::string name_;
std::string generated_type_;
};
typedef struct Type {
public:
Type() : impl_(nullptr) {}
Type(TypeImpl* type_impl) : impl_(type_impl) {}
bool operator==(const Type& other) const { return impl_ == other.impl_; }
bool operator!=(const Type& other) const { return impl_ != other.impl_; }
bool Is(const Type& other) const { return impl_ == other.impl_; }
bool Is(const std::string& name) const { return name == impl_->name(); }
bool IsSubclass(Type from) {
TypeImpl* to_class = type_impl();
TypeImpl* from_class = from.type_impl();
while (from_class != nullptr) {
if (to_class == from_class) return true;
from_class = from_class->parent();
}
return false;
}
bool IsException() const { return name() == EXCEPTION_TYPE_STRING; }
bool IsVoid() const { return name() == VOID_TYPE_STRING; }
bool IsNever() const { return name() == NEVER_TYPE_STRING; }
bool IsBit() const { return name() == BIT_TYPE_STRING; }
bool IsVoidOrNever() const { return IsVoid() || IsNever(); }
const std::string& name() const { return impl_->name(); }
const std::string& GetGeneratedTypeName() const {
return type_impl()->generated_type();
}
std::string GetGeneratedTNodeTypeName() const {
std::string result = type_impl()->generated_type();
result = result.substr(6, result.length() - 7);
return result;
}
protected:
TypeImpl* type_impl() const { return impl_; }
private:
TypeImpl* impl_;
} Type;
inline std::ostream& operator<<(std::ostream& os, Type t) {
os << t.name().c_str();
return os;
}
using TypeVector = std::vector<Type>;
class VisitResult {
public:
VisitResult() {}
VisitResult(Type type, const std::string& variable)
: type_(type), variable_(variable) {}
Type type() const { return type_; }
const std::string& variable() const { return variable_; }
private:
Type type_;
std::string variable_;
};
class VisitResultVector : public std::vector<VisitResult> {
public:
VisitResultVector() : std::vector<VisitResult>() {}
VisitResultVector(std::initializer_list<VisitResult> init)
: std::vector<VisitResult>(init) {}
TypeVector GetTypeVector() const {
TypeVector result;
for (auto& visit_result : *this) {
result.push_back(visit_result.type());
}
return result;
}
};
std::ostream& operator<<(std::ostream& os, const TypeVector& types);
struct NameAndType {
std::string name;
Type type;
};
typedef std::vector<NameAndType> NameAndTypeVector;
struct LabelDefinition {
std::string name;
NameAndTypeVector parameters;
};
typedef std::vector<LabelDefinition> LabelDefinitionVector;
struct LabelDeclaration {
std::string name;
TypeVector types;
};
typedef std::vector<LabelDeclaration> LabelDeclarationVector;
struct ParameterTypes {
TypeVector types;
bool var_args;
};
std::ostream& operator<<(std::ostream& os, const ParameterTypes& parameters);
struct Signature {
const TypeVector& types() const { return parameter_types.types; }
NameVector parameter_names;
ParameterTypes parameter_types;
Type return_type;
LabelDeclarationVector label_defintions;
std::vector<Label*> labels;
};
struct Arguments {
VisitResultVector parameters;
std::vector<Label*> labels;
};
std::ostream& operator<<(std::ostream& os, const Signature& sig);
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_TYPES_H_

57
src/torque/utils.cc Normal file
View File

@ -0,0 +1,57 @@
// Copyright 2017 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.
#include <fstream>
#include <iostream>
#include <string>
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
void ReportError(const std::string& error) {
std::cerr << error << std::endl;
throw(-1);
}
std::string CamelifyString(const std::string& underscore_string) {
std::string result;
bool word_beginning = true;
for (auto current : underscore_string) {
if (current == '_' || current == '-') {
word_beginning = true;
continue;
}
if (word_beginning) {
current = toupper(current);
}
result += current;
word_beginning = false;
}
return result;
}
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents) {
std::ifstream old_contents_stream(file_path.c_str());
std::string old_contents;
if (old_contents_stream.good()) {
std::istreambuf_iterator<char> eos;
old_contents =
std::string(std::istreambuf_iterator<char>(old_contents_stream), eos);
old_contents_stream.close();
}
if (old_contents.length() == 0 || old_contents != contents) {
std::ofstream new_contents_stream;
new_contents_stream.open(file_path.c_str());
new_contents_stream << contents;
new_contents_stream.close();
}
}
} // namespace torque
} // namespace internal
} // namespace v8

29
src/torque/utils.h Normal file
View File

@ -0,0 +1,29 @@
// Copyright 2017 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_UTILS_H_
#define V8_TORQUE_UTILS_H_
#include <string>
#include "src/objects.h"
namespace v8 {
namespace internal {
namespace torque {
typedef std::vector<std::string> NameVector;
void ReportError(const std::string& error);
std::string CamelifyString(const std::string& underscore_string);
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents);
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_UTILS_H_

36
tools/format-torque.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python
# Copyright 2014 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.
"""This program either generates the parser files for Torque, generating
the source and header files directly in V8's src directory."""
import subprocess
import sys
import re
from subprocess import Popen, PIPE
if len(sys.argv) < 2 or len(sys.argv) > 3:
print "invalid number of arguments"
sys.exit(-1)
use_stdout = True
if len(sys.argv) == 3 and sys.argv[1] == '-i':
use_stdout = False
filename = sys.argv[len(sys.argv) - 1]
with open(filename, 'r') as content_file:
content = content_file.read()
p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate(content)
rc = p.returncode
if (rc <> 0):
sys.exit(rc);
if use_stdout:
print output
else:
output_file = open(filename, 'w')
output_file.write(output);
output_file.close()

View File

@ -23,6 +23,15 @@ group("v8_run_gcmole") {
"../../testing/gtest/include/gtest/gtest_prod.h",
"../../third_party/googletest/src/googletest/include/gtest/gtest_prod.h",
"../../third_party/icu/source/",
"$target_gen_dir/../../builtin-definitions-from-dsl.h",
"$target_gen_dir/../../builtins-array-from-dsl-gen.cc",
"$target_gen_dir/../../builtins-array-from-dsl-gen.h",
"$target_gen_dir/../../builtins-base-from-dsl-gen.cc",
"$target_gen_dir/../../builtins-base-from-dsl-gen.h",
]
deps = [
"../../:run_torque",
]
if (v8_gcmole) {

View File

@ -112,6 +112,7 @@ local function MakeClangCommandLine(
.. " -DV8_INTL_SUPPORT"
.. " -I./"
.. " -Iinclude/"
.. " -Iout/Release/gen"
.. " -Ithird_party/icu/source/common"
.. " -Ithird_party/icu/source/i18n"
.. " " .. arch_options

View File

@ -4,6 +4,7 @@
# found in the LICENSE file.
import os
import os.path
import signal
import subprocess
import sys
@ -17,6 +18,11 @@ BASE_PATH = os.path.dirname(os.path.dirname(GCMOLE_PATH))
assert len(sys.argv) == 2
if not os.path.isfile("out/Release/gen/builtin-definitions-from-dsl.h"):
print "Expected generated headers in out/Release/gen."
print "Either build v8 in out/Release or change gcmole.lua:115"
sys.exit(-1)
proc = subprocess.Popen(
[LUA, DRIVER, sys.argv[1]],
env={'CLANG_BIN': CLANG_BIN, 'CLANG_PLUGINS': CLANG_PLUGINS},

71
tools/make-torque-parser.py Executable file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env python
# Copyright 2014 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.
"""This program either generates the parser files for Torque, generating
the source and header files directly in V8's src directory."""
import subprocess
import sys
import os
import ntpath
import re
cwd = os.getcwd()
tools = ntpath.dirname(sys.argv[0]);
grammar = tools + '/../src/torque/Torque.g4'
basename = ntpath.basename(grammar)
dirname = ntpath.dirname(grammar)
os.chdir(dirname)
cargs = ['java', '-Xmx500M', 'org.antlr.v4.Tool', '-visitor', basename]
result = subprocess.call(cargs)
os.chdir(cwd)
def fix_file(filename):
is_header = re.search(r'\.h', filename) <> None;
header_macro = filename.upper();
header_macro = re.sub('\.', '_', header_macro);
header_macro = "V8_TORQUE_" + header_macro + '_';
copyright = '// Copyright 2018 the V8 project authors. All rights reserved.\n'
copyright += '// Use of this source code is governed by a BSD-style license that can be\n'
copyright += '// found in the LICENSE file.\n'
file_path = tools + '/../src/torque/' + filename;
temp_file_path = file_path + '.tmp'
output_file = open(temp_file_path, 'w')
output_file.write(copyright);
if is_header:
output_file.write('#ifndef ' + header_macro + '\n');
output_file.write('#define ' + header_macro + '\n');
with open(file_path) as f:
content = f.readlines()
for x in content:
x = re.sub(';;', ';', x)
x = re.sub('antlr4-runtime\.h', './antlr4-runtime.h', x)
x = re.sub(' TorqueParser.antlr4', ' explicit TorqueParser(antlr4', x)
x = re.sub(' TorqueLexer.antlr4', ' explicit TorqueLexer(antlr4', x)
if not re.search('= 0', x):
x = re.sub('virtual', '', x)
output_file.write(x)
if is_header:
output_file.write('#endif // ' + header_macro + '\n');
output_file.close();
subprocess.call(['rm', file_path])
subprocess.call(['mv', temp_file_path, file_path])
fix_file('TorqueBaseListener.h');
fix_file('TorqueBaseListener.cpp');
fix_file('TorqueBaseVisitor.h');
fix_file('TorqueBaseVisitor.cpp');
fix_file('TorqueLexer.h');
fix_file('TorqueLexer.cpp');
fix_file('TorqueParser.h');
fix_file('TorqueParser.cpp');
fix_file('TorqueListener.h');
fix_file('TorqueListener.cpp');
fix_file('TorqueVisitor.h');
fix_file('TorqueVisitor.cpp');

View File

@ -283,7 +283,7 @@ class SourceProcessor(SourceFileProcessor):
Check that all files include a copyright notice and no trailing whitespaces.
"""
RELEVANT_EXTENSIONS = ['.js', '.cc', '.h', '.py', '.c', '.status']
RELEVANT_EXTENSIONS = ['.js', '.cc', '.h', '.py', '.c', '.status', '.tq', '.g4']
def __init__(self):
self.runtime_function_call_pattern = self.CreateRuntimeFunctionCallMatcher()