Class: Stone::AST::TypeOfExpression

Inherits:
Expression show all
Defined in:
lib/stone/ast/type_of_expression.rb

Instance Attribute Summary collapse

Attributes inherited from Stone::AST

#children, #name

Instance Method Summary collapse

Constructor Details

#initialize(inner_expression) ⇒ TypeOfExpression



12
13
14
15
# File 'lib/stone/ast/type_of_expression.rb', line 12

def initialize(inner_expression)
  @inner_expression = inner_expression
  @name = :type_of_expression
end

Instance Attribute Details

#inner_expressionObject (readonly)

Returns the value of attribute inner_expression.



10
11
12
# File 'lib/stone/ast/type_of_expression.rb', line 10

def inner_expression
  @inner_expression
end

Instance Method Details

#to_llir(builder, mod, scope = Stone::Scope.top_level) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/stone/ast/type_of_expression.rb', line 21

def to_llir(builder, mod, scope = Stone::Scope.top_level)
  # Union field access: extract type tag at runtime
  return @inner_expression.extract_union_type_tag(builder, mod, scope) if union_field_access?(mod)

  # Default: return compile-time type constant
  context = Stone::TypeContext.new(mod)
  result_type = @inner_expression.type(context)
  Stone::RTTI.type_constant_for(mod, result_type)
end

#to_sObject



31
32
33
# File 'lib/stone/ast/type_of_expression.rb', line 31

def to_s
  "Type.of(#{@inner_expression})"
end

#type(_context = nil) ⇒ Object



17
18
19
# File 'lib/stone/ast/type_of_expression.rb', line 17

def type(_context = nil)
  Stone::Type::Type
end