comparison src/globals.h @ 30576:72e6073a2822 v9.0.0623

patch 9.0.0623: error for modifying a const is not detected at compile time Commit: https://github.com/vim/vim/commit/fa1039760e8c1a0c7a2a722160bd3d71a4736e61 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 29 19:14:42 2022 +0100 patch 9.0.0623: error for modifying a const is not detected at compile time Problem: Error for modifying a const is not detected at compile time. Solution: Add TTFLAG_CONST and check for it in add() and extend().
author Bram Moolenaar <Bram@vim.org>
date Thu, 29 Sep 2022 20:15:05 +0200
parents b5f67135fcb6
children f2f35161d75a
comparison
equal deleted inserted replaced
30575:3b314751334b 30576:72e6073a2822
394 EXTERN int may_garbage_collect INIT(= FALSE); 394 EXTERN int may_garbage_collect INIT(= FALSE);
395 EXTERN int want_garbage_collect INIT(= FALSE); 395 EXTERN int want_garbage_collect INIT(= FALSE);
396 EXTERN int garbage_collect_at_exit INIT(= FALSE); 396 EXTERN int garbage_collect_at_exit INIT(= FALSE);
397 397
398 398
399 // Commonly used types. 399 // Array with predefined commonly used types.
400 // "unknown" is used for when the type is really unknown, e.g. global 400 //
401 // variables. Also for when a function may or may not return something. 401 // For each entry of a regular type the next one has the "const" version.
402 EXTERN type_T t_unknown INIT6(VAR_UNKNOWN, 0, 0, TTFLAG_STATIC, NULL, NULL); 402 // E.g. "&t_const_bool == &t_bool + 1"
403 403
404 // "any" is used for when the type is mixed. Excludes "void". 404 // t_unknown - used for when the type is really unknown, e.g. global variables.
405 EXTERN type_T t_any INIT6(VAR_ANY, 0, 0, TTFLAG_STATIC, NULL, NULL); 405 // Also for when a function may or may not return something.
406 406 #define t_unknown (static_types[0])
407 // "void" is used for a function not returning anything. 407 #define t_const_unknown (static_types[1])
408 EXTERN type_T t_void INIT6(VAR_VOID, 0, 0, TTFLAG_STATIC, NULL, NULL); 408
409 409 // t_any - used for when the type can be anything, but excludes "void".
410 EXTERN type_T t_bool INIT6(VAR_BOOL, 0, 0, TTFLAG_STATIC, NULL, NULL); 410 #define t_any (static_types[2])
411 EXTERN type_T t_null INIT6(VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL); 411 #define t_const_any (static_types[3])
412 EXTERN type_T t_none INIT6(VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL); 412
413 EXTERN type_T t_number INIT6(VAR_NUMBER, 0, 0, TTFLAG_STATIC, NULL, NULL); 413 // t_void - used for a function not returning anything.
414 EXTERN type_T t_number_bool INIT6(VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_BOOL_OK, NULL, NULL); 414 #define t_void (static_types[4])
415 EXTERN type_T t_float INIT6(VAR_FLOAT, 0, 0, TTFLAG_STATIC, NULL, NULL); 415 #define t_const_void (static_types[5])
416 EXTERN type_T t_string INIT6(VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL); 416
417 EXTERN type_T t_blob INIT6(VAR_BLOB, 0, 0, TTFLAG_STATIC, NULL, NULL); 417 #define t_bool (static_types[6])
418 EXTERN type_T t_blob_null INIT6(VAR_BLOB, 0, 0, TTFLAG_STATIC, &t_void, NULL); 418 #define t_const_bool (static_types[7])
419 EXTERN type_T t_job INIT6(VAR_JOB, 0, 0, TTFLAG_STATIC, NULL, NULL); 419
420 EXTERN type_T t_channel INIT6(VAR_CHANNEL, 0, 0, TTFLAG_STATIC, NULL, NULL); 420 #define t_null (static_types[8])
421 421 #define t_const_null (static_types[9])
422 // Special value used for @#. 422
423 EXTERN type_T t_number_or_string INIT6(VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL); 423 #define t_none (static_types[10])
424 424 #define t_const_none (static_types[11])
425 EXTERN type_T t_func_unknown INIT6(VAR_FUNC, -1, -1, TTFLAG_STATIC, &t_unknown, NULL); 425
426 EXTERN type_T t_func_void INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_void, NULL); 426 #define t_number (static_types[12])
427 EXTERN type_T t_func_any INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_any, NULL); 427 #define t_const_number (static_types[13])
428 EXTERN type_T t_func_number INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_number, NULL); 428
429 EXTERN type_T t_func_string INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_string, NULL); 429 // t_number_bool - number that can be used as a bool
430 EXTERN type_T t_func_bool INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_bool, NULL); 430 #define t_number_bool (static_types[14])
431 EXTERN type_T t_func_0_void INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_void, NULL); 431 #define t_const_number_bool (static_types[15])
432 EXTERN type_T t_func_0_any INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_any, NULL); 432
433 EXTERN type_T t_func_0_number INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_number, NULL); 433 #define t_float (static_types[16])
434 EXTERN type_T t_func_0_string INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_string, NULL); 434 #define t_const_float (static_types[17])
435 435
436 EXTERN type_T t_list_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_any, NULL); 436 #define t_string (static_types[18])
437 EXTERN type_T t_dict_any INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_any, NULL); 437 #define t_const_string (static_types[19])
438 EXTERN type_T t_list_empty INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_unknown, NULL); 438
439 EXTERN type_T t_dict_empty INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_unknown, NULL); 439 #define t_blob (static_types[20])
440 440 #define t_const_blob (static_types[21])
441 EXTERN type_T t_list_bool INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_bool, NULL); 441
442 EXTERN type_T t_list_number INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_number, NULL); 442 #define t_blob_null (static_types[22])
443 EXTERN type_T t_list_string INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_string, NULL); 443 #define t_const_blob_null (static_types[23])
444 EXTERN type_T t_list_job INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_job, NULL); 444
445 EXTERN type_T t_list_dict_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_dict_any, NULL); 445 #define t_job (static_types[24])
446 EXTERN type_T t_list_list_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_any, NULL); 446 #define t_const_job (static_types[25])
447 EXTERN type_T t_list_list_string INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_string, NULL); 447
448 448 #define t_channel (static_types[26])
449 EXTERN type_T t_dict_bool INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_bool, NULL); 449 #define t_const_channel (static_types[27])
450 EXTERN type_T t_dict_number INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_number, NULL); 450
451 EXTERN type_T t_dict_string INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_string, NULL); 451 // t_number_or_string - Special value used for @#.
452 452 #define t_number_or_string (static_types[28])
453 #endif 453 #define t_const_number_or_string (static_types[29])
454 454
455 #ifdef FEAT_EVAL 455 // t_func_unknown - function with any arguments and no or unknown return value
456 #define t_func_unknown (static_types[30])
457 #define t_const_func_unknown (static_types[31])
458
459 // t_func_void - function with any arguments and no return value
460 #define t_func_void (static_types[32])
461 #define t_const_func_void (static_types[33])
462
463 #define t_func_any (static_types[34])
464 #define t_const_func_any (static_types[35])
465
466 #define t_func_number (static_types[36])
467 #define t_const_func_number (static_types[37])
468
469 #define t_func_string (static_types[38])
470 #define t_const_func_string (static_types[39])
471
472 #define t_func_bool (static_types[40])
473 #define t_const_func_bool (static_types[41])
474
475 // t_func_0_void - function without arguments and nor return value
476 #define t_func_0_void (static_types[42])
477 #define t_const_func_0_void (static_types[43])
478
479 #define t_func_0_any (static_types[44])
480 #define t_const_func_0_any (static_types[45])
481
482 #define t_func_0_number (static_types[46])
483 #define t_const_func_0_number (static_types[47])
484
485 #define t_func_0_string (static_types[48])
486 #define t_const_func_0_string (static_types[49])
487
488 #define t_list_any (static_types[50])
489 #define t_const_list_any (static_types[51])
490
491 #define t_dict_any (static_types[52])
492 #define t_const_dict_any (static_types[53])
493
494 #define t_list_empty (static_types[54])
495 #define t_const_list_empty (static_types[55])
496
497 #define t_dict_empty (static_types[56])
498 #define t_const_dict_empty (static_types[57])
499
500 #define t_list_bool (static_types[58])
501 #define t_const_list_bool (static_types[59])
502
503 #define t_list_number (static_types[60])
504 #define t_const_list_number (static_types[61])
505
506 #define t_list_string (static_types[62])
507 #define t_const_list_string (static_types[63])
508
509 #define t_list_job (static_types[64])
510 #define t_const_list_job (static_types[65])
511
512 #define t_list_dict_any (static_types[66])
513 #define t_const_list_dict_any (static_types[67])
514
515 #define t_list_list_any (static_types[68])
516 #define t_const_list_list_any (static_types[69])
517
518 #define t_list_list_string (static_types[70])
519 #define t_const_list_list_string (static_types[71])
520
521 #define t_dict_bool (static_types[72])
522 #define t_const_dict_bool (static_types[73])
523
524 #define t_dict_number (static_types[74])
525 #define t_const_dict_number (static_types[75])
526
527 #define t_dict_string (static_types[76])
528 #define t_const_dict_string (static_types[77])
529
530 EXTERN type_T static_types[78]
531 #ifdef DO_INIT
532 = {
533 // 0: t_unknown
534 {VAR_UNKNOWN, 0, 0, TTFLAG_STATIC, NULL, NULL},
535 {VAR_UNKNOWN, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
536
537 // 2: t_any
538 {VAR_ANY, 0, 0, TTFLAG_STATIC, NULL, NULL},
539 {VAR_ANY, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
540
541 // 4: t_void
542 {VAR_VOID, 0, 0, TTFLAG_STATIC, NULL, NULL},
543 {VAR_VOID, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
544
545 // 6: t_bool
546 {VAR_BOOL, 0, 0, TTFLAG_STATIC, NULL, NULL},
547 {VAR_BOOL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
548
549 // 8: t_null
550 {VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL},
551 {VAR_SPECIAL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
552
553 // 10: t_none
554 {VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL},
555 {VAR_SPECIAL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
556
557 // 12: t_number
558 {VAR_NUMBER, 0, 0, TTFLAG_STATIC, NULL, NULL},
559 {VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
560
561 // 14: t_number_bool
562 {VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_BOOL_OK, NULL, NULL},
563 {VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_BOOL_OK|TTFLAG_CONST, NULL, NULL},
564
565 // 16: t_float
566 {VAR_FLOAT, 0, 0, TTFLAG_STATIC, NULL, NULL},
567 {VAR_FLOAT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
568
569 // 18: t_string
570 {VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL},
571 {VAR_STRING, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
572
573 // 20: t_blob
574 {VAR_BLOB, 0, 0, TTFLAG_STATIC, NULL, NULL},
575 {VAR_BLOB, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
576
577 // 22: t_blob_null
578 {VAR_BLOB, 0, 0, TTFLAG_STATIC, &t_void, NULL},
579 {VAR_BLOB, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_void, NULL},
580
581 // 24: t_job
582 {VAR_JOB, 0, 0, TTFLAG_STATIC, NULL, NULL},
583 {VAR_JOB, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
584
585 // 26: t_channel
586 {VAR_CHANNEL, 0, 0, TTFLAG_STATIC, NULL, NULL},
587 {VAR_CHANNEL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
588
589 // 28: t_number_or_string
590 {VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL},
591 {VAR_STRING, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
592
593 // 30: t_func_unknown
594 {VAR_FUNC, -1, -1, TTFLAG_STATIC, &t_unknown, NULL},
595 {VAR_FUNC, -1, -1, TTFLAG_STATIC|TTFLAG_CONST, &t_unknown, NULL},
596
597 // 32: t_func_void
598 {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_void, NULL},
599 {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_void, NULL},
600
601 // 34: t_func_any
602 {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_any, NULL},
603 {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
604
605 // 36: t_func_number
606 {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_number, NULL},
607 {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
608
609 // 38: t_func_string
610 {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_string, NULL},
611 {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
612
613 // 40: t_func_bool
614 {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_bool, NULL},
615 {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_bool, NULL},
616
617 // 42: t_func_0_void
618 {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_void, NULL},
619 {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_void, NULL},
620
621 // 44: t_func_0_any
622 {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_any, NULL},
623 {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
624
625 // 46: t_func_0_number
626 {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_number, NULL},
627 {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
628
629 // 48: t_func_0_string
630 {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_string, NULL},
631 {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
632
633 // 50: t_list_any
634 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_any, NULL},
635 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
636
637 // 52: t_dict_any
638 {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_any, NULL},
639 {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
640
641 // 54: t_list_empty
642 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_unknown, NULL},
643 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_unknown, NULL},
644
645 // 56: t_dict_empty
646 {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_unknown, NULL},
647 {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_unknown, NULL},
648
649 // 58: t_list_bool
650 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_bool, NULL},
651 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_bool, NULL},
652
653 // 60: t_list_number
654 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_number, NULL},
655 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
656
657 // 62: t_list_string
658 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_string, NULL},
659 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
660
661 // 64: t_list_job
662 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_job, NULL},
663 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_job, NULL},
664
665 // 66: t_list_dict_any
666 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_dict_any, NULL},
667 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_dict_any, NULL},
668
669 // 68: t_list_list_any
670 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_any, NULL},
671 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_list_any, NULL},
672
673 // 70: t_list_list_string
674 {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_string, NULL},
675 {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_list_string, NULL},
676
677 // 72: t_dict_bool
678 {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_bool, NULL},
679 {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_bool, NULL},
680
681 // 74: t_dict_number
682 {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_number, NULL},
683 {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
684
685 // 76: t_dict_string
686 {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_string, NULL},
687 {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
688 }
689 #endif
690 ;
691
456 EXTERN int did_source_packages INIT(= FALSE); 692 EXTERN int did_source_packages INIT(= FALSE);
457 #endif 693 #endif // FEAT_EVAL
458 694
459 // Magic number used for hashitem "hi_key" value indicating a deleted item. 695 // Magic number used for hashitem "hi_key" value indicating a deleted item.
460 // Only the address is used. 696 // Only the address is used.
461 EXTERN char_u hash_removed; 697 EXTERN char_u hash_removed;
462 698