Class: PtrType
- Includes:
- HasType
- Defined in:
- lib/tecsgen/core/types.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#check ⇒ Object
意味的誤りがあれば、文字列を返す.
- #check_init(locale, ident, initializer, kind, attribute = nil) ⇒ Object
- #check_struct_tag(kind) ⇒ Object
- #clear_max ⇒ Object
- #get_count ⇒ Object
-
#get_max ⇒ Object
PtrType# size_is の最大値.
- #get_referto ⇒ Object
- #get_size ⇒ Object
- #get_string ⇒ Object
- #get_type ⇒ Object
- #get_type_str ⇒ Object
- #get_type_str_post ⇒ Object
- #has_pointer? ⇒ Boolean
- #has_sized_pointer? ⇒ Boolean
- #has_unsized_string? ⇒ Boolean
-
#initialize(referto = nil) ⇒ PtrType
constructor
A new instance of PtrType.
- #is_nullable? ⇒ Boolean
- #set_scs(size, count, string, max, b_nullable) ⇒ Object
- #set_type(type) ⇒ Object
- #show_tree(indent) ⇒ Object
Methods included from HasType
Methods inherited from Type
#cast, #equal?, #get_ID_str, #get_bit_size, #get_original_type, #is_const?, #is_void?, #is_volatile?, #print_info, #print_info_post, print_info_post, reset_print_info, #set_qualifier
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(referto = nil) ⇒ PtrType
Returns a new instance of PtrType.
1334 1335 1336 1337 1338 1339 1340 1341 |
# File 'lib/tecsgen/core/types.rb', line 1334 def initialize(referto = nil) super() @type = referto @size = nil @count = nil @string = nil initHasType end |
Instance Method Details
#check ⇒ Object
意味的誤りがあれば、文字列を返す
1369 1370 1371 1372 |
# File 'lib/tecsgen/core/types.rb', line 1369 def check # 意味的誤りがあれば、文字列を返す return nil if @type.nil? @type.check end |
#check_init(locale, ident, initializer, kind, attribute = nil) ⇒ Object
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 |
# File 'lib/tecsgen/core/types.rb', line 1380 def check_init(locale, ident, initializer, kind, attribute = nil) if initializer.instance_of?(Expression) val = initializer.eval_const2(nil, attribute) if val.is_a? PointerVal type = val.get_type # PtrType t1 = self t2 = type while t1.is_a?(PtrType) && t2.is_a?(PtrType) t1 = t1.get_type t2 = t2.get_type if (t1.class == t2.class) && (t1.get_bit_size == t2.get_bit_size) elsif (t1.is_a?(CDefinedType) || t2.is_a?(CDefinedType)) && t1.get_type_str == t2.get_type_str && t1.get_type_str_post && t2.get_type_str_post # int8_t などが、一方は .h に定義されているケース else cdl_error2(locale, "T1032 $1: incompatible pointer type", ident) break end end elsif val.is_a? IntegerVal if val.to_i != 0 cdl_error2(locale, "T1033 $1: need cast to assign integer to pointer", ident) end elsif val.is_a? StringVal # 文字列定数 # mikan L"wide string" if @type.get_bit_size != -1 && @type.get_bit_size != -11 # -1: char_t cdl_error2(locale, "T1034 $1: unsuitable string constant", ident) end elsif val.instance_of?(Array) i = 0 val.each {|ini| @type.check_init(locale, "#{ident}[#{i}]", ini, kind, attribute = nil) i += 1 } elsif val.instance_of?(C_EXP) else cdl_error2(locale, "T1035 $1: unsuitable initializer for pointer", ident) end elsif initializer.instance_of?(Array) if @size.nil? && @count.nil? cdl_error2(locale, "T9999 $1: non-size_is pointer cannot have array initializer", ident) end i = 0 initializer.each {|ini| @type.check_init(locale, "#{ident}[#{i}]", ini, kind, attribute = nil) i += 1 } elsif initializer.instance_of?(C_EXP) else cdl_error2(locale, "T1036 $1: unsuitable initializer for pointer", ident) end end |
#check_struct_tag(kind) ⇒ Object
1374 1375 1376 1377 1378 |
# File 'lib/tecsgen/core/types.rb', line 1374 def check_struct_tag(kind) if kind != :MEMBER # 構造体メンバーの場合、ポインタの先の構造体タグをチェックしない @type.check_struct_tag kind end end |
#clear_max ⇒ Object
1480 1481 1482 |
# File 'lib/tecsgen/core/types.rb', line 1480 def clear_max @max = nil end |
#get_count ⇒ Object
1488 1489 1490 |
# File 'lib/tecsgen/core/types.rb', line 1488 def get_count @count end |
#get_max ⇒ Object
PtrType# size_is の最大値
1497 1498 1499 |
# File 'lib/tecsgen/core/types.rb', line 1497 def get_max @max end |
#get_referto ⇒ Object
1436 1437 1438 1439 |
# File 'lib/tecsgen/core/types.rb', line 1436 def get_referto clone_type @type end |
#get_size ⇒ Object
1484 1485 1486 |
# File 'lib/tecsgen/core/types.rb', line 1484 def get_size @size end |
#get_string ⇒ Object
1492 1493 1494 |
# File 'lib/tecsgen/core/types.rb', line 1492 def get_string @string end |
#get_type ⇒ Object
1505 1506 1507 1508 |
# File 'lib/tecsgen/core/types.rb', line 1505 def get_type clone_type @type end |
#get_type_str ⇒ Object
1351 1352 1353 1354 1355 1356 1357 1358 |
# File 'lib/tecsgen/core/types.rb', line 1351 def get_type_str if @type.is_a?(ArrayType) || @type.is_a?(FuncType) parenthes = "(" else parenthes = "" end return "#{@type.get_type_str}#{parenthes}*" end |
#get_type_str_post ⇒ Object
1360 1361 1362 1363 1364 1365 1366 1367 |
# File 'lib/tecsgen/core/types.rb', line 1360 def get_type_str_post if @type.is_a?(ArrayType) || @type.is_a?(FuncType) parenthes = ")" else parenthes = "" end "#{parenthes}#{@type.get_type_str_post}" end |
#has_pointer? ⇒ Boolean
1510 1511 1512 |
# File 'lib/tecsgen/core/types.rb', line 1510 def has_pointer? true end |
#has_sized_pointer? ⇒ Boolean
1514 1515 1516 |
# File 'lib/tecsgen/core/types.rb', line 1514 def has_sized_pointer? !@size.nil? || !@count.nil? || @string.instance_of?(Expression) || @type.has_sized_pointer? end |
#has_unsized_string? ⇒ Boolean
1518 1519 1520 |
# File 'lib/tecsgen/core/types.rb', line 1518 def has_unsized_string? @string == -1 || @type.has_unsized_string? end |
#is_nullable? ⇒ Boolean
1501 1502 1503 |
# File 'lib/tecsgen/core/types.rb', line 1501 def is_nullable? return @b_nullable end |
#set_scs(size, count, string, max, b_nullable) ⇒ Object
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 |
# File 'lib/tecsgen/core/types.rb', line 1441 def set_scs(size, count, string, max, b_nullable) @size = size @count = count @max = max @b_nullable = b_nullable # string は最も左側の ptr に作用する if @type.is_a?(PtrType) # ptr_level が 2 以上であることは ParamDecl#initializer でチェックされる clone_type @type.set_scs(nil, nil, string, nil, false) elsif @type.is_a?(VoidType) && (size || count || string) str = "" if size str = "size_is" end if count if str str += ", " end str += "count_is" end if string if str str += ", " end str += "string" end cdl_error("T1040 $1 specified for void pointer type", str) else @string = string end if !@size.nil? && (@b_nullable != false) cdl_error("T9999 size_is & nullable cannot be specified simultaneously. If size is zero, pointer must be null") end end |
#set_type(type) ⇒ Object
1343 1344 1345 1346 1347 1348 1349 |
# File 'lib/tecsgen/core/types.rb', line 1343 def set_type(type) unless @type @type = type else @type.set_type(type) # 枝先の type を設定 end end |
#show_tree(indent) ⇒ Object
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 |
# File 'lib/tecsgen/core/types.rb', line 1522 def show_tree(indent) indent.times { print " " } puts "PtrType: qualifier=#{@qualifier}, nullable=#{@b_nullable} #{locale_str}" super(indent + 1) (indent + 1).times { print " " } if @size print "size=#{@size}, " else print "size=nil, " end if @max print "max=#{@size}, " else print "max=nil, " end if @count print "count=#{@count}, " else print "count=nil, " end if @string if @string.instance_of?(Expression) print "string=#{@string}\n" else print "string=yes\n" end else print "string=nil\n" end (indent + 1).times { print " " } puts "type:" @type.show_tree(indent + 2) end |