1
1
2
+ internal void
3
+ F4_CPP_ParseMacroDefinition (F4_Index_ParseCtx *ctx, F4_Index_TokenSkipFlags flags)
4
+ {
5
+ Token *name = 0 ;
6
+ if (F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &name, flags))
7
+ {
8
+ F4_Index_MakeNote (ctx->app , ctx->file , 0 , F4_Index_StringFromToken (ctx, name),
9
+ F4_Index_NoteKind_Macro, 0 , Ii64 (name));
10
+ }
11
+ for (;!ctx->done ;)
12
+ {
13
+ Token *token = token_it_read (&ctx->it );
14
+ if (!(token->flags & TokenBaseFlag_PreprocessorBody) ||
15
+ token->kind == TokenBaseKind_Preprocessor)
16
+ {
17
+ break ;
18
+ }
19
+ F4_Index_ParseCtx_IncWs (ctx);
20
+ }
21
+ }
22
+
2
23
internal b32
3
24
F4_CPP_SkipParseBody (F4_Index_ParseCtx *ctx)
4
25
{
@@ -8,7 +29,22 @@ F4_CPP_SkipParseBody(F4_Index_ParseCtx *ctx)
8
29
for (;!ctx->done ;)
9
30
{
10
31
Token *token = token_it_read (&ctx->it );
11
- if (token->sub_kind == TokenCppKind_BraceOp)
32
+ Token *name;
33
+ if (!token) {
34
+ ctx->done = true ;
35
+ }
36
+ // NOTE(jack): Comments and macros can occur inside bodies that we would like to skip,
37
+ // and should still be indexed.
38
+ else if (F4_Index_PeekTokenKind (ctx, TokenBaseKind_Comment, &name))
39
+ {
40
+ F4_Index_ParseComment (ctx, name);
41
+ }
42
+ // NOTE(jack): Macros
43
+ else if (F4_Index_RequireTokenSubKind (ctx, TokenCppKind_PPDefine, 0 , F4_Index_TokenSkipFlag_SkipWhitespace))
44
+ {
45
+ F4_CPP_ParseMacroDefinition (ctx, F4_Index_TokenSkipFlag_SkipWhitespace);
46
+ }
47
+ else if (token->sub_kind == TokenCppKind_BraceOp)
12
48
{
13
49
nest += 1 ;
14
50
body_found = 1 ;
@@ -18,11 +54,11 @@ F4_CPP_SkipParseBody(F4_Index_ParseCtx *ctx)
18
54
nest -= 1 ;
19
55
if (nest == 0 )
20
56
{
57
+ F4_Index_ParseCtx_Inc (ctx, F4_Index_TokenSkipFlag_SkipWhitespace);
21
58
break ;
22
59
}
23
60
}
24
- else
25
- {
61
+ else if (body_found == 0 ) {
26
62
break ;
27
63
}
28
64
@@ -68,43 +104,39 @@ internal F4_LANGUAGE_INDEXFILE(F4_CPP_IndexFile)
68
104
(F4_Index_PeekToken (ctx, S8Lit (" union" ))) ||
69
105
(F4_Index_PeekToken (ctx, S8Lit (" enum" )))))
70
106
{
71
- // ~ NOTE(rjf): Structs
72
- if (scope_nest == 0 &&
73
- F4_Index_RequireToken (ctx, S8Lit (" struct" ), flags) &&
74
- F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &name, flags))
107
+ // ~ NOTE(rjf): Structs and Unions (nested declarations not parsed)
108
+ if (F4_Index_RequireTokenSubKind (ctx, TokenCppKind_Struct, &name, flags) ||
109
+ F4_Index_RequireTokenSubKind (ctx, TokenCppKind_Union, &name, flags))
75
110
{
76
111
handled = 1 ;
77
- F4_Index_NoteFlags note_flags = F4_Index_NoteFlag_ProductType;
112
+ F4_Index_NoteFlags note_flags = ((name->sub_kind == TokenCppKind_Struct) ?
113
+ F4_Index_NoteFlag_ProductType : F4_Index_NoteFlag_SumType);
114
+
115
+ b32 name_found = F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &name, flags);
78
116
if (!F4_CPP_SkipParseBody (ctx))
79
117
{
80
118
note_flags |= F4_Index_NoteFlag_Prototype;
81
119
}
82
- F4_Index_MakeNote (ctx->app , ctx->file , 0 ,
83
- F4_Index_StringFromToken (ctx, name),
84
- F4_Index_NoteKind_Type,
85
- note_flags, Ii64 (name));
86
- }
87
-
88
- // ~ NOTE(rjf): Unions
89
- else if (scope_nest == 0 &&
90
- F4_Index_RequireToken (ctx, S8Lit (" union" ), flags) &&
91
- F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &name, flags))
92
- {
93
- handled = 1 ;
94
- F4_Index_NoteFlags note_flags = F4_Index_NoteFlag_SumType;
95
- if (!F4_CPP_SkipParseBody (ctx))
120
+ if (name_found) {
121
+ F4_Index_MakeNote (ctx->app , ctx->file , 0 ,
122
+ F4_Index_StringFromToken (ctx, name),
123
+ F4_Index_NoteKind_Type,
124
+ note_flags, Ii64 (name));
125
+ }
126
+ // NOTE(jack): clear the prototype flag so that the typedef'd name
127
+ // is not flagged as a prototype
128
+ note_flags &= ~F4_Index_NoteFlag_Prototype;
129
+ if (F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &name, flags))
96
130
{
97
- note_flags |= F4_Index_NoteFlag_Prototype;
131
+ F4_Index_MakeNote (ctx->app , ctx->file , 0 ,
132
+ F4_Index_StringFromToken (ctx, name),
133
+ F4_Index_NoteKind_Type,
134
+ note_flags, Ii64 (name));
98
135
}
99
- F4_Index_MakeNote (ctx->app , ctx->file , 0 ,
100
- F4_Index_StringFromToken (ctx, name),
101
- F4_Index_NoteKind_Type,
102
- note_flags, Ii64 (name));
103
136
}
104
137
105
138
// ~ NOTE(rjf): Enums
106
- else if (scope_nest == 0 &&
107
- F4_Index_RequireToken (ctx, string_u8_litexpr (" enum" ), flags))
139
+ else if (F4_Index_RequireToken (ctx, string_u8_litexpr (" enum" ), flags))
108
140
{
109
141
handled = 1 ;
110
142
F4_Index_NoteFlags note_flags = 0 ;
@@ -130,6 +162,48 @@ internal F4_LANGUAGE_INDEXFILE(F4_CPP_IndexFile)
130
162
131
163
for (;!ctx->done ;)
132
164
{
165
+ if (F4_Index_RequireTokenKind (ctx, TokenBaseKind_Comment, &constant, flags))
166
+ {
167
+ F4_Index_ParseComment (ctx, constant);
168
+ }
169
+ // NOTE(jack): Macros
170
+ if (F4_Index_RequireTokenSubKind (ctx, TokenCppKind_PPDefine, 0 , flags))
171
+ {
172
+ // NOTE(jack): If the defined token is the enum type name,
173
+ // don't note it as an macro
174
+ // typedef enum Key
175
+ // {
176
+ // #define Key(name, str) Key_##name,
177
+ // #include "os_key_list.inc"
178
+ // #undef Key
179
+ // Key_Max
180
+ // } Key;
181
+
182
+ if (!F4_Index_PeekToken (ctx, F4_Index_StringFromToken (ctx, name)))
183
+ {
184
+ F4_CPP_ParseMacroDefinition (ctx, F4_Index_TokenSkipFlag_SkipWhitespace);
185
+ }
186
+ else
187
+ {
188
+ F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, 0 , flags);
189
+ for (;!ctx->done ;)
190
+ {
191
+ Token *token = token_it_read (&ctx->it );
192
+ if (!(token->flags & TokenBaseFlag_PreprocessorBody) ||
193
+ token->kind == TokenBaseKind_Preprocessor)
194
+ {
195
+ break ;
196
+ }
197
+ F4_Index_ParseCtx_IncWs (ctx);
198
+ }
199
+ }
200
+ }
201
+
202
+ // NOTE(jack): On #undef skip past the identifier so that it isn't noted as a constant
203
+ if (F4_Index_RequireTokenSubKind (ctx, TokenCppKind_PPUndef, 0 , flags))
204
+ {
205
+ F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, 0 , flags);
206
+ }
133
207
if (F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &constant, flags))
134
208
{
135
209
F4_Index_MakeNote (ctx->app , ctx->file , 0 , F4_Index_StringFromToken (ctx, constant), F4_Index_NoteKind_Constant, 0 , Ii64 (constant));
@@ -139,6 +213,10 @@ internal F4_LANGUAGE_INDEXFILE(F4_CPP_IndexFile)
139
213
{
140
214
for (;!ctx->done ;)
141
215
{
216
+ if (F4_Index_RequireTokenKind (ctx, TokenBaseKind_Comment, &constant, flags))
217
+ {
218
+ F4_Index_ParseComment (ctx, constant);
219
+ }
142
220
if (F4_Index_PeekToken (ctx, S8Lit (" }" )) ||
143
221
F4_Index_PeekToken (ctx, S8Lit (" ," )))
144
222
{
@@ -174,11 +252,23 @@ internal F4_LANGUAGE_INDEXFILE(F4_CPP_IndexFile)
174
252
F4_Index_NoteKind_Type,
175
253
note_flags, Ii64 (name));
176
254
}
255
+
256
+ // NOTE(jack): clear the prototype flag so that the typedef'd name
257
+ // is not flagged as a prototype
258
+ note_flags &= ~F4_Index_NoteFlag_Prototype;
259
+ if (F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &name, flags))
260
+ {
261
+ F4_Index_MakeNote (ctx->app , ctx->file , 0 ,
262
+ F4_Index_StringFromToken (ctx, name),
263
+ F4_Index_NoteKind_Type,
264
+ note_flags, Ii64 (name));
265
+ }
177
266
}
178
267
179
268
// ~ NOTE(rjf): Regular Typedef
180
269
else
181
270
{
271
+ Token *aliased_type_token = token_it_read (&ctx->it );
182
272
for (;token_it_inc_all (&ctx->it );)
183
273
{
184
274
Token *token = token_it_read (&ctx->it );
@@ -198,37 +288,24 @@ internal F4_LANGUAGE_INDEXFILE(F4_CPP_IndexFile)
198
288
F4_Index_SeekToken (ctx, S8Lit (" ;" ));
199
289
if (name)
200
290
{
291
+ F4_Index_Note* aliased_type_index_note = F4_Index_LookupNote (F4_Index_StringFromToken (ctx, aliased_type_token));
292
+ F4_Index_NoteFlags note_flags = 0 ;
293
+
294
+ if (aliased_type_index_note) {
295
+ note_flags = aliased_type_index_note->flags ;
296
+ }
201
297
F4_Index_MakeNote (ctx->app , ctx->file , 0 ,
202
298
F4_Index_StringFromToken (ctx, name),
203
299
F4_Index_NoteKind_Type,
204
- 0 , Ii64 (name));
300
+ note_flags , Ii64 (name));
205
301
}
206
302
}
207
-
208
303
}
209
-
210
304
// ~ NOTE(rjf): Macros
211
- else if (F4_Index_PeekTokenSubKind (ctx, TokenCppKind_PPDefine, 0 ))
305
+ else if (F4_Index_RequireTokenSubKind (ctx, TokenCppKind_PPDefine, 0 , flags ))
212
306
{
213
307
handled = 1 ;
214
-
215
- F4_Index_ParseCtx_Inc (ctx, F4_Index_TokenSkipFlag_SkipWhitespace);
216
- if (F4_Index_RequireTokenKind (ctx, TokenBaseKind_Identifier, &name, flags))
217
- {
218
- F4_Index_MakeNote (ctx->app , ctx->file , 0 , F4_Index_StringFromToken (ctx, name),
219
- F4_Index_NoteKind_Macro, 0 , Ii64 (name));
220
- }
221
-
222
- for (;!ctx->done ;)
223
- {
224
- Token *token = token_it_read (&ctx->it );
225
- if (!(token->flags & TokenBaseFlag_PreprocessorBody) ||
226
- token->kind == TokenBaseKind_Preprocessor)
227
- {
228
- break ;
229
- }
230
- F4_Index_ParseCtx_IncWs (ctx);
231
- }
308
+ F4_CPP_ParseMacroDefinition (ctx, flags);
232
309
}
233
310
234
311
// ~ NOTE(rjf): Comment Tags
0 commit comments