Mercurial > vim
comparison src/vim9type.c @ 34676:5b25ec43f208 v9.1.0219
patch 9.1.0219: Vim9: No enum support
Commit: https://github.com/vim/vim/commit/3164cf8f12f14b725b918e3170bb0a9085af8298
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Mar 28 10:36:42 2024 +0100
patch 9.1.0219: Vim9: No enum support
Problem: No enum support
Solution: Implement enums for Vim9 script
(Yegappan Lakshmanan)
closes: #14224
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 28 Mar 2024 10:45:06 +0100 |
parents | ab6a70fad5b5 |
children | 3f9d9ee5cb7c |
comparison
equal
deleted
inserted
replaced
34675:42bca55140ec | 34676:5b25ec43f208 |
---|---|
717 type_T *actual_type; | 717 type_T *actual_type; |
718 int res = FAIL; | 718 int res = FAIL; |
719 | 719 |
720 if (expected == NULL) | 720 if (expected == NULL) |
721 return OK; // didn't expect anything. | 721 return OK; // didn't expect anything. |
722 // | 722 |
723 ga_init2(&type_list, sizeof(type_T *), 10); | 723 ga_init2(&type_list, sizeof(type_T *), 10); |
724 | 724 |
725 // A null_function and null_partial are special cases, they can be used to | 725 // A null_function and null_partial are special cases, they can be used to |
726 // clear a variable. | 726 // clear a variable. |
727 if ((actual_tv->v_type == VAR_FUNC && actual_tv->vval.v_string == NULL) | 727 if ((actual_tv->v_type == VAR_FUNC && actual_tv->vval.v_string == NULL) |
1737 } | 1737 } |
1738 } | 1738 } |
1739 | 1739 |
1740 if (type->tt_type == VAR_OBJECT || type->tt_type == VAR_CLASS) | 1740 if (type->tt_type == VAR_OBJECT || type->tt_type == VAR_CLASS) |
1741 { | 1741 { |
1742 char_u *class_name = type->tt_class == NULL ? (char_u *)"Unknown" | 1742 char_u *class_name; |
1743 : type->tt_class->class_name; | 1743 if (type->tt_class != NULL) |
1744 { | |
1745 class_name = type->tt_class->class_name; | |
1746 if (IS_ENUM(type->tt_class)) | |
1747 name = "enum"; | |
1748 } | |
1749 else | |
1750 class_name = (char_u *)"Unknown"; | |
1744 size_t len = STRLEN(name) + STRLEN(class_name) + 3; | 1751 size_t len = STRLEN(name) + STRLEN(class_name) + 3; |
1745 *tofree = alloc(len); | 1752 *tofree = alloc(len); |
1746 if (*tofree != NULL) | 1753 if (*tofree != NULL) |
1747 { | 1754 { |
1748 vim_snprintf(*tofree, len, "%s<%s>", name, class_name); | 1755 vim_snprintf(*tofree, len, "%s<%s>", name, class_name); |
1867 int | 1874 int |
1868 check_typval_is_value(typval_T *tv) | 1875 check_typval_is_value(typval_T *tv) |
1869 { | 1876 { |
1870 if (tv == NULL) | 1877 if (tv == NULL) |
1871 return OK; | 1878 return OK; |
1872 if (tv->v_type == VAR_CLASS) | 1879 |
1873 { | 1880 switch (tv->v_type) |
1874 if (tv->vval.v_class != NULL) | 1881 { |
1875 semsg(_(e_using_class_as_value_str), tv->vval.v_class->class_name); | 1882 case VAR_CLASS: |
1876 else | 1883 { |
1877 emsg(e_using_class_as_var_val); | 1884 class_T *cl = tv->vval.v_class; |
1878 return FAIL; | 1885 if (IS_ENUM(cl)) |
1879 } | 1886 semsg(_(e_using_enum_as_value_str), cl->class_name); |
1880 else if (tv->v_type == VAR_TYPEALIAS) | 1887 else |
1881 { | 1888 semsg(_(e_using_class_as_value_str), cl->class_name); |
1882 semsg(_(e_using_typealias_as_value_str), tv->vval.v_typealias->ta_name); | 1889 } |
1883 return FAIL; | 1890 return FAIL; |
1891 | |
1892 case VAR_TYPEALIAS: | |
1893 semsg(_(e_using_typealias_as_value_str), | |
1894 tv->vval.v_typealias->ta_name); | |
1895 return FAIL; | |
1896 | |
1897 default: | |
1898 break; | |
1884 } | 1899 } |
1885 return OK; | 1900 return OK; |
1886 } | 1901 } |
1887 | 1902 |
1888 /* | 1903 /* |
1891 int | 1906 int |
1892 check_type_is_value(type_T *type) | 1907 check_type_is_value(type_T *type) |
1893 { | 1908 { |
1894 if (type == NULL) | 1909 if (type == NULL) |
1895 return OK; | 1910 return OK; |
1896 if (type->tt_type == VAR_CLASS) | 1911 switch (type->tt_type) |
1897 { | 1912 { |
1898 semsg(_(e_using_class_as_value_str), type->tt_class->class_name); | 1913 case VAR_CLASS: |
1899 return FAIL; | 1914 if (IS_ENUM(type->tt_class)) |
1900 } | 1915 semsg(_(e_using_enum_as_value_str), |
1901 else if (type->tt_type == VAR_TYPEALIAS) | 1916 type->tt_class->class_name); |
1902 { | 1917 else |
1903 // TODO: Not sure what could be done here to get a name. | 1918 semsg(_(e_using_class_as_value_str), |
1904 // Maybe an optional argument? | 1919 type->tt_class->class_name); |
1905 emsg(_(e_using_typealias_as_var_val)); | 1920 return FAIL; |
1906 return FAIL; | 1921 |
1922 case VAR_TYPEALIAS: | |
1923 // TODO: Not sure what could be done here to get a name. | |
1924 // Maybe an optional argument? | |
1925 emsg(_(e_using_typealias_as_var_val)); | |
1926 return FAIL; | |
1927 | |
1928 default: | |
1929 break; | |
1907 } | 1930 } |
1908 return OK; | 1931 return OK; |
1909 } | 1932 } |
1910 | 1933 |
1911 #endif // FEAT_EVAL | 1934 #endif // FEAT_EVAL |