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.



4096
4097
4098
# File 'lib/idl/ast.rb', line 4096

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

Instance Method Details

#conditionObject



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

def condition = @children[1]

#return_expressionObject



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

def return_expression = @children[0]

#return_type(symtab) ⇒ Type

Returns The actual return type.

Returns:

  • (Type)

    The actual return type



4108
4109
4110
# File 'lib/idl/ast.rb', line 4108

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



4113
4114
4115
# File 'lib/idl/ast.rb', line 4113

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

#return_value(symtab) ⇒ Integer, ...

Evaluate the compile-time return value of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on the taken path), execute the node and update the symtab

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Returns:

  • (Integer)

    The return value, if it is integral

  • (Boolean)

    The return value, if it is boolean

  • (nil)

    if the return value is not compile-time-known

Raises:

  • ValueError if, during evaluation, a node without a compile-time value is found



4119
4120
4121
4122
4123
4124
4125
4126
4127
# File 'lib/idl/ast.rb', line 4119

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

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

#return_values(symtab) ⇒ Array<Integer>, Array<Boolean>

Evaluate all possible compile-time return values of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on a possible path), execute the node and update the symtab

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Returns:

  • (Array<Integer>)

    The possible return values. Will be an empty array if there are no return values

  • (Array<Boolean>)

    The possible return values. Will be an empty array if there are no return values

Raises:

  • ValueError if, during evaluation, a node without a compile-time value is found



4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
# File 'lib/idl/ast.rb', line 4130

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



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

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:



4101
4102
4103
4104
4105
# File 'lib/idl/ast.rb', line 4101

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