Class: Rubex::AST::TopStatement::MethodDef
- Inherits:
-
Object
- Object
- Rubex::AST::TopStatement::MethodDef
- Includes:
- Helpers::Writers
- Defined in:
- lib/rubex/ast/top_statement/method_def.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arg_list ⇒ Object
Method arguments.
-
#entry ⇒ Object
readonly
Symbol Table entry.
-
#name ⇒ Object
readonly
Ruby name of the method.
-
#scope ⇒ Object
readonly
Instance of Scope::Local for this method.
-
#self_name ⇒ Object
readonly
Variable name that identifies ‘self’.
-
#statements ⇒ Object
readonly
The statments/expressions contained within the method.
Instance Method Summary collapse
- #analyse_statement(outer_scope) ⇒ Object
-
#generate_code(code, c_function: false) ⇒ Object
Option c_function - When set to true, certain code that is not required for Ruby methods will be generated too.
-
#initialize(name, arg_list, statements) ⇒ MethodDef
constructor
A new instance of MethodDef.
- #rescan_declarations(_scope) ⇒ Object
Methods included from Helpers::Writers
#declare_carrays, #declare_ruby_objects, #declare_temps, #declare_types, #declare_vars, #sue_footer, #sue_header, #write_char_2_ruby_str_code, #write_char_2_ruby_str_header, #write_usability_functions_code, #write_usability_functions_header, #write_usability_macros
Constructor Details
#initialize(name, arg_list, statements) ⇒ MethodDef
Returns a new instance of MethodDef.
20 21 22 23 24 25 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 20 def initialize(name, arg_list, statements) @name = name @arg_list = arg_list @statements = statements @self_name = Rubex::ARG_PREFIX + 'self' end |
Instance Attribute Details
#arg_list ⇒ Object
Method arguments. Accessor because arguments need to be modified in
case of auxillary C functions of attach classes.
10 11 12 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 10 def arg_list @arg_list end |
#entry ⇒ Object (readonly)
Symbol Table entry.
14 15 16 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 14 def entry @entry end |
#name ⇒ Object (readonly)
Ruby name of the method.
7 8 9 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 7 def name @name end |
#scope ⇒ Object (readonly)
Instance of Scope::Local for this method.
16 17 18 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 16 def scope @scope end |
#self_name ⇒ Object (readonly)
Variable name that identifies ‘self’
18 19 20 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 18 def self_name @self_name end |
#statements ⇒ Object (readonly)
The statments/expressions contained within the method.
12 13 14 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 12 def statements @statements end |
Instance Method Details
#analyse_statement(outer_scope) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 27 def analyse_statement(outer_scope) @entry = outer_scope.find @name @scope = @entry.type.scope @scope.type = @entry.type @scope.self_name = @self_name @arg_list = @entry.type.arg_list @statements.each do |stat| stat.analyse_statement @scope end end |
#generate_code(code, c_function: false) ⇒ Object
Option c_function - When set to true, certain code that is not required
for Ruby methods will be generated too.
40 41 42 43 44 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 40 def generate_code(code, c_function: false) code.block do generate_function_definition code, c_function: c_function end end |
#rescan_declarations(_scope) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/rubex/ast/top_statement/method_def.rb', line 46 def rescan_declarations(_scope) @statements.each do |stat| stat.respond_to?(:rescan_declarations) && stat.rescan_declarations(@scope) end end |