Class: Rubex::AST::Statement::CFunctionDecl

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/statement/c_function_decl.rb

Instance Attribute Summary

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #statement?

Constructor Details

#initialize(type, return_ptr_level, name, arg_list) ⇒ CFunctionDecl

Returns a new instance of CFunctionDecl.



5
6
7
8
# File 'lib/rubex/ast/statement/c_function_decl.rb', line 5

def initialize(type, return_ptr_level, name, arg_list)
  @type, @return_ptr_level, @name, @arg_list = type, return_ptr_level,
  name, arg_list
end

Instance Method Details

#analyse_statement(local_scope, extern: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubex/ast/statement/c_function_decl.rb', line 10

def analyse_statement(local_scope, extern: false)
  @arg_list&.analyse_statement(local_scope, extern: extern)
  c_name = extern ? @name : (Rubex::C_FUNC_PREFIX + @name)
  @entry = local_scope.add_c_method(
    name: @name,
    c_name: c_name,
    return_type: Helpers.determine_dtype(@type, @return_ptr_level),
    arg_list: @arg_list,
    scope: nil,
    extern: extern
  )
end

#generate_code(code, local_scope) ⇒ Object



23
24
25
26
# File 'lib/rubex/ast/statement/c_function_decl.rb', line 23

def generate_code(code, local_scope)
  super
  code << "/* C function #{@name} declared.*/" if @entry.extern?
end