Class: MilkTea::Types::Function

Inherits:
Base
  • Object
show all
Defined in:
lib/milk_tea/core/types/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accept, #bitwise?, #boolean?, #field_c_name, #float?, #integer?, #numeric?, #sendable?, #void?

Constructor Details

#initialize(name, params:, return_type:, receiver_type: nil, receiver_editable: false, variadic: false, external: false) ⇒ Function

Returns a new instance of Function.



1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
# File 'lib/milk_tea/core/types/types.rb', line 1323

def initialize(name, params:, return_type:, receiver_type: nil, receiver_editable: false, variadic: false, external: false)
  @name = name
  @params = params.freeze
  @return_type = return_type
  @receiver_type = receiver_type
  @receiver_editable = receiver_editable
  @variadic = variadic
  @external = external
  @hash = [self.class, @params, return_type, receiver_type, receiver_editable, variadic].hash
  freeze
end

Instance Attribute Details

#externalObject (readonly)

Returns the value of attribute external.



1321
1322
1323
# File 'lib/milk_tea/core/types/types.rb', line 1321

def external
  @external
end

#hashObject (readonly)

Returns the value of attribute hash.



1346
1347
1348
# File 'lib/milk_tea/core/types/types.rb', line 1346

def hash
  @hash
end

#nameObject (readonly)

Returns the value of attribute name.



1321
1322
1323
# File 'lib/milk_tea/core/types/types.rb', line 1321

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



1321
1322
1323
# File 'lib/milk_tea/core/types/types.rb', line 1321

def params
  @params
end

#receiver_editableObject (readonly)

Returns the value of attribute receiver_editable.



1321
1322
1323
# File 'lib/milk_tea/core/types/types.rb', line 1321

def receiver_editable
  @receiver_editable
end

#receiver_typeObject (readonly)

Returns the value of attribute receiver_type.



1321
1322
1323
# File 'lib/milk_tea/core/types/types.rb', line 1321

def receiver_type
  @receiver_type
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



1321
1322
1323
# File 'lib/milk_tea/core/types/types.rb', line 1321

def return_type
  @return_type
end

#variadicObject (readonly)

Returns the value of attribute variadic.



1321
1322
1323
# File 'lib/milk_tea/core/types/types.rb', line 1321

def variadic
  @variadic
end

Instance Method Details

#childrenObject



1356
1357
1358
1359
1360
1361
# File 'lib/milk_tea/core/types/types.rb', line 1356

def children
  result = params.flat_map { |p| [p.type, p.boundary_type].compact }
  result << return_type
  result << receiver_type if receiver_type
  result
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


1335
1336
1337
1338
1339
1340
1341
1342
# File 'lib/milk_tea/core/types/types.rb', line 1335

def eql?(other)
  other.is_a?(Function) &&
    other.params == params &&
    other.return_type == return_type &&
    other.receiver_type == receiver_type &&
    other.receiver_editable == receiver_editable &&
    other.variadic == variadic
end

#to_sObject



1349
1350
1351
1352
1353
1354
# File 'lib/milk_tea/core/types/types.rb', line 1349

def to_s
  pieces = []
  pieces << receiver_type.to_s if receiver_type
  pieces << name if name
  "fn #{pieces.join('.')}"
end