Import upstream version 0.23.0
Debian Janitor
1 year, 2 months ago
397 | 397 | if ( returnType.length > -1 && param == params[returnType.length] && params[returnType.length].direction != GirParamDirection.Default ) |
398 | 398 | continue; |
399 | 399 | |
400 | if ( paramCount == 0 && strct.type == GirStructType.Record && isInstanceParam(param) ) | |
400 | if ( paramCount == 0 && strct.type == GirStructType.Record && isInstanceParam(param) && type != GirFunctionType.Constructor ) | |
401 | 401 | continue; |
402 | 402 | |
403 | 403 | if ( paramCount++ > 0 ) |
443 | 443 | |
444 | 444 | if ( instanceParam || ( !params.empty && isInstanceParam(params[0])) ) |
445 | 445 | { |
446 | GirStruct dType; | |
447 | ||
448 | if ( instanceParam ) | |
449 | { | |
450 | dType = strct.pack.getStruct(instanceParam.type.name); | |
451 | ||
452 | if ( dType.cType != instanceParam.type.cType.removePtr() && !instanceParam.type.cType.among("gpointer", "gconstpointer") ) | |
453 | gtkCall ~= "cast("~ stringToGtkD(instanceParam.type.cType, wrapper.aliasses, localAliases()) ~")"; | |
454 | } | |
455 | else | |
456 | { | |
457 | dType = strct.pack.getStruct(params[0].type.name); | |
458 | ||
459 | if ( dType.cType != params[0].type.cType.removePtr() && !params[0].type.cType.among("gpointer", "gconstpointer") ) | |
460 | gtkCall ~= "cast("~ stringToGtkD(params[0].type.cType, wrapper.aliasses, localAliases()) ~")"; | |
461 | } | |
462 | ||
463 | if ( instanceParam && instanceParam.type.name in strct.structWrap ) | |
464 | { | |
465 | GirStruct insType = strct.pack.getStruct(strct.structWrap[instanceParam.type.name]); | |
446 | GirParam instance = instanceParam ? instanceParam : params[0]; | |
447 | GirStruct dType = strct.pack.getStruct(instance.type.name); | |
448 | ||
449 | if ( dType.cType != instance.type.cType.removePtr() && !instance.type.cType.among("gpointer", "gconstpointer") ) | |
450 | gtkCall ~= "cast("~ stringToGtkD(instance.type.cType, wrapper.aliasses, localAliases()) ~")"; | |
451 | ||
452 | if ( instance && instance.type.name in strct.structWrap ) | |
453 | { | |
454 | GirStruct insType = strct.pack.getStruct(strct.structWrap[instance.type.name]); | |
466 | 455 | |
467 | 456 | if ( insType ) |
468 | 457 | dType = insType; |
470 | 459 | |
471 | 460 | if ( type == GirFunctionType.Constructor || strct.isNamespace() || strct.noNamespace ) |
472 | 461 | { |
473 | string id = tokenToGtkD(instanceParam.name, wrapper.aliasses, localAliases()); | |
462 | string id = tokenToGtkD(instance.name, wrapper.aliasses, localAliases()); | |
474 | 463 | |
475 | 464 | if ( dType && !(dType.isNamespace() || dType.noNamespace) ) |
476 | 465 | gtkCall ~= "("~ id ~" is null) ? null : "~ id ~"."~ dType.getHandleFunc() ~"()"; |
17 | 17 | module gtd.GirType; |
18 | 18 | |
19 | 19 | import std.algorithm: among, canFind, startsWith; |
20 | import std.array: replace; | |
20 | import std.array: replace, split; | |
21 | 21 | import std.conv: to; |
22 | 22 | import std.range: empty; |
23 | 23 | |
102 | 102 | if ( cType is null && (name == "filename" || name == "utf8") ) |
103 | 103 | cType = "gchar*"; |
104 | 104 | |
105 | //Vala libraries can have the package name in there name twice, befoer and after the dot. | |
106 | string[] arr = split(name, '.'); | |
107 | if ( arr.length > 1 && arr[1].startsWith(arr[0]) ) | |
108 | { | |
109 | name = arr[1][arr[0].length .. $]; | |
110 | } | |
111 | ||
105 | 112 | if ( reader.front.type == XMLNodeType.EmptyTag ) |
106 | 113 | return; |
107 | 114 |
23 | 23 | import std.path; |
24 | 24 | import std.stdio; |
25 | 25 | import std.string; |
26 | import std.process : environment; | |
26 | 27 | |
27 | 28 | import gtd.DefReader; |
28 | 29 | import gtd.GirField; |
557 | 558 | |
558 | 559 | string getAbsoluteGirPath(string girFile) |
559 | 560 | { |
560 | if ( commandlineGirPath ) | |
561 | { | |
562 | string cmdGirFile = buildNormalizedPath(commandlineGirPath, girFile); | |
563 | ||
564 | if ( exists(cmdGirFile) ) | |
565 | return cmdGirFile; | |
566 | } | |
567 | ||
568 | return buildNormalizedPath(getGirDirectory(), girFile); | |
561 | string[] girDirectories = getGirDirectories(); | |
562 | foreach(dir; girDirectories) | |
563 | { | |
564 | string girFilePath = buildNormalizedPath(dir, girFile); | |
565 | if (exists(girFilePath) && isFile(girFilePath)) | |
566 | return girFilePath; | |
567 | } | |
568 | ||
569 | error("Couldn't find the gir file: ", girFile, " in any of: ", girDirectories.join(", ")); | |
570 | // Error shouldn't return anyways | |
571 | assert(0); | |
569 | 572 | } |
570 | 573 | |
571 | 574 | private void printFilePath(string fileName) |
584 | 587 | } |
585 | 588 | } |
586 | 589 | |
587 | private string getGirDirectory() | |
588 | { | |
590 | private string[] getGirDirectories() | |
591 | { | |
592 | static string[] dirs; | |
593 | if(dirs !is null) | |
594 | { | |
595 | return dirs; | |
596 | } | |
597 | ||
598 | if ( commandlineGirPath ) | |
599 | { | |
600 | dirs ~= commandlineGirPath; | |
601 | } | |
602 | ||
589 | 603 | version(Windows) |
590 | 604 | { |
591 | import std.process : environment; | |
592 | ||
593 | static string path; | |
594 | ||
595 | if (path !is null) | |
596 | return path; | |
597 | ||
598 | 605 | foreach (p; splitter(environment.get("PATH"), ';')) |
599 | 606 | { |
600 | string dllPath = buildNormalizedPath(p, "libgtk-3-0.dll"); | |
601 | ||
602 | if ( exists(dllPath) ) | |
603 | path = p.buildNormalizedPath("../share/gir-1.0"); | |
607 | dirs ~= p.buildNormalizedPath("../share/gir-1.0"); | |
604 | 608 | } |
605 | 609 | |
606 | return path; | |
607 | 610 | } |
608 | 611 | else version(OSX) |
609 | 612 | { |
610 | import std.process : environment; | |
611 | ||
612 | static string path; | |
613 | ||
614 | if (path !is null) | |
615 | return path; | |
616 | ||
617 | path = environment.get("GTK_BASEPATH"); | |
613 | string path = environment.get("GTK_BASEPATH"); | |
618 | 614 | if(path) |
619 | 615 | { |
620 | path = path.buildNormalizedPath("../share/gir-1.0"); | |
616 | dirs ~= path.buildNormalizedPath("../share/gir-1.0"); | |
621 | 617 | } |
622 | else | |
618 | ||
619 | path = environment.get("HOMEBREW_ROOT"); | |
620 | if(path) | |
623 | 621 | { |
624 | path = environment.get("HOMEBREW_ROOT"); | |
625 | if(path) | |
626 | { | |
627 | path = path.buildNormalizedPath("share/gir-1.0"); | |
628 | } | |
622 | dirs ~= path.buildNormalizedPath("share/gir-1.0"); | |
629 | 623 | } |
630 | ||
631 | return path; | |
632 | 624 | } |
633 | 625 | else |
634 | 626 | { |
635 | return "/usr/share/gir-1.0"; | |
636 | } | |
627 | string xdgDataDirs = environment.get("XDG_DATA_DIRS", "/usr/local/share:/usr/share"); | |
628 | foreach (p; splitter(xdgDataDirs, ':')) | |
629 | { | |
630 | dirs ~= p.buildNormalizedPath("gir-1.0"); | |
631 | } | |
632 | } | |
633 | ||
634 | return dirs.filter!(p=> exists(p) && isDir(p) ).array; | |
637 | 635 | } |
638 | 636 | |
639 | 637 | private GirParam findParam(GirStruct strct, string func, string name) |
16 | 16 | |
17 | 17 | module gtd.IndentedStringBuilder; |
18 | 18 | |
19 | import std.algorithm: canFind, startsWith, endsWith; | |
19 | import std.algorithm: canFind, count, startsWith, endsWith; | |
20 | 20 | import std.range: empty; |
21 | 21 | import std.string: strip; |
22 | 22 | |
25 | 25 | { |
26 | 26 | string tabs; |
27 | 27 | bool statement; |
28 | bool paramList; | |
28 | int paramList = 0; | |
29 | 29 | |
30 | 30 | this() |
31 | 31 | { |
58 | 58 | return tabs ~" "~ line ~ "\n"; |
59 | 59 | } |
60 | 60 | |
61 | if ( endsWith(line, "}", "};") || startsWith(line, "}", "};") || line == "));" || line == "connectFlags);" || (paramList && endsWith(line, ");", ")")) ) | |
61 | if ( endsWith(line, "}", "};") || startsWith(line, "}", "};") || line == "));" || line == "connectFlags);" || (paramList > 0 && endsWith(line, ");", ")") && count(line, '(') != count(line, ')')) ) | |
62 | 62 | { |
63 | 63 | if ( !canFind(line, '{') && tabs.length > 0 ) |
64 | 64 | tabs.length = tabs.length -1; |
69 | 69 | if ( endsWith(line, ");") && !endsWith(line, "));") && line != ");" ) |
70 | 70 | statement = true; |
71 | 71 | |
72 | paramList = false; | |
72 | if ( paramList > 0 ) | |
73 | paramList--; | |
73 | 74 | } |
74 | 75 | |
75 | 76 | if ( line.empty ) |
101 | 102 | else if ( endsWith(line, "(") ) |
102 | 103 | { |
103 | 104 | tabs ~= '\t'; |
104 | paramList = true; | |
105 | paramList++; | |
105 | 106 | } |
106 | 107 | |
107 | 108 | return text; |