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