-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery-index-web.h
More file actions
144 lines (124 loc) · 4.57 KB
/
Copy pathquery-index-web.h
File metadata and controls
144 lines (124 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Public header for the WEB_SAFE query-index extraction surface.
*
* Types and function declarations shared between the smoke target
* (query-index-web.c compiled standalone) and the linked WASM module
* (qi-web-entry.c + query-index-web.c).
*
* This header is deliberately free of sqlite3.h and tree-sitter includes.
*/
#ifndef QUERY_INDEX_WEB_H
#define QUERY_INDEX_WEB_H
#include "config.h"
/* config.h may unconditionally #define ENABLE_TYPESCRIPT to 0, overriding the
* -D flag passed to emcc. The web bridge needs scope/namespace columns. */
#undef ENABLE_TYPESCRIPT
#define ENABLE_TYPESCRIPT 1
#include "shared/constants.h"
#include "shared/sql_builder.h"
/* -- Types extracted from query-index.c -- */
typedef enum {
CONTEXT_CLASS,
CONTEXT_INTERFACE,
CONTEXT_FUNCTION,
CONTEXT_ARGUMENT,
CONTEXT_VARIABLE,
CONTEXT_EXCEPTION,
CONTEXT_TYPE,
CONTEXT_PROPERTY,
CONTEXT_COMMENT,
CONTEXT_STRING,
CONTEXT_FILENAME,
CONTEXT_IMPORT,
CONTEXT_EXPORT,
CONTEXT_CALL,
CONTEXT_NAMESPACE,
CONTEXT_ENUM,
CONTEXT_ENUM_CASE,
CONTEXT_TRAIT,
CONTEXT_LAMBDA,
CONTEXT_LABEL,
CONTEXT_GOTO,
CONTEXT_MACRO
} ContextType;
/* Database wrapper - forward-declared without sqlite3.h for header cleanliness */
struct sqlite3;
struct sqlite3_stmt;
typedef struct {
struct sqlite3 *db;
struct sqlite3_stmt *insert_stmt;
} CodeIndexDatabase;
typedef struct {
ContextType types[MAX_CONTEXT_TYPES];
int count;
} ContextTypeList;
typedef struct {
char *patterns[MAX_PATTERNS];
int count;
} PatternList;
typedef struct {
char *values[MAX_CONTEXT_TYPES];
int count;
} StringList;
typedef struct {
char *directory; /* NULL if no directory part */
char *filename; /* Always present */
} FilePattern;
typedef struct {
FilePattern patterns[MAX_CONTEXT_TYPES];
int count;
} FileFilterList;
typedef struct {
int line_start; /* -1 = not set */
int line_end; /* -1 = not set */
#define COLUMN(name, ...) StringList name;
#define INT_COLUMN(name, ...) StringList name;
#include "shared/column_schema.def"
#undef COLUMN
#undef INT_COLUMN
/* Virtual filter (no backing column): --parent-type resolves
* parent_symbol to its same-file definition and matches that
* definition's declared type */
StringList parent_type;
} QueryFilters;
typedef struct {
char directory[DIRECTORY_MAX_LENGTH];
char filename[FILENAME_MAX_LENGTH];
int line_start;
int line_end;
} WithinRange;
typedef struct {
WithinRange ranges[MAX_PATTERNS];
int count;
} WithinRangeList;
/* -- Forward declarations from shared helpers (needed by web entry point) -- */
/* from shared/string_utils.h */
void to_upper(char *str);
void to_lowercase_copy(const char *src, char *dst, size_t size);
void pluralize_common_word(const char *word, char *output, size_t output_size);
char *try_strdup_ctx(const char *str, const char *err_msg);
char *safe_strdup_ctx(const char *str, const char *err_msg);
/* from shared/database.h */
ContextType string_to_context(const char *str);
const char *context_to_string(ContextType type, int compact);
/* from shared/file_utils.h */
int parse_source_location(const char *source_location, int *start_line,
int *start_column, int *end_line, int *end_column);
/* -- WEB_SAFE function declarations (exact extractions from query-index.c) -- */
const char *map_context_web(const char *token);
void convert_wildcards_web(const char *pattern, char *output, size_t output_size);
int process_file_pattern_web(const char *input, char **dir_out, char **file_out);
int build_common_filters_web(SqlQueryBuilder *builder,
ContextTypeList *include, ContextTypeList *exclude,
QueryFilters *filters, FileFilterList *file_filter,
WithinRangeList *within_ranges, int debug,
const char *col_prefix);
int build_query_filters_web(SqlQueryBuilder *builder, PatternList *patterns,
ContextTypeList *include, ContextTypeList *exclude,
QueryFilters *filters, FileFilterList *file_filter,
WithinRangeList *within_ranges, int line_range, int debug);
int build_query_sql_web(SqlQueryBuilder *builder, PatternList *patterns,
ContextTypeList *include, ContextTypeList *exclude,
QueryFilters *filters, FileFilterList *file_filter,
WithinRangeList *within_ranges, int line_range, int debug);
#endif /* QUERY_INDEX_WEB_H */