1 /*
2  * This file is part of gtkD.
3  * 
4  * gtkD 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, with
8  * some exceptions, please read the COPYING file.
9  * 
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 module utils.convparms;
21 
22 //debug = omitCode;
23 //debug = omitSignal;
24 //debug = overrides;
25 
26 public struct ConvParms
27 {
28 
29 	private import utils.GtkDClass;
30 	private import std.stdio;
31 	
32 	public string inFile;
33 	public string outPack;
34 	public string bindDir;
35 	public string outFile;
36 	public string strct;
37 	public string realStrct;
38 	public string ctorStrct;	/// the ToolItem derivates all retrun GtkToolItem
39 	public string clss;
40 	public string interf;
41 	public bool isInterface;  ///Are we generating an interface.
42 	public string[] templ;
43 	public string extend;
44 	public string[] impl;
45 	public string[] prefixes;
46 	public bool strictPrefix;	/// include only function that match the prefix
47 	public string[] imprts;
48 	public string[string]  structWrap;
49 	public string[] noStructs;
50 	public string[] noPrefixes;
51 	public string[] noCode;		    /// insert the external declaration but not the wrapping code
52 	public string[] noSignals;		/// Don't generate Signals
53 	public string[string] aliases;
54 	public string[string] mAliases;
55 	public string[] overrides;		     /// list of functions that need override for gtkD to work with dmd 2
56 	public string[][string]  outParms;   /// list of params that should be treated as out parameters
57 	public string[][string]  inoutParms; /// list of params that should be treated as inout/ref parameters
58 	public string[string][string] array; /// array["funct":["param":["length param"]]
59 	public string classCode;		     /// any valid D code to be copied to the final GtkD class
60 	public string interfaceCode;	     /// any valid D code to be copied to the final GtkD interface
61 	public string[] text;		         /// text to be added to the text read from the file
62 
63 	public void clearAll()
64 	{
65 		string[string] clear(){string[string] cc;return cc;};
66 		
67 		inFile.length = 0;
68 		//outPack.length = 0;
69 		outFile.length = 0;
70 		bindDir.length = 0;
71 		strct.length = 0;
72 		realStrct.length = 0;
73 		ctorStrct.length = 0;
74 		clss.length = 0;
75 		interf.length = 0;
76 		isInterface = false;
77 		extend.length = 0;
78 		prefixes.length = 0;
79 		templ.length = 0;
80 		impl.length = 0;
81 		strictPrefix = false;
82 		imprts.length = 0;
83 		structWrap = clear();
84 		noPrefixes.length = 0;
85 		noCode.length = 0;
86 		noStructs.length = 0;
87 		noSignals.length = 0;
88 		aliases = clear();
89 		mAliases = clear();
90 		overrides.length = 0;
91 		outParms = null;
92 		inoutParms = null;
93 		array = null;
94 		classCode.length = 0;
95 		interfaceCode.length = 0;
96 		text.length = 0;
97 
98 	}
99 	
100 	public string toString()
101 	{
102 		string text;
103 		text ~= "/*";
104 		text ~= "\n * Conversion parameters:";
105 		text ~= "\n * inFile  = "~inFile;
106 		text ~= "\n * outPack = "~outPack;
107 		text ~= "\n * outFile = "~outFile;
108 		text ~= "\n * strct   = "~strct;
109 		text ~= "\n * realStrct="~realStrct;
110 		text ~= "\n * ctorStrct="~ctorStrct;
111 		text ~= "\n * clss    = "~clss;
112 		text ~= "\n * interf  = "~interf;
113 		text ~= "\n * class Code: " ~ (classCode.length>0 ? "Yes" : "No");
114 		text ~= "\n * interface Code: " ~ (interfaceCode.length>0 ? "Yes" : "No");
115 		text ~= "\n * template for:";
116 		foreach ( string tp ; templ )
117 		{
118 			text ~= "\n * \t- "~tp;
119 		}
120 		
121 		text ~= "\n * extend  = "~extend;
122 		
123 		text ~= "\n * implements:";
124 		foreach ( string ip ; impl )
125 		{
126 			text ~= "\n * \t- "~ip;
127 		}
128 
129 		text ~= "\n * prefixes:";
130 		foreach ( string prefix ; prefixes )
131 		{
132 			text ~= "\n * \t- "~prefix;
133 		}
134 		
135 		text ~= "\n * omit structs:";
136 		foreach ( string noStruct ; noStructs )
137 		{
138 			text ~= "\n * \t- "~noStruct;
139 		}
140 		
141 		text ~= "\n * omit prefixes:";
142 		foreach ( string noPrefix ; noPrefixes )
143 		{
144 			text ~= "\n * \t- "~noPrefix;
145 		}
146 		
147 		text ~= "\n * omit code:";
148 		foreach ( string ncode ; noCode )
149 		{
150 			text ~= "\n * \t- "~ncode;
151 		}
152 
153 		text ~= "\n * omit signals:";
154 		foreach ( string nsignal ; noSignals )
155 		{
156 			text ~= "\n * \t- "~nsignal;
157 		}
158 		
159 		text ~= "\n * imports:";
160 		foreach ( string imp ; imprts )
161 		{
162 			text ~= "\n * \t- "~imp;
163 		}
164 
165 		text ~= "\n * structWrap:";
166 		foreach ( string key ; structWrap.keys.sort )
167 		{
168 			text ~= "\n * \t- "~key~" -> "~structWrap[key];
169 		}
170 
171 		text ~= "\n * module aliases:";
172 		foreach ( string key ; mAliases.keys.sort )
173 		{
174 			text ~= "\n * \t- "~key~" -> "~mAliases[key];
175 		}
176 		text ~= "\n * local aliases:";
177 		foreach ( string key ; aliases.keys.sort )
178 		{
179 			text ~= "\n * \t- "~key~" -> "~aliases[key];
180 		}
181 		text ~= "\n * overrides:";
182 		foreach ( string over ; overrides )
183 		{
184 			text ~= "\n * \t- "~over;
185 		}
186 		text ~= "\n */\n\n";
187 		return text;
188 	}
189 	
190 	public bool containsPrefix(string prefix)
191 	{
192 		bool contains = false;
193 		int i = 0;
194 		while ( !contains && i<prefixes.length )
195 		{
196 			contains = GtkDClass.startsWith(prefix, prefixes[i]);
197 			++i;
198 		}
199 		return contains;
200 	}	
201 
202 	public string getPrefix(string prefix)
203 	{
204 		string fundPrefix;
205 		bool contains = false;
206 		int i = 0;
207 		while ( !contains && i<prefixes.length )
208 		{
209 			if ( GtkDClass.startsWith(prefix, prefixes[i]) )
210 			{
211 				contains = true;
212 				fundPrefix = prefixes[i];
213 			}
214 			++i;
215 		}
216 		return fundPrefix;
217 	}	
218 
219 	public bool needsOverride(string functionName)
220 	{
221 		bool needed = false;
222 		int i=0;
223 		while ( !needed && i<overrides.length )
224 		{
225 			needed = functionName == overrides[i];
226 			debug(overrides)writefln("\t (%s) %s ?= %s", needed, functionName, overrides[i]);
227 			++i;
228 		}
229 		debug(overrides)writefln("\t (%s) %s %s", i, (needed?"override >>>>>>>":"no override <<<<<"), functionName);
230 		return needed;
231 	}
232 
233 	public bool omitCode(string codeName)
234 	{
235 		bool omit = false;
236 		int i=0;
237 		while ( !omit && i<noCode.length )
238 		{
239 			omit = codeName == noCode[i];
240 			debug(omitCode)writefln("\t (%s) %s ?= %s", omit, codeName, noCode[i]);
241 			++i;
242 		}
243 		debug(omitCode)writefln("\t (%s) %s %s", i, (omit?"omited >>>>>>>":"included <<<<<"), codeName);
244 		return omit;
245 	}
246 	
247 	public bool omitSignal(string signalName)
248 	{
249 		bool omit = false;
250 		int i=0;
251 		while ( !omit && i<noSignals.length )
252 		{
253 			omit = signalName == noSignals[i];
254 			debug(omitSignal)writefln("\t (%s) %s ?= %s", omit, signalName, noSignals[i]);
255 			++i;
256 		}
257 		debug(omitSignal)writefln("\t (%s) %s %s", i, (omit?"omited >>>>>>>":"included <<<<<"), signalName);
258 		return omit;
259 	}
260 }