Class: FuncType

Inherits:
Type show all
Defined in:
lib/tecsgen/core/types.rb

Direct Known Subclasses

CFuncType

Instance Method Summary collapse

Methods inherited from Type

#cast, #clear_max, #equal?, #get_ID_str, #get_bit_size, #get_original_type, #has_pointer?, #has_sized_pointer?, #has_unsized_string?, #is_const?, #is_void?, #is_volatile?, #print_info, print_info_post, #print_info_post, reset_print_info, #set_qualifier, #set_scs

Methods inherited from Node

#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale

Constructor Details

#initialize(paramlist = nil) ⇒ FuncType

@has_receive

bool : has [receive] parameter



1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
# File 'lib/tecsgen/core/types.rb', line 1037

def initialize(paramlist = nil)
  super()

  @has_in = false
  @has_inout = false
  @has_out = false
  @has_send = false
  @has_receive = false

  @paramlist = paramlist
  @b_oneway = false
  if paramlist
    paramlist.check_param
  else
    @paramlist = ParamList.new(nil)
  end
  @paramlist.set_owner self # ParamList
  @paramlist.get_items.each{|p|
    case p.get_direction
    when :IN
      @has_in = true
    when :INOUT
      @has_inout = true
    when :OUT
      @has_out = true
    when :SEND
      @has_send = true
    when :RECEIVE
      @has_receive = true
    else
      raise "unkown direction"
    end
  }
end

Instance Method Details

#checkObject

意味的誤りがあれば、文字列を返す



1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
# File 'lib/tecsgen/core/types.rb', line 1072

def check # 意味的誤りがあれば、文字列を返す
  if @type.class == ArrayType # 配列を返す関数
    return "function returning array"
  elsif @type.class == FuncType # 関数を返す関数
    return "function returning function"
  end
  return @type.check # 関数の return する型のチェック

  # パラメータの型のチェックは ParamList#check_param で行う
end

#check_init(locale, ident, initializer, kind, attribute = nil) ⇒ Object



1089
1090
1091
1092
# File 'lib/tecsgen/core/types.rb', line 1089

def check_init(locale, ident, initializer, kind, attribute = nil)
  cdl_error2(locale, "T1028 $1: cannot initialize function pointer", ident)
  return
end

#check_struct_tag(kind) ⇒ Object



1083
1084
1085
1086
1087
# File 'lib/tecsgen/core/types.rb', line 1083

def check_struct_tag(kind)
  @type.check_struct_tag kind
  # ParamDecl でもチェックされるので、ここではチェックしない
  # @paramlist.check_struct_tag kind
end

#get_paramlistObject



1119
1120
1121
# File 'lib/tecsgen/core/types.rb', line 1119

def get_paramlist
  @paramlist
end

#get_typeObject

return type を返す

return type を返す get_return_type とすべきだった



1106
1107
1108
# File 'lib/tecsgen/core/types.rb', line 1106

def get_type
  @type
end

#get_type_strObject



1110
1111
1112
# File 'lib/tecsgen/core/types.rb', line 1110

def get_type_str
  return @type.get_type_str
end

#get_type_str_postObject



1114
1115
1116
1117
# File 'lib/tecsgen/core/types.rb', line 1114

def get_type_str_post
  # 型だけを返す (仮引数の名前を含めない)
  @paramlist.to_str(false)
end

#has_in?Boolean

パラメータが in, inout, out, send, receive を持つか

Returns:

  • (Boolean)


1154
1155
1156
# File 'lib/tecsgen/core/types.rb', line 1154

def has_in?
  @has_in
end

#has_inout?Boolean

Returns:

  • (Boolean)


1158
1159
1160
# File 'lib/tecsgen/core/types.rb', line 1158

def has_inout?
  @has_inout
end

#has_inward?Boolean

入力方向のパラメータを持つか

Returns:

  • (Boolean)


1175
1176
1177
# File 'lib/tecsgen/core/types.rb', line 1175

def has_inward?
  @has_in || @has_inout || @has_send
end

#has_out?Boolean

Returns:

  • (Boolean)


1162
1163
1164
# File 'lib/tecsgen/core/types.rb', line 1162

def has_out?
  @has_out
end

#has_outward?Boolean

出力方向のパラメータを持つか

Returns:

  • (Boolean)


1180
1181
1182
# File 'lib/tecsgen/core/types.rb', line 1180

def has_outward?
  @has_inout || @has_out || @has_receive
end

#has_receive?Boolean

Returns:

  • (Boolean)


1170
1171
1172
# File 'lib/tecsgen/core/types.rb', line 1170

def has_receive?
  @has_receive
end

#has_send?Boolean

Returns:

  • (Boolean)


1166
1167
1168
# File 'lib/tecsgen/core/types.rb', line 1166

def has_send?
  @has_send
end

#is_oneway?Boolean

Returns:

  • (Boolean)


1139
1140
1141
# File 'lib/tecsgen/core/types.rb', line 1139

def is_oneway?
  @b_oneway
end

#need_PPAllocator?(b_opaque = false) ⇒ Boolean

Push Pop Allocator が必要か?

Transparent RPC の場合 oneway かつ in の配列(size_is, count_is, string のいずれかで修飾)がある

Returns:

  • (Boolean)


1145
1146
1147
1148
1149
1150
1151
# File 'lib/tecsgen/core/types.rb', line 1145

def need_PPAllocator?(b_opaque = false)
  if @b_oneway || b_opaque
    return @paramlist.need_PPAllocator?(b_opaque)
  else
    return false
  end
end

#set_oneway(b_oneway) ⇒ Object



1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/tecsgen/core/types.rb', line 1123

def set_oneway(b_oneway)
  @b_oneway = b_oneway

  if (@type.get_type_str != "ER" && @type.get_type_str != "void") || @type.get_type_str_post != ""
    cdl_error("T1029 oneway function cannot return type \'$1$2\', \'void\' or \'ER\' is permitted", @type.get_type_str, @type.get_type_str_post)
  end

  if @paramlist
    @paramlist.get_items.each{|p|
      if p.get_direction != :IN && p.get_direction != :SEND
        cdl_error("T1030 oneway function cannot have $1 parameter for \'$2\'", p.get_direction, p.get_name)
      end
    }
  end
end

#set_type(type) ⇒ Object



1094
1095
1096
1097
1098
1099
1100
# File 'lib/tecsgen/core/types.rb', line 1094

def set_type(type)
  unless @type
    @type = type
  else
    @type.set_type(type)
  end
end

#show_tree(indent) ⇒ Object



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File 'lib/tecsgen/core/types.rb', line 1184

def show_tree(indent)
  indent.times { print "  " }
  if @b_oneway
    puts "FunctType:  oneway=true #{locale_str}"
  else
    puts "FunctType:  oneway=false #{locale_str}"
  end
  super(indent + 1)
  if @paramlist
    @paramlist.show_tree(indent + 1)
  end
  (indent + 1).times { print "  " }
  puts "return type:"
  @type.show_tree(indent + 2)
end