Method: ArrayType#check_init

Defined in:
lib/tecsgen/core/types.rb

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



1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
# File 'lib/tecsgen/core/types.rb', line 1275

def check_init(locale, ident, initializer, kind, attribute = nil)
  if initializer.instance_of?(Array)
    # 要素数が指定されている場合、初期化要素数をチェック
    if @subscript
      n_sub = @subscript.eval_const(nil)
      if n_sub
        if initializer.length > n_sub
          cdl_error2(locale, "T9999 $1: too many initializer, $2 for $3", ident, initializer.length, n_sub)
        end
      end
    end
    index = 0
    initializer.each{|i|
      @type.check_init(locale, "#{ident}[#{index}]", i, kind, attribute = nil)
      index += 1
    }
  else
    cdl_error2(locale, "T1031 $1: unsuitable initializer for array", ident)
  end
end