Disable per Zoltan's suggestion
[mono.git] / mcs / class / System / System.Text.RegularExpressions / Regex.jvm.cs
1 //
2 // Regex.jvm.cs
3 //
4 // Author:
5 //      Arina Itkes  <arinai@mainsoft.com>
6 //
7 // Copyright (C) 2007 Mainsoft, Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Runtime.Serialization;
32
33 namespace System.Text.RegularExpressions
34 {
35         public partial class Regex : ISerializable
36         {
37                 IMachineFactory _monoFactory;
38                 readonly object _monoFactoryLock = new object ();
39
40                 internal bool SameGroupNamesFlag {
41                         get {
42                                 return GetJvmMachine ().PatternData.SameGroupsFlag;
43                         }
44                 }
45
46                 internal IMachine GetMonoMachine () {
47
48                         lock (_monoFactoryLock) {
49                                 if (_monoFactory != null) 
50                                         return _monoFactory.NewInstance ();
51                                 
52                                 _monoFactory = CreateMachineFactory (this.pattern, this.Options);
53                         }
54
55                         return _monoFactory.NewInstance ();
56                 }
57
58                 internal JvmReMachine GetJvmMachine () {
59                         if (machineFactory is InterpreterFactory)
60                                 return null;
61
62                         return ((JvmReMachineFactory) machineFactory).GetMachine ();
63                 }
64
65                 internal int GetJavaNumberByNetNumber (int netNumber) {
66                         if (netNumber < 0 || netNumber > group_count) {
67                                 return netNumber;
68                         }
69
70                         return GetJvmMachine ().PatternData.NetToJavaNumbersMap [netNumber];
71                 }
72
73                 private void Init () {
74                         
75                         this.machineFactory = cache.Lookup (this.pattern, this.roptions);
76                         
77                         if (this.machineFactory != null) {
78                 
79                                 this.group_count = this.machineFactory.GroupCount;
80                                 this.mapping = this.machineFactory.Mapping;
81                                 this._groupNumberToNameMap = this.machineFactory.NamesMapping;
82
83                                 return;
84                         }
85
86                         PatternData patternData = null;
87                         string errorMessage = null;
88                         try{
89                                 patternData = PatternDataBuilder.GetPatternData(pattern, roptions);
90                         }catch(Exception e){
91 #if DEBUG
92                                 throw;
93 #endif
94                                 errorMessage = "Creating pattern on JVM failed for pattern " + pattern
95                                 + "\n" + e.Message;
96                         }
97
98                         if (patternData == null){
99                                 InitNewRegex();
100                                 if (errorMessage != null)
101                                         Console.WriteLine (errorMessage);
102                         }
103                         else
104                                 InitJvmRegex (patternData);
105
106                         cache.Add (this.pattern, this.roptions, this.machineFactory);
107                         return;
108                 }
109
110                 private void InitJvmRegex (PatternData patternData) {
111                         
112                         machineFactory = new JvmReMachineFactory (patternData);
113                         this.group_count = this.machineFactory.GroupCount;
114                         this.mapping = this.machineFactory.Mapping;
115                         this._groupNumberToNameMap = this.machineFactory.NamesMapping;
116                 }
117
118         }
119 }