Class: YARP::CallAndWriteNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of the ‘&&=` operator on a call.

foo.bar &&= value
^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) ⇒ CallAndWriteNode

def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, flags: Integer, read_name: String, write_name: String, operator_loc: Location, value: Node, location: Location) -> void



1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
# File 'lib/yarp/node.rb', line 1252

def initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location)
  @receiver = receiver
  @call_operator_loc = call_operator_loc
  @message_loc = message_loc
  @opening_loc = opening_loc
  @arguments = arguments
  @closing_loc = closing_loc
  @flags = flags
  @read_name = read_name
  @write_name = write_name
  @operator_loc = operator_loc
  @value = value
  @location = location
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



1231
1232
1233
# File 'lib/yarp/node.rb', line 1231

def arguments
  @arguments
end

#call_operator_locObject (readonly)

attr_reader call_operator_loc: Location?



1222
1223
1224
# File 'lib/yarp/node.rb', line 1222

def call_operator_loc
  @call_operator_loc
end

#closing_locObject (readonly)

attr_reader closing_loc: Location?



1234
1235
1236
# File 'lib/yarp/node.rb', line 1234

def closing_loc
  @closing_loc
end

#flagsObject (readonly)

attr_reader flags: Integer



1237
1238
1239
# File 'lib/yarp/node.rb', line 1237

def flags
  @flags
end

#message_locObject (readonly)

attr_reader message_loc: Location?



1225
1226
1227
# File 'lib/yarp/node.rb', line 1225

def message_loc
  @message_loc
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



1228
1229
1230
# File 'lib/yarp/node.rb', line 1228

def opening_loc
  @opening_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



1246
1247
1248
# File 'lib/yarp/node.rb', line 1246

def operator_loc
  @operator_loc
end

#read_nameObject (readonly)

attr_reader read_name: String



1240
1241
1242
# File 'lib/yarp/node.rb', line 1240

def read_name
  @read_name
end

#receiverObject (readonly)

attr_reader receiver: Node?



1219
1220
1221
# File 'lib/yarp/node.rb', line 1219

def receiver
  @receiver
end

#valueObject (readonly)

attr_reader value: Node



1249
1250
1251
# File 'lib/yarp/node.rb', line 1249

def value
  @value
end

#write_nameObject (readonly)

attr_reader write_name: String



1243
1244
1245
# File 'lib/yarp/node.rb', line 1243

def write_name
  @write_name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1268
1269
1270
# File 'lib/yarp/node.rb', line 1268

def accept(visitor)
  visitor.visit_call_and_write_node(self)
end

#call_operatorObject

def call_operator: () -> String?



1309
1310
1311
# File 'lib/yarp/node.rb', line 1309

def call_operator
  call_operator_loc&.slice
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



1273
1274
1275
# File 'lib/yarp/node.rb', line 1273

def child_nodes
  [receiver, arguments, value]
end

#closingObject

def closing: () -> String?



1324
1325
1326
# File 'lib/yarp/node.rb', line 1324

def closing
  closing_loc&.slice
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



1278
1279
1280
# File 'lib/yarp/node.rb', line 1278

def comment_targets
  [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> CallAndWriteNode



1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
# File 'lib/yarp/node.rb', line 1283

def copy(**params)
  CallAndWriteNode.new(
    params.fetch(:receiver) { receiver },
    params.fetch(:call_operator_loc) { call_operator_loc },
    params.fetch(:message_loc) { message_loc },
    params.fetch(:opening_loc) { opening_loc },
    params.fetch(:arguments) { arguments },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:flags) { flags },
    params.fetch(:read_name) { read_name },
    params.fetch(:write_name) { write_name },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:value) { value },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



1304
1305
1306
# File 'lib/yarp/node.rb', line 1304

def deconstruct_keys(keys)
  { receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, flags: flags, read_name: read_name, write_name: write_name, operator_loc: operator_loc, value: value, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
# File 'lib/yarp/node.rb', line 1343

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (receiver = self.receiver).nil?
    inspector << "├── receiver: ∅\n"
  else
    inspector << "├── receiver:\n"
    inspector << receiver.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  inspector << "├── call_operator_loc: #{inspector.location(call_operator_loc)}\n"
  inspector << "├── message_loc: #{inspector.location(message_loc)}\n"
  inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n"
  if (arguments = self.arguments).nil?
    inspector << "├── arguments: ∅\n"
  else
    inspector << "├── arguments:\n"
    inspector << arguments.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n"
  inspector << "├── flags: #{[("safe_navigation" if safe_navigation?), ("variable_call" if variable_call?)].compact.join(", ")}\n"
  inspector << "├── read_name: #{read_name.inspect}\n"
  inspector << "├── write_name: #{write_name.inspect}\n"
  inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector << "└── value:\n"
  inspector << inspector.child_node(value, "    ")
  inspector.to_str
end

#messageObject

def message: () -> String?



1314
1315
1316
# File 'lib/yarp/node.rb', line 1314

def message
  message_loc&.slice
end

#openingObject

def opening: () -> String?



1319
1320
1321
# File 'lib/yarp/node.rb', line 1319

def opening
  opening_loc&.slice
end

#operatorObject

def operator: () -> String



1339
1340
1341
# File 'lib/yarp/node.rb', line 1339

def operator
  operator_loc.slice
end

#safe_navigation?Boolean

def safe_navigation?: () -> bool

Returns:

  • (Boolean)


1329
1330
1331
# File 'lib/yarp/node.rb', line 1329

def safe_navigation?
  flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
end

#variable_call?Boolean

def variable_call?: () -> bool

Returns:

  • (Boolean)


1334
1335
1336
# File 'lib/yarp/node.rb', line 1334

def variable_call?
  flags.anybits?(CallNodeFlags::VARIABLE_CALL)
end