orbacle 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b560995e47155365bd986cb4ef871acf85fb7cb4753c098f7f7f60bf86cb0a30
4
- data.tar.gz: 37ce9c0971c5b2afeee80687daf0cb1aede67e82bc43dfd207223244c1398d0b
3
+ metadata.gz: 7b916d0faf99f58f268106d55916e43a08023beb458ecafc81888902e523c025
4
+ data.tar.gz: a0846bb91366f78cbcb91077ddbf7454d47ce3e5660640d82046e545a305a001
5
5
  SHA512:
6
- metadata.gz: 546a7ca50aa3c04276a13a934e41cda17836fa795d33391c6d3420e0b4764d0a643940c141a58277e9e41f5b4ddebbd2deb4b0c6a10ff61931621e565012aed3
7
- data.tar.gz: d9834d7895f9ce459516104d3011fa88e4b06d8fb5178fc13dfcd776fd731692ad505d3e91886399a71387beafc3c6af6ceb300ee3fe62d2a1bac64655683209
6
+ metadata.gz: 0ccce4920723ee351415d28ddb6d90f7afb72f015f3d3297d62c99f9fb3edcc918591e5e80546ddb558aa53e3d355dc366a8a4f286f7942c48abd4605b933323
7
+ data.tar.gz: 5fc9bcfa9a643a76e44ec3589ead8aa70a31fb83c867a6d7ccef2fa39c1016b8dbbda56c4acaa417a4da604450ee9011baadee1647478d61782aeac5d58a90a5
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ * Jump to method definition works when jumping on the dot. Allows to jump to foo.(bar) (shorthand `call` notation).
3
+ * Major speedup for some big files, having large arrays or hashes
4
+ * Jump to definition now works when using it on `super` keyword.
5
+
2
6
  ## 0.1.0
3
7
 
4
8
  * First public version released
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orbacle (0.1.0)
5
- lsp-protocol (>= 0.0.3)
4
+ orbacle (0.2.0)
5
+ lsp-protocol (= 0.0.7)
6
6
  parser (~> 2.4.0.2)
7
7
  priority_queue_cxx
8
8
  rgl (~> 0.5.3)
@@ -30,7 +30,7 @@ GEM
30
30
  ice_nine (0.11.2)
31
31
  json (1.8.6)
32
32
  lazy_priority_queue (0.1.1)
33
- lsp-protocol (0.0.3)
33
+ lsp-protocol (0.0.7)
34
34
  memoizable (0.4.2)
35
35
  thread_safe (~> 0.3, >= 0.3.1)
36
36
  mini_portile2 (2.3.0)
@@ -116,4 +116,4 @@ DEPENDENCIES
116
116
  ruby-prof
117
117
 
118
118
  BUNDLED WITH
119
- 1.16.2
119
+ 1.16.4
data/Makefile CHANGED
@@ -8,28 +8,9 @@ mutant:
8
8
  @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::RubyParser"
9
9
  @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::ConstantsTree"
10
10
  @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::FindDefinitionUnderPosition"
11
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::LangServer"
11
+ @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::LangServer" --ignore-subject "Orbacle::LangServer#handle_text_document_did_change"
12
12
  @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::Engine"
13
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#add_lambda"
14
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_lambda"
15
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_instance_methods_from_class_id"
16
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#find_instance_method_from_class_id"
17
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_instance_methods_from_class_name"
18
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#find_instance_method_from_class_name"
19
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_class_methods_from_class_name"
20
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#find_class_method_from_class_name"
21
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#find_super_method"
22
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#change_method_visibility"
23
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_class"
24
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#add_klass"
25
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#add_mod"
26
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_module"
27
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_definition"
28
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_parent_of"
29
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#set_type_of"
30
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#type_of"
31
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_eigenclass_of_definition"
32
- @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree#get_methods"
13
+ @MUTANT_TESTING=true bundle exec mutant --include lib --require orbacle --use rspec "Orbacle::GlobalTree"
33
14
 
34
15
  test: test-unit test-performance
35
16
 
@@ -54,4 +35,6 @@ build:
54
35
  @gem build orbacle.gemspec
55
36
 
56
37
  install: build
57
- @gem install orbacle-0.0.1.gem
38
+ @gem install orbacle-0.2.0.gem
39
+
40
+ full: setup build install
data/README.md CHANGED
@@ -1,5 +1,3 @@
1
- [![CircleCI](https://circleci.com/gh/swistak35/orbacle/tree/master.svg?style=svg)](https://circleci.com/gh/swistak35/orbacle/tree/master)
2
-
3
1
  # Orbacle
4
2
 
5
3
  <img src="http://swistak35.com/img/orbacle-logo.png" alt="Orbacle logo" width="100px" align="left" />
@@ -15,8 +13,25 @@ Create a language server for ruby, which can be used across different code edito
15
13
  ## Current status
16
14
 
17
15
  Currently language server supports:
18
- * hover request - information about "type" of an expression
19
- * jump to definition - jump to definition of constant or method
16
+
17
+ ### Hover request
18
+
19
+ Information about "type" of an expression
20
+
21
+
22
+ ### Jump to definition
23
+
24
+ Works in following cases:
25
+ * used on constant -> jump to constant definition
26
+ * used on method call -> jump to definition of that method
27
+ * used on `super` keyword -> jump to the definition of method from the parent class (doesn't respect `include` / `prepend` yet)
28
+
29
+
30
+ ### V i d e o
31
+
32
+
33
+ ![vokoscreen-2018-08-01_21-38-46](https://user-images.githubusercontent.com/332289/43544509-6b240d06-95d3-11e8-81e8-fe03b2c1cf6f.gif)
34
+
20
35
 
21
36
  ## Setup
22
37
 
@@ -47,6 +62,15 @@ let g:LanguageClient_waitOutputTimeout = 240
47
62
 
48
63
  Currently I do not accept contributions, as this is part of MSc thesis. However features ideas and bug reports are accepted.
49
64
 
65
+ ## Support
66
+
67
+ If you have found a bug, feel free to create an issue. However, because of the fact that I'm focusing now more on the features required to MSc, support for other developers are lower priority for me.
68
+
69
+ ## Code status
70
+
71
+ [![CircleCI](https://circleci.com/gh/swistak35/orbacle/tree/master.svg?style=svg)](https://circleci.com/gh/swistak35/orbacle/tree/master)
72
+ [![Gem Version](https://badge.fury.io/rb/orbacle.svg)](https://badge.fury.io/rb/orbacle)
73
+
50
74
  ## Bibliography
51
75
 
52
76
  * [Tern](http://marijnhaverbeke.nl/blog/tern.html)
data/lib/orbacle.rb CHANGED
@@ -15,6 +15,18 @@ module Orbacle
15
15
  end
16
16
  end
17
17
 
18
+ def on_edges?(position)
19
+ on_left_edge?(position) || on_right_edge?(position)
20
+ end
21
+
22
+ def on_left_edge?(position)
23
+ position == self.start
24
+ end
25
+
26
+ def on_right_edge?(position)
27
+ position == self.end
28
+ end
29
+
18
30
  def end_line
19
31
  self.end.line
20
32
  end
@@ -60,8 +72,6 @@ module Orbacle
60
72
  BIG_VALUE = 0b111111100100000010110010110011101010000101010100001100100110001
61
73
  end
62
74
 
63
- require 'parser/current'
64
-
65
75
  require 'orbacle/ast_utils'
66
76
  require 'orbacle/bottom_type'
67
77
  require 'orbacle/builder/context'
@@ -75,6 +85,7 @@ require 'orbacle/constants_tree'
75
85
  require 'orbacle/define_builtins'
76
86
  require 'orbacle/engine'
77
87
  require 'orbacle/find_definition_under_position'
88
+ require 'orbacle/find_call_under_position'
78
89
  require 'orbacle/generic_type'
79
90
  require 'orbacle/global_tree'
80
91
  require 'orbacle/graph'
@@ -154,8 +154,6 @@ module Orbacle
154
154
  handle_case(ast, context)
155
155
  when :yield
156
156
  handle_yield(ast, context)
157
- when :block_pass
158
- handle_block_pass(ast, context)
159
157
 
160
158
  when :while then handle_while(ast, context)
161
159
  when :until then handle_while(ast, context)
@@ -202,7 +200,7 @@ module Orbacle
202
200
  include OperatorAssignmentProcessors
203
201
 
204
202
  def handle_lvasgn(ast, context)
205
- var_name = ast.children[0].to_s
203
+ var_name = ast.children[0]
206
204
  expr = ast.children[1]
207
205
 
208
206
  node_lvasgn = add_vertex(Node.new(:lvasgn, { var_name: var_name }, build_location_from_ast(context, ast)))
@@ -392,7 +390,7 @@ module Orbacle
392
390
  end
393
391
 
394
392
  def handle_lvar(ast, context)
395
- var_name = ast.children[0].to_s
393
+ var_name = ast.children[0]
396
394
 
397
395
  node_lvar = add_vertex(Node.new(:lvar, { var_name: var_name }, build_location_from_ast(context, ast)))
398
396
 
@@ -404,7 +402,7 @@ module Orbacle
404
402
  end
405
403
 
406
404
  def handle_ivar(ast, context)
407
- ivar_name = ast.children.first.to_s
405
+ ivar_name = ast.children.first
408
406
 
409
407
  ivar_definition_node = if context.selfie.klass?
410
408
  @graph.get_class_level_ivar_definition_node(context.scope, ivar_name)
@@ -423,7 +421,7 @@ module Orbacle
423
421
  end
424
422
 
425
423
  def handle_ivasgn(ast, context)
426
- ivar_name = ast.children[0].to_s
424
+ ivar_name = ast.children[0]
427
425
  expr = ast.children[1]
428
426
 
429
427
  node_ivasgn = add_vertex(Node.new(:ivasgn, { var_name: ivar_name }, build_location_from_ast(context, ast)))
@@ -451,7 +449,7 @@ module Orbacle
451
449
  end
452
450
 
453
451
  def handle_cvasgn(ast, context)
454
- cvar_name = ast.children[0].to_s
452
+ cvar_name = ast.children[0]
455
453
  expr = ast.children[1]
456
454
 
457
455
  node_cvasgn = add_vertex(Node.new(:cvasgn, { var_name: cvar_name }, build_location_from_ast(context, ast)))
@@ -471,7 +469,7 @@ module Orbacle
471
469
  end
472
470
 
473
471
  def handle_cvar(ast, context)
474
- cvar_name = ast.children.first.to_s
472
+ cvar_name = ast.children.first
475
473
 
476
474
  cvar_definition_node = @graph.get_cvar_definition_node(context.scope, cvar_name)
477
475
 
@@ -482,7 +480,7 @@ module Orbacle
482
480
  end
483
481
 
484
482
  def handle_gvasgn(ast, context)
485
- gvar_name = ast.children[0].to_s
483
+ gvar_name = ast.children[0]
486
484
  expr = ast.children[1]
487
485
 
488
486
  node_gvasgn = add_vertex(Node.new(:gvasgn, { var_name: gvar_name }, build_location_from_ast(context, ast)))
@@ -497,7 +495,7 @@ module Orbacle
497
495
  end
498
496
 
499
497
  def handle_gvar(ast, context)
500
- gvar_name = ast.children.first.to_s
498
+ gvar_name = ast.children.first
501
499
 
502
500
  gvar_definition_node = @graph.get_gvar_definition_node(gvar_name)
503
501
 
@@ -512,7 +510,7 @@ module Orbacle
512
510
  block_message_name = block_message_block_pass.children.last.children.last
513
511
  normal_arg_exprs = arg_exprs[0..-2]
514
512
  send_ast_type = csend ? :csend : :send
515
- send_ast = Parser::AST::Node.new(send_ast_type, [obj_expr, message_name.to_sym, *normal_arg_exprs])
513
+ send_ast = Parser::AST::Node.new(send_ast_type, [obj_expr, message_name, *normal_arg_exprs])
516
514
  arg_ast = Parser::AST::Node.new(:args, [Parser::AST::Node.new(:arg, [:__orbacle__x])])
517
515
  block_body_ast = Parser::AST::Node.new(:send, [Parser::AST::Node.new(:lvar, [:__orbacle__x]), block_message_name])
518
516
  block_ast = Parser::AST::Node.new(:block, [send_ast, arg_ast, block_body_ast])
@@ -528,7 +526,7 @@ module Orbacle
528
526
 
529
527
  def handle_send(ast, context, csend)
530
528
  obj_expr = ast.children[0]
531
- message_name = ast.children[1].to_s
529
+ message_name = ast.children[1]
532
530
  arg_exprs = ast.children[2..-1]
533
531
 
534
532
  return transform_symbol_shorthand(obj_expr, message_name, arg_exprs, csend, context) if transform_symbol_shorthand_applies?(arg_exprs)
@@ -544,10 +542,10 @@ module Orbacle
544
542
 
545
543
  final_context, call_arg_nodes, block_node = prepare_argument_nodes(obj_context, arg_exprs)
546
544
 
547
- return handle_changing_visibility(context, message_name.to_sym, arg_exprs) if obj_expr.nil? && ["public", "protected", "private"].include?(message_name)
548
- return handle_custom_attr_reader_send(context, arg_exprs, ast) if obj_expr.nil? && message_name == "attr_reader"
549
- return handle_custom_attr_writer_send(context, arg_exprs, ast) if obj_expr.nil? && message_name == "attr_writer"
550
- return handle_custom_attr_accessor_send(context, arg_exprs, ast) if obj_expr.nil? && message_name == "attr_accessor"
545
+ return handle_changing_visibility(context, message_name, arg_exprs) if obj_expr.nil? && [:public, :protected, :private].include?(message_name)
546
+ return handle_custom_attr_reader_send(context, arg_exprs, ast) if obj_expr.nil? && message_name == :attr_reader
547
+ return handle_custom_attr_writer_send(context, arg_exprs, ast) if obj_expr.nil? && message_name == :attr_writer
548
+ return handle_custom_attr_accessor_send(context, arg_exprs, ast) if obj_expr.nil? && message_name == :attr_accessor
551
549
 
552
550
  call_obj_node = add_vertex(Node.new(:call_obj, {}))
553
551
  @graph.add_edge(obj_node, call_obj_node)
@@ -592,7 +590,7 @@ module Orbacle
592
590
  return Result.new(final_node, context.with_visibility(new_visibility))
593
591
  elsif context.analyzed_klass_id
594
592
  methods_to_change_visibility = arg_exprs.map do |arg_expr|
595
- [:sym, :str].include?(arg_expr.type) ? arg_expr.children[0].to_s : nil
593
+ [:sym, :str].include?(arg_expr.type) ? arg_expr.children[0] : nil
596
594
  end.compact
597
595
  methods_to_change_visibility.each do |name|
598
596
  @tree.change_method_visibility(context.analyzed_klass_id, name, new_visibility)
@@ -638,12 +636,12 @@ module Orbacle
638
636
  end
639
637
 
640
638
  def define_attr_reader_method(context, ivar_name, location)
641
- ivar_definition_node = @graph.get_ivar_definition_node(context.scope, "@#{ivar_name}")
639
+ ivar_definition_node = @graph.get_ivar_definition_node(context.scope, :"@#{ivar_name}")
642
640
 
643
641
  metod = @tree.add_method(
644
642
  id_generator.call,
645
643
  context.analyzed_klass_id,
646
- ivar_name,
644
+ :"#{ivar_name}",
647
645
  location,
648
646
  context.analyzed_klass.method_visibility,
649
647
  GlobalTree::ArgumentsTree.new([], [], nil))
@@ -652,14 +650,14 @@ module Orbacle
652
650
  end
653
651
 
654
652
  def define_attr_writer_method(context, ivar_name, location)
655
- ivar_definition_node = @graph.get_ivar_definition_node(context.scope, "@#{ivar_name}")
653
+ ivar_definition_node = @graph.get_ivar_definition_node(context.scope, :"@#{ivar_name}")
656
654
 
657
- arg_name = "_attr_writer"
655
+ arg_name = :_attr_writer
658
656
  arg_node = add_vertex(Node.new(:formal_arg, { var_name: arg_name }))
659
657
  metod = @tree.add_method(
660
658
  id_generator.call,
661
659
  context.analyzed_klass_id,
662
- "#{ivar_name}=",
660
+ :"#{ivar_name}=",
663
661
  location,
664
662
  context.analyzed_klass.method_visibility,
665
663
  GlobalTree::ArgumentsTree.new([GlobalTree::ArgumentsTree::Regular.new(arg_name)], [], nil))
@@ -729,7 +727,7 @@ module Orbacle
729
727
  metod = @tree.add_method(
730
728
  id_generator.call,
731
729
  context.analyzed_klass_id,
732
- method_name.to_s,
730
+ method_name,
733
731
  build_location_from_ast(context, ast),
734
732
  context.analyzed_klass.method_visibility,
735
733
  arguments_tree)
@@ -799,8 +797,8 @@ module Orbacle
799
797
  ConstRef.from_ast(parent_klass_name_ast, context.nesting)
800
798
  end
801
799
 
802
- klass = @tree.add_klass(parent_name_ref)
803
- klass_constant = @tree.add_constant(
800
+ klass = @tree.add_class(parent_name_ref)
801
+ @tree.add_constant(
804
802
  GlobalTree::Constant.new(klass_name_ref.name, context.scope.increase_by_ref(klass_name_ref).decrease, build_location_from_ast(context, ast), klass.id))
805
803
 
806
804
  new_context = context
@@ -822,7 +820,7 @@ module Orbacle
822
820
 
823
821
  module_name_ref = ConstRef.from_ast(module_name_ast, context.nesting)
824
822
 
825
- mod = @tree.add_mod
823
+ mod = @tree.add_module
826
824
  @tree.add_constant(
827
825
  GlobalTree::Constant.new(
828
826
  module_name_ref.name, context.scope.increase_by_ref(module_name_ref).decrease, build_location_from_ast(context, ast), mod.id))
@@ -872,7 +870,7 @@ module Orbacle
872
870
  metod = @tree.add_method(
873
871
  id_generator.call,
874
872
  place_of_definition_id,
875
- method_name.to_s,
873
+ method_name,
876
874
  build_location_from_ast(context, ast),
877
875
  context.analyzed_klass.method_visibility,
878
876
  arguments_tree)
@@ -904,14 +902,14 @@ module Orbacle
904
902
  if expr_is_class_definition?(expr)
905
903
  parent_klass_name_ast = expr.children[2]
906
904
  parent_name_ref = parent_klass_name_ast.nil? ? nil : ConstRef.from_ast(parent_klass_name_ast, context.nesting)
907
- klass = @tree.add_klass(parent_name_ref)
905
+ klass = @tree.add_class(parent_name_ref)
908
906
  @tree.add_constant(
909
907
  GlobalTree::Constant.new(
910
908
  const_name_ref.name, context.scope.increase_by_ref(const_name_ref).decrease, build_location_from_ast(context, ast), klass.id))
911
909
 
912
910
  return Result.new(Node.new(:nil, {}), context)
913
911
  elsif expr_is_module_definition?(expr)
914
- mod = @tree.add_mod
912
+ mod = @tree.add_module
915
913
  @tree.add_constant(
916
914
  GlobalTree::Constant.new(
917
915
  const_name_ref.name, context.scope.increase_by_ref(const_name_ref).decrease, build_location_from_ast(context, ast), mod.id))
@@ -1280,7 +1278,7 @@ module Orbacle
1280
1278
  nodes = {}
1281
1279
 
1282
1280
  final_context = formal_arguments.reduce(context) do |current_context, arg_ast|
1283
- arg_name = arg_ast.children[0]&.to_s
1281
+ arg_name = arg_ast.children[0]
1284
1282
  maybe_arg_default_expr = arg_ast.children[1]
1285
1283
  location = build_location_from_ast(current_context, arg_ast)
1286
1284
 
@@ -1332,7 +1330,7 @@ module Orbacle
1332
1330
  args = []
1333
1331
 
1334
1332
  final_context = arg_asts.reduce(context) do |current_context, arg_ast|
1335
- arg_name = arg_ast.children[0]&.to_s
1333
+ arg_name = arg_ast.children[0]
1336
1334
 
1337
1335
  case arg_ast.type
1338
1336
  when :arg
@@ -70,7 +70,7 @@ module Orbacle
70
70
  def complete_assignment(partial_assignment_ast, full_rhs_ast)
71
71
  if partial_assignment_ast.type == :send
72
72
  send_obj_ast, accessor_method_name, _ = partial_assignment_ast.children
73
- partial_assignment_ast.updated(nil, [send_obj_ast, "#{accessor_method_name}=", full_rhs_ast])
73
+ partial_assignment_ast.updated(nil, [send_obj_ast, :"#{accessor_method_name}=", full_rhs_ast])
74
74
  elsif [:lvasgn, :ivasgn, :cvasgn, :casgn, :gvasgn].include?(partial_assignment_ast.type)
75
75
  partial_assignment_ast.append(full_rhs_ast)
76
76
  end
@@ -24,14 +24,6 @@ module Orbacle
24
24
 
25
25
  attr_reader :const_name, :is_absolute, :nesting
26
26
 
27
- def to_full_const_name
28
- if absolute?
29
- const_name
30
- else
31
- ConstName.new([*nesting.to_primitive, const_name.to_string])
32
- end
33
- end
34
-
35
27
  def absolute?
36
28
  @is_absolute
37
29
  end
@@ -13,71 +13,128 @@ module Orbacle
13
13
  add_dir_klass
14
14
  add_file_klass
15
15
  add_integer_klass
16
+ add_array_klass
16
17
  end
17
18
 
18
19
  private
19
20
  attr_reader :id_generator
20
21
 
21
22
  def add_object_klass
22
- klass = @tree.add_klass(nil)
23
+ klass = @tree.add_class(nil)
23
24
  @tree.add_constant(
24
25
  GlobalTree::Constant.new("Object", Scope.empty, nil, klass.id))
26
+ eigenclass = @tree.get_eigenclass_of_definition(klass.id)
25
27
 
26
28
  # BasicObject
27
- template_just_bool(klass, "==")
28
- template_just_bool(klass, "!")
29
- template_just_bool(klass, "!=")
30
- template_just_bool(klass, "equal?")
31
- template_just_int(klass, "object_id")
32
- template_just_int(klass, "__id__")
29
+ template_just_bool(klass, :"==")
30
+ template_just_bool(klass, :"!")
31
+ template_just_bool(klass, :"!=")
32
+ template_just_bool(klass, :equal?)
33
+ template_just_int(klass, :object_id)
34
+ template_just_int(klass, :__id__)
33
35
 
34
36
  # Object
35
- template_just_bool(klass, "!~")
36
- template_maybe_int(klass, "<=>")
37
- template_just_bool(klass, "===")
38
- template_just_nil(klass, "display")
39
- template_just_bool(klass, "eql?")
40
- template_just_bool(klass, "frozen?")
41
- template_just_bool(klass, "instance_of?")
42
- template_just_bool(klass, "instance_variable_defined?")
43
- template_just_bool(klass, "is_a?")
44
- template_just_str(klass, "inspect")
45
- template_just_bool(klass, "kind_of?")
46
- template_just_bool(klass, "nil?")
47
- template_just_bool(klass, "respond_to?")
48
- template_just_bool(klass, "respond_to_missing?")
49
- template_just_bool(klass, "tainted?")
50
- template_just_bool(klass, "untrusted?")
51
- template_just_str(klass, "to_s")
37
+ template_just_bool(klass, :"!~")
38
+ template_maybe_int(klass, :"<=>")
39
+ template_just_bool(klass, :"===")
40
+ template_caller_id(klass, :clone)
41
+ addm_object_class(klass)
42
+ template_just_nil(klass, :display)
43
+ template_caller_id(klass, :dup)
44
+ template_just_bool(klass, :eql?)
45
+ template_caller_id(klass, :freeze)
46
+ template_just_bool(klass, :frozen?)
47
+ template_just_bool(klass, :instance_of?)
48
+ template_just_bool(klass, :instance_variable_defined?)
49
+ template_just_bool(klass, :is_a?)
50
+ template_just_str(klass, :inspect)
51
+ template_caller_id(klass, :itself)
52
+ template_just_bool(klass, :kind_of?)
53
+ template_just_bool(klass, :nil?)
54
+ template_just_bool(klass, :respond_to?)
55
+ template_just_bool(klass, :respond_to_missing?)
56
+ template_caller_id(klass, :taint)
57
+ template_caller_id(klass, :trust)
58
+ template_just_bool(klass, :tainted?)
59
+ template_caller_id(klass, :untaint)
60
+ template_caller_id(klass, :untrust)
61
+ template_just_bool(klass, :untrusted?)
62
+ template_just_str(klass, :to_s)
63
+
64
+ addm_object_class(eigenclass)
52
65
  end
53
66
 
54
67
  def add_integer_klass
55
- klass = @tree.add_klass(nil)
68
+ klass = @tree.add_class(nil)
56
69
  @tree.add_constant(
57
70
  GlobalTree::Constant.new("Integer", Scope.empty, nil, klass.id))
58
71
 
59
- template_just_int(klass, "succ")
60
- template_just_int(klass, "+")
61
- template_just_int(klass, "-")
62
- template_just_int(klass, "*")
72
+ template_just_int(klass, :succ)
73
+ template_just_int(klass, :"+")
74
+ template_just_int(klass, :"-")
75
+ template_just_int(klass, :"*")
63
76
  end
64
77
 
65
78
  def add_dir_klass
66
- klass = @tree.add_klass(nil)
79
+ klass = @tree.add_class(nil)
67
80
  @tree.add_constant(
68
81
  GlobalTree::Constant.new("Dir", Scope.empty, nil, klass.id))
69
82
  eigenclass = @tree.get_eigenclass_of_definition(klass.id)
70
83
 
71
- template_just_array_of_str(eigenclass, "glob")
84
+ template_just_array_of_str(eigenclass, :glob)
72
85
  end
73
86
 
74
87
  def add_file_klass
75
- klass = @tree.add_klass(nil)
88
+ klass = @tree.add_class(nil)
76
89
  @tree.add_constant(
77
90
  GlobalTree::Constant.new("File", Scope.empty, nil, klass.id))
78
91
  eigenclass = @tree.get_eigenclass_of_definition(klass.id)
79
92
 
80
- template_just_str(eigenclass, "read")
93
+ template_just_str(eigenclass, :read)
94
+ end
95
+
96
+ def add_array_klass
97
+ klass = @tree.add_class(nil)
98
+ @tree.add_constant(GlobalTree::Constant.new("Array", Scope.empty, nil, klass.id))
99
+
100
+ add_array_map(klass)
101
+ add_array_each(klass)
102
+ end
103
+
104
+ def add_array_map(klass)
105
+ metod = add_method(klass.id, :map, :public, GlobalTree::ArgumentsTree.new([], []))
106
+ caller_node = Node.new(:caller, {})
107
+ result_node = Node.new(:method_result, {})
108
+ yield_arg = Node.new(:call_arg, {})
109
+ yield_result = Node.new(:yield_result, {})
110
+ yields = [Graph::Yield.new([yield_arg], yield_result)]
111
+ unwrap_array = Node.new(:unwrap_array, {})
112
+ wrap_array = Node.new(:wrap_array, {})
113
+ all_nodes = [caller_node, result_node, yield_arg, yield_result, unwrap_array, wrap_array]
114
+ all_edges = [
115
+ [caller_node, unwrap_array],
116
+ [unwrap_array, yield_arg],
117
+ [yield_result, wrap_array],
118
+ [wrap_array, result_node],
119
+ ]
120
+ @graph.store_metod_subgraph(metod.id, {}, caller_node, result_node, yields, all_nodes, all_edges)
121
+ end
122
+
123
+ def add_array_each(klass)
124
+ metod = add_method(klass.id, :each, :public, GlobalTree::ArgumentsTree.new([], []))
125
+ caller_node = Node.new(:caller, {})
126
+ result_node = Node.new(:method_result, {})
127
+ yield_arg = Node.new(:call_arg, {})
128
+ yield_result = Node.new(:yield_result, {})
129
+ yields = [Graph::Yield.new([yield_arg], yield_result)]
130
+ unwrap_array = Node.new(:unwrap_array, {})
131
+ all_nodes = [caller_node, result_node, yield_arg, yield_result, unwrap_array]
132
+ all_edges = [
133
+ [caller_node, unwrap_array],
134
+ [unwrap_array, yield_arg],
135
+ [caller_node, result_node],
136
+ ]
137
+ @graph.store_metod_subgraph(metod.id, {}, caller_node, result_node, yields, all_nodes, all_edges)
81
138
  end
82
139
 
83
140
  def template_just_int(klass, name)
@@ -120,18 +177,40 @@ module Orbacle
120
177
  @graph.add_edge(array_node, @graph.get_metod_nodes(metod.id).result)
121
178
  end
122
179
 
180
+ def template_caller_id(klass, name)
181
+ metod = add_method(klass.id, name, :public, GlobalTree::ArgumentsTree.new([], []))
182
+ caller_node = Node.new(:caller, {})
183
+ result_node = Node.new(:method_result, {})
184
+ all_nodes = [caller_node, result_node]
185
+ all_edges = [
186
+ [caller_node, result_node]
187
+ ]
188
+ @graph.store_metod_subgraph(metod.id, {}, caller_node, result_node, [], all_nodes, all_edges)
189
+ end
190
+
191
+ def addm_object_class(klass)
192
+ metod = add_method(klass.id, :class, :public, GlobalTree::ArgumentsTree.new([], []))
193
+ caller_node = Node.new(:caller, {})
194
+ extract_class_node = Node.new(:extract_class, {})
195
+ result_node = Node.new(:method_result, {})
196
+ all_nodes = [caller_node, extract_class_node, result_node]
197
+ all_edges = [
198
+ [caller_node, extract_class_node],
199
+ [extract_class_node, result_node]
200
+ ]
201
+ @graph.store_metod_subgraph(metod.id, {}, caller_node, result_node, [], all_nodes, all_edges)
202
+ end
203
+
123
204
  def template_args(klass, name)
124
- metod = @tree.add_method(
125
- generate_id,
126
- klass.id,
127
- name,
128
- nil,
129
- :public,
130
- GlobalTree::ArgumentsTree.new([], []))
205
+ metod = add_method(klass.id, name, :public, GlobalTree::ArgumentsTree.new([], []))
131
206
  @graph.store_metod_nodes(metod.id, {})
132
207
  metod
133
208
  end
134
209
 
210
+ def add_method(class_id, name, visibility, args)
211
+ @tree.add_method(generate_id, class_id, name, nil, visibility, args)
212
+ end
213
+
135
214
  def generate_id
136
215
  id_generator.call
137
216
  end