1 /* 2 * This file is part of gir-to-d. 3 * 4 * gir-to-d is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation, either version 3 7 * of the License, or (at your option) any later version. 8 * 9 * gir-to-d is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with gir-to-d. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 module gtd.GirAlias; 19 20 import std..string : splitLines, strip; 21 22 import gtd.GirType; 23 import gtd.GirWrapper; 24 import gtd.Log; 25 import gtd.XMLReader; 26 27 final class GirAlias 28 { 29 string name; 30 string cType; 31 string doc; 32 33 GirType baseType; 34 GirWrapper wrapper; 35 36 this(GirWrapper wrapper) 37 { 38 this.wrapper = wrapper; 39 } 40 41 void parse(T)(XMLReader!T reader) 42 { 43 name = reader.front.attributes["name"]; 44 cType = reader.front.attributes["c:type"]; 45 46 reader.popFront(); 47 48 while( !reader.empty && !reader.endTag("alias") ) 49 { 50 switch(reader.front.value) 51 { 52 case "type": 53 baseType = new GirType(wrapper); 54 baseType.parse(reader); 55 break; 56 case "doc": 57 reader.popFront(); 58 doc ~= reader.front.value; 59 reader.popFront(); 60 break; 61 case "doc-deprecated": 62 reader.popFront(); 63 doc ~= "\n\nDeprecated: "~ reader.front.value; 64 reader.popFront(); 65 break; 66 case "source-position": 67 reader.skipTag(); 68 break; 69 default: 70 warning("Unexpected tag: ", reader.front.value, " in GirAlias: ", name, reader); 71 } 72 reader.popFront(); 73 } 74 } 75 76 string[] getAliasDeclaration() 77 { 78 string[] buff; 79 if ( doc !is null && wrapper.includeComments ) 80 { 81 buff ~= "/**"; 82 foreach ( line; doc.splitLines() ) 83 buff ~= " * "~ line.strip(); 84 buff ~= " */"; 85 } 86 87 buff ~= "public alias "~ stringToGtkD(baseType.cType, wrapper.aliasses) ~" "~ tokenToGtkD(cType, wrapper.aliasses) ~";"; 88 89 return buff; 90 } 91 }