runtime_analysis 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +115 -0
- data/LICENSE.txt +96 -0
- data/README.md +164 -0
- data/editor/nvim/README.md +278 -0
- data/editor/nvim/lua/runtime_analysis/connected.lua +565 -0
- data/editor/nvim/lua/runtime_analysis/go_to_class.lua +63 -0
- data/editor/nvim/lua/runtime_analysis/inline.lua +138 -0
- data/editor/nvim/lua/runtime_analysis/lens.lua +50 -0
- data/editor/nvim/lua/runtime_analysis/lsp.lua +92 -0
- data/editor/nvim/lua/runtime_analysis/menu.lua +98 -0
- data/editor/nvim/lua/runtime_analysis/preview.lua +70 -0
- data/editor/nvim/lua/runtime_analysis/project.lua +28 -0
- data/editor/nvim/lua/runtime_analysis/rerun.lua +39 -0
- data/editor/nvim/lua/runtime_analysis/text.lua +23 -0
- data/editor/nvim/lua/runtime_analysis/value_popup.lua +45 -0
- data/editor/nvim/plugin/runtime_analysis.lua +71 -0
- data/examples/trackers/PROMPT.md +86 -0
- data/examples/trackers/honeybadger.rb +19 -0
- data/examples/trackers/sentry.rb +16 -0
- data/ext/runtime_analysis/extconf.rb +68 -0
- data/ext/runtime_analysis/fast.c +775 -0
- data/ext/runtime_analysis/fast.h +59 -0
- data/ext/runtime_analysis/hold.c +560 -0
- data/ext/runtime_analysis/init.c +36 -0
- data/ext/runtime_analysis/names.c +78 -0
- data/ext/runtime_analysis/names.h +28 -0
- data/ext/runtime_analysis/novelty.c +139 -0
- data/ext/runtime_analysis/novelty.h +22 -0
- data/ext/runtime_analysis/os.c +73 -0
- data/ext/runtime_analysis/os.h +32 -0
- data/ext/runtime_analysis/ring.c +445 -0
- data/ext/runtime_analysis/rows.c +304 -0
- data/ext/runtime_analysis/sink.c +485 -0
- data/ext/runtime_analysis/sink.h +240 -0
- data/ext/runtime_analysis/state.c +254 -0
- data/ext/runtime_analysis/state.h +57 -0
- data/ext/runtime_analysis/wrapper.c +278 -0
- data/ext/runtime_analysis/wrapper.h +24 -0
- data/lib/runtime_analysis/errors.rb +34 -0
- data/lib/runtime_analysis/failsafe.rb +123 -0
- data/lib/runtime_analysis/host/controller_entry_point.rb +18 -0
- data/lib/runtime_analysis/host/declared.rb +152 -0
- data/lib/runtime_analysis/host/inject.rb +90 -0
- data/lib/runtime_analysis/host/job_runners.rb +27 -0
- data/lib/runtime_analysis/host/middleware.rb +23 -0
- data/lib/runtime_analysis/host/minitest_integration.rb +22 -0
- data/lib/runtime_analysis/host/railtie.rb +42 -0
- data/lib/runtime_analysis/host/reports.rb +54 -0
- data/lib/runtime_analysis/host/rspec_integration.rb +17 -0
- data/lib/runtime_analysis/host/web.rb +22 -0
- data/lib/runtime_analysis/host.rb +34 -0
- data/lib/runtime_analysis/inject.rb +5 -0
- data/lib/runtime_analysis/minitest.rb +9 -0
- data/lib/runtime_analysis/native/build.rb +17 -0
- data/lib/runtime_analysis/native/byte_size.rb +27 -0
- data/lib/runtime_analysis/native/call_site_logger/definitions.rb +51 -0
- data/lib/runtime_analysis/native/call_site_logger/held.rb +35 -0
- data/lib/runtime_analysis/native/call_site_logger/rows.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger/segments.rb +100 -0
- data/lib/runtime_analysis/native/call_site_logger/streams.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger.rb +80 -0
- data/lib/runtime_analysis/native/rotation_policy.rb +28 -0
- data/lib/runtime_analysis/native/sanitizer_runtime.rb +50 -0
- data/lib/runtime_analysis/native/sink.rb +12 -0
- data/lib/runtime_analysis/native.rb +74 -0
- data/lib/runtime_analysis/platform.rb +30 -0
- data/lib/runtime_analysis/query/index/anonymise.rb +98 -0
- data/lib/runtime_analysis/query/index/graph.rb +107 -0
- data/lib/runtime_analysis/query/index/graph_cache.rb +32 -0
- data/lib/runtime_analysis/query/index/reading/declared.rb +42 -0
- data/lib/runtime_analysis/query/index/reading/dict.rb +43 -0
- data/lib/runtime_analysis/query/index/reading/frame.rb +27 -0
- data/lib/runtime_analysis/query/index/reading/node.rb +45 -0
- data/lib/runtime_analysis/query/index/reading/path.rb +21 -0
- data/lib/runtime_analysis/query/index/reading/reruns.rb +30 -0
- data/lib/runtime_analysis/query/index/reading/rows.rb +128 -0
- data/lib/runtime_analysis/query/index/reading/stream.rb +82 -0
- data/lib/runtime_analysis/query/index/reading/tree.rb +66 -0
- data/lib/runtime_analysis/query/index/reading/tree_builder.rb +135 -0
- data/lib/runtime_analysis/query/index/reading/values.rb +49 -0
- data/lib/runtime_analysis/query/index/reading.rb +80 -0
- data/lib/runtime_analysis/query/index/shapes.rb +142 -0
- data/lib/runtime_analysis/query/index/signatures/active_support.rb +31 -0
- data/lib/runtime_analysis/query/index/signatures/core.json +1 -0
- data/lib/runtime_analysis/query/index/signatures/layers.rb +29 -0
- data/lib/runtime_analysis/query/index/signatures/lineage.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/overloads.rb +32 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/entry.rb +95 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/export.rb +76 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/library.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/overload.rb +66 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/project.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/types.rb +79 -0
- data/lib/runtime_analysis/query/index/signatures/rbs.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/sig.rb +48 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/signed.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/table.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/types.rb +96 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet.rb +150 -0
- data/lib/runtime_analysis/query/index/signatures/sources.rb +80 -0
- data/lib/runtime_analysis/query/index/signatures/written.rb +45 -0
- data/lib/runtime_analysis/query/index/signatures.rb +93 -0
- data/lib/runtime_analysis/query/index/source_named_graph.rb +84 -0
- data/lib/runtime_analysis/query/index/static/change_set.rb +20 -0
- data/lib/runtime_analysis/query/index/static/changes.rb +80 -0
- data/lib/runtime_analysis/query/index/static/code_visitor.rb +144 -0
- data/lib/runtime_analysis/query/index/static/klass.rb +13 -0
- data/lib/runtime_analysis/query/index/static/method.rb +19 -0
- data/lib/runtime_analysis/query/index/static/params.rb +52 -0
- data/lib/runtime_analysis/query/index/static/source.rb +69 -0
- data/lib/runtime_analysis/query/index/static/stub.rb +14 -0
- data/lib/runtime_analysis/query/index/static/stub_visitor.rb +133 -0
- data/lib/runtime_analysis/query/index/static/value.rb +17 -0
- data/lib/runtime_analysis/query/index/static/values.rb +71 -0
- data/lib/runtime_analysis/query/index/static/visibility.rb +40 -0
- data/lib/runtime_analysis/query/index/static.rb +85 -0
- data/lib/runtime_analysis/query/index.rb +32 -0
- data/lib/runtime_analysis/query/nodes.rb +60 -0
- data/lib/runtime_analysis/query/project/config.rb +108 -0
- data/lib/runtime_analysis/query/project.rb +40 -0
- data/lib/runtime_analysis/query/report/document.rb +84 -0
- data/lib/runtime_analysis/query/report/finding.rb +15 -0
- data/lib/runtime_analysis/query/report/json_renderer.rb +51 -0
- data/lib/runtime_analysis/query/report/list.rb +15 -0
- data/lib/runtime_analysis/query/report/location.rb +14 -0
- data/lib/runtime_analysis/query/report/one_row.rb +14 -0
- data/lib/runtime_analysis/query/report/outline.rb +15 -0
- data/lib/runtime_analysis/query/report/paint.rb +34 -0
- data/lib/runtime_analysis/query/report/related.rb +11 -0
- data/lib/runtime_analysis/query/report/table.rb +15 -0
- data/lib/runtime_analysis/query/report/text.rb +13 -0
- data/lib/runtime_analysis/query/report/text_renderer.rb +102 -0
- data/lib/runtime_analysis/query/report.rb +35 -0
- data/lib/runtime_analysis/query/surfaces/class_value.rb +17 -0
- data/lib/runtime_analysis/query/surfaces/cli/answer.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli/command_line.rb +77 -0
- data/lib/runtime_analysis/query/surfaces/cli/usage.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli.rb +101 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/lexical.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/notation.rb +33 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/observed.rb +102 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/outline.rb +111 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_file.rb +100 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_member.rb +50 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_notation.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/seen.rb +74 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sig_text.rb +49 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_edit.rb +106 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_notation.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/subject.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/crystallise.rb +94 -0
- data/lib/runtime_analysis/query/surfaces/mcp.rb +89 -0
- data/lib/runtime_analysis/query/surfaces/record/commands.rb +45 -0
- data/lib/runtime_analysis/query/surfaces/record/environment.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/record/ignore.rb +62 -0
- data/lib/runtime_analysis/query/surfaces/record/question.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/record/run.rb +30 -0
- data/lib/runtime_analysis/query/surfaces/record.rb +122 -0
- data/lib/runtime_analysis/query/surfaces/rerun.rb +87 -0
- data/lib/runtime_analysis/query/surfaces/setup/agents.rb +76 -0
- data/lib/runtime_analysis/query/surfaces/setup/changes.rb +107 -0
- data/lib/runtime_analysis/query/surfaces/setup/project.rb +80 -0
- data/lib/runtime_analysis/query/surfaces/setup/steps.md +205 -0
- data/lib/runtime_analysis/query/surfaces/setup.rb +98 -0
- data/lib/runtime_analysis/query/surfaces.rb +14 -0
- data/lib/runtime_analysis/query/tools/base.rb +86 -0
- data/lib/runtime_analysis/query/tools/method_lookup.rb +37 -0
- data/lib/runtime_analysis/query/tools/namespaces.rb +36 -0
- data/lib/runtime_analysis/query/tools/origins.rb +47 -0
- data/lib/runtime_analysis/query/tools/stubs.rb +53 -0
- data/lib/runtime_analysis/query/tools/unknown_method.rb +11 -0
- data/lib/runtime_analysis/query/tools/verify_mock.rb +145 -0
- data/lib/runtime_analysis/query/tools/what_calls.rb +67 -0
- data/lib/runtime_analysis/query/tools/what_it_receives.rb +142 -0
- data/lib/runtime_analysis/query/tools/where_nil_comes_from.rb +105 -0
- data/lib/runtime_analysis/query/tools/who_actually_answered.rb +82 -0
- data/lib/runtime_analysis/query/tools.rb +34 -0
- data/lib/runtime_analysis/query.rb +33 -0
- data/lib/runtime_analysis/recording/blob.rb +13 -0
- data/lib/runtime_analysis/recording/format.rb +32 -0
- data/lib/runtime_analysis/recording/opcodes.rb +30 -0
- data/lib/runtime_analysis/recording/raise_ids.rb +15 -0
- data/lib/runtime_analysis/recording/ruby_sink.rb +176 -0
- data/lib/runtime_analysis/recording/run_manifest.rb +110 -0
- data/lib/runtime_analysis/recording/seen/nothing.rb +15 -0
- data/lib/runtime_analysis/recording/seen/tally.rb +48 -0
- data/lib/runtime_analysis/recording/seen.rb +63 -0
- data/lib/runtime_analysis/recording/sink.rb +19 -0
- data/lib/runtime_analysis/recording/source_blob.rb +20 -0
- data/lib/runtime_analysis/recording.rb +52 -0
- data/lib/runtime_analysis/rspec.rb +8 -0
- data/lib/runtime_analysis/ruby_parsing/packages.rb +17 -0
- data/lib/runtime_analysis/ruby_parsing.rb +98 -0
- data/lib/runtime_analysis/trace/configuration/capturing.rb +32 -0
- data/lib/runtime_analysis/trace/configuration/per_run.rb +31 -0
- data/lib/runtime_analysis/trace/configuration/tier.rb +27 -0
- data/lib/runtime_analysis/trace/configuration.rb +115 -0
- data/lib/runtime_analysis/trace/entries.rb +47 -0
- data/lib/runtime_analysis/trace/hold/raises.rb +28 -0
- data/lib/runtime_analysis/trace/hold/requests.rb +47 -0
- data/lib/runtime_analysis/trace/hold/telling.rb +45 -0
- data/lib/runtime_analysis/trace/hold/unwound.rb +30 -0
- data/lib/runtime_analysis/trace/hold.rb +142 -0
- data/lib/runtime_analysis/trace/inclusion.rb +46 -0
- data/lib/runtime_analysis/trace/installer/alias_repair.rb +68 -0
- data/lib/runtime_analysis/trace/installer/answers.rb +24 -0
- data/lib/runtime_analysis/trace/installer/body_sync.rb +25 -0
- data/lib/runtime_analysis/trace/installer/built_classes.rb +43 -0
- data/lib/runtime_analysis/trace/installer/called_names.rb +33 -0
- data/lib/runtime_analysis/trace/installer/class_builders.rb +50 -0
- data/lib/runtime_analysis/trace/installer/deferral.rb +42 -0
- data/lib/runtime_analysis/trace/installer/hook.rb +170 -0
- data/lib/runtime_analysis/trace/installer/included_gems.rb +53 -0
- data/lib/runtime_analysis/trace/installer/probe.rb +28 -0
- data/lib/runtime_analysis/trace/installer/reflection.rb +50 -0
- data/lib/runtime_analysis/trace/installer/registry.rb +78 -0
- data/lib/runtime_analysis/trace/installer/sorbet.rb +29 -0
- data/lib/runtime_analysis/trace/installer/wrapping/ivar_writes.rb +62 -0
- data/lib/runtime_analysis/trace/installer/wrapping.rb +66 -0
- data/lib/runtime_analysis/trace/installer.rb +149 -0
- data/lib/runtime_analysis/trace/mechanism/block_entries.rb +29 -0
- data/lib/runtime_analysis/trace/mechanism/frame_readers.rb +61 -0
- data/lib/runtime_analysis/trace/mechanism/native_asks.rb +36 -0
- data/lib/runtime_analysis/trace/mechanism/native_sync.rb +28 -0
- data/lib/runtime_analysis/trace/mechanism/pure_wrapper.rb +41 -0
- data/lib/runtime_analysis/trace/mechanism/ruby_wrapper.rb +141 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper.rb +79 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper_shape.rb +40 -0
- data/lib/runtime_analysis/trace/mechanism.rb +28 -0
- data/lib/runtime_analysis/trace/nil_origin/answers.rb +24 -0
- data/lib/runtime_analysis/trace/nil_origin/beyond.rb +182 -0
- data/lib/runtime_analysis/trace/nil_origin/index.rb +164 -0
- data/lib/runtime_analysis/trace/nil_origin/lifetime.rb +29 -0
- data/lib/runtime_analysis/trace/nil_origin/named.rb +48 -0
- data/lib/runtime_analysis/trace/nil_origin/objects.rb +78 -0
- data/lib/runtime_analysis/trace/nil_origin/provenance.rb +136 -0
- data/lib/runtime_analysis/trace/nil_origin/receiver.rb +121 -0
- data/lib/runtime_analysis/trace/nil_origin/rows.rb +43 -0
- data/lib/runtime_analysis/trace/nil_origin/source.rb +315 -0
- data/lib/runtime_analysis/trace/nil_origin/stored.rb +159 -0
- data/lib/runtime_analysis/trace/nil_origin/told.rb +152 -0
- data/lib/runtime_analysis/trace/nil_origin/values.rb +47 -0
- data/lib/runtime_analysis/trace/nil_origin/weighed.rb +70 -0
- data/lib/runtime_analysis/trace/nil_origin/writers.rb +79 -0
- data/lib/runtime_analysis/trace/nil_origin.rb +278 -0
- data/lib/runtime_analysis/trace/novelty.rb +17 -0
- data/lib/runtime_analysis/trace/pure/novelty.rb +43 -0
- data/lib/runtime_analysis/trace/pure/state.rb +94 -0
- data/lib/runtime_analysis/trace/pure.rb +15 -0
- data/lib/runtime_analysis/trace/recorder/class_name.rb +63 -0
- data/lib/runtime_analysis/trace/recorder/fingerprint.rb +39 -0
- data/lib/runtime_analysis/trace/recorder/frame_key.rb +27 -0
- data/lib/runtime_analysis/trace/recorder/paths.rb +89 -0
- data/lib/runtime_analysis/trace/recorder/raise_site.rb +36 -0
- data/lib/runtime_analysis/trace/recorder/reachability.rb +46 -0
- data/lib/runtime_analysis/trace/recorder/row_emission.rb +137 -0
- data/lib/runtime_analysis/trace/recorder/safe_steps.rb +84 -0
- data/lib/runtime_analysis/trace/recorder/tree_steps.rb +42 -0
- data/lib/runtime_analysis/trace/recorder/unwinding.rb +23 -0
- data/lib/runtime_analysis/trace/recorder.rb +149 -0
- data/lib/runtime_analysis/trace/state.rb +16 -0
- data/lib/runtime_analysis/trace.rb +142 -0
- data/lib/runtime_analysis/version.rb +6 -0
- data/lib/runtime_analysis/web.rb +6 -0
- data/lib/runtime_analysis.rb +125 -0
- metadata +330 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
require_relative "usage"
|
|
5
|
+
require "runtime_analysis/query/report"
|
|
6
|
+
|
|
7
|
+
module RuntimeAnalysis
|
|
8
|
+
module Query
|
|
9
|
+
module Surfaces
|
|
10
|
+
class Cli
|
|
11
|
+
class CommandLine
|
|
12
|
+
DEFAULT_RECORDING = "tmp/runtime_analysis"
|
|
13
|
+
RECORDING = "Directory holding the recording (default #{DEFAULT_RECORDING})".freeze
|
|
14
|
+
|
|
15
|
+
attr_reader :arguments
|
|
16
|
+
|
|
17
|
+
def initialize(tool = nil)
|
|
18
|
+
@tool = tool
|
|
19
|
+
@recording = DEFAULT_RECORDING
|
|
20
|
+
@arguments = {}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def recording = File.expand_path(@recording)
|
|
24
|
+
def root = @root ? File.expand_path(@root) : Dir.pwd
|
|
25
|
+
|
|
26
|
+
def json? = @json == true
|
|
27
|
+
def help? = @help == true
|
|
28
|
+
|
|
29
|
+
def top = @arguments.fetch(:top) { @top || Report.top }
|
|
30
|
+
|
|
31
|
+
def parse!(argv)
|
|
32
|
+
parser.parse!(argv)
|
|
33
|
+
@arguments[@tool.positional.name] = argv.shift if @tool&.positional && argv.any?
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def help
|
|
38
|
+
parser.help
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def require_all!
|
|
42
|
+
missing = @tool.arguments.select { |argument| argument.required && !@arguments.key?(argument.name) }
|
|
43
|
+
raise ArgumentError, "missing #{missing.map(&:name).join(", ")} for #{@tool.tool_name}" if missing.any?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def parser
|
|
49
|
+
@parser ||= OptionParser.new(Usage.for(@tool)) do |opts|
|
|
50
|
+
@tool&.arguments&.each { |argument| declare(opts, argument) }
|
|
51
|
+
common(opts)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def declare(opts, argument)
|
|
56
|
+
flag = "--#{argument.name.to_s.tr("_", "-")}"
|
|
57
|
+
opts.on(argument.type == :boolean ? flag : "#{flag} VALUE", argument.description) do |value|
|
|
58
|
+
@arguments[argument.name] = value
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def common(opts)
|
|
63
|
+
opts.on("--recording DIR", RECORDING) { @recording = _1 }
|
|
64
|
+
opts.on("--root DIR", "Project root (default the current directory)") { @root = _1 }
|
|
65
|
+
rows(opts) unless @tool&.arguments&.any? { |argument| argument.name == :top }
|
|
66
|
+
opts.on("--json", "Print JSON") { @json = true }
|
|
67
|
+
opts.on("--help", "Describe the tool and its options") { @help = true }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def rows(opts)
|
|
71
|
+
opts.on("--top N", "How many rows to show (default #{Report.top}, or all)") { @top = _1 }
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: wording only; asserted through command_line_spec.rb and cli_spec.rb.
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Query
|
|
7
|
+
module Surfaces
|
|
8
|
+
class Cli
|
|
9
|
+
module Usage
|
|
10
|
+
GENERAL = "Usage: ra <tool> [argument] [options]\n\nOptions:"
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def for(tool)
|
|
15
|
+
return GENERAL unless tool
|
|
16
|
+
|
|
17
|
+
"#{call(tool)}\n\n#{tool.description}\n#{argument(tool.positional)}\nOptions:"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def call(tool)
|
|
21
|
+
positional = tool.positional
|
|
22
|
+
"Usage: ra #{tool.tool_name}#{" <#{positional.name}>" if positional} [options]"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def argument(positional)
|
|
26
|
+
"\nArguments:\n <#{positional.name}> #{positional.description}\n" if positional
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/query"
|
|
4
|
+
require "runtime_analysis/query/surfaces"
|
|
5
|
+
require "runtime_analysis/query/index"
|
|
6
|
+
require "runtime_analysis/recording"
|
|
7
|
+
require_relative "cli/answer"
|
|
8
|
+
require_relative "cli/command_line"
|
|
9
|
+
require_relative "rerun"
|
|
10
|
+
require_relative "crystallise"
|
|
11
|
+
require_relative "record"
|
|
12
|
+
require "runtime_analysis/errors"
|
|
13
|
+
|
|
14
|
+
module RuntimeAnalysis
|
|
15
|
+
module Query
|
|
16
|
+
module Surfaces
|
|
17
|
+
class Cli
|
|
18
|
+
def self.run(argv, out: $stdout, err: $stderr, graphs: Index)
|
|
19
|
+
new(argv, out, err, graphs).run
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.command_line(tool = nil) = CommandLine.new(tool)
|
|
23
|
+
|
|
24
|
+
def initialize(argv, out, err, graphs)
|
|
25
|
+
@argv = argv
|
|
26
|
+
@out = out
|
|
27
|
+
@err = err
|
|
28
|
+
@graphs = graphs
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
REQUIRED = "a tool or command is required: record, rerun, crystallise, or a tool's name"
|
|
32
|
+
COMMANDS = { "rerun" => :rerun, "record" => :record,
|
|
33
|
+
"crystallise" => :crystallise, "crystallize" => :crystallise }.freeze
|
|
34
|
+
|
|
35
|
+
def run
|
|
36
|
+
dispatch(tool_name)
|
|
37
|
+
rescue ArgumentError, Errors.unusable_options, Recording.newer_format => e
|
|
38
|
+
complain(e)
|
|
39
|
+
rescue Errors.reader_gone
|
|
40
|
+
0
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def paint
|
|
46
|
+
@paint ||= Report.paint(@out)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def command_line(tool = nil)
|
|
50
|
+
Cli.command_line(tool)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def rerun = Rerun.command(@argv, command_line, @graphs, @out)
|
|
54
|
+
|
|
55
|
+
def record = Record.command(@argv, command_line, @out)
|
|
56
|
+
|
|
57
|
+
def crystallise = Crystallise.command(@argv, command_line, @graphs, @out)
|
|
58
|
+
|
|
59
|
+
def complain(error)
|
|
60
|
+
@err.puts "ra: #{error}"
|
|
61
|
+
2
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def dispatch(name)
|
|
65
|
+
raise ArgumentError, REQUIRED if name.nil?
|
|
66
|
+
return __send__(COMMANDS.fetch(name)) if COMMANDS.key?(name)
|
|
67
|
+
|
|
68
|
+
execute(Tools.find(name))
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def tool_name
|
|
72
|
+
@argv.delete_at(first_word(0))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def first_word(index)
|
|
76
|
+
word = @argv.at(index)
|
|
77
|
+
return index unless word&.start_with?("--")
|
|
78
|
+
|
|
79
|
+
first_word(index + (word == "--json" ? 1 : 2))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def execute(tool)
|
|
83
|
+
line = command_line(tool).parse!(@argv)
|
|
84
|
+
return describe(tool) if line.help?
|
|
85
|
+
|
|
86
|
+
answer(tool, line)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def describe(tool)
|
|
90
|
+
@out.puts command_line(tool).help
|
|
91
|
+
0
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def answer(tool, line)
|
|
95
|
+
line.require_all!
|
|
96
|
+
Answer.new(@out, paint).call(tool, @graphs.load(line.recording), line)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Query
|
|
5
|
+
module Surfaces
|
|
6
|
+
class Crystallise
|
|
7
|
+
class Lexical
|
|
8
|
+
def initialize(nesting, known)
|
|
9
|
+
@nesting = nesting
|
|
10
|
+
@known = known
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def name(full)
|
|
14
|
+
short = shortest(full)
|
|
15
|
+
hidden?(short, full) ? "::#{full}" : short
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def type(type)
|
|
19
|
+
type&.map { |each| each.instance_of?(Array) ? holding(*each) : name(each) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def holding(holder, *held)
|
|
25
|
+
[name(holder), *held.map { |each| type(each) }]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def shortest(full)
|
|
29
|
+
around = @nesting.map { |each| "#{each}::" }.select { |prefix| full.start_with?(prefix) }
|
|
30
|
+
full.delete_prefix(around.max_by(&:size).to_s)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def hidden?(short, full)
|
|
34
|
+
first = short.split("::").first
|
|
35
|
+
@nesting.any? do |each|
|
|
36
|
+
found = "#{each}::#{first}"
|
|
37
|
+
@known.include?(found) && !full.start_with?(found)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Query
|
|
5
|
+
module Surfaces
|
|
6
|
+
class Crystallise
|
|
7
|
+
module Notation
|
|
8
|
+
def of(type)
|
|
9
|
+
return untyped if type.nil? || type.empty?
|
|
10
|
+
|
|
11
|
+
written((type - ["nil"]).map { |each| one(*each) }, type.include?("nil"))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def written(present, maybe_nil)
|
|
17
|
+
return only_nil if present.empty?
|
|
18
|
+
|
|
19
|
+
maybe_nil ? optional(present) : union(present)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def itself_of(held)
|
|
23
|
+
held.first.first if held.first&.size == 1 && held.first.first.instance_of?(String)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def holding(name, held, takes)
|
|
27
|
+
"#{name}[#{Array.new(takes) { |index| of(held.at(index)) }.join(", ")}]"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/ruby_parsing"
|
|
4
|
+
require_relative "seen"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Query
|
|
8
|
+
module Surfaces
|
|
9
|
+
class Crystallise
|
|
10
|
+
class Observed
|
|
11
|
+
Parameter = Struct.new(:name, :kind, :type)
|
|
12
|
+
KINDS = { required: :requireds, optional: :optionals, rest: :rest, post: :posts, keyword: :keywords,
|
|
13
|
+
keyrest: :keyword_rest, block: :block }.freeze
|
|
14
|
+
FORWARDED = %i[rest keyrest block].freeze
|
|
15
|
+
|
|
16
|
+
attr_reader :method
|
|
17
|
+
|
|
18
|
+
def initialize(method, definition, graph, shapes, seen = Seen)
|
|
19
|
+
@method = method
|
|
20
|
+
@definition = definition
|
|
21
|
+
@graph = graph
|
|
22
|
+
@shapes = shapes
|
|
23
|
+
@seen = seen
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def seen?
|
|
27
|
+
@graph.nodes_of(@method.identity).any?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def named?
|
|
31
|
+
parameters.all?(&:name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def initializer?
|
|
35
|
+
@method.name == "initialize" && !@method.class_method
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def result
|
|
39
|
+
@seen.type(@shapes.return_shape(@method.identity))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def parameters
|
|
43
|
+
@parameters ||= @definition ? declared : made
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def yields?
|
|
47
|
+
@definition ? yield_in?(@definition.body) : false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def declared
|
|
53
|
+
list = @definition.parameters or return []
|
|
54
|
+
KINDS.flat_map { |kind, part| Array(list.public_send(part)).flat_map { |node| read(kind, node) } }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def made
|
|
58
|
+
@method.name.end_with?("=") ? [Parameter.new(:value, :required, argument(0))] : []
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def read(kind, node)
|
|
62
|
+
case RubyParsing.kind(node)
|
|
63
|
+
when :forwarding_parameter_node then FORWARDED.map { |each| Parameter.new(nil, each) }
|
|
64
|
+
when :no_keywords_parameter_node then []
|
|
65
|
+
else named(kind, node)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def named(kind, node)
|
|
70
|
+
kind = :optional_keyword if RubyParsing.kind(node) == :optional_keyword_parameter_node
|
|
71
|
+
Parameter.new((node.name if node.respond_to?(:name)), kind, type(kind, node))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def type(kind, node)
|
|
75
|
+
return keyword(node) if kind.end_with?("keyword")
|
|
76
|
+
|
|
77
|
+
position = positional.index(node)
|
|
78
|
+
position && argument(position)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def positional
|
|
82
|
+
[*@definition.parameters.requireds, *@definition.parameters.optionals]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def keyword(node)
|
|
86
|
+
@seen.type(@shapes.kwarg_shape(@method.identity, node.name.to_s))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def argument(position)
|
|
90
|
+
@seen.type(@shapes.argument_shape(@method.identity, position))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def yield_in?(node)
|
|
94
|
+
return false if node.nil? || RubyParsing.definition?(node)
|
|
95
|
+
|
|
96
|
+
RubyParsing.kind(node) == :yield_node || node.compact_child_nodes.any? { |child| yield_in?(child) }
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through ../crystallise_spec.rb, which writes signatures into nested classes and modules.
|
|
4
|
+
|
|
5
|
+
require "runtime_analysis/ruby_parsing"
|
|
6
|
+
require "runtime_analysis/query/nodes"
|
|
7
|
+
|
|
8
|
+
module RuntimeAnalysis
|
|
9
|
+
module Query
|
|
10
|
+
module Surfaces
|
|
11
|
+
class Crystallise
|
|
12
|
+
class Outline < RubyParsing.visitor
|
|
13
|
+
Scope = Struct.new(:node, :namespace?, :lines, :scopes, :extended, :nesting)
|
|
14
|
+
|
|
15
|
+
class Scope
|
|
16
|
+
def class_block?
|
|
17
|
+
RubyParsing.kind(node) == :constant_write_node
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def each(&block)
|
|
21
|
+
block.call(self)
|
|
22
|
+
scopes.each { |scope| scope.each(&block) }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.of(tree)
|
|
27
|
+
new.tap { |outline| tree.accept(outline) }.top
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
attr_reader :top
|
|
31
|
+
|
|
32
|
+
def initialize
|
|
33
|
+
super()
|
|
34
|
+
@top = Scope.new(nil, true, [], [], nil, [])
|
|
35
|
+
@open = [@top]
|
|
36
|
+
@blocks_already_opened = Set.new
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def visit_class_node(node)
|
|
40
|
+
within(node, true) { super }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def visit_module_node(node)
|
|
44
|
+
within(node, true) { super }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def visit_singleton_class_node(node)
|
|
48
|
+
within(node, false) { super }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def visit_constant_write_node(node)
|
|
52
|
+
Nodes.class_block?(node) ? body(node, node.value.block, true) { super } : super
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def visit_def_node(node)
|
|
56
|
+
@open.last.lines << node.start_line
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def visit_call_node(node)
|
|
60
|
+
note(node) if node.receiver.nil?
|
|
61
|
+
Nodes.class_methods_block?(node) ? body(node, node.block, false) { super } : super
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def visit_block_node(node)
|
|
65
|
+
@blocks_already_opened.include?(node) ? super : within(nil, false) { super }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def note(node)
|
|
71
|
+
scope = @open.last
|
|
72
|
+
scope.lines << node.start_line
|
|
73
|
+
scope.extended ||= extends_sig?(node)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def body(node, block, namespace, &)
|
|
77
|
+
@blocks_already_opened << block
|
|
78
|
+
within(node, namespace, &)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def within(node, namespace)
|
|
82
|
+
scope = Scope.new(node, namespace, [], [], false, nesting(node, namespace))
|
|
83
|
+
declaring_scope(namespace).scopes << scope
|
|
84
|
+
@open << scope
|
|
85
|
+
yield
|
|
86
|
+
@open.pop
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def declaring_scope(namespace)
|
|
90
|
+
namespace ? @open.reverse.find { |scope| scope.namespace? && !scope.class_block? } : @open.last
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def nesting(node, namespace)
|
|
94
|
+
around = @open.last.nesting
|
|
95
|
+
return around unless namespace && RubyParsing.kind(node) != :constant_write_node
|
|
96
|
+
|
|
97
|
+
[qualified(node.constant_path.slice, around.at(0)), *around]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def qualified(written, outer)
|
|
101
|
+
written.start_with?("::") ? written.delete_prefix("::") : [outer, written].compact.join("::")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def extends_sig?(node)
|
|
105
|
+
node.name == :extend && node.arguments&.arguments&.first&.slice == "T::Sig"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through ../crystallise_spec.rb, which writes and rewrites RBS files.
|
|
4
|
+
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "runtime_analysis/ruby_parsing"
|
|
7
|
+
require_relative "rbs_member"
|
|
8
|
+
|
|
9
|
+
module RuntimeAnalysis
|
|
10
|
+
module Query
|
|
11
|
+
module Surfaces
|
|
12
|
+
class Crystallise
|
|
13
|
+
class RbsFile
|
|
14
|
+
HEADER = "# Written by `ra crystallise` from recorded runs.\n"
|
|
15
|
+
NOUN = "method"
|
|
16
|
+
|
|
17
|
+
def initialize(subject)
|
|
18
|
+
@subject = subject
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def noun = NOUN
|
|
22
|
+
|
|
23
|
+
def count
|
|
24
|
+
lines.count { |line| line.match?(/\A\s+(private )?def /) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def preview
|
|
28
|
+
HEADER + lines.map { |line| "#{line}\n" }.join
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def target
|
|
32
|
+
File.join("sig", @subject.file.delete_suffix(".rb").concat(".rbs"))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def save(root)
|
|
36
|
+
path = File.join(root, target)
|
|
37
|
+
ours?(path) && write(path)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def ours?(path)
|
|
43
|
+
!File.exist?(path) || File.read(path).start_with?(HEADER)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def write(path)
|
|
47
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
48
|
+
File.write(path, preview)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def lines
|
|
52
|
+
@lines ||= spaced(@subject.outline.scopes.map { |scope| block(scope, 0) })
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def block(scope, depth)
|
|
56
|
+
inside = spaced([members(scope, depth + 1), *nested(scope).map { |inner| block(inner, depth + 1) }])
|
|
57
|
+
inside.empty? ? [] : framed(scope.node, inside, " " * depth)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def framed(node, inside, indent)
|
|
61
|
+
["#{indent}#{header(node)}", *inside, "#{indent}end"]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def spaced(parts)
|
|
65
|
+
parts.reject(&:empty?).flat_map { |part| ["", *part] }.drop(1)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def nested(scope)
|
|
69
|
+
scope.scopes.select(&:namespace?)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def members(scope, depth)
|
|
73
|
+
methods = bodies(scope).flat_map { |body| @subject.seen_in(body) }
|
|
74
|
+
methods.map { |method| "#{" " * depth}#{member(method, @subject.lexical(scope))}" }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def bodies(scope)
|
|
78
|
+
[scope, *scope.scopes.reject(&:namespace?).flat_map { |inner| bodies(inner) }]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def member(method, lexical)
|
|
82
|
+
RbsMember.new(@subject.observed(method), lexical)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def header(node)
|
|
86
|
+
case RubyParsing.kind(node)
|
|
87
|
+
when :constant_write_node then "class #{node.name}"
|
|
88
|
+
when :module_node then "module #{node.constant_path.slice}"
|
|
89
|
+
else "class #{node.constant_path.slice}#{above(node)}"
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def above(node)
|
|
94
|
+
" < #{node.superclass.slice}" if RubyParsing.constant?(node.superclass)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "rbs_notation"
|
|
4
|
+
require_relative "lexical"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Query
|
|
8
|
+
module Surfaces
|
|
9
|
+
class Crystallise
|
|
10
|
+
class RbsMember
|
|
11
|
+
FORMS = { required: "%<type>s %<name>s", post: "%<type>s %<name>s", optional: "?%<type>s %<name>s",
|
|
12
|
+
rest: "*%<type>s %<name>s", keyword: "%<name>s: %<type>s",
|
|
13
|
+
optional_keyword: "?%<name>s: %<type>s", keyrest: "**%<type>s %<name>s" }.freeze
|
|
14
|
+
BLOCK = " ?{ (*untyped) -> untyped }"
|
|
15
|
+
|
|
16
|
+
def initialize(observed, lexical)
|
|
17
|
+
@observed = observed
|
|
18
|
+
@method = observed.method
|
|
19
|
+
@lexical = lexical
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_s
|
|
23
|
+
"#{"private " if @method.visibility == :private}def #{"self." if @method.class_method}#{@method.name}: " \
|
|
24
|
+
"(#{parameters.join(", ")})#{BLOCK if block?} -> #{result}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def parameters
|
|
30
|
+
@observed.parameters.reject { |each| each.kind == :block }.map do |each|
|
|
31
|
+
format(FORMS.fetch(each.kind), type: written(each.type), name: each.name).rstrip
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def block?
|
|
36
|
+
@observed.yields? || @observed.parameters.any? { |each| each.kind == :block }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def result
|
|
40
|
+
@observed.initializer? ? "void" : written(@observed.result)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def written(type)
|
|
44
|
+
RbsNotation.of(@lexical.type(type))
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "notation"
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Query
|
|
7
|
+
module Surfaces
|
|
8
|
+
class Crystallise
|
|
9
|
+
module RbsNotation
|
|
10
|
+
extend Notation
|
|
11
|
+
|
|
12
|
+
HOLDERS = { "Array" => 1, "Hash" => 2, "Set" => 1, "Range" => 1 }.freeze
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
def untyped = "untyped"
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def only_nil = "nil"
|
|
20
|
+
|
|
21
|
+
def union(present)
|
|
22
|
+
present.join(" | ")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def optional(present)
|
|
26
|
+
present.size > 1 ? "(#{union(present)})?" : "#{present.first}?"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def one(name, *held)
|
|
30
|
+
return a_class(itself_of(held)) if name == "Class"
|
|
31
|
+
|
|
32
|
+
takes = HOLDERS[name]
|
|
33
|
+
takes ? holding(name, held, takes) : name
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def a_class(itself)
|
|
37
|
+
itself ? "singleton(#{itself})" : "Class"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|