Class: Wood::Nodes::Operator

Inherits:
Node
  • Object
show all
Defined in:
lib/wood/nodes/operator.rb

Constant Summary collapse

BOOL_OPS =
[:<, :>, :<=, :>=, :==, :"!=", :"&&", :"||"]
NON_BOOL_OPS =
[:*, :/, :+, :-, :>>, :<<, :&, :|]

Instance Method Summary collapse

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/wood/nodes/operator.rb', line 8

def boolean?
  BOOL_OPS.include? name
end

#to_booleanObject



12
13
14
15
16
17
18
# File 'lib/wood/nodes/operator.rb', line 12

def to_boolean
  if boolean?
    return self
  else
    return Operator[name: :"!=", left: self, right: IntLiteral[0]]
  end
end

#typeObject



20
21
22
23
24
25
26
# File 'lib/wood/nodes/operator.rb', line 20

def type
  if boolean?
    Wood::Types::Bool
  else
    @type || Wood::Types::CommonType[@left.type, @right.type]
  end
end