8
8
using System . Xml ;
9
9
using CppSharp ;
10
10
using CppSharp . AST ;
11
+ using CppSharp . Generators ;
11
12
using CppSharp . Generators . CSharp ;
12
13
using HtmlAgilityPack ;
13
14
using Mono . Data . Sqlite ;
@@ -251,64 +252,31 @@ public void DocumentFunction(Function function)
251
252
var lineStart = function . LineNumberStart ;
252
253
var lineEnd = function . LineNumberEnd ;
253
254
var functions = this . functionNodes [ function . OriginalName ] ;
255
+ var unit = function . OriginalNamespace . TranslationUnit ;
256
+ var location = unit . FileName ;
254
257
var node = functions . Find (
255
- f => f . Location == function . TranslationUnit . FileName &&
256
- ( f . LineNumber == lineStart || f . LineNumber == lineEnd ) ) ;
258
+ f => f . Location == location &&
259
+ ( f . LineNumber == lineStart || f . LineNumber == lineEnd ) ) ;
257
260
var @params = function . Parameters . Where ( p => p . Kind == ParameterKind . Regular ) . ToList ( ) ;
258
- // HACK: functions in qglobal.h have weird additional definitions just for docs
259
- if ( ( node == null || node . HRef == null ) && function . TranslationUnit . FileName == "qglobal.h" )
260
- {
261
- node = functions . Find (
262
- c => c . Location == function . TranslationUnit . FileName &&
263
- ( c . FullName == function . QualifiedOriginalName || c . Name == function . OriginalName ) &&
264
- c . Access != "private" && c . ParametersModifiers . Count == @params . Count ) ;
265
- }
266
- // HACK: some functions are "located" in a cpp, go figure...
267
- if ( ( node == null || node . HRef == null ) && function . Signature != null )
261
+ int realParamsCount = @params . Count ( p => ! string . IsNullOrWhiteSpace ( p . OriginalName ) || p . DefaultArgument == null ) ;
262
+ // functions can have different line numbers because of #defines
263
+ if ( node == null || node . HRef == null )
268
264
{
269
- var qualifiedOriginalName = function . GetQualifiedName ( decl => decl . OriginalName ,
270
- decl =>
271
- {
272
- var @class = decl . OriginalNamespace as Class ;
273
- return @class != null ? ( @class . OriginalClass ?? @class ) : decl . OriginalNamespace ;
274
- } ) ;
275
- var nodes = functions . Where ( f => f . FullName == qualifiedOriginalName &&
276
- f . ParametersModifiers . Count == @params . Count ) . ToList ( ) ;
277
- if ( nodes . Count == 0 )
278
- {
279
- @params . RemoveAll ( p => string . IsNullOrEmpty ( p . OriginalName ) && p . DefaultArgument != null ) ;
280
- }
281
- nodes = functions . Where ( f => f . FullName == qualifiedOriginalName &&
282
- f . ParametersModifiers . Count == @params . Count ) . ToList ( ) ;
283
- if ( nodes . Count == 0 )
284
- {
285
- var method = function as Method ;
286
- if ( method != null && ! method . IsStatic && function . OriginalFunction == null )
287
- {
288
- return ;
289
- }
290
- nodes = functions . Where ( f => f . Name == function . OriginalName &&
291
- f . ParametersModifiers . Count == @params . Count ) . ToList ( ) ;
292
- }
265
+ var nodes = functions . FindAll (
266
+ f => CheckLocation ( f . Location , location ) &&
267
+ ( f . FullName == function . QualifiedOriginalName || f . Name == function . OriginalName ) &&
268
+ f . Access != "private" && f . ParametersModifiers . Count == realParamsCount ) ;
269
+ // HACK: work around https://bugreports.qt.io/browse/QTBUG-53994
293
270
if ( nodes . Count == 1 )
294
271
{
295
272
node = nodes [ 0 ] ;
296
273
}
297
274
else
298
275
{
299
- if ( function . Signature . Contains ( '(' ) )
300
- {
301
- var startArgs = function . Signature . IndexOf ( '(' ) + 1 ;
302
- var signature = function . Signature ;
303
- if ( signature . Contains ( ": " ) )
304
- {
305
- signature = signature . Substring ( 0 , signature . IndexOf ( ": " , StringComparison . Ordinal ) ) ;
306
- }
307
- signature = signature . Substring ( startArgs , signature . LastIndexOf ( ')' ) - startArgs ) ;
308
- signature = this . regexSpaceBetweenArgs . Replace ( this . regexArgName . Replace ( signature , "$1$3$5" ) , " " ) ;
309
- node = nodes . Find ( f => string . Join ( ", " ,
310
- f . ParametersModifiers . Select ( m => m . Replace ( " *" , "*" ) . Replace ( " &" , "&" ) ) ) == signature ) ;
311
- }
276
+ Generator . CurrentOutputNamespace = unit . Module . OutputNamespace ;
277
+ var paramTypes = @params . Select ( p => p . Type . ToString ( ) ) . ToList ( ) ;
278
+ node = nodes . Find (
279
+ f => f . ParametersModifiers . SequenceEqual ( paramTypes , new TypeInIndexEqualityComparer ( ) ) ) ;
312
280
}
313
281
}
314
282
if ( node != null && node . HRef != null )
@@ -323,7 +291,7 @@ public void DocumentFunction(Function function)
323
291
{
324
292
var docs = this . membersDocumentation [ file ] [ key ] ;
325
293
var i = 0 ;
326
- // HACK: work around bugs of the type of https://bugreports.qt.io/browse/QTBUG-46148
294
+ // HACK: work around https://bugreports.qt.io/browse/QTBUG-53941
327
295
if ( function . Namespace . Name == "QByteArray" &&
328
296
( ( function . OriginalName == "qCompress" && @params . Count == 2 ) ||
329
297
( function . OriginalName == "qUncompress" && @params . Count == 1 ) ) )
@@ -351,6 +319,24 @@ public void DocumentFunction(Function function)
351
319
}
352
320
}
353
321
322
+ private static bool CheckLocation ( string indexLocation , string location )
323
+ {
324
+ if ( indexLocation == location )
325
+ {
326
+ return true ;
327
+ }
328
+ // work around https://bugreports.qt.io/browse/QTBUG-53946
329
+ if ( Path . GetExtension ( indexLocation ) != ".h" && indexLocation . Contains ( '_' ) )
330
+ {
331
+ var i = indexLocation . IndexOf ( '_' ) ;
332
+ if ( i >= 0 )
333
+ {
334
+ return indexLocation . Substring ( 0 , i ) + ".h" == location ;
335
+ }
336
+ }
337
+ return false ;
338
+ }
339
+
354
340
private static string EscapeId ( string link )
355
341
{
356
342
var idBuilder = new StringBuilder ( ) ;
@@ -787,8 +773,6 @@ private static void AddObsoleteAttribute(Declaration function)
787
773
788
774
private readonly Dictionary < string , List < DocumentationNode > > typesDocumentation = new Dictionary < string , List < DocumentationNode > > ( ) ;
789
775
private readonly Dictionary < string , Dictionary < string , List < MemberDocumentationNode > > > membersDocumentation = new Dictionary < string , Dictionary < string , List < MemberDocumentationNode > > > ( ) ;
790
- private readonly Regex regexArgName = new Regex ( @"((unsigned\s*)?[\w<>]+)\s*(\*|&)?\s*\w*(\s*=\s*[^=,]+?)?(,|$)" , RegexOptions . Compiled ) ;
791
- private readonly Regex regexSpaceBetweenArgs = new Regex ( @"\r?\n\s+" , RegexOptions . Compiled ) ;
792
776
793
777
private readonly Dictionary < string , List < FunctionDocIndexNode > > functionNodes = new Dictionary < string , List < FunctionDocIndexNode > > ( ) ;
794
778
private readonly Dictionary < string , List < FullNameDocIndexNode > > propertyNodes = new Dictionary < string , List < FullNameDocIndexNode > > ( ) ;
@@ -797,5 +781,18 @@ private static void AddObsoleteAttribute(Declaration function)
797
781
private readonly List < DocIndexNode > variableNodes = new List < DocIndexNode > ( ) ;
798
782
799
783
private Regex regexParameters = new Regex ( @"<i>\s*(.+?)\s*</i>" , RegexOptions . Compiled ) ;
784
+
785
+ private class TypeInIndexEqualityComparer : IEqualityComparer < string >
786
+ {
787
+ public bool Equals ( string x , string y )
788
+ {
789
+ return x . Contains ( y ) ;
790
+ }
791
+
792
+ public int GetHashCode ( string obj )
793
+ {
794
+ return obj . GetHashCode ( ) ;
795
+ }
796
+ }
800
797
}
801
798
}
0 commit comments