Class: Riml::DefNode
- Inherits:
-
Struct
- Object
- Struct
- Riml::DefNode
- Includes:
- FullyNameable, Indentable, Visitable
- Defined in:
- lib/riml/nodes.rb
Overview
Method definition.
Direct Known Subclasses
Constant Summary collapse
- SPLAT =
lambda {|arg| arg == Riml::Constants::SPLAT_LITERAL || arg.to_s[0, 1] == "*"}
- DEFAULT_PARAMS =
lambda {|p| DefaultParamNode === p}
Constants included from Visitable
Instance Attribute Summary collapse
-
#bang ⇒ Object
Returns the value of attribute bang.
-
#expressions ⇒ Object
Returns the value of attribute expressions.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#name ⇒ Object
Returns the value of attribute name.
- #original_name ⇒ Object
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#private_function ⇒ Object
(also: #private_function?)
Returns the value of attribute private_function.
-
#scope_modifier ⇒ Object
Returns the value of attribute scope_modifier.
-
#sid ⇒ Object
(also: #sid?)
Returns the value of attribute sid.
Attributes included from Visitable
#compiled_output, #force_newline, #parent_node, #parser_info, #scope
Instance Method Summary collapse
-
#argument_variable_names ⇒ Object
[“arg1”, “arg2”}.
- #autoload? ⇒ Boolean
- #children ⇒ Object
- #default_param_nodes ⇒ Object
- #defined_on_dictionary? ⇒ Boolean
-
#initialize(*args) ⇒ DefNode
constructor
A new instance of DefNode.
- #is_splat_arg?(node) ⇒ Boolean
- #nested_function? ⇒ Boolean
- #nested_within ⇒ Object
- #shadowed_argument?(var_name) ⇒ Boolean
- #shadowed_argument_variable_names ⇒ Object
-
#splat ⇒ Object
returns the splat argument or nil.
-
#super_node ⇒ Object
FIXME: only detects top-level super nodes.
- #to_scope ⇒ Object
Methods included from FullyNameable
Methods included from Indentable
Methods included from Visitable
#accept, #force_newline_if_child_call_node?, #location_info
Methods included from Walkable
#child_after, #child_previous_to, #each, #index_by_children, #index_by_member, #insert_after, #insert_before, #next, #previous, #remove, #replace_with
Constructor Details
#initialize(*args) ⇒ DefNode
Returns a new instance of DefNode.
611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/riml/nodes.rb', line 611 def initialize(*args) super # max number of arguments in viml if parameters.reject(&DEFAULT_PARAMS).size > 20 error_msg = "can't have more than 20 parameters for function #{full_name}" error = Riml::UserArgumentError.new(error_msg, self) raise error end expressions.nodes.select { |node| DefNode === node}.each do |nested_func| nested_func.nested_within.unshift(self) end end |
Instance Attribute Details
#bang ⇒ Object
Returns the value of attribute bang
603 604 605 |
# File 'lib/riml/nodes.rb', line 603 def bang @bang end |
#expressions ⇒ Object
Returns the value of attribute expressions
603 604 605 |
# File 'lib/riml/nodes.rb', line 603 def expressions @expressions end |
#keywords ⇒ Object
Returns the value of attribute keywords
603 604 605 |
# File 'lib/riml/nodes.rb', line 603 def keywords @keywords end |
#name ⇒ Object
Returns the value of attribute name
603 604 605 |
# File 'lib/riml/nodes.rb', line 603 def name @name end |
#original_name ⇒ Object
627 628 629 |
# File 'lib/riml/nodes.rb', line 627 def original_name @original_name ||= name end |
#parameters ⇒ Object
Returns the value of attribute parameters
603 604 605 |
# File 'lib/riml/nodes.rb', line 603 def parameters @parameters end |
#private_function ⇒ Object Also known as: private_function?
Returns the value of attribute private_function.
608 609 610 |
# File 'lib/riml/nodes.rb', line 608 def private_function @private_function end |
#scope_modifier ⇒ Object
Returns the value of attribute scope_modifier
603 604 605 |
# File 'lib/riml/nodes.rb', line 603 def scope_modifier @scope_modifier end |
#sid ⇒ Object Also known as: sid?
Returns the value of attribute sid
603 604 605 |
# File 'lib/riml/nodes.rb', line 603 def sid @sid end |
Instance Method Details
#argument_variable_names ⇒ Object
[“arg1”, “arg2”}
633 634 635 |
# File 'lib/riml/nodes.rb', line 633 def argument_variable_names parameters.reject(&SPLAT) end |
#autoload? ⇒ Boolean
670 671 672 |
# File 'lib/riml/nodes.rb', line 670 def autoload? name.include?('#') end |
#children ⇒ Object
698 699 700 701 702 703 704 705 |
# File 'lib/riml/nodes.rb', line 698 def children children = if sid? [sid, expressions] else [expressions] end children.concat(default_param_nodes) end |
#default_param_nodes ⇒ Object
688 689 690 |
# File 'lib/riml/nodes.rb', line 688 def default_param_nodes parameters.select(&DEFAULT_PARAMS) end |
#defined_on_dictionary? ⇒ Boolean
666 667 668 |
# File 'lib/riml/nodes.rb', line 666 def defined_on_dictionary? keywords.include?('dict') end |
#is_splat_arg?(node) ⇒ Boolean
692 693 694 695 696 |
# File 'lib/riml/nodes.rb', line 692 def is_splat_arg?(node) splat = splat() return false unless splat GetVariableNode === node && node.scope_modifier.nil? && node.name == splat[1..-1] end |
#nested_function? ⇒ Boolean
649 650 651 |
# File 'lib/riml/nodes.rb', line 649 def nested_function? not nested_within.empty? end |
#nested_within ⇒ Object
645 646 647 |
# File 'lib/riml/nodes.rb', line 645 def nested_within @nested_within ||= [] end |
#shadowed_argument?(var_name) ⇒ Boolean
637 638 639 |
# File 'lib/riml/nodes.rb', line 637 def shadowed_argument?(var_name) shadowed_argument_variable_names.include?(var_name) end |
#shadowed_argument_variable_names ⇒ Object
641 642 643 |
# File 'lib/riml/nodes.rb', line 641 def shadowed_argument_variable_names @shadowed_argument_variable_names ||= Set.new end |
#splat ⇒ Object
returns the splat argument or nil
654 655 656 |
# File 'lib/riml/nodes.rb', line 654 def splat parameters.detect(&SPLAT) end |
#super_node ⇒ Object
FIXME: only detects top-level super nodes
677 678 679 |
# File 'lib/riml/nodes.rb', line 677 def super_node expressions.nodes.detect {|n| SuperNode === n} end |
#to_scope ⇒ Object
681 682 683 684 685 686 |
# File 'lib/riml/nodes.rb', line 681 def to_scope ScopeNode.new.tap do |scope| scope.argument_variable_names += argument_variable_names scope.function = self end end |