From 6d38b8e82ab0e46e1acdddc93de4efb4fee9a55e Mon Sep 17 00:00:00 2001
From: Jakob Rath <git@jakobrath.eu>
Date: Sun, 15 Dec 2013 11:29:04 +0100
Subject: [PATCH] Use typedefs for pointers.

---
 src/bindings/ruby/lib/hammer/internal.rb | 89 ++++++++++++------------
 1 file changed, 46 insertions(+), 43 deletions(-)

diff --git a/src/bindings/ruby/lib/hammer/internal.rb b/src/bindings/ruby/lib/hammer/internal.rb
index 8132567b..3ef39a1f 100644
--- a/src/bindings/ruby/lib/hammer/internal.rb
+++ b/src/bindings/ruby/lib/hammer/internal.rb
@@ -6,53 +6,56 @@ module Hammer
 
     ffi_lib 'libhammer.dylib'
 
+    typedef :pointer, :h_parser
+    typedef :pointer, :h_parse_result
+
     # run a parser
-    attach_function :h_parse, [:pointer, :string, :size_t], :pointer
+    attach_function :h_parse, [:h_parser, :string, :size_t], :h_parse_result
 
     # build a parser
-    attach_function :h_token, [:string, :size_t], :pointer
-    attach_function :h_ch, [:uint8], :pointer
-    attach_function :h_ch_range, [:uint8, :uint8], :pointer
-    attach_function :h_int_range, [:int64, :int64], :pointer
-    attach_function :h_bits, [:size_t, :bool], :pointer
-    attach_function :h_int64, [], :pointer
-    attach_function :h_int32, [], :pointer
-    attach_function :h_int16, [], :pointer
-    attach_function :h_int8,  [], :pointer
-    attach_function :h_uint64, [], :pointer
-    attach_function :h_uint32, [], :pointer
-    attach_function :h_uint16, [], :pointer
-    attach_function :h_uint8,  [], :pointer
-    attach_function :h_whitespace, [:pointer], :pointer
-    attach_function :h_left,   [:pointer, :pointer], :pointer
-    attach_function :h_right,  [:pointer, :pointer], :pointer
-    attach_function :h_middle, [:pointer, :pointer, :pointer], :pointer
-    #attach_function :h_in, [:string, :size_t], :pointer
-    #attach_function :h_not_in, [:string, :size_t], :pointer
-    attach_function :h_end_p, [], :pointer
-    attach_function :h_nothing_p, [], :pointer
-    attach_function :h_sequence, [:varargs], :pointer
-    attach_function :h_choice, [:varargs], :pointer
-    attach_function :h_butnot, [:pointer, :pointer], :pointer
-    attach_function :h_difference, [:pointer, :pointer], :pointer
-    attach_function :h_xor, [:pointer, :pointer], :pointer
-    attach_function :h_many, [:pointer], :pointer
-    attach_function :h_many1, [:pointer], :pointer
-    #attach_function :h_repeat_n, [:pointer, :size_t], :pointer
-    attach_function :h_optional, [:pointer], :pointer
-    attach_function :h_ignore, [:pointer], :pointer
-    attach_function :h_sepBy, [:pointer, :pointer], :pointer
-    attach_function :h_sepBy1, [:pointer, :pointer], :pointer
-    attach_function :h_epsilon_p, [], :pointer
-    attach_function :h_length_value, [:pointer, :pointer], :pointer
-    attach_function :h_and, [:pointer], :pointer
-    attach_function :h_not, [:pointer], :pointer
+    attach_function :h_token, [:string, :size_t], :h_parser
+    attach_function :h_ch, [:uint8], :h_parser
+    attach_function :h_ch_range, [:uint8, :uint8], :h_parser
+    attach_function :h_int_range, [:int64, :int64], :h_parser
+    attach_function :h_bits, [:size_t, :bool], :h_parser
+    attach_function :h_int64, [], :h_parser
+    attach_function :h_int32, [], :h_parser
+    attach_function :h_int16, [], :h_parser
+    attach_function :h_int8,  [], :h_parser
+    attach_function :h_uint64, [], :h_parser
+    attach_function :h_uint32, [], :h_parser
+    attach_function :h_uint16, [], :h_parser
+    attach_function :h_uint8,  [], :h_parser
+    attach_function :h_whitespace, [:h_parser], :h_parser
+    attach_function :h_left,   [:h_parser, :h_parser], :h_parser
+    attach_function :h_right,  [:h_parser, :h_parser], :h_parser
+    attach_function :h_middle, [:h_parser, :h_parser, :h_parser], :h_parser
+    #attach_function :h_in, [:string, :size_t], :h_parser
+    #attach_function :h_not_in, [:string, :size_t], :h_parser
+    attach_function :h_end_p, [], :h_parser
+    attach_function :h_nothing_p, [], :h_parser
+    attach_function :h_sequence, [:varargs], :h_parser
+    attach_function :h_choice, [:varargs], :h_parser
+    attach_function :h_butnot, [:h_parser, :h_parser], :h_parser
+    attach_function :h_difference, [:h_parser, :h_parser], :h_parser
+    attach_function :h_xor, [:h_parser, :h_parser], :h_parser
+    attach_function :h_many, [:h_parser], :h_parser
+    attach_function :h_many1, [:h_parser], :h_parser
+    #attach_function :h_repeat_n, [:h_parser, :size_t], :h_parser
+    attach_function :h_optional, [:h_parser], :h_parser
+    attach_function :h_ignore, [:h_parser], :h_parser
+    attach_function :h_sepBy, [:h_parser, :h_parser], :h_parser
+    attach_function :h_sepBy1, [:h_parser, :h_parser], :h_parser
+    attach_function :h_epsilon_p, [], :h_parser
+    attach_function :h_length_value, [:h_parser, :h_parser], :h_parser
+    attach_function :h_and, [:h_parser], :h_parser
+    attach_function :h_not, [:h_parser], :h_parser
 
-    attach_function :h_indirect, [], :pointer
-    attach_function :h_bind_indirect, [:pointer, :pointer], :void
+    attach_function :h_indirect, [], :h_parser
+    attach_function :h_bind_indirect, [:h_parser, :h_parser], :void
 
-    #attach_function :h_action, [:pointer, ...], :pointer
-    #attach_function :h_attr_bool, [:pointer, ...], :pointer
+    #attach_function :h_action, [:h_parser, ...], :h_parser
+    #attach_function :h_attr_bool, [:h_parser, ...], :h_parser
 
     #class HParseResult < FFI::Struct
     #  layout  :ast, :pointer,
@@ -61,7 +64,7 @@ module Hammer
     #end
 
     # free the parse result
-    attach_function :h_parse_result_free, [:pointer], :void
+    attach_function :h_parse_result_free, [:h_parse_result], :void
 
     # TODO: Does the HParser* need to be freed?
   end
-- 
GitLab