Skip to content

Commit 15a5548

Browse files
committed
Extend finding of functions to also get overloads
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 385c5e9 commit 15a5548

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/AST/ASTContext.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public Class FindCompleteClass(string name, bool ignoreCase = false)
9292
/// Finds an existing function in the library modules.
9393
public IEnumerable<Function> FindFunction(string name)
9494
{
95-
return TranslationUnits.Select(module => module.FindFunction(name))
96-
.Where(type => type != null);
95+
return TranslationUnits.SelectMany(module => module.FindFunction(name));
9796
}
9897

9998
/// Finds an existing typedef in the library modules.

src/AST/Namespace.cs

+10-12
Original file line numberDiff line numberDiff line change
@@ -160,33 +160,33 @@ public Enumeration FindEnum(IntPtr ptr)
160160
return Enums.FirstOrDefault(f => f.OriginalPtr == ptr);
161161
}
162162

163-
public Function FindFunction(string name, bool createDecl = false)
163+
public IEnumerable<Function> FindFunction(string name, bool createDecl = false)
164164
{
165165
if (string.IsNullOrEmpty(name))
166-
return null;
166+
return Enumerable.Empty<Function>();
167167

168168
var entries = name.Split(new string[] { "::" },
169169
StringSplitOptions.RemoveEmptyEntries).ToList();
170170

171171
if (entries.Count <= 1)
172172
{
173-
var function = Functions.FirstOrDefault(e => e.Name.Equals(name));
173+
var functions = Functions.Where(e => e.Name.Equals(name));
174174

175-
if (function == null && createDecl)
175+
if (!functions.Any() && createDecl)
176176
{
177-
function = new Function() { Name = name, Namespace = this };
177+
var function = new Function() { Name = name, Namespace = this };
178178
Declarations.Add(function);
179179
}
180180

181-
return function;
181+
return functions;
182182
}
183183

184-
var funcName = entries[entries.Count - 1];
184+
var funcName = entries[^1];
185185
var namespaces = entries.Take(entries.Count - 1);
186186

187187
var @namespace = FindNamespace(namespaces);
188188
if (@namespace == null)
189-
return null;
189+
return Enumerable.Empty<Function>();
190190

191191
return @namespace.FindFunction(funcName, createDecl);
192192
}
@@ -201,14 +201,12 @@ public Function FindFunctionByUSR(string usr)
201201

202202
Class CreateClass(string name, bool isComplete)
203203
{
204-
var @class = new Class
204+
return new Class
205205
{
206206
Name = name,
207207
Namespace = this,
208208
IsIncomplete = !isComplete
209209
};
210-
211-
return @class;
212210
}
213211

214212
public Class FindClass(string name,
@@ -316,7 +314,7 @@ public TypedefNameDecl FindTypedef(string name, bool createDecl = false)
316314
public T FindType<T>(string name) where T : Declaration
317315
{
318316
var type = FindEnum(name)
319-
?? FindFunction(name)
317+
?? FindFunction(name).FirstOrDefault()
320318
?? (Declaration)FindClass(name)
321319
?? FindTypedef(name);
322320

src/Generator/Library.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public static void CopyClassFields(this ASTContext context, string source,
533533
public static IEnumerable<Function> FindFunction(this ASTContext context, string name)
534534
{
535535
return context.TranslationUnits
536-
.Select(module => module.FindFunction(name))
536+
.SelectMany(module => module.FindFunction(name))
537537
.Where(function => function != null);
538538
}
539539

0 commit comments

Comments
 (0)