class ParseC::Function
Defined function.
Attributes
name[R]
Func name.
variadic[R]
Variadic (end with ellipsis).
Public Class Methods
new( name, variadic = false )
click to toggle source
Initialize function object. Default return type to void.
@param name [String] Func name.
# File lib/parsec.rb, line 249 def initialize( name, variadic = false ) @name = name @variadic = variadic @args = {} @returnType = 'void' end
Public Instance Methods
addArgument( name, type )
click to toggle source
Add argument to functions argument list.
# File lib/parsec.rb, line 264 def addArgument( name, type ) @args[ name ] = type end
argDecl( name )
click to toggle source
Get argument declarations String presentation.
# File lib/parsec.rb, line 284 def argDecl( name ) if name # Has type. "#{@args[ name ]} #{name}" else # Void/variadic. @args[ name ] end end
declaration()
click to toggle source
Return functions declation as String.
# File lib/parsec.rb, line 296 def declaration "#{@returnType} #{@name}( #{(@args.keys.map { |k| argDecl(k) }).join(', ')} );" end
done()
click to toggle source
Close function defition. If argument list is empty, then arg list contains only void.
# File lib/parsec.rb, line 271 def done if @variadic @args[ nil ] = '...' end if @args.empty? @args = { nil => 'void' } end self end
setReturnType( type )
click to toggle source
Set function return type.
# File lib/parsec.rb, line 258 def setReturnType( type ) @returnType = type end