Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit 4b2040c

Browse files
committed
allow typedef'd enums in C++ indexer
1 parent 52e64d8 commit 4b2040c

File tree

1 file changed

+84
-48
lines changed

1 file changed

+84
-48
lines changed

4coder_fleury_lang_cpp.cpp

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,54 @@ F4_CPP_ParseFunctionBodyIFuckingHateCPlusPlus(F4_Index_ParseCtx *ctx, b32 *proto
133133
return valid;
134134
}
135135

136+
function void
137+
F4_CPP_ParseEnumBodyIFuckingHateCPlusPlus(F4_Index_ParseCtx *ctx)
138+
{
139+
if(F4_Index_ParsePattern(ctx, "%t", "{"))
140+
{
141+
for(;!ctx->done;)
142+
{
143+
Token *constant = 0;
144+
if(F4_Index_ParsePattern(ctx, "%k%t", TokenBaseKind_Identifier, &constant, ","))
145+
{
146+
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, constant), F4_Index_NoteKind_Constant, 0, Ii64(constant));
147+
}
148+
else if(F4_Index_ParsePattern(ctx, "%k%t", TokenBaseKind_Identifier, &constant, "="))
149+
{
150+
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, constant), F4_Index_NoteKind_Constant, 0, Ii64(constant));
151+
152+
for(;!ctx->done;)
153+
{
154+
Token *token = token_it_read(&ctx->it);
155+
if(token->kind == TokenBaseKind_StatementClose)
156+
{
157+
F4_Index_ParseCtx_Inc(ctx, 0);
158+
break;
159+
}
160+
else if(token->kind == TokenBaseKind_ScopeClose ||
161+
token->kind == TokenBaseKind_ScopeOpen)
162+
{
163+
break;
164+
}
165+
F4_Index_ParseCtx_Inc(ctx, 0);
166+
}
167+
}
168+
else if(F4_Index_ParsePattern(ctx, "%k", TokenBaseKind_Identifier, &constant))
169+
{
170+
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, constant), F4_Index_NoteKind_Constant, 0, Ii64(constant));
171+
}
172+
else if(F4_Index_ParsePattern(ctx, "%t", "}"))
173+
{
174+
break;
175+
}
176+
else
177+
{
178+
F4_Index_ParseCtx_Inc(ctx, 0);
179+
}
180+
}
181+
}
182+
}
183+
136184
internal F4_LANGUAGE_INDEXFILE(F4_CPP_IndexFile)
137185
{
138186
int scope_nest = 0;
@@ -187,63 +235,51 @@ internal F4_LANGUAGE_INDEXFILE(F4_CPP_IndexFile)
187235
F4_CPP_ParseStructOrUnionBodyIFuckingHateCPlusPlus(ctx, F4_Index_NoteFlag_SumType);
188236
}
189237

190-
//~ NOTE(rjf): Enum Protoypes
191-
else if(F4_Index_ParsePattern(ctx, "%t%k%t", "enum", TokenBaseKind_Identifier, &name, ";"))
238+
//~ NOTE(rjf): Typedef'd Enums
239+
else if(F4_Index_ParsePattern(ctx, "%t%t%k", "typedef", "enum", TokenBaseKind_Identifier, &name) ||
240+
F4_Index_ParsePattern(ctx, "%t%t", "typedef", "enum"))
192241
{
193242
handled = 1;
194-
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, name),
195-
F4_Index_NoteKind_Type, 0, Ii64(name));
243+
b32 prototype = 0;
244+
b32 possible_name_at_end = name == 0;
245+
if(F4_Index_ParsePattern(ctx, "%t", ";"))
246+
{
247+
prototype = 1;
248+
}
249+
if(prototype == 0)
250+
{
251+
F4_CPP_ParseEnumBodyIFuckingHateCPlusPlus(ctx);
252+
}
253+
if(possible_name_at_end)
254+
{
255+
if(F4_Index_ParsePattern(ctx, "%k", TokenBaseKind_Identifier, &name))
256+
{}
257+
}
258+
if(name != 0)
259+
{
260+
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, name),
261+
F4_Index_NoteKind_Type, prototype ? F4_Index_NoteFlag_Prototype : 0, Ii64(name));
262+
}
196263
}
197264

198-
//~ NOTE(rjf): Enum Definitions
199-
else if(F4_Index_ParsePattern(ctx, "%t%k%t", "enum", TokenBaseKind_Identifier, &name, "{") ||
200-
F4_Index_ParsePattern(ctx, "%t%t", "enum", "{"))
265+
//~ NOTE(rjf): Enums
266+
else if(F4_Index_ParsePattern(ctx, "%t%k", "enum", TokenBaseKind_Identifier, &name) ||
267+
F4_Index_ParsePattern(ctx, "%t", "enum"))
201268
{
202269
handled = 1;
203-
if(name != 0)
270+
b32 prototype = 0;
271+
if(F4_Index_ParsePattern(ctx, "%t", ";"))
204272
{
205-
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, name),
206-
F4_Index_NoteKind_Type, 0, Ii64(name));
273+
prototype = 1;
207274
}
208-
for(;!ctx->done;)
275+
if(prototype == 0)
209276
{
210-
Token *constant = 0;
211-
if(F4_Index_ParsePattern(ctx, "%k%t", TokenBaseKind_Identifier, &constant, ","))
212-
{
213-
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, constant), F4_Index_NoteKind_Constant, 0, Ii64(constant));
214-
}
215-
else if(F4_Index_ParsePattern(ctx, "%k%t", TokenBaseKind_Identifier, &constant, "="))
216-
{
217-
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, constant), F4_Index_NoteKind_Constant, 0, Ii64(constant));
218-
219-
for(;!ctx->done;)
220-
{
221-
Token *token = token_it_read(&ctx->it);
222-
if(token->kind == TokenBaseKind_StatementClose)
223-
{
224-
F4_Index_ParseCtx_Inc(ctx, 0);
225-
break;
226-
}
227-
else if(token->kind == TokenBaseKind_ScopeClose ||
228-
token->kind == TokenBaseKind_ScopeOpen)
229-
{
230-
break;
231-
}
232-
F4_Index_ParseCtx_Inc(ctx, 0);
233-
}
234-
}
235-
else if(F4_Index_ParsePattern(ctx, "%k", TokenBaseKind_Identifier, &constant))
236-
{
237-
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, constant), F4_Index_NoteKind_Constant, 0, Ii64(constant));
238-
}
239-
else if(F4_Index_ParsePattern(ctx, "%t", "}"))
240-
{
241-
break;
242-
}
243-
else
244-
{
245-
F4_Index_ParseCtx_Inc(ctx, 0);
246-
}
277+
F4_CPP_ParseEnumBodyIFuckingHateCPlusPlus(ctx);
278+
}
279+
if(name != 0)
280+
{
281+
F4_Index_MakeNote(ctx->app, ctx->file, 0, F4_Index_StringFromToken(ctx, name),
282+
F4_Index_NoteKind_Type, prototype ? F4_Index_NoteFlag_Prototype : 0, Ii64(name));
247283
}
248284
}
249285

0 commit comments

Comments
 (0)