Codebase list gir-to-d / run/0c91d1c7-e177-483b-8a5c-76520405b43b/upstream
Import upstream version 0.23.0 Debian Janitor 1 year, 2 months ago
4 changed file(s) with 65 addition(s) and 70 deletion(s). Raw diff Collapse all Expand all
397397 if ( returnType.length > -1 && param == params[returnType.length] && params[returnType.length].direction != GirParamDirection.Default )
398398 continue;
399399
400 if ( paramCount == 0 && strct.type == GirStructType.Record && isInstanceParam(param) )
400 if ( paramCount == 0 && strct.type == GirStructType.Record && isInstanceParam(param) && type != GirFunctionType.Constructor )
401401 continue;
402402
403403 if ( paramCount++ > 0 )
443443
444444 if ( instanceParam || ( !params.empty && isInstanceParam(params[0])) )
445445 {
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]);
466455
467456 if ( insType )
468457 dType = insType;
470459
471460 if ( type == GirFunctionType.Constructor || strct.isNamespace() || strct.noNamespace )
472461 {
473 string id = tokenToGtkD(instanceParam.name, wrapper.aliasses, localAliases());
462 string id = tokenToGtkD(instance.name, wrapper.aliasses, localAliases());
474463
475464 if ( dType && !(dType.isNamespace() || dType.noNamespace) )
476465 gtkCall ~= "("~ id ~" is null) ? null : "~ id ~"."~ dType.getHandleFunc() ~"()";
1717 module gtd.GirType;
1818
1919 import std.algorithm: among, canFind, startsWith;
20 import std.array: replace;
20 import std.array: replace, split;
2121 import std.conv: to;
2222 import std.range: empty;
2323
102102 if ( cType is null && (name == "filename" || name == "utf8") )
103103 cType = "gchar*";
104104
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
105112 if ( reader.front.type == XMLNodeType.EmptyTag )
106113 return;
107114
2323 import std.path;
2424 import std.stdio;
2525 import std.string;
26 import std.process : environment;
2627
2728 import gtd.DefReader;
2829 import gtd.GirField;
557558
558559 string getAbsoluteGirPath(string girFile)
559560 {
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);
569572 }
570573
571574 private void printFilePath(string fileName)
584587 }
585588 }
586589
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
589603 version(Windows)
590604 {
591 import std.process : environment;
592
593 static string path;
594
595 if (path !is null)
596 return path;
597
598605 foreach (p; splitter(environment.get("PATH"), ';'))
599606 {
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");
604608 }
605609
606 return path;
607610 }
608611 else version(OSX)
609612 {
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");
618614 if(path)
619615 {
620 path = path.buildNormalizedPath("../share/gir-1.0");
616 dirs ~= path.buildNormalizedPath("../share/gir-1.0");
621617 }
622 else
618
619 path = environment.get("HOMEBREW_ROOT");
620 if(path)
623621 {
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");
629623 }
630
631 return path;
632624 }
633625 else
634626 {
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;
637635 }
638636
639637 private GirParam findParam(GirStruct strct, string func, string name)
1616
1717 module gtd.IndentedStringBuilder;
1818
19 import std.algorithm: canFind, startsWith, endsWith;
19 import std.algorithm: canFind, count, startsWith, endsWith;
2020 import std.range: empty;
2121 import std.string: strip;
2222
2525 {
2626 string tabs;
2727 bool statement;
28 bool paramList;
28 int paramList = 0;
2929
3030 this()
3131 {
5858 return tabs ~" "~ line ~ "\n";
5959 }
6060
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, ')')) )
6262 {
6363 if ( !canFind(line, '{') && tabs.length > 0 )
6464 tabs.length = tabs.length -1;
6969 if ( endsWith(line, ");") && !endsWith(line, "));") && line != ");" )
7070 statement = true;
7171
72 paramList = false;
72 if ( paramList > 0 )
73 paramList--;
7374 }
7475
7576 if ( line.empty )
101102 else if ( endsWith(line, "(") )
102103 {
103104 tabs ~= '\t';
104 paramList = true;
105 paramList++;
105106 }
106107
107108 return text;