Class: MilkTea::Types::Function

Inherits:
Base
  • Object
show all
Defined in:
lib/milk_tea/core/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.



1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
# File 'lib/milk_tea/core/types.rb', line 1312

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.



1310
1311
1312
# File 'lib/milk_tea/core/types.rb', line 1310

def external
  @external
end

#hashObject (readonly)

Returns the value of attribute hash.



1335
1336
1337
# File 'lib/milk_tea/core/types.rb', line 1335

def hash
  @hash
end

#nameObject (readonly)

Returns the value of attribute name.



1310
1311
1312
# File 'lib/milk_tea/core/types.rb', line 1310

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



1310
1311
1312
# File 'lib/milk_tea/core/types.rb', line 1310

def params
  @params
end

#receiver_editableObject (readonly)

Returns the value of attribute receiver_editable.



1310
1311
1312
# File 'lib/milk_tea/core/types.rb', line 1310

def receiver_editable
  @receiver_editable
end

#receiver_typeObject (readonly)

Returns the value of attribute receiver_type.



1310
1311
1312
# File 'lib/milk_tea/core/types.rb', line 1310

def receiver_type
  @receiver_type
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



1310
1311
1312
# File 'lib/milk_tea/core/types.rb', line 1310

def return_type
  @return_type
end

#variadicObject (readonly)

Returns the value of attribute variadic.



1310
1311
1312
# File 'lib/milk_tea/core/types.rb', line 1310

def variadic
  @variadic
end

Instance Method Details

#childrenObject



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

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)


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

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



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

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