1 #ifndef NVIM_API_PRIVATE_DEFS_H
2 #define NVIM_API_PRIVATE_DEFS_H
3 
4 #include <stdbool.h>
5 #include <stdint.h>
6 #include <string.h>
7 
8 #include "nvim/func_attr.h"
9 #include "nvim/types.h"
10 
11 #define ARRAY_DICT_INIT { .size = 0, .capacity = 0, .items = NULL }
12 #define STRING_INIT { .data = NULL, .size = 0 }
13 #define OBJECT_INIT { .type = kObjectTypeNil }
14 #define ERROR_INIT { .type = kErrorTypeNone, .msg = NULL }
15 #define REMOTE_TYPE(type) typedef handle_T type
16 
17 #define ERROR_SET(e) ((e)->type != kErrorTypeNone)
18 
19 #ifdef INCLUDE_GENERATED_DECLARATIONS
20 # define ArrayOf(...) Array
21 # define DictionaryOf(...) Dictionary
22 # define Dict(name) KeyDict_##name
23 #endif
24 
25 // Basic types
26 typedef enum {
27   kErrorTypeNone = -1,
28   kErrorTypeException,
29   kErrorTypeValidation,
30 } ErrorType;
31 
32 typedef enum {
33   kMessageTypeUnknown = -1,
34   // Per msgpack-rpc spec.
35   kMessageTypeRequest = 0,
36   kMessageTypeResponse = 1,
37   kMessageTypeNotification = 2,
38 } MessageType;
39 
40 /// Mask for all internal calls
41 #define INTERNAL_CALL_MASK (((uint64_t)1) << (sizeof(uint64_t) * 8 - 1))
42 
43 /// Internal call from VimL code
44 #define VIML_INTERNAL_CALL INTERNAL_CALL_MASK
45 
46 /// Internal call from lua code
47 #define LUA_INTERNAL_CALL (VIML_INTERNAL_CALL + 1)
48 
49 static inline bool is_internal_call(const uint64_t channel_id)
50   REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
51 
52 /// Check whether call is internal
53 ///
54 /// @param[in]  channel_id  Channel id.
55 ///
56 /// @return true if channel_id refers to internal channel.
is_internal_call(const uint64_t channel_id)57 static inline bool is_internal_call(const uint64_t channel_id)
58 {
59   return !!(channel_id & INTERNAL_CALL_MASK);
60 }
61 
62 typedef struct {
63   ErrorType type;
64   char *msg;
65 } Error;
66 
67 typedef bool Boolean;
68 typedef int64_t Integer;
69 typedef double Float;
70 
71 /// Maximum value of an Integer
72 #define API_INTEGER_MAX INT64_MAX
73 
74 /// Minimum value of an Integer
75 #define API_INTEGER_MIN INT64_MIN
76 
77 typedef struct {
78   char *data;
79   size_t size;
80 } String;
81 
82 REMOTE_TYPE(Buffer);
83 REMOTE_TYPE(Window);
84 REMOTE_TYPE(Tabpage);
85 
86 typedef struct object Object;
87 
88 typedef struct {
89   Object *items;
90   size_t size, capacity;
91 } Array;
92 
93 typedef struct key_value_pair KeyValuePair;
94 
95 typedef struct {
96   KeyValuePair *items;
97   size_t size, capacity;
98 } Dictionary;
99 
100 typedef enum {
101   kObjectTypeNil = 0,
102   kObjectTypeBoolean,
103   kObjectTypeInteger,
104   kObjectTypeFloat,
105   kObjectTypeString,
106   kObjectTypeArray,
107   kObjectTypeDictionary,
108   kObjectTypeLuaRef,
109   // EXT types, cannot be split or reordered, see #EXT_OBJECT_TYPE_SHIFT
110   kObjectTypeBuffer,
111   kObjectTypeWindow,
112   kObjectTypeTabpage,
113 } ObjectType;
114 
115 struct object {
116   ObjectType type;
117   union {
118     Boolean boolean;
119     Integer integer;
120     Float floating;
121     String string;
122     Array array;
123     Dictionary dictionary;
124     LuaRef luaref;
125   } data;
126 };
127 
128 struct key_value_pair {
129   String key;
130   Object value;
131 };
132 
133 typedef Object *(*field_hash)(void *retval, const char *str, size_t len);
134 typedef struct {
135   char *str;
136   size_t ptr_off;
137 } KeySetLink;
138 
139 #ifdef INCLUDE_GENERATED_DECLARATIONS
140 # include "keysets_defs.generated.h"
141 #endif
142 
143 #endif  // NVIM_API_PRIVATE_DEFS_H
144