Class: Idl::ConditionalReturnStatementAst

Inherits:
AstNode
  • Object
show all
Includes:
Returns
Defined in:
lib/idl/ast.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, return_expression, condition) ⇒ ConditionalReturnStatementAst

Returns a new instance of ConditionalReturnStatementAst.



4073
4074
4075
# File 'lib/idl/ast.rb', line 4073

def initialize(input, interval, return_expression, condition)
  super(input, interval, [return_expression, condition])
end

Instance Method Details

#conditionObject



4071
# File 'lib/idl/ast.rb', line 4071

def condition = @children[1]

#return_expressionObject



4070
# File 'lib/idl/ast.rb', line 4070

def return_expression = @children[0]

#return_type(symtab) ⇒ Object



4085
4086
4087
# File 'lib/idl/ast.rb', line 4085

def return_type(symtab)
  return_expression.return_type(symtab)
end

#return_types(symtab) ⇒ Array<Type>

Returns List of actual return types.

Returns:

  • (Array<Type>)

    List of actual return types



4090
4091
4092
# File 'lib/idl/ast.rb', line 4090

def return_types(symtab)
  return_expression.return_types(symtab)
end

#return_value(symtab) ⇒ Object



4096
4097
4098
4099
4100
4101
4102
4103
4104
# File 'lib/idl/ast.rb', line 4096

def return_value(symtab)
  cond = condition.value(symtab)

  if cond
    return_expression.return_value(symtab)
  else
    nil
  end
end

#return_values(symtab) ⇒ Object



4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
# File 'lib/idl/ast.rb', line 4107

def return_values(symtab)
  value_result = value_try do
    cond = condition.value(symtab)

    return cond ? return_expression.return_values(symtab) : EMPTY_ARRAY

  end
  value_else(value_result) do
    # condition isn't known, so the return value is always possible
    return_expression.return_values(symtab)
  end
end

#to_idlObject



4120
# File 'lib/idl/ast.rb', line 4120

def to_idl = "#{return_expression.to_idl} if (#{condition.to_idl});"

#type_check(symtab) ⇒ void

This method returns an undefined value.

type check this node and all children

Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError

Parameters:

Raises:



4078
4079
4080
4081
4082
# File 'lib/idl/ast.rb', line 4078

def type_check(symtab)
  condition.type_check(symtab)
  type_error "Condition must be boolean" unless condition.type(symtab).kind == :boolean
  return_expression.type_check(symtab)
end