Sha256: db8040eabcdfd782d49a9b3dc321d3eb0d70b9745d48ebcceb86f546ab096f80

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

module GirFFI
  module Builders
    # Abstract parent class of the argument building classes. These
    # classes are used by FunctionBuilder to create the code that
    # processes each argument before and after the actual function call.
    class BaseArgumentBuilder
      KEYWORDS = [
        "alias", "and", "begin", "break", "case", "class", "def", "do",
        "else", "elsif", "end", "ensure", "false", "for", "if", "in",
        "module", "next", "nil", "not", "or", "redo", "rescue", "retry",
        "return", "self", "super", "then", "true", "undef", "unless",
        "until", "when", "while", "yield"
      ]

      attr_reader :arginfo
      attr_accessor :length_arg, :array_arg
      attr_accessor :is_closure

      def initialize var_gen, arginfo
        @var_gen = var_gen
        @arginfo = arginfo
        @length_arg = nil
        @array_arg = nil
        @is_closure = false
      end

      def name
        @name ||= safe(arginfo.name)
      end

      def direction
        @direction ||= arginfo.direction
      end

      def type_info
        @type_info ||= arginfo.argument_type
      end

      def specialized_type_tag
        type_info.flattened_tag
      end

      # TODO: Use class rather than class name
      def argument_class_name
        type_info.argument_class_name
      end

      def array_length_idx
        type_info.array_length
      end

      def safe name
        if KEYWORDS.include? name
          "#{name}_"
        else
          name
        end
      end

      def callarg
        @callarg ||= new_variable
      end

      def new_variable
        @var_gen.new_var
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.7.3 lib/gir_ffi/builders/base_argument_builder.rb
gir_ffi-0.7.2 lib/gir_ffi/builders/base_argument_builder.rb
gir_ffi-0.7.1 lib/gir_ffi/builders/base_argument_builder.rb
gir_ffi-0.7.0 lib/gir_ffi/builders/base_argument_builder.rb