summaryrefslogtreecommitdiffstats
path: root/src/globals.h
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-29 19:14:42 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-29 19:14:42 +0100
commitfa1039760e8c1a0c7a2a722160bd3d71a4736e61 (patch)
tree3749fc4f1e8e0cdccdde2c131dfca30b3b07917c /src/globals.h
parent9f573a8df02d9f699a43d2afbd1d2841d700b9ad (diff)
patch 9.0.0623: error for modifying a const is not detected at compile timev9.0.0623
Problem: Error for modifying a const is not detected at compile time. Solution: Add TTFLAG_CONST and check for it in add() and extend().
Diffstat (limited to 'src/globals.h')
-rw-r--r--src/globals.h346
1 files changed, 291 insertions, 55 deletions
diff --git a/src/globals.h b/src/globals.h
index fee2951e0a..aa0efb89a8 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -396,65 +396,301 @@ EXTERN int want_garbage_collect INIT(= FALSE);
EXTERN int garbage_collect_at_exit INIT(= FALSE);
-// Commonly used types.
-// "unknown" is used for when the type is really unknown, e.g. global
-// variables. Also for when a function may or may not return something.
-EXTERN type_T t_unknown INIT6(VAR_UNKNOWN, 0, 0, TTFLAG_STATIC, NULL, NULL);
-
-// "any" is used for when the type is mixed. Excludes "void".
-EXTERN type_T t_any INIT6(VAR_ANY, 0, 0, TTFLAG_STATIC, NULL, NULL);
-
-// "void" is used for a function not returning anything.
-EXTERN type_T t_void INIT6(VAR_VOID, 0, 0, TTFLAG_STATIC, NULL, NULL);
-
-EXTERN type_T t_bool INIT6(VAR_BOOL, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_null INIT6(VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_none INIT6(VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_number INIT6(VAR_NUMBER, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_number_bool INIT6(VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_BOOL_OK, NULL, NULL);
-EXTERN type_T t_float INIT6(VAR_FLOAT, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_string INIT6(VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_blob INIT6(VAR_BLOB, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_blob_null INIT6(VAR_BLOB, 0, 0, TTFLAG_STATIC, &t_void, NULL);
-EXTERN type_T t_job INIT6(VAR_JOB, 0, 0, TTFLAG_STATIC, NULL, NULL);
-EXTERN type_T t_channel INIT6(VAR_CHANNEL, 0, 0, TTFLAG_STATIC, NULL, NULL);
-
-// Special value used for @#.
-EXTERN type_T t_number_or_string INIT6(VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL);
-
-EXTERN type_T t_func_unknown INIT6(VAR_FUNC, -1, -1, TTFLAG_STATIC, &t_unknown, NULL);
-EXTERN type_T t_func_void INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_void, NULL);
-EXTERN type_T t_func_any INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_any, NULL);
-EXTERN type_T t_func_number INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_number, NULL);
-EXTERN type_T t_func_string INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_string, NULL);
-EXTERN type_T t_func_bool INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_bool, NULL);
-EXTERN type_T t_func_0_void INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_void, NULL);
-EXTERN type_T t_func_0_any INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_any, NULL);
-EXTERN type_T t_func_0_number INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_number, NULL);
-EXTERN type_T t_func_0_string INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_string, NULL);
-
-EXTERN type_T t_list_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_any, NULL);
-EXTERN type_T t_dict_any INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_any, NULL);
-EXTERN type_T t_list_empty INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_unknown, NULL);
-EXTERN type_T t_dict_empty INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_unknown, NULL);
-
-EXTERN type_T t_list_bool INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_bool, NULL);
-EXTERN type_T t_list_number INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_number, NULL);
-EXTERN type_T t_list_string INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_string, NULL);
-EXTERN type_T t_list_job INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_job, NULL);
-EXTERN type_T t_list_dict_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_dict_any, NULL);
-EXTERN type_T t_list_list_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_any, NULL);
-EXTERN type_T t_list_list_string INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_string, NULL);
-
-EXTERN type_T t_dict_bool INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_bool, NULL);
-EXTERN type_T t_dict_number INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_number, NULL);
-EXTERN type_T t_dict_string INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_string, NULL);
+// Array with predefined commonly used types.
+//
+// For each entry of a regular type the next one has the "const" version.
+// E.g. "&t_const_bool == &t_bool + 1"
+
+// t_unknown - used for when the type is really unknown, e.g. global variables.
+// Also for when a function may or may not return something.
+#define t_unknown (static_types[0])
+#define t_const_unknown (static_types[1])
+
+// t_any - used for when the type can be anything, but excludes "void".
+#define t_any (static_types[2])
+#define t_const_any (static_types[3])
+
+// t_void - used for a function not returning anything.
+#define t_void (static_types[4])
+#define t_const_void (static_types[5])
+
+#define t_bool (static_types[6])
+#define t_const_bool (static_types[7])
+
+#define t_null (static_types[8])
+#define t_const_null (static_types[9])
+
+#define t_none (static_types[10])
+#define t_const_none (static_types[11])
+
+#define t_number (static_types[12])
+#define t_const_number (static_types[13])
+
+// t_number_bool - number that can be used as a bool
+#define t_number_bool (static_types[14])
+#define t_const_number_bool (static_types[15])
+
+#define t_float (static_types[16])
+#define t_const_float (static_types[17])
+
+#define t_string (static_types[18])
+#define t_const_string (static_types[19])
+
+#define t_blob (static_types[20])
+#define t_const_blob (static_types[21])
+
+#define t_blob_null (static_types[22])
+#define t_const_blob_null (static_types[23])
+
+#define t_job (static_types[24])
+#define t_const_job (static_types[25])
+
+#define t_channel (static_types[26])
+#define t_const_channel (static_types[27])
+
+// t_number_or_string - Special value used for @#.
+#define t_number_or_string (static_types[28])
+#define t_const_number_or_string (static_types[29])
+
+// t_func_unknown - function with any arguments and no or unknown return value
+#define t_func_unknown (static_types[30])
+#define t_const_func_unknown (static_types[31])
+
+// t_func_void - function with any arguments and no return value
+#define t_func_void (static_types[32])
+#define t_const_func_void (static_types[33])
+
+#define t_func_any (static_types[34])
+#define t_const_func_any (static_types[35])
+
+#define t_func_number (static_types[36])
+#define t_const_func_number (static_types[37])
+
+#define t_func_string (static_types[38])
+#define t_const_func_string (static_types[39])
+
+#define t_func_bool (static_types[40])
+#define t_const_func_bool (static_types[41])
+
+// t_func_0_void - function without arguments and nor return value
+#define t_func_0_void (static_types[42])
+#define t_const_func_0_void (static_types[43])
+
+#define t_func_0_any (static_types[44])
+#define t_const_func_0_any (static_types[45])
+
+#define t_func_0_number (static_types[46])
+#define t_const_func_0_number (static_types[47])
+
+#define t_func_0_string (static_types[48])
+#define t_const_func_0_string (static_types[49])
+
+#define t_list_any (static_types[50])
+#define t_const_list_any (static_types[51])
+
+#define t_dict_any (static_types[52])
+#define t_const_dict_any (static_types[53])
+
+#define t_list_empty (static_types[54])
+#define t_const_list_empty (static_types[55])
+
+#define t_dict_empty (static_types[56])
+#define t_const_dict_empty (static_types[57])
+
+#define t_list_bool (static_types[58])
+#define t_const_list_bool (static_types[59])
+
+#define t_list_number (static_types[60])
+#define t_const_list_number (static_types[61])
+
+#define t_list_string (static_types[62])
+#define t_const_list_string (static_types[63])
+
+#define t_list_job (static_types[64])
+#define t_const_list_job (static_types[65])
+
+#define t_list_dict_any (static_types[66])
+#define t_const_list_dict_any (static_types[67])
+
+#define t_list_list_any (static_types[68])
+#define t_const_list_list_any (static_types[69])
+#define t_list_list_string (static_types[70])
+#define t_const_list_list_string (static_types[71])
+
+#define t_dict_bool (static_types[72])
+#define t_const_dict_bool (static_types[73])
+
+#define t_dict_number (static_types[74])
+#define t_const_dict_number (static_types[75])
+
+#define t_dict_string (static_types[76])
+#define t_const_dict_string (static_types[77])
+
+EXTERN type_T static_types[78]
+#ifdef DO_INIT
+= {
+ // 0: t_unknown
+ {VAR_UNKNOWN, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_UNKNOWN, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 2: t_any
+ {VAR_ANY, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_ANY, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 4: t_void
+ {VAR_VOID, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_VOID, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 6: t_bool
+ {VAR_BOOL, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_BOOL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 8: t_null
+ {VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_SPECIAL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 10: t_none
+ {VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_SPECIAL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 12: t_number
+ {VAR_NUMBER, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 14: t_number_bool
+ {VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_BOOL_OK, NULL, NULL},
+ {VAR_NUMBER, 0, 0, TTFLAG_STATIC|TTFLAG_BOOL_OK|TTFLAG_CONST, NULL, NULL},
+
+ // 16: t_float
+ {VAR_FLOAT, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_FLOAT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 18: t_string
+ {VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_STRING, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 20: t_blob
+ {VAR_BLOB, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_BLOB, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 22: t_blob_null
+ {VAR_BLOB, 0, 0, TTFLAG_STATIC, &t_void, NULL},
+ {VAR_BLOB, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_void, NULL},
+
+ // 24: t_job
+ {VAR_JOB, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_JOB, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 26: t_channel
+ {VAR_CHANNEL, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_CHANNEL, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 28: t_number_or_string
+ {VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL},
+ {VAR_STRING, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, NULL, NULL},
+
+ // 30: t_func_unknown
+ {VAR_FUNC, -1, -1, TTFLAG_STATIC, &t_unknown, NULL},
+ {VAR_FUNC, -1, -1, TTFLAG_STATIC|TTFLAG_CONST, &t_unknown, NULL},
+
+ // 32: t_func_void
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_void, NULL},
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_void, NULL},
+
+ // 34: t_func_any
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_any, NULL},
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
+
+ // 36: t_func_number
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_number, NULL},
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
+
+ // 38: t_func_string
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_string, NULL},
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
+
+ // 40: t_func_bool
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_bool, NULL},
+ {VAR_FUNC, -1, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_bool, NULL},
+
+ // 42: t_func_0_void
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_void, NULL},
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_void, NULL},
+
+ // 44: t_func_0_any
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_any, NULL},
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
+
+ // 46: t_func_0_number
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_number, NULL},
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
+
+ // 48: t_func_0_string
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_string, NULL},
+ {VAR_FUNC, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
+
+ // 50: t_list_any
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_any, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
+
+ // 52: t_dict_any
+ {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_any, NULL},
+ {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_any, NULL},
+
+ // 54: t_list_empty
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_unknown, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_unknown, NULL},
+
+ // 56: t_dict_empty
+ {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_unknown, NULL},
+ {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_unknown, NULL},
+
+ // 58: t_list_bool
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_bool, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_bool, NULL},
+
+ // 60: t_list_number
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_number, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
+
+ // 62: t_list_string
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_string, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
+
+ // 64: t_list_job
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_job, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_job, NULL},
+
+ // 66: t_list_dict_any
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_dict_any, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_dict_any, NULL},
+
+ // 68: t_list_list_any
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_any, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_list_any, NULL},
+
+ // 70: t_list_list_string
+ {VAR_LIST, 0, 0, TTFLAG_STATIC, &t_list_string, NULL},
+ {VAR_LIST, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_list_string, NULL},
+
+ // 72: t_dict_bool
+ {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_bool, NULL},
+ {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_bool, NULL},
+
+ // 74: t_dict_number
+ {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_number, NULL},
+ {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_number, NULL},
+
+ // 76: t_dict_string
+ {VAR_DICT, 0, 0, TTFLAG_STATIC, &t_string, NULL},
+ {VAR_DICT, 0, 0, TTFLAG_STATIC|TTFLAG_CONST, &t_string, NULL},
+}
#endif
+;
-#ifdef FEAT_EVAL
EXTERN int did_source_packages INIT(= FALSE);
-#endif
+#endif // FEAT_EVAL
// Magic number used for hashitem "hi_key" value indicating a deleted item.
// Only the address is used.