diff options
Diffstat (limited to 'Prebuild/src/Core/Nodes/OptionsNode.cs')
-rw-r--r-- | Prebuild/src/Core/Nodes/OptionsNode.cs | 655 |
1 files changed, 655 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Nodes/OptionsNode.cs b/Prebuild/src/Core/Nodes/OptionsNode.cs new file mode 100644 index 0000000..b5a2f60 --- /dev/null +++ b/Prebuild/src/Core/Nodes/OptionsNode.cs | |||
@@ -0,0 +1,655 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2007-01-08 17:55:40 +0100 (må, 08 jan 2007) $ | ||
31 | * $Revision: 197 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | |||
36 | |||
37 | using System; | ||
38 | using System.Collections; | ||
39 | using System.Collections.Specialized; | ||
40 | using System.Reflection; | ||
41 | using System.Xml; | ||
42 | |||
43 | using Prebuild.Core.Attributes; | ||
44 | using Prebuild.Core.Interfaces; | ||
45 | using Prebuild.Core.Utilities; | ||
46 | |||
47 | namespace Prebuild.Core.Nodes | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// | ||
51 | /// </summary> | ||
52 | [DataNode("Options")] | ||
53 | public class OptionsNode : DataNode | ||
54 | { | ||
55 | #region Fields | ||
56 | |||
57 | private static Hashtable m_OptionFields; | ||
58 | |||
59 | [OptionNode("CompilerDefines")] | ||
60 | private string m_CompilerDefines = ""; | ||
61 | |||
62 | /// <summary> | ||
63 | /// | ||
64 | /// </summary> | ||
65 | public string CompilerDefines | ||
66 | { | ||
67 | get | ||
68 | { | ||
69 | return m_CompilerDefines; | ||
70 | } | ||
71 | set | ||
72 | { | ||
73 | m_CompilerDefines = value; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | [OptionNode("OptimizeCode")] | ||
78 | private bool m_OptimizeCode; | ||
79 | |||
80 | /// <summary> | ||
81 | /// | ||
82 | /// </summary> | ||
83 | public bool OptimizeCode | ||
84 | { | ||
85 | get | ||
86 | { | ||
87 | return m_OptimizeCode; | ||
88 | } | ||
89 | set | ||
90 | { | ||
91 | m_OptimizeCode = value; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | [OptionNode("CheckUnderflowOverflow")] | ||
96 | private bool m_CheckUnderflowOverflow; | ||
97 | |||
98 | /// <summary> | ||
99 | /// | ||
100 | /// </summary> | ||
101 | public bool CheckUnderflowOverflow | ||
102 | { | ||
103 | get | ||
104 | { | ||
105 | return m_CheckUnderflowOverflow; | ||
106 | } | ||
107 | set | ||
108 | { | ||
109 | m_CheckUnderflowOverflow = value; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | [OptionNode("AllowUnsafe")] | ||
114 | private bool m_AllowUnsafe; | ||
115 | |||
116 | /// <summary> | ||
117 | /// | ||
118 | /// </summary> | ||
119 | public bool AllowUnsafe | ||
120 | { | ||
121 | get | ||
122 | { | ||
123 | return m_AllowUnsafe; | ||
124 | } | ||
125 | set | ||
126 | { | ||
127 | m_AllowUnsafe = value; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | [OptionNode("PreBuildEvent")] | ||
132 | private string m_PreBuildEvent; | ||
133 | |||
134 | /// <summary> | ||
135 | /// | ||
136 | /// </summary> | ||
137 | public string PreBuildEvent | ||
138 | { | ||
139 | get | ||
140 | { | ||
141 | return m_PreBuildEvent; | ||
142 | } | ||
143 | set | ||
144 | { | ||
145 | m_PreBuildEvent = value; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | [OptionNode("PostBuildEvent")] | ||
150 | private string m_PostBuildEvent; | ||
151 | |||
152 | /// <summary> | ||
153 | /// | ||
154 | /// </summary> | ||
155 | public string PostBuildEvent | ||
156 | { | ||
157 | get | ||
158 | { | ||
159 | return m_PostBuildEvent; | ||
160 | } | ||
161 | set | ||
162 | { | ||
163 | m_PostBuildEvent = value; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | [OptionNode("PreBuildEventArgs")] | ||
168 | private string m_PreBuildEventArgs; | ||
169 | |||
170 | /// <summary> | ||
171 | /// | ||
172 | /// </summary> | ||
173 | public string PreBuildEventArgs | ||
174 | { | ||
175 | get | ||
176 | { | ||
177 | return m_PreBuildEventArgs; | ||
178 | } | ||
179 | set | ||
180 | { | ||
181 | m_PreBuildEventArgs = value; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | [OptionNode("PostBuildEventArgs")] | ||
186 | private string m_PostBuildEventArgs; | ||
187 | |||
188 | /// <summary> | ||
189 | /// | ||
190 | /// </summary> | ||
191 | public string PostBuildEventArgs | ||
192 | { | ||
193 | get | ||
194 | { | ||
195 | return m_PostBuildEventArgs; | ||
196 | } | ||
197 | set | ||
198 | { | ||
199 | m_PostBuildEventArgs = value; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | [OptionNode("RunPostBuildEvent")] | ||
204 | private string m_RunPostBuildEvent; | ||
205 | |||
206 | /// <summary> | ||
207 | /// | ||
208 | /// </summary> | ||
209 | public string RunPostBuildEvent | ||
210 | { | ||
211 | get | ||
212 | { | ||
213 | return m_RunPostBuildEvent; | ||
214 | } | ||
215 | set | ||
216 | { | ||
217 | m_RunPostBuildEvent = value; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | [OptionNode("RunScript")] | ||
222 | private string m_RunScript; | ||
223 | |||
224 | /// <summary> | ||
225 | /// | ||
226 | /// </summary> | ||
227 | public string RunScript | ||
228 | { | ||
229 | get | ||
230 | { | ||
231 | return m_RunScript; | ||
232 | } | ||
233 | set | ||
234 | { | ||
235 | m_RunScript = value; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | [OptionNode("WarningLevel")] | ||
240 | private int m_WarningLevel = 4; | ||
241 | |||
242 | /// <summary> | ||
243 | /// | ||
244 | /// </summary> | ||
245 | public int WarningLevel | ||
246 | { | ||
247 | get | ||
248 | { | ||
249 | return m_WarningLevel; | ||
250 | } | ||
251 | set | ||
252 | { | ||
253 | m_WarningLevel = value; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | [OptionNode("WarningsAsErrors")] | ||
258 | private bool m_WarningsAsErrors; | ||
259 | |||
260 | /// <summary> | ||
261 | /// | ||
262 | /// </summary> | ||
263 | public bool WarningsAsErrors | ||
264 | { | ||
265 | get | ||
266 | { | ||
267 | return m_WarningsAsErrors; | ||
268 | } | ||
269 | set | ||
270 | { | ||
271 | m_WarningsAsErrors = value; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | [OptionNode("SuppressWarnings")] | ||
276 | private string m_SuppressWarnings = ""; | ||
277 | |||
278 | /// <summary> | ||
279 | /// | ||
280 | /// </summary> | ||
281 | public string SuppressWarnings | ||
282 | { | ||
283 | get | ||
284 | { | ||
285 | return m_SuppressWarnings; | ||
286 | } | ||
287 | set | ||
288 | { | ||
289 | m_SuppressWarnings = value; | ||
290 | } | ||
291 | } | ||
292 | |||
293 | [OptionNode("OutputPath")] | ||
294 | private string m_OutputPath = "bin/"; | ||
295 | |||
296 | /// <summary> | ||
297 | /// | ||
298 | /// </summary> | ||
299 | public string OutputPath | ||
300 | { | ||
301 | get | ||
302 | { | ||
303 | return m_OutputPath; | ||
304 | } | ||
305 | set | ||
306 | { | ||
307 | m_OutputPath = value; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | [OptionNode("GenerateDocumentation")] | ||
312 | private bool m_GenerateDocumentation; | ||
313 | |||
314 | /// <summary> | ||
315 | /// | ||
316 | /// </summary> | ||
317 | public bool GenerateDocumentation | ||
318 | { | ||
319 | get | ||
320 | { | ||
321 | return m_GenerateDocumentation; | ||
322 | } | ||
323 | set | ||
324 | { | ||
325 | m_GenerateDocumentation = value; | ||
326 | } | ||
327 | } | ||
328 | |||
329 | [OptionNode("GenerateXmlDocFile")] | ||
330 | private bool m_GenerateXmlDocFile; | ||
331 | |||
332 | /// <summary> | ||
333 | /// | ||
334 | /// </summary> | ||
335 | public bool GenerateXmlDocFile | ||
336 | { | ||
337 | get | ||
338 | { | ||
339 | return m_GenerateXmlDocFile; | ||
340 | } | ||
341 | set | ||
342 | { | ||
343 | m_GenerateXmlDocFile = value; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | [OptionNode("XmlDocFile")] | ||
348 | private string m_XmlDocFile = ""; | ||
349 | |||
350 | /// <summary> | ||
351 | /// | ||
352 | /// </summary> | ||
353 | public string XmlDocFile | ||
354 | { | ||
355 | get | ||
356 | { | ||
357 | return m_XmlDocFile; | ||
358 | } | ||
359 | set | ||
360 | { | ||
361 | m_XmlDocFile = value; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | [OptionNode("KeyFile")] | ||
366 | private string m_KeyFile = ""; | ||
367 | |||
368 | /// <summary> | ||
369 | /// | ||
370 | /// </summary> | ||
371 | public string KeyFile | ||
372 | { | ||
373 | get | ||
374 | { | ||
375 | return m_KeyFile; | ||
376 | } | ||
377 | set | ||
378 | { | ||
379 | m_KeyFile = value; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | [OptionNode("DebugInformation")] | ||
384 | private bool m_DebugInformation; | ||
385 | |||
386 | /// <summary> | ||
387 | /// | ||
388 | /// </summary> | ||
389 | public bool DebugInformation | ||
390 | { | ||
391 | get | ||
392 | { | ||
393 | return m_DebugInformation; | ||
394 | } | ||
395 | set | ||
396 | { | ||
397 | m_DebugInformation = value; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | [OptionNode("RegisterComInterop")] | ||
402 | private bool m_RegisterComInterop; | ||
403 | |||
404 | /// <summary> | ||
405 | /// | ||
406 | /// </summary> | ||
407 | public bool RegisterComInterop | ||
408 | { | ||
409 | get | ||
410 | { | ||
411 | return m_RegisterComInterop; | ||
412 | } | ||
413 | set | ||
414 | { | ||
415 | m_RegisterComInterop = value; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | [OptionNode("RemoveIntegerChecks")] | ||
420 | private bool m_RemoveIntegerChecks; | ||
421 | |||
422 | /// <summary> | ||
423 | /// | ||
424 | /// </summary> | ||
425 | public bool RemoveIntegerChecks | ||
426 | { | ||
427 | get | ||
428 | { | ||
429 | return m_RemoveIntegerChecks; | ||
430 | } | ||
431 | set | ||
432 | { | ||
433 | m_RemoveIntegerChecks = value; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | [OptionNode("IncrementalBuild")] | ||
438 | private bool m_IncrementalBuild; | ||
439 | |||
440 | /// <summary> | ||
441 | /// | ||
442 | /// </summary> | ||
443 | public bool IncrementalBuild | ||
444 | { | ||
445 | get | ||
446 | { | ||
447 | return m_IncrementalBuild; | ||
448 | } | ||
449 | set | ||
450 | { | ||
451 | m_IncrementalBuild = value; | ||
452 | } | ||
453 | } | ||
454 | |||
455 | [OptionNode("BaseAddress")] | ||
456 | private string m_BaseAddress = "285212672"; | ||
457 | |||
458 | /// <summary> | ||
459 | /// | ||
460 | /// </summary> | ||
461 | public string BaseAddress | ||
462 | { | ||
463 | get | ||
464 | { | ||
465 | return m_BaseAddress; | ||
466 | } | ||
467 | set | ||
468 | { | ||
469 | m_BaseAddress = value; | ||
470 | } | ||
471 | } | ||
472 | |||
473 | [OptionNode("FileAlignment")] | ||
474 | private int m_FileAlignment = 4096; | ||
475 | |||
476 | /// <summary> | ||
477 | /// | ||
478 | /// </summary> | ||
479 | public int FileAlignment | ||
480 | { | ||
481 | get | ||
482 | { | ||
483 | return m_FileAlignment; | ||
484 | } | ||
485 | set | ||
486 | { | ||
487 | m_FileAlignment = value; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | [OptionNode("NoStdLib")] | ||
492 | private bool m_NoStdLib; | ||
493 | |||
494 | /// <summary> | ||
495 | /// | ||
496 | /// </summary> | ||
497 | public bool NoStdLib | ||
498 | { | ||
499 | get | ||
500 | { | ||
501 | return m_NoStdLib; | ||
502 | } | ||
503 | set | ||
504 | { | ||
505 | m_NoStdLib = value; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | private StringCollection m_FieldsDefined; | ||
510 | |||
511 | #endregion | ||
512 | |||
513 | #region Constructors | ||
514 | |||
515 | /// <summary> | ||
516 | /// Initializes the <see cref="OptionsNode"/> class. | ||
517 | /// </summary> | ||
518 | static OptionsNode() | ||
519 | { | ||
520 | Type t = typeof(OptionsNode); | ||
521 | |||
522 | m_OptionFields = new Hashtable(); | ||
523 | foreach(FieldInfo f in t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) | ||
524 | { | ||
525 | object[] attrs = f.GetCustomAttributes(typeof(OptionNodeAttribute), false); | ||
526 | if(attrs == null || attrs.Length < 1) | ||
527 | { | ||
528 | continue; | ||
529 | } | ||
530 | |||
531 | OptionNodeAttribute ona = (OptionNodeAttribute)attrs[0]; | ||
532 | m_OptionFields[ona.NodeName] = f; | ||
533 | } | ||
534 | } | ||
535 | |||
536 | /// <summary> | ||
537 | /// Initializes a new instance of the <see cref="OptionsNode"/> class. | ||
538 | /// </summary> | ||
539 | public OptionsNode() | ||
540 | { | ||
541 | m_FieldsDefined = new StringCollection(); | ||
542 | } | ||
543 | |||
544 | #endregion | ||
545 | |||
546 | #region Properties | ||
547 | |||
548 | /// <summary> | ||
549 | /// Gets the <see cref="Object"/> at the specified index. | ||
550 | /// </summary> | ||
551 | /// <value></value> | ||
552 | public object this[string index] | ||
553 | { | ||
554 | get | ||
555 | { | ||
556 | if(!m_OptionFields.ContainsKey(index)) | ||
557 | { | ||
558 | return null; | ||
559 | } | ||
560 | |||
561 | FieldInfo f = (FieldInfo)m_OptionFields[index]; | ||
562 | return f.GetValue(this); | ||
563 | } | ||
564 | } | ||
565 | |||
566 | /// <summary> | ||
567 | /// Gets the <see cref="Object"/> at the specified index. | ||
568 | /// </summary> | ||
569 | /// <value></value> | ||
570 | public object this[string index, object defaultValue] | ||
571 | { | ||
572 | get | ||
573 | { | ||
574 | object valueObject = this[index]; | ||
575 | if(valueObject != null && valueObject is string && ((string)valueObject).Length == 0) | ||
576 | { | ||
577 | return defaultValue; | ||
578 | } | ||
579 | return valueObject; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | |||
584 | #endregion | ||
585 | |||
586 | #region Private Methods | ||
587 | |||
588 | private void FlagDefined(string name) | ||
589 | { | ||
590 | if(!m_FieldsDefined.Contains(name)) | ||
591 | { | ||
592 | m_FieldsDefined.Add(name); | ||
593 | } | ||
594 | } | ||
595 | |||
596 | private void SetOption(string nodeName, string val) | ||
597 | { | ||
598 | lock(m_OptionFields) | ||
599 | { | ||
600 | if(!m_OptionFields.ContainsKey(nodeName)) | ||
601 | { | ||
602 | return; | ||
603 | } | ||
604 | |||
605 | FieldInfo f = (FieldInfo)m_OptionFields[nodeName]; | ||
606 | f.SetValue(this, Helper.TranslateValue(f.FieldType, val)); | ||
607 | FlagDefined(f.Name); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | #endregion | ||
612 | |||
613 | #region Public Methods | ||
614 | |||
615 | /// <summary> | ||
616 | /// Parses the specified node. | ||
617 | /// </summary> | ||
618 | /// <param name="node">The node.</param> | ||
619 | public override void Parse(XmlNode node) | ||
620 | { | ||
621 | if( node == null ) | ||
622 | { | ||
623 | throw new ArgumentNullException("node"); | ||
624 | } | ||
625 | |||
626 | foreach(XmlNode child in node.ChildNodes) | ||
627 | { | ||
628 | SetOption(child.Name, Helper.InterpolateForEnvironmentVariables(child.InnerText)); | ||
629 | } | ||
630 | } | ||
631 | |||
632 | /// <summary> | ||
633 | /// Copies to. | ||
634 | /// </summary> | ||
635 | /// <param name="opt">The opt.</param> | ||
636 | public void CopyTo(OptionsNode opt) | ||
637 | { | ||
638 | if(opt == null) | ||
639 | { | ||
640 | return; | ||
641 | } | ||
642 | |||
643 | foreach(FieldInfo f in m_OptionFields.Values) | ||
644 | { | ||
645 | if(m_FieldsDefined.Contains(f.Name)) | ||
646 | { | ||
647 | f.SetValue(opt, f.GetValue(this)); | ||
648 | opt.m_FieldsDefined.Add(f.Name); | ||
649 | } | ||
650 | } | ||
651 | } | ||
652 | |||
653 | #endregion | ||
654 | } | ||
655 | } | ||