Module: Rucc::Node::Conv
- Included in:
- Rucc::Node
- Defined in:
- lib/rucc/node/conv.rb
Overview
Type conversion
Instance Method Summary collapse
Instance Method Details
#conv(node) ⇒ Node
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rucc/node/conv.rb', line 9 def conv(node) return nil if node.nil? ty = node.ty case ty.kind when Kind::ARRAY # C11 6.3.2.1p3: An array of T is converted to a pointer to T. return Node.ast_uop(AST::CONV, Type.make_ptr_type(ty.ptr), node) when Kind::FUNC # C11 6.3.2.1p4: A function designator is converted to a pointer to the function. return Node.ast_uop(AST::ADDR, Type.make_ptr_type(ty), node) when Kind::SHORT, Kind::CHAR, Kind::BOOL # C11 6.3.1.1p2: The integer promotions return Node.ast_conv(Type::INT, node) when Kind::INT if !ty.bitsize.nil? && ty.bitsize > 0 return Node.ast_conv(Type::INT, node) end end node end |