/* vi:set ts=8 sts=4 sw=4 noet: * * VIM - Vi IMproved by Bram Moolenaar * * Do ":help uganda" in Vim to read copying and usage conditions. * Do ":help credits" in Vim to see a list of people who contributed. * See README.txt for an overview of the Vim source code. *//* * vim9type.c: handling of types */#define USING_FLOAT_STUFF#include"vim.h"#if defined(FEAT_EVAL) || defined(PROTO)#ifdef VMS#include<float.h>#endif/* * Allocate memory for a type_T and add the pointer to type_gap, so that it can * be easily freed later. */type_T*get_type_ptr(garray_T*type_gap){type_T*type;if(ga_grow(type_gap,1)==FAIL)returnNULL;type=ALLOC_CLEAR_ONE(type_T);if(type!=NULL){((type_T**)type_gap->ga_data)[type_gap->ga_len]=type;++type_gap->ga_len;}returntype;}voidclear_type_list(garray_T*gap){while(gap->ga_len>0)vim_free(((type_T**)gap->ga_data)[--gap->ga_len]);ga_clear(gap);}/* * Take a type that is using entries in a growarray and turn it into a type * with allocated entries. */type_T*alloc_type(type_T*type){type_T*ret;if(type==NULL)returnNULL;// A fixed type never contains allocated types, return as-is.if(type->tt_flags&TTFLAG_STATIC)returntype;ret=ALLOC_ONE(type_T);*ret=*type;if(ret->tt_member!=NULL)ret->tt_member=alloc_type(ret->tt_member);if(type->tt_args!=NULL){inti;ret->tt_args=ALLOC_MULT(type_T*,type->tt_argcount);if(ret->tt_args!=NULL)for(i=0;i<type->tt_argcount;++i)ret->tt_args[i]=alloc_type(type->tt_args[i]);}returnret;}/* * Free a type that was created with alloc_type(). */voidfree_type(type_T*type){inti;if(type==NULL||(type->tt_flags&TTFLAG_STATIC))return;if(type->tt_args!=NULL){for(i=0;i<type->tt_argcount;++i)free_type(type->tt_args[i]);vim_free(type->tt_args);}free_type(type->tt_member);vim_free(type);}type_T*get_list_type(type_T*member_type,garray_T*type_gap){type_T*type;// recognize commonly used typesif(member_type==NULL||member_type->tt_type==VAR_ANY)return&t_list_any;if(member_type->tt_type==VAR_VOID||member_type->tt_type==VAR_UNKNOWN)return&t_list_empty;if(member_type->tt_type==VAR_BOOL)return&t_list_bool;if(member_type->tt_type==VAR_NUMBER)