src/ipcc/ipcc.rb
def parse_prototype
      tok = @prototype.scan(/[A-Za-z0-9]+|[\(\),]|\*+/)
      #pp tok
      
      @return_type = tok.shift
      raise "only 'int' return types are supported at the current time" unless @return_type == 'int'
      
      @server_method = tok.shift
      raise "syntax error in: #{@prototype}" unless tok.shift == '('
      
      args = []
      arg = { :pass_by => :value, :ident => nil, :type => nil }
      node = nil 
      until node == ')'
        node = tok.shift
        case node
        when ')'
          break
        when '**'
          arg[:pass_by] = :reference # assumes 'char **'
          arg[:type] += ' **'
        when '*'
          arg[:pass_by] = :reference if arg[:type] != 'char'
          arg[:type] += ' *'
        when /u?int(8|16|32|64)_t/, 'int', 'long', 'bool', 'void', 'char'
          arg[:type] = node
        when 'const'
          # ignored, for now
        when ','
          args.push(arg.dup)
          arg = { :pass_by => :value, :ident => nil, :type => nil }
        when /[A-Za-z0-9]+/
          arg[:ident] = node
        else
          raise "syntax error in: #{@prototype}, node=#{@node}"
        end
      end
      args.push(arg)
      #pp args
      
      @accepts = []
      @returns = [] 
      for i in 0.upto(args.length - 1)
        arg = Argument.new(i, args[i][:ident], args[i][:type], args[i][:pass_by])
        if arg.pass_by == :value
          @accepts << arg
        else
          @returns << arg
        end
      end
      #pp @accepts
      #pp @returns
    end
# Given a C function prototype, parse it into a list of @accepts and @returns
Given a C function prototype, parse it into a list of @accepts and @returns
Given a C function prototype parse it into a list of @accepts and @returns
def parse_prototype
      tok = @prototype.scan(/[A-Za-z0-9]+|[\(\),]|\*+/)
      @return_type = tok.shift
      raise "only 'int' return types are supported at the current time" unless @return_type == 'int'
      @server_method = tok.shift
      raise "syntax error in: #{@prototype}" unless tok.shift == '('
      args = []
      arg = { :pass_by => :value, :ident => nil, :type => nil }
      node = nil 
      until node == ')'
        node = tok.shift
        case node
        when ')'
          break
        when '**'
          arg[:pass_by] = :reference 
          arg[:type] += ' **'
        when '*'
          arg[:pass_by] = :reference if arg[:type] != 'char'
          arg[:type] += ' *'
        when /u?int(8|16|32|64)_t/, 'int', 'long', 'bool', 'void', 'char'
          arg[:type] = node
        when 'const'
        when ','
          args.push(arg.dup)
          arg = { :pass_by => :value, :ident => nil, :type => nil }
        when /[A-Za-z0-9]+/
          arg[:ident] = node
        else
          raise "syntax error in: #{@prototype}, node=#{@node}"
        end
      end
      args.push(arg)
      @accepts = []
      @returns = [] 
      for i in 0.upto(args.length - 1)
        arg = Argument.new(i, args[i][:ident], args[i][:type], args[i][:pass_by])
        if arg.pass_by == :value
          @accepts << arg
        else
          @returns << arg
        end
      end
    end
def parse_prototype tok = @prototype . scan ( / [A-Za-z0-9]+|[ \( \) ,]| \* + / ) @return_type = tok . shift raise "only 'int' return types are supported at the current time" unless @return_type == 'int' @server_method = tok . shift raise "syntax error in: #{@prototype}" unless tok . shift == '(' args = [ ] arg = { :pass_by => :value , :ident => nil , :type => nil } node = nil until node == ')' node = tok . shift case node when ')' break when '**' arg [ :pass_by ] = :reference arg [ :type ] += ' **' when '*' arg [ :pass_by ] = :reference if arg [ :type ] != 'char' arg [ :type ] += ' *' when / u?int(8|16|32|64)_t / , 'int' , 'long' , 'bool' , 'void' , 'char' arg [ :type ] = node when 'const' when ',' args . push ( arg . dup ) arg = { :pass_by => :value , :ident => nil , :type => nil } when / [A-Za-z0-9]+ / arg [ :ident ] = node else raise "syntax error in: #{@prototype}, node=#{@node}" end end args . push ( arg ) @accepts = [ ] @returns = [ ] for i in 0 . upto ( args . length - 1 ) arg = Argument . new ( i , args [ i ] [ :ident ] , args [ i ] [ :type ] , args [ i ] [ :pass_by ] ) if arg . pass_by == :value @accepts << arg else @returns << arg end end end
Given a C function prototype, parse it into a list of @accepts and @returns
Given a C function prototype parse it into a list of @accepts and @returns
#pp tok # assumes 'char **' # ignored, for now #pp args #pp @accepts #pp @returns